Merge tag 'edac_updates_for_5.7' of git://git.kernel.org/pub/scm/linux/kernel/git...
authorLinus Torvalds <torvalds@linux-foundation.org>
Mon, 30 Mar 2020 20:12:37 +0000 (13:12 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Mon, 30 Mar 2020 20:12:37 +0000 (13:12 -0700)
Pull EDAC updates from Borislav Petkov:

 - A substantial edac_mc cleanup, sanitizing object freeing,
   streamlining and simplifying code flow, and getting rid of a lot of
   needless complexity in memory controller representation code, by
   Robert Richter.

 - A new EDAC driver for the ARM DMC-520 memory controller, by Lei Wang,
   Shiping Ji and others.

 - The usual sprinkling of misc cleanups and fixes all over the
   subsystem.

* tag 'edac_updates_for_5.7' of git://git.kernel.org/pub/scm/linux/kernel/git/ras/ras:
  EDAC/armada_xp: Use scnprintf() for avoiding potential buffer overflow
  EDAC/synopsys: Do not dump uninitialized pinf->col
  EDAC: Add EDAC driver for DMC520
  dt-bindings: edac: Dmc-520.yaml
  EDAC/mce_amd: Print !SMCA processor warning only once
  EDAC/mc: Remove per layer counters
  EDAC/mc: Remove detail[] string and cleanup error string generation
  EDAC/mc: Pass the error descriptor to error reporting functions
  EDAC/mc: Remove enable_per_layer_report function argument
  EDAC/mc: Report "unknown memory" on too many DIMM labels found
  EDAC/mc: Carve out error increment into a separate function
  EDAC/mc: Determine mci pointer from the error descriptor
  EDAC: Store error type in struct edac_raw_error_desc
  EDAC/mc: Reorder functions edac_mc_alloc*()
  EDAC/mc: Split edac_mc_alloc() into smaller functions
  EDAC/mc: Change mci device removal to use put_device()

342 files changed:
Documentation/ABI/removed/sysfs-kernel-uids [moved from Documentation/ABI/testing/sysfs-kernel-uids with 91% similarity]
Documentation/Makefile
Documentation/PCI/pci.rst
Documentation/accounting/psi.rst
Documentation/admin-guide/binfmt-misc.rst
Documentation/admin-guide/blockdev/zram.rst
Documentation/admin-guide/bootconfig.rst
Documentation/admin-guide/cgroup-v1/index.rst
Documentation/admin-guide/cgroup-v2.rst
Documentation/admin-guide/edid.rst [moved from Documentation/driver-api/edid.rst with 98% similarity]
Documentation/admin-guide/hw-vuln/tsx_async_abort.rst
Documentation/admin-guide/index.rst
Documentation/admin-guide/iostats.rst
Documentation/admin-guide/kernel-parameters.txt
Documentation/admin-guide/kernel-per-CPU-kthreads.rst
Documentation/admin-guide/perf/imx-ddr.rst
Documentation/admin-guide/sysctl/kernel.rst
Documentation/arm/tcm.rst
Documentation/block/capability.rst
Documentation/conf.py
Documentation/core-api/index.rst
Documentation/core-api/kobject.rst [moved from Documentation/kobject.txt with 87% similarity]
Documentation/debugging-modules.txt [deleted file]
Documentation/dev-tools/gcov.rst
Documentation/dev-tools/kmemleak.rst
Documentation/driver-api/80211/mac80211-advanced.rst
Documentation/driver-api/dmaengine/index.rst
Documentation/driver-api/driver-model/driver.rst
Documentation/driver-api/index.rst
Documentation/driver-api/io-mapping.rst [moved from Documentation/io-mapping.txt with 100% similarity]
Documentation/driver-api/io_ordering.rst [moved from Documentation/io_ordering.txt with 100% similarity]
Documentation/driver-api/ioctl.rst [moved from Documentation/core-api/ioctl.rst with 100% similarity]
Documentation/features/vm/pte_special/arch-support.txt
Documentation/filesystems/9p.rst [moved from Documentation/filesystems/9p.txt with 63% similarity]
Documentation/filesystems/adfs.rst [moved from Documentation/filesystems/adfs.txt with 85% similarity]
Documentation/filesystems/affs.rst [moved from Documentation/filesystems/affs.txt with 86% similarity]
Documentation/filesystems/afs.rst [moved from Documentation/filesystems/afs.txt with 90% similarity]
Documentation/filesystems/autofs-mount-control.rst [moved from Documentation/filesystems/autofs-mount-control.txt with 89% similarity]
Documentation/filesystems/befs.rst [moved from Documentation/filesystems/befs.txt with 83% similarity]
Documentation/filesystems/bfs.rst [moved from Documentation/filesystems/bfs.txt with 71% similarity]
Documentation/filesystems/btrfs.rst [moved from Documentation/filesystems/btrfs.txt with 96% similarity]
Documentation/filesystems/ceph.rst [moved from Documentation/filesystems/ceph.txt with 91% similarity]
Documentation/filesystems/cifs/cifsroot.txt
Documentation/filesystems/cramfs.rst [moved from Documentation/filesystems/cramfs.txt with 88% similarity]
Documentation/filesystems/debugfs.rst [moved from Documentation/filesystems/debugfs.txt with 91% similarity]
Documentation/filesystems/dlmfs.rst [moved from Documentation/filesystems/dlmfs.txt with 86% similarity]
Documentation/filesystems/ecryptfs.rst [moved from Documentation/filesystems/ecryptfs.txt with 62% similarity]
Documentation/filesystems/efivarfs.rst [moved from Documentation/filesystems/efivarfs.txt with 85% similarity]
Documentation/filesystems/erofs.rst [moved from Documentation/filesystems/erofs.txt with 54% similarity]
Documentation/filesystems/ext2.rst [moved from Documentation/filesystems/ext2.txt with 91% similarity]
Documentation/filesystems/ext3.rst [moved from Documentation/filesystems/ext3.txt with 88% similarity]
Documentation/filesystems/f2fs.rst [moved from Documentation/filesystems/f2fs.txt with 84% similarity]
Documentation/filesystems/fuse.rst
Documentation/filesystems/gfs2-uevents.rst [moved from Documentation/filesystems/gfs2-uevents.txt with 94% similarity]
Documentation/filesystems/gfs2.rst [moved from Documentation/filesystems/gfs2.txt with 76% similarity]
Documentation/filesystems/hfs.rst [moved from Documentation/filesystems/hfs.txt with 80% similarity]
Documentation/filesystems/hfsplus.rst [moved from Documentation/filesystems/hfsplus.txt with 95% similarity]
Documentation/filesystems/hpfs.rst [moved from Documentation/filesystems/hpfs.txt with 66% similarity]
Documentation/filesystems/index.rst
Documentation/filesystems/inotify.rst [moved from Documentation/filesystems/inotify.txt with 83% similarity]
Documentation/filesystems/isofs.rst [new file with mode: 0644]
Documentation/filesystems/isofs.txt [deleted file]
Documentation/filesystems/nfs/index.rst [new file with mode: 0644]
Documentation/filesystems/nfs/knfsd-stats.rst [moved from Documentation/filesystems/nfs/knfsd-stats.txt with 95% similarity]
Documentation/filesystems/nfs/nfs41-server.rst [new file with mode: 0644]
Documentation/filesystems/nfs/nfs41-server.txt [deleted file]
Documentation/filesystems/nfs/pnfs.rst [moved from Documentation/filesystems/nfs/pnfs.txt with 87% similarity]
Documentation/filesystems/nfs/rpc-cache.rst [moved from Documentation/filesystems/nfs/rpc-cache.txt with 66% similarity]
Documentation/filesystems/nfs/rpc-server-gss.rst [moved from Documentation/filesystems/nfs/rpc-server-gss.txt with 92% similarity]
Documentation/filesystems/nilfs2.rst [moved from Documentation/filesystems/nilfs2.txt with 89% similarity]
Documentation/filesystems/ntfs.rst [moved from Documentation/filesystems/ntfs.txt with 85% similarity]
Documentation/filesystems/ocfs2-online-filecheck.rst [moved from Documentation/filesystems/ocfs2-online-filecheck.txt with 77% similarity]
Documentation/filesystems/ocfs2.rst [moved from Documentation/filesystems/ocfs2.txt with 88% similarity]
Documentation/filesystems/omfs.rst [new file with mode: 0644]
Documentation/filesystems/omfs.txt [deleted file]
Documentation/filesystems/orangefs.rst [moved from Documentation/filesystems/orangefs.txt with 83% similarity]
Documentation/filesystems/proc.rst [moved from Documentation/filesystems/proc.txt with 65% similarity]
Documentation/filesystems/qnx6.rst [moved from Documentation/filesystems/qnx6.txt with 98% similarity]
Documentation/filesystems/ramfs-rootfs-initramfs.rst [moved from Documentation/filesystems/ramfs-rootfs-initramfs.txt with 91% similarity]
Documentation/filesystems/relay.rst [moved from Documentation/filesystems/relay.txt with 91% similarity]
Documentation/filesystems/romfs.rst [moved from Documentation/filesystems/romfs.txt with 86% similarity]
Documentation/filesystems/squashfs.rst [moved from Documentation/filesystems/squashfs.txt with 91% similarity]
Documentation/filesystems/sysfs.rst [moved from Documentation/filesystems/sysfs.txt with 56% similarity]
Documentation/filesystems/sysv-fs.rst [moved from Documentation/filesystems/sysv-fs.txt with 73% similarity]
Documentation/filesystems/tmpfs.rst [moved from Documentation/filesystems/tmpfs.txt with 86% similarity]
Documentation/filesystems/ubifs-authentication.rst
Documentation/filesystems/ubifs.rst [moved from Documentation/filesystems/ubifs.txt with 91% similarity]
Documentation/filesystems/udf.rst [moved from Documentation/filesystems/udf.txt with 83% similarity]
Documentation/filesystems/virtiofs.rst
Documentation/filesystems/zonefs.rst [moved from Documentation/filesystems/zonefs.txt with 90% similarity]
Documentation/gpu/i915.rst
Documentation/index.rst
Documentation/kbuild/gcc-plugins.rst [moved from Documentation/core-api/gcc-plugins.rst with 98% similarity]
Documentation/kbuild/index.rst
Documentation/kernel-hacking/hacking.rst
Documentation/kernel-hacking/locking.rst
Documentation/kref.txt
Documentation/media/kapi/v4l2-controls.rst
Documentation/misc-devices/index.rst
Documentation/misc-devices/mic/index.rst [moved from Documentation/mic/index.rst with 100% similarity]
Documentation/misc-devices/mic/mic_overview.rst [moved from Documentation/mic/mic_overview.rst with 100% similarity]
Documentation/misc-devices/mic/scif_overview.rst [moved from Documentation/mic/scif_overview.rst with 100% similarity]
Documentation/networking/snmp_counter.rst
Documentation/powerpc/ultravisor.rst
Documentation/process/2.Process.rst
Documentation/process/coding-style.rst
Documentation/process/deprecated.rst
Documentation/process/email-clients.rst
Documentation/process/howto.rst
Documentation/process/kernel-docs.rst
Documentation/process/management-style.rst
Documentation/scsi/scsi_mid_low_api.txt
Documentation/security/siphash.rst
Documentation/target/tcmu-design.rst
Documentation/trace/events.rst
Documentation/translations/it_IT/networking/netdev-FAQ.rst
Documentation/translations/it_IT/process/programming-language.rst
Documentation/translations/zh_CN/filesystems/index.rst [new file with mode: 0644]
Documentation/translations/zh_CN/filesystems/virtiofs.rst [new file with mode: 0644]
Documentation/translations/zh_CN/index.rst
Documentation/translations/zh_CN/io_ordering.txt
Documentation/translations/zh_CN/process/5.Posting.rst
Documentation/userspace-api/ioctl/ioctl-number.rst
Documentation/x86/exception-tables.rst
Documentation/x86/intel-iommu.rst
MAINTAINERS
arch/arm/include/asm/floppy.h
arch/m68k/emu/nfblock.c
arch/unicore32/include/asm/io.h
arch/xtensa/platforms/iss/simdisk.c
block/Makefile
block/bfq-cgroup.c
block/bfq-iosched.c
block/bfq-iosched.h
block/bio.c
block/blk-cgroup.c
block/blk-core.c
block/blk-flush.c
block/blk-ioc.c
block/blk-iocost.c
block/blk-map.c
block/blk-mq.c
block/blk-settings.c
block/blk-zoned.c
block/blk.h
block/genhd.c
block/ioctl.c
block/opal_proto.h
block/partitions/Makefile
block/partitions/acorn.c
block/partitions/acorn.h [deleted file]
block/partitions/aix.c
block/partitions/aix.h [deleted file]
block/partitions/amiga.c
block/partitions/amiga.h [deleted file]
block/partitions/atari.h
block/partitions/check.c [deleted file]
block/partitions/check.h
block/partitions/cmdline.c
block/partitions/cmdline.h [deleted file]
block/partitions/core.c [moved from block/partition-generic.c with 72% similarity]
block/partitions/efi.h
block/partitions/ibm.c
block/partitions/ibm.h [deleted file]
block/partitions/karma.c
block/partitions/karma.h [deleted file]
block/partitions/ldm.c
block/partitions/ldm.h
block/partitions/mac.h
block/partitions/msdos.c
block/partitions/msdos.h [deleted file]
block/partitions/osf.c
block/partitions/osf.h [deleted file]
block/partitions/sgi.c
block/partitions/sgi.h [deleted file]
block/partitions/sun.c
block/partitions/sun.h [deleted file]
block/partitions/sysv68.c
block/partitions/sysv68.h [deleted file]
block/partitions/ultrix.c
block/partitions/ultrix.h [deleted file]
block/sed-opal.c
drivers/ata/Kconfig
drivers/ata/Makefile
drivers/ata/ahci.c
drivers/ata/libata-core.c
drivers/ata/libata-eh.c
drivers/ata/libata-pata-timings.c [new file with mode: 0644]
drivers/ata/libata-sata.c [new file with mode: 0644]
drivers/ata/libata-scsi.c
drivers/ata/libata-sff.c
drivers/ata/libata-transport.c
drivers/ata/libata.h
drivers/ata/sata_promise.c
drivers/block/Makefile
drivers/block/aoe/aoeblk.c
drivers/block/brd.c
drivers/block/drbd/drbd_main.c
drivers/block/drbd/drbd_receiver.c
drivers/block/drbd/drbd_worker.c
drivers/block/floppy.c
drivers/block/loop.c
drivers/block/nbd.c
drivers/block/null_blk_main.c
drivers/block/null_blk_trace.c [new file with mode: 0644]
drivers/block/null_blk_trace.h [new file with mode: 0644]
drivers/block/null_blk_zoned.c
drivers/block/pktcdvd.c
drivers/block/ps3vram.c
drivers/block/rsxx/dev.c
drivers/block/rsxx/dma.c
drivers/block/umem.c
drivers/block/virtio_blk.c
drivers/block/xen-blkfront.c
drivers/block/zram/zram_drv.c
drivers/char/tpm/eventlog/common.c
drivers/char/tpm/eventlog/of.c
drivers/char/tpm/eventlog/tpm1.c
drivers/char/tpm/eventlog/tpm2.c
drivers/char/tpm/tpm-chip.c
drivers/char/tpm/tpm.h
drivers/char/tpm/tpm2-cmd.c
drivers/char/tpm/tpm_ibmvtpm.c
drivers/char/tpm/tpm_ibmvtpm.h
drivers/char/tpm/tpm_tis_spi_cr50.c
drivers/char/tpm/tpm_tis_spi_main.c
drivers/i3c/device.c
drivers/i3c/master.c
drivers/i3c/master/dw-i3c-master.c
drivers/i3c/master/i3c-master-cdns.c
drivers/lightnvm/core.c
drivers/lightnvm/pblk-sysfs.c
drivers/md/bcache/btree.c
drivers/md/bcache/btree.h
drivers/md/bcache/request.c
drivers/md/bcache/request.h
drivers/md/bcache/super.c
drivers/md/bcache/sysfs.c
drivers/md/bcache/writeback.c
drivers/md/bcache/writeback.h
drivers/md/dm.c
drivers/md/md.c
drivers/nvdimm/blk.c
drivers/nvdimm/btt.c
drivers/nvdimm/pmem.c
drivers/nvme/host/Kconfig
drivers/nvme/host/core.c
drivers/nvme/host/fabrics.c
drivers/nvme/host/fc.c
drivers/nvme/host/multipath.c
drivers/nvme/host/nvme.h
drivers/nvme/host/pci.c
drivers/nvme/host/rdma.c
drivers/nvme/host/tcp.c
drivers/nvme/target/admin-cmd.c
drivers/nvme/target/configfs.c
drivers/nvme/target/core.c
drivers/nvme/target/loop.c
drivers/nvme/target/nvmet.h
drivers/nvme/target/rdma.c
drivers/nvme/target/tcp.c
drivers/s390/block/dcssblk.c
drivers/s390/block/xpram.c
drivers/scsi/BusLogic.c
drivers/scsi/Kconfig
drivers/scsi/aacraid/linit.c
drivers/scsi/aic7xxx/aic79xx_osm.c
drivers/scsi/aic7xxx/aic7xxx_osm.c
drivers/scsi/arcmsr/arcmsr_hba.c
drivers/scsi/libsas/Kconfig
drivers/scsi/megaraid.c
drivers/scsi/scsi_debug.c
drivers/scsi/scsicam.c
drivers/scsi/sd.c
fs/block_dev.c
fs/buffer.c
fs/erofs/decompressor.c
fs/erofs/internal.h
fs/erofs/super.c
fs/erofs/utils.c
fs/erofs/zdata.c
fs/ext4/super.c
fs/ext4/sysfs.c
fs/f2fs/f2fs.h
fs/f2fs/super.c
fs/internal.h
fs/io-wq.c
fs/io-wq.h
fs/io_uring.c
fs/nfs/Kconfig
fs/pstore/inode.c
fs/pstore/platform.c
fs/pstore/ram.c
fs/pstore/ram_core.c
fs/reiserfs/journal.c
fs/splice.c
include/linux/bio.h
include/linux/blk-mq.h
include/linux/blkdev.h
include/linux/fs.h
include/linux/genhd.h
include/linux/io-mapping.h
include/linux/iocontext.h
include/linux/libata.h
include/linux/msdos_partition.h [new file with mode: 0644]
include/linux/part_stat.h [new file with mode: 0644]
include/linux/pci_ids.h
include/linux/raid/detect.h [new file with mode: 0644]
include/linux/seccomp.h
include/linux/socket.h
include/linux/splice.h
include/net/compat.h
include/scsi/scsicam.h
include/trace/events/io_uring.h
include/uapi/linux/fdreg.h
include/uapi/linux/io_uring.h
include/uapi/linux/seccomp.h
init/do_mounts.c
kernel/seccomp.c
kernel/task_work.c
net/compat.c
net/ipv4/Kconfig
net/ipv4/ipconfig.c
net/socket.c
scripts/check-sysctl-docs [new file with mode: 0755]
scripts/documentation-file-ref-check
scripts/gcc-plugins/Kconfig
scripts/mod/devicetable-offsets.c
scripts/mod/file2alias.c
scripts/sphinx-pre-install
security/keys/key.c
security/keys/keyctl.c
tools/edid/1024x768.S [moved from Documentation/EDID/1024x768.S with 100% similarity]
tools/edid/1280x1024.S [moved from Documentation/EDID/1280x1024.S with 100% similarity]
tools/edid/1600x1200.S [moved from Documentation/EDID/1600x1200.S with 100% similarity]
tools/edid/1680x1050.S [moved from Documentation/EDID/1680x1050.S with 100% similarity]
tools/edid/1920x1080.S [moved from Documentation/EDID/1920x1080.S with 100% similarity]
tools/edid/800x600.S [moved from Documentation/EDID/800x600.S with 100% similarity]
tools/edid/Makefile [moved from Documentation/EDID/Makefile with 100% similarity]
tools/edid/edid.S [moved from Documentation/EDID/edid.S with 100% similarity]
tools/edid/hex [moved from Documentation/EDID/hex with 100% similarity]
tools/testing/selftests/seccomp/seccomp_bpf.c

similarity index 91%
rename from Documentation/ABI/testing/sysfs-kernel-uids
rename to Documentation/ABI/removed/sysfs-kernel-uids
index 4182b70..dc4463f 100644 (file)
@@ -1,5 +1,5 @@
 What:          /sys/kernel/uids/<uid>/cpu_shares
-Date:          December 2007
+Date:          December 2007, finally removed in kernel v2.6.34-rc1
 Contact:       Dhaval Giani <dhaval@linux.vnet.ibm.com>
                Srivatsa Vaddagiri <vatsa@linux.vnet.ibm.com>
 Description:
index d77bb60..79ecee6 100644 (file)
@@ -13,7 +13,7 @@ endif
 SPHINXBUILD   = sphinx-build
 SPHINXOPTS    =
 SPHINXDIRS    = .
-_SPHINXDIRS   = $(patsubst $(srctree)/Documentation/%/index.rst,%,$(wildcard $(srctree)/Documentation/*/index.rst))
+_SPHINXDIRS   = $(sort $(patsubst $(srctree)/Documentation/%/index.rst,%,$(wildcard $(srctree)/Documentation/*/index.rst)))
 SPHINX_CONF   = conf.py
 PAPER         =
 BUILDDIR      = $(obj)/output
index 6864f9a..8c016d8 100644 (file)
@@ -239,7 +239,7 @@ from the PCI device config space. Use the values in the pci_dev structure
 as the PCI "bus address" might have been remapped to a "host physical"
 address by the arch/chip-set specific kernel support.
 
-See Documentation/io-mapping.txt for how to access device registers
+See Documentation/driver-api/io-mapping.rst for how to access device registers
 or device memory.
 
 The device driver needs to call pci_request_region() to verify
index 621111c..f2b3439 100644 (file)
@@ -1,3 +1,5 @@
+.. _psi:
+
 ================================
 PSI - Pressure Stall Information
 ================================
index 97b0d79..95c93bb 100644 (file)
@@ -1,5 +1,5 @@
-Kernel Support for miscellaneous (your favourite) Binary Formats v1.1
-=====================================================================
+Kernel Support for miscellaneous Binary Formats (binfmt_misc)
+=============================================================
 
 This Kernel feature allows you to invoke almost (for restrictions see below)
 every program by simply typing its name in the shell.
index 27c77d8..a6fd1f9 100644 (file)
@@ -251,8 +251,6 @@ line of text and contains the following stats separated by whitespace:
 
  ================ =============================================================
  orig_data_size   uncompressed size of data stored in this disk.
-                 This excludes same-element-filled pages (same_pages) since
-                 no memory is allocated for them.
                   Unit: bytes
  compr_data_size  compressed size of data stored in this disk
  mem_used_total   the amount of memory allocated for this disk. This
index cf2edcd..d6b3b77 100644 (file)
@@ -23,7 +23,7 @@ of dot-connected-words, and key and value are connected by ``=``. The value
 has to be terminated by semi-colon (``;``) or newline (``\n``).
 For array value, array entries are separated by comma (``,``). ::
 
-KEY[.WORD[...]] = VALUE[, VALUE2[...]][;]
+  KEY[.WORD[...]] = VALUE[, VALUE2[...]][;]
 
 Unlike the kernel command line syntax, spaces are OK around the comma and ``=``.
 
index 10bf48b..226f644 100644 (file)
@@ -1,3 +1,5 @@
+.. _cgroup-v1:
+
 ========================
 Control Groups version 1
 ========================
index 3f80146..fbb1116 100644 (file)
@@ -9,7 +9,7 @@ This is the authoritative documentation on the design, interface and
 conventions of cgroup v2.  It describes all userland-visible aspects
 of cgroup including core and specific controller behaviors.  All
 future changes must be reflected in this document.  Documentation for
-v1 is available under Documentation/admin-guide/cgroup-v1/.
+v1 is available under :ref:`Documentation/admin-guide/cgroup-v1/index.rst <cgroup-v1>`.
 
 .. CONTENTS
 
@@ -1023,7 +1023,7 @@ All time durations are in microseconds.
        A read-only nested-key file which exists on non-root cgroups.
 
        Shows pressure stall information for CPU. See
-       Documentation/accounting/psi.rst for details.
+       :ref:`Documentation/accounting/psi.rst <psi>` for details.
 
   cpu.uclamp.min
         A read-write single value file which exists on non-root cgroups.
@@ -1103,7 +1103,7 @@ PAGE_SIZE multiple when read back.
        proportionally to the overage, reducing reclaim pressure for
        smaller overages.
 
-       Effective min boundary is limited by memory.min values of
+       Effective min boundary is limited by memory.min values of
        all ancestor cgroups. If there is memory.min overcommitment
        (child cgroup or cgroups are requiring more protected memory
        than parent will allow), then each child cgroup will get
@@ -1313,53 +1313,41 @@ PAGE_SIZE multiple when read back.
                Number of major page faults incurred
 
          workingset_refault
-
                Number of refaults of previously evicted pages
 
          workingset_activate
-
                Number of refaulted pages that were immediately activated
 
          workingset_nodereclaim
-
                Number of times a shadow node has been reclaimed
 
          pgrefill
-
                Amount of scanned pages (in an active LRU list)
 
          pgscan
-
                Amount of scanned pages (in an inactive LRU list)
 
          pgsteal
-
                Amount of reclaimed pages
 
          pgactivate
-
                Amount of pages moved to the active LRU list
 
          pgdeactivate
-
                Amount of pages moved to the inactive LRU list
 
          pglazyfree
-
                Amount of pages postponed to be freed under memory pressure
 
          pglazyfreed
-
                Amount of reclaimed lazyfree pages
 
          thp_fault_alloc
-
                Number of transparent hugepages which were allocated to satisfy
                a page fault, including COW faults. This counter is not present
                when CONFIG_TRANSPARENT_HUGEPAGE is not set.
 
          thp_collapse_alloc
-
                Number of transparent hugepages which were allocated to allow
                collapsing an existing range of pages. This counter is not
                present when CONFIG_TRANSPARENT_HUGEPAGE is not set.
@@ -1403,7 +1391,7 @@ PAGE_SIZE multiple when read back.
        A read-only nested-key file which exists on non-root cgroups.
 
        Shows pressure stall information for memory. See
-       Documentation/accounting/psi.rst for details.
+       :ref:`Documentation/accounting/psi.rst <psi>` for details.
 
 
 Usage Guidelines
@@ -1478,7 +1466,7 @@ IO Interface Files
          dios          Number of discard IOs
          ======        =====================
 
-       An example read output follows:
+       An example read output follows::
 
          8:16 rbytes=1459200 wbytes=314773504 rios=192 wios=353 dbytes=0 dios=0
          8:0 rbytes=90430464 wbytes=299008000 rios=8950 wios=1252 dbytes=50331648 dios=3021
@@ -1643,7 +1631,7 @@ IO Interface Files
        A read-only nested-key file which exists on non-root cgroups.
 
        Shows pressure stall information for IO. See
-       Documentation/accounting/psi.rst for details.
+       :ref:`Documentation/accounting/psi.rst <psi>` for details.
 
 
 Writeback
@@ -1853,7 +1841,7 @@ Cpuset Interface Files
        from the requested CPUs.
 
        The CPU numbers are comma-separated numbers or ranges.
-       For example:
+       For example::
 
          # cat cpuset.cpus
          0-4,6,8-10
@@ -1892,7 +1880,7 @@ Cpuset Interface Files
        from the requested memory nodes.
 
        The memory node numbers are comma-separated numbers or ranges.
-       For example:
+       For example::
 
          # cat cpuset.mems
          0-1,3
similarity index 98%
rename from Documentation/driver-api/edid.rst
rename to Documentation/admin-guide/edid.rst
index b1b5acd..80deeb2 100644 (file)
@@ -11,11 +11,13 @@ Today, with the advent of Kernel Mode Setting, a graphics board is
 either correctly working because all components follow the standards -
 or the computer is unusable, because the screen remains dark after
 booting or it displays the wrong area. Cases when this happens are:
+
 - The graphics board does not recognize the monitor.
 - The graphics board is unable to detect any EDID data.
 - The graphics board incorrectly forwards EDID data to the driver.
 - The monitor sends no or bogus EDID data.
 - A KVM sends its own EDID data instead of querying the connected monitor.
+
 Adding the kernel parameter "nomodeset" helps in most cases, but causes
 restrictions later on.
 
@@ -32,7 +34,7 @@ individual data for a specific misbehaving monitor, commented sources
 and a Makefile environment are given here.
 
 To create binary EDID and C source code files from the existing data
-material, simply type "make".
+material, simply type "make" in tools/edid/.
 
 If you want to create your own EDID file, copy the file 1024x768.S,
 replace the settings with your own data and add a new target to the
index af6865b..68d96f0 100644 (file)
@@ -136,8 +136,6 @@ enables the mitigation by default.
 The mitigation can be controlled at boot time via a kernel command line option.
 See :ref:`taa_mitigation_control_command_line`.
 
-.. _virt_mechanism:
-
 Virtualization mitigation
 ^^^^^^^^^^^^^^^^^^^^^^^^^
 
index f1d0ccf..5a6269f 100644 (file)
@@ -75,6 +75,7 @@ configure specific aspects of kernel behavior to your liking.
    cputopology
    dell_rbu
    device-mapper/index
+   edid
    efi-stub
    ext4
    nfs/index
index df5b834..9b14b0c 100644 (file)
@@ -100,7 +100,7 @@ Field 10 -- # of milliseconds spent doing I/Os (unsigned int)
 
     Since 5.0 this field counts jiffies when at least one request was
     started or completed. If request runs more than 2 jiffies then some
-    I/O time will not be accounted unless there are other requests.
+    I/O time might be not accounted in case of concurrent requests.
 
 Field 11 -- weighted # of milliseconds spent doing I/Os (unsigned int)
     This field is incremented at each I/O start, I/O completion, I/O
@@ -143,6 +143,9 @@ are summed (possibly overflowing the unsigned long variable they are
 summed to) and the result given to the user.  There is no convenient
 user interface for accessing the per-CPU counters themselves.
 
+Since 4.19 request times are measured with nanoseconds precision and
+truncated to milliseconds before showing in this interface.
+
 Disks vs Partitions
 -------------------
 
index c07815d..d7da466 100644 (file)
                        A valid base address must be provided, and the serial
                        port must already be setup and configured.
 
+               ec_imx21,<addr>
+               ec_imx6q,<addr>
+                       Start an early, polled-mode, output-only console on the
+                       Freescale i.MX UART at the specified address. The UART
+                       must already be setup and configured.
+
                ar3700_uart,<addr>
                        Start an early, polled-mode console on the
                        Armada 3700 serial port at the specified
                        provided by tboot because it makes the system
                        vulnerable to DMA attacks.
                nobounce [Default off]
-                       Disable bounce buffer for unstrusted devices such as
+                       Disable bounce buffer for untrusted devices such as
                        the Thunderbolt devices. This will treat the untrusted
                        devices as the trusted ones, hence might expose security
                        risks of DMA attacks.
                        No delay
 
        ip=             [IP_PNP]
-                       See Documentation/filesystems/nfs/nfsroot.txt.
+                       See Documentation/admin-guide/nfs/nfsroot.rst.
 
        ipcmni_extend   [KNL] Extend the maximum number of unique System V
                        IPC identifiers from 32,768 to 16,777,216.
                        <name>,<region-number>[,<base>,<size>,<buswidth>,<altbuswidth>]
 
        mtdparts=       [MTD]
-                       See drivers/mtd/cmdlinepart.c.
+                       See drivers/mtd/parsers/cmdlinepart.c
 
        multitce=off    [PPC]  This parameter disables the use of the pSeries
                        firmware feature for updating multiple TCE entries
                        Default value is 0.
 
        nfsaddrs=       [NFS] Deprecated.  Use ip= instead.
-                       See Documentation/filesystems/nfs/nfsroot.txt.
+                       See Documentation/admin-guide/nfs/nfsroot.rst.
 
        nfsroot=        [NFS] nfs root filesystem for disk-less boxes.
-                       See Documentation/filesystems/nfs/nfsroot.txt.
+                       See Documentation/admin-guide/nfs/nfsroot.rst.
 
        nfsrootdebug    [NFS] enable nfsroot debugging messages.
-                       See Documentation/filesystems/nfs/nfsroot.txt.
+                       See Documentation/admin-guide/nfs/nfsroot.rst.
 
        nfs.callback_nr_threads=
                        [NFSv4] set the total number of threads that the
                        Format: <integer>
 
                        A nonzero value instructs the soft-lockup detector
-                       to panic the machine when a soft-lockup occurs. This
-                       is also controlled by CONFIG_BOOTPARAM_SOFTLOCKUP_PANIC
-                       which is the respective build-time switch to that
-                       functionality.
+                       to panic the machine when a soft-lockup occurs. It is
+                       also controlled by the kernel.softlockup_panic sysctl
+                       and CONFIG_BOOTPARAM_SOFTLOCKUP_PANIC, which is the
+                       respective build-time switch to that functionality.
 
        softlockup_all_cpu_backtrace=
                        [KNL] Should the soft-lockup detector generate
index baeeba8..21818ac 100644 (file)
@@ -234,7 +234,7 @@ To reduce its OS jitter, do any of the following:
        Such a workqueue can be confined to a given subset of the
        CPUs using the ``/sys/devices/virtual/workqueue/*/cpumask`` sysfs
        files.  The set of WQ_SYSFS workqueues can be displayed using
-       "ls sys/devices/virtual/workqueue".  That said, the workqueues
+       "ls /sys/devices/virtual/workqueue".  That said, the workqueues
        maintainer would like to caution people against indiscriminately
        sprinkling WQ_SYSFS across all the workqueues.  The reason for
        caution is that it is easy to add WQ_SYSFS, but because sysfs is
index 3726a10..f05f56c 100644 (file)
@@ -43,7 +43,8 @@ value 1 for supported.
 
   AXI_ID and AXI_MASKING are mapped on DPCR1 register in performance counter.
   When non-masked bits are matching corresponding AXI_ID bits then counter is
-  incremented. Perf counter is incremented if
+  incremented. Perf counter is incremented if::
+
         AxID && AXI_MASKING == AXI_ID && AXI_MASKING
 
   This filter doesn't support filter different AXI ID for axid-read and axid-write
index def0748..335696d 100644 (file)
 Documentation for /proc/sys/kernel/
 ===================================
 
-kernel version 2.2.10
+.. See scripts/check-sysctl-docs to keep this up to date
+
 
 Copyright (c) 1998, 1999,  Rik van Riel <riel@nl.linux.org>
 
 Copyright (c) 2009,        Shen Feng<shen@cn.fujitsu.com>
 
-For general info and legal blurb, please look in index.rst.
+For general info and legal blurb, please look in :doc:`index`.
 
 ------------------------------------------------------------------------------
 
 This file contains documentation for the sysctl files in
-/proc/sys/kernel/ and is valid for Linux kernel version 2.2.
+``/proc/sys/kernel/`` and is valid for Linux kernel version 2.2.
 
 The files in this directory can be used to tune and monitor
 miscellaneous and general things in the operation of the Linux
-kernel. Since some of the files _can_ be used to screw up your
+kernel. Since some of the files *can* be used to screw up your
 system, it is advisable to read both documentation and source
 before actually making adjustments.
 
 Currently, these files might (depending on your configuration)
-show up in /proc/sys/kernel:
-
-- acct
-- acpi_video_flags
-- auto_msgmni
-- bootloader_type           [ X86 only ]
-- bootloader_version        [ X86 only ]
-- cap_last_cap
-- core_pattern
-- core_pipe_limit
-- core_uses_pid
-- ctrl-alt-del
-- dmesg_restrict
-- domainname
-- hostname
-- hotplug
-- hardlockup_all_cpu_backtrace
-- hardlockup_panic
-- hung_task_panic
-- hung_task_check_count
-- hung_task_timeout_secs
-- hung_task_check_interval_secs
-- hung_task_warnings
-- hyperv_record_panic_msg
-- kexec_load_disabled
-- kptr_restrict
-- l2cr                        [ PPC only ]
-- modprobe                    ==> Documentation/debugging-modules.txt
-- modules_disabled
-- msg_next_id                [ sysv ipc ]
-- msgmax
-- msgmnb
-- msgmni
-- nmi_watchdog
-- osrelease
-- ostype
-- overflowgid
-- overflowuid
-- panic
-- panic_on_oops
-- panic_on_stackoverflow
-- panic_on_unrecovered_nmi
-- panic_on_warn
-- panic_print
-- panic_on_rcu_stall
-- perf_cpu_time_max_percent
-- perf_event_paranoid
-- perf_event_max_stack
-- perf_event_mlock_kb
-- perf_event_max_contexts_per_stack
-- pid_max
-- powersave-nap               [ PPC only ]
-- printk
-- printk_delay
-- printk_ratelimit
-- printk_ratelimit_burst
-- pty                         ==> Documentation/filesystems/devpts.txt
-- randomize_va_space
-- real-root-dev               ==> Documentation/admin-guide/initrd.rst
-- reboot-cmd                  [ SPARC only ]
-- rtsig-max
-- rtsig-nr
-- sched_energy_aware
-- seccomp/                    ==> Documentation/userspace-api/seccomp_filter.rst
-- sem
-- sem_next_id                [ sysv ipc ]
-- sg-big-buff                 [ generic SCSI device (sg) ]
-- shm_next_id                [ sysv ipc ]
-- shm_rmid_forced
-- shmall
-- shmmax                      [ sysv ipc ]
-- shmmni
-- softlockup_all_cpu_backtrace
-- soft_watchdog
-- stack_erasing
-- stop-a                      [ SPARC only ]
-- sysrq                       ==> Documentation/admin-guide/sysrq.rst
-- sysctl_writes_strict
-- tainted                     ==> Documentation/admin-guide/tainted-kernels.rst
-- threads-max
-- unknown_nmi_panic
-- watchdog
-- watchdog_thresh
-- version
-
-
-acct:
-=====
+show up in ``/proc/sys/kernel``:
+
+.. contents:: :local:
+
+
+acct
+====
+
+::
 
-highwater lowwater frequency
+    highwater lowwater frequency
 
 If BSD-style process accounting is enabled these values control
 its behaviour. If free space on filesystem where the log lives
-goes below <lowwater>% accounting suspends. If free space gets
-above <highwater>% accounting resumes. <Frequency> determines
+goes below ``lowwater``% accounting suspends. If free space gets
+above ``highwater``% accounting resumes. ``frequency`` determines
 how often do we check the amount of free space (value is in
 seconds). Default:
-4 2 30
-That is, suspend accounting if there left <= 2% free; resume it
-if we got >=4%; consider information about amount of free space
-valid for 30 seconds.
 
+::
 
-acpi_video_flags:
-=================
+    4 2 30
+
+That is, suspend accounting if free space drops below 2%; resume it
+if it increases to at least 4%; consider information about amount of
+free space valid for 30 seconds.
 
-flags
 
-See Doc*/kernel/power/video.txt, it allows mode of video boot to be
-set during run time.
+acpi_video_flags
+================
 
+See :doc:`/power/video`. This allows the video resume mode to be set,
+in a similar fashion to the ``acpi_sleep`` kernel parameter, by
+combining the following values:
+
+= =======
+1 s3_bios
+2 s3_mode
+4 s3_beep
+= =======
 
-auto_msgmni:
-============
+
+auto_msgmni
+===========
 
 This variable has no effect and may be removed in future kernel
 releases. Reading it always returns 0.
-Up to Linux 3.17, it enabled/disabled automatic recomputing of msgmni
-upon memory add/remove or upon ipc namespace creation/removal.
+Up to Linux 3.17, it enabled/disabled automatic recomputing of
+`msgmni`_
+upon memory add/remove or upon IPC namespace creation/removal.
 Echoing "1" into this file enabled msgmni automatic recomputing.
-Echoing "0" turned it off. auto_msgmni default value was 1.
-
+Echoing "0" turned it off. The default value was 1.
 
-bootloader_type:
-================
 
-x86 bootloader identification
+bootloader_type (x86 only)
+==========================
 
 This gives the bootloader type number as indicated by the bootloader,
 shifted left by 4, and OR'd with the low four bits of the bootloader
 version.  The reason for this encoding is that this used to match the
-type_of_loader field in the kernel header; the encoding is kept for
+``type_of_loader`` field in the kernel header; the encoding is kept for
 backwards compatibility.  That is, if the full bootloader type number
 is 0x15 and the full version number is 0x234, this file will contain
 the value 340 = 0x154.
 
-See the type_of_loader and ext_loader_type fields in
-Documentation/x86/boot.rst for additional information.
-
+See the ``type_of_loader`` and ``ext_loader_type`` fields in
+:doc:`/x86/boot` for additional information.
 
-bootloader_version:
-===================
 
-x86 bootloader version
+bootloader_version (x86 only)
+=============================
 
 The complete bootloader version number.  In the example above, this
 file will contain the value 564 = 0x234.
 
-See the type_of_loader and ext_loader_ver fields in
-Documentation/x86/boot.rst for additional information.
+See the ``type_of_loader`` and ``ext_loader_ver`` fields in
+:doc:`/x86/boot` for additional information.
 
 
-cap_last_cap:
-=============
+cap_last_cap
+============
 
 Highest valid capability of the running kernel.  Exports
-CAP_LAST_CAP from the kernel.
+``CAP_LAST_CAP`` from the kernel.
 
 
-core_pattern:
-=============
+core_pattern
+============
 
-core_pattern is used to specify a core dumpfile pattern name.
+``core_pattern`` is used to specify a core dumpfile pattern name.
 
 * max length 127 characters; default value is "core"
-* core_pattern is used as a pattern template for the output filename;
-  certain string patterns (beginning with '%') are substituted with
-  their actual values.
-* backward compatibility with core_uses_pid:
+* ``core_pattern`` is used as a pattern template for the output
+  filename; certain string patterns (beginning with '%') are
+  substituted with their actual values.
+* backward compatibility with ``core_uses_pid``:
 
-       If core_pattern does not include "%p" (default does not)
-       and core_uses_pid is set, then .PID will be appended to
+       If ``core_pattern`` does not include "%p" (default does not)
+       and ``core_uses_pid`` is set, then .PID will be appended to
        the filename.
 
-* corename format specifiers::
-
-       %<NUL>  '%' is dropped
-       %%      output one '%'
-       %p      pid
-       %P      global pid (init PID namespace)
-       %i      tid
-       %I      global tid (init PID namespace)
-       %u      uid (in initial user namespace)
-       %g      gid (in initial user namespace)
-       %d      dump mode, matches PR_SET_DUMPABLE and
-               /proc/sys/fs/suid_dumpable
-       %s      signal number
-       %t      UNIX time of dump
-       %h      hostname
-       %e      executable filename (may be shortened)
-       %E      executable path
-       %<OTHER> both are dropped
+* corename format specifiers
+
+       ========        ==========================================
+       %<NUL>          '%' is dropped
+       %%              output one '%'
+       %p              pid
+       %P              global pid (init PID namespace)
+       %i              tid
+       %I              global tid (init PID namespace)
+       %u              uid (in initial user namespace)
+       %g              gid (in initial user namespace)
+       %d              dump mode, matches ``PR_SET_DUMPABLE`` and
+                       ``/proc/sys/fs/suid_dumpable``
+       %s              signal number
+       %t              UNIX time of dump
+       %h              hostname
+       %e              executable filename (may be shortened)
+       %E              executable path
+       %c              maximum size of core file by resource limit RLIMIT_CORE
+       %<OTHER>        both are dropped
+       ========        ==========================================
 
 * If the first character of the pattern is a '|', the kernel will treat
   the rest of the pattern as a command to run.  The core dump will be
   written to the standard input of that program instead of to a file.
 
 
-core_pipe_limit:
-================
+core_pipe_limit
+===============
 
-This sysctl is only applicable when core_pattern is configured to pipe
-core files to a user space helper (when the first character of
-core_pattern is a '|', see above).  When collecting cores via a pipe
-to an application, it is occasionally useful for the collecting
-application to gather data about the crashing process from its
-/proc/pid directory.  In order to do this safely, the kernel must wait
-for the collecting process to exit, so as not to remove the crashing
-processes proc files prematurely.  This in turn creates the
-possibility that a misbehaving userspace collecting process can block
-the reaping of a crashed process simply by never exiting.  This sysctl
-defends against that.  It defines how many concurrent crashing
-processes may be piped to user space applications in parallel.  If
-this value is exceeded, then those crashing processes above that value
-are noted via the kernel log and their cores are skipped.  0 is a
-special value, indicating that unlimited processes may be captured in
-parallel, but that no waiting will take place (i.e. the collecting
-process is not guaranteed access to /proc/<crashing pid>/).  This
-value defaults to 0.
-
-
-core_uses_pid:
-==============
+This sysctl is only applicable when `core_pattern`_ is configured to
+pipe core files to a user space helper (when the first character of
+``core_pattern`` is a '|', see above).
+When collecting cores via a pipe to an application, it is occasionally
+useful for the collecting application to gather data about the
+crashing process from its ``/proc/pid`` directory.
+In order to do this safely, the kernel must wait for the collecting
+process to exit, so as not to remove the crashing processes proc files
+prematurely.
+This in turn creates the possibility that a misbehaving userspace
+collecting process can block the reaping of a crashed process simply
+by never exiting.
+This sysctl defends against that.
+It defines how many concurrent crashing processes may be piped to user
+space applications in parallel.
+If this value is exceeded, then those crashing processes above that
+value are noted via the kernel log and their cores are skipped.
+0 is a special value, indicating that unlimited processes may be
+captured in parallel, but that no waiting will take place (i.e. the
+collecting process is not guaranteed access to ``/proc/<crashing
+pid>/``).
+This value defaults to 0.
+
+
+core_uses_pid
+=============
 
 The default coredump filename is "core".  By setting
-core_uses_pid to 1, the coredump filename becomes core.PID.
-If core_pattern does not include "%p" (default does not)
-and core_uses_pid is set, then .PID will be appended to
+``core_uses_pid`` to 1, the coredump filename becomes core.PID.
+If `core_pattern`_ does not include "%p" (default does not)
+and ``core_uses_pid`` is set, then .PID will be appended to
 the filename.
 
 
-ctrl-alt-del:
-=============
+ctrl-alt-del
+============
 
 When the value in this file is 0, ctrl-alt-del is trapped and
-sent to the init(1) program to handle a graceful restart.
+sent to the ``init(1)`` program to handle a graceful restart.
 When, however, the value is > 0, Linux's reaction to a Vulcan
 Nerve Pinch (tm) will be an immediate reboot, without even
 syncing its dirty buffers.
@@ -269,21 +204,22 @@ Note:
   to decide what to do with it.
 
 
-dmesg_restrict:
-===============
+dmesg_restrict
+==============
 
 This toggle indicates whether unprivileged users are prevented
-from using dmesg(8) to view messages from the kernel's log buffer.
-When dmesg_restrict is set to (0) there are no restrictions. When
-dmesg_restrict is set set to (1), users must have CAP_SYSLOG to use
-dmesg(8).
+from using ``dmesg(8)`` to view messages from the kernel's log
+buffer.
+When ``dmesg_restrict`` is set to 0 there are no restrictions.
+When ``dmesg_restrict`` is set set to 1, users must have
+``CAP_SYSLOG`` to use ``dmesg(8)``.
 
-The kernel config option CONFIG_SECURITY_DMESG_RESTRICT sets the
-default value of dmesg_restrict.
+The kernel config option ``CONFIG_SECURITY_DMESG_RESTRICT`` sets the
+default value of ``dmesg_restrict``.
 
 
-domainname & hostname:
-======================
+domainname & hostname
+=====================
 
 These files can be used to set the NIS/YP domainname and the
 hostname of your box in exactly the same way as the commands
@@ -302,167 +238,206 @@ hostname "darkstar" and DNS (Internet Domain Name Server)
 domainname "frop.org", not to be confused with the NIS (Network
 Information Service) or YP (Yellow Pages) domainname. These two
 domain names are in general different. For a detailed discussion
-see the hostname(1) man page.
+see the ``hostname(1)`` man page.
 
 
-hardlockup_all_cpu_backtrace:
-=============================
+hardlockup_all_cpu_backtrace
+============================
 
 This value controls the hard lockup detector behavior when a hard
 lockup condition is detected as to whether or not to gather further
 debug information. If enabled, arch-specific all-CPU stack dumping
 will be initiated.
 
-0: do nothing. This is the default behavior.
-
-1: on detection capture more debug information.
+= ============================================
+0 Do nothing. This is the default behavior.
+1 On detection capture more debug information.
+= ============================================
 
 
-hardlockup_panic:
-=================
+hardlockup_panic
+================
 
 This parameter can be used to control whether the kernel panics
 when a hard lockup is detected.
 
-   0 - don't panic on hard lockup
-   1 - panic on hard lockup
+= ===========================
+0 Don't panic on hard lockup.
+1 Panic on hard lockup.
+= ===========================
 
-See Documentation/admin-guide/lockup-watchdogs.rst for more information.  This can
-also be set using the nmi_watchdog kernel parameter.
+See :doc:`/admin-guide/lockup-watchdogs` for more information.
+This can also be set using the nmi_watchdog kernel parameter.
 
 
-hotplug:
-========
+hotplug
+=======
 
 Path for the hotplug policy agent.
-Default value is "/sbin/hotplug".
+Default value is "``/sbin/hotplug``".
 
 
-hung_task_panic:
-================
+hung_task_panic
+===============
 
 Controls the kernel's behavior when a hung task is detected.
-This file shows up if CONFIG_DETECT_HUNG_TASK is enabled.
-
-0: continue operation. This is the default behavior.
+This file shows up if ``CONFIG_DETECT_HUNG_TASK`` is enabled.
 
-1: panic immediately.
+= =================================================
+0 Continue operation. This is the default behavior.
+1 Panic immediately.
+= =================================================
 
 
-hung_task_check_count:
-======================
+hung_task_check_count
+=====================
 
 The upper bound on the number of tasks that are checked.
-This file shows up if CONFIG_DETECT_HUNG_TASK is enabled.
+This file shows up if ``CONFIG_DETECT_HUNG_TASK`` is enabled.
 
 
-hung_task_timeout_secs:
-=======================
+hung_task_timeout_secs
+======================
 
 When a task in D state did not get scheduled
 for more than this value report a warning.
-This file shows up if CONFIG_DETECT_HUNG_TASK is enabled.
+This file shows up if ``CONFIG_DETECT_HUNG_TASK`` is enabled.
 
-0: means infinite timeout - no checking done.
+0 means infinite timeout, no checking is done.
 
-Possible values to set are in range {0..LONG_MAX/HZ}.
+Possible values to set are in range {0:``LONG_MAX``/``HZ``}.
 
 
-hung_task_check_interval_secs:
-==============================
+hung_task_check_interval_secs
+=============================
 
 Hung task check interval. If hung task checking is enabled
-(see hung_task_timeout_secs), the check is done every
-hung_task_check_interval_secs seconds.
-This file shows up if CONFIG_DETECT_HUNG_TASK is enabled.
+(see `hung_task_timeout_secs`_), the check is done every
+``hung_task_check_interval_secs`` seconds.
+This file shows up if ``CONFIG_DETECT_HUNG_TASK`` is enabled.
 
-0 (default): means use hung_task_timeout_secs as checking interval.
-Possible values to set are in range {0..LONG_MAX/HZ}.
+0 (default) means use ``hung_task_timeout_secs`` as checking
+interval.
 
+Possible values to set are in range {0:``LONG_MAX``/``HZ``}.
 
-hung_task_warnings:
-===================
+
+hung_task_warnings
+==================
 
 The maximum number of warnings to report. During a check interval
 if a hung task is detected, this value is decreased by 1.
 When this value reaches 0, no more warnings will be reported.
-This file shows up if CONFIG_DETECT_HUNG_TASK is enabled.
+This file shows up if ``CONFIG_DETECT_HUNG_TASK`` is enabled.
 
 -1: report an infinite number of warnings.
 
 
-hyperv_record_panic_msg:
-========================
+hyperv_record_panic_msg
+=======================
 
 Controls whether the panic kmsg data should be reported to Hyper-V.
 
-0: do not report panic kmsg data.
+= =========================================================
+0 Do not report panic kmsg data.
+1 Report the panic kmsg data. This is the default behavior.
+= =========================================================
 
-1: report the panic kmsg data. This is the default behavior.
 
+kexec_load_disabled
+===================
 
-kexec_load_disabled:
-====================
-
-A toggle indicating if the kexec_load syscall has been disabled. This
-value defaults to 0 (false: kexec_load enabled), but can be set to 1
-(true: kexec_load disabled). Once true, kexec can no longer be used, and
-the toggle cannot be set back to false. This allows a kexec image to be
-loaded before disabling the syscall, allowing a system to set up (and
-later use) an image without it being altered. Generally used together
-with the "modules_disabled" sysctl.
+A toggle indicating if the ``kexec_load`` syscall has been disabled.
+This value defaults to 0 (false: ``kexec_load`` enabled), but can be
+set to 1 (true: ``kexec_load`` disabled).
+Once true, kexec can no longer be used, and the toggle cannot be set
+back to false.
+This allows a kexec image to be loaded before disabling the syscall,
+allowing a system to set up (and later use) an image without it being
+altered.
+Generally used together with the `modules_disabled`_ sysctl.
 
 
-kptr_restrict:
-==============
+kptr_restrict
+=============
 
 This toggle indicates whether restrictions are placed on
-exposing kernel addresses via /proc and other interfaces.
+exposing kernel addresses via ``/proc`` and other interfaces.
+
+When ``kptr_restrict`` is set to 0 (the default) the address is hashed
+before printing.
+(This is the equivalent to %p.)
+
+When ``kptr_restrict`` is set to 1, kernel pointers printed using the
+%pK format specifier will be replaced with 0s unless the user has
+``CAP_SYSLOG`` and effective user and group ids are equal to the real
+ids.
+This is because %pK checks are done at read() time rather than open()
+time, so if permissions are elevated between the open() and the read()
+(e.g via a setuid binary) then %pK will not leak kernel pointers to
+unprivileged users.
+Note, this is a temporary solution only.
+The correct long-term solution is to do the permission checks at
+open() time.
+Consider removing world read permissions from files that use %pK, and
+using `dmesg_restrict`_ to protect against uses of %pK in ``dmesg(8)``
+if leaking kernel pointer values to unprivileged users is a concern.
+
+When ``kptr_restrict`` is set to 2, kernel pointers printed using
+%pK will be replaced with 0s regardless of privileges.
+
+
+modprobe
+========
 
-When kptr_restrict is set to 0 (the default) the address is hashed before
-printing. (This is the equivalent to %p.)
+This gives the full path of the modprobe command which the kernel will
+use to load modules. This can be used to debug module loading
+requests::
 
-When kptr_restrict is set to (1), kernel pointers printed using the %pK
-format specifier will be replaced with 0's unless the user has CAP_SYSLOG
-and effective user and group ids are equal to the real ids. This is
-because %pK checks are done at read() time rather than open() time, so
-if permissions are elevated between the open() and the read() (e.g via
-a setuid binary) then %pK will not leak kernel pointers to unprivileged
-users. Note, this is a temporary solution only. The correct long-term
-solution is to do the permission checks at open() time. Consider removing
-world read permissions from files that use %pK, and using dmesg_restrict
-to protect against uses of %pK in dmesg(8) if leaking kernel pointer
-values to unprivileged users is a concern.
+    echo '#! /bin/sh' > /tmp/modprobe
+    echo 'echo "$@" >> /tmp/modprobe.log' >> /tmp/modprobe
+    echo 'exec /sbin/modprobe "$@"' >> /tmp/modprobe
+    chmod a+x /tmp/modprobe
+    echo /tmp/modprobe > /proc/sys/kernel/modprobe
 
-When kptr_restrict is set to (2), kernel pointers printed using
-%pK will be replaced with 0's regardless of privileges.
+This only applies when the *kernel* is requesting that the module be
+loaded; it won't have any effect if the module is being loaded
+explicitly using ``modprobe`` from userspace.
 
 
-l2cr: (PPC only)
+modules_disabled
 ================
 
-This flag controls the L2 cache of G3 processor boards. If
-0, the cache is disabled. Enabled if nonzero.
-
-
-modules_disabled:
-=================
-
 A toggle value indicating if modules are allowed to be loaded
 in an otherwise modular kernel.  This toggle defaults to off
 (0), but can be set true (1).  Once true, modules can be
 neither loaded nor unloaded, and the toggle cannot be set back
-to false.  Generally used with the "kexec_load_disabled" toggle.
+to false.  Generally used with the `kexec_load_disabled`_ toggle.
+
+
+.. _msgmni:
+
+msgmax, msgmnb, and msgmni
+==========================
+
+``msgmax`` is the maximum size of an IPC message, in bytes. 8192 by
+default (``MSGMAX``).
 
+``msgmnb`` is the maximum size of an IPC queue, in bytes. 16384 by
+default (``MSGMNB``).
 
-msg_next_id, sem_next_id, and shm_next_id:
-==========================================
+``msgmni`` is the maximum number of IPC queues. 32000 by default
+(``MSGMNI``).
+
+
+msg_next_id, sem_next_id, and shm_next_id (System V IPC)
+========================================================
 
 These three toggles allows to specify desired id for next allocated IPC
 object: message, semaphore or shared memory respectively.
 
 By default they are equal to -1, which means generic allocation logic.
-Possible values to set are in range {0..INT_MAX}.
+Possible values to set are in range {0:``INT_MAX``}.
 
 Notes:
   1) kernel doesn't guarantee, that new object will have desired id. So,
@@ -472,15 +447,16 @@ Notes:
      fails, it is undefined if the value remains unmodified or is reset to -1.
 
 
-nmi_watchdog:
-=============
+nmi_watchdog
+============
 
 This parameter can be used to control the NMI watchdog
 (i.e. the hard lockup detector) on x86 systems.
 
-0 - disable the hard lockup detector
-
-1 - enable the hard lockup detector
+= =================================
+0 Disable the hard lockup detector.
+1 Enable the hard lockup detector.
+= =================================
 
 The hard lockup detector monitors each CPU for its ability to respond to
 timer interrupts. The mechanism utilizes CPU performance counter registers
@@ -492,11 +468,11 @@ in a KVM virtual machine. This default can be overridden by adding::
 
    nmi_watchdog=1
 
-to the guest kernel command line (see Documentation/admin-guide/kernel-parameters.rst).
+to the guest kernel command line (see :doc:`/admin-guide/kernel-parameters`).
 
 
-numa_balancing:
-===============
+numa_balancing
+==============
 
 Enables/disables automatic page fault based NUMA memory
 balancing. Memory is moved automatically to nodes
@@ -514,9 +490,10 @@ ideally is offset by improved memory locality but there is no universal
 guarantee. If the target workload is already bound to NUMA nodes then this
 feature should be disabled. Otherwise, if the system overhead from the
 feature is too high then the rate the kernel samples for NUMA hinting
-faults may be controlled by the numa_balancing_scan_period_min_ms,
+faults may be controlled by the `numa_balancing_scan_period_min_ms,
 numa_balancing_scan_delay_ms, numa_balancing_scan_period_max_ms,
-numa_balancing_scan_size_mb, and numa_balancing_settle_count sysctls.
+numa_balancing_scan_size_mb`_, and numa_balancing_settle_count sysctls.
+
 
 numa_balancing_scan_period_min_ms, numa_balancing_scan_delay_ms, numa_balancing_scan_period_max_ms, numa_balancing_scan_size_mb
 ===============================================================================================================================
@@ -542,23 +519,23 @@ workload pattern changes and minimises performance impact due to remote
 memory accesses. These sysctls control the thresholds for scan delays and
 the number of pages scanned.
 
-numa_balancing_scan_period_min_ms is the minimum time in milliseconds to
+``numa_balancing_scan_period_min_ms`` is the minimum time in milliseconds to
 scan a tasks virtual memory. It effectively controls the maximum scanning
 rate for each task.
 
-numa_balancing_scan_delay_ms is the starting "scan delay" used for a task
+``numa_balancing_scan_delay_ms`` is the starting "scan delay" used for a task
 when it initially forks.
 
-numa_balancing_scan_period_max_ms is the maximum time in milliseconds to
+``numa_balancing_scan_period_max_ms`` is the maximum time in milliseconds to
 scan a tasks virtual memory. It effectively controls the minimum scanning
 rate for each task.
 
-numa_balancing_scan_size_mb is how many megabytes worth of pages are
+``numa_balancing_scan_size_mb`` is how many megabytes worth of pages are
 scanned for a given scan.
 
 
-osrelease, ostype & version:
-============================
+osrelease, ostype & version
+===========================
 
 ::
 
@@ -569,15 +546,16 @@ osrelease, ostype & version:
   # cat version
   #5 Wed Feb 25 21:49:24 MET 1998
 
-The files osrelease and ostype should be clear enough. Version
+The files ``osrelease`` and ``ostype`` should be clear enough.
+``version``
 needs a little more clarification however. The '#5' means that
 this is the fifth kernel built from this source base and the
 date behind it indicates the time the kernel was built.
 The only way to tune these values is to rebuild the kernel :-)
 
 
-overflowgid & overflowuid:
-==========================
+overflowgid & overflowuid
+=========================
 
 if your architecture did not always support 32-bit UIDs (i.e. arm,
 i386, m68k, sh, and sparc32), a fixed UID and GID will be returned to
@@ -588,108 +566,119 @@ These sysctls allow you to change the value of the fixed UID and GID.
 The default is 65534.
 
 
+panic
+=====
+
+The value in this file determines the behaviour of the kernel on a
 panic:
-======
 
-The value in this file represents the number of seconds the kernel
-waits before rebooting on a panic. When you use the software watchdog,
-the recommended setting is 60.
+* if zero, the kernel will loop forever;
+* if negative, the kernel will reboot immediately;
+* if positive, the kernel will reboot after the corresponding number
+  of seconds.
 
+When you use the software watchdog, the recommended setting is 60.
 
-panic_on_io_nmi:
-================
+
+panic_on_io_nmi
+===============
 
 Controls the kernel's behavior when a CPU receives an NMI caused by
 an IO error.
 
-0: try to continue operation (default)
-
-1: panic immediately. The IO error triggered an NMI. This indicates a
-   serious system condition which could result in IO data corruption.
-   Rather than continuing, panicking might be a better choice. Some
-   servers issue this sort of NMI when the dump button is pushed,
-   and you can use this option to take a crash dump.
+= ==================================================================
+0 Try to continue operation (default).
+1 Panic immediately. The IO error triggered an NMI. This indicates a
+  serious system condition which could result in IO data corruption.
+  Rather than continuing, panicking might be a better choice. Some
+  servers issue this sort of NMI when the dump button is pushed,
+  and you can use this option to take a crash dump.
+= ==================================================================
 
 
-panic_on_oops:
-==============
+panic_on_oops
+=============
 
 Controls the kernel's behaviour when an oops or BUG is encountered.
 
-0: try to continue operation
-
-1: panic immediately.  If the `panic` sysctl is also non-zero then the
-   machine will be rebooted.
+= ===================================================================
+0 Try to continue operation.
+1 Panic immediately.  If the `panic` sysctl is also non-zero then the
+  machine will be rebooted.
+= ===================================================================
 
 
-panic_on_stackoverflow:
-=======================
+panic_on_stackoverflow
+======================
 
 Controls the kernel's behavior when detecting the overflows of
 kernel, IRQ and exception stacks except a user stack.
-This file shows up if CONFIG_DEBUG_STACKOVERFLOW is enabled.
-
-0: try to continue operation.
+This file shows up if ``CONFIG_DEBUG_STACKOVERFLOW`` is enabled.
 
-1: panic immediately.
+= ==========================
+0 Try to continue operation.
+1 Panic immediately.
+= ==========================
 
 
-panic_on_unrecovered_nmi:
-=========================
+panic_on_unrecovered_nmi
+========================
 
 The default Linux behaviour on an NMI of either memory or unknown is
 to continue operation. For many environments such as scientific
 computing it is preferable that the box is taken out and the error
 dealt with than an uncorrected parity/ECC error get propagated.
 
-A small number of systems do generate NMI's for bizarre random reasons
+A small number of systems do generate NMIs for bizarre random reasons
 such as power management so the default is off. That sysctl works like
 the existing panic controls already in that directory.
 
 
-panic_on_warn:
-==============
+panic_on_warn
+=============
 
 Calls panic() in the WARN() path when set to 1.  This is useful to avoid
 a kernel rebuild when attempting to kdump at the location of a WARN().
 
-0: only WARN(), default behaviour.
-
-1: call panic() after printing out WARN() location.
+= ================================================
+0 Only WARN(), default behaviour.
+1 Call panic() after printing out WARN() location.
+= ================================================
 
 
-panic_print:
-============
+panic_print
+===========
 
 Bitmask for printing system info when panic happens. User can chose
 combination of the following bits:
 
-=====  ========================================
+=====  ============================================
 bit 0  print all tasks info
 bit 1  print system memory info
 bit 2  print timer info
-bit 3  print locks info if CONFIG_LOCKDEP is on
+bit 3  print locks info if ``CONFIG_LOCKDEP`` is on
 bit 4  print ftrace buffer
-=====  ========================================
+=====  ============================================
 
 So for example to print tasks and memory info on panic, user can::
 
   echo 3 > /proc/sys/kernel/panic_print
 
 
-panic_on_rcu_stall:
-===================
+panic_on_rcu_stall
+==================
 
 When set to 1, calls panic() after RCU stall detection messages. This
 is useful to define the root cause of RCU stalls using a vmcore.
 
-0: do not panic() when RCU stall takes place, default behavior.
+= ============================================================
+0 Do not panic() when RCU stall takes place, default behavior.
+1 panic() after printing RCU stall messages.
+= ============================================================
 
-1: panic() after printing RCU stall messages.
 
-
-perf_cpu_time_max_percent:
-==========================
+perf_cpu_time_max_percent
+=========================
 
 Hints to the kernel how much CPU time it should be allowed to
 use to handle perf sampling events.  If the perf subsystem
@@ -702,171 +691,179 @@ unexpectedly take too long to execute, the NMIs can become
 stacked up next to each other so much that nothing else is
 allowed to execute.
 
-0:
-   disable the mechanism.  Do not monitor or correct perf's
-   sampling rate no matter how CPU time it takes.
+===== ========================================================
+0     Disable the mechanism.  Do not monitor or correct perf's
+      sampling rate no matter how CPU time it takes.
 
-1-100:
-   attempt to throttle perf's sample rate to this
-   percentage of CPU.  Note: the kernel calculates an
-   "expected" length of each sample event.  100 here means
-   100% of that expected length.  Even if this is set to
-   100, you may still see sample throttling if this
-   length is exceeded.  Set to 0 if you truly do not care
-   how much CPU is consumed.
+1-100 Attempt to throttle perf's sample rate to this
+      percentage of CPU.  Note: the kernel calculates an
+      "expected" length of each sample event.  100 here means
+      100% of that expected length.  Even if this is set to
+      100, you may still see sample throttling if this
+      length is exceeded.  Set to 0 if you truly do not care
+      how much CPU is consumed.
+===== ========================================================
 
 
-perf_event_paranoid:
-====================
+perf_event_paranoid
+===================
 
 Controls use of the performance events system by unprivileged
 users (without CAP_SYS_ADMIN).  The default value is 2.
 
 ===  ==================================================================
- -1  Allow use of (almost) all events by all users
+ -1  Allow use of (almost) all events by all users.
 
-     Ignore mlock limit after perf_event_mlock_kb without CAP_IPC_LOCK
+     Ignore mlock limit after perf_event_mlock_kb without
+     ``CAP_IPC_LOCK``.
 
->=0  Disallow ftrace function tracepoint by users without CAP_SYS_ADMIN
+>=0  Disallow ftrace function tracepoint by users without
+     ``CAP_SYS_ADMIN``.
 
-     Disallow raw tracepoint access by users without CAP_SYS_ADMIN
+     Disallow raw tracepoint access by users without ``CAP_SYS_ADMIN``.
 
->=1  Disallow CPU event access by users without CAP_SYS_ADMIN
+>=1  Disallow CPU event access by users without ``CAP_SYS_ADMIN``.
 
->=2  Disallow kernel profiling by users without CAP_SYS_ADMIN
+>=2  Disallow kernel profiling by users without ``CAP_SYS_ADMIN``.
 ===  ==================================================================
 
 
-perf_event_max_stack:
-=====================
+perf_event_max_stack
+====================
 
-Controls maximum number of stack frames to copy for (attr.sample_type &
-PERF_SAMPLE_CALLCHAIN) configured events, for instance, when using
-'perf record -g' or 'perf trace --call-graph fp'.
+Controls maximum number of stack frames to copy for (``attr.sample_type &
+PERF_SAMPLE_CALLCHAIN``) configured events, for instance, when using
+'``perf record -g``' or '``perf trace --call-graph fp``'.
 
 This can only be done when no events are in use that have callchains
-enabled, otherwise writing to this file will return -EBUSY.
+enabled, otherwise writing to this file will return ``-EBUSY``.
 
 The default value is 127.
 
 
-perf_event_mlock_kb:
-====================
+perf_event_mlock_kb
+===================
 
 Control size of per-cpu ring buffer not counted agains mlock limit.
 
 The default value is 512 + 1 page
 
 
-perf_event_max_contexts_per_stack:
-==================================
+perf_event_max_contexts_per_stack
+=================================
 
 Controls maximum number of stack frame context entries for
-(attr.sample_type & PERF_SAMPLE_CALLCHAIN) configured events, for
-instance, when using 'perf record -g' or 'perf trace --call-graph fp'.
+(``attr.sample_type & PERF_SAMPLE_CALLCHAIN``) configured events, for
+instance, when using '``perf record -g``' or '``perf trace --call-graph fp``'.
 
 This can only be done when no events are in use that have callchains
-enabled, otherwise writing to this file will return -EBUSY.
+enabled, otherwise writing to this file will return ``-EBUSY``.
 
 The default value is 8.
 
 
-pid_max:
-========
+pid_max
+=======
 
 PID allocation wrap value.  When the kernel's next PID value
 reaches this value, it wraps back to a minimum PID value.
-PIDs of value pid_max or larger are not allocated.
+PIDs of value ``pid_max`` or larger are not allocated.
 
 
-ns_last_pid:
-============
+ns_last_pid
+===========
 
 The last pid allocated in the current (the one task using this sysctl
 lives in) pid namespace. When selecting a pid for a next task on fork
 kernel tries to allocate a number starting from this one.
 
 
-powersave-nap: (PPC only)
-=========================
+powersave-nap (PPC only)
+========================
 
 If set, Linux-PPC will use the 'nap' mode of powersaving,
 otherwise the 'doze' mode will be used.
 
+
 ==============================================================
 
-printk:
-=======
+printk
+======
 
-The four values in printk denote: console_loglevel,
-default_message_loglevel, minimum_console_loglevel and
-default_console_loglevel respectively.
+The four values in printk denote: ``console_loglevel``,
+``default_message_loglevel``, ``minimum_console_loglevel`` and
+``default_console_loglevel`` respectively.
 
 These values influence printk() behavior when printing or
-logging error messages. See 'man 2 syslog' for more info on
+logging error messages. See '``man 2 syslog``' for more info on
 the different loglevels.
 
-- console_loglevel:
-       messages with a higher priority than
-       this will be printed to the console
-- default_message_loglevel:
-       messages without an explicit priority
-       will be printed with this priority
-- minimum_console_loglevel:
-       minimum (highest) value to which
-       console_loglevel can be set
-- default_console_loglevel:
-       default value for console_loglevel
+======================== =====================================
+console_loglevel         messages with a higher priority than
+                         this will be printed to the console
+default_message_loglevel messages without an explicit priority
+                         will be printed with this priority
+minimum_console_loglevel minimum (highest) value to which
+                         console_loglevel can be set
+default_console_loglevel default value for console_loglevel
+======================== =====================================
 
 
-printk_delay:
-=============
+printk_delay
+============
 
-Delay each printk message in printk_delay milliseconds
+Delay each printk message in ``printk_delay`` milliseconds
 
 Value from 0 - 10000 is allowed.
 
 
-printk_ratelimit:
-=================
+printk_ratelimit
+================
 
-Some warning messages are rate limited. printk_ratelimit specifies
+Some warning messages are rate limited. ``printk_ratelimit`` specifies
 the minimum length of time between these messages (in seconds).
 The default value is 5 seconds.
 
 A value of 0 will disable rate limiting.
 
 
-printk_ratelimit_burst:
-=======================
+printk_ratelimit_burst
+======================
 
-While long term we enforce one message per printk_ratelimit
+While long term we enforce one message per `printk_ratelimit`_
 seconds, we do allow a burst of messages to pass through.
-printk_ratelimit_burst specifies the number of messages we can
+``printk_ratelimit_burst`` specifies the number of messages we can
 send before ratelimiting kicks in.
 
 The default value is 10 messages.
 
 
-printk_devkmsg:
-===============
-
-Control the logging to /dev/kmsg from userspace:
-
-ratelimit:
-       default, ratelimited
+printk_devkmsg
+==============
 
-on: unlimited logging to /dev/kmsg from userspace
+Control the logging to ``/dev/kmsg`` from userspace:
 
-off: logging to /dev/kmsg disabled
+========= =============================================
+ratelimit default, ratelimited
+on        unlimited logging to /dev/kmsg from userspace
+off       logging to /dev/kmsg disabled
+========= =============================================
 
-The kernel command line parameter printk.devkmsg= overrides this and is
+The kernel command line parameter ``printk.devkmsg=`` overrides this and is
 a one-time setting until next reboot: once set, it cannot be changed by
 this sysctl interface anymore.
 
+==============================================================
 
-randomize_va_space:
-===================
+
+pty
+===
+
+See Documentation/filesystems/devpts.txt.
+
+
+randomize_va_space
+==================
 
 This option can be used to select the type of process address
 space randomization that is used in the system, for architectures
@@ -881,10 +878,10 @@ that support this feature.
     This, among other things, implies that shared libraries will be
     loaded to random addresses.  Also for PIE-linked binaries, the
     location of code start is randomized.  This is the default if the
-    CONFIG_COMPAT_BRK option is enabled.
+    ``CONFIG_COMPAT_BRK`` option is enabled.
 
 2   Additionally enable heap randomization.  This is the default if
-    CONFIG_COMPAT_BRK is disabled.
+    ``CONFIG_COMPAT_BRK`` is disabled.
 
     There are a few legacy applications out there (such as some ancient
     versions of libc.so.5 from 1996) that assume that brk area starts
@@ -894,31 +891,27 @@ that support this feature.
     systems it is safe to choose full randomization.
 
     Systems with ancient and/or broken binaries should be configured
-    with CONFIG_COMPAT_BRK enabled, which excludes the heap from process
+    with ``CONFIG_COMPAT_BRK`` enabled, which excludes the heap from process
     address space randomization.
 ==  ===========================================================================
 
 
-reboot-cmd: (Sparc only)
-========================
-
-??? This seems to be a way to give an argument to the Sparc
-ROM/Flash boot loader. Maybe to tell it what to do after
-rebooting. ???
+real-root-dev
+=============
 
+See :doc:`/admin-guide/initrd`.
 
-rtsig-max & rtsig-nr:
-=====================
 
-The file rtsig-max can be used to tune the maximum number
-of POSIX realtime (queued) signals that can be outstanding
-in the system.
+reboot-cmd (SPARC only)
+=======================
 
-rtsig-nr shows the number of RT signals currently queued.
+??? This seems to be a way to give an argument to the Sparc
+ROM/Flash boot loader. Maybe to tell it what to do after
+rebooting. ???
 
 
-sched_energy_aware:
-===================
+sched_energy_aware
+==================
 
 Enables/disables Energy Aware Scheduling (EAS). EAS starts
 automatically on platforms where it can run (that is,
@@ -928,75 +921,88 @@ requirements for EAS but you do not want to use it, change
 this value to 0.
 
 
-sched_schedstats:
-=================
+sched_schedstats
+================
 
 Enables/disables scheduler statistics. Enabling this feature
 incurs a small amount of overhead in the scheduler but is
 useful for debugging and performance tuning.
 
 
-sg-big-buff:
-============
+seccomp
+=======
+
+See :doc:`/userspace-api/seccomp_filter`.
+
+
+sg-big-buff
+===========
 
 This file shows the size of the generic SCSI (sg) buffer.
 You can't tune it just yet, but you could change it on
-compile time by editing include/scsi/sg.h and changing
-the value of SG_BIG_BUFF.
+compile time by editing ``include/scsi/sg.h`` and changing
+the value of ``SG_BIG_BUFF``.
 
 There shouldn't be any reason to change this value. If
 you can come up with one, you probably know what you
 are doing anyway :)
 
 
-shmall:
-=======
+shmall
+======
 
 This parameter sets the total amount of shared memory pages that
-can be used system wide. Hence, SHMALL should always be at least
-ceil(shmmax/PAGE_SIZE).
+can be used system wide. Hence, ``shmall`` should always be at least
+``ceil(shmmax/PAGE_SIZE)``.
 
-If you are not sure what the default PAGE_SIZE is on your Linux
-system, you can run the following command:
+If you are not sure what the default ``PAGE_SIZE`` is on your Linux
+system, you can run the following command::
 
        # getconf PAGE_SIZE
 
 
-shmmax:
-=======
+shmmax
+======
 
 This value can be used to query and set the run time limit
 on the maximum shared memory segment size that can be created.
 Shared memory segments up to 1Gb are now supported in the
-kernel.  This value defaults to SHMMAX.
+kernel.  This value defaults to ``SHMMAX``.
 
 
-shm_rmid_forced:
-================
+shmmni
+======
+
+This value determines the maximum number of shared memory segments.
+4096 by default (``SHMMNI``).
+
+
+shm_rmid_forced
+===============
 
 Linux lets you set resource limits, including how much memory one
-process can consume, via setrlimit(2).  Unfortunately, shared memory
+process can consume, via ``setrlimit(2)``.  Unfortunately, shared memory
 segments are allowed to exist without association with any process, and
 thus might not be counted against any resource limits.  If enabled,
 shared memory segments are automatically destroyed when their attach
 count becomes zero after a detach or a process termination.  It will
 also destroy segments that were created, but never attached to, on exit
-from the process.  The only use left for IPC_RMID is to immediately
+from the process.  The only use left for ``IPC_RMID`` is to immediately
 destroy an unattached segment.  Of course, this breaks the way things are
 defined, so some applications might stop working.  Note that this
 feature will do you no good unless you also configure your resource
-limits (in particular, RLIMIT_AS and RLIMIT_NPROC).  Most systems don't
+limits (in particular, ``RLIMIT_AS`` and ``RLIMIT_NPROC``).  Most systems don't
 need this.
 
 Note that if you change this from 0 to 1, already created segments
 without users and with a dead originative process will be destroyed.
 
 
-sysctl_writes_strict:
-=====================
+sysctl_writes_strict
+====================
 
 Control how file position affects the behavior of updating sysctl values
-via the /proc/sys interface:
+via the ``/proc/sys`` interface:
 
   ==   ======================================================================
   -1   Legacy per-write sysctl value handling, with no printk warnings.
@@ -1013,8 +1019,8 @@ via the /proc/sys interface:
   ==   ======================================================================
 
 
-softlockup_all_cpu_backtrace:
-=============================
+softlockup_all_cpu_backtrace
+============================
 
 This value controls the soft lockup detector thread's behavior
 when a soft lockup condition is detected as to whether or not
@@ -1024,43 +1030,80 @@ be issued an NMI and instructed to capture stack trace.
 This feature is only applicable for architectures which support
 NMI.
 
-0: do nothing. This is the default behavior.
+= ============================================
+0 Do nothing. This is the default behavior.
+1 On detection capture more debug information.
+= ============================================
 
-1: on detection capture more debug information.
 
+softlockup_panic
+=================
 
-soft_watchdog:
-==============
+This parameter can be used to control whether the kernel panics
+when a soft lockup is detected.
 
-This parameter can be used to control the soft lockup detector.
+= ============================================
+0 Don't panic on soft lockup.
+1 Panic on soft lockup.
+= ============================================
 
-   0 - disable the soft lockup detector
+This can also be set using the softlockup_panic kernel parameter.
 
-   1 - enable the soft lockup detector
+
+soft_watchdog
+=============
+
+This parameter can be used to control the soft lockup detector.
+
+= =================================
+0 Disable the soft lockup detector.
+1 Enable the soft lockup detector.
+= =================================
 
 The soft lockup detector monitors CPUs for threads that are hogging the CPUs
 without rescheduling voluntarily, and thus prevent the 'watchdog/N' threads
 from running. The mechanism depends on the CPUs ability to respond to timer
 interrupts which are needed for the 'watchdog/N' threads to be woken up by
-the watchdog timer function, otherwise the NMI watchdog - if enabled - can
+the watchdog timer function, otherwise the NMI watchdog — if enabled — can
 detect a hard lockup condition.
 
 
-stack_erasing:
-==============
+stack_erasing
+=============
 
 This parameter can be used to control kernel stack erasing at the end
-of syscalls for kernels built with CONFIG_GCC_PLUGIN_STACKLEAK.
+of syscalls for kernels built with ``CONFIG_GCC_PLUGIN_STACKLEAK``.
 
 That erasing reduces the information which kernel stack leak bugs
 can reveal and blocks some uninitialized stack variable attacks.
 The tradeoff is the performance impact: on a single CPU system kernel
 compilation sees a 1% slowdown, other systems and workloads may vary.
 
-  0: kernel stack erasing is disabled, STACKLEAK_METRICS are not updated.
+= ====================================================================
+0 Kernel stack erasing is disabled, STACKLEAK_METRICS are not updated.
+1 Kernel stack erasing is enabled (default), it is performed before
+  returning to the userspace at the end of syscalls.
+= ====================================================================
+
+
+stop-a (SPARC only)
+===================
+
+Controls Stop-A:
+
+= ====================================
+0 Stop-A has no effect.
+1 Stop-A breaks to the PROM (default).
+= ====================================
+
+Stop-A is always enabled on a panic, so that the user can return to
+the boot PROM.
 
-  1: kernel stack erasing is enabled (default), it is performed before
-     returning to the userspace at the end of syscalls.
+
+sysrq
+=====
+
+See :doc:`/admin-guide/sysrq`.
 
 
 tainted
@@ -1090,30 +1133,30 @@ ORed together. The letters are seen in "Tainted" line of Oops reports.
 131072  `(T)`  The kernel was built with the struct randomization plugin
 ======  =====  ==============================================================
 
-See Documentation/admin-guide/tainted-kernels.rst for more information.
+See :doc:`/admin-guide/tainted-kernels` for more information.
 
 
-threads-max:
-============
+threads-max
+===========
 
 This value controls the maximum number of threads that can be created
-using fork().
+using ``fork()``.
 
 During initialization the kernel sets this value such that even if the
 maximum number of threads is created, the thread structures occupy only
 a part (1/8th) of the available RAM pages.
 
-The minimum value that can be written to threads-max is 1.
+The minimum value that can be written to ``threads-max`` is 1.
 
-The maximum value that can be written to threads-max is given by the
-constant FUTEX_TID_MASK (0x3fffffff).
+The maximum value that can be written to ``threads-max`` is given by the
+constant ``FUTEX_TID_MASK`` (0x3fffffff).
 
-If a value outside of this range is written to threads-max an error
-EINVAL occurs.
+If a value outside of this range is written to ``threads-max`` an
+``EINVAL`` error occurs.
 
 
-unknown_nmi_panic:
-==================
+unknown_nmi_panic
+=================
 
 The value in this file affects behavior of handling NMI. When the
 value is non-zero, unknown NMI is trapped and then panic occurs. At
@@ -1123,37 +1166,39 @@ NMI switch that most IA32 servers have fires unknown NMI up, for
 example.  If a system hangs up, try pressing the NMI switch.
 
 
-watchdog:
-=========
+watchdog
+========
 
 This parameter can be used to disable or enable the soft lockup detector
-_and_ the NMI watchdog (i.e. the hard lockup detector) at the same time.
-
-   0 - disable both lockup detectors
+*and* the NMI watchdog (i.e. the hard lockup detector) at the same time.
 
-   1 - enable both lockup detectors
+= ==============================
+0 Disable both lockup detectors.
+1 Enable both lockup detectors.
+= ==============================
 
 The soft lockup detector and the NMI watchdog can also be disabled or
-enabled individually, using the soft_watchdog and nmi_watchdog parameters.
-If the watchdog parameter is read, for example by executing::
+enabled individually, using the ``soft_watchdog`` and ``nmi_watchdog``
+parameters.
+If the ``watchdog`` parameter is read, for example by executing::
 
    cat /proc/sys/kernel/watchdog
 
-the output of this command (0 or 1) shows the logical OR of soft_watchdog
-and nmi_watchdog.
+the output of this command (0 or 1) shows the logical OR of
+``soft_watchdog`` and ``nmi_watchdog``.
 
 
-watchdog_cpumask:
-=================
+watchdog_cpumask
+================
 
 This value can be used to control on which cpus the watchdog may run.
-The default cpumask is all possible cores, but if NO_HZ_FULL is
+The default cpumask is all possible cores, but if ``NO_HZ_FULL`` is
 enabled in the kernel config, and cores are specified with the
-nohz_full= boot argument, those cores are excluded by default.
+``nohz_full=`` boot argument, those cores are excluded by default.
 Offline cores can be included in this mask, and if the core is later
 brought online, the watchdog will be started based on the mask value.
 
-Typically this value would only be touched in the nohz_full case
+Typically this value would only be touched in the ``nohz_full`` case
 to re-enable cores that by default were not running the watchdog,
 if a kernel lockup was suspected on those cores.
 
@@ -1164,12 +1209,12 @@ might say::
   echo 0,2-4 > /proc/sys/kernel/watchdog_cpumask
 
 
-watchdog_thresh:
-================
+watchdog_thresh
+===============
 
 This value can be used to control the frequency of hrtimer and NMI
 events and the soft and hard lockup thresholds. The default threshold
 is 10 seconds.
 
-The softlockup threshold is (2 * watchdog_thresh). Setting this
+The softlockup threshold is (``2 * watchdog_thresh``). Setting this
 tunable to zero will disable lockup detection altogether.
index effd9c7..b256f97 100644 (file)
@@ -4,18 +4,18 @@ ARM TCM (Tightly-Coupled Memory) handling in Linux
 
 Written by Linus Walleij <linus.walleij@stericsson.com>
 
-Some ARM SoC:s have a so-called TCM (Tightly-Coupled Memory).
+Some ARM SoCs have a so-called TCM (Tightly-Coupled Memory).
 This is usually just a few (4-64) KiB of RAM inside the ARM
 processor.
 
-Due to being embedded inside the CPU The TCM has a
+Due to being embedded inside the CPU, the TCM has a
 Harvard-architecture, so there is an ITCM (instruction TCM)
 and a DTCM (data TCM). The DTCM can not contain any
 instructions, but the ITCM can actually contain data.
 The size of DTCM or ITCM is minimum 4KiB so the typical
 minimum configuration is 4KiB ITCM and 4KiB DTCM.
 
-ARM CPU:s have special registers to read out status, physical
+ARM CPUs have special registers to read out status, physical
 location and size of TCM memories. arch/arm/include/asm/cputype.h
 defines a CPUID_TCM register that you can read out from the
 system control coprocessor. Documentation from ARM can be found
index 2cf258d..160a514 100644 (file)
@@ -2,17 +2,9 @@
 Generic Block Device Capability
 ===============================
 
-This file documents the sysfs file block/<disk>/capability
+This file documents the sysfs file ``block/<disk>/capability``.
 
-capability is a hex word indicating which capabilities a specific disk
-supports.  For more information on bits not listed here, see
-include/linux/genhd.h
+``capability`` is a bitfield, printed in hexadecimal, indicating which
+capabilities a specific block device supports:
 
-GENHD_FL_MEDIA_CHANGE_NOTIFY
-----------------------------
-
-Value: 4
-
-When this bit is set, the disk supports Asynchronous Notification
-of media change events.  These events will be broadcast to user
-space via kernel uevent.
+.. kernel-doc:: include/linux/genhd.h
index 3c7bdf4..9ae8e9a 100644 (file)
@@ -38,7 +38,11 @@ needs_sphinx = '1.3'
 # ones.
 extensions = ['kerneldoc', 'rstFlatTable', 'kernel_include', 'cdomain',
               'kfigure', 'sphinx.ext.ifconfig', 'automarkup',
-              'maintainers_include']
+              'maintainers_include', 'sphinx.ext.autosectionlabel' ]
+
+# Ensure that autosectionlabel will produce unique names
+autosectionlabel_prefix_document = True
+autosectionlabel_maxdepth = 2
 
 # The name of the math extension changed on Sphinx 1.4
 if (major == 1 and minor > 3) or (major > 1):
index a501dc1..0897ad1 100644 (file)
@@ -8,41 +8,81 @@ This is the beginning of a manual for core kernel APIs.  The conversion
 Core utilities
 ==============
 
+This section has general and "core core" documentation.  The first is a
+massive grab-bag of kerneldoc info left over from the docbook days; it
+should really be broken up someday when somebody finds the energy to do
+it.
+
 .. toctree::
    :maxdepth: 1
 
    kernel-api
+   workqueue
+   printk-formats
+   symbol-namespaces
+
+Data structures and low-level utilities
+=======================================
+
+Library functionality that is used throughout the kernel.
+
+.. toctree::
+   :maxdepth: 1
+
+   kobject
    assoc_array
+   xarray
+   idr
+   circular-buffers
+   generic-radix-tree
+   packing
+   timekeeping
+   errseq
+
+Concurrency primitives
+======================
+
+How Linux keeps everything from happening at the same time.  See
+:doc:`/locking/index` for more related documentation.
+
+.. toctree::
+   :maxdepth: 1
+
    atomic_ops
-   cachetlb
    refcount-vs-atomic
-   cpu_hotplug
-   idr
    local_ops
-   workqueue
+   padata
+   ../RCU/index
+
+Low-level hardware management
+=============================
+
+Cache management, managing CPU hotplug, etc.
+
+.. toctree::
+   :maxdepth: 1
+
+   cachetlb
+   cpu_hotplug
+   memory-hotplug
    genericirq
-   xarray
-   librs
-   genalloc
-   errseq
-   packing
-   printk-formats
-   circular-buffers
-   generic-radix-tree
+   protection-keys
+
+Memory management
+=================
+
+How to allocate and use memory in the kernel.  Note that there is a lot
+more memory-management documentation in :doc:`/vm/index`.
+
+.. toctree::
+   :maxdepth: 1
+
    memory-allocation
    mm-api
+   genalloc
    pin_user_pages
-   gfp_mask-from-fs-io
-   timekeeping
    boot-time-mm
-   memory-hotplug
-   protection-keys
-   ../RCU/index
-   gcc-plugins
-   symbol-namespaces
-   padata
-   ioctl
-
+   gfp_mask-from-fs-io
 
 Interfaces for kernel debugging
 ===============================
@@ -53,6 +93,16 @@ Interfaces for kernel debugging
    debug-objects
    tracepoint
 
+Everything else
+===============
+
+Documents that don't fit elsewhere or which have yet to be categorized.
+
+.. toctree::
+   :maxdepth: 1
+
+   librs
+
 .. only:: subproject and html
 
    Indices
similarity index 87%
rename from Documentation/kobject.txt
rename to Documentation/core-api/kobject.rst
index ff4c250..1f62d4d 100644 (file)
@@ -25,7 +25,7 @@ some terms we will be working with.
    usually embedded within some other structure which contains the stuff
    the code is really interested in.
 
-   No structure should EVER have more than one kobject embedded within it.
+   No structure should **EVER** have more than one kobject embedded within it.
    If it does, the reference counting for the object is sure to be messed
    up and incorrect, and your code will be buggy.  So do not do this.
 
@@ -55,7 +55,7 @@ a larger, domain-specific object.  To this end, kobjects will be found
 embedded in other structures.  If you are used to thinking of things in
 object-oriented terms, kobjects can be seen as a top-level, abstract class
 from which other classes are derived.  A kobject implements a set of
-capabilities which are not particularly useful by themselves, but which are
+capabilities which are not particularly useful by themselves, but are
 nice to have in other objects.  The C language does not allow for the
 direct expression of inheritance, so other techniques - such as structure
 embedding - must be used.
@@ -65,12 +65,12 @@ this is analogous as to how "list_head" structs are rarely useful on
 their own, but are invariably found embedded in the larger objects of
 interest.)
 
-So, for example, the UIO code in drivers/uio/uio.c has a structure that
+So, for example, the UIO code in ``drivers/uio/uio.c`` has a structure that
 defines the memory region associated with a uio device::
 
     struct uio_map {
-       struct kobject kobj;
-       struct uio_mem *mem;
+            struct kobject kobj;
+            struct uio_mem *mem;
     };
 
 If you have a struct uio_map structure, finding its embedded kobject is
@@ -78,30 +78,30 @@ just a matter of using the kobj member.  Code that works with kobjects will
 often have the opposite problem, however: given a struct kobject pointer,
 what is the pointer to the containing structure?  You must avoid tricks
 (such as assuming that the kobject is at the beginning of the structure)
-and, instead, use the container_of() macro, found in <linux/kernel.h>::
+and, instead, use the container_of() macro, found in ``<linux/kernel.h>``::
 
     container_of(pointer, type, member)
 
 where:
 
-  * "pointer" is the pointer to the embedded kobject,
-  * "type" is the type of the containing structure, and
-  * "member" is the name of the structure field to which "pointer" points.
+  * ``pointer`` is the pointer to the embedded kobject,
+  * ``type`` is the type of the containing structure, and
+  * ``member`` is the name of the structure field to which ``pointer`` points.
 
 The return value from container_of() is a pointer to the corresponding
-container type. So, for example, a pointer "kp" to a struct kobject
-embedded *within* a struct uio_map could be converted to a pointer to the
-*containing* uio_map structure with::
+container type. So, for example, a pointer ``kp`` to a struct kobject
+embedded **within** a struct uio_map could be converted to a pointer to the
+**containing** uio_map structure with::
 
     struct uio_map *u_map = container_of(kp, struct uio_map, kobj);
 
-For convenience, programmers often define a simple macro for "back-casting"
+For convenience, programmers often define a simple macro for **back-casting**
 kobject pointers to the containing type.  Exactly this happens in the
-earlier drivers/uio/uio.c, as you can see here::
+earlier ``drivers/uio/uio.c``, as you can see here::
 
     struct uio_map {
-        struct kobject kobj;
-        struct uio_mem *mem;
+            struct kobject kobj;
+            struct uio_mem *mem;
     };
 
     #define to_map(map) container_of(map, struct uio_map, kobj)
@@ -125,7 +125,7 @@ must have an associated kobj_type.  After calling kobject_init(), to
 register the kobject with sysfs, the function kobject_add() must be called::
 
     int kobject_add(struct kobject *kobj, struct kobject *parent,
-                   const char *fmt, ...);
+                    const char *fmt, ...);
 
 This sets up the parent of the kobject and the name for the kobject
 properly.  If the kobject is to be associated with a specific kset,
@@ -172,13 +172,13 @@ call to kobject_uevent()::
 
     int kobject_uevent(struct kobject *kobj, enum kobject_action action);
 
-Use the KOBJ_ADD action for when the kobject is first added to the kernel.
+Use the **KOBJ_ADD** action for when the kobject is first added to the kernel.
 This should be done only after any attributes or children of the kobject
 have been initialized properly, as userspace will instantly start to look
 for them when this call happens.
 
 When the kobject is removed from the kernel (details on how to do that are
-below), the uevent for KOBJ_REMOVE will be automatically created by the
+below), the uevent for **KOBJ_REMOVE** will be automatically created by the
 kobject core, so the caller does not have to worry about doing that by
 hand.
 
@@ -238,7 +238,7 @@ Both types of attributes used here, with a kobject that has been created
 with the kobject_create_and_add(), can be of type kobj_attribute, so no
 special custom attribute is needed to be created.
 
-See the example module, samples/kobject/kobject-example.c for an
+See the example module, ``samples/kobject/kobject-example.c`` for an
 implementation of a simple kobject and attributes.
 
 
@@ -270,10 +270,10 @@ such a method has a form like::
 
     void my_object_release(struct kobject *kobj)
     {
-           struct my_object *mine = container_of(kobj, struct my_object, kobj);
+            struct my_object *mine = container_of(kobj, struct my_object, kobj);
 
-           /* Perform any additional cleanup on this object, then... */
-           kfree(mine);
+            /* Perform any additional cleanup on this object, then... */
+            kfree(mine);
     }
 
 One important point cannot be overstated: every kobject must have a
@@ -297,11 +297,11 @@ instead, it is associated with the ktype. So let us introduce struct
 kobj_type::
 
     struct kobj_type {
-           void (*release)(struct kobject *kobj);
-           const struct sysfs_ops *sysfs_ops;
-           struct attribute **default_attrs;
-           const struct kobj_ns_type_operations *(*child_ns_type)(struct kobject *kobj);
-           const void *(*namespace)(struct kobject *kobj);
+            void (*release)(struct kobject *kobj);
+            const struct sysfs_ops *sysfs_ops;
+            struct attribute **default_attrs;
+            const struct kobj_ns_type_operations *(*child_ns_type)(struct kobject *kobj);
+            const void *(*namespace)(struct kobject *kobj);
     };
 
 This structure is used to describe a particular type of kobject (or, more
@@ -352,8 +352,8 @@ created and never declared statically or on the stack.  To create a new
 kset use::
 
   struct kset *kset_create_and_add(const char *name,
-                                  struct kset_uevent_ops *u,
-                                  struct kobject *parent);
+                                   struct kset_uevent_ops *u,
+                                   struct kobject *parent);
 
 When you are finished with the kset, call::
 
@@ -365,16 +365,16 @@ Because other references to the kset may still exist, the release may happen
 after kset_unregister() returns.
 
 An example of using a kset can be seen in the
-samples/kobject/kset-example.c file in the kernel tree.
+``samples/kobject/kset-example.c`` file in the kernel tree.
 
 If a kset wishes to control the uevent operations of the kobjects
 associated with it, it can use the struct kset_uevent_ops to handle it::
 
   struct kset_uevent_ops {
-        int (*filter)(struct kset *kset, struct kobject *kobj);
-        const char *(*name)(struct kset *kset, struct kobject *kobj);
-        int (*uevent)(struct kset *kset, struct kobject *kobj,
-                      struct kobj_uevent_env *env);
+          int (*filter)(struct kset *kset, struct kobject *kobj);
+          const char *(*name)(struct kset *kset, struct kobject *kobj);
+          int (*uevent)(struct kset *kset, struct kobject *kobj,
+                        struct kobj_uevent_env *env);
   };
 
 
@@ -408,8 +408,8 @@ Kobject removal
 After a kobject has been registered with the kobject core successfully, it
 must be cleaned up when the code is finished with it.  To do that, call
 kobject_put().  By doing this, the kobject core will automatically clean up
-all of the memory allocated by this kobject.  If a KOBJ_ADD uevent has been
-sent for the object, a corresponding KOBJ_REMOVE uevent will be sent, and
+all of the memory allocated by this kobject.  If a ``KOBJ_ADD`` uevent has been
+sent for the object, a corresponding ``KOBJ_REMOVE`` uevent will be sent, and
 any other sysfs housekeeping will be handled for the caller properly.
 
 If you need to do a two-stage delete of the kobject (say you are not
@@ -430,5 +430,5 @@ Example code to copy from
 =========================
 
 For a more complete example of using ksets and kobjects properly, see the
-example programs samples/kobject/{kobject-example.c,kset-example.c},
-which will be built as loadable modules if you select CONFIG_SAMPLE_KOBJECT.
+example programs ``samples/kobject/{kobject-example.c,kset-example.c}``,
+which will be built as loadable modules if you select ``CONFIG_SAMPLE_KOBJECT``.
diff --git a/Documentation/debugging-modules.txt b/Documentation/debugging-modules.txt
deleted file mode 100644 (file)
index 172ad4a..0000000
+++ /dev/null
@@ -1,22 +0,0 @@
-Debugging Modules after 2.6.3
------------------------------
-
-In almost all distributions, the kernel asks for modules which don't
-exist, such as "net-pf-10" or whatever.  Changing "modprobe -q" to
-"succeed" in this case is hacky and breaks some setups, and also we
-want to know if it failed for the fallback code for old aliases in
-fs/char_dev.c, for example.
-
-In the past a debugging message which would fill people's logs was
-emitted.  This debugging message has been removed.  The correct way
-of debugging module problems is something like this:
-
-echo '#! /bin/sh' > /tmp/modprobe
-echo 'echo "$@" >> /tmp/modprobe.log' >> /tmp/modprobe
-echo 'exec /sbin/modprobe "$@"' >> /tmp/modprobe
-chmod a+x /tmp/modprobe
-echo /tmp/modprobe > /proc/sys/kernel/modprobe
-
-Note that the above applies only when the *kernel* is requesting
-that the module be loaded -- it won't have any effect if that module
-is being loaded explicitly using "modprobe" from userspace.
index 46aae52..7bd0135 100644 (file)
@@ -203,7 +203,7 @@ Cause
     may not correctly copy files from sysfs.
 
 Solution
-    Use ``cat``' to read ``.gcda`` files and ``cp -d`` to copy links.
+    Use ``cat`` to read ``.gcda`` files and ``cp -d`` to copy links.
     Alternatively use the mechanism shown in Appendix B.
 
 
index 3a289e8..fce2628 100644 (file)
@@ -8,7 +8,8 @@ with the difference that the orphan objects are not freed but only
 reported via /sys/kernel/debug/kmemleak. A similar method is used by the
 Valgrind tool (``memcheck --leak-check``) to detect the memory leaks in
 user-space applications.
-Kmemleak is supported on x86, arm, powerpc, sparc, sh, microblaze, ppc, mips, s390 and tile.
+Kmemleak is supported on x86, arm, arm64, powerpc, sparc, sh, microblaze, mips,
+s390, nds32, arc and xtensa.
 
 Usage
 -----
index 9f1c5bb..24cb64b 100644 (file)
@@ -272,8 +272,8 @@ STA information lifetime rules
 .. kernel-doc:: net/mac80211/sta_info.c
    :doc: STA information lifetime rules
 
-Aggregation
-===========
+Aggregation Functions
+=====================
 
 .. kernel-doc:: net/mac80211/sta_info.h
    :functions: sta_ampdu_mlme
@@ -284,8 +284,8 @@ Aggregation
 .. kernel-doc:: net/mac80211/sta_info.h
    :functions: tid_ampdu_rx
 
-Synchronisation
-===============
+Synchronisation Functions
+=========================
 
 TBD
 
index b9df904..bdc45d8 100644 (file)
@@ -5,8 +5,8 @@ DMAEngine documentation
 DMAEngine documentation provides documents for various aspects of DMAEngine
 framework.
 
-DMAEngine documentation
------------------------
+DMAEngine development documentation
+-----------------------------------
 
 This book helps with DMAengine internal APIs and guide for DMAEngine device
 driver writers.
index baa6a85..63887b8 100644 (file)
@@ -210,7 +210,7 @@ probed.
 While the typical use case for sync_state() is to have the kernel cleanly take
 over management of devices from the bootloader, the usage of sync_state() is
 not restricted to that. Use it whenever it makes sense to take an action after
-all the consumers of a device have probed.
+all the consumers of a device have probed::
 
        int     (*remove)       (struct device *dev);
 
index 0ebe205..d4e78cb 100644 (file)
@@ -17,6 +17,7 @@ available subsections can be seen below.
    driver-model/index
    basics
    infrastructure
+   ioctl
    early-userspace/index
    pm/index
    clk
@@ -74,11 +75,12 @@ available subsections can be seen below.
    connector
    console
    dcdbas
-   edid
    eisa
    ipmb
    isa
    isapnp
+   io-mapping
+   io_ordering
    generic-counter
    lightnvm-pblk
    memory-devices/index
index 2dc5df6..3d492a3 100644 (file)
@@ -23,7 +23,7 @@
     |    openrisc: | TODO |
     |      parisc: | TODO |
     |     powerpc: |  ok  |
-    |       riscv: | TODO |
+    |       riscv: |  ok  |
     |        s390: |  ok  |
     |          sh: |  ok  |
     |       sparc: |  ok  |
similarity index 63%
rename from Documentation/filesystems/9p.txt
rename to Documentation/filesystems/9p.rst
index fec7144..f054d1c 100644 (file)
@@ -1,7 +1,10 @@
-                   v9fs: Plan 9 Resource Sharing for Linux
-                   =======================================
+.. SPDX-License-Identifier: GPL-2.0
 
-ABOUT
+=======================================
+v9fs: Plan 9 Resource Sharing for Linux
+=======================================
+
+About
 =====
 
 v9fs is a Unix implementation of the Plan 9 9p remote filesystem protocol.
@@ -14,32 +17,34 @@ and Maya Gokhale.  Additional development by Greg Watson
 
 The best detailed explanation of the Linux implementation and applications of
 the 9p client is available in the form of a USENIX paper:
+
    http://www.usenix.org/events/usenix05/tech/freenix/hensbergen.html
 
 Other applications are described in the following papers:
+
        * XCPU & Clustering
-               http://xcpu.org/papers/xcpu-talk.pdf
+         http://xcpu.org/papers/xcpu-talk.pdf
        * KVMFS: control file system for KVM
-               http://xcpu.org/papers/kvmfs.pdf
+         http://xcpu.org/papers/kvmfs.pdf
        * CellFS: A New Programming Model for the Cell BE
-               http://xcpu.org/papers/cellfs-talk.pdf
+         http://xcpu.org/papers/cellfs-talk.pdf
        * PROSE I/O: Using 9p to enable Application Partitions
-               http://plan9.escet.urjc.es/iwp9/cready/PROSE_iwp9_2006.pdf
+         http://plan9.escet.urjc.es/iwp9/cready/PROSE_iwp9_2006.pdf
        * VirtFS: A Virtualization Aware File System pass-through
-               http://goo.gl/3WPDg
+         http://goo.gl/3WPDg
 
-USAGE
+Usage
 =====
 
-For remote file server:
+For remote file server::
 
        mount -t 9p 10.10.1.2 /mnt/9
 
-For Plan 9 From User Space applications (http://swtch.com/plan9)
+For Plan 9 From User Space applications (http://swtch.com/plan9)::
 
        mount -t 9p `namespace`/acme /mnt/9 -o trans=unix,uname=$USER
 
-For server running on QEMU host with virtio transport:
+For server running on QEMU host with virtio transport::
 
        mount -t 9p -o trans=virtio <mount_tag> /mnt/9
 
@@ -48,18 +53,22 @@ mount points. Each 9P export is seen by the client as a virtio device with an
 associated "mount_tag" property. Available mount tags can be
 seen by reading /sys/bus/virtio/drivers/9pnet_virtio/virtio<n>/mount_tag files.
 
-OPTIONS
+Options
 =======
 
+  ============= ===============================================================
   trans=name   select an alternative transport.  Valid options are
                currently:
-                       unix    - specifying a named pipe mount point
-                       tcp     - specifying a normal TCP/IP connection
-                       fd      - used passed file descriptors for connection
-                                (see rfdno and wfdno)
-                       virtio  - connect to the next virtio channel available
-                               (from QEMU with trans_virtio module)
-                       rdma    - connect to a specified RDMA channel
+
+                       ========  ============================================
+                       unix      specifying a named pipe mount point
+                       tcp       specifying a normal TCP/IP connection
+                       fd        used passed file descriptors for connection
+                                  (see rfdno and wfdno)
+                       virtio    connect to the next virtio channel available
+                                 (from QEMU with trans_virtio module)
+                       rdma      connect to a specified RDMA channel
+                       ========  ============================================
 
   uname=name   user name to attempt mount as on the remote server.  The
                server may override or ignore this value.  Certain user
@@ -69,28 +78,36 @@ OPTIONS
                offering several exported file systems.
 
   cache=mode   specifies a caching policy.  By default, no caches are used.
-                        none = default no cache policy, metadata and data
+
+                        none
+                               default no cache policy, metadata and data
                                 alike are synchronous.
-                       loose = no attempts are made at consistency,
+                       loose
+                               no attempts are made at consistency,
                                 intended for exclusive, read-only mounts
-                        fscache = use FS-Cache for a persistent, read-only
+                        fscache
+                               use FS-Cache for a persistent, read-only
                                cache backend.
-                        mmap = minimal cache that is only used for read-write
+                        mmap
+                               minimal cache that is only used for read-write
                                 mmap.  Northing else is cached, like cache=none
 
   debug=n      specifies debug level.  The debug level is a bitmask.
-                       0x01  = display verbose error messages
-                       0x02  = developer debug (DEBUG_CURRENT)
-                       0x04  = display 9p trace
-                       0x08  = display VFS trace
-                       0x10  = display Marshalling debug
-                       0x20  = display RPC debug
-                       0x40  = display transport debug
-                       0x80  = display allocation debug
-                       0x100 = display protocol message debug
-                       0x200 = display Fid debug
-                       0x400 = display packet debug
-                       0x800 = display fscache tracing debug
+
+                       =====   ================================
+                       0x01    display verbose error messages
+                       0x02    developer debug (DEBUG_CURRENT)
+                       0x04    display 9p trace
+                       0x08    display VFS trace
+                       0x10    display Marshalling debug
+                       0x20    display RPC debug
+                       0x40    display transport debug
+                       0x80    display allocation debug
+                       0x100   display protocol message debug
+                       0x200   display Fid debug
+                       0x400   display packet debug
+                       0x800   display fscache tracing debug
+                       =====   ================================
 
   rfdno=n      the file descriptor for reading with trans=fd
 
@@ -103,9 +120,12 @@ OPTIONS
   noextend     force legacy mode (no 9p2000.u or 9p2000.L semantics)
 
   version=name Select 9P protocol version. Valid options are:
-                       9p2000          - Legacy mode (same as noextend)
-                       9p2000.u        - Use 9P2000.u protocol
-                       9p2000.L        - Use 9P2000.L protocol
+
+                       ========        ==============================
+                       9p2000          Legacy mode (same as noextend)
+                       9p2000.u        Use 9P2000.u protocol
+                       9p2000.L        Use 9P2000.L protocol
+                       ========        ==============================
 
   dfltuid      attempt to mount as a particular uid
 
@@ -118,22 +138,27 @@ OPTIONS
                hosts.  This functionality will be expanded in later versions.
 
   access       there are four access modes.
-                       user  = if a user tries to access a file on v9fs
+                       user
+                               if a user tries to access a file on v9fs
                                filesystem for the first time, v9fs sends an
                                attach command (Tattach) for that user.
                                This is the default mode.
-                       <uid> = allows only user with uid=<uid> to access
+                       <uid>
+                               allows only user with uid=<uid> to access
                                the files on the mounted filesystem
-                       any   = v9fs does single attach and performs all
+                       any
+                               v9fs does single attach and performs all
                                operations as one user
-                       client = ACL based access check on the 9p client
+                       clien
+                                ACL based access check on the 9p client
                                 side for access validation
 
   cachetag     cache tag to use the specified persistent cache.
                cache tags for existing cache sessions can be listed at
                /sys/fs/9p/caches. (applies only to cache=fscache)
+  ============= ===============================================================
 
-RESOURCES
+Resources
 =========
 
 Protocol specifications are maintained on github:
@@ -158,4 +183,3 @@ http://plan9.bell-labs.com/plan9
 
 For information on Plan 9 from User Space (Plan 9 applications and libraries
 ported to Linux/BSD/OSX/etc) check out http://swtch.com/plan9
-
similarity index 85%
rename from Documentation/filesystems/adfs.txt
rename to Documentation/filesystems/adfs.rst
index 0baa8e8..5b22cae 100644 (file)
@@ -1,3 +1,9 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+===============================
+Acorn Disc Filing System - ADFS
+===============================
+
 Filesystems supported by ADFS
 -----------------------------
 
@@ -25,6 +31,7 @@ directory updates, specifically updating the access mode and timestamp.
 Mount options for ADFS
 ----------------------
 
+  ============  ======================================================
   uid=nnn      All files in the partition will be owned by
                user id nnn.  Default 0 (root).
   gid=nnn      All files in the partition will be in group
@@ -36,22 +43,23 @@ Mount options for ADFS
   ftsuffix=n   When ftsuffix=0, no file type suffix will be applied.
                When ftsuffix=1, a hexadecimal suffix corresponding to
                the RISC OS file type will be added.  Default 0.
+  ============  ======================================================
 
 Mapping of ADFS permissions to Linux permissions
 ------------------------------------------------
 
   ADFS permissions consist of the following:
 
-       Owner read
-       Owner write
-       Other read
-       Other write
+       Owner read
+       Owner write
+       Other read
+       Other write
 
   (In older versions, an 'execute' permission did exist, but this
-   does not hold the same meaning as the Linux 'execute' permission
-   and is now obsolete).
+  does not hold the same meaning as the Linux 'execute' permission
+  and is now obsolete).
 
-  The mapping is performed as follows:
+  The mapping is performed as follows::
 
        Owner read                              -> -r--r--r--
        Owner write                             -> --w--w---w
@@ -66,17 +74,18 @@ Mapping of ADFS permissions to Linux permissions
        Possible other mode permissions         -> ----rwxrwx
 
   Hence, with the default masks, if a file is owner read/write, and
-  not a UnixExec filetype, then the permissions will be:
+  not a UnixExec filetype, then the permissions will be::
 
                        -rw-------
 
   However, if the masks were ownmask=0770,othmask=0007, then this would
-  be modified to:
+  be modified to::
+
                        -rw-rw----
 
   There is no restriction on what you can do with these masks.  You may
   wish that either read bits give read access to the file for all, but
-  keep the default write protection (ownmask=0755,othmask=0577):
+  keep the default write protection (ownmask=0755,othmask=0577)::
 
                        -rw-r--r--
 
similarity index 86%
rename from Documentation/filesystems/affs.txt
rename to Documentation/filesystems/affs.rst
index 71b63c2..7f1a40d 100644 (file)
@@ -1,9 +1,13 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+=============================
 Overview of Amiga Filesystems
 =============================
 
 Not all varieties of the Amiga filesystems are supported for reading and
 writing. The Amiga currently knows six different filesystems:
 
+============== ===============================================================
 DOS\0          The old or original filesystem, not really suited for
                hard disks and normally not used on them, either.
                Supported read/write.
@@ -23,6 +27,7 @@ DOS\4         The original filesystem with directory cache. The directory
                sense on hard disks. Supported read only.
 
 DOS\5          The Fast File System with directory cache. Supported read only.
+============== ===============================================================
 
 All of the above filesystems allow block sizes from 512 to 32K bytes.
 Supported block sizes are: 512, 1024, 2048 and 4096 bytes. Larger blocks
@@ -36,14 +41,18 @@ are supported, too.
 Mount options for the AFFS
 ==========================
 
-protect                If this option is set, the protection bits cannot be altered.
+protect
+               If this option is set, the protection bits cannot be altered.
 
-setuid[=uid]   This sets the owner of all files and directories in the file
+setuid[=uid]
+               This sets the owner of all files and directories in the file
                system to uid or the uid of the current user, respectively.
 
-setgid[=gid]   Same as above, but for gid.
+setgid[=gid]
+               Same as above, but for gid.
 
-mode=mode      Sets the mode flags to the given (octal) value, regardless
+mode=mode
+               Sets the mode flags to the given (octal) value, regardless
                of the original permissions. Directories will get an x
                permission if the corresponding r bit is set.
                This is useful since most of the plain AmigaOS files
@@ -53,33 +62,41 @@ nofilenametruncate
                The file system will return an error when filename exceeds
                standard maximum filename length (30 characters).
 
-reserved=num   Sets the number of reserved blocks at the start of the
+reserved=num
+               Sets the number of reserved blocks at the start of the
                partition to num. You should never need this option.
                Default is 2.
 
-root=block     Sets the block number of the root block. This should never
+root=block
+               Sets the block number of the root block. This should never
                be necessary.
 
-bs=blksize     Sets the blocksize to blksize. Valid block sizes are 512,
+bs=blksize
+               Sets the blocksize to blksize. Valid block sizes are 512,
                1024, 2048 and 4096. Like the root option, this should
                never be necessary, as the affs can figure it out itself.
 
-quiet          The file system will not return an error for disallowed
+quiet
+               The file system will not return an error for disallowed
                mode changes.
 
-verbose                The volume name, file system type and block size will
+verbose
+               The volume name, file system type and block size will
                be written to the syslog when the filesystem is mounted.
 
-mufs           The filesystem is really a muFS, also it doesn't
+mufs
+               The filesystem is really a muFS, also it doesn't
                identify itself as one. This option is necessary if
                the filesystem wasn't formatted as muFS, but is used
                as one.
 
-prefix=path    Path will be prefixed to every absolute path name of
+prefix=path
+               Path will be prefixed to every absolute path name of
                symbolic links on an AFFS partition. Default = "/".
                (See below.)
 
-volume=name    When symbolic links with an absolute path are created
+volume=name
+               When symbolic links with an absolute path are created
                on an AFFS partition, name will be prepended as the
                volume name. Default = "" (empty string).
                (See below.)
@@ -119,7 +136,7 @@ The Linux rwxrwxrwx file mode is handled as follows:
 
   - All other flags (suid, sgid, ...) are ignored and will
     not be retained.
-    
+
 Newly created files and directories will get the user and group ID
 of the current user and a mode according to the umask.
 
@@ -148,11 +165,13 @@ might be "User", "WB" and "Graphics", the mount points /amiga/User,
 Examples
 ========
 
-Command line:
+Command line::
+
     mount  Archive/Amiga/Workbench3.1.adf /mnt -t affs -o loop,verbose
     mount  /dev/sda3 /Amiga -t affs
 
-/etc/fstab entry:
+/etc/fstab entry::
+
     /dev/sdb5  /amiga/Workbench    affs    noauto,user,exec,verbose 0 0
 
 IMPORTANT NOTE
@@ -170,7 +189,8 @@ before booting Windows!
 
 If the damage is already done, the following should fix the RDB
 (where <disk> is the device name).
-DO AT YOUR OWN RISK:
+
+DO AT YOUR OWN RISK::
 
   dd if=/dev/<disk> of=rdb.tmp count=1
   cp rdb.tmp rdb.fixed
@@ -189,10 +209,14 @@ By default, filenames are truncated to 30 characters without warning.
 'nofilenametruncate' mount option can change that behavior.
 
 Case is ignored by the affs in filename matching, but Linux shells
-do care about the case. Example (with /wb being an affs mounted fs):
+do care about the case. Example (with /wb being an affs mounted fs)::
+
     rm /wb/WRONGCASE
-will remove /mnt/wrongcase, but
+
+will remove /mnt/wrongcase, but::
+
     rm /wb/WR*
+
 will not since the names are matched by the shell.
 
 The block allocation is designed for hard disk partitions. If more
@@ -219,4 +243,4 @@ due to an incompatibility with the Amiga floppy controller.
 
 If you are interested in an Amiga Emulator for Linux, look at
 
-http://web.archive.org/web/*/http://www.freiburg.linux.de/~uae/
+http://web.archive.org/web/%2E/http://www.freiburg.linux.de/~uae/
similarity index 90%
rename from Documentation/filesystems/afs.txt
rename to Documentation/filesystems/afs.rst
index 8c6ea7b..c4ec39a 100644 (file)
@@ -1,8 +1,10 @@
-                            ====================
-                            kAFS: AFS FILESYSTEM
-                            ====================
+.. SPDX-License-Identifier: GPL-2.0
 
-Contents:
+====================
+kAFS: AFS FILESYSTEM
+====================
+
+.. Contents:
 
  - Overview.
  - Usage.
@@ -14,8 +16,7 @@ Contents:
  - The @sys substitution.
 
 
-========
-OVERVIEW
+Overview
 ========
 
 This filesystem provides a fairly simple secure AFS filesystem driver. It is
@@ -35,35 +36,33 @@ It does not yet support the following AFS features:
  (*) pioctl() system call.
 
 
-===========
-COMPILATION
+Compilation
 ===========
 
 The filesystem should be enabled by turning on the kernel configuration
-options:
+options::
 
        CONFIG_AF_RXRPC         - The RxRPC protocol transport
        CONFIG_RXKAD            - The RxRPC Kerberos security handler
        CONFIG_AFS              - The AFS filesystem
 
-Additionally, the following can be turned on to aid debugging:
+Additionally, the following can be turned on to aid debugging::
 
        CONFIG_AF_RXRPC_DEBUG   - Permit AF_RXRPC debugging to be enabled
        CONFIG_AFS_DEBUG        - Permit AFS debugging to be enabled
 
 They permit the debugging messages to be turned on dynamically by manipulating
-the masks in the following files:
+the masks in the following files::
 
        /sys/module/af_rxrpc/parameters/debug
        /sys/module/kafs/parameters/debug
 
 
-=====
-USAGE
+Usage
 =====
 
 When inserting the driver modules the root cell must be specified along with a
-list of volume location server IP addresses:
+list of volume location server IP addresses::
 
        modprobe rxrpc
        modprobe kafs rootcell=cambridge.redhat.com:172.16.18.73:172.16.18.91
@@ -77,14 +76,14 @@ The second module is the kerberos RxRPC security driver, and the third module
 is the actual filesystem driver for the AFS filesystem.
 
 Once the module has been loaded, more modules can be added by the following
-procedure:
+procedure::
 
        echo add grand.central.org 18.9.48.14:128.2.203.61:130.237.48.87 >/proc/fs/afs/cells
 
 Where the parameters to the "add" command are the name of a cell and a list of
 volume location servers within that cell, with the latter separated by colons.
 
-Filesystems can be mounted anywhere by commands similar to the following:
+Filesystems can be mounted anywhere by commands similar to the following::
 
        mount -t afs "%cambridge.redhat.com:root.afs." /afs
        mount -t afs "#cambridge.redhat.com:root.cell." /afs/cambridge
@@ -104,8 +103,7 @@ named volume will be looked up in the cell specified during modprobe.
 Additional cells can be added through /proc (see later section).
 
 
-===========
-MOUNTPOINTS
+Mountpoints
 ===========
 
 AFS has a concept of mountpoints. In AFS terms, these are specially formatted
@@ -123,42 +121,40 @@ culled first.  If all are culled, then the requested volume will also be
 unmounted, otherwise error EBUSY will be returned.
 
 This can be used by the administrator to attempt to unmount the whole AFS tree
-mounted on /afs in one go by doing:
+mounted on /afs in one go by doing::
 
        umount /afs
 
 
-============
-DYNAMIC ROOT
+Dynamic Root
 ============
 
 A mount option is available to create a serverless mount that is only usable
-for dynamic lookup.  Creating such a mount can be done by, for example:
+for dynamic lookup.  Creating such a mount can be done by, for example::
 
        mount -t afs none /afs -o dyn
 
 This creates a mount that just has an empty directory at the root.  Attempting
 to look up a name in this directory will cause a mountpoint to be created that
-looks up a cell of the same name, for example:
+looks up a cell of the same name, for example::
 
        ls /afs/grand.central.org/
 
 
-===============
-PROC FILESYSTEM
+Proc Filesystem
 ===============
 
 The AFS modules creates a "/proc/fs/afs/" directory and populates it:
 
   (*) A "cells" file that lists cells currently known to the afs module and
-      their usage counts:
+      their usage counts::
 
        [root@andromeda ~]# cat /proc/fs/afs/cells
        USE NAME
          3 cambridge.redhat.com
 
   (*) A directory per cell that contains files that list volume location
-      servers, volumes, and active servers known within that cell.
+      servers, volumes, and active servers known within that cell::
 
        [root@andromeda ~]# cat /proc/fs/afs/cambridge.redhat.com/servers
        USE ADDR            STATE
@@ -171,8 +167,7 @@ The AFS modules creates a "/proc/fs/afs/" directory and populates it:
          1 Val 20000000 20000001 20000002 root.afs
 
 
-=================
-THE CELL DATABASE
+The Cell Database
 =================
 
 The filesystem maintains an internal database of all the cells it knows and the
@@ -181,7 +176,7 @@ the system belongs is added to the database when modprobe is performed by the
 "rootcell=" argument or, if compiled in, using a "kafs.rootcell=" argument on
 the kernel command line.
 
-Further cells can be added by commands similar to the following:
+Further cells can be added by commands similar to the following::
 
        echo add CELLNAME VLADDR[:VLADDR][:VLADDR]... >/proc/fs/afs/cells
        echo add grand.central.org 18.9.48.14:128.2.203.61:130.237.48.87 >/proc/fs/afs/cells
@@ -189,8 +184,7 @@ Further cells can be added by commands similar to the following:
 No other cell database operations are available at this time.
 
 
-========
-SECURITY
+Security
 ========
 
 Secure operations are initiated by acquiring a key using the klog program.  A
@@ -198,17 +192,17 @@ very primitive klog program is available at:
 
        http://people.redhat.com/~dhowells/rxrpc/klog.c
 
-This should be compiled by:
+This should be compiled by::
 
        make klog LDLIBS="-lcrypto -lcrypt -lkrb4 -lkeyutils"
 
-And then run as:
+And then run as::
 
        ./klog
 
 Assuming it's successful, this adds a key of type RxRPC, named for the service
 and cell, eg: "afs@<cellname>".  This can be viewed with the keyctl program or
-by cat'ing /proc/keys:
+by cat'ing /proc/keys::
 
        [root@andromeda ~]# keyctl show
        Session Keyring
@@ -232,20 +226,19 @@ socket), then the operations on the file will be made with key that was used to
 open the file.
 
 
-=====================
-THE @SYS SUBSTITUTION
+The @sys Substitution
 =====================
 
 The list of up to 16 @sys substitutions for the current network namespace can
-be configured by writing a list to /proc/fs/afs/sysname:
+be configured by writing a list to /proc/fs/afs/sysname::
 
        [root@andromeda ~]# echo foo amd64_linux_26 >/proc/fs/afs/sysname
 
-or cleared entirely by writing an empty list:
+or cleared entirely by writing an empty list::
 
        [root@andromeda ~]# echo >/proc/fs/afs/sysname
 
-The current list for current network namespace can be retrieved by:
+The current list for current network namespace can be retrieved by::
 
        [root@andromeda ~]# cat /proc/fs/afs/sysname
        foo
@@ -1,4 +1,6 @@
+.. SPDX-License-Identifier: GPL-2.0
 
+====================================================================
 Miscellaneous Device control operations for the autofs kernel module
 ====================================================================
 
@@ -36,24 +38,24 @@ For example, there are two types of automount maps, direct (in the kernel
 module source you will see a third type called an offset, which is just
 a direct mount in disguise) and indirect.
 
-Here is a master map with direct and indirect map entries:
+Here is a master map with direct and indirect map entries::
 
-/-      /etc/auto.direct
-/test   /etc/auto.indirect
+    /-      /etc/auto.direct
+    /test   /etc/auto.indirect
 
-and the corresponding map files:
+and the corresponding map files::
 
-/etc/auto.direct:
+    /etc/auto.direct:
 
-/automount/dparse/g6  budgie:/autofs/export1
-/automount/dparse/g1  shark:/autofs/export1
-and so on.
+    /automount/dparse/g6  budgie:/autofs/export1
+    /automount/dparse/g1  shark:/autofs/export1
+    and so on.
 
-/etc/auto.indirect:
+/etc/auto.indirect::
 
-g1    shark:/autofs/export1
-g6    budgie:/autofs/export1
-and so on.
+    g1    shark:/autofs/export1
+    g6    budgie:/autofs/export1
+    and so on.
 
 For the above indirect map an autofs file system is mounted on /test and
 mounts are triggered for each sub-directory key by the inode lookup
@@ -69,23 +71,23 @@ use the follow_link inode operation to trigger the mount.
 But, each entry in direct and indirect maps can have offsets (making
 them multi-mount map entries).
 
-For example, an indirect mount map entry could also be:
+For example, an indirect mount map entry could also be::
 
-g1  \
-   /        shark:/autofs/export5/testing/test \
-   /s1      shark:/autofs/export/testing/test/s1 \
-   /s2      shark:/autofs/export5/testing/test/s2 \
-   /s1/ss1  shark:/autofs/export1 \
-   /s2/ss2  shark:/autofs/export2
+    g1  \
+    /        shark:/autofs/export5/testing/test \
+    /s1      shark:/autofs/export/testing/test/s1 \
+    /s2      shark:/autofs/export5/testing/test/s2 \
+    /s1/ss1  shark:/autofs/export1 \
+    /s2/ss2  shark:/autofs/export2
 
-and a similarly a direct mount map entry could also be:
+and a similarly a direct mount map entry could also be::
 
-/automount/dparse/g1 \
-    /       shark:/autofs/export5/testing/test \
-    /s1     shark:/autofs/export/testing/test/s1 \
-    /s2     shark:/autofs/export5/testing/test/s2 \
-    /s1/ss1 shark:/autofs/export2 \
-    /s2/ss2 shark:/autofs/export2
+    /automount/dparse/g1 \
+       /       shark:/autofs/export5/testing/test \
+       /s1     shark:/autofs/export/testing/test/s1 \
+       /s2     shark:/autofs/export5/testing/test/s2 \
+       /s1/ss1 shark:/autofs/export2 \
+       /s2/ss2 shark:/autofs/export2
 
 One of the issues with version 4 of autofs was that, when mounting an
 entry with a large number of offsets, possibly with nesting, we needed
@@ -170,32 +172,32 @@ autofs Miscellaneous Device mount control interface
 The control interface is opening a device node, typically /dev/autofs.
 
 All the ioctls use a common structure to pass the needed parameter
-information and return operation results:
-
-struct autofs_dev_ioctl {
-       __u32 ver_major;
-       __u32 ver_minor;
-       __u32 size;             /* total size of data passed in
-                                * including this struct */
-       __s32 ioctlfd;          /* automount command fd */
-
-       /* Command parameters */
-       union {
-               struct args_protover            protover;
-               struct args_protosubver         protosubver;
-               struct args_openmount           openmount;
-               struct args_ready               ready;
-               struct args_fail                fail;
-               struct args_setpipefd           setpipefd;
-               struct args_timeout             timeout;
-               struct args_requester           requester;
-               struct args_expire              expire;
-               struct args_askumount           askumount;
-               struct args_ismountpoint        ismountpoint;
-       };
-
-       char path[0];
-};
+information and return operation results::
+
+    struct autofs_dev_ioctl {
+           __u32 ver_major;
+           __u32 ver_minor;
+           __u32 size;             /* total size of data passed in
+                                   * including this struct */
+           __s32 ioctlfd;          /* automount command fd */
+
+           /* Command parameters */
+           union {
+                   struct args_protover                protover;
+                   struct args_protosubver             protosubver;
+                   struct args_openmount               openmount;
+                   struct args_ready           ready;
+                   struct args_fail            fail;
+                   struct args_setpipefd               setpipefd;
+                   struct args_timeout         timeout;
+                   struct args_requester               requester;
+                   struct args_expire          expire;
+                   struct args_askumount               askumount;
+                   struct args_ismountpoint    ismountpoint;
+           };
+
+           char path[0];
+    };
 
 The ioctlfd field is a mount point file descriptor of an autofs mount
 point. It is returned by the open call and is used by all calls except
@@ -212,7 +214,7 @@ is used account for the increased structure length when translating the
 structure sent from user space.
 
 This structure can be initialized before setting specific fields by using
-the void function call init_autofs_dev_ioctl(struct autofs_dev_ioctl *).
+the void function call init_autofs_dev_ioctl(``struct autofs_dev_ioctl *``).
 
 All of the ioctls perform a copy of this structure from user space to
 kernel space and return -EINVAL if the size parameter is smaller than
similarity index 83%
rename from Documentation/filesystems/befs.txt
rename to Documentation/filesystems/befs.rst
index da45e6c..79f9740 100644 (file)
@@ -1,48 +1,54 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+=========================
 BeOS filesystem for Linux
+=========================
 
 Document last updated: Dec 6, 2001
 
-WARNING
+Warning
 =======
 Make sure you understand that this is alpha software.  This means that the
-implementation is neither complete nor well-tested. 
+implementation is neither complete nor well-tested.
 
 I DISCLAIM ALL RESPONSIBILITY FOR ANY POSSIBLE BAD EFFECTS OF THIS CODE!
 
-LICENSE
-=====
-This software is covered by the GNU General Public License. 
+License
+=======
+This software is covered by the GNU General Public License.
 See the file COPYING for the complete text of the license.
 Or the GNU website: <http://www.gnu.org/licenses/licenses.html>
 
-AUTHOR
-=====
+Author
+======
 The largest part of the code written by Will Dyson <will_dyson@pobox.com>
 He has been working on the code since Aug 13, 2001. See the changelog for
 details.
 
 Original Author: Makoto Kato <m_kato@ga2.so-net.ne.jp>
+
 His original code can still be found at:
 <http://hp.vector.co.jp/authors/VA008030/bfs/>
+
 Does anyone know of a more current email address for Makoto? He doesn't
 respond to the address given above...
 
 This filesystem doesn't have a maintainer.
 
-WHAT IS THIS DRIVER?
-==================
-This module implements the native filesystem of BeOS http://www.beincorporated.com/ 
+What is this Driver?
+====================
+This module implements the native filesystem of BeOS http://www.beincorporated.com/
 for the linux 2.4.1 and later kernels. Currently it is a read-only
 implementation.
 
 Which is it, BFS or BEFS?
-================
-Be, Inc said, "BeOS Filesystem is officially called BFS, not BeFS". 
+=========================
+Be, Inc said, "BeOS Filesystem is officially called BFS, not BeFS".
 But Unixware Boot Filesystem is called bfs, too. And they are already in
 the kernel. Because of this naming conflict, on Linux the BeOS
 filesystem is called befs.
 
-HOW TO INSTALL
+How to Install
 ==============
 step 1.  Install the BeFS  patch into the source code tree of linux.
 
@@ -54,16 +60,16 @@ is called patch-befs-xxx, you would do the following:
        patch -p1 < /path/to/patch-befs-xxx
 
 if the patching step fails (i.e. there are rejected hunks), you can try to
-figure it out yourself (it shouldn't be hard), or mail the maintainer 
+figure it out yourself (it shouldn't be hard), or mail the maintainer
 (Will Dyson <will_dyson@pobox.com>) for help.
 
 step 2.  Configuration & make kernel
 
 The linux kernel has many compile-time options. Most of them are beyond the
 scope of this document. I suggest the Kernel-HOWTO document as a good general
-reference on this topic. http://www.linuxdocs.org/HOWTOs/Kernel-HOWTO-4.html 
+reference on this topic. http://www.linuxdocs.org/HOWTOs/Kernel-HOWTO-4.html
 
-However, to use the BeFS module, you must enable it at configure time.
+However, to use the BeFS module, you must enable it at configure time::
 
        cd /foo/bar/linux
        make menuconfig (or xconfig)
@@ -82,35 +88,40 @@ step 3.  Install
 See the kernel howto <http://www.linux.com/howto/Kernel-HOWTO.html> for
 instructions on this critical step.
 
-USING BFS
+Using BFS
 =========
 To use the BeOS filesystem, use filesystem type 'befs'.
 
-ex)
+ex::
+
     mount -t befs /dev/fd0 /beos
 
-MOUNT OPTIONS
+Mount Options
 =============
+
+=============  ===========================================================
 uid=nnn        All files in the partition will be owned by user id nnn.
 gid=nnn               All files in the partition will be in group nnn.
 iocharset=xxx  Use xxx as the name of the NLS translation table.
 debug          The driver will output debugging information to the syslog.
+=============  ===========================================================
 
-HOW TO GET LASTEST VERSION
+How to Get Lastest Version
 ==========================
 
 The latest version is currently available at:
 <http://befs-driver.sourceforge.net/>
 
-ANY KNOWN BUGS?
-===========
+Any Known Bugs?
+===============
 As of Jan 20, 2002:
-       
+
        None
 
-SPECIAL THANKS
+Special Thanks
 ==============
 Dominic Giampalo ... Writing "Practical file system design with Be filesystem"
+
 Hiroyuki Yamada  ... Testing LinuxPPC.
 
 
similarity index 71%
rename from Documentation/filesystems/bfs.txt
rename to Documentation/filesystems/bfs.rst
index 843ce91..ce14b90 100644 (file)
@@ -1,4 +1,7 @@
-BFS FILESYSTEM FOR LINUX
+.. SPDX-License-Identifier: GPL-2.0
+
+========================
+BFS Filesystem for Linux
 ========================
 
 The BFS filesystem is used by SCO UnixWare OS for the /stand slice, which
@@ -9,22 +12,22 @@ In order to access /stand partition under Linux you obviously need to
 know the partition number and the kernel must support UnixWare disk slices
 (CONFIG_UNIXWARE_DISKLABEL config option). However BFS support does not
 depend on having UnixWare disklabel support because one can also mount
-BFS filesystem via loopback:
+BFS filesystem via loopback::
 
-# losetup /dev/loop0 stand.img
-# mount -t bfs /dev/loop0 /mnt/stand
+    # losetup /dev/loop0 stand.img
+    # mount -t bfs /dev/loop0 /mnt/stand
 
-where stand.img is a file containing the image of BFS filesystem. 
+where stand.img is a file containing the image of BFS filesystem.
 When you have finished using it and umounted you need to also deallocate
-/dev/loop0 device by:
+/dev/loop0 device by::
 
-# losetup -d /dev/loop0
+    # losetup -d /dev/loop0
 
-You can simplify mounting by just typing:
+You can simplify mounting by just typing::
 
-# mount -t bfs -o loop stand.img /mnt/stand
+    # mount -t bfs -o loop stand.img /mnt/stand
 
-this will allocate the first available loopback device (and load loop.o 
+this will allocate the first available loopback device (and load loop.o
 kernel module if necessary) automatically. If the loopback driver is not
 loaded automatically, make sure that you have compiled the module and
 that modprobe is functioning. Beware that umount will not deallocate
@@ -33,21 +36,21 @@ that modprobe is functioning. Beware that umount will not deallocate
 losetup(8). Read losetup(8) manpage for more info.
 
 To create the BFS image under UnixWare you need to find out first which
-slice contains it. The command prtvtoc(1M) is your friend:
+slice contains it. The command prtvtoc(1M) is your friend::
 
-# prtvtoc /dev/rdsk/c0b0t0d0s0
+    # prtvtoc /dev/rdsk/c0b0t0d0s0
 
 (assuming your root disk is on target=0, lun=0, bus=0, controller=0). Then you
 look for the slice with tag "STAND", which is usually slice 10. With this
-information you can use dd(1) to create the BFS image:
+information you can use dd(1) to create the BFS image::
 
-# umount /stand
-# dd if=/dev/rdsk/c0b0t0d0sa of=stand.img bs=512
+    # umount /stand
+    # dd if=/dev/rdsk/c0b0t0d0sa of=stand.img bs=512
 
 Just in case, you can verify that you have done the right thing by checking
-the magic number:
+the magic number::
 
-# od -Ad -tx4 stand.img | more
+    # od -Ad -tx4 stand.img | more
 
 The first 4 bytes should be 0x1badface.
 
similarity index 96%
rename from Documentation/filesystems/btrfs.txt
rename to Documentation/filesystems/btrfs.rst
index f9dad22..d0904f6 100644 (file)
@@ -1,3 +1,6 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+=====
 BTRFS
 =====
 
similarity index 91%
rename from Documentation/filesystems/ceph.txt
rename to Documentation/filesystems/ceph.rst
index b19b6a0..b46a721 100644 (file)
@@ -1,3 +1,6 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+============================
 Ceph Distributed File System
 ============================
 
@@ -15,6 +18,7 @@ Basic features include:
  * Easy deployment: most FS components are userspace daemons
 
 Also,
+
  * Flexible snapshots (on any directory)
  * Recursive accounting (nested files, directories, bytes)
 
@@ -63,7 +67,7 @@ no 'du' or similar recursive scan of the file system is required.
 Finally, Ceph also allows quotas to be set on any directory in the system.
 The quota can restrict the number of bytes or the number of files stored
 beneath that point in the directory hierarchy.  Quotas can be set using
-extended attributes 'ceph.quota.max_files' and 'ceph.quota.max_bytes', eg:
+extended attributes 'ceph.quota.max_files' and 'ceph.quota.max_bytes', eg::
 
  setfattr -n ceph.quota.max_bytes -v 100000000 /some/dir
  getfattr -n ceph.quota.max_bytes /some/dir
@@ -76,7 +80,7 @@ from writing as much data as it needs.
 Mount Syntax
 ============
 
-The basic mount syntax is:
+The basic mount syntax is::
 
  # mount -t ceph monip[:port][,monip2[:port]...]:/[subdir] mnt
 
@@ -84,7 +88,7 @@ You only need to specify a single monitor, as the client will get the
 full list when it connects.  (However, if the monitor you specify
 happens to be down, the mount won't succeed.)  The port can be left
 off if the monitor is using the default.  So if the monitor is at
-1.2.3.4,
+1.2.3.4::
 
  # mount -t ceph 1.2.3.4:/ /mnt/ceph
 
@@ -163,14 +167,14 @@ Mount Options
        available modes are "no" and "clean". The default is "no".
 
        * no: never attempt to reconnect when client detects that it has been
-       blacklisted. Operations will generally fail after being blacklisted.
+         blacklisted. Operations will generally fail after being blacklisted.
 
        * clean: client reconnects to the ceph cluster automatically when it
-       detects that it has been blacklisted. During reconnect, client drops
-       dirty data/metadata, invalidates page caches and writable file handles.
-       After reconnect, file locks become stale because the MDS loses track
-       of them. If an inode contains any stale file locks, read/write on the
-       inode is not allowed until applications release all stale file locks.
+         detects that it has been blacklisted. During reconnect, client drops
+         dirty data/metadata, invalidates page caches and writable file handles.
+         After reconnect, file locks become stale because the MDS loses track
+         of them. If an inode contains any stale file locks, read/write on the
+         inode is not allowed until applications release all stale file locks.
 
 More Information
 ================
@@ -179,8 +183,8 @@ For more information on Ceph, see the home page at
        https://ceph.com/
 
 The Linux kernel client source tree is available at
-       https://github.com/ceph/ceph-client.git
-       git://git.kernel.org/pub/scm/linux/kernel/git/sage/ceph-client.git
+       https://github.com/ceph/ceph-client.git
+       git://git.kernel.org/pub/scm/linux/kernel/git/sage/ceph-client.git
 
 and the source for the full system is at
        https://github.com/ceph/ceph.git
index 0fa1a2c..947b7ec 100644 (file)
@@ -13,7 +13,7 @@ network by utilizing SMB or CIFS protocol.
 
 In order to mount, the network stack will also need to be set up by
 using 'ip=' config option. For more details, see
-Documentation/filesystems/nfs/nfsroot.txt.
+Documentation/admin-guide/nfs/nfsroot.rst.
 
 A CIFS root mount currently requires the use of SMB1+UNIX Extensions
 which is only supported by the Samba server. SMB1 is the older
similarity index 88%
rename from Documentation/filesystems/cramfs.txt
rename to Documentation/filesystems/cramfs.rst
index 8e19a53..afbdbde 100644 (file)
@@ -1,12 +1,15 @@
+.. SPDX-License-Identifier: GPL-2.0
 
-       Cramfs - cram a filesystem onto a small ROM
+===========================================
+Cramfs - cram a filesystem onto a small ROM
+===========================================
 
-cramfs is designed to be simple and small, and to compress things well. 
+cramfs is designed to be simple and small, and to compress things well.
 
 It uses the zlib routines to compress a file one page at a time, and
 allows random page access.  The meta-data is not compressed, but is
 expressed in a very terse representation to make it use much less
-diskspace than traditional filesystems. 
+diskspace than traditional filesystems.
 
 You can't write to a cramfs filesystem (making it compressible and
 compact also makes it _very_ hard to update on-the-fly), so you have to
@@ -28,9 +31,9 @@ issue.
 Hard links are supported, but hard linked files
 will still have a link count of 1 in the cramfs image.
 
-Cramfs directories have no `.' or `..' entries.  Directories (like
+Cramfs directories have no ``.`` or ``..`` entries.  Directories (like
 every other file on cramfs) always have a link count of 1.  (There's
-no need to use -noleaf in `find', btw.)
+no need to use -noleaf in ``find``, btw.)
 
 No timestamps are stored in a cramfs, so these default to the epoch
 (1970 GMT).  Recently-accessed files may have updated timestamps, but
@@ -70,9 +73,9 @@ MTD drivers are cfi_cmdset_0001 (Intel/Sharp CFI flash) or physmap
 (Flash device in physical memory map). MTD partitions based on such devices
 are fine too. Then that device should be specified with the "mtd:" prefix
 as the mount device argument. For example, to mount the MTD device named
-"fs_partition" on the /mnt directory:
+"fs_partition" on the /mnt directory::
 
-$ mount -t cramfs mtd:fs_partition /mnt
+    $ mount -t cramfs mtd:fs_partition /mnt
 
 To boot a kernel with this as root filesystem, suffice to specify
 something like "root=mtd:fs_partition" on the kernel command line.
@@ -90,6 +93,7 @@ https://github.com/npitre/cramfs-tools
 For /usr/share/magic
 --------------------
 
+=====  ======================= =======================
 0      ulelong 0x28cd3d45      Linux cramfs offset 0
 >4     ulelong x               size %d
 >8     ulelong x               flags 0x%x
@@ -110,6 +114,7 @@ For /usr/share/magic
 >552   ulelong x               fsid.blocks %d
 >556   ulelong x               fsid.files %d
 >560   string  >\0             name "%.16s"
+=====  ======================= =======================
 
 
 Hacker Notes
similarity index 91%
rename from Documentation/filesystems/debugfs.txt
rename to Documentation/filesystems/debugfs.rst
index 55336a4..80f332b 100644 (file)
@@ -1,4 +1,11 @@
-Copyright 2009 Jonathan Corbet <corbet@lwn.net>
+.. SPDX-License-Identifier: GPL-2.0
+.. include:: <isonum.txt>
+
+=======
+DebugFS
+=======
+
+Copyright |copy| 2009 Jonathan Corbet <corbet@lwn.net>
 
 Debugfs exists as a simple way for kernel developers to make information
 available to user space.  Unlike /proc, which is only meant for information
@@ -6,11 +13,11 @@ about a process, or sysfs, which has strict one-value-per-file rules,
 debugfs has no rules at all.  Developers can put any information they want
 there.  The debugfs filesystem is also intended to not serve as a stable
 ABI to user space; in theory, there are no stability constraints placed on
-files exported there.  The real world is not always so simple, though [1];
+files exported there.  The real world is not always so simple, though [1]_;
 even debugfs interfaces are best designed with the idea that they will need
 to be maintained forever.
 
-Debugfs is typically mounted with a command like:
+Debugfs is typically mounted with a command like::
 
     mount -t debugfs none /sys/kernel/debug
 
@@ -23,7 +30,7 @@ Note that the debugfs API is exported GPL-only to modules.
 
 Code using debugfs should include <linux/debugfs.h>.  Then, the first order
 of business will be to create at least one directory to hold a set of
-debugfs files:
+debugfs files::
 
     struct dentry *debugfs_create_dir(const char *name, struct dentry *parent);
 
@@ -36,7 +43,7 @@ something went wrong.  If ERR_PTR(-ENODEV) is returned, that is an
 indication that the kernel has been built without debugfs support and none
 of the functions described below will work.
 
-The most general way to create a file within a debugfs directory is with:
+The most general way to create a file within a debugfs directory is with::
 
     struct dentry *debugfs_create_file(const char *name, umode_t mode,
                                       struct dentry *parent, void *data,
@@ -53,7 +60,7 @@ ERR_PTR(-ERROR) on error, or ERR_PTR(-ENODEV) if debugfs support is
 missing.
 
 Create a file with an initial size, the following function can be used
-instead:
+instead::
 
     struct dentry *debugfs_create_file_size(const char *name, umode_t mode,
                                struct dentry *parent, void *data,
@@ -66,7 +73,7 @@ as the function debugfs_create_file.
 In a number of cases, the creation of a set of file operations is not
 actually necessary; the debugfs code provides a number of helper functions
 for simple situations.  Files containing a single integer value can be
-created with any of:
+created with any of::
 
     void debugfs_create_u8(const char *name, umode_t mode,
                           struct dentry *parent, u8 *value);
@@ -80,7 +87,7 @@ created with any of:
 These files support both reading and writing the given value; if a specific
 file should not be written to, simply set the mode bits accordingly.  The
 values in these files are in decimal; if hexadecimal is more appropriate,
-the following functions can be used instead:
+the following functions can be used instead::
 
     void debugfs_create_x8(const char *name, umode_t mode,
                           struct dentry *parent, u8 *value);
@@ -94,7 +101,7 @@ the following functions can be used instead:
 These functions are useful as long as the developer knows the size of the
 value to be exported.  Some types can have different widths on different
 architectures, though, complicating the situation somewhat.  There are
-functions meant to help out in such special cases:
+functions meant to help out in such special cases::
 
     void debugfs_create_size_t(const char *name, umode_t mode,
                               struct dentry *parent, size_t *value);
@@ -103,7 +110,7 @@ As might be expected, this function will create a debugfs file to represent
 a variable of type size_t.
 
 Similarly, there are helpers for variables of type unsigned long, in decimal
-and hexadecimal:
+and hexadecimal::
 
     struct dentry *debugfs_create_ulong(const char *name, umode_t mode,
                                        struct dentry *parent,
@@ -111,7 +118,7 @@ and hexadecimal:
     void debugfs_create_xul(const char *name, umode_t mode,
                            struct dentry *parent, unsigned long *value);
 
-Boolean values can be placed in debugfs with:
+Boolean values can be placed in debugfs with::
 
     struct dentry *debugfs_create_bool(const char *name, umode_t mode,
                                       struct dentry *parent, bool *value);
@@ -120,7 +127,7 @@ A read on the resulting file will yield either Y (for non-zero values) or
 N, followed by a newline.  If written to, it will accept either upper- or
 lower-case values, or 1 or 0.  Any other input will be silently ignored.
 
-Also, atomic_t values can be placed in debugfs with:
+Also, atomic_t values can be placed in debugfs with::
 
     void debugfs_create_atomic_t(const char *name, umode_t mode,
                                 struct dentry *parent, atomic_t *value)
@@ -129,7 +136,7 @@ A read of this file will get atomic_t values, and a write of this file
 will set atomic_t values.
 
 Another option is exporting a block of arbitrary binary data, with
-this structure and function:
+this structure and function::
 
     struct debugfs_blob_wrapper {
        void *data;
@@ -151,7 +158,7 @@ If you want to dump a block of registers (something that happens quite
 often during development, even if little such code reaches mainline.
 Debugfs offers two functions: one to make a registers-only file, and
 another to insert a register block in the middle of another sequential
-file.
+file::
 
     struct debugfs_reg32 {
        char *name;
@@ -175,7 +182,7 @@ The "base" argument may be 0, but you may want to build the reg32 array
 using __stringify, and a number of register names (macros) are actually
 byte offsets over a base for the register block.
 
-If you want to dump an u32 array in debugfs, you can create file with:
+If you want to dump an u32 array in debugfs, you can create file with::
 
     void debugfs_create_u32_array(const char *name, umode_t mode,
                        struct dentry *parent,
@@ -185,7 +192,7 @@ The "array" argument provides data, and the "elements" argument is
 the number of elements in the array. Note: Once array is created its
 size can not be changed.
 
-There is a helper function to create device related seq_file:
+There is a helper function to create device related seq_file::
 
    struct dentry *debugfs_create_devm_seqfile(struct device *dev,
                                const char *name,
@@ -197,14 +204,14 @@ The "dev" argument is the device related to this debugfs file, and
 the "read_fn" is a function pointer which to be called to print the
 seq_file content.
 
-There are a couple of other directory-oriented helper functions:
+There are a couple of other directory-oriented helper functions::
 
-    struct dentry *debugfs_rename(struct dentry *old_dir, 
+    struct dentry *debugfs_rename(struct dentry *old_dir,
                                  struct dentry *old_dentry,
-                                 struct dentry *new_dir, 
+                                 struct dentry *new_dir,
                                  const char *new_name);
 
-    struct dentry *debugfs_create_symlink(const char *name, 
+    struct dentry *debugfs_create_symlink(const char *name,
                                           struct dentry *parent,
                                          const char *target);
 
@@ -219,7 +226,7 @@ module is unloaded without explicitly removing debugfs entries, the result
 will be a lot of stale pointers and no end of highly antisocial behavior.
 So all debugfs users - at least those which can be built as modules - must
 be prepared to remove all files and directories they create there.  A file
-can be removed with:
+can be removed with::
 
     void debugfs_remove(struct dentry *dentry);
 
@@ -229,7 +236,7 @@ be removed.
 Once upon a time, debugfs users were required to remember the dentry
 pointer for every debugfs file they created so that all files could be
 cleaned up.  We live in more civilized times now, though, and debugfs users
-can call:
+can call::
 
     void debugfs_remove_recursive(struct dentry *dentry);
 
@@ -237,5 +244,4 @@ If this function is passed a pointer for the dentry corresponding to the
 top-level directory, the entire hierarchy below that directory will be
 removed.
 
-Notes:
-       [1] http://lwn.net/Articles/309298/
+.. [1] http://lwn.net/Articles/309298/
similarity index 86%
rename from Documentation/filesystems/dlmfs.txt
rename to Documentation/filesystems/dlmfs.rst
index fcf4d50..68daaa7 100644 (file)
@@ -1,20 +1,25 @@
-dlmfs
-==================
+.. SPDX-License-Identifier: GPL-2.0
+.. include:: <isonum.txt>
+
+=====
+DLMFS
+=====
+
 A minimal DLM userspace interface implemented via a virtual file
 system.
 
 dlmfs is built with OCFS2 as it requires most of its infrastructure.
 
-Project web page:    http://ocfs2.wiki.kernel.org
-Tools web page:      https://github.com/markfasheh/ocfs2-tools
-OCFS2 mailing lists: http://oss.oracle.com/projects/ocfs2/mailman/
+:Project web page:    http://ocfs2.wiki.kernel.org
+:Tools web page:      https://github.com/markfasheh/ocfs2-tools
+:OCFS2 mailing lists: http://oss.oracle.com/projects/ocfs2/mailman/
 
 All code copyright 2005 Oracle except when otherwise noted.
 
-CREDITS
+Credits
 =======
 
-Some code taken from ramfs which is Copyright (C) 2000 Linus Torvalds
+Some code taken from ramfs which is Copyright |copy| 2000 Linus Torvalds
 and Transmeta Corp.
 
 Mark Fasheh <mark.fasheh@oracle.com>
@@ -96,14 +101,19 @@ operation. If the lock succeeds, you'll get an fd.
 open(2) with O_CREAT to ensure the resource inode is created - dlmfs does
 not automatically create inodes for existing lock resources.
 
+============  ===========================
 Open Flag     Lock Request Type
----------     -----------------
+============  ===========================
 O_RDONLY      Shared Read
 O_RDWR        Exclusive
+============  ===========================
+
 
+============  ===========================
 Open Flag     Resulting Locking Behavior
----------     --------------------------
+============  ===========================
 O_NONBLOCK    Trylock operation
+============  ===========================
 
 You must provide exactly one of O_RDONLY or O_RDWR.
 
similarity index 62%
rename from Documentation/filesystems/ecryptfs.txt
rename to Documentation/filesystems/ecryptfs.rst
index 01d8a08..1f2edef 100644 (file)
@@ -1,14 +1,18 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+======================================================
 eCryptfs: A stacked cryptographic filesystem for Linux
+======================================================
 
 eCryptfs is free software. Please see the file COPYING for details.
 For documentation, please see the files in the doc/ subdirectory.  For
 building and installation instructions please see the INSTALL file.
 
-Maintainer: Phillip Hellewell
-Lead developer: Michael A. Halcrow <mhalcrow@us.ibm.com>
-Developers: Michael C. Thompson
-            Kent Yoder
-Web Site: http://ecryptfs.sf.net
+:Maintainer: Phillip Hellewell
+:Lead developer: Michael A. Halcrow <mhalcrow@us.ibm.com>
+:Developers: Michael C. Thompson
+             Kent Yoder
+:Web Site: http://ecryptfs.sf.net
 
 This software is currently undergoing development. Make sure to
 maintain a backup copy of any data you write into eCryptfs.
@@ -19,34 +23,36 @@ SourceForge site:
 http://sourceforge.net/projects/ecryptfs/
 
 Userspace requirements include:
- - David Howells' userspace keyring headers and libraries (version
-   1.0 or higher), obtainable from
-   http://people.redhat.com/~dhowells/keyutils/
- - Libgcrypt
+
+- David Howells' userspace keyring headers and libraries (version
+  1.0 or higher), obtainable from
+  http://people.redhat.com/~dhowells/keyutils/
+- Libgcrypt
 
 
-NOTES
+.. note::
 
-In the beta/experimental releases of eCryptfs, when you upgrade
-eCryptfs, you should copy the files to an unencrypted location and
-then copy the files back into the new eCryptfs mount to migrate the
-files.
+   In the beta/experimental releases of eCryptfs, when you upgrade
+   eCryptfs, you should copy the files to an unencrypted location and
+   then copy the files back into the new eCryptfs mount to migrate the
+   files.
 
 
-MOUNT-WIDE PASSPHRASE
+Mount-wide Passphrase
+=====================
 
 Create a new directory into which eCryptfs will write its encrypted
 files (i.e., /root/crypt).  Then, create the mount point directory
-(i.e., /mnt/crypt).  Now it's time to mount eCryptfs:
+(i.e., /mnt/crypt).  Now it's time to mount eCryptfs::
 
-mount -t ecryptfs /root/crypt /mnt/crypt
+    mount -t ecryptfs /root/crypt /mnt/crypt
 
 You should be prompted for a passphrase and a salt (the salt may be
 blank).
 
-Try writing a new file:
+Try writing a new file::
 
-echo "Hello, World" > /mnt/crypt/hello.txt
+    echo "Hello, World" > /mnt/crypt/hello.txt
 
 The operation will complete.  Notice that there is a new file in
 /root/crypt that is at least 12288 bytes in size (depending on your
@@ -59,10 +65,13 @@ keyctl clear @u
 Then umount /mnt/crypt and mount again per the instructions given
 above.
 
-cat /mnt/crypt/hello.txt
+::
+
+    cat /mnt/crypt/hello.txt
 
 
-NOTES
+Notes
+=====
 
 eCryptfs version 0.1 should only be mounted on (1) empty directories
 or (2) directories containing files only created by eCryptfs. If you
similarity index 85%
rename from Documentation/filesystems/efivarfs.txt
rename to Documentation/filesystems/efivarfs.rst
index 686a64b..90ac656 100644 (file)
@@ -1,5 +1,8 @@
+.. SPDX-License-Identifier: GPL-2.0
 
+=======================================
 efivarfs - a (U)EFI variable filesystem
+=======================================
 
 The efivarfs filesystem was created to address the shortcomings of
 using entries in sysfs to maintain EFI variables. The old sysfs EFI
@@ -11,7 +14,7 @@ than a single page, sysfs isn't the best interface for this.
 Variables can be created, deleted and modified with the efivarfs
 filesystem.
 
-efivarfs is typically mounted like this,
+efivarfs is typically mounted like this::
 
        mount -t efivarfs none /sys/firmware/efi/efivars
 
similarity index 54%
rename from Documentation/filesystems/erofs.txt
rename to Documentation/filesystems/erofs.rst
index db6d39c..bf14517 100644 (file)
@@ -1,3 +1,9 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+======================================
+Enhanced Read-Only File System - EROFS
+======================================
+
 Overview
 ========
 
@@ -6,6 +12,7 @@ from other read-only file systems, it aims to be designed for flexibility,
 scalability, but be kept simple and high performance.
 
 It is designed as a better filesystem solution for the following scenarios:
+
  - read-only storage media or
 
  - part of a fully trusted read-only solution, which means it needs to be
@@ -17,6 +24,7 @@ It is designed as a better filesystem solution for the following scenarios:
    for those embedded devices with limited memory (ex, smartphone);
 
 Here is the main features of EROFS:
+
  - Little endian on-disk design;
 
  - Currently 4KB block size (nobh) and therefore maximum 16TB address space;
@@ -24,13 +32,17 @@ Here is the main features of EROFS:
  - Metadata & data could be mixed by design;
 
  - 2 inode versions for different requirements:
+
+   =====================  ============  =====================================
                           compact (v1)  extended (v2)
-   Inode metadata size:   32 bytes      64 bytes
-   Max file size:         4 GB          16 EB (also limited by max. vol size)
-   Max uids/gids:         65536         4294967296
-   File change time:      no            yes (64 + 32-bit timestamp)
-   Max hardlinks:         65536         4294967296
-   Metadata reserved:     4 bytes       14 bytes
+   =====================  ============  =====================================
+   Inode metadata size    32 bytes      64 bytes
+   Max file size          4 GB          16 EB (also limited by max. vol size)
+   Max uids/gids          65536         4294967296
+   File change time       no            yes (64 + 32-bit timestamp)
+   Max hardlinks          65536         4294967296
+   Metadata reserved      4 bytes       14 bytes
+   =====================  ============  =====================================
 
  - Support extended attributes (xattrs) as an option;
 
@@ -43,29 +55,36 @@ Here is the main features of EROFS:
 
 The following git tree provides the file system user-space tools under
 development (ex, formatting tool mkfs.erofs):
->> git://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs-utils.git
+
+- git://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs-utils.git
 
 Bugs and patches are welcome, please kindly help us and send to the following
 linux-erofs mailing list:
->> linux-erofs mailing list   <linux-erofs@lists.ozlabs.org>
+
+- linux-erofs mailing list   <linux-erofs@lists.ozlabs.org>
 
 Mount options
 =============
 
+===================    =========================================================
 (no)user_xattr         Setup Extended User Attributes. Note: xattr is enabled
                        by default if CONFIG_EROFS_FS_XATTR is selected.
 (no)acl                Setup POSIX Access Control List. Note: acl is enabled
                        by default if CONFIG_EROFS_FS_POSIX_ACL is selected.
 cache_strategy=%s      Select a strategy for cached decompression from now on:
-                         disabled: In-place I/O decompression only;
-                        readahead: Cache the last incomplete compressed physical
+
+                      ==========  =============================================
+                         disabled  In-place I/O decompression only;
+                        readahead  Cache the last incomplete compressed physical
                                    cluster for further reading. It still does
                                    in-place I/O decompression for the rest
                                    compressed physical clusters;
-                       readaround: Cache the both ends of incomplete compressed
+                       readaround  Cache the both ends of incomplete compressed
                                    physical clusters for further reading.
                                    It still does in-place I/O decompression
                                    for the rest compressed physical clusters.
+                      ==========  =============================================
+===================    =========================================================
 
 On-disk details
 ===============
@@ -73,7 +92,7 @@ On-disk details
 Summary
 -------
 Different from other read-only file systems, an EROFS volume is designed
-to be as simple as possible:
+to be as simple as possible::
 
                                 |-> aligned with the block size
    ____________________________________________________________
@@ -83,41 +102,45 @@ to be as simple as possible:
 
 All data areas should be aligned with the block size, but metadata areas
 may not. All metadatas can be now observed in two different spaces (views):
+
  1. Inode metadata space
+
     Each valid inode should be aligned with an inode slot, which is a fixed
     value (32 bytes) and designed to be kept in line with compact inode size.
 
     Each inode can be directly found with the following formula:
          inode offset = meta_blkaddr * block_size + 32 * nid
 
-                                |-> aligned with 8B
-                                           |-> followed closely
-    + meta_blkaddr blocks                                      |-> another slot
-     _____________________________________________________________________
-    |  ...   | inode |  xattrs  | extents  | data inline | ... | inode ...
-    |________|_______|(optional)|(optional)|__(optional)_|_____|__________
-             |-> aligned with the inode slot size
-                  .                   .
-                .                         .
-              .                              .
-            .                                    .
-          .                                         .
-        .                                              .
-      .____________________________________________________|-> aligned with 4B
-      | xattr_ibody_header | shared xattrs | inline xattrs |
-      |____________________|_______________|_______________|
-      |->    12 bytes    <-|->x * 4 bytes<-|               .
-                          .                .                 .
-                    .                      .                   .
-               .                           .                     .
-           ._______________________________.______________________.
-           | id | id | id | id |  ... | id | ent | ... | ent| ... |
-           |____|____|____|____|______|____|_____|_____|____|_____|
-                                           |-> aligned with 4B
-                                                       |-> aligned with 4B
+    ::
+
+                                   |-> aligned with 8B
+                                           |-> followed closely
+       + meta_blkaddr blocks                                      |-> another slot
+       _____________________________________________________________________
+       |  ...   | inode |  xattrs  | extents  | data inline | ... | inode ...
+       |________|_______|(optional)|(optional)|__(optional)_|_____|__________
+               |-> aligned with the inode slot size
+                   .                   .
+                   .                         .
+               .                              .
+               .                                    .
+           .                                         .
+           .                                              .
+       .____________________________________________________|-> aligned with 4B
+       | xattr_ibody_header | shared xattrs | inline xattrs |
+       |____________________|_______________|_______________|
+       |->    12 bytes    <-|->x * 4 bytes<-|               .
+                           .                .                 .
+                       .                      .                   .
+               .                           .                     .
+           ._______________________________.______________________.
+           | id | id | id | id |  ... | id | ent | ... | ent| ... |
+           |____|____|____|____|______|____|_____|_____|____|_____|
+                                           |-> aligned with 4B
+                                                       |-> aligned with 4B
 
     Inode could be 32 or 64 bytes, which can be distinguished from a common
-    field which all inode versions have -- i_format:
+    field which all inode versions have -- i_format::
 
         __________________               __________________
        |     i_format     |             |     i_format     |
@@ -132,16 +155,19 @@ may not. All metadatas can be now observed in two different spaces (views):
     proper alignment, and they could be optional for different data mappings.
     _currently_ total 4 valid data mappings are supported:
 
+    ==  ====================================================================
      0  flat file data without data inline (no extent);
      1  fixed-sized output data compression (with non-compacted indexes);
      2  flat file data with tail packing data inline (no extent);
      3  fixed-sized output data compression (with compacted indexes, v5.3+).
+    ==  ====================================================================
 
     The size of the optional xattrs is indicated by i_xattr_count in inode
     header. Large xattrs or xattrs shared by many different files can be
     stored in shared xattrs metadata rather than inlined right after inode.
 
  2. Shared xattrs metadata space
+
     Shared xattrs space is similar to the above inode space, started with
     a specific block indicated by xattr_blkaddr, organized one by one with
     proper align.
@@ -149,11 +175,13 @@ may not. All metadatas can be now observed in two different spaces (views):
     Each share xattr can also be directly found by the following formula:
          xattr offset = xattr_blkaddr * block_size + 4 * xattr_id
 
-                           |-> aligned by  4 bytes
-    + xattr_blkaddr blocks                     |-> aligned with 4 bytes
-     _________________________________________________________________________
-    |  ...   | xattr_entry |  xattr data | ... |  xattr_entry | xattr data  ...
-    |________|_____________|_____________|_____|______________|_______________
+    ::
+
+                           |-> aligned by  4 bytes
+       + xattr_blkaddr blocks                     |-> aligned with 4 bytes
+       _________________________________________________________________________
+       |  ...   | xattr_entry |  xattr data | ... |  xattr_entry | xattr data  ...
+       |________|_____________|_____________|_____|______________|_______________
 
 Directories
 -----------
@@ -163,19 +191,21 @@ random file lookup, and all directory entries are _strictly_ recorded in
 alphabetical order in order to support improved prefix binary search
 algorithm (could refer to the related source code).
 
-                 ___________________________
-                /                           |
-               /              ______________|________________
-              /              /              | nameoff1       | nameoffN-1
- ____________.______________._______________v________________v__________
-| dirent | dirent | ... | dirent | filename | filename | ... | filename |
-|___.0___|____1___|_____|___N-1__|____0_____|____1_____|_____|___N-1____|
-     \                           ^
-      \                          |                           * could have
-       \                         |                             trailing '\0'
-        \________________________| nameoff0
+::
+
+                   ___________________________
+                   /                           |
+               /              ______________|________________
+               /              /              | nameoff1       | nameoffN-1
+    ____________.______________._______________v________________v__________
+    | dirent | dirent | ... | dirent | filename | filename | ... | filename |
+    |___.0___|____1___|_____|___N-1__|____0_____|____1_____|_____|___N-1____|
+       \                           ^
+       \                          |                           * could have
+       \                         |                             trailing '\0'
+           \________________________| nameoff0
 
-                             Directory block
+                               Directory block
 
 Note that apart from the offset of the first filename, nameoff0 also indicates
 the total number of directory entries in this block since it is no need to
@@ -184,28 +214,27 @@ introduce another on-disk field at all.
 Compression
 -----------
 Currently, EROFS supports 4KB fixed-sized output transparent file compression,
-as illustrated below:
-
-         |---- Variant-Length Extent ----|-------- VLE --------|----- VLE -----
-         clusterofs                      clusterofs            clusterofs
-         |                               |                     |   logical data
-_________v_______________________________v_____________________v_______________
-... |    .        |             |        .    |             |  .          | ...
-____|____.________|_____________|________.____|_____________|__.__________|____
-    |-> cluster <-|-> cluster <-|-> cluster <-|-> cluster <-|-> cluster <-|
-         size          size          size          size          size
-          .                             .                .                   .
-           .                       .               .                  .
-            .                  .              .                .
-      _______._____________._____________._____________._____________________
-         ... |             |             |             | ... physical data
-      _______|_____________|_____________|_____________|_____________________
-             |-> cluster <-|-> cluster <-|-> cluster <-|
-                  size          size          size
+as illustrated below::
+
+           |---- Variant-Length Extent ----|-------- VLE --------|----- VLE -----
+           clusterofs                      clusterofs            clusterofs
+           |                               |                     |   logical data
+    _________v_______________________________v_____________________v_______________
+    ... |    .        |             |        .    |             |  .          | ...
+    ____|____.________|_____________|________.____|_____________|__.__________|____
+       |-> cluster <-|-> cluster <-|-> cluster <-|-> cluster <-|-> cluster <-|
+           size          size          size          size          size
+           .                             .                .                   .
+           .                       .               .                  .
+               .                  .              .                .
+       _______._____________._____________._____________._____________________
+           ... |             |             |             | ... physical data
+       _______|_____________|_____________|_____________|_____________________
+               |-> cluster <-|-> cluster <-|-> cluster <-|
+                   size          size          size
 
 Currently each on-disk physical cluster can contain 4KB (un)compressed data
 at most. For each logical cluster, there is a corresponding on-disk index to
 describe its cluster type, physical cluster address, etc.
 
 See "struct z_erofs_vle_decompressed_index" in erofs_fs.h for more details.
-
similarity index 91%
rename from Documentation/filesystems/ext2.txt
rename to Documentation/filesystems/ext2.rst
index 94c2cf0..d83dbbb 100644 (file)
@@ -1,3 +1,5 @@
+.. SPDX-License-Identifier: GPL-2.0
+
 
 The Second Extended Filesystem
 ==============================
@@ -14,8 +16,9 @@ Options
 Most defaults are determined by the filesystem superblock, and can be
 set using tune2fs(8). Kernel-determined defaults are indicated by (*).
 
-bsddf                  (*)     Makes `df' act like BSD.
-minixdf                                Makes `df' act like Minix.
+====================    ===     ================================================
+bsddf                  (*)     Makes ``df`` act like BSD.
+minixdf                                Makes ``df`` act like Minix.
 
 check=none, nocheck    (*)     Don't do extra checking of bitmaps on mount
                                (check=normal and check=strict options removed)
@@ -62,6 +65,7 @@ quota, usrquota                       Enable user disk quota support
 
 grpquota                       Enable group disk quota support
                                (requires CONFIG_QUOTA).
+====================    ===     ================================================
 
 noquota option ls silently ignored by ext2.
 
@@ -294,9 +298,9 @@ respective fsck programs.
 If you're exceptionally paranoid, there are 3 ways of making metadata
 writes synchronous on ext2:
 
-per-file if you have the program source: use the O_SYNC flag to open()
-per-file if you don't have the source: use "chattr +S" on the file
-per-filesystem: add the "sync" option to mount (or in /etc/fstab)
+per-file if you have the program source: use the O_SYNC flag to open()
+per-file if you don't have the source: use "chattr +S" on the file
+per-filesystem: add the "sync" option to mount (or in /etc/fstab)
 
 the first and last are not ext2 specific but do force the metadata to
 be written synchronously.  See also Journaling below.
@@ -316,10 +320,12 @@ Most of these limits could be overcome with slight changes in the on-disk
 format and using a compatibility flag to signal the format change (at
 the expense of some compatibility).
 
-Filesystem block size:     1kB        2kB        4kB        8kB
-
-File size limit:          16GB      256GB     2048GB     2048GB
-Filesystem size limit:  2047GB     8192GB    16384GB    32768GB
+=====================  =======    =======    =======   ========
+Filesystem block size      1kB        2kB        4kB        8kB
+=====================  =======    =======    =======   ========
+File size limit           16GB      256GB     2048GB     2048GB
+Filesystem size limit   2047GB     8192GB    16384GB    32768GB
+=====================  =======    =======    =======   ========
 
 There is a 2.4 kernel limit of 2048GB for a single block device, so no
 filesystem larger than that can be created at this time.  There is also
@@ -370,19 +376,24 @@ ext4 and journaling.
 References
 ==========
 
+=======================        ===============================================
 The kernel source      file:/usr/src/linux/fs/ext2/
 e2fsprogs (e2fsck)     http://e2fsprogs.sourceforge.net/
 Design & Implementation        http://e2fsprogs.sourceforge.net/ext2intro.html
 Journaling (ext3)      ftp://ftp.uk.linux.org/pub/linux/sct/fs/jfs/
 Filesystem Resizing    http://ext2resize.sourceforge.net/
-Compression (*)                http://e2compr.sourceforge.net/
+Compression [1]_       http://e2compr.sourceforge.net/
+=======================        ===============================================
 
 Implementations for:
+
+=======================        ===========================================================
 Windows 95/98/NT/2000  http://www.chrysocome.net/explore2fs
-Windows 95 (*)         http://www.yipton.net/content.html#FSDEXT2
-DOS client (*)         ftp://metalab.unc.edu/pub/Linux/system/filesystems/ext2/
-OS/2 (+)               ftp://metalab.unc.edu/pub/Linux/system/filesystems/ext2/
+Windows 95 [1]_                http://www.yipton.net/content.html#FSDEXT2
+DOS client [1]_                ftp://metalab.unc.edu/pub/Linux/system/filesystems/ext2/
+OS/2 [2]_              ftp://metalab.unc.edu/pub/Linux/system/filesystems/ext2/
 RISC OS client         http://www.esw-heim.tu-clausthal.de/~marco/smorbrod/IscaFS/
+=======================        ===========================================================
 
-(*) no longer actively developed/supported (as of Apr 2001)
-(+) no longer actively developed/supported (as of Mar 2009)
+.. [1] no longer actively developed/supported (as of Apr 2001)
+.. [2] no longer actively developed/supported (as of Mar 2009)
similarity index 88%
rename from Documentation/filesystems/ext3.txt
rename to Documentation/filesystems/ext3.rst
index 58758fb..c06cec3 100644 (file)
@@ -1,4 +1,6 @@
+.. SPDX-License-Identifier: GPL-2.0
 
+===============
 Ext3 Filesystem
 ===============
 
similarity index 84%
rename from Documentation/filesystems/f2fs.txt
rename to Documentation/filesystems/f2fs.rst
index 4eb3e2d..d681203 100644 (file)
@@ -1,6 +1,8 @@
-================================================================================
+.. SPDX-License-Identifier: GPL-2.0
+
+==========================================
 WHAT IS Flash-Friendly File System (F2FS)?
-================================================================================
+==========================================
 
 NAND flash memory-based storage devices, such as SSD, eMMC, and SD cards, have
 been equipped on a variety systems ranging from mobile to server systems. Since
@@ -20,14 +22,15 @@ layout, but also for selecting allocation and cleaning algorithms.
 
 The following git tree provides the file system formatting tool (mkfs.f2fs),
 a consistency checking tool (fsck.f2fs), and a debugging tool (dump.f2fs).
->> git://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs-tools.git
+
+- git://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs-tools.git
 
 For reporting bugs and sending patches, please use the following mailing list:
->> linux-f2fs-devel@lists.sourceforge.net
 
-================================================================================
-BACKGROUND AND DESIGN ISSUES
-================================================================================
+- linux-f2fs-devel@lists.sourceforge.net
+
+Background and Design issues
+============================
 
 Log-structured File System (LFS)
 --------------------------------
@@ -61,6 +64,7 @@ needs to reclaim these obsolete blocks seamlessly to users. This job is called
 as a cleaning process.
 
 The process consists of three operations as follows.
+
 1. A victim segment is selected through referencing segment usage table.
 2. It loads parent index structures of all the data in the victim identified by
    segment summary blocks.
@@ -71,9 +75,8 @@ This cleaning job may cause unexpected long delays, so the most important goal
 is to hide the latencies to users. And also definitely, it should reduce the
 amount of valid data to be moved, and move them quickly as well.
 
-================================================================================
-KEY FEATURES
-================================================================================
+Key Features
+============
 
 Flash Awareness
 ---------------
@@ -94,10 +97,11 @@ Cleaning Overhead
 - Support multi-head logs for static/dynamic hot and cold data separation
 - Introduce adaptive logging for efficient block allocation
 
-================================================================================
-MOUNT OPTIONS
-================================================================================
+Mount Options
+=============
 
+
+====================== ============================================================
 background_gc=%s       Turn on/off cleaning operations, namely garbage
                        collection, triggered in background when I/O subsystem is
                        idle. If background_gc=on, it will turn on the garbage
@@ -167,7 +171,10 @@ fault_injection=%d     Enable fault injection in all supported types with
 fault_type=%d          Support configuring fault injection type, should be
                        enabled with fault_injection option, fault type value
                        is shown below, it supports single or combined type.
+
+                       ===================     ===========
                        Type_Name               Type_Value
+                       ===================     ===========
                        FAULT_KMALLOC           0x000000001
                        FAULT_KVMALLOC          0x000000002
                        FAULT_PAGE_ALLOC                0x000000004
@@ -183,6 +190,7 @@ fault_type=%d          Support configuring fault injection type, should be
                        FAULT_CHECKPOINT                0x000001000
                        FAULT_DISCARD           0x000002000
                        FAULT_WRITE_IO          0x000004000
+                       ===================     ===========
 mode=%s                Control block allocation mode which supports "adaptive"
                        and "lfs". In "lfs" mode, there should be no random
                        writes towards main area.
@@ -219,7 +227,7 @@ fsync_mode=%s          Control the policy of fsync. Currently supports "posix",
                        non-atomic files likewise "nobarrier" mount option.
 test_dummy_encryption  Enable dummy encryption, which provides a fake fscrypt
                        context. The fake fscrypt context is used by xfstests.
-checkpoint=%s[:%u[%]]     Set to "disable" to turn off checkpointing. Set to "enable"
+checkpoint=%s[:%u[%]]  Set to "disable" to turn off checkpointing. Set to "enable"
                        to reenable checkpointing. Is enabled by default. While
                        disabled, any unmounting or unexpected shutdowns will cause
                        the filesystem contents to appear as they did when the
@@ -246,22 +254,22 @@ compress_extension=%s  Support adding specified extension, so that f2fs can enab
                        on compression extension list and enable compression on
                        these file by default rather than to enable it via ioctl.
                        For other files, we can still enable compression via ioctl.
+====================== ============================================================
 
-================================================================================
-DEBUGFS ENTRIES
-================================================================================
+Debugfs Entries
+===============
 
 /sys/kernel/debug/f2fs/ contains information about all the partitions mounted as
 f2fs. Each file shows the whole f2fs information.
 
 /sys/kernel/debug/f2fs/status includes:
+
  - major file system information managed by f2fs currently
  - average SIT information about whole segments
  - current memory footprint consumed by f2fs.
 
-================================================================================
-SYSFS ENTRIES
-================================================================================
+Sysfs Entries
+=============
 
 Information about mounted f2fs file systems can be found in
 /sys/fs/f2fs.  Each mounted filesystem will have a directory in
@@ -271,22 +279,24 @@ The files in each per-device directory are shown in table below.
 Files in /sys/fs/f2fs/<devname>
 (see also Documentation/ABI/testing/sysfs-fs-f2fs)
 
-================================================================================
-USAGE
-================================================================================
+Usage
+=====
 
 1. Download userland tools and compile them.
 
 2. Skip, if f2fs was compiled statically inside kernel.
-   Otherwise, insert the f2fs.ko module.
- # insmod f2fs.ko
+   Otherwise, insert the f2fs.ko module::
+
+       # insmod f2fs.ko
 
-3. Create a directory trying to mount
- # mkdir /mnt/f2fs
+3. Create a directory trying to mount::
 
-4. Format the block device, and then mount as f2fs
- # mkfs.f2fs -l label /dev/block_device
- # mount -t f2fs /dev/block_device /mnt/f2fs
+       # mkdir /mnt/f2fs
+
+4. Format the block device, and then mount as f2fs::
+
+       # mkfs.f2fs -l label /dev/block_device
+       # mount -t f2fs /dev/block_device /mnt/f2fs
 
 mkfs.f2fs
 ---------
@@ -294,18 +304,26 @@ The mkfs.f2fs is for the use of formatting a partition as the f2fs filesystem,
 which builds a basic on-disk layout.
 
 The options consist of:
--l [label]   : Give a volume label, up to 512 unicode name.
--a [0 or 1]  : Split start location of each area for heap-based allocation.
-               1 is set by default, which performs this.
--o [int]     : Set overprovision ratio in percent over volume size.
-               5 is set by default.
--s [int]     : Set the number of segments per section.
-               1 is set by default.
--z [int]     : Set the number of sections per zone.
-               1 is set by default.
--e [str]     : Set basic extension list. e.g. "mp3,gif,mov"
--t [0 or 1]  : Disable discard command or not.
-               1 is set by default, which conducts discard.
+
+===============    ===========================================================
+``-l [label]``     Give a volume label, up to 512 unicode name.
+``-a [0 or 1]``    Split start location of each area for heap-based allocation.
+
+                   1 is set by default, which performs this.
+``-o [int]``       Set overprovision ratio in percent over volume size.
+
+                   5 is set by default.
+``-s [int]``       Set the number of segments per section.
+
+                   1 is set by default.
+``-z [int]``       Set the number of sections per zone.
+
+                   1 is set by default.
+``-e [str]``       Set basic extension list. e.g. "mp3,gif,mov"
+``-t [0 or 1]``    Disable discard command or not.
+
+                   1 is set by default, which conducts discard.
+===============    ===========================================================
 
 fsck.f2fs
 ---------
@@ -314,7 +332,8 @@ partition, which examines whether the filesystem metadata and user-made data
 are cross-referenced correctly or not.
 Note that, initial version of the tool does not fix any inconsistency.
 
-The options consist of:
+The options consist of::
+
   -d debug level [default:0]
 
 dump.f2fs
@@ -327,20 +346,21 @@ It shows on-disk inode information recognized by a given inode number, and is
 able to dump all the SSA and SIT entries into predefined files, ./dump_ssa and
 ./dump_sit respectively.
 
-The options consist of:
+The options consist of::
+
   -d debug level [default:0]
   -i inode no (hex)
   -s [SIT dump segno from #1~#2 (decimal), for all 0~-1]
   -a [SSA dump segno from #1~#2 (decimal), for all 0~-1]
 
-Examples:
-# dump.f2fs -i [ino] /dev/sdx
-# dump.f2fs -s 0~-1 /dev/sdx (SIT dump)
-# dump.f2fs -a 0~-1 /dev/sdx (SSA dump)
+Examples::
+
+    # dump.f2fs -i [ino] /dev/sdx
+    # dump.f2fs -s 0~-1 /dev/sdx (SIT dump)
+    # dump.f2fs -a 0~-1 /dev/sdx (SSA dump)
 
-================================================================================
-DESIGN
-================================================================================
+Design
+======
 
 On-disk Layout
 --------------
@@ -351,7 +371,7 @@ consists of a set of sections. By default, section and zone sizes are set to one
 segment size identically, but users can easily modify the sizes by mkfs.
 
 F2FS splits the entire volume into six areas, and all the areas except superblock
-consists of multiple segments as described below.
+consists of multiple segments as described below::
 
                                             align with the zone size <-|
                  |-> align with the segment size
@@ -373,28 +393,28 @@ consists of multiple segments as described below.
                                    |__zone__|
 
 - Superblock (SB)
: It is located at the beginning of the partition, and there exist two copies
  It is located at the beginning of the partition, and there exist two copies
    to avoid file system crash. It contains basic partition information and some
    default parameters of f2fs.
 
 - Checkpoint (CP)
: It contains file system information, bitmaps for valid NAT/SIT sets, orphan
  It contains file system information, bitmaps for valid NAT/SIT sets, orphan
    inode lists, and summary entries of current active segments.
 
 - Segment Information Table (SIT)
: It contains segment information such as valid block count and bitmap for the
  It contains segment information such as valid block count and bitmap for the
    validity of all the blocks.
 
 - Node Address Table (NAT)
: It is composed of a block address table for all the node blocks stored in
  It is composed of a block address table for all the node blocks stored in
    Main area.
 
 - Segment Summary Area (SSA)
: It contains summary entries which contains the owner information of all the
  It contains summary entries which contains the owner information of all the
    data and node blocks stored in Main area.
 
 - Main Area
: It contains file and directory data including their indices.
  It contains file and directory data including their indices.
 
 In order to avoid misalignment between file system and flash-based storage, F2FS
 aligns the start block address of CP with the segment size. Also, it aligns the
@@ -414,7 +434,7 @@ One of them always indicates the last valid data, which is called as shadow copy
 mechanism. In addition to CP, NAT and SIT also adopt the shadow copy mechanism.
 
 For file system consistency, each CP points to which NAT and SIT copies are
-valid, as shown as below.
+valid, as shown as below::
 
   +--------+----------+---------+
   |   CP   |    SIT   |   NAT   |
@@ -438,7 +458,7 @@ indirect node. F2FS assigns 4KB to an inode block which contains 923 data block
 indices, two direct node pointers, two indirect node pointers, and one double
 indirect node pointer as described below. One direct node block contains 1018
 data blocks, and one indirect node block contains also 1018 node blocks. Thus,
-one inode block (i.e., a file) covers:
+one inode block (i.e., a file) covers::
 
   4KB * (923 + 2 * 1018 + 2 * 1018 * 1018 + 1018 * 1018 * 1018) := 3.94TB.
 
@@ -473,6 +493,8 @@ A dentry block consists of 214 dentry slots and file names. Therein a bitmap is
 used to represent whether each dentry is valid or not. A dentry block occupies
 4KB with the following composition.
 
+::
+
   Dentry Block(4 K) = bitmap (27 bytes) + reserved (3 bytes) +
                      dentries(11 * 214 bytes) + file name (8 * 214 bytes)
 
@@ -498,23 +520,25 @@ F2FS implements multi-level hash tables for directory structure. Each level has
 a hash table with dedicated number of hash buckets as shown below. Note that
 "A(2B)" means a bucket includes 2 data blocks.
 
-----------------------
-A : bucket
-B : block
-N : MAX_DIR_HASH_DEPTH
-----------------------
+::
+
+    ----------------------
+    A : bucket
+    B : block
+    N : MAX_DIR_HASH_DEPTH
+    ----------------------
 
-level #0   | A(2B)
-           |
-level #1   | A(2B) - A(2B)
-           |
-level #2   | A(2B) - A(2B) - A(2B) - A(2B)
-     .     |   .       .       .       .
-level #N/2 | A(2B) - A(2B) - A(2B) - A(2B) - A(2B) - ... - A(2B)
-     .     |   .       .       .       .
-level #N   | A(4B) - A(4B) - A(4B) - A(4B) - A(4B) - ... - A(4B)
+    level #0   | A(2B)
+           |
+    level #1   | A(2B) - A(2B)
+           |
+    level #2   | A(2B) - A(2B) - A(2B) - A(2B)
+       .     |   .       .       .       .
+    level #N/2 | A(2B) - A(2B) - A(2B) - A(2B) - A(2B) - ... - A(2B)
+       .     |   .       .       .       .
+    level #N   | A(4B) - A(4B) - A(4B) - A(4B) - A(4B) - ... - A(4B)
 
-The number of blocks and buckets are determined by,
+The number of blocks and buckets are determined by::
 
                             ,- 2, if n < MAX_DIR_HASH_DEPTH / 2,
   # of blocks in level #n = |
@@ -532,7 +556,7 @@ dentry consisting of the file name and its inode number. If not found, F2FS
 scans the next hash table in level #1. In this way, F2FS scans hash tables in
 each levels incrementally from 1 to N. In each levels F2FS needs to scan only
 one bucket determined by the following equation, which shows O(log(# of files))
-complexity.
+complexity::
 
   bucket number to scan in level #n = (hash value) % (# of buckets in level #n)
 
@@ -540,7 +564,8 @@ In the case of file creation, F2FS finds empty consecutive slots that cover the
 file name. F2FS searches the empty slots in the hash tables of whole levels from
 1 to N in the same way as the lookup operation.
 
-The following figure shows an example of two cases holding children.
+The following figure shows an example of two cases holding children::
+
        --------------> Dir <--------------
        |                                 |
     child                             child
@@ -611,14 +636,15 @@ Write-hint Policy
 2) whint_mode=user-based. F2FS tries to pass down hints given by
 users.
 
+===================== ======================== ===================
 User                  F2FS                     Block
-----                  ----                     -----
+===================== ======================== ===================
                       META                     WRITE_LIFE_NOT_SET
                       HOT_NODE                 "
                       WARM_NODE                "
                       COLD_NODE                "
-*ioctl(COLD)          COLD_DATA                WRITE_LIFE_EXTREME
-*extension list       "                        "
+ioctl(COLD)           COLD_DATA                WRITE_LIFE_EXTREME
+extension list        "                        "
 
 -- buffered io
 WRITE_LIFE_EXTREME    COLD_DATA                WRITE_LIFE_EXTREME
@@ -635,11 +661,13 @@ WRITE_LIFE_NOT_SET    WARM_DATA                WRITE_LIFE_NOT_SET
 WRITE_LIFE_NONE       "                        WRITE_LIFE_NONE
 WRITE_LIFE_MEDIUM     "                        WRITE_LIFE_MEDIUM
 WRITE_LIFE_LONG       "                        WRITE_LIFE_LONG
+===================== ======================== ===================
 
 3) whint_mode=fs-based. F2FS passes down hints with its policy.
 
+===================== ======================== ===================
 User                  F2FS                     Block
-----                  ----                     -----
+===================== ======================== ===================
                       META                     WRITE_LIFE_MEDIUM;
                       HOT_NODE                 WRITE_LIFE_NOT_SET
                       WARM_NODE                "
@@ -662,6 +690,7 @@ WRITE_LIFE_NOT_SET    WARM_DATA                WRITE_LIFE_NOT_SET
 WRITE_LIFE_NONE       "                        WRITE_LIFE_NONE
 WRITE_LIFE_MEDIUM     "                        WRITE_LIFE_MEDIUM
 WRITE_LIFE_LONG       "                        WRITE_LIFE_LONG
+===================== ======================== ===================
 
 Fallocate(2) Policy
 -------------------
@@ -681,6 +710,7 @@ Allocating disk space
 However, once F2FS receives ioctl(fd, F2FS_IOC_SET_PIN_FILE) in prior to
 fallocate(fd, DEFAULT_MODE), it allocates on-disk blocks addressess having
 zero or random data, which is useful to the below scenario where:
+
  1. create(fd)
  2. ioctl(fd, F2FS_IOC_SET_PIN_FILE)
  3. fallocate(fd, 0, 0, size)
@@ -692,39 +722,41 @@ Compression implementation
 --------------------------
 
 - New term named cluster is defined as basic unit of compression, file can
-be divided into multiple clusters logically. One cluster includes 4 << n
-(n >= 0) logical pages, compression size is also cluster size, each of
-cluster can be compressed or not.
+  be divided into multiple clusters logically. One cluster includes 4 << n
+  (n >= 0) logical pages, compression size is also cluster size, each of
+  cluster can be compressed or not.
 
 - In cluster metadata layout, one special block address is used to indicate
-cluster is compressed one or normal one, for compressed cluster, following
-metadata maps cluster to [1, 4 << n - 1] physical blocks, in where f2fs
-stores data including compress header and compressed data.
+  cluster is compressed one or normal one, for compressed cluster, following
+  metadata maps cluster to [1, 4 << n - 1] physical blocks, in where f2fs
+  stores data including compress header and compressed data.
 
 - In order to eliminate write amplification during overwrite, F2FS only
-support compression on write-once file, data can be compressed only when
-all logical blocks in file are valid and cluster compress ratio is lower
-than specified threshold.
+  support compression on write-once file, data can be compressed only when
+  all logical blocks in file are valid and cluster compress ratio is lower
+  than specified threshold.
 
 - To enable compression on regular inode, there are three ways:
-* chattr +c file
-* chattr +c dir; touch dir/file
-* mount w/ -o compress_extension=ext; touch file.ext
-
-Compress metadata layout:
-                             [Dnode Structure]
-             +-----------------------------------------------+
-             | cluster 1 | cluster 2 | ......... | cluster N |
-             +-----------------------------------------------+
-             .           .                       .           .
-       .                       .                .                      .
-  .         Compressed Cluster       .        .        Normal Cluster            .
-+----------+---------+---------+---------+  +---------+---------+---------+---------+
-|compr flag| block 1 | block 2 | block 3 |  | block 1 | block 2 | block 3 | block 4 |
-+----------+---------+---------+---------+  +---------+---------+---------+---------+
-           .                             .
-         .                                           .
-       .                                                           .
-      +-------------+-------------+----------+----------------------------+
-      | data length | data chksum | reserved |      compressed data       |
-      +-------------+-------------+----------+----------------------------+
+
+  * chattr +c file
+  * chattr +c dir; touch dir/file
+  * mount w/ -o compress_extension=ext; touch file.ext
+
+Compress metadata layout::
+
+                               [Dnode Structure]
+               +-----------------------------------------------+
+               | cluster 1 | cluster 2 | ......... | cluster N |
+               +-----------------------------------------------+
+               .           .                       .           .
+       .                       .                .                      .
+    .         Compressed Cluster       .        .        Normal Cluster            .
+    +----------+---------+---------+---------+  +---------+---------+---------+---------+
+    |compr flag| block 1 | block 2 | block 3 |  | block 1 | block 2 | block 3 | block 4 |
+    +----------+---------+---------+---------+  +---------+---------+---------+---------+
+           .                             .
+           .                                           .
+       .                                                           .
+       +-------------+-------------+----------+----------------------------+
+       | data length | data chksum | reserved |      compressed data       |
+       +-------------+-------------+----------+----------------------------+
index 8e45506..cd717f9 100644 (file)
@@ -1,7 +1,8 @@
 .. SPDX-License-Identifier: GPL-2.0
-==============
+
+====
 FUSE
-==============
+====
 
 Definitions
 ===========
similarity index 94%
rename from Documentation/filesystems/gfs2-uevents.txt
rename to Documentation/filesystems/gfs2-uevents.rst
index 19a19eb..f162a2c 100644 (file)
@@ -1,14 +1,18 @@
-                              uevents and GFS2
-                             ==================
+.. SPDX-License-Identifier: GPL-2.0
+
+================
+uevents and GFS2
+================
 
 During the lifetime of a GFS2 mount, a number of uevents are generated.
 This document explains what the events are and what they are used
 for (by gfs_controld in gfs2-utils).
 
 A list of GFS2 uevents
------------------------
+======================
 
 1. ADD
+------
 
 The ADD event occurs at mount time. It will always be the first
 uevent generated by the newly created filesystem. If the mount
@@ -21,6 +25,7 @@ with no journal assigned), and read-only (with journal assigned) status
 of the filesystem respectively.
 
 2. ONLINE
+---------
 
 The ONLINE uevent is generated after a successful mount or remount. It
 has the same environment variables as the ADD uevent. The ONLINE
@@ -29,6 +34,7 @@ RDONLY are a relatively recent addition (2.6.32-rc+) and will not
 be generated by older kernels.
 
 3. CHANGE
+---------
 
 The CHANGE uevent is used in two places. One is when reporting the
 successful mount of the filesystem by the first node (FIRSTMOUNT=Done).
@@ -52,6 +58,7 @@ cluster. For this reason the ONLINE uevent was used when adding a new
 uevent for a successful mount or remount.
 
 4. OFFLINE
+----------
 
 The OFFLINE uevent is only generated due to filesystem errors and is used
 as part of the "withdraw" mechanism. Currently this doesn't give any
@@ -59,6 +66,7 @@ information about what the error is, which is something that needs to
 be fixed.
 
 5. REMOVE
+---------
 
 The REMOVE uevent is generated at the end of an unsuccessful mount
 or at the end of a umount of the filesystem. All REMOVE uevents will
@@ -68,9 +76,10 @@ kobject subsystem.
 
 
 Information common to all GFS2 uevents (uevent environment variables)
-----------------------------------------------------------------------
+=====================================================================
 
 1. LOCKTABLE=
+--------------
 
 The LOCKTABLE is a string, as supplied on the mount command
 line (locktable=) or via fstab. It is used as a filesystem label
@@ -78,6 +87,7 @@ as well as providing the information for a lock_dlm mount to be
 able to join the cluster.
 
 2. LOCKPROTO=
+-------------
 
 The LOCKPROTO is a string, and its value depends on what is set
 on the mount command line, or via fstab. It will be either
@@ -85,12 +95,14 @@ lock_nolock or lock_dlm. In the future other lock managers
 may be supported.
 
 3. JOURNALID=
+-------------
 
 If a journal is in use by the filesystem (journals are not
 assigned for spectator mounts) then this will give the
 numeric journal id in all GFS2 uevents.
 
 4. UUID=
+--------
 
 With recent versions of gfs2-utils, mkfs.gfs2 writes a UUID
 into the filesystem superblock. If it exists, this will
similarity index 76%
rename from Documentation/filesystems/gfs2.txt
rename to Documentation/filesystems/gfs2.rst
index cc4f230..8d1ab58 100644 (file)
@@ -1,5 +1,8 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+==================
 Global File System
-------------------
+==================
 
 https://fedorahosted.org/cluster/wiki/HomePage
 
@@ -14,16 +17,18 @@ on one machine show up immediately on all other machines in the cluster.
 GFS uses interchangeable inter-node locking mechanisms, the currently
 supported mechanisms are:
 
-  lock_nolock -- allows gfs to be used as a local file system
+  lock_nolock
+    - allows gfs to be used as a local file system
 
-  lock_dlm -- uses a distributed lock manager (dlm) for inter-node locking
-  The dlm is found at linux/fs/dlm/
+  lock_dlm
+    - uses a distributed lock manager (dlm) for inter-node locking.
+      The dlm is found at linux/fs/dlm/
 
 Lock_dlm depends on user space cluster management systems found
 at the URL above.
 
 To use gfs as a local file system, no external clustering systems are
-needed, simply:
+needed, simply::
 
   $ mkfs -t gfs2 -p lock_nolock -j 1 /dev/block_device
   $ mount -t gfs2 /dev/block_device /dir
@@ -37,9 +42,12 @@ GFS2 is not on-disk compatible with previous versions of GFS, but it
 is pretty close.
 
 The following man pages can be found at the URL above:
+
+  ============         =============================================
   fsck.gfs2            to repair a filesystem
   gfs2_grow            to expand a filesystem online
   gfs2_jadd            to add journals to a filesystem online
   tunegfs2             to manipulate, examine and tune a filesystem
-  gfs2_convert to convert a gfs filesystem to gfs2 in-place
+  gfs2_convert         to convert a gfs filesystem to gfs2 in-place
   mkfs.gfs2            to make a filesystem
+  ============         =============================================
similarity index 80%
rename from Documentation/filesystems/hfs.txt
rename to Documentation/filesystems/hfs.rst
index d096df6..ab17a00 100644 (file)
@@ -1,11 +1,16 @@
-Note: This filesystem doesn't have a maintainer.
+.. SPDX-License-Identifier: GPL-2.0
 
+==================================
 Macintosh HFS Filesystem for Linux
 ==================================
 
-HFS stands for ``Hierarchical File System'' and is the filesystem used
+
+.. Note:: This filesystem doesn't have a maintainer.
+
+
+HFS stands for ``Hierarchical File System`` and is the filesystem used
 by the Mac Plus and all later Macintosh models.  Earlier Macintosh
-models used MFS (``Macintosh File System''), which is not supported,
+models used MFS (``Macintosh File System``), which is not supported,
 MacOS 8.1 and newer support a filesystem called HFS+ that's similar to
 HFS but is extended in various areas.  Use the hfsplus filesystem driver
 to access such filesystems from Linux.
@@ -49,25 +54,25 @@ Writing to HFS Filesystems
 HFS is not a UNIX filesystem, thus it does not have the usual features you'd
 expect:
 
o You can't modify the set-uid, set-gid, sticky or executable bits or the uid
* You can't modify the set-uid, set-gid, sticky or executable bits or the uid
    and gid of files.
o You can't create hard- or symlinks, device files, sockets or FIFOs.
* You can't create hard- or symlinks, device files, sockets or FIFOs.
 
 HFS does on the other have the concepts of multiple forks per file.  These
 non-standard forks are represented as hidden additional files in the normal
 filesystems namespace which is kind of a cludge and makes the semantics for
 the a little strange:
 
o You can't create, delete or rename resource forks of files or the
* You can't create, delete or rename resource forks of files or the
    Finder's metadata.
o They are however created (with default values), deleted and renamed
* They are however created (with default values), deleted and renamed
    along with the corresponding data fork or directory.
o Copying files to a different filesystem will loose those attributes
* Copying files to a different filesystem will loose those attributes
    that are essential for MacOS to work.
 
 
 Creating HFS filesystems
-===================================
+========================
 
 The hfsutils package from Robert Leslie contains a program called
 hformat that can be used to create HFS filesystem. See
similarity index 95%
rename from Documentation/filesystems/hfsplus.txt
rename to Documentation/filesystems/hfsplus.rst
index 59f7569..f02f4f5 100644 (file)
@@ -1,4 +1,6 @@
+.. SPDX-License-Identifier: GPL-2.0
 
+======================================
 Macintosh HFSPlus Filesystem for Linux
 ======================================
 
similarity index 66%
rename from Documentation/filesystems/hpfs.txt
rename to Documentation/filesystems/hpfs.rst
index 74630bd..0db1522 100644 (file)
@@ -1,13 +1,21 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+====================
 Read/Write HPFS 2.09
+====================
+
 1998-2004, Mikulas Patocka
 
-email: mikulas@artax.karlin.mff.cuni.cz
-homepage: http://artax.karlin.mff.cuni.cz/~mikulas/vyplody/hpfs/index-e.cgi
+:email: mikulas@artax.karlin.mff.cuni.cz
+:homepage: http://artax.karlin.mff.cuni.cz/~mikulas/vyplody/hpfs/index-e.cgi
 
-CREDITS:
+Credits
+=======
 Chris Smith, 1993, original read-only HPFS, some code and hpfs structures file
        is taken from it
+
 Jacques Gelinas, MSDos mmap, Inspired by fs/nfs/mmap.c (Jon Tombs 15 Aug 1993)
+
 Werner Almesberger, 1992, 1993, MSDos option parser & CR/LF conversion
 
 Mount options
@@ -50,6 +58,7 @@ timeshift=(-)nnn (default 0)
 
 
 File names
+==========
 
 As in OS/2, filenames are case insensitive. However, shell thinks that names
 are case sensitive, so for example when you create a file FOO, you can use
@@ -64,6 +73,7 @@ access it under names 'a.', 'a..', 'a .  . . ' etc.
 
 
 Extended attributes
+===================
 
 On HPFS partitions, OS/2 can associate to each file a special information called
 extended attributes. Extended attributes are pairs of (key,value) where key is
@@ -88,6 +98,7 @@ values doesn't work.
 
 
 Symlinks
+========
 
 You can do symlinks on HPFS partition, symlinks are achieved by setting extended
 attribute named "SYMLINK" with symlink value. Like on ext2, you can chown and
@@ -101,6 +112,7 @@ to analyze or change OS2SYS.INI.
 
 
 Codepages
+=========
 
 HPFS can contain several uppercasing tables for several codepages and each
 file has a pointer to codepage its name is in. However OS/2 was created in
@@ -128,6 +140,7 @@ this codepage - if you don't try to do what I described above :-)
 
 
 Known bugs
+==========
 
 HPFS386 on OS/2 server is not supported. HPFS386 installed on normal OS/2 client
 should work. If you have OS/2 server, use only read-only mode. I don't know how
@@ -152,7 +165,8 @@ would result in directory tree splitting, that takes disk space. Workaround is
 to delete other files that are leaf (probability that the file is non-leaf is
 about 1/50) or to truncate file first to make some space.
 You encounter this problem only if you have many directories so that
-preallocated directory band is full i.e.
+preallocated directory band is full i.e.::
+
        number_of_directories / size_of_filesystem_in_mb > 4.
 
 You can't delete open directories.
@@ -174,6 +188,7 @@ anybody know what does it mean?
 
 
 What does "unbalanced tree" message mean?
+=========================================
 
 Old versions of this driver created sometimes unbalanced dnode trees. OS/2
 chkdsk doesn't scream if the tree is unbalanced (and sometimes creates
@@ -187,6 +202,7 @@ whole created by this driver, it is BUG - let me know about it.
 
 
 Bugs in OS/2
+============
 
 When you have two (or more) lost directories pointing each to other, chkdsk
 locks up when repairing filesystem.
@@ -199,98 +215,139 @@ File names like "a .b" are marked as 'long' by OS/2 but chkdsk "corrects" it and
 marks them as short (and writes "minor fs error corrected"). This bug is not in
 HPFS386.
 
-Codepage bugs described above.
+Codepage bugs described above
+=============================
 
 If you don't install fixpacks, there are many, many more...
 
 
 History
+=======
+
+====== =========================================================================
+0.90   First public release
+0.91   Fixed bug that caused shooting to memory when write_inode was called on
+       open inode (rarely happened)
+0.92   Fixed a little memory leak in freeing directory inodes
+0.93   Fixed bug that locked up the machine when there were too many filenames
+       with first 15 characters same
+       Fixed write_file to zero file when writing behind file end
+0.94   Fixed a little memory leak when trying to delete busy file or directory
+0.95   Fixed a bug that i_hpfs_parent_dir was not updated when moving files
+1.90   First version for 2.1.1xx kernels
+1.91   Fixed a bug that chk_sectors failed when sectors were at the end of disk
+       Fixed a race-condition when write_inode is called while deleting file
+       Fixed a bug that could possibly happen (with very low probability) when
+       using 0xff in filenames.
+
+       Rewritten locking to avoid race-conditions
+
+       Mount option 'eas' now works
+
+       Fsync no longer returns error
+
+       Files beginning with '.' are marked hidden
+
+       Remount support added
+
+       Alloc is not so slow when filesystem becomes full
+
+       Atimes are no more updated because it slows down operation
+
+       Code cleanup (removed all commented debug prints)
+1.92   Corrected a bug when sync was called just before closing file
+1.93   Modified, so that it works with kernels >= 2.1.131, I don't know if it
+       works with previous versions
+
+       Fixed a possible problem with disks > 64G (but I don't have one, so I can't
+       test it)
+
+       Fixed a file overflow at 2G
+
+       Added new option 'timeshift'
+
+       Changed behaviour on HPFS386: It is now possible to operate on HPFS386 in
+       read-only mode
+
+       Fixed a bug that slowed down alloc and prevented allocating 100% space
+       (this bug was not destructive)
+1.94   Added workaround for one bug in Linux
+
+       Fixed one buffer leak
+
+       Fixed some incompatibilities with large extended attributes (but it's still
+       not 100% ok, I have no info on it and OS/2 doesn't want to create them)
+
+       Rewritten allocation
 
-0.90 First public release
-0.91 Fixed bug that caused shooting to memory when write_inode was called on
-       open inode (rarely happened)
-0.92 Fixed a little memory leak in freeing directory inodes
-0.93 Fixed bug that locked up the machine when there were too many filenames
-       with first 15 characters same
-     Fixed write_file to zero file when writing behind file end
-0.94 Fixed a little memory leak when trying to delete busy file or directory
-0.95 Fixed a bug that i_hpfs_parent_dir was not updated when moving files
-1.90 First version for 2.1.1xx kernels
-1.91 Fixed a bug that chk_sectors failed when sectors were at the end of disk
-     Fixed a race-condition when write_inode is called while deleting file
-     Fixed a bug that could possibly happen (with very low probability) when
-       using 0xff in filenames
-     Rewritten locking to avoid race-conditions
-     Mount option 'eas' now works
-     Fsync no longer returns error
-     Files beginning with '.' are marked hidden
-     Remount support added
-     Alloc is not so slow when filesystem becomes full
-     Atimes are no more updated because it slows down operation
-     Code cleanup (removed all commented debug prints)
-1.92 Corrected a bug when sync was called just before closing file
-1.93 Modified, so that it works with kernels >= 2.1.131, I don't know if it
-       works with previous versions
-     Fixed a possible problem with disks > 64G (but I don't have one, so I can't
-       test it)
-     Fixed a file overflow at 2G
-     Added new option 'timeshift'
-     Changed behaviour on HPFS386: It is now possible to operate on HPFS386 in
-       read-only mode
-     Fixed a bug that slowed down alloc and prevented allocating 100% space
-       (this bug was not destructive)
-1.94 Added workaround for one bug in Linux
-     Fixed one buffer leak
-     Fixed some incompatibilities with large extended attributes (but it's still
-       not 100% ok, I have no info on it and OS/2 doesn't want to create them)
-     Rewritten allocation
-     Fixed a bug with i_blocks (du sometimes didn't display correct values)
-     Directories have no longer archive attribute set (some programs don't like
-       it)
-     Fixed a bug that it set badly one flag in large anode tree (it was not
-       destructive)
-1.95 Fixed one buffer leak, that could happen on corrupted filesystem
-     Fixed one bug in allocation in 1.94
-1.96 Added workaround for one bug in OS/2 (HPFS locked up, HPFS386 reported
-       error sometimes when opening directories in PMSHELL)
-     Fixed a possible bitmap race
-     Fixed possible problem on large disks
-     You can now delete open files
-     Fixed a nondestructive race in rename
-1.97 Support for HPFS v3 (on large partitions)
-     Fixed a bug that it didn't allow creation of files > 128M (it should be 2G)
+       Fixed a bug with i_blocks (du sometimes didn't display correct values)
+
+       Directories have no longer archive attribute set (some programs don't like
+       it)
+
+       Fixed a bug that it set badly one flag in large anode tree (it was not
+       destructive)
+1.95   Fixed one buffer leak, that could happen on corrupted filesystem
+
+       Fixed one bug in allocation in 1.94
+1.96   Added workaround for one bug in OS/2 (HPFS locked up, HPFS386 reported
+       error sometimes when opening directories in PMSHELL)
+
+       Fixed a possible bitmap race
+
+       Fixed possible problem on large disks
+
+       You can now delete open files
+
+       Fixed a nondestructive race in rename
+1.97   Support for HPFS v3 (on large partitions)
+
+       ZFixed a bug that it didn't allow creation of files > 128M
+       (it should be 2G)
 1.97.1 Changed names of global symbols
+
        Fixed a bug when chmoding or chowning root directory
-1.98 Fixed a deadlock when using old_readdir
-     Better directory handling; workaround for "unbalanced tree" bug in OS/2
-1.99 Corrected a possible problem when there's not enough space while deleting
-       file
-     Now it tries to truncate the file if there's not enough space when deleting
-     Removed a lot of redundant code
-2.00 Fixed a bug in rename (it was there since 1.96)
-     Better anti-fragmentation strategy
-2.01 Fixed problem with directory listing over NFS
-     Directory lseek now checks for proper parameters
-     Fixed race-condition in buffer code - it is in all filesystems in Linux;
-        when reading device (cat /dev/hda) while creating files on it, files
-        could be damaged
-2.02 Workaround for bug in breada in Linux. breada could cause accesses beyond
-        end of partition
-2.03 Char, block devices and pipes are correctly created
-     Fixed non-crashing race in unlink (Alexander Viro)
-     Now it works with Japanese version of OS/2
-2.04 Fixed error when ftruncate used to extend file
-2.05 Fixed crash when got mount parameters without =
-     Fixed crash when allocation of anode failed due to full disk
-     Fixed some crashes when block io or inode allocation failed
-2.06 Fixed some crash on corrupted disk structures
-     Better allocation strategy
-     Reschedule points added so that it doesn't lock CPU long time
-     It should work in read-only mode on Warp Server
-2.07 More fixes for Warp Server. Now it really works
-2.08 Creating new files is not so slow on large disks
-     An attempt to sync deleted file does not generate filesystem error
-2.09 Fixed error on extremely fragmented files
-
-
- vim: set textwidth=80:
+1.98   Fixed a deadlock when using old_readdir
+       Better directory handling; workaround for "unbalanced tree" bug in OS/2
+1.99   Corrected a possible problem when there's not enough space while deleting
+       file
+
+       Now it tries to truncate the file if there's not enough space when
+       deleting
+
+       Removed a lot of redundant code
+2.00   Fixed a bug in rename (it was there since 1.96)
+       Better anti-fragmentation strategy
+2.01   Fixed problem with directory listing over NFS
+
+       Directory lseek now checks for proper parameters
+
+       Fixed race-condition in buffer code - it is in all filesystems in Linux;
+       when reading device (cat /dev/hda) while creating files on it, files
+       could be damaged
+2.02   Workaround for bug in breada in Linux. breada could cause accesses beyond
+       end of partition
+2.03   Char, block devices and pipes are correctly created
+
+       Fixed non-crashing race in unlink (Alexander Viro)
+
+       Now it works with Japanese version of OS/2
+2.04   Fixed error when ftruncate used to extend file
+2.05   Fixed crash when got mount parameters without =
+
+       Fixed crash when allocation of anode failed due to full disk
+
+       Fixed some crashes when block io or inode allocation failed
+2.06   Fixed some crash on corrupted disk structures
+
+       Better allocation strategy
+
+       Reschedule points added so that it doesn't lock CPU long time
+
+       It should work in read-only mode on Warp Server
+2.07   More fixes for Warp Server. Now it really works
+2.08   Creating new files is not so slow on large disks
+
+       An attempt to sync deleted file does not generate filesystem error
+2.09   Fixed error on extremely fragmented files
+====== =========================================================================
index 386eaad..e7b46da 100644 (file)
@@ -1,3 +1,5 @@
+.. _filesystems_index:
+
 ===============================
 Filesystems in the Linux kernel
 ===============================
@@ -46,8 +48,53 @@ Documentation for filesystem implementations.
 .. toctree::
    :maxdepth: 2
 
+   9p
+   adfs
+   affs
+   afs
    autofs
+   autofs-mount-control
+   befs
+   bfs
+   btrfs
+   ceph
+   cramfs
+   debugfs
+   dlmfs
+   ecryptfs
+   efivarfs
+   erofs
+   ext2
+   ext3
+   f2fs
+   gfs2
+   gfs2-uevents
+   hfs
+   hfsplus
+   hpfs
    fuse
+   inotify
+   isofs
+   nilfs2
+   nfs/index
+   ntfs
+   ocfs2
+   ocfs2-online-filecheck
+   omfs
+   orangefs
    overlayfs
+   proc
+   qnx6
+   ramfs-rootfs-initramfs
+   relay
+   romfs
+   squashfs
+   sysfs
+   sysv-fs
+   tmpfs
+   ubifs
+   ubifs-authentication.rst
+   udf
    virtiofs
    vfat
+   zonefs
similarity index 83%
rename from Documentation/filesystems/inotify.txt
rename to Documentation/filesystems/inotify.rst
index 51f61db..7f7ef8a 100644 (file)
@@ -1,27 +1,36 @@
-                                  inotify
-           a powerful yet simple file change notification system
+.. SPDX-License-Identifier: GPL-2.0
+
+===============================================================
+Inotify - A Powerful yet Simple File Change Notification System
+===============================================================
 
 
 
 Document started 15 Mar 2005 by Robert Love <rml@novell.com>
+
 Document updated 4 Jan 2015 by Zhang Zhen <zhenzhang.zhang@huawei.com>
-       --Deleted obsoleted interface, just refer to manpages for user interface.
+
+       - Deleted obsoleted interface, just refer to manpages for user interface.
 
 (i) Rationale
 
-Q: What is the design decision behind not tying the watch to the open fd of
+Q:
+   What is the design decision behind not tying the watch to the open fd of
    the watched object?
 
-A: Watches are associated with an open inotify device, not an open file.
+A:
+   Watches are associated with an open inotify device, not an open file.
    This solves the primary problem with dnotify: keeping the file open pins
    the file and thus, worse, pins the mount.  Dnotify is therefore infeasible
    for use on a desktop system with removable media as the media cannot be
    unmounted.  Watching a file should not require that it be open.
 
-Q: What is the design decision behind using an-fd-per-instance as opposed to
+Q:
+   What is the design decision behind using an-fd-per-instance as opposed to
    an fd-per-watch?
 
-A: An fd-per-watch quickly consumes more file descriptors than are allowed,
+A:
+   An fd-per-watch quickly consumes more file descriptors than are allowed,
    more fd's than are feasible to manage, and more fd's than are optimally
    select()-able.  Yes, root can bump the per-process fd limit and yes, users
    can use epoll, but requiring both is a silly and extraneous requirement.
@@ -29,8 +38,8 @@ A: An fd-per-watch quickly consumes more file descriptors than are allowed,
    spaces is thus sensible.  The current design is what user-space developers
    want: Users initialize inotify, once, and add n watches, requiring but one
    fd and no twiddling with fd limits.  Initializing an inotify instance two
-   thousand times is silly.  If we can implement user-space's preferences 
-   cleanly--and we can, the idr layer makes stuff like this trivial--then we 
+   thousand times is silly.  If we can implement user-space's preferences
+   cleanly--and we can, the idr layer makes stuff like this trivial--then we
    should.
 
    There are other good arguments.  With a single fd, there is a single
@@ -65,9 +74,11 @@ A: An fd-per-watch quickly consumes more file descriptors than are allowed,
    need not be a one-fd-per-process mapping; it is one-fd-per-queue and a
    process can easily want more than one queue.
 
-Q: Why the system call approach?
+Q:
+   Why the system call approach?
 
-A: The poor user-space interface is the second biggest problem with dnotify.
+A:
+   The poor user-space interface is the second biggest problem with dnotify.
    Signals are a terrible, terrible interface for file notification.  Or for
    anything, for that matter.  The ideal solution, from all perspectives, is a
    file descriptor-based one that allows basic file I/O and poll/select.
diff --git a/Documentation/filesystems/isofs.rst b/Documentation/filesystems/isofs.rst
new file mode 100644 (file)
index 0000000..08fd469
--- /dev/null
@@ -0,0 +1,64 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+==================
+ISO9660 Filesystem
+==================
+
+Mount options that are the same as for msdos and vfat partitions.
+
+  =========    ========================================================
+  gid=nnn      All files in the partition will be in group nnn.
+  uid=nnn      All files in the partition will be owned by user id nnn.
+  umask=nnn    The permission mask (see umask(1)) for the partition.
+  =========    ========================================================
+
+Mount options that are the same as vfat partitions. These are only useful
+when using discs encoded using Microsoft's Joliet extensions.
+
+ ==============        =============================================================
+ iocharset=name Character set to use for converting from Unicode to
+               ASCII.  Joliet filenames are stored in Unicode format, but
+               Unix for the most part doesn't know how to deal with Unicode.
+               There is also an option of doing UTF-8 translations with the
+               utf8 option.
+  utf8          Encode Unicode names in UTF-8 format. Default is no.
+ ==============        =============================================================
+
+Mount options unique to the isofs filesystem.
+
+ ================= ============================================================
+  block=512        Set the block size for the disk to 512 bytes
+  block=1024       Set the block size for the disk to 1024 bytes
+  block=2048       Set the block size for the disk to 2048 bytes
+  check=relaxed    Matches filenames with different cases
+  check=strict     Matches only filenames with the exact same case
+  cruft            Try to handle badly formatted CDs.
+  map=off          Do not map non-Rock Ridge filenames to lower case
+  map=normal       Map non-Rock Ridge filenames to lower case
+  map=acorn        As map=normal but also apply Acorn extensions if present
+  mode=xxx         Sets the permissions on files to xxx unless Rock Ridge
+                  extensions set the permissions otherwise
+  dmode=xxx        Sets the permissions on directories to xxx unless Rock Ridge
+                  extensions set the permissions otherwise
+  overriderockperm Set permissions on files and directories according to
+                  'mode' and 'dmode' even though Rock Ridge extensions are
+                  present.
+  nojoliet         Ignore Joliet extensions if they are present.
+  norock           Ignore Rock Ridge extensions if they are present.
+  hide            Completely strip hidden files from the file system.
+  showassoc       Show files marked with the 'associated' bit
+  unhide          Deprecated; showing hidden files is now default;
+                  If given, it is a synonym for 'showassoc' which will
+                  recreate previous unhide behavior
+  session=x        Select number of session on multisession CD
+  sbsector=xxx     Session begins from sector xxx
+ ================= ============================================================
+
+Recommended documents about ISO 9660 standard are located at:
+
+- http://www.y-adagio.com/
+- ftp://ftp.ecma.ch/ecma-st/Ecma-119.pdf
+
+Quoting from the PDF "This 2nd Edition of Standard ECMA-119 is technically
+identical with ISO 9660.", so it is a valid and gratis substitute of the
+official ISO specification.
diff --git a/Documentation/filesystems/isofs.txt b/Documentation/filesystems/isofs.txt
deleted file mode 100644 (file)
index ba0a933..0000000
+++ /dev/null
@@ -1,48 +0,0 @@
-Mount options that are the same as for msdos and vfat partitions.
-
-  gid=nnn      All files in the partition will be in group nnn.
-  uid=nnn      All files in the partition will be owned by user id nnn.
-  umask=nnn    The permission mask (see umask(1)) for the partition.
-
-Mount options that are the same as vfat partitions. These are only useful
-when using discs encoded using Microsoft's Joliet extensions.
-  iocharset=name Character set to use for converting from Unicode to
-               ASCII.  Joliet filenames are stored in Unicode format, but
-               Unix for the most part doesn't know how to deal with Unicode.
-               There is also an option of doing UTF-8 translations with the
-               utf8 option.
-  utf8          Encode Unicode names in UTF-8 format. Default is no.
-
-Mount options unique to the isofs filesystem.
-  block=512     Set the block size for the disk to 512 bytes
-  block=1024    Set the block size for the disk to 1024 bytes
-  block=2048    Set the block size for the disk to 2048 bytes
-  check=relaxed Matches filenames with different cases
-  check=strict  Matches only filenames with the exact same case
-  cruft         Try to handle badly formatted CDs.
-  map=off       Do not map non-Rock Ridge filenames to lower case
-  map=normal    Map non-Rock Ridge filenames to lower case
-  map=acorn     As map=normal but also apply Acorn extensions if present
-  mode=xxx      Sets the permissions on files to xxx unless Rock Ridge
-               extensions set the permissions otherwise
-  dmode=xxx     Sets the permissions on directories to xxx unless Rock Ridge
-               extensions set the permissions otherwise
-  overriderockperm Set permissions on files and directories according to
-               'mode' and 'dmode' even though Rock Ridge extensions are
-               present.
-  nojoliet      Ignore Joliet extensions if they are present.
-  norock        Ignore Rock Ridge extensions if they are present.
-  hide         Completely strip hidden files from the file system.
-  showassoc    Show files marked with the 'associated' bit
-  unhide       Deprecated; showing hidden files is now default;
-               If given, it is a synonym for 'showassoc' which will
-               recreate previous unhide behavior
-  session=x     Select number of session on multisession CD
-  sbsector=xxx  Session begins from sector xxx
-
-Recommended documents about ISO 9660 standard are located at:
-http://www.y-adagio.com/
-ftp://ftp.ecma.ch/ecma-st/Ecma-119.pdf
-Quoting from the PDF "This 2nd Edition of Standard ECMA-119 is technically 
-identical with ISO 9660.", so it is a valid and gratis substitute of the
-official ISO specification.
diff --git a/Documentation/filesystems/nfs/index.rst b/Documentation/filesystems/nfs/index.rst
new file mode 100644 (file)
index 0000000..6580562
--- /dev/null
@@ -0,0 +1,13 @@
+===============================
+NFS
+===============================
+
+
+.. toctree::
+   :maxdepth: 1
+
+   pnfs
+   rpc-cache
+   rpc-server-gss
+   nfs41-server
+   knfsd-stats
@@ -1,7 +1,9 @@
-
+============================
 Kernel NFS Server Statistics
 ============================
 
+:Authors: Greg Banks <gnb@sgi.com> - 26 Mar 2009
+
 This document describes the format and semantics of the statistics
 which the kernel NFS server makes available to userspace.  These
 statistics are available in several text form pseudo files, each of
@@ -18,7 +20,7 @@ by parsing routines.  All other lines contain a sequence of fields
 separated by whitespace.
 
 /proc/fs/nfsd/pool_stats
-------------------------
+========================
 
 This file is available in kernels from 2.6.30 onwards, if the
 /proc/fs/nfsd filesystem is mounted (it almost always should be).
@@ -109,15 +111,12 @@ this case), or the transport can be enqueued for later attention
 (sockets-enqueued counts this case), or the packet can be temporarily
 deferred because the transport is currently being used by an nfsd
 thread.  This last case is not very interesting and is not explicitly
-counted, but can be inferred from the other counters thus:
+counted, but can be inferred from the other counters thus::
 
-packets-deferred = packets-arrived - ( sockets-enqueued + threads-woken )
+       packets-deferred = packets-arrived - ( sockets-enqueued + threads-woken )
 
 
 More
-----
-Descriptions of the other statistics file should go here.
-
+====
 
-Greg Banks <gnb@sgi.com>
-26 Mar 2009
+Descriptions of the other statistics file should go here.
diff --git a/Documentation/filesystems/nfs/nfs41-server.rst b/Documentation/filesystems/nfs/nfs41-server.rst
new file mode 100644 (file)
index 0000000..16b5f02
--- /dev/null
@@ -0,0 +1,256 @@
+=============================
+NFSv4.1 Server Implementation
+=============================
+
+Server support for minorversion 1 can be controlled using the
+/proc/fs/nfsd/versions control file.  The string output returned
+by reading this file will contain either "+4.1" or "-4.1"
+correspondingly.
+
+Currently, server support for minorversion 1 is enabled by default.
+It can be disabled at run time by writing the string "-4.1" to
+the /proc/fs/nfsd/versions control file.  Note that to write this
+control file, the nfsd service must be taken down.  You can use rpc.nfsd
+for this; see rpc.nfsd(8).
+
+(Warning: older servers will interpret "+4.1" and "-4.1" as "+4" and
+"-4", respectively.  Therefore, code meant to work on both new and old
+kernels must turn 4.1 on or off *before* turning support for version 4
+on or off; rpc.nfsd does this correctly.)
+
+The NFSv4 minorversion 1 (NFSv4.1) implementation in nfsd is based
+on RFC 5661.
+
+From the many new features in NFSv4.1 the current implementation
+focuses on the mandatory-to-implement NFSv4.1 Sessions, providing
+"exactly once" semantics and better control and throttling of the
+resources allocated for each client.
+
+The table below, taken from the NFSv4.1 document, lists
+the operations that are mandatory to implement (REQ), optional
+(OPT), and NFSv4.0 operations that are required not to implement (MNI)
+in minor version 1.  The first column indicates the operations that
+are not supported yet by the linux server implementation.
+
+The OPTIONAL features identified and their abbreviations are as follows:
+
+- **pNFS**     Parallel NFS
+- **FDELG**    File Delegations
+- **DDELG**    Directory Delegations
+
+The following abbreviations indicate the linux server implementation status.
+
+- **I**        Implemented NFSv4.1 operations.
+- **NS**       Not Supported.
+- **NS\***     Unimplemented optional feature.
+
+Operations
+==========
+
++-----------------------+----------------------+---------------------+---------------------------+----------------+
+| Implementation status | Operation            | REQ,REC, OPT or NMI | Feature (REQ, REC or OPT) | Definition     |
++=======================+======================+=====================+===========================+================+
+|                       | ACCESS               | REQ                 |                           | Section 18.1   |
++-----------------------+----------------------+---------------------+---------------------------+----------------+
+| I                     | BACKCHANNEL_CTL      | REQ                 |                           | Section 18.33  |
++-----------------------+----------------------+---------------------+---------------------------+----------------+
+| I                     | BIND_CONN_TO_SESSION | REQ                 |                           | Section 18.34  |
++-----------------------+----------------------+---------------------+---------------------------+----------------+
+|                       | CLOSE                | REQ                 |                           | Section 18.2   |
++-----------------------+----------------------+---------------------+---------------------------+----------------+
+|                       | COMMIT               | REQ                 |                           | Section 18.3   |
++-----------------------+----------------------+---------------------+---------------------------+----------------+
+|                       | CREATE               | REQ                 |                           | Section 18.4   |
++-----------------------+----------------------+---------------------+---------------------------+----------------+
+| I                     | CREATE_SESSION       | REQ                 |                           | Section 18.36  |
++-----------------------+----------------------+---------------------+---------------------------+----------------+
+| NS*                   | DELEGPURGE           | OPT                 | FDELG (REQ)               | Section 18.5   |
++-----------------------+----------------------+---------------------+---------------------------+----------------+
+|                       | DELEGRETURN          | OPT                 | FDELG,                    | Section 18.6   |
++-----------------------+----------------------+---------------------+---------------------------+----------------+
+|                       |                      |                     | DDELG, pNFS               |                |
++-----------------------+----------------------+---------------------+---------------------------+----------------+
+|                       |                      |                     | (REQ)                     |                |
++-----------------------+----------------------+---------------------+---------------------------+----------------+
+| I                     | DESTROY_CLIENTID     | REQ                 |                           | Section 18.50  |
++-----------------------+----------------------+---------------------+---------------------------+----------------+
+| I                     | DESTROY_SESSION      | REQ                 |                           | Section 18.37  |
++-----------------------+----------------------+---------------------+---------------------------+----------------+
+| I                     | EXCHANGE_ID          | REQ                 |                           | Section 18.35  |
++-----------------------+----------------------+---------------------+---------------------------+----------------+
+| I                     | FREE_STATEID         | REQ                 |                           | Section 18.38  |
++-----------------------+----------------------+---------------------+---------------------------+----------------+
+|                       | GETATTR              | REQ                 |                           | Section 18.7   |
++-----------------------+----------------------+---------------------+---------------------------+----------------+
+| I                     | GETDEVICEINFO        | OPT                 | pNFS (REQ)                | Section 18.40  |
++-----------------------+----------------------+---------------------+---------------------------+----------------+
+| NS*                   | GETDEVICELIST        | OPT                 | pNFS (OPT)                | Section 18.41  |
++-----------------------+----------------------+---------------------+---------------------------+----------------+
+|                       | GETFH                | REQ                 |                           | Section 18.8   |
++-----------------------+----------------------+---------------------+---------------------------+----------------+
+| NS*                   | GET_DIR_DELEGATION   | OPT                 | DDELG (REQ)               | Section 18.39  |
++-----------------------+----------------------+---------------------+---------------------------+----------------+
+| I                     | LAYOUTCOMMIT         | OPT                 | pNFS (REQ)                | Section 18.42  |
++-----------------------+----------------------+---------------------+---------------------------+----------------+
+| I                     | LAYOUTGET            | OPT                 | pNFS (REQ)                | Section 18.43  |
++-----------------------+----------------------+---------------------+---------------------------+----------------+
+| I                     | LAYOUTRETURN         | OPT                 | pNFS (REQ)                | Section 18.44  |
++-----------------------+----------------------+---------------------+---------------------------+----------------+
+|                       | LINK                 | OPT                 |                           | Section 18.9   |
++-----------------------+----------------------+---------------------+---------------------------+----------------+
+|                       | LOCK                 | REQ                 |                           | Section 18.10  |
++-----------------------+----------------------+---------------------+---------------------------+----------------+
+|                       | LOCKT                | REQ                 |                           | Section 18.11  |
++-----------------------+----------------------+---------------------+---------------------------+----------------+
+|                       | LOCKU                | REQ                 |                           | Section 18.12  |
++-----------------------+----------------------+---------------------+---------------------------+----------------+
+|                       | LOOKUP               | REQ                 |                           | Section 18.13  |
++-----------------------+----------------------+---------------------+---------------------------+----------------+
+|                       | LOOKUPP              | REQ                 |                           | Section 18.14  |
++-----------------------+----------------------+---------------------+---------------------------+----------------+
+|                       | NVERIFY              | REQ                 |                           | Section 18.15  |
++-----------------------+----------------------+---------------------+---------------------------+----------------+
+|                       | OPEN                 | REQ                 |                           | Section 18.16  |
++-----------------------+----------------------+---------------------+---------------------------+----------------+
+| NS*                   | OPENATTR             | OPT                 |                           | Section 18.17  |
++-----------------------+----------------------+---------------------+---------------------------+----------------+
+|                       | OPEN_CONFIRM         | MNI                 |                           | N/A            |
++-----------------------+----------------------+---------------------+---------------------------+----------------+
+|                       | OPEN_DOWNGRADE       | REQ                 |                           | Section 18.18  |
++-----------------------+----------------------+---------------------+---------------------------+----------------+
+|                       | PUTFH                | REQ                 |                           | Section 18.19  |
++-----------------------+----------------------+---------------------+---------------------------+----------------+
+|                       | PUTPUBFH             | REQ                 |                           | Section 18.20  |
++-----------------------+----------------------+---------------------+---------------------------+----------------+
+|                       | PUTROOTFH            | REQ                 |                           | Section 18.21  |
++-----------------------+----------------------+---------------------+---------------------------+----------------+
+|                       | READ                 | REQ                 |                           | Section 18.22  |
++-----------------------+----------------------+---------------------+---------------------------+----------------+
+|                       | READDIR              | REQ                 |                           | Section 18.23  |
++-----------------------+----------------------+---------------------+---------------------------+----------------+
+|                       | READLINK             | OPT                 |                           | Section 18.24  |
++-----------------------+----------------------+---------------------+---------------------------+----------------+
+|                       | RECLAIM_COMPLETE     | REQ                 |                           | Section 18.51  |
++-----------------------+----------------------+---------------------+---------------------------+----------------+
+|                       | RELEASE_LOCKOWNER    | MNI                 |                           | N/A            |
++-----------------------+----------------------+---------------------+---------------------------+----------------+
+|                       | REMOVE               | REQ                 |                           | Section 18.25  |
++-----------------------+----------------------+---------------------+---------------------------+----------------+
+|                       | RENAME               | REQ                 |                           | Section 18.26  |
++-----------------------+----------------------+---------------------+---------------------------+----------------+
+|                       | RENEW                | MNI                 |                           | N/A            |
++-----------------------+----------------------+---------------------+---------------------------+----------------+
+|                       | RESTOREFH            | REQ                 |                           | Section 18.27  |
++-----------------------+----------------------+---------------------+---------------------------+----------------+
+|                       | SAVEFH               | REQ                 |                           | Section 18.28  |
++-----------------------+----------------------+---------------------+---------------------------+----------------+
+|                       | SECINFO              | REQ                 |                           | Section 18.29  |
++-----------------------+----------------------+---------------------+---------------------------+----------------+
+| I                     | SECINFO_NO_NAME      | REC                 | pNFS files                | Section 18.45, |
++-----------------------+----------------------+---------------------+---------------------------+----------------+
+|                       |                      |                     | layout (REQ)              | Section 13.12  |
++-----------------------+----------------------+---------------------+---------------------------+----------------+
+| I                     | SEQUENCE             | REQ                 |                           | Section 18.46  |
++-----------------------+----------------------+---------------------+---------------------------+----------------+
+|                       | SETATTR              | REQ                 |                           | Section 18.30  |
++-----------------------+----------------------+---------------------+---------------------------+----------------+
+|                       | SETCLIENTID          | MNI                 |                           | N/A            |
++-----------------------+----------------------+---------------------+---------------------------+----------------+
+|                       | SETCLIENTID_CONFIRM  | MNI                 |                           | N/A            |
++-----------------------+----------------------+---------------------+---------------------------+----------------+
+| NS                    | SET_SSV              | REQ                 |                           | Section 18.47  |
++-----------------------+----------------------+---------------------+---------------------------+----------------+
+| I                     | TEST_STATEID         | REQ                 |                           | Section 18.48  |
++-----------------------+----------------------+---------------------+---------------------------+----------------+
+|                       | VERIFY               | REQ                 |                           | Section 18.31  |
++-----------------------+----------------------+---------------------+---------------------------+----------------+
+| NS*                   | WANT_DELEGATION      | OPT                 | FDELG (OPT)               | Section 18.49  |
++-----------------------+----------------------+---------------------+---------------------------+----------------+
+|                       | WRITE                | REQ                 |                           | Section 18.32  |
++-----------------------+----------------------+---------------------+---------------------------+----------------+
+
+
+Callback Operations
+===================
++-----------------------+-------------------------+---------------------+---------------------------+---------------+
+| Implementation status | Operation               | REQ,REC, OPT or NMI | Feature (REQ, REC or OPT) | Definition    |
++=======================+=========================+=====================+===========================+===============+
+|                       | CB_GETATTR              | OPT                 | FDELG (REQ)               | Section 20.1  |
++-----------------------+-------------------------+---------------------+---------------------------+---------------+
+| I                     | CB_LAYOUTRECALL         | OPT                 | pNFS (REQ)                | Section 20.3  |
++-----------------------+-------------------------+---------------------+---------------------------+---------------+
+| NS*                   | CB_NOTIFY               | OPT                 | DDELG (REQ)               | Section 20.4  |
++-----------------------+-------------------------+---------------------+---------------------------+---------------+
+| NS*                   | CB_NOTIFY_DEVICEID      | OPT                 | pNFS (OPT)                | Section 20.12 |
++-----------------------+-------------------------+---------------------+---------------------------+---------------+
+| NS*                   | CB_NOTIFY_LOCK          | OPT                 |                           | Section 20.11 |
++-----------------------+-------------------------+---------------------+---------------------------+---------------+
+| NS*                   | CB_PUSH_DELEG           | OPT                 | FDELG (OPT)               | Section 20.5  |
++-----------------------+-------------------------+---------------------+---------------------------+---------------+
+|                       | CB_RECALL               | OPT                 | FDELG,                    | Section 20.2  |
++-----------------------+-------------------------+---------------------+---------------------------+---------------+
+|                       |                         |                     | DDELG, pNFS               |               |
++-----------------------+-------------------------+---------------------+---------------------------+---------------+
+|                       |                         |                     | (REQ)                     |               |
++-----------------------+-------------------------+---------------------+---------------------------+---------------+
+| NS*                   | CB_RECALL_ANY           | OPT                 | FDELG,                    | Section 20.6  |
++-----------------------+-------------------------+---------------------+---------------------------+---------------+
+|                       |                         |                     | DDELG, pNFS               |               |
++-----------------------+-------------------------+---------------------+---------------------------+---------------+
+|                       |                         |                     | (REQ)                     |               |
++-----------------------+-------------------------+---------------------+---------------------------+---------------+
+| NS                    | CB_RECALL_SLOT          | REQ                 |                           | Section 20.8  |
++-----------------------+-------------------------+---------------------+---------------------------+---------------+
+| NS*                   | CB_RECALLABLE_OBJ_AVAIL | OPT                 | DDELG, pNFS               | Section 20.7  |
++-----------------------+-------------------------+---------------------+---------------------------+---------------+
+|                       |                         |                     | (REQ)                     |               |
++-----------------------+-------------------------+---------------------+---------------------------+---------------+
+| I                     | CB_SEQUENCE             | OPT                 | FDELG,                    | Section 20.9  |
++-----------------------+-------------------------+---------------------+---------------------------+---------------+
+|                       |                         |                     | DDELG, pNFS               |               |
++-----------------------+-------------------------+---------------------+---------------------------+---------------+
+|                       |                         |                     | (REQ)                     |               |
++-----------------------+-------------------------+---------------------+---------------------------+---------------+
+| NS*                   | CB_WANTS_CANCELLED      | OPT                 | FDELG,                    | Section 20.10 |
++-----------------------+-------------------------+---------------------+---------------------------+---------------+
+|                       |                         |                     | DDELG, pNFS               |               |
++-----------------------+-------------------------+---------------------+---------------------------+---------------+
+|                       |                         |                     | (REQ)                     |               |
++-----------------------+-------------------------+---------------------+---------------------------+---------------+
+
+
+Implementation notes:
+=====================
+
+SSV:
+  The spec claims this is mandatory, but we don't actually know of any
+  implementations, so we're ignoring it for now.  The server returns
+  NFS4ERR_ENCR_ALG_UNSUPP on EXCHANGE_ID, which should be future-proof.
+
+GSS on the backchannel:
+  Again, theoretically required but not widely implemented (in
+  particular, the current Linux client doesn't request it).  We return
+  NFS4ERR_ENCR_ALG_UNSUPP on CREATE_SESSION.
+
+DELEGPURGE:
+  mandatory only for servers that support CLAIM_DELEGATE_PREV and/or
+  CLAIM_DELEG_PREV_FH (which allows clients to keep delegations that
+  persist across client reboots).  Thus we need not implement this for
+  now.
+
+EXCHANGE_ID:
+  implementation ids are ignored
+
+CREATE_SESSION:
+  backchannel attributes are ignored
+
+SEQUENCE:
+  no support for dynamic slot table renegotiation (optional)
+
+Nonstandard compound limitations:
+  No support for a sessions fore channel RPC compound that requires both a
+  ca_maxrequestsize request and a ca_maxresponsesize reply, so we may
+  fail to live up to the promise we made in CREATE_SESSION fore channel
+  negotiation.
+
+See also http://wiki.linux-nfs.org/wiki/index.php/Server_4.0_and_4.1_issues.
diff --git a/Documentation/filesystems/nfs/nfs41-server.txt b/Documentation/filesystems/nfs/nfs41-server.txt
deleted file mode 100644 (file)
index 682a59f..0000000
+++ /dev/null
@@ -1,173 +0,0 @@
-NFSv4.1 Server Implementation
-
-Server support for minorversion 1 can be controlled using the
-/proc/fs/nfsd/versions control file.  The string output returned
-by reading this file will contain either "+4.1" or "-4.1"
-correspondingly.
-
-Currently, server support for minorversion 1 is enabled by default.
-It can be disabled at run time by writing the string "-4.1" to
-the /proc/fs/nfsd/versions control file.  Note that to write this
-control file, the nfsd service must be taken down.  You can use rpc.nfsd
-for this; see rpc.nfsd(8).
-
-(Warning: older servers will interpret "+4.1" and "-4.1" as "+4" and
-"-4", respectively.  Therefore, code meant to work on both new and old
-kernels must turn 4.1 on or off *before* turning support for version 4
-on or off; rpc.nfsd does this correctly.)
-
-The NFSv4 minorversion 1 (NFSv4.1) implementation in nfsd is based
-on RFC 5661.
-
-From the many new features in NFSv4.1 the current implementation
-focuses on the mandatory-to-implement NFSv4.1 Sessions, providing
-"exactly once" semantics and better control and throttling of the
-resources allocated for each client.
-
-The table below, taken from the NFSv4.1 document, lists
-the operations that are mandatory to implement (REQ), optional
-(OPT), and NFSv4.0 operations that are required not to implement (MNI)
-in minor version 1.  The first column indicates the operations that
-are not supported yet by the linux server implementation.
-
-The OPTIONAL features identified and their abbreviations are as follows:
-       pNFS    Parallel NFS
-       FDELG   File Delegations
-       DDELG   Directory Delegations
-
-The following abbreviations indicate the linux server implementation status.
-       I       Implemented NFSv4.1 operations.
-       NS      Not Supported.
-       NS*     Unimplemented optional feature.
-
-Operations
-
-   +----------------------+------------+--------------+----------------+
-   | Operation            | REQ, REC,  | Feature      | Definition     |
-   |                      | OPT, or    | (REQ, REC,   |                |
-   |                      | MNI        | or OPT)      |                |
-   +----------------------+------------+--------------+----------------+
-   | ACCESS               | REQ        |              | Section 18.1   |
-I  | BACKCHANNEL_CTL      | REQ        |              | Section 18.33  |
-I  | BIND_CONN_TO_SESSION | REQ        |              | Section 18.34  |
-   | CLOSE                | REQ        |              | Section 18.2   |
-   | COMMIT               | REQ        |              | Section 18.3   |
-   | CREATE               | REQ        |              | Section 18.4   |
-I  | CREATE_SESSION       | REQ        |              | Section 18.36  |
-NS*| DELEGPURGE           | OPT        | FDELG (REQ)  | Section 18.5   |
-   | DELEGRETURN          | OPT        | FDELG,       | Section 18.6   |
-   |                      |            | DDELG, pNFS  |                |
-   |                      |            | (REQ)        |                |
-I  | DESTROY_CLIENTID     | REQ        |              | Section 18.50  |
-I  | DESTROY_SESSION      | REQ        |              | Section 18.37  |
-I  | EXCHANGE_ID          | REQ        |              | Section 18.35  |
-I  | FREE_STATEID         | REQ        |              | Section 18.38  |
-   | GETATTR              | REQ        |              | Section 18.7   |
-I  | GETDEVICEINFO        | OPT        | pNFS (REQ)   | Section 18.40  |
-NS*| GETDEVICELIST        | OPT        | pNFS (OPT)   | Section 18.41  |
-   | GETFH                | REQ        |              | Section 18.8   |
-NS*| GET_DIR_DELEGATION   | OPT        | DDELG (REQ)  | Section 18.39  |
-I  | LAYOUTCOMMIT         | OPT        | pNFS (REQ)   | Section 18.42  |
-I  | LAYOUTGET            | OPT        | pNFS (REQ)   | Section 18.43  |
-I  | LAYOUTRETURN         | OPT        | pNFS (REQ)   | Section 18.44  |
-   | LINK                 | OPT        |              | Section 18.9   |
-   | LOCK                 | REQ        |              | Section 18.10  |
-   | LOCKT                | REQ        |              | Section 18.11  |
-   | LOCKU                | REQ        |              | Section 18.12  |
-   | LOOKUP               | REQ        |              | Section 18.13  |
-   | LOOKUPP              | REQ        |              | Section 18.14  |
-   | NVERIFY              | REQ        |              | Section 18.15  |
-   | OPEN                 | REQ        |              | Section 18.16  |
-NS*| OPENATTR             | OPT        |              | Section 18.17  |
-   | OPEN_CONFIRM         | MNI        |              | N/A            |
-   | OPEN_DOWNGRADE       | REQ        |              | Section 18.18  |
-   | PUTFH                | REQ        |              | Section 18.19  |
-   | PUTPUBFH             | REQ        |              | Section 18.20  |
-   | PUTROOTFH            | REQ        |              | Section 18.21  |
-   | READ                 | REQ        |              | Section 18.22  |
-   | READDIR              | REQ        |              | Section 18.23  |
-   | READLINK             | OPT        |              | Section 18.24  |
-   | RECLAIM_COMPLETE     | REQ        |              | Section 18.51  |
-   | RELEASE_LOCKOWNER    | MNI        |              | N/A            |
-   | REMOVE               | REQ        |              | Section 18.25  |
-   | RENAME               | REQ        |              | Section 18.26  |
-   | RENEW                | MNI        |              | N/A            |
-   | RESTOREFH            | REQ        |              | Section 18.27  |
-   | SAVEFH               | REQ        |              | Section 18.28  |
-   | SECINFO              | REQ        |              | Section 18.29  |
-I  | SECINFO_NO_NAME      | REC        | pNFS files   | Section 18.45, |
-   |                      |            | layout (REQ) | Section 13.12  |
-I  | SEQUENCE             | REQ        |              | Section 18.46  |
-   | SETATTR              | REQ        |              | Section 18.30  |
-   | SETCLIENTID          | MNI        |              | N/A            |
-   | SETCLIENTID_CONFIRM  | MNI        |              | N/A            |
-NS | SET_SSV              | REQ        |              | Section 18.47  |
-I  | TEST_STATEID         | REQ        |              | Section 18.48  |
-   | VERIFY               | REQ        |              | Section 18.31  |
-NS*| WANT_DELEGATION      | OPT        | FDELG (OPT)  | Section 18.49  |
-   | WRITE                | REQ        |              | Section 18.32  |
-
-Callback Operations
-
-   +-------------------------+-----------+-------------+---------------+
-   | Operation               | REQ, REC, | Feature     | Definition    |
-   |                         | OPT, or   | (REQ, REC,  |               |
-   |                         | MNI       | or OPT)     |               |
-   +-------------------------+-----------+-------------+---------------+
-   | CB_GETATTR              | OPT       | FDELG (REQ) | Section 20.1  |
-I  | CB_LAYOUTRECALL         | OPT       | pNFS (REQ)  | Section 20.3  |
-NS*| CB_NOTIFY               | OPT       | DDELG (REQ) | Section 20.4  |
-NS*| CB_NOTIFY_DEVICEID      | OPT       | pNFS (OPT)  | Section 20.12 |
-NS*| CB_NOTIFY_LOCK          | OPT       |             | Section 20.11 |
-NS*| CB_PUSH_DELEG           | OPT       | FDELG (OPT) | Section 20.5  |
-   | CB_RECALL               | OPT       | FDELG,      | Section 20.2  |
-   |                         |           | DDELG, pNFS |               |
-   |                         |           | (REQ)       |               |
-NS*| CB_RECALL_ANY           | OPT       | FDELG,      | Section 20.6  |
-   |                         |           | DDELG, pNFS |               |
-   |                         |           | (REQ)       |               |
-NS | CB_RECALL_SLOT          | REQ       |             | Section 20.8  |
-NS*| CB_RECALLABLE_OBJ_AVAIL | OPT       | DDELG, pNFS | Section 20.7  |
-   |                         |           | (REQ)       |               |
-I  | CB_SEQUENCE             | OPT       | FDELG,      | Section 20.9  |
-   |                         |           | DDELG, pNFS |               |
-   |                         |           | (REQ)       |               |
-NS*| CB_WANTS_CANCELLED      | OPT       | FDELG,      | Section 20.10 |
-   |                         |           | DDELG, pNFS |               |
-   |                         |           | (REQ)       |               |
-   +-------------------------+-----------+-------------+---------------+
-
-Implementation notes:
-
-SSV:
-* The spec claims this is mandatory, but we don't actually know of any
-  implementations, so we're ignoring it for now.  The server returns
-  NFS4ERR_ENCR_ALG_UNSUPP on EXCHANGE_ID, which should be future-proof.
-
-GSS on the backchannel:
-* Again, theoretically required but not widely implemented (in
-  particular, the current Linux client doesn't request it).  We return
-  NFS4ERR_ENCR_ALG_UNSUPP on CREATE_SESSION.
-
-DELEGPURGE:
-* mandatory only for servers that support CLAIM_DELEGATE_PREV and/or
-  CLAIM_DELEG_PREV_FH (which allows clients to keep delegations that
-  persist across client reboots).  Thus we need not implement this for
-  now.
-
-EXCHANGE_ID:
-* implementation ids are ignored
-
-CREATE_SESSION:
-* backchannel attributes are ignored
-
-SEQUENCE:
-* no support for dynamic slot table renegotiation (optional)
-
-Nonstandard compound limitations:
-* No support for a sessions fore channel RPC compound that requires both a
-  ca_maxrequestsize request and a ca_maxresponsesize reply, so we may
-  fail to live up to the promise we made in CREATE_SESSION fore channel
-  negotiation.
-
-See also http://wiki.linux-nfs.org/wiki/index.php/Server_4.0_and_4.1_issues.
similarity index 87%
rename from Documentation/filesystems/nfs/pnfs.txt
rename to Documentation/filesystems/nfs/pnfs.rst
index 80dc0bd..7c470ec 100644 (file)
@@ -1,15 +1,17 @@
-Reference counting in pnfs:
+==========================
+Reference counting in pnfs
 ==========================
 
 The are several inter-related caches.  We have layouts which can
 reference multiple devices, each of which can reference multiple data servers.
 Each data server can be referenced by multiple devices.  Each device
-can be referenced by multiple layouts.  To keep all of this straight,
+can be referenced by multiple layouts. To keep all of this straight,
 we need to reference count.
 
 
 struct pnfs_layout_hdr
-----------------------
+======================
+
 The on-the-wire command LAYOUTGET corresponds to struct
 pnfs_layout_segment, usually referred to by the variable name lseg.
 Each nfs_inode may hold a pointer to a cache of these layout
@@ -25,7 +27,8 @@ the reference count, as the layout is kept around by the lseg that
 keeps it in the list.
 
 deviceid_cache
---------------
+==============
+
 lsegs reference device ids, which are resolved per nfs_client and
 layout driver type.  The device ids are held in a RCU cache (struct
 nfs4_deviceid_cache).  The cache itself is referenced across each
@@ -38,24 +41,26 @@ justification, but seems reasonable given that we can have multiple
 deviceid's per filesystem, and multiple filesystems per nfs_client.
 
 The hash code is copied from the nfsd code base.  A discussion of
-hashing and variations of this algorithm can be found at:
-http://groups.google.com/group/comp.lang.c/browse_thread/thread/9522965e2b8d3809
+hashing and variations of this algorithm can be found `here.
+<http://groups.google.com/group/comp.lang.c/browse_thread/thread/9522965e2b8d3809>`_
 
 data server cache
------------------
+=================
+
 file driver devices refer to data servers, which are kept in a module
 level cache.  Its reference is held over the lifetime of the deviceid
 pointing to it.
 
 lseg
-----
+====
+
 lseg maintains an extra reference corresponding to the NFS_LSEG_VALID
 bit which holds it in the pnfs_layout_hdr's list.  When the final lseg
 is removed from the pnfs_layout_hdr's list, the NFS_LAYOUT_DESTROYED
 bit is set, preventing any new lsegs from being added.
 
 layout drivers
---------------
+==============
 
 PNFS utilizes what is called layout drivers. The STD defines 4 basic
 layout types: "files", "objects", "blocks", and "flexfiles". For each
@@ -68,6 +73,6 @@ Blocks-layout-driver code is in: fs/nfs/blocklayout/.. directory
 Flexfiles-layout-driver code is in: fs/nfs/flexfilelayout/.. directory
 
 blocks-layout setup
--------------------
+===================
 
 TODO: Document the setup needs of the blocks layout driver
similarity index 66%
rename from Documentation/filesystems/nfs/rpc-cache.txt
rename to Documentation/filesystems/nfs/rpc-cache.rst
index c4dac82..bb164ee 100644 (file)
@@ -1,9 +1,14 @@
-       This document gives a brief introduction to the caching
+=========
+RPC Cache
+=========
+
+This document gives a brief introduction to the caching
 mechanisms in the sunrpc layer that is used, in particular,
 for NFS authentication.
 
-CACHES
+Caches
 ======
+
 The caching replaces the old exports table and allows for
 a wide variety of values to be caches.
 
@@ -12,6 +17,7 @@ quite possibly very different in content and use.  There is a corpus
 of common code for managing these caches.
 
 Examples of caches that are likely to be needed are:
+
   - mapping from IP address to client name
   - mapping from client name and filesystem to export options
   - mapping from UID to list of GIDs, to work around NFS's limitation
@@ -21,6 +27,7 @@ Examples of caches that are likely to be needed are:
   - mapping from network identify to public key for crypto authentication.
 
 The common code handles such things as:
+
    - general cache lookup with correct locking
    - supporting 'NEGATIVE' as well as positive entries
    - allowing an EXPIRED time on cache items, and removing
@@ -35,60 +42,66 @@ The common code handles such things as:
 Creating a Cache
 ----------------
 
-1/ A cache needs a datum to store.  This is in the form of a
-   structure definition that must contain a
-     struct cache_head
+-  A cache needs a datum to store.  This is in the form of a
+   structure definition that must contain a struct cache_head
    as an element, usually the first.
    It will also contain a key and some content.
    Each cache element is reference counted and contains
    expiry and update times for use in cache management.
-2/ A cache needs a "cache_detail" structure that
+ A cache needs a "cache_detail" structure that
    describes the cache.  This stores the hash table, some
    parameters for cache management, and some operations detailing how
    to work with particular cache items.
-   The operations requires are:
-       struct cache_head *alloc(void)
-               This simply allocates appropriate memory and returns
-               a pointer to the cache_detail embedded within the
-               structure
-       void cache_put(struct kref *)
-               This is called when the last reference to an item is
-               dropped.  The pointer passed is to the 'ref' field
-               in the cache_head.  cache_put should release any
-               references create by 'cache_init' and, if CACHE_VALID
-               is set, any references created by cache_update.
-               It should then release the memory allocated by
-               'alloc'.
-        int match(struct cache_head *orig, struct cache_head *new)
-               test if the keys in the two structures match.  Return
-               1 if they do, 0 if they don't.
-       void init(struct cache_head *orig, struct cache_head *new)
-               Set the 'key' fields in 'new' from 'orig'.  This may
-               include taking references to shared objects.
-       void update(struct cache_head *orig, struct cache_head *new)
-               Set the 'content' fileds in 'new' from 'orig'.
-       int cache_show(struct seq_file *m, struct cache_detail *cd,
-                       struct cache_head *h)
-               Optional.  Used to provide a /proc file that lists the
-               contents of a cache.  This should show one item,
-               usually on just one line.
-       int cache_request(struct cache_detail *cd, struct cache_head *h,
-               char **bpp, int *blen)
-               Format a request to be send to user-space for an item
-               to be instantiated.  *bpp is a buffer of size *blen.
-               bpp should be moved forward over the encoded message,
-               and  *blen should be reduced to show how much free
-               space remains.  Return 0 on success or <0 if not
-               enough room or other problem.
-       int cache_parse(struct cache_detail *cd, char *buf, int len)
-               A message from user space has arrived to fill out a
-               cache entry.  It is in 'buf' of length 'len'.
-               cache_parse should parse this, find the item in the
-               cache with sunrpc_cache_lookup_rcu, and update the item
-               with sunrpc_cache_update.
-
-
-3/ A cache needs to be registered using cache_register().  This
+
+   The operations are:
+
+    struct cache_head \*alloc(void)
+      This simply allocates appropriate memory and returns
+      a pointer to the cache_detail embedded within the
+      structure
+
+    void cache_put(struct kref \*)
+      This is called when the last reference to an item is
+      dropped.  The pointer passed is to the 'ref' field
+      in the cache_head.  cache_put should release any
+      references create by 'cache_init' and, if CACHE_VALID
+      is set, any references created by cache_update.
+      It should then release the memory allocated by
+      'alloc'.
+
+    int match(struct cache_head \*orig, struct cache_head \*new)
+      test if the keys in the two structures match.  Return
+      1 if they do, 0 if they don't.
+
+    void init(struct cache_head \*orig, struct cache_head \*new)
+      Set the 'key' fields in 'new' from 'orig'.  This may
+      include taking references to shared objects.
+
+    void update(struct cache_head \*orig, struct cache_head \*new)
+      Set the 'content' fileds in 'new' from 'orig'.
+
+    int cache_show(struct seq_file \*m, struct cache_detail \*cd, struct cache_head \*h)
+      Optional.  Used to provide a /proc file that lists the
+      contents of a cache.  This should show one item,
+      usually on just one line.
+
+    int cache_request(struct cache_detail \*cd, struct cache_head \*h, char \*\*bpp, int \*blen)
+      Format a request to be send to user-space for an item
+      to be instantiated.  \*bpp is a buffer of size \*blen.
+      bpp should be moved forward over the encoded message,
+      and  \*blen should be reduced to show how much free
+      space remains.  Return 0 on success or <0 if not
+      enough room or other problem.
+
+    int cache_parse(struct cache_detail \*cd, char \*buf, int len)
+      A message from user space has arrived to fill out a
+      cache entry.  It is in 'buf' of length 'len'.
+      cache_parse should parse this, find the item in the
+      cache with sunrpc_cache_lookup_rcu, and update the item
+      with sunrpc_cache_update.
+
+
+-  A cache needs to be registered using cache_register().  This
    includes it on a list of caches that will be regularly
    cleaned to discard old data.
 
@@ -107,7 +120,7 @@ cache_check will return -ENOENT in the entry is negative or if an up
 call is needed but not possible, -EAGAIN if an upcall is pending,
 or 0 if the data is valid;
 
-cache_check can be passed a "struct cache_req *".  This structure is
+cache_check can be passed a "struct cache_req\*".  This structure is
 typically embedded in the actual request and can be used to create a
 deferred copy of the request (struct cache_deferred_req).  This is
 done when the found cache item is not uptodate, but the is reason to
@@ -139,9 +152,11 @@ The 'channel' works a bit like a datagram socket. Each 'write' is
 passed as a whole to the cache for parsing and interpretation.
 Each cache can treat the write requests differently, but it is
 expected that a message written will contain:
+
   - a key
   - an expiry time
   - a content.
+
 with the intention that an item in the cache with the give key
 should be create or updated to have the given content, and the
 expiry time should be set on that item.
@@ -156,7 +171,8 @@ If there are no more requests to return, read will return EOF, but a
 select or poll for read will block waiting for another request to be
 added.
 
-Thus a user-space helper is likely to:
+Thus a user-space helper is likely to::
+
   open the channel.
     select for readable
     read a request
@@ -175,12 +191,13 @@ Each cache should also define a "cache_request" method which
 takes a cache item and encodes a request into the buffer
 provided.
 
-Note: If a cache has no active readers on the channel, and has had not
-active readers for more than 60 seconds, further requests will not be
-added to the channel but instead all lookups that do not find a valid
-entry will fail.  This is partly for backward compatibility: The
-previous nfs exports table was deemed to be authoritative and a
-failed lookup meant a definite 'no'.
+.. note::
+  If a cache has no active readers on the channel, and has had not
+  active readers for more than 60 seconds, further requests will not be
+  added to the channel but instead all lookups that do not find a valid
+  entry will fail.  This is partly for backward compatibility: The
+  previous nfs exports table was deemed to be authoritative and a
+  failed lookup meant a definite 'no'.
 
 request/response format
 -----------------------
@@ -193,10 +210,11 @@ with precisely one newline character which should be at the end.
 Fields within the record should be separated by spaces, normally one.
 If spaces, newlines, or nul characters are needed in a field they
 much be quoted.  two mechanisms are available:
-1/ If a field begins '\x' then it must contain an even number of
+
+-  If a field begins '\x' then it must contain an even number of
    hex digits, and pairs of these digits provide the bytes in the
    field.
-2/ otherwise a \ in the field must be followed by 3 octal digits
+ otherwise a \ in the field must be followed by 3 octal digits
    which give the code for a byte.  Other characters are treated
    as them selves.  At the very least, space, newline, nul, and
    '\' must be quoted in this way.
@@ -1,4 +1,4 @@
-
+=========================================
 rpcsec_gss support for kernel RPC servers
 =========================================
 
@@ -9,14 +9,17 @@ NFSv4.1 and higher don't require the client to act as a server for the
 purposes of authentication.)
 
 RPCGSS is specified in a few IETF documents:
+
  - RFC2203 v1: http://tools.ietf.org/rfc/rfc2203.txt
  - RFC5403 v2: http://tools.ietf.org/rfc/rfc5403.txt
+
 and there is a 3rd version  being proposed:
+
  - http://tools.ietf.org/id/draft-williams-rpcsecgssv3.txt
    (At draft n. 02 at the time of writing)
 
 Background
-----------
+==========
 
 The RPCGSS Authentication method describes a way to perform GSSAPI
 Authentication for NFS.  Although GSSAPI is itself completely mechanism
@@ -29,6 +32,7 @@ depends on GSSAPI extensions that are KRB5 specific.
 GSSAPI is a complex library, and implementing it completely in kernel is
 unwarranted. However GSSAPI operations are fundementally separable in 2
 parts:
+
 - initial context establishment
 - integrity/privacy protection (signing and encrypting of individual
   packets)
@@ -41,7 +45,7 @@ kernel, but leave the initial context establishment to userspace.  We
 need upcalls to request userspace to perform context establishment.
 
 NFS Server Legacy Upcall Mechanism
-----------------------------------
+==================================
 
 The classic upcall mechanism uses a custom text based upcall mechanism
 to talk to a custom daemon called rpc.svcgssd that is provide by the
@@ -62,21 +66,20 @@ groups) due to limitation on the size of the buffer that can be send
 back to the kernel (4KiB).
 
 NFS Server New RPC Upcall Mechanism
------------------------------------
+===================================
 
 The newer upcall mechanism uses RPC over a unix socket to a daemon
 called gss-proxy, implemented by a userspace program called Gssproxy.
 
-The gss_proxy RPC protocol is currently documented here:
-
-       https://fedorahosted.org/gss-proxy/wiki/ProtocolDocumentation
+The gss_proxy RPC protocol is currently documented `here
+<https://fedorahosted.org/gss-proxy/wiki/ProtocolDocumentation>`_.
 
 This upcall mechanism uses the kernel rpc client and connects to the gssproxy
 userspace program over a regular unix socket. The gssproxy protocol does not
 suffer from the size limitations of the legacy protocol.
 
 Negotiating Upcall Mechanisms
------------------------------
+=============================
 
 To provide backward compatibility, the kernel defaults to using the
 legacy mechanism.  To switch to the new mechanism, gss-proxy must bind
similarity index 89%
rename from Documentation/filesystems/nilfs2.txt
rename to Documentation/filesystems/nilfs2.rst
index f2f3f85..6c49f04 100644 (file)
@@ -1,5 +1,8 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+======
 NILFS2
-------
+======
 
 NILFS2 is a log-structured file system (LFS) supporting continuous
 snapshotting.  In addition to versioning capability of the entire file
@@ -25,9 +28,9 @@ available from the following download page.  At least "mkfs.nilfs2",
 cleaner or garbage collector) are required.  Details on the tools are
 described in the man pages included in the package.
 
-Project web page:    https://nilfs.sourceforge.io/
-Download page:       https://nilfs.sourceforge.io/en/download.html
-List info:           http://vger.kernel.org/vger-lists.html#linux-nilfs
+:Project web page:    https://nilfs.sourceforge.io/
+:Download page:       https://nilfs.sourceforge.io/en/download.html
+:List info:           http://vger.kernel.org/vger-lists.html#linux-nilfs
 
 Caveats
 =======
@@ -47,6 +50,7 @@ Mount options
 NILFS2 supports the following mount options:
 (*) == default
 
+======================= =======================================================
 barrier(*)             This enables/disables the use of write barriers.  This
 nobarrier              requires an IO stack which can support barriers, and
                        if nilfs gets an error on a barrier write, it will
@@ -79,6 +83,7 @@ discard                       This enables/disables the use of discard/TRIM commands.
 nodiscard(*)           The discard/TRIM commands are sent to the underlying
                        block device when blocks are freed.  This is useful
                        for SSD devices and sparse/thinly-provisioned LUNs.
+======================= =======================================================
 
 Ioctls
 ======
@@ -87,9 +92,11 @@ There is some NILFS2 specific functionality which can be accessed by application
 through the system call interfaces. The list of all NILFS2 specific ioctls are
 shown in the table below.
 
-Table of NILFS2 specific ioctls
-..............................................................................
+Table of NILFS2 specific ioctls:
+
+ ============================== ===============================================
  Ioctl                         Description
+ ============================== ===============================================
  NILFS_IOCTL_CHANGE_CPMODE      Change mode of given checkpoint between
                                checkpoint and snapshot state. This ioctl is
                                used in chcp and mkcp utilities.
@@ -142,11 +149,12 @@ Table of NILFS2 specific ioctls
  NILFS_IOCTL_SET_ALLOC_RANGE    Define lower limit of segments in bytes and
                                upper limit of segments in bytes. This ioctl
                                is used by nilfs_resize utility.
+ ============================== ===============================================
 
 NILFS2 usage
 ============
 
-To use nilfs2 as a local file system, simply:
+To use nilfs2 as a local file system, simply::
 
  # mkfs -t nilfs2 /dev/block_device
  # mount -t nilfs2 /dev/block_device /dir
@@ -157,18 +165,20 @@ This will also invoke the cleaner through the mount helper program
 Checkpoints and snapshots are managed by the following commands.
 Their manpages are included in the nilfs-utils package above.
 
+  ====     ===========================================================
   lscp     list checkpoints or snapshots.
   mkcp     make a checkpoint or a snapshot.
   chcp     change an existing checkpoint to a snapshot or vice versa.
   rmcp     invalidate specified checkpoint(s).
+  ====     ===========================================================
 
-To mount a snapshot,
+To mount a snapshot::
 
  # mount -t nilfs2 -r -o cp=<cno> /dev/block_device /snap_dir
 
 where <cno> is the checkpoint number of the snapshot.
 
-To unmount the NILFS2 mount point or snapshot, simply:
+To unmount the NILFS2 mount point or snapshot, simply::
 
  # umount /dir
 
@@ -181,7 +191,7 @@ Disk format
 A nilfs2 volume is equally divided into a number of segments except
 for the super block (SB) and segment #0.  A segment is the container
 of logs.  Each log is composed of summary information blocks, payload
-blocks, and an optional super root block (SR):
+blocks, and an optional super root block (SR)::
 
    ______________________________________________________
   | |SB| | Segment | Segment | Segment | ... | Segment | |
@@ -200,7 +210,7 @@ blocks, and an optional super root block (SR):
   |_blocks__|_________________|__|
 
 The payload blocks are organized per file, and each file consists of
-data blocks and B-tree node blocks:
+data blocks and B-tree node blocks::
 
     |<---       File-A        --->|<---       File-B        --->|
    _______________________________________________________________
@@ -213,7 +223,7 @@ files without data blocks or B-tree node blocks.
 
 The organization of the blocks is recorded in the summary information
 blocks, which contains a header structure (nilfs_segment_summary), per
-file structures (nilfs_finfo), and per block structures (nilfs_binfo):
+file structures (nilfs_finfo), and per block structures (nilfs_binfo)::
 
   _________________________________________________________________________
  | Summary | finfo | binfo | ... | binfo | finfo | binfo | ... | binfo |...
@@ -223,7 +233,7 @@ file structures (nilfs_finfo), and per block structures (nilfs_binfo):
 The logs include regular files, directory files, symbolic link files
 and several meta data files.  The mata data files are the files used
 to maintain file system meta data.  The current version of NILFS2 uses
-the following meta data files:
+the following meta data files::
 
  1) Inode file (ifile)             -- Stores on-disk inodes
  2) Checkpoint file (cpfile)       -- Stores checkpoints
@@ -232,7 +242,7 @@ the following meta data files:
     (DAT)                             block numbers.  This file serves to
                                       make on-disk blocks relocatable.
 
-The following figure shows a typical organization of the logs:
+The following figure shows a typical organization of the logs::
 
   _________________________________________________________________________
  | Summary | regular file | file  | ... | ifile | cpfile | sufile | DAT |SR|
@@ -250,7 +260,7 @@ three special inodes, inodes for the DAT, cpfile, and sufile.  Inodes
 of regular files, directories, symlinks and other special files, are
 included in the ifile.  The inode of ifile itself is included in the
 corresponding checkpoint entry in the cpfile.  Thus, the hierarchy
-among NILFS2 files can be depicted as follows:
+among NILFS2 files can be depicted as follows::
 
   Super block (SB)
        |
similarity index 85%
rename from Documentation/filesystems/ntfs.txt
rename to Documentation/filesystems/ntfs.rst
index 553f10d..5bb093a 100644 (file)
@@ -1,19 +1,21 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+================================
 The Linux NTFS filesystem driver
 ================================
 
 
-Table of contents
-=================
+.. Table of contents
 
-- Overview
-- Web site
-- Features
-- Supported mount options
-- Known bugs and (mis-)features
-- Using NTFS volume and stripe sets
-  - The Device-Mapper driver
-  - The Software RAID / MD driver
-  - Limitations when using the MD driver
+   - Overview
+   - Web site
+   - Features
+   - Supported mount options
+   - Known bugs and (mis-)features
+   - Using NTFS volume and stripe sets
+     - The Device-Mapper driver
+     - The Software RAID / MD driver
+     - Limitations when using the MD driver
 
 
 Overview
@@ -66,8 +68,10 @@ Features
   partition by creating a large file while in Windows and then loopback
   mounting the file while in Linux and creating a Linux filesystem on it that
   is used to install Linux on it.
-- A comparison of the two drivers using:
+- A comparison of the two drivers using::
+
        time find . -type f -exec md5sum "{}" \;
+
   run three times in sequence with each driver (after a reboot) on a 1.4GiB
   NTFS partition, showed the new driver to be 20% faster in total time elapsed
   (from 9:43 minutes on average down to 7:53).  The time spent in user space
@@ -104,6 +108,7 @@ In addition to the generic mount options described by the manual page for the
 mount command (man 8 mount, also see man 5 fstab), the NTFS driver supports the
 following mount options:
 
+======================= =======================================================
 iocharset=name         Deprecated option.  Still supported but please use
                        nls=name in the future.  See description for nls=name.
 
@@ -175,16 +180,22 @@ disable_sparse=<BOOL>     If disable_sparse is specified, creation of sparse
 
 errors=opt             What to do when critical filesystem errors are found.
                        Following values can be used for "opt":
-                         continue: DEFAULT, try to clean-up as much as
+
+                         ========  =========================================
+                         continue  DEFAULT, try to clean-up as much as
                                    possible, e.g. marking a corrupt inode as
                                    bad so it is no longer accessed, and then
                                    continue.
-                         recover:  At present only supported is recovery of
+                         recover   At present only supported is recovery of
                                    the boot sector from the backup copy.
                                    If read-only mount, the recovery is done
                                    in memory only and not written to disk.
-                       Note that the options are additive, i.e. specifying:
+                         ========  =========================================
+
+                       Note that the options are additive, i.e. specifying::
+
                           errors=continue,errors=recover
+
                        means the driver will attempt to recover and if that
                        fails it will clean-up as much as possible and
                        continue.
@@ -202,12 +213,18 @@ mft_zone_multiplier=      Set the MFT zone multiplier for the volume (this
                        In general use the default.  If you have a lot of small
                        files then use a higher value.  The values have the
                        following meaning:
+
+                             =====         =================================
                              Value          MFT zone size (% of volume size)
+                             =====         =================================
                                1               12.5%
                                2               25%
                                3               37.5%
                                4               50%
+                             =====         =================================
+
                        Note this option is irrelevant for read-only mounts.
+======================= =======================================================
 
 
 Known bugs and (mis-)features
@@ -252,18 +269,18 @@ To create the table describing your volume you will need to know each of its
 components and their sizes in sectors, i.e. multiples of 512-byte blocks.
 
 For NT4 fault tolerant volumes you can obtain the sizes using fdisk.  So for
-example if one of your partitions is /dev/hda2 you would do:
+example if one of your partitions is /dev/hda2 you would do::
 
-$ fdisk -ul /dev/hda
+    $ fdisk -ul /dev/hda
 
-Disk /dev/hda: 81.9 GB, 81964302336 bytes
-255 heads, 63 sectors/track, 9964 cylinders, total 160086528 sectors
-Units = sectors of 1 * 512 = 512 bytes
+    Disk /dev/hda: 81.9 GB, 81964302336 bytes
+    255 heads, 63 sectors/track, 9964 cylinders, total 160086528 sectors
+    Units = sectors of 1 * 512 = 512 bytes
 
-   Device Boot      Start         End      Blocks   Id  System
-   /dev/hda1   *          63     4209029     2104483+  83  Linux
-   /dev/hda2         4209030    37768814    16779892+  86  NTFS
-   /dev/hda3        37768815    46170809     4200997+  83  Linux
+       Device Boot      Start         End      Blocks   Id  System
+       /dev/hda1   *          63     4209029     2104483+  83  Linux
+       /dev/hda2         4209030    37768814    16779892+  86  NTFS
+       /dev/hda3        37768815    46170809     4200997+  83  Linux
 
 And you would know that /dev/hda2 has a size of 37768814 - 4209030 + 1 =
 33559785 sectors.
@@ -271,15 +288,17 @@ And you would know that /dev/hda2 has a size of 37768814 - 4209030 + 1 =
 For Win2k and later dynamic disks, you can for example use the ldminfo utility
 which is part of the Linux LDM tools (the latest version at the time of
 writing is linux-ldm-0.0.8.tar.bz2).  You can download it from:
+
        http://www.linux-ntfs.org/
+
 Simply extract the downloaded archive (tar xvjf linux-ldm-0.0.8.tar.bz2), go
 into it (cd linux-ldm-0.0.8) and change to the test directory (cd test).  You
 will find the precompiled (i386) ldminfo utility there.  NOTE: You will not be
 able to compile this yourself easily so use the binary version!
 
-Then you would use ldminfo in dump mode to obtain the necessary information:
+Then you would use ldminfo in dump mode to obtain the necessary information::
 
-$ ./ldminfo --dump /dev/hda
+    $ ./ldminfo --dump /dev/hda
 
 This would dump the LDM database found on /dev/hda which describes all of your
 dynamic disks and all the volumes on them.  At the bottom you will see the
@@ -305,42 +324,36 @@ give you the correct information to do this.
 Assuming you know all your devices and their sizes things are easy.
 
 For a linear raid the table would look like this (note all values are in
-512-byte sectors):
+512-byte sectors)::
 
---- cut here ---
-# Offset into  Size of this    Raid type       Device          Start sector
-# volume       device                                          of device
-0              1028161         linear          /dev/hda1       0
-1028161                3903762         linear          /dev/hdb2       0
-4931923                2103211         linear          /dev/hdc1       0
---- cut here ---
+    # Offset into      Size of this    Raid type       Device          Start sector
+    # volume   device                                          of device
+    0          1028161         linear          /dev/hda1       0
+    1028161            3903762         linear          /dev/hdb2       0
+    4931923            2103211         linear          /dev/hdc1       0
 
 For a striped volume, i.e. raid level 0, you will need to know the chunk size
 you used when creating the volume.  Windows uses 64kiB as the default, so it
 will probably be this unless you changes the defaults when creating the array.
 
 For a raid level 0 the table would look like this (note all values are in
-512-byte sectors):
+512-byte sectors)::
 
---- cut here ---
-# Offset   Size            Raid     Number   Chunk  1st        Start   2nd       Start
-# into     of the   type     of              size   Device     in      Device    in
-# volume   volume           stripes                    device            device
-0         2056320  striped  2        128    /dev/hda1  0       /dev/hdb1 0
---- cut here ---
+    # Offset   Size        Raid     Number   Chunk  1st        Start   2nd       Start
+    # into     of the   type     of          size   Device     in      Device    in
+    # volume   volume       stripes                    device            device
+    0     2056320  striped  2        128    /dev/hda1  0       /dev/hdb1 0
 
 If there are more than two devices, just add each of them to the end of the
 line.
 
 Finally, for a mirrored volume, i.e. raid level 1, the table would look like
-this (note all values are in 512-byte sectors):
+this (note all values are in 512-byte sectors)::
 
---- cut here ---
-# Ofs Size   Raid   Log  Number Region Should Number Source  Start Target Start
-# in  of the type   type of log size   sync?  of     Device  in    Device in
-# vol volume            params              mirrors         Device       Device
-0    2056320 mirror core 2     16     nosync 2    /dev/hda1 0   /dev/hdb1 0
---- cut here ---
+    # Ofs Size   Raid   Log  Number Region Should Number Source  Start Target Start
+    # in  of the type   type of log size   sync?  of     Device  in    Device in
+    # vol volume                params              mirrors         Device       Device
+    0    2056320 mirror core 2 16     nosync 2    /dev/hda1 0   /dev/hdb1 0
 
 If you are mirroring to multiple devices you can specify further targets at the
 end of the line.
@@ -353,17 +366,17 @@ to the "Target Device" or if you specified multiple target devices to all of
 them.
 
 Once you have your table, save it in a file somewhere (e.g. /etc/ntfsvolume1),
-and hand it over to dmsetup to work with, like so:
+and hand it over to dmsetup to work with, like so::
 
-$ dmsetup create myvolume1 /etc/ntfsvolume1
+    $ dmsetup create myvolume1 /etc/ntfsvolume1
 
 You can obviously replace "myvolume1" with whatever name you like.
 
 If it all worked, you will now have the device /dev/device-mapper/myvolume1
 which you can then just use as an argument to the mount command as usual to
-mount the ntfs volume.  For example:
+mount the ntfs volume.  For example::
 
-$ mount -t ntfs -o ro /dev/device-mapper/myvolume1 /mnt/myvol1
+    $ mount -t ntfs -o ro /dev/device-mapper/myvolume1 /mnt/myvol1
 
 (You need to create the directory /mnt/myvol1 first and of course you can use
 anything you like instead of /mnt/myvol1 as long as it is an existing
@@ -395,18 +408,18 @@ Windows by default uses a stripe chunk size of 64k, so you probably want the
 "chunk-size 64k" option for each raid-disk, too.
 
 For example, if you have a stripe set consisting of two partitions /dev/hda5
-and /dev/hdb1 your /etc/raidtab would look like this:
-
-raiddev /dev/md0
-       raid-level      0
-       nr-raid-disks   2
-       nr-spare-disks  0
-       persistent-superblock   0
-       chunk-size      64k
-       device          /dev/hda5
-       raid-disk       0
-       device          /dev/hdb1
-       raid-disk       1
+and /dev/hdb1 your /etc/raidtab would look like this::
+
+    raiddev /dev/md0
+           raid-level  0
+           nr-raid-disks       2
+           nr-spare-disks      0
+           persistent-superblock       0
+           chunk-size  64k
+           device              /dev/hda5
+           raid-disk   0
+           device              /dev/hdb1
+           raid-disk   1
 
 For linear raid, just change the raid-level above to "raid-level linear", for
 mirrors, change it to "raid-level 1", and for stripe sets with parity, change
@@ -427,7 +440,9 @@ Once the raidtab is setup, run for example raid0run -a to start all devices or
 raid0run /dev/md0 to start a particular md device, in this case /dev/md0.
 
 Then just use the mount command as usual to mount the ntfs volume using for
-example:       mount -t ntfs -o ro /dev/md0 /mnt/myntfsvolume
+example::
+
+    mount -t ntfs -o ro /dev/md0 /mnt/myntfsvolume
 
 It is advisable to do the mount read-only to see if the md volume has been
 setup correctly to avoid the possibility of causing damage to the data on the
@@ -1,5 +1,8 @@
-                   OCFS2 online file check
-                   -----------------------
+.. SPDX-License-Identifier: GPL-2.0
+
+=====================================
+OCFS2 file system - online file check
+=====================================
 
 This document will describe OCFS2 online file check feature.
 
@@ -40,7 +43,7 @@ When there are errors in the OCFS2 filesystem, they are usually accompanied
 by the inode number which caused the error. This inode number would be the
 input to check/fix the file.
 
-There is a sysfs directory for each OCFS2 file system mounting:
+There is a sysfs directory for each OCFS2 file system mounting::
 
   /sys/fs/ocfs2/<devname>/filecheck
 
@@ -50,34 +53,36 @@ communicate with kernel space, tell which file(inode number) will be checked or
 fixed. Currently, three operations are supported, which includes checking
 inode, fixing inode and setting the size of result record history.
 
-1. If you want to know what error exactly happened to <inode> before fixing, do
+1. If you want to know what error exactly happened to <inode> before fixing, do::
+
+    # echo "<inode>" > /sys/fs/ocfs2/<devname>/filecheck/check
+    # cat /sys/fs/ocfs2/<devname>/filecheck/check
+
+The output is like this::
 
-  # echo "<inode>" > /sys/fs/ocfs2/<devname>/filecheck/check
-  # cat /sys/fs/ocfs2/<devname>/filecheck/check
+    INO                DONE    ERROR
+    39502              1       GENERATION
 
-The output is like this:
-  INO          DONE    ERROR
-39502          1       GENERATION
+    <INO> lists the inode numbers.
+    <DONE> indicates whether the operation has been finished.
+    <ERROR> says what kind of errors was found. For the detailed error numbers,
+    please refer to the file linux/fs/ocfs2/filecheck.h.
 
-<INO> lists the inode numbers.
-<DONE> indicates whether the operation has been finished.
-<ERROR> says what kind of errors was found. For the detailed error numbers,
-please refer to the file linux/fs/ocfs2/filecheck.h.
+2. If you determine to fix this inode, do::
 
-2. If you determine to fix this inode, do
+    # echo "<inode>" > /sys/fs/ocfs2/<devname>/filecheck/fix
+    # cat /sys/fs/ocfs2/<devname>/filecheck/fix
 
-  # echo "<inode>" > /sys/fs/ocfs2/<devname>/filecheck/fix
-  # cat /sys/fs/ocfs2/<devname>/filecheck/fix
+The output is like this:::
 
-The output is like this:
-  INO          DONE    ERROR
-39502          1       SUCCESS
+    INO                DONE    ERROR
+    39502              1       SUCCESS
 
 This time, the <ERROR> column indicates whether this fix is successful or not.
 
 3. The record cache is used to store the history of check/fix results. It's
 default size is 10, and can be adjust between the range of 10 ~ 100. You can
-adjust the size like this:
+adjust the size like this::
 
   # echo "<size>" > /sys/fs/ocfs2/<devname>/filecheck/set
 
similarity index 88%
rename from Documentation/filesystems/ocfs2.txt
rename to Documentation/filesystems/ocfs2.rst
index 4c49e54..412386b 100644 (file)
@@ -1,5 +1,9 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+================
 OCFS2 filesystem
-==================
+================
+
 OCFS2 is a general purpose extent based shared disk cluster file
 system with many similarities to ext3. It supports 64 bit inode
 numbers, and has automatically extending metadata groups which may
@@ -14,22 +18,26 @@ OCFS2 mailing lists: http://oss.oracle.com/projects/ocfs2/mailman/
 
 All code copyright 2005 Oracle except when otherwise noted.
 
-CREDITS:
+Credits
+=======
+
 Lots of code taken from ext3 and other projects.
 
 Authors in alphabetical order:
-Joel Becker   <joel.becker@oracle.com>
-Zach Brown    <zach.brown@oracle.com>
-Mark Fasheh   <mfasheh@suse.com>
-Kurt Hackel   <kurt.hackel@oracle.com>
-Tao Ma        <tao.ma@oracle.com>
-Sunil Mushran <sunil.mushran@oracle.com>
-Manish Singh  <manish.singh@oracle.com>
-Tiger Yang    <tiger.yang@oracle.com>
+
+- Joel Becker   <joel.becker@oracle.com>
+- Zach Brown    <zach.brown@oracle.com>
+- Mark Fasheh   <mfasheh@suse.com>
+- Kurt Hackel   <kurt.hackel@oracle.com>
+- Tao Ma        <tao.ma@oracle.com>
+- Sunil Mushran <sunil.mushran@oracle.com>
+- Manish Singh  <manish.singh@oracle.com>
+- Tiger Yang    <tiger.yang@oracle.com>
 
 Caveats
 =======
 Features which OCFS2 does not support yet:
+
        - Directory change notification (F_NOTIFY)
        - Distributed Caching (F_SETLEASE/F_GETLEASE/break_lease)
 
@@ -37,8 +45,10 @@ Mount options
 =============
 
 OCFS2 supports the following mount options:
+
 (*) == default
 
+======================= ========================================================
 barrier=1              This enables/disables barriers. barrier=0 disables it,
                        barrier=1 enables it.
 errors=remount-ro(*)   Remount the filesystem read-only on an error.
@@ -104,3 +114,4 @@ journal_async_commit        Commit block can be written to disk without waiting
                        for descriptor blocks. If enabled older kernels cannot
                        mount the device. This will enable 'journal_checksum'
                        internally.
+======================= ========================================================
diff --git a/Documentation/filesystems/omfs.rst b/Documentation/filesystems/omfs.rst
new file mode 100644 (file)
index 0000000..4c8bb30
--- /dev/null
@@ -0,0 +1,112 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+================================
+Optimized MPEG Filesystem (OMFS)
+================================
+
+Overview
+========
+
+OMFS is a filesystem created by SonicBlue for use in the ReplayTV DVR
+and Rio Karma MP3 player.  The filesystem is extent-based, utilizing
+block sizes from 2k to 8k, with hash-based directories.  This
+filesystem driver may be used to read and write disks from these
+devices.
+
+Note, it is not recommended that this FS be used in place of a general
+filesystem for your own streaming media device.  Native Linux filesystems
+will likely perform better.
+
+More information is available at:
+
+    http://linux-karma.sf.net/
+
+Various utilities, including mkomfs and omfsck, are included with
+omfsprogs, available at:
+
+    http://bobcopeland.com/karma/
+
+Instructions are included in its README.
+
+Options
+=======
+
+OMFS supports the following mount-time options:
+
+    ============   ========================================
+    uid=n          make all files owned by specified user
+    gid=n          make all files owned by specified group
+    umask=xxx      set permission umask to xxx
+    fmask=xxx      set umask to xxx for files
+    dmask=xxx      set umask to xxx for directories
+    ============   ========================================
+
+Disk format
+===========
+
+OMFS discriminates between "sysblocks" and normal data blocks.  The sysblock
+group consists of super block information, file metadata, directory structures,
+and extents.  Each sysblock has a header containing CRCs of the entire
+sysblock, and may be mirrored in successive blocks on the disk.  A sysblock may
+have a smaller size than a data block, but since they are both addressed by the
+same 64-bit block number, any remaining space in the smaller sysblock is
+unused.
+
+Sysblock header information::
+
+    struct omfs_header {
+           __be64 h_self;                  /* FS block where this is located */
+           __be32 h_body_size;             /* size of useful data after header */
+           __be16 h_crc;                   /* crc-ccitt of body_size bytes */
+           char h_fill1[2];
+           u8 h_version;                   /* version, always 1 */
+           char h_type;                    /* OMFS_INODE_X */
+           u8 h_magic;                     /* OMFS_IMAGIC */
+           u8 h_check_xor;                 /* XOR of header bytes before this */
+           __be32 h_fill2;
+    };
+
+Files and directories are both represented by omfs_inode::
+
+    struct omfs_inode {
+           struct omfs_header i_head;      /* header */
+           __be64 i_parent;                /* parent containing this inode */
+           __be64 i_sibling;               /* next inode in hash bucket */
+           __be64 i_ctime;                 /* ctime, in milliseconds */
+           char i_fill1[35];
+           char i_type;                    /* OMFS_[DIR,FILE] */
+           __be32 i_fill2;
+           char i_fill3[64];
+           char i_name[OMFS_NAMELEN];      /* filename */
+           __be64 i_size;                  /* size of file, in bytes */
+    };
+
+Directories in OMFS are implemented as a large hash table.  Filenames are
+hashed then prepended into the bucket list beginning at OMFS_DIR_START.
+Lookup requires hashing the filename, then seeking across i_sibling pointers
+until a match is found on i_name.  Empty buckets are represented by block
+pointers with all-1s (~0).
+
+A file is an omfs_inode structure followed by an extent table beginning at
+OMFS_EXTENT_START::
+
+    struct omfs_extent_entry {
+           __be64 e_cluster;               /* start location of a set of blocks */
+           __be64 e_blocks;                /* number of blocks after e_cluster */
+    };
+
+    struct omfs_extent {
+           __be64 e_next;                  /* next extent table location */
+           __be32 e_extent_count;          /* total # extents in this table */
+           __be32 e_fill;
+           struct omfs_extent_entry e_entry;       /* start of extent entries */
+    };
+
+Each extent holds the block offset followed by number of blocks allocated to
+the extent.  The final extent in each table is a terminator with e_cluster
+being ~0 and e_blocks being ones'-complement of the total number of blocks
+in the table.
+
+If this table overflows, a continuation inode is written and pointed to by
+e_next.  These have a header but lack the rest of the inode structure.
+
diff --git a/Documentation/filesystems/omfs.txt b/Documentation/filesystems/omfs.txt
deleted file mode 100644 (file)
index 1d0d41f..0000000
+++ /dev/null
@@ -1,106 +0,0 @@
-Optimized MPEG Filesystem (OMFS)
-
-Overview
-========
-
-OMFS is a filesystem created by SonicBlue for use in the ReplayTV DVR
-and Rio Karma MP3 player.  The filesystem is extent-based, utilizing
-block sizes from 2k to 8k, with hash-based directories.  This
-filesystem driver may be used to read and write disks from these
-devices.
-
-Note, it is not recommended that this FS be used in place of a general
-filesystem for your own streaming media device.  Native Linux filesystems
-will likely perform better.
-
-More information is available at:
-
-    http://linux-karma.sf.net/
-
-Various utilities, including mkomfs and omfsck, are included with
-omfsprogs, available at:
-
-    http://bobcopeland.com/karma/
-
-Instructions are included in its README.
-
-Options
-=======
-
-OMFS supports the following mount-time options:
-
-    uid=n        - make all files owned by specified user
-    gid=n        - make all files owned by specified group
-    umask=xxx    - set permission umask to xxx
-    fmask=xxx    - set umask to xxx for files
-    dmask=xxx    - set umask to xxx for directories
-
-Disk format
-===========
-
-OMFS discriminates between "sysblocks" and normal data blocks.  The sysblock
-group consists of super block information, file metadata, directory structures,
-and extents.  Each sysblock has a header containing CRCs of the entire
-sysblock, and may be mirrored in successive blocks on the disk.  A sysblock may
-have a smaller size than a data block, but since they are both addressed by the
-same 64-bit block number, any remaining space in the smaller sysblock is
-unused.
-
-Sysblock header information:
-
-struct omfs_header {
-        __be64 h_self;                  /* FS block where this is located */
-        __be32 h_body_size;             /* size of useful data after header */
-        __be16 h_crc;                   /* crc-ccitt of body_size bytes */
-        char h_fill1[2];
-        u8 h_version;                   /* version, always 1 */
-        char h_type;                    /* OMFS_INODE_X */
-        u8 h_magic;                     /* OMFS_IMAGIC */
-        u8 h_check_xor;                 /* XOR of header bytes before this */
-        __be32 h_fill2;
-};
-
-Files and directories are both represented by omfs_inode:
-
-struct omfs_inode {
-        struct omfs_header i_head;      /* header */
-        __be64 i_parent;                /* parent containing this inode */
-        __be64 i_sibling;               /* next inode in hash bucket */
-        __be64 i_ctime;                 /* ctime, in milliseconds */
-        char i_fill1[35];
-        char i_type;                    /* OMFS_[DIR,FILE] */
-        __be32 i_fill2;
-        char i_fill3[64];
-        char i_name[OMFS_NAMELEN];      /* filename */
-        __be64 i_size;                  /* size of file, in bytes */
-};
-
-Directories in OMFS are implemented as a large hash table.  Filenames are
-hashed then prepended into the bucket list beginning at OMFS_DIR_START.
-Lookup requires hashing the filename, then seeking across i_sibling pointers
-until a match is found on i_name.  Empty buckets are represented by block
-pointers with all-1s (~0).
-
-A file is an omfs_inode structure followed by an extent table beginning at
-OMFS_EXTENT_START:
-
-struct omfs_extent_entry {
-        __be64 e_cluster;               /* start location of a set of blocks */
-        __be64 e_blocks;                /* number of blocks after e_cluster */
-};
-
-struct omfs_extent {
-        __be64 e_next;                  /* next extent table location */
-        __be32 e_extent_count;          /* total # extents in this table */
-        __be32 e_fill;
-        struct omfs_extent_entry e_entry;       /* start of extent entries */
-};
-
-Each extent holds the block offset followed by number of blocks allocated to
-the extent.  The final extent in each table is a terminator with e_cluster
-being ~0 and e_blocks being ones'-complement of the total number of blocks
-in the table.
-
-If this table overflows, a continuation inode is written and pointed to by
-e_next.  These have a header but lack the rest of the inode structure.
-
similarity index 83%
rename from Documentation/filesystems/orangefs.txt
rename to Documentation/filesystems/orangefs.rst
index f4ba949..7d6d4ca 100644 (file)
@@ -1,3 +1,6 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+========
 ORANGEFS
 ========
 
@@ -21,25 +24,25 @@ Orangefs features include:
   * Stateless
 
 
-MAILING LIST ARCHIVES
+Mailing List Archives
 =====================
 
 http://lists.orangefs.org/pipermail/devel_lists.orangefs.org/
 
 
-MAILING LIST SUBMISSIONS
+Mailing List Submissions
 ========================
 
 devel@lists.orangefs.org
 
 
-DOCUMENTATION
+Documentation
 =============
 
 http://www.orangefs.org/documentation/
 
 
-USERSPACE FILESYSTEM SOURCE
+Userspace Filesystem Source
 ===========================
 
 http://www.orangefs.org/download
@@ -48,16 +51,16 @@ Orangefs versions prior to 2.9.3 would not be compatible with the
 upstream version of the kernel client.
 
 
-RUNNING ORANGEFS ON A SINGLE SERVER
+Running ORANGEFS On a Single Server
 ===================================
 
 OrangeFS is usually run in large installations with multiple servers and
 clients, but a complete filesystem can be run on a single machine for
 development and testing.
 
-On Fedora, install orangefs and orangefs-server.
+On Fedora, install orangefs and orangefs-server::
 
-dnf -y install orangefs orangefs-server
+    dnf -y install orangefs orangefs-server
 
 There is an example server configuration file in
 /etc/orangefs/orangefs.conf.  Change localhost to your hostname if
@@ -70,29 +73,29 @@ single line.  Uncomment it and change the hostname if necessary.  This
 controls clients which use libpvfs2.  This does not control the
 pvfs2-client-core.
 
-Create the filesystem.
+Create the filesystem::
 
-pvfs2-server -f /etc/orangefs/orangefs.conf
+    pvfs2-server -f /etc/orangefs/orangefs.conf
 
-Start the server.
+Start the server::
 
-systemctl start orangefs-server
+    systemctl start orangefs-server
 
-Test the server.
+Test the server::
 
-pvfs2-ping -m /pvfsmnt
+    pvfs2-ping -m /pvfsmnt
 
 Start the client.  The module must be compiled in or loaded before this
-point.
+point::
 
-systemctl start orangefs-client
+    systemctl start orangefs-client
 
-Mount the filesystem.
+Mount the filesystem::
 
-mount -t pvfs2 tcp://localhost:3334/orangefs /pvfsmnt
+    mount -t pvfs2 tcp://localhost:3334/orangefs /pvfsmnt
 
 
-BUILDING ORANGEFS ON A SINGLE SERVER
+Building ORANGEFS on a Single Server
 ====================================
 
 Where OrangeFS cannot be installed from distribution packages, it may be
@@ -102,49 +105,51 @@ You can omit --prefix if you don't care that things are sprinkled around
 in /usr/local.  As of version 2.9.6, OrangeFS uses Berkeley DB by
 default, we will probably be changing the default to LMDB soon.
 
-./configure --prefix=/opt/ofs --with-db-backend=lmdb
+::
 
-make
+    ./configure --prefix=/opt/ofs --with-db-backend=lmdb
 
-make install
+    make
 
-Create an orangefs config file.
+    make install
 
-/opt/ofs/bin/pvfs2-genconfig /etc/pvfs2.conf
+Create an orangefs config file::
 
-Create an /etc/pvfs2tab file.
+    /opt/ofs/bin/pvfs2-genconfig /etc/pvfs2.conf
 
-echo tcp://localhost:3334/orangefs /pvfsmnt pvfs2 defaults,noauto 0 0 > \
-    /etc/pvfs2tab
+Create an /etc/pvfs2tab file::
 
-Create the mount point you specified in the tab file if needed.
+    echo tcp://localhost:3334/orangefs /pvfsmnt pvfs2 defaults,noauto 0 0 > \
+       /etc/pvfs2tab
 
-mkdir /pvfsmnt
+Create the mount point you specified in the tab file if needed::
 
-Bootstrap the server.
+    mkdir /pvfsmnt
 
-/opt/ofs/sbin/pvfs2-server -f /etc/pvfs2.conf
+Bootstrap the server::
 
-Start the server.
+    /opt/ofs/sbin/pvfs2-server -f /etc/pvfs2.conf
 
-/opt/osf/sbin/pvfs2-server /etc/pvfs2.conf
+Start the server::
+
+    /opt/osf/sbin/pvfs2-server /etc/pvfs2.conf
 
 Now the server should be running. Pvfs2-ls is a simple
-test to verify that the server is running.
+test to verify that the server is running::
 
-/opt/ofs/bin/pvfs2-ls /pvfsmnt
+    /opt/ofs/bin/pvfs2-ls /pvfsmnt
 
 If stuff seems to be working, load the kernel module and
-turn on the client core.
+turn on the client core::
 
-/opt/ofs/sbin/pvfs2-client -p /opt/osf/sbin/pvfs2-client-core
+    /opt/ofs/sbin/pvfs2-client -p /opt/osf/sbin/pvfs2-client-core
 
-Mount your filesystem.
+Mount your filesystem::
 
-mount -t pvfs2 tcp://localhost:3334/orangefs /pvfsmnt
+    mount -t pvfs2 tcp://localhost:3334/orangefs /pvfsmnt
 
 
-RUNNING XFSTESTS
+Running xfstests
 ================
 
 It is useful to use a scratch filesystem with xfstests.  This can be
@@ -159,21 +164,23 @@ Then there are two FileSystem sections: orangefs and scratch.
 
 This change should be made before creating the filesystem.
 
-pvfs2-server -f /etc/orangefs/orangefs.conf
+::
+
+    pvfs2-server -f /etc/orangefs/orangefs.conf
 
-To run xfstests, create /etc/xfsqa.config.
+To run xfstests, create /etc/xfsqa.config::
 
-TEST_DIR=/orangefs
-TEST_DEV=tcp://localhost:3334/orangefs
-SCRATCH_MNT=/scratch
-SCRATCH_DEV=tcp://localhost:3334/scratch
+    TEST_DIR=/orangefs
+    TEST_DEV=tcp://localhost:3334/orangefs
+    SCRATCH_MNT=/scratch
+    SCRATCH_DEV=tcp://localhost:3334/scratch
 
-Then xfstests can be run
+Then xfstests can be run::
 
-./check -pvfs2
+    ./check -pvfs2
 
 
-OPTIONS
+Options
 =======
 
 The following mount options are accepted:
@@ -193,32 +200,32 @@ The following mount options are accepted:
     Distributed locking is being worked on for the future.
 
 
-DEBUGGING
+Debugging
 =========
 
 If you want the debug (GOSSIP) statements in a particular
-source file (inode.c for example) go to syslog:
+source file (inode.c for example) go to syslog::
 
   echo inode > /sys/kernel/debug/orangefs/kernel-debug
 
-No debugging (the default):
+No debugging (the default)::
 
   echo none > /sys/kernel/debug/orangefs/kernel-debug
 
-Debugging from several source files:
+Debugging from several source files::
 
   echo inode,dir > /sys/kernel/debug/orangefs/kernel-debug
 
-All debugging:
+All debugging::
 
   echo all > /sys/kernel/debug/orangefs/kernel-debug
 
-Get a list of all debugging keywords:
+Get a list of all debugging keywords::
 
   cat /sys/kernel/debug/orangefs/debug-help
 
 
-PROTOCOL BETWEEN KERNEL MODULE AND USERSPACE
+Protocol between Kernel Module and Userspace
 ============================================
 
 Orangefs is a user space filesystem and an associated kernel module.
@@ -234,7 +241,8 @@ The kernel module implements a pseudo device that userspace
 can read from and write to. Userspace can also manipulate the
 kernel module through the pseudo device with ioctl.
 
-THE BUFMAP:
+The Bufmap
+----------
 
 At startup userspace allocates two page-size-aligned (posix_memalign)
 mlocked memory buffers, one is used for IO and one is used for readdir
@@ -250,7 +258,8 @@ copied from user space to kernel space with copy_from_user and is used
 to initialize the kernel module's "bufmap" (struct orangefs_bufmap), which
 then contains:
 
-  * refcnt - a reference counter
+  * refcnt
+    - a reference counter
   * desc_size - PVFS2_BUFMAP_DEFAULT_DESC_SIZE (4194304) - the IO buffer's
     partition size, which represents the filesystem's block size and
     is used for s_blocksize in super blocks.
@@ -259,17 +268,19 @@ then contains:
   * desc_shift - log2(desc_size), used for s_blocksize_bits in super blocks.
   * total_size - the total size of the IO buffer.
   * page_count - the number of 4096 byte pages in the IO buffer.
-  * page_array - a pointer to page_count * (sizeof(struct page*)) bytes
+  * page_array - a pointer to ``page_count * (sizeof(struct page*))`` bytes
     of kcalloced memory. This memory is used as an array of pointers
     to each of the pages in the IO buffer through a call to get_user_pages.
-  * desc_array - a pointer to desc_count * (sizeof(struct orangefs_bufmap_desc))
+  * desc_array - a pointer to ``desc_count * (sizeof(struct orangefs_bufmap_desc))``
     bytes of kcalloced memory. This memory is further intialized:
 
       user_desc is the kernel's copy of the IO buffer's ORANGEFS_dev_map_desc
       structure. user_desc->ptr points to the IO buffer.
 
-      pages_per_desc = bufmap->desc_size / PAGE_SIZE
-      offset = 0
+      ::
+
+       pages_per_desc = bufmap->desc_size / PAGE_SIZE
+       offset = 0
 
         bufmap->desc_array[0].page_array = &bufmap->page_array[offset]
         bufmap->desc_array[0].array_count = pages_per_desc = 1024
@@ -293,7 +304,8 @@ then contains:
   * readdir_index_lock - a spinlock to protect readdir_index_array during
     update.
 
-OPERATIONS:
+Operations
+----------
 
 The kernel module builds an "op" (struct orangefs_kernel_op_s) when it
 needs to communicate with userspace. Part of the op contains the "upcall"
@@ -308,13 +320,19 @@ in flight at any given time.
 
 Ops are stateful:
 
- * unknown  - op was just initialized
- * waiting  - op is on request_list (upward bound)
- * inprogr  - op is in progress (waiting for downcall)
- * serviced - op has matching downcall; ok
- * purged   - op has to start a timer since client-core
+ * unknown
+           - op was just initialized
+ * waiting
+           - op is on request_list (upward bound)
+ * inprogr
+           - op is in progress (waiting for downcall)
+ * serviced
+           - op has matching downcall; ok
+ * purged
+           - op has to start a timer since client-core
               exited uncleanly before servicing op
- * given up - submitter has given up waiting for it
+ * given up
+           - submitter has given up waiting for it
 
 When some arbitrary userspace program needs to perform a
 filesystem operation on Orangefs (readdir, I/O, create, whatever)
@@ -389,10 +407,15 @@ union of structs, each of which is associated with a particular
 response type.
 
 The several members outside of the union are:
- - int32_t type - type of operation.
- - int32_t status - return code for the operation.
- - int64_t trailer_size - 0 unless readdir operation.
- - char *trailer_buf - initialized to NULL, used during readdir operations.
+
+ ``int32_t type``
+    - type of operation.
+ ``int32_t status``
+    - return code for the operation.
+ ``int64_t trailer_size``
+    - 0 unless readdir operation.
+ ``char *trailer_buf``
+    - initialized to NULL, used during readdir operations.
 
 The appropriate member inside the union is filled out for any
 particular response.
@@ -449,18 +472,20 @@ Userspace uses writev() on /dev/pvfs2-req to pass responses to the requests
 made by the kernel side.
 
 A buffer_list containing:
+
   - a pointer to the prepared response to the request from the
     kernel (struct pvfs2_downcall_t).
   - and also, in the case of a readdir request, a pointer to a
     buffer containing descriptors for the objects in the target
     directory.
+
 ... is sent to the function (PINT_dev_write_list) which performs
 the writev.
 
 PINT_dev_write_list has a local iovec array: struct iovec io_array[10];
 
 The first four elements of io_array are initialized like this for all
-responses:
+responses::
 
   io_array[0].iov_base = address of local variable "proto_ver" (int32_t)
   io_array[0].iov_len = sizeof(int32_t)
@@ -475,7 +500,7 @@ responses:
                          of global variable vfs_request (vfs_request_t)
   io_array[3].iov_len = sizeof(pvfs2_downcall_t)
 
-Readdir responses initialize the fifth element io_array like this:
+Readdir responses initialize the fifth element io_array like this::
 
   io_array[4].iov_base = contents of member trailer_buf (char *)
                          from out_downcall member of global variable
@@ -517,13 +542,13 @@ from a dentry is cheap, obtaining it from userspace is relatively expensive,
 hence the motivation to use the dentry when possible.
 
 The timeout values d_time and getattr_time are jiffy based, and the
-code is designed to avoid the jiffy-wrap problem:
+code is designed to avoid the jiffy-wrap problem::
 
-"In general, if the clock may have wrapped around more than once, there
-is no way to tell how much time has elapsed. However, if the times t1
-and t2 are known to be fairly close, we can reliably compute the
-difference in a way that takes into account the possibility that the
-clock may have wrapped between times."
+    "In general, if the clock may have wrapped around more than once, there
+    is no way to tell how much time has elapsed. However, if the times t1
+    and t2 are known to be fairly close, we can reliably compute the
+    difference in a way that takes into account the possibility that the
+    clock may have wrapped between times."
 
-                      from course notes by instructor Andy Wang
+from course notes by instructor Andy Wang
 
similarity index 65%
rename from Documentation/filesystems/proc.txt
rename to Documentation/filesystems/proc.rst
index 99ca040..38b6069 100644 (file)
@@ -1,19 +1,20 @@
-------------------------------------------------------------------------------
-                       T H E  /proc   F I L E S Y S T E M
-------------------------------------------------------------------------------
-/proc/sys         Terrehon Bowden <terrehon@pacbell.net>        October 7 1999
-                  Bodo Bauer <bb@ricochet.net>
+.. SPDX-License-Identifier: GPL-2.0
+
+====================
+The /proc Filesystem
+====================
+
+=====================  =======================================  ================
+/proc/sys              Terrehon Bowden <terrehon@pacbell.net>,  October 7 1999
+                       Bodo Bauer <bb@ricochet.net>
+2.4.x update          Jorge Nerin <comandante@zaralinux.com>   November 14 2000
+move /proc/sys        Shen Feng <shen@cn.fujitsu.com>          April 1 2009
+fixes/update part 1.1  Stefani Seibold <stefani@seibold.net>    June 9 2009
+=====================  =======================================  ================
+
 
-2.4.x update     Jorge Nerin <comandante@zaralinux.com>      November 14 2000
-move /proc/sys   Shen Feng <shen@cn.fujitsu.com>                 April 1 2009
-------------------------------------------------------------------------------
-Version 1.3                                              Kernel version 2.2.12
-                                             Kernel version 2.4.0-test11-pre4
-------------------------------------------------------------------------------
-fixes/update part 1.1  Stefani Seibold <stefani@seibold.net>       June 9 2009
 
-Table of Contents
------------------
+.. Table of Contents
 
   0     Preface
   0.1  Introduction/Credits
@@ -50,9 +51,8 @@ Table of Contents
   4    Configuring procfs
   4.1  Mount options
 
-------------------------------------------------------------------------------
 Preface
-------------------------------------------------------------------------------
+=======
 
 0.1 Introduction/Credits
 ------------------------
@@ -95,20 +95,18 @@ We don't  guarantee  the  correctness  of this document, and if you come to us
 complaining about  how  you  screwed  up  your  system  because  of  incorrect
 documentation, we won't feel responsible...
 
-------------------------------------------------------------------------------
-CHAPTER 1: COLLECTING SYSTEM INFORMATION
-------------------------------------------------------------------------------
+Chapter 1: Collecting System Information
+========================================
 
-------------------------------------------------------------------------------
 In This Chapter
-------------------------------------------------------------------------------
+---------------
 * Investigating  the  properties  of  the  pseudo  file  system  /proc and its
   ability to provide information on the running Linux system
 * Examining /proc's structure
 * Uncovering  various  information  about the kernel and the processes running
   on the system
-------------------------------------------------------------------------------
 
+------------------------------------------------------------------------------
 
 The proc  file  system acts as an interface to internal data structures in the
 kernel. It  can  be  used to obtain information about the system and to change
@@ -134,9 +132,11 @@ never act on any new process that the kernel may, through chance, have
 also assigned the process ID <pid>. Instead, operations on these FDs
 usually fail with ESRCH.
 
-Table 1-1: Process specific entries in /proc
-..............................................................................
+.. table:: Table 1-1: Process specific entries in /proc
+
+ =============  ===============================================================
  File          Content
+ =============  ===============================================================
  clear_refs    Clears page referenced bits shown in smaps output
  cmdline       Command line arguments
  cpu           Current and last cpu in which it was executed   (2.4)(smp)
@@ -160,10 +160,10 @@ Table 1-1: Process specific entries in /proc
                can be derived from smaps, but is faster and more convenient
  numa_maps     An extension based on maps, showing the memory locality and
                binding policy as well as mem usage (in pages) of each mapping.
-..............................................................................
+ =============  ===============================================================
 
 For example, to get the status information of a process, all you have to do is
-read the file /proc/PID/status:
+read the file /proc/PID/status::
 
   >cat /proc/self/status
   Name:   cat
@@ -222,14 +222,17 @@ contains details information about the process itself.  Its fields are
 explained in Table 1-4.
 
 (for SMP CONFIG users)
+
 For making accounting scalable, RSS related information are handled in an
 asynchronous manner and the value may not be very precise. To see a precise
 snapshot of a moment, you can see /proc/<pid>/smaps file and scan page table.
 It's slow but very precise.
 
-Table 1-2: Contents of the status files (as of 4.19)
-..............................................................................
+.. table:: Table 1-2: Contents of the status files (as of 4.19)
+
+ ==========================  ===================================================
  Field                       Content
+ ==========================  ===================================================
  Name                        filename of the executable
  Umask                       file mode creation mask
  State                       state (R is running, S is sleeping, D is sleeping
@@ -254,7 +257,8 @@ Table 1-2: Contents of the status files (as of 4.19)
  VmPin                       pinned memory size
  VmHWM                       peak resident set size ("high water mark")
  VmRSS                       size of memory portions. It contains the three
-                             following parts (VmRSS = RssAnon + RssFile + RssShmem)
+                             following parts
+                             (VmRSS = RssAnon + RssFile + RssShmem)
  RssAnon                     size of resident anonymous memory
  RssFile                     size of resident file mappings
  RssShmem                    size of resident shmem memory (includes SysV shm,
@@ -292,27 +296,32 @@ Table 1-2: Contents of the status files (as of 4.19)
  Mems_allowed_list           Same as previous, but in "list format"
  voluntary_ctxt_switches     number of voluntary context switches
  nonvoluntary_ctxt_switches  number of non voluntary context switches
-..............................................................................
+ ==========================  ===================================================
 
-Table 1-3: Contents of the statm files (as of 2.6.8-rc3)
-..............................................................................
+
+.. table:: Table 1-3: Contents of the statm files (as of 2.6.8-rc3)
+
+ ======== ===============================      ==============================
  Field    Content
+ ======== ===============================      ==============================
  size     total program size (pages)           (same as VmSize in status)
  resident size of memory portions (pages)      (same as VmRSS in status)
  shared   number of pages that are shared      (i.e. backed by a file, same
                                                as RssFile+RssShmem in status)
  trs      number of pages that are 'code'      (not including libs; broken,
-                                                       includes data segment)
+                                               includes data segment)
  lrs      number of pages of library           (always 0 on 2.6)
  drs      number of pages of data/stack                (including libs; broken,
-                                                       includes library text)
+                                               includes library text)
  dt       number of dirty pages                        (always 0 on 2.6)
-..............................................................................
+ ======== ===============================      ==============================
+
 
+.. table:: Table 1-4: Contents of the stat files (as of 2.6.30-rc7)
 
-Table 1-4: Contents of the stat files (as of 2.6.30-rc7)
-..............................................................................
- Field          Content
+  ============= ===============================================================
+  Field         Content
+  ============= ===============================================================
   pid           process id
   tcomm         filename of the executable
   state         state (R is running, S is sleeping, D is sleeping in an
@@ -348,7 +357,8 @@ Table 1-4: Contents of the stat files (as of 2.6.30-rc7)
   blocked       bitmap of blocked signals
   sigign        bitmap of ignored signals
   sigcatch      bitmap of caught signals
-  0            (place holder, used to be the wchan address, use /proc/PID/wchan instead)
+  0            (place holder, used to be the wchan address,
+               use /proc/PID/wchan instead)
   0             (place holder)
   0             (place holder)
   exit_signal   signal to send to parent thread on exit
@@ -365,39 +375,40 @@ Table 1-4: Contents of the stat files (as of 2.6.30-rc7)
   arg_end       address below which program command line is placed
   env_start     address above which program environment is placed
   env_end       address below which program environment is placed
-  exit_code     the thread's exit_code in the form reported by the waitpid system call
-..............................................................................
+  exit_code     the thread's exit_code in the form reported by the waitpid
+               system call
+  ============= ===============================================================
 
 The /proc/PID/maps file contains the currently mapped memory regions and
 their access permissions.
 
-The format is:
-
-address           perms offset  dev   inode      pathname
-
-08048000-08049000 r-xp 00000000 03:00 8312       /opt/test
-08049000-0804a000 rw-p 00001000 03:00 8312       /opt/test
-0804a000-0806b000 rw-p 00000000 00:00 0          [heap]
-a7cb1000-a7cb2000 ---p 00000000 00:00 0
-a7cb2000-a7eb2000 rw-p 00000000 00:00 0
-a7eb2000-a7eb3000 ---p 00000000 00:00 0
-a7eb3000-a7ed5000 rw-p 00000000 00:00 0
-a7ed5000-a8008000 r-xp 00000000 03:00 4222       /lib/libc.so.6
-a8008000-a800a000 r--p 00133000 03:00 4222       /lib/libc.so.6
-a800a000-a800b000 rw-p 00135000 03:00 4222       /lib/libc.so.6
-a800b000-a800e000 rw-p 00000000 00:00 0
-a800e000-a8022000 r-xp 00000000 03:00 14462      /lib/libpthread.so.0
-a8022000-a8023000 r--p 00013000 03:00 14462      /lib/libpthread.so.0
-a8023000-a8024000 rw-p 00014000 03:00 14462      /lib/libpthread.so.0
-a8024000-a8027000 rw-p 00000000 00:00 0
-a8027000-a8043000 r-xp 00000000 03:00 8317       /lib/ld-linux.so.2
-a8043000-a8044000 r--p 0001b000 03:00 8317       /lib/ld-linux.so.2
-a8044000-a8045000 rw-p 0001c000 03:00 8317       /lib/ld-linux.so.2
-aff35000-aff4a000 rw-p 00000000 00:00 0          [stack]
-ffffe000-fffff000 r-xp 00000000 00:00 0          [vdso]
+The format is::
+
+    address           perms offset  dev   inode      pathname
+
+    08048000-08049000 r-xp 00000000 03:00 8312       /opt/test
+    08049000-0804a000 rw-p 00001000 03:00 8312       /opt/test
+    0804a000-0806b000 rw-p 00000000 00:00 0          [heap]
+    a7cb1000-a7cb2000 ---p 00000000 00:00 0
+    a7cb2000-a7eb2000 rw-p 00000000 00:00 0
+    a7eb2000-a7eb3000 ---p 00000000 00:00 0
+    a7eb3000-a7ed5000 rw-p 00000000 00:00 0
+    a7ed5000-a8008000 r-xp 00000000 03:00 4222       /lib/libc.so.6
+    a8008000-a800a000 r--p 00133000 03:00 4222       /lib/libc.so.6
+    a800a000-a800b000 rw-p 00135000 03:00 4222       /lib/libc.so.6
+    a800b000-a800e000 rw-p 00000000 00:00 0
+    a800e000-a8022000 r-xp 00000000 03:00 14462      /lib/libpthread.so.0
+    a8022000-a8023000 r--p 00013000 03:00 14462      /lib/libpthread.so.0
+    a8023000-a8024000 rw-p 00014000 03:00 14462      /lib/libpthread.so.0
+    a8024000-a8027000 rw-p 00000000 00:00 0
+    a8027000-a8043000 r-xp 00000000 03:00 8317       /lib/ld-linux.so.2
+    a8043000-a8044000 r--p 0001b000 03:00 8317       /lib/ld-linux.so.2
+    a8044000-a8045000 rw-p 0001c000 03:00 8317       /lib/ld-linux.so.2
+    aff35000-aff4a000 rw-p 00000000 00:00 0          [stack]
+    ffffe000-fffff000 r-xp 00000000 00:00 0          [vdso]
 
 where "address" is the address space in the process that it occupies, "perms"
-is a set of permissions:
+is a set of permissions::
 
  r = read
  w = write
@@ -411,42 +422,44 @@ with the memory region, as the case would be with BSS (uninitialized data).
 The "pathname" shows the name associated file for this mapping.  If the mapping
 is not associated with a file:
 
- [heap]                   = the heap of the program
- [stack]                  = the stack of the main process
- [vdso]                   = the "virtual dynamic shared object",
+ =======                    ====================================
+ [heap]                     the heap of the program
+ [stack]                    the stack of the main process
+ [vdso]                     the "virtual dynamic shared object",
                             the kernel system call handler
+ =======                    ====================================
 
  or if empty, the mapping is anonymous.
 
 The /proc/PID/smaps is an extension based on maps, showing the memory
 consumption for each of the process's mappings. For each mapping (aka Virtual
-Memory Area, or VMA) there is a series of lines such as the following:
-
-08048000-080bc000 r-xp 00000000 03:02 13130      /bin/bash
-
-Size:               1084 kB
-KernelPageSize:        4 kB
-MMUPageSize:           4 kB
-Rss:                 892 kB
-Pss:                 374 kB
-Shared_Clean:        892 kB
-Shared_Dirty:          0 kB
-Private_Clean:         0 kB
-Private_Dirty:         0 kB
-Referenced:          892 kB
-Anonymous:             0 kB
-LazyFree:              0 kB
-AnonHugePages:         0 kB
-ShmemPmdMapped:        0 kB
-Shared_Hugetlb:        0 kB
-Private_Hugetlb:       0 kB
-Swap:                  0 kB
-SwapPss:               0 kB
-KernelPageSize:        4 kB
-MMUPageSize:           4 kB
-Locked:                0 kB
-THPeligible:           0
-VmFlags: rd ex mr mw me dw
+Memory Area, or VMA) there is a series of lines such as the following::
+
+    08048000-080bc000 r-xp 00000000 03:02 13130      /bin/bash
+
+    Size:               1084 kB
+    KernelPageSize:        4 kB
+    MMUPageSize:           4 kB
+    Rss:                 892 kB
+    Pss:                 374 kB
+    Shared_Clean:        892 kB
+    Shared_Dirty:          0 kB
+    Private_Clean:         0 kB
+    Private_Dirty:         0 kB
+    Referenced:          892 kB
+    Anonymous:             0 kB
+    LazyFree:              0 kB
+    AnonHugePages:         0 kB
+    ShmemPmdMapped:        0 kB
+    Shared_Hugetlb:        0 kB
+    Private_Hugetlb:       0 kB
+    Swap:                  0 kB
+    SwapPss:               0 kB
+    KernelPageSize:        4 kB
+    MMUPageSize:           4 kB
+    Locked:                0 kB
+    THPeligible:           0
+    VmFlags: rd ex mr mw me dw
 
 The first of these lines shows the same information as is displayed for the
 mapping in /proc/PID/maps.  Following lines show the size of the mapping
@@ -461,26 +474,35 @@ The "proportional set size" (PSS) of a process is the count of pages it has
 in memory, where each page is divided by the number of processes sharing it.
 So if a process has 1000 pages all to itself, and 1000 shared with one other
 process, its PSS will be 1500.
+
 Note that even a page which is part of a MAP_SHARED mapping, but has only
 a single pte mapped, i.e.  is currently used by only one process, is accounted
 as private and not as shared.
+
 "Referenced" indicates the amount of memory currently marked as referenced or
 accessed.
+
 "Anonymous" shows the amount of memory that does not belong to any file.  Even
 a mapping associated with a file may contain anonymous pages: when MAP_PRIVATE
 and a page is modified, the file page is replaced by a private anonymous copy.
+
 "LazyFree" shows the amount of memory which is marked by madvise(MADV_FREE).
 The memory isn't freed immediately with madvise(). It's freed in memory
 pressure if the memory is clean. Please note that the printed value might
 be lower than the real value due to optimizations used in the current
 implementation. If this is not desirable please file a bug report.
+
 "AnonHugePages" shows the ammount of memory backed by transparent hugepage.
+
 "ShmemPmdMapped" shows the ammount of shared (shmem/tmpfs) memory backed by
 huge pages.
+
 "Shared_Hugetlb" and "Private_Hugetlb" show the ammounts of memory backed by
 hugetlbfs page which is *not* counted in "RSS" or "PSS" field for historical
 reasons. And these are not included in {Shared,Private}_{Clean,Dirty} field.
+
 "Swap" shows how much would-be-anonymous memory is also used, but out on swap.
+
 For shmem mappings, "Swap" includes also the size of the mapped (and not
 replaced by copy-on-write) part of the underlying shmem object out on swap.
 "SwapPss" shows proportional swap share of this mapping. Unlike "Swap", this
@@ -489,36 +511,39 @@ does not take into account swapped out page of underlying shmem objects.
 "THPeligible" indicates whether the mapping is eligible for allocating THP
 pages - 1 if true, 0 otherwise. It just shows the current status.
 
-"VmFlags" field deserves a separate description. This member represents the kernel
-flags associated with the particular virtual memory area in two letter encoded
-manner. The codes are the following:
-    rd  - readable
-    wr  - writeable
-    ex  - executable
-    sh  - shared
-    mr  - may read
-    mw  - may write
-    me  - may execute
-    ms  - may share
-    gd  - stack segment growns down
-    pf  - pure PFN range
-    dw  - disabled write to the mapped file
-    lo  - pages are locked in memory
-    io  - memory mapped I/O area
-    sr  - sequential read advise provided
-    rr  - random read advise provided
-    dc  - do not copy area on fork
-    de  - do not expand area on remapping
-    ac  - area is accountable
-    nr  - swap space is not reserved for the area
-    ht  - area uses huge tlb pages
-    ar  - architecture specific flag
-    dd  - do not include area into core dump
-    sd  - soft-dirty flag
-    mm  - mixed map area
-    hg  - huge page advise flag
-    nh  - no-huge page advise flag
-    mg  - mergable advise flag
+"VmFlags" field deserves a separate description. This member represents the
+kernel flags associated with the particular virtual memory area in two letter
+encoded manner. The codes are the following:
+
+    ==    =======================================
+    rd    readable
+    wr    writeable
+    ex    executable
+    sh    shared
+    mr    may read
+    mw    may write
+    me    may execute
+    ms    may share
+    gd    stack segment growns down
+    pf    pure PFN range
+    dw    disabled write to the mapped file
+    lo    pages are locked in memory
+    io    memory mapped I/O area
+    sr    sequential read advise provided
+    rr    random read advise provided
+    dc    do not copy area on fork
+    de    do not expand area on remapping
+    ac    area is accountable
+    nr    swap space is not reserved for the area
+    ht    area uses huge tlb pages
+    ar    architecture specific flag
+    dd    do not include area into core dump
+    sd    soft dirty flag
+    mm    mixed map area
+    hg    huge page advise flag
+    nh    no huge page advise flag
+    mg    mergable advise flag
+    ==    =======================================
 
 Note that there is no guarantee that every flag and associated mnemonic will
 be present in all further kernel releases. Things get changed, the flags may
@@ -531,6 +556,7 @@ enabled.
 
 Note: reading /proc/PID/maps or /proc/PID/smaps is inherently racy (consistent
 output can be achieved only in the single read call).
+
 This typically manifests when doing partial reads of these files while the
 memory map is being modified.  Despite the races, we do provide the following
 guarantees:
@@ -544,9 +570,9 @@ The /proc/PID/smaps_rollup file includes the same fields as /proc/PID/smaps,
 but their values are the sums of the corresponding values for all mappings of
 the process.  Additionally, it contains these fields:
 
-Pss_Anon
-Pss_File
-Pss_Shmem
+Pss_Anon
+Pss_File
+Pss_Shmem
 
 They represent the proportional shares of anonymous, file, and shmem pages, as
 described for smaps above.  These fields are omitted in smaps since each
@@ -558,20 +584,25 @@ The /proc/PID/clear_refs is used to reset the PG_Referenced and ACCESSED/YOUNG
 bits on both physical and virtual pages associated with a process, and the
 soft-dirty bit on pte (see Documentation/admin-guide/mm/soft-dirty.rst
 for details).
-To clear the bits for all the pages associated with the process
+To clear the bits for all the pages associated with the process::
+
     > echo 1 > /proc/PID/clear_refs
 
-To clear the bits for the anonymous pages associated with the process
+To clear the bits for the anonymous pages associated with the process::
+
     > echo 2 > /proc/PID/clear_refs
 
-To clear the bits for the file mapped pages associated with the process
+To clear the bits for the file mapped pages associated with the process::
+
     > echo 3 > /proc/PID/clear_refs
 
-To clear the soft-dirty bit
+To clear the soft-dirty bit::
+
     > echo 4 > /proc/PID/clear_refs
 
 To reset the peak resident set size ("high water mark") to the process's
-current value:
+current value::
+
     > echo 5 > /proc/PID/clear_refs
 
 Any other value written to /proc/PID/clear_refs will have no effect.
@@ -584,30 +615,33 @@ Documentation/admin-guide/mm/pagemap.rst.
 The /proc/pid/numa_maps is an extension based on maps, showing the memory
 locality and binding policy, as well as the memory usage (in pages) of
 each mapping. The output follows a general format where mapping details get
-summarized separated by blank spaces, one mapping per each file line:
-
-address   policy    mapping details
-
-00400000 default file=/usr/local/bin/app mapped=1 active=0 N3=1 kernelpagesize_kB=4
-00600000 default file=/usr/local/bin/app anon=1 dirty=1 N3=1 kernelpagesize_kB=4
-3206000000 default file=/lib64/ld-2.12.so mapped=26 mapmax=6 N0=24 N3=2 kernelpagesize_kB=4
-320621f000 default file=/lib64/ld-2.12.so anon=1 dirty=1 N3=1 kernelpagesize_kB=4
-3206220000 default file=/lib64/ld-2.12.so anon=1 dirty=1 N3=1 kernelpagesize_kB=4
-3206221000 default anon=1 dirty=1 N3=1 kernelpagesize_kB=4
-3206800000 default file=/lib64/libc-2.12.so mapped=59 mapmax=21 active=55 N0=41 N3=18 kernelpagesize_kB=4
-320698b000 default file=/lib64/libc-2.12.so
-3206b8a000 default file=/lib64/libc-2.12.so anon=2 dirty=2 N3=2 kernelpagesize_kB=4
-3206b8e000 default file=/lib64/libc-2.12.so anon=1 dirty=1 N3=1 kernelpagesize_kB=4
-3206b8f000 default anon=3 dirty=3 active=1 N3=3 kernelpagesize_kB=4
-7f4dc10a2000 default anon=3 dirty=3 N3=3 kernelpagesize_kB=4
-7f4dc10b4000 default anon=2 dirty=2 active=1 N3=2 kernelpagesize_kB=4
-7f4dc1200000 default file=/anon_hugepage\040(deleted) huge anon=1 dirty=1 N3=1 kernelpagesize_kB=2048
-7fff335f0000 default stack anon=3 dirty=3 N3=3 kernelpagesize_kB=4
-7fff3369d000 default mapped=1 mapmax=35 active=0 N3=1 kernelpagesize_kB=4
+summarized separated by blank spaces, one mapping per each file line::
+
+    address   policy    mapping details
+
+    00400000 default file=/usr/local/bin/app mapped=1 active=0 N3=1 kernelpagesize_kB=4
+    00600000 default file=/usr/local/bin/app anon=1 dirty=1 N3=1 kernelpagesize_kB=4
+    3206000000 default file=/lib64/ld-2.12.so mapped=26 mapmax=6 N0=24 N3=2 kernelpagesize_kB=4
+    320621f000 default file=/lib64/ld-2.12.so anon=1 dirty=1 N3=1 kernelpagesize_kB=4
+    3206220000 default file=/lib64/ld-2.12.so anon=1 dirty=1 N3=1 kernelpagesize_kB=4
+    3206221000 default anon=1 dirty=1 N3=1 kernelpagesize_kB=4
+    3206800000 default file=/lib64/libc-2.12.so mapped=59 mapmax=21 active=55 N0=41 N3=18 kernelpagesize_kB=4
+    320698b000 default file=/lib64/libc-2.12.so
+    3206b8a000 default file=/lib64/libc-2.12.so anon=2 dirty=2 N3=2 kernelpagesize_kB=4
+    3206b8e000 default file=/lib64/libc-2.12.so anon=1 dirty=1 N3=1 kernelpagesize_kB=4
+    3206b8f000 default anon=3 dirty=3 active=1 N3=3 kernelpagesize_kB=4
+    7f4dc10a2000 default anon=3 dirty=3 N3=3 kernelpagesize_kB=4
+    7f4dc10b4000 default anon=2 dirty=2 active=1 N3=2 kernelpagesize_kB=4
+    7f4dc1200000 default file=/anon_hugepage\040(deleted) huge anon=1 dirty=1 N3=1 kernelpagesize_kB=2048
+    7fff335f0000 default stack anon=3 dirty=3 N3=3 kernelpagesize_kB=4
+    7fff3369d000 default mapped=1 mapmax=35 active=0 N3=1 kernelpagesize_kB=4
 
 Where:
+
 "address" is the starting address for the mapping;
+
 "policy" reports the NUMA memory policy set for the mapping (see Documentation/admin-guide/mm/numa_memory_policy.rst);
+
 "mapping details" summarizes mapping data such as mapping type, page usage counters,
 node locality page counters (N0 == node0, N1 == node1, ...) and the kernel page
 size, in KB, that is backing the mapping up.
@@ -621,81 +655,83 @@ the running kernel. The files used to obtain this information are contained in
 system. It  depends  on the kernel configuration and the loaded modules, which
 files are there, and which are missing.
 
-Table 1-5: Kernel info in /proc
-..............................................................................
- File        Content                                           
- apm         Advanced power management info                    
- buddyinfo   Kernel memory allocator information (see text)    (2.5)
- bus         Directory containing bus specific information     
- cmdline     Kernel command line                               
- cpuinfo     Info about the CPU                                
- devices     Available devices (block and character)           
- dma         Used DMS channels                                 
- filesystems Supported filesystems                             
- driver             Various drivers grouped here, currently rtc (2.4)
- execdomains Execdomains, related to security                  (2.4)
- fb         Frame Buffer devices                               (2.4)
- fs         File system parameters, currently nfs/exports      (2.4)
- ide         Directory containing info about the IDE subsystem 
- interrupts  Interrupt usage                                   
- iomem      Memory map                                         (2.4)
- ioports     I/O port usage                                    
- irq        Masks for irq to cpu affinity                      (2.4)(smp?)
- isapnp             ISA PnP (Plug&Play) Info                           (2.4)
- kcore       Kernel core image (can be ELF or A.OUT(deprecated in 2.4))   
- kmsg        Kernel messages                                   
- ksyms       Kernel symbol table                               
- loadavg     Load average of last 1, 5 & 15 minutes                
- locks       Kernel locks                                      
- meminfo     Memory info                                       
- misc        Miscellaneous                                     
- modules     List of loaded modules                            
- mounts      Mounted filesystems                               
- net         Networking info (see text)                        
+.. table:: Table 1-5: Kernel info in /proc
+
+ ============ ===============================================================
+ File         Content
+ ============ ===============================================================
+ apm          Advanced power management info
+ buddyinfo    Kernel memory allocator information (see text)   (2.5)
+ bus          Directory containing bus specific information
+ cmdline      Kernel command line
+ cpuinfo      Info about the CPU
+ devices      Available devices (block and character)
+ dma          Used DMS channels
+ filesystems  Supported filesystems
+ driver       Various drivers grouped here, currently rtc      (2.4)
+ execdomains  Execdomains, related to security                 (2.4)
+ fb          Frame Buffer devices                              (2.4)
+ fs          File system parameters, currently nfs/exports     (2.4)
+ ide          Directory containing info about the IDE subsystem
+ interrupts   Interrupt usage
+ iomem               Memory map                                        (2.4)
+ ioports      I/O port usage
+ irq         Masks for irq to cpu affinity                     (2.4)(smp?)
+ isapnp       ISA PnP (Plug&Play) Info                         (2.4)
+ kcore        Kernel core image (can be ELF or A.OUT(deprecated in 2.4))
+ kmsg         Kernel messages
+ ksyms        Kernel symbol table
+ loadavg      Load average of last 1, 5 & 15 minutes
+ locks        Kernel locks
+ meminfo      Memory info
+ misc         Miscellaneous
+ modules      List of loaded modules
+ mounts       Mounted filesystems
+ net          Networking info (see text)
  pagetypeinfo Additional page allocator information (see text)  (2.5)
- partitions  Table of partitions known to the system           
- pci        Deprecated info of PCI bus (new way -> /proc/bus/pci/,
-             decoupled by lspci                                        (2.4)
- rtc         Real time clock                                   
- scsi        SCSI info (see text)                              
- slabinfo    Slab pool info                                    
- softirqs    softirq usage
- stat        Overall statistics                                
- swaps       Swap space utilization                            
- sys         See chapter 2                                     
- sysvipc     Info of SysVIPC Resources (msg, sem, shm)         (2.4)
- tty        Info of tty drivers
- uptime      Wall clock since boot, combined idle time of all cpus
- version     Kernel version                                    
- video      bttv info of video resources                       (2.4)
- vmallocinfo Show vmalloced areas
-..............................................................................
+ partitions   Table of partitions known to the system
+ pci         Deprecated info of PCI bus (new way -> /proc/bus/pci/,
+              decoupled by lspci                               (2.4)
+ rtc          Real time clock
+ scsi         SCSI info (see text)
+ slabinfo     Slab pool info
+ softirqs     softirq usage
+ stat         Overall statistics
+ swaps        Swap space utilization
+ sys          See chapter 2
+ sysvipc      Info of SysVIPC Resources (msg, sem, shm)                (2.4)
+ tty         Info of tty drivers
+ uptime       Wall clock since boot, combined idle time of all cpus
+ version      Kernel version
+ video               bttv info of video resources                      (2.4)
+ vmallocinfo  Show vmalloced areas
+ ============ ===============================================================
 
 You can,  for  example,  check  which interrupts are currently in use and what
-they are used for by looking in the file /proc/interrupts:
-
-  > cat /proc/interrupts 
-             CPU0        
-    0:    8728810          XT-PIC  timer 
-    1:        895          XT-PIC  keyboard 
-    2:          0          XT-PIC  cascade 
-    3:     531695          XT-PIC  aha152x 
-    4:    2014133          XT-PIC  serial 
-    5:      44401          XT-PIC  pcnet_cs 
-    8:          2          XT-PIC  rtc 
-   11:          8          XT-PIC  i82365 
-   12:     182918          XT-PIC  PS/2 Mouse 
-   13:          1          XT-PIC  fpu 
-   14:    1232265          XT-PIC  ide0 
-   15:          7          XT-PIC  ide1 
-  NMI:          0 
+they are used for by looking in the file /proc/interrupts::
+
+  > cat /proc/interrupts
+             CPU0
+    0:    8728810          XT-PIC  timer
+    1:        895          XT-PIC  keyboard
+    2:          0          XT-PIC  cascade
+    3:     531695          XT-PIC  aha152x
+    4:    2014133          XT-PIC  serial
+    5:      44401          XT-PIC  pcnet_cs
+    8:          2          XT-PIC  rtc
+   11:          8          XT-PIC  i82365
+   12:     182918          XT-PIC  PS/2 Mouse
+   13:          1          XT-PIC  fpu
+   14:    1232265          XT-PIC  ide0
+   15:          7          XT-PIC  ide1
+  NMI:          0
 
 In 2.4.* a couple of lines where added to this file LOC & ERR (this time is the
-output of a SMP machine):
+output of a SMP machine)::
 
-  > cat /proc/interrupts 
+  > cat /proc/interrupts
 
-             CPU0       CPU1       
+             CPU0       CPU1
     0:    1243498    1214548    IO-APIC-edge  timer
     1:       8949       8958    IO-APIC-edge  keyboard
     2:          0          0          XT-PIC  cascade
@@ -708,8 +744,8 @@ output of a SMP machine):
    15:       2183       2415    IO-APIC-edge  ide1
    17:      30564      30414   IO-APIC-level  eth0
    18:        177        164   IO-APIC-level  bttv
-  NMI:    2457961    2457959 
-  LOC:    2457882    2457881 
+  NMI:    2457961    2457959
+  LOC:    2457882    2457881
   ERR:       2155
 
 NMI is incremented in this case because every timer interrupt generates a NMI
@@ -726,21 +762,25 @@ In 2.6.2* /proc/interrupts was expanded again.  This time the goal was for
 /proc/interrupts to display every IRQ vector in use by the system, not
 just those considered 'most important'.  The new vectors are:
 
-  THR -- interrupt raised when a machine check threshold counter
+THR
+  interrupt raised when a machine check threshold counter
   (typically counting ECC corrected errors of memory or cache) exceeds
   a configurable threshold.  Only available on some systems.
 
-  TRM -- a thermal event interrupt occurs when a temperature threshold
+TRM
+  a thermal event interrupt occurs when a temperature threshold
   has been exceeded for the CPU.  This interrupt may also be generated
   when the temperature drops back to normal.
 
-  SPU -- a spurious interrupt is some interrupt that was raised then lowered
+SPU
+  a spurious interrupt is some interrupt that was raised then lowered
   by some IO device before it could be fully processed by the APIC.  Hence
   the APIC sees the interrupt but does not know what device it came from.
   For this case the APIC will generate the interrupt with a IRQ vector
   of 0xff. This might also be generated by chipset bugs.
 
-  RES, CAL, TLB -- rescheduling, call and TLB flush interrupts are
+RES, CAL, TLB]
+  rescheduling, call and TLB flush interrupts are
   sent from one CPU to another per the needs of the OS.  Typically,
   their statistics are used by kernel developers and interested users to
   determine the occurrence of interrupts of the given type.
@@ -756,7 +796,8 @@ IRQ to only one CPU, or to exclude a CPU of handling IRQs. The contents of the
 irq subdir is one subdir for each IRQ, and two files; default_smp_affinity and
 prof_cpu_mask.
 
-For example 
+For example::
+
   > ls /proc/irq/
   0  10  12  14  16  18  2  4  6  8  prof_cpu_mask
   1  11  13  15  17  19  3  5  7  9  default_smp_affinity
@@ -764,20 +805,20 @@ For example
   smp_affinity
 
 smp_affinity is a bitmask, in which you can specify which CPUs can handle the
-IRQ, you can set it by doing:
+IRQ, you can set it by doing::
 
   > echo 1 > /proc/irq/10/smp_affinity
 
 This means that only the first CPU will handle the IRQ, but you can also echo
 5 which means that only the first and third CPU can handle the IRQ.
 
-The contents of each smp_affinity file is the same by default:
+The contents of each smp_affinity file is the same by default::
 
   > cat /proc/irq/0/smp_affinity
   ffffffff
 
 There is an alternate interface, smp_affinity_list which allows specifying
-a cpu range instead of a bitmask:
+a cpu range instead of a bitmask::
 
   > cat /proc/irq/0/smp_affinity_list
   1024-1031
@@ -810,46 +851,46 @@ Linux uses  slab  pools for memory management above page level in version 2.2.
 Commonly used  objects  have  their  own  slab  pool (such as network buffers,
 directory cache, and so on).
 
-..............................................................................
+::
 
-> cat /proc/buddyinfo
+    > cat /proc/buddyinfo
 
-Node 0, zone      DMA      0      4      5      4      4      3 ...
-Node 0, zone   Normal      1      0      0      1    101      8 ...
-Node 0, zone  HighMem      2      0      0      1      1      0 ...
+    Node 0, zone      DMA      0      4      5      4      4      3 ...
+    Node 0, zone   Normal      1      0      0      1    101      8 ...
+    Node 0, zone  HighMem      2      0      0      1      1      0 ...
 
 External fragmentation is a problem under some workloads, and buddyinfo is a
-useful tool for helping diagnose these problems.  Buddyinfo will give you a 
+useful tool for helping diagnose these problems.  Buddyinfo will give you a
 clue as to how big an area you can safely allocate, or why a previous
 allocation failed.
 
-Each column represents the number of pages of a certain order which are 
-available.  In this case, there are 0 chunks of 2^0*PAGE_SIZE available in 
-ZONE_DMA, 4 chunks of 2^1*PAGE_SIZE in ZONE_DMA, 101 chunks of 2^4*PAGE_SIZE 
-available in ZONE_NORMAL, etc... 
+Each column represents the number of pages of a certain order which are
+available.  In this case, there are 0 chunks of 2^0*PAGE_SIZE available in
+ZONE_DMA, 4 chunks of 2^1*PAGE_SIZE in ZONE_DMA, 101 chunks of 2^4*PAGE_SIZE
+available in ZONE_NORMAL, etc...
 
 More information relevant to external fragmentation can be found in
-pagetypeinfo.
-
-> cat /proc/pagetypeinfo
-Page block order: 9
-Pages per block:  512
-
-Free pages count per migrate type at order       0      1      2      3      4      5      6      7      8      9     10
-Node    0, zone      DMA, type    Unmovable      0      0      0      1      1      1      1      1      1      1      0
-Node    0, zone      DMA, type  Reclaimable      0      0      0      0      0      0      0      0      0      0      0
-Node    0, zone      DMA, type      Movable      1      1      2      1      2      1      1      0      1      0      2
-Node    0, zone      DMA, type      Reserve      0      0      0      0      0      0      0      0      0      1      0
-Node    0, zone      DMA, type      Isolate      0      0      0      0      0      0      0      0      0      0      0
-Node    0, zone    DMA32, type    Unmovable    103     54     77      1      1      1     11      8      7      1      9
-Node    0, zone    DMA32, type  Reclaimable      0      0      2      1      0      0      0      0      1      0      0
-Node    0, zone    DMA32, type      Movable    169    152    113     91     77     54     39     13      6      1    452
-Node    0, zone    DMA32, type      Reserve      1      2      2      2      2      0      1      1      1      1      0
-Node    0, zone    DMA32, type      Isolate      0      0      0      0      0      0      0      0      0      0      0
-
-Number of blocks type     Unmovable  Reclaimable      Movable      Reserve      Isolate
-Node 0, zone      DMA            2            0            5            1            0
-Node 0, zone    DMA32           41            6          967            2            0
+pagetypeinfo::
+
+    > cat /proc/pagetypeinfo
+    Page block order: 9
+    Pages per block:  512
+
+    Free pages count per migrate type at order       0      1      2      3      4      5      6      7      8      9     10
+    Node    0, zone      DMA, type    Unmovable      0      0      0      1      1      1      1      1      1      1      0
+    Node    0, zone      DMA, type  Reclaimable      0      0      0      0      0      0      0      0      0      0      0
+    Node    0, zone      DMA, type      Movable      1      1      2      1      2      1      1      0      1      0      2
+    Node    0, zone      DMA, type      Reserve      0      0      0      0      0      0      0      0      0      1      0
+    Node    0, zone      DMA, type      Isolate      0      0      0      0      0      0      0      0      0      0      0
+    Node    0, zone    DMA32, type    Unmovable    103     54     77      1      1      1     11      8      7      1      9
+    Node    0, zone    DMA32, type  Reclaimable      0      0      2      1      0      0      0      0      1      0      0
+    Node    0, zone    DMA32, type      Movable    169    152    113     91     77     54     39     13      6      1    452
+    Node    0, zone    DMA32, type      Reserve      1      2      2      2      2      0      1      1      1      1      0
+    Node    0, zone    DMA32, type      Isolate      0      0      0      0      0      0      0      0      0      0      0
+
+    Number of blocks type     Unmovable  Reclaimable      Movable      Reserve      Isolate
+    Node 0, zone      DMA            2            0            5            1            0
+    Node 0, zone    DMA32           41            6          967            2            0
 
 Fragmentation avoidance in the kernel works by grouping pages of different
 migrate types into the same contiguous regions of memory called page blocks.
@@ -870,59 +911,63 @@ unless memory has been mlock()'d. Some of the Reclaimable blocks should
 also be allocatable although a lot of filesystem metadata may have to be
 reclaimed to achieve this.
 
-..............................................................................
 
-meminfo:
+meminfo
+~~~~~~~
 
 Provides information about distribution and utilization of memory.  This
 varies by architecture and compile options.  The following is from a
 16GB PIII, which has highmem enabled.  You may not have all of these fields.
 
-> cat /proc/meminfo
-
-MemTotal:     16344972 kB
-MemFree:      13634064 kB
-MemAvailable: 14836172 kB
-Buffers:          3656 kB
-Cached:        1195708 kB
-SwapCached:          0 kB
-Active:         891636 kB
-Inactive:      1077224 kB
-HighTotal:    15597528 kB
-HighFree:     13629632 kB
-LowTotal:       747444 kB
-LowFree:          4432 kB
-SwapTotal:           0 kB
-SwapFree:            0 kB
-Dirty:             968 kB
-Writeback:           0 kB
-AnonPages:      861800 kB
-Mapped:         280372 kB
-Shmem:             644 kB
-KReclaimable:   168048 kB
-Slab:           284364 kB
-SReclaimable:   159856 kB
-SUnreclaim:     124508 kB
-PageTables:      24448 kB
-NFS_Unstable:        0 kB
-Bounce:              0 kB
-WritebackTmp:        0 kB
-CommitLimit:   7669796 kB
-Committed_AS:   100056 kB
-VmallocTotal:   112216 kB
-VmallocUsed:       428 kB
-VmallocChunk:   111088 kB
-Percpu:          62080 kB
-HardwareCorrupted:   0 kB
-AnonHugePages:   49152 kB
-ShmemHugePages:      0 kB
-ShmemPmdMapped:      0 kB
-
-
-    MemTotal: Total usable ram (i.e. physical ram minus a few reserved
+::
+
+    > cat /proc/meminfo
+
+    MemTotal:     16344972 kB
+    MemFree:      13634064 kB
+    MemAvailable: 14836172 kB
+    Buffers:          3656 kB
+    Cached:        1195708 kB
+    SwapCached:          0 kB
+    Active:         891636 kB
+    Inactive:      1077224 kB
+    HighTotal:    15597528 kB
+    HighFree:     13629632 kB
+    LowTotal:       747444 kB
+    LowFree:          4432 kB
+    SwapTotal:           0 kB
+    SwapFree:            0 kB
+    Dirty:             968 kB
+    Writeback:           0 kB
+    AnonPages:      861800 kB
+    Mapped:         280372 kB
+    Shmem:             644 kB
+    KReclaimable:   168048 kB
+    Slab:           284364 kB
+    SReclaimable:   159856 kB
+    SUnreclaim:     124508 kB
+    PageTables:      24448 kB
+    NFS_Unstable:        0 kB
+    Bounce:              0 kB
+    WritebackTmp:        0 kB
+    CommitLimit:   7669796 kB
+    Committed_AS:   100056 kB
+    VmallocTotal:   112216 kB
+    VmallocUsed:       428 kB
+    VmallocChunk:   111088 kB
+    Percpu:          62080 kB
+    HardwareCorrupted:   0 kB
+    AnonHugePages:   49152 kB
+    ShmemHugePages:      0 kB
+    ShmemPmdMapped:      0 kB
+
+MemTotal
+              Total usable ram (i.e. physical ram minus a few reserved
               bits and the kernel binary code)
-     MemFree: The sum of LowFree+HighFree
-MemAvailable: An estimate of how much memory is available for starting new
+MemFree
+              The sum of LowFree+HighFree
+MemAvailable
+              An estimate of how much memory is available for starting new
               applications, without swapping. Calculated from MemFree,
               SReclaimable, the size of the file LRU lists, and the low
               watermarks in each zone.
@@ -930,69 +975,99 @@ MemAvailable: An estimate of how much memory is available for starting new
               page cache to function well, and that not all reclaimable
               slab will be reclaimable, due to items being in use. The
               impact of those factors will vary from system to system.
-     Buffers: Relatively temporary storage for raw disk blocks
+Buffers
+              Relatively temporary storage for raw disk blocks
               shouldn't get tremendously large (20MB or so)
-      Cached: in-memory cache for files read from the disk (the
+Cached
+              in-memory cache for files read from the disk (the
               pagecache).  Doesn't include SwapCached
-  SwapCached: Memory that once was swapped out, is swapped back in but
+SwapCached
+              Memory that once was swapped out, is swapped back in but
               still also is in the swapfile (if memory is needed it
               doesn't need to be swapped out AGAIN because it is already
               in the swapfile. This saves I/O)
-      Active: Memory that has been used more recently and usually not
+Active
+              Memory that has been used more recently and usually not
               reclaimed unless absolutely necessary.
-    Inactive: Memory which has been less recently used.  It is more
+Inactive
+              Memory which has been less recently used.  It is more
               eligible to be reclaimed for other purposes
-   HighTotal:
-    HighFree: Highmem is all memory above ~860MB of physical memory
+HighTotal, HighFree
+              Highmem is all memory above ~860MB of physical memory
               Highmem areas are for use by userspace programs, or
               for the pagecache.  The kernel must use tricks to access
               this memory, making it slower to access than lowmem.
-    LowTotal:
-     LowFree: Lowmem is memory which can be used for everything that
+LowTotal, LowFree
+              Lowmem is memory which can be used for everything that
               highmem can be used for, but it is also available for the
               kernel's use for its own data structures.  Among many
               other things, it is where everything from the Slab is
               allocated.  Bad things happen when you're out of lowmem.
-   SwapTotal: total amount of swap space available
-    SwapFree: Memory which has been evicted from RAM, and is temporarily
+SwapTotal
+              total amount of swap space available
+SwapFree
+              Memory which has been evicted from RAM, and is temporarily
               on the disk
-       Dirty: Memory which is waiting to get written back to the disk
-   Writeback: Memory which is actively being written back to the disk
-   AnonPages: Non-file backed pages mapped into userspace page tables
-HardwareCorrupted: The amount of RAM/memory in KB, the kernel identifies as
+Dirty
+              Memory which is waiting to get written back to the disk
+Writeback
+              Memory which is actively being written back to the disk
+AnonPages
+              Non-file backed pages mapped into userspace page tables
+HardwareCorrupted
+              The amount of RAM/memory in KB, the kernel identifies as
              corrupted.
-AnonHugePages: Non-file backed huge pages mapped into userspace page tables
-      Mapped: files which have been mmaped, such as libraries
-       Shmem: Total memory used by shared memory (shmem) and tmpfs
-ShmemHugePages: Memory used by shared memory (shmem) and tmpfs allocated
+AnonHugePages
+              Non-file backed huge pages mapped into userspace page tables
+Mapped
+              files which have been mmaped, such as libraries
+Shmem
+              Total memory used by shared memory (shmem) and tmpfs
+ShmemHugePages
+              Memory used by shared memory (shmem) and tmpfs allocated
               with huge pages
-ShmemPmdMapped: Shared memory mapped into userspace with huge pages
-KReclaimable: Kernel allocations that the kernel will attempt to reclaim
+ShmemPmdMapped
+              Shared memory mapped into userspace with huge pages
+KReclaimable
+              Kernel allocations that the kernel will attempt to reclaim
               under memory pressure. Includes SReclaimable (below), and other
               direct allocations with a shrinker.
-        Slab: in-kernel data structures cache
-SReclaimable: Part of Slab, that might be reclaimed, such as caches
-  SUnreclaim: Part of Slab, that cannot be reclaimed on memory pressure
-  PageTables: amount of memory dedicated to the lowest level of page
+Slab
+              in-kernel data structures cache
+SReclaimable
+              Part of Slab, that might be reclaimed, such as caches
+SUnreclaim
+              Part of Slab, that cannot be reclaimed on memory pressure
+PageTables
+              amount of memory dedicated to the lowest level of page
               tables.
-NFS_Unstable: NFS pages sent to the server, but not yet committed to stable
+NFS_Unstable
+              NFS pages sent to the server, but not yet committed to stable
              storage
-      Bounce: Memory used for block device "bounce buffers"
-WritebackTmp: Memory used by FUSE for temporary writeback buffers
- CommitLimit: Based on the overcommit ratio ('vm.overcommit_ratio'),
+Bounce
+              Memory used for block device "bounce buffers"
+WritebackTmp
+              Memory used by FUSE for temporary writeback buffers
+CommitLimit
+              Based on the overcommit ratio ('vm.overcommit_ratio'),
               this is the total amount of  memory currently available to
               be allocated on the system. This limit is only adhered to
               if strict overcommit accounting is enabled (mode 2 in
               'vm.overcommit_memory').
-              The CommitLimit is calculated with the following formula:
-              CommitLimit = ([total RAM pages] - [total huge TLB pages]) *
-                             overcommit_ratio / 100 + [total swap pages]
+
+              The CommitLimit is calculated with the following formula::
+
+                CommitLimit = ([total RAM pages] - [total huge TLB pages]) *
+                               overcommit_ratio / 100 + [total swap pages]
+
               For example, on a system with 1G of physical RAM and 7G
               of swap with a `vm.overcommit_ratio` of 30 it would
               yield a CommitLimit of 7.3G.
+
               For more details, see the memory overcommit documentation
               in vm/overcommit-accounting.
-Committed_AS: The amount of memory presently allocated on the system.
+Committed_AS
+              The amount of memory presently allocated on the system.
               The committed memory is a sum of all of the memory which
               has been allocated by processes, even if it has not been
               "used" by them as of yet. A process which malloc()'s 1G
@@ -1005,21 +1080,25 @@ Committed_AS: The amount of memory presently allocated on the system.
               This is useful if one needs to guarantee that processes will
               not fail due to lack of memory once that memory has been
               successfully allocated.
-VmallocTotal: total size of vmalloc memory area
- VmallocUsed: amount of vmalloc area which is used
-VmallocChunk: largest contiguous block of vmalloc area which is free
-      Percpu: Memory allocated to the percpu allocator used to back percpu
+VmallocTotal
+              total size of vmalloc memory area
+VmallocUsed
+              amount of vmalloc area which is used
+VmallocChunk
+              largest contiguous block of vmalloc area which is free
+Percpu
+              Memory allocated to the percpu allocator used to back percpu
               allocations. This stat excludes the cost of metadata.
 
-..............................................................................
-
-vmallocinfo:
+vmallocinfo
+~~~~~~~~~~~
 
 Provides information about vmalloced/vmaped areas. One line per area,
 containing the virtual address range of the area, size in bytes,
 caller information of the creator, and optional information depending
 on the kind of area :
 
+ ==========  ===================================================
  pages=nr    number of pages
  phys=addr   if a physical address was specified
  ioremap     I/O mapping (ioremap() and friends)
@@ -1029,49 +1108,54 @@ on the kind of area :
  vpages      buffer for pages pointers was vmalloced (huge area)
  N<node>=nr  (Only on NUMA kernels)
              Number of pages allocated on memory node <node>
-
-> cat /proc/vmallocinfo
-0xffffc20000000000-0xffffc20000201000 2101248 alloc_large_system_hash+0x204 ...
-  /0x2c0 pages=512 vmalloc N0=128 N1=128 N2=128 N3=128
-0xffffc20000201000-0xffffc20000302000 1052672 alloc_large_system_hash+0x204 ...
-  /0x2c0 pages=256 vmalloc N0=64 N1=64 N2=64 N3=64
-0xffffc20000302000-0xffffc20000304000    8192 acpi_tb_verify_table+0x21/0x4f...
-  phys=7fee8000 ioremap
-0xffffc20000304000-0xffffc20000307000   12288 acpi_tb_verify_table+0x21/0x4f...
-  phys=7fee7000 ioremap
-0xffffc2000031d000-0xffffc2000031f000    8192 init_vdso_vars+0x112/0x210
-0xffffc2000031f000-0xffffc2000032b000   49152 cramfs_uncompress_init+0x2e ...
-  /0x80 pages=11 vmalloc N0=3 N1=3 N2=2 N3=3
-0xffffc2000033a000-0xffffc2000033d000   12288 sys_swapon+0x640/0xac0      ...
-  pages=2 vmalloc N1=2
-0xffffc20000347000-0xffffc2000034c000   20480 xt_alloc_table_info+0xfe ...
-  /0x130 [x_tables] pages=4 vmalloc N0=4
-0xffffffffa0000000-0xffffffffa000f000   61440 sys_init_module+0xc27/0x1d00 ...
-   pages=14 vmalloc N2=14
-0xffffffffa000f000-0xffffffffa0014000   20480 sys_init_module+0xc27/0x1d00 ...
-   pages=4 vmalloc N1=4
-0xffffffffa0014000-0xffffffffa0017000   12288 sys_init_module+0xc27/0x1d00 ...
-   pages=2 vmalloc N1=2
-0xffffffffa0017000-0xffffffffa0022000   45056 sys_init_module+0xc27/0x1d00 ...
-   pages=10 vmalloc N0=10
-
-..............................................................................
-
-softirqs:
+ ==========  ===================================================
+
+::
+
+    > cat /proc/vmallocinfo
+    0xffffc20000000000-0xffffc20000201000 2101248 alloc_large_system_hash+0x204 ...
+    /0x2c0 pages=512 vmalloc N0=128 N1=128 N2=128 N3=128
+    0xffffc20000201000-0xffffc20000302000 1052672 alloc_large_system_hash+0x204 ...
+    /0x2c0 pages=256 vmalloc N0=64 N1=64 N2=64 N3=64
+    0xffffc20000302000-0xffffc20000304000    8192 acpi_tb_verify_table+0x21/0x4f...
+    phys=7fee8000 ioremap
+    0xffffc20000304000-0xffffc20000307000   12288 acpi_tb_verify_table+0x21/0x4f...
+    phys=7fee7000 ioremap
+    0xffffc2000031d000-0xffffc2000031f000    8192 init_vdso_vars+0x112/0x210
+    0xffffc2000031f000-0xffffc2000032b000   49152 cramfs_uncompress_init+0x2e ...
+    /0x80 pages=11 vmalloc N0=3 N1=3 N2=2 N3=3
+    0xffffc2000033a000-0xffffc2000033d000   12288 sys_swapon+0x640/0xac0      ...
+    pages=2 vmalloc N1=2
+    0xffffc20000347000-0xffffc2000034c000   20480 xt_alloc_table_info+0xfe ...
+    /0x130 [x_tables] pages=4 vmalloc N0=4
+    0xffffffffa0000000-0xffffffffa000f000   61440 sys_init_module+0xc27/0x1d00 ...
+    pages=14 vmalloc N2=14
+    0xffffffffa000f000-0xffffffffa0014000   20480 sys_init_module+0xc27/0x1d00 ...
+    pages=4 vmalloc N1=4
+    0xffffffffa0014000-0xffffffffa0017000   12288 sys_init_module+0xc27/0x1d00 ...
+    pages=2 vmalloc N1=2
+    0xffffffffa0017000-0xffffffffa0022000   45056 sys_init_module+0xc27/0x1d00 ...
+    pages=10 vmalloc N0=10
+
+
+softirqs
+~~~~~~~~
 
 Provides counts of softirq handlers serviced since boot time, for each cpu.
 
-> cat /proc/softirqs
-                CPU0       CPU1       CPU2       CPU3
-      HI:          0          0          0          0
-   TIMER:      27166      27120      27097      27034
-  NET_TX:          0          0          0         17
-  NET_RX:         42          0          0         39
-   BLOCK:          0          0        107       1121
- TASKLET:          0          0          0        290
-   SCHED:      27035      26983      26971      26746
- HRTIMER:          0          0          0          0
-     RCU:       1678       1769       2178       2250
+::
+
+    > cat /proc/softirqs
+                   CPU0       CPU1       CPU2       CPU3
+       HI:          0          0          0          0
+    TIMER:      27166      27120      27097      27034
+    NET_TX:          0          0          0         17
+    NET_RX:         42          0          0         39
+    BLOCK:          0          0        107       1121
+    TASKLET:          0          0          0        290
+    SCHED:      27035      26983      26971      26746
+    HRTIMER:          0          0          0          0
+       RCU:       1678       1769       2178       2250
 
 
 1.3 IDE devices in /proc/ide
@@ -1083,7 +1167,7 @@ file drivers  and a link for each IDE device, pointing to the device directory
 in the controller specific subtree.
 
 The file  drivers  contains general information about the drivers used for the
-IDE devices:
+IDE devices::
 
   > cat /proc/ide/drivers
   ide-cdrom version 4.53
@@ -1094,57 +1178,61 @@ subdirectories. These  are  named  ide0,  ide1  and  so  on.  Each  of  these
 directories contains the files shown in table 1-6.
 
 
-Table 1-6: IDE controller info in  /proc/ide/ide?
-..............................................................................
- File    Content                                 
- channel IDE channel (0 or 1)                    
- config  Configuration (only for PCI/IDE bridge) 
- mate    Mate name                               
- model   Type/Chipset of IDE controller          
-..............................................................................
+.. table:: Table 1-6: IDE controller info in  /proc/ide/ide?
+
+ ======= =======================================
+ File    Content
+ ======= =======================================
+ channel IDE channel (0 or 1)
+ config  Configuration (only for PCI/IDE bridge)
+ mate    Mate name
+ model   Type/Chipset of IDE controller
+ ======= =======================================
 
 Each device  connected  to  a  controller  has  a separate subdirectory in the
 controllers directory.  The  files  listed in table 1-7 are contained in these
 directories.
 
 
-Table 1-7: IDE device information
-..............................................................................
- File             Content                                    
- cache            The cache                                  
- capacity         Capacity of the medium (in 512Byte blocks) 
- driver           driver and version                         
- geometry         physical and logical geometry              
- identify         device identify block                      
- media            media type                                 
- model            device identifier                          
- settings         device setup                               
- smart_thresholds IDE disk management thresholds             
- smart_values     IDE disk management values                 
-..............................................................................
-
-The most  interesting  file is settings. This file contains a nice overview of
-the drive parameters:
-
-  # cat /proc/ide/ide0/hda/settings 
-  name                    value           min             max             mode 
-  ----                    -----           ---             ---             ---- 
-  bios_cyl                526             0               65535           rw 
-  bios_head               255             0               255             rw 
-  bios_sect               63              0               63              rw 
-  breada_readahead        4               0               127             rw 
-  bswap                   0               0               1               r 
-  file_readahead          72              0               2097151         rw 
-  io_32bit                0               0               3               rw 
-  keepsettings            0               0               1               rw 
-  max_kb_per_request      122             1               127             rw 
-  multcount               0               0               8               rw 
-  nice1                   1               0               1               rw 
-  nowerr                  0               0               1               rw 
-  pio_mode                write-only      0               255             w 
-  slow                    0               0               1               rw 
-  unmaskirq               0               0               1               rw 
-  using_dma               0               0               1               rw 
+.. table:: Table 1-7: IDE device information
+
+ ================ ==========================================
+ File             Content
+ ================ ==========================================
+ cache            The cache
+ capacity         Capacity of the medium (in 512Byte blocks)
+ driver           driver and version
+ geometry         physical and logical geometry
+ identify         device identify block
+ media            media type
+ model            device identifier
+ settings         device setup
+ smart_thresholds IDE disk management thresholds
+ smart_values     IDE disk management values
+ ================ ==========================================
+
+The most  interesting  file is ``settings``. This file contains a nice
+overview of the drive parameters::
+
+  # cat /proc/ide/ide0/hda/settings
+  name                    value           min             max             mode
+  ----                    -----           ---             ---             ----
+  bios_cyl                526             0               65535           rw
+  bios_head               255             0               255             rw
+  bios_sect               63              0               63              rw
+  breada_readahead        4               0               127             rw
+  bswap                   0               0               1               r
+  file_readahead          72              0               2097151         rw
+  io_32bit                0               0               3               rw
+  keepsettings            0               0               1               rw
+  max_kb_per_request      122             1               127             rw
+  multcount               0               0               8               rw
+  nice1                   1               0               1               rw
+  nowerr                  0               0               1               rw
+  pio_mode                write-only      0               255             w
+  slow                    0               0               1               rw
+  unmaskirq               0               0               1               rw
+  using_dma               0               0               1               rw
 
 
 1.4 Networking info in /proc/net
@@ -1155,67 +1243,70 @@ additional values  you  get  for  IP  version 6 if you configure the kernel to
 support this. Table 1-9 lists the files and their meaning.
 
 
-Table 1-8: IPv6 info in /proc/net
-..............................................................................
- File       Content                                               
- udp6       UDP sockets (IPv6)                                    
- tcp6       TCP sockets (IPv6)                                    
- raw6       Raw device statistics (IPv6)                          
- igmp6      IP multicast addresses, which this host joined (IPv6) 
- if_inet6   List of IPv6 interface addresses                      
- ipv6_route Kernel routing table for IPv6                         
- rt6_stats  Global IPv6 routing tables statistics                 
- sockstat6  Socket statistics (IPv6)                              
- snmp6      Snmp data (IPv6)                                      
-..............................................................................
-
-
-Table 1-9: Network info in /proc/net
-..............................................................................
- File          Content                                                         
- arp           Kernel  ARP table                                               
- dev           network devices with statistics                                 
+.. table:: Table 1-8: IPv6 info in /proc/net
+
+ ========== =====================================================
+ File       Content
+ ========== =====================================================
+ udp6       UDP sockets (IPv6)
+ tcp6       TCP sockets (IPv6)
+ raw6       Raw device statistics (IPv6)
+ igmp6      IP multicast addresses, which this host joined (IPv6)
+ if_inet6   List of IPv6 interface addresses
+ ipv6_route Kernel routing table for IPv6
+ rt6_stats  Global IPv6 routing tables statistics
+ sockstat6  Socket statistics (IPv6)
+ snmp6      Snmp data (IPv6)
+ ========== =====================================================
+
+.. table:: Table 1-9: Network info in /proc/net
+
+ ============= ================================================================
+ File          Content
+ ============= ================================================================
+ arp           Kernel  ARP table
+ dev           network devices with statistics
  dev_mcast     the Layer2 multicast groups a device is listening too
                (interface index, label, number of references, number of bound
-               addresses). 
- dev_stat      network device status                                           
- ip_fwchains   Firewall chain linkage                                          
- ip_fwnames    Firewall chain names                                            
- ip_masq       Directory containing the masquerading tables                    
- ip_masquerade Major masquerading table                                        
- netstat       Network statistics                                              
- raw           raw device statistics                                           
- route         Kernel routing table                                            
- rpc           Directory containing rpc info                                   
- rt_cache      Routing cache                                                   
- snmp          SNMP data                                                       
- sockstat      Socket statistics                                               
- tcp           TCP  sockets                                                    
- udp           UDP sockets                                                     
- unix          UNIX domain sockets                                             
- wireless      Wireless interface data (Wavelan etc)                           
- igmp          IP multicast addresses, which this host joined                  
- psched        Global packet scheduler parameters.                             
- netlink       List of PF_NETLINK sockets                                      
- ip_mr_vifs    List of multicast virtual interfaces                            
- ip_mr_cache   List of multicast routing cache                                 
-..............................................................................
+               addresses).
+ dev_stat      network device status
+ ip_fwchains   Firewall chain linkage
+ ip_fwnames    Firewall chain names
+ ip_masq       Directory containing the masquerading tables
+ ip_masquerade Major masquerading table
+ netstat       Network statistics
+ raw           raw device statistics
+ route         Kernel routing table
+ rpc           Directory containing rpc info
+ rt_cache      Routing cache
+ snmp          SNMP data
+ sockstat      Socket statistics
+ tcp           TCP  sockets
+ udp           UDP sockets
+ unix          UNIX domain sockets
+ wireless      Wireless interface data (Wavelan etc)
+ igmp          IP multicast addresses, which this host joined
+ psched        Global packet scheduler parameters.
+ netlink       List of PF_NETLINK sockets
+ ip_mr_vifs    List of multicast virtual interfaces
+ ip_mr_cache   List of multicast routing cache
+ ============= ================================================================
 
 You can  use  this  information  to see which network devices are available in
-your system and how much traffic was routed over those devices:
-
-  > cat /proc/net/dev 
-  Inter-|Receive                                                   |[... 
-   face |bytes    packets errs drop fifo frame compressed multicast|[... 
-      lo:  908188   5596     0    0    0     0          0         0 [...         
-    ppp0:15475140  20721   410    0    0   410          0         0 [...  
-    eth0:  614530   7085     0    0    0     0          0         1 [... 
-   
-  ...] Transmit 
-  ...] bytes    packets errs drop fifo colls carrier compressed 
-  ...]  908188     5596    0    0    0     0       0          0 
-  ...] 1375103    17405    0    0    0     0       0          0 
-  ...] 1703981     5535    0    0    0     3       0          0 
+your system and how much traffic was routed over those devices::
+
+  > cat /proc/net/dev
+  Inter-|Receive                                                   |[...
+   face |bytes    packets errs drop fifo frame compressed multicast|[...
+      lo:  908188   5596     0    0    0     0          0         0 [...
+    ppp0:15475140  20721   410    0    0   410          0         0 [...
+    eth0:  614530   7085     0    0    0     0          0         1 [...
+
+  ...] Transmit
+  ...] bytes    packets errs drop fifo colls carrier compressed
+  ...]  908188     5596    0    0    0     0       0          0
+  ...] 1375103    17405    0    0    0     0       0          0
+  ...] 1703981     5535    0    0    0     3       0          0
 
 In addition, each Channel Bond interface has its own directory.  For
 example, the bond0 device will have a directory called /proc/net/bond0/.
@@ -1228,62 +1319,62 @@ many times the slaves link has failed.
 
 If you  have  a  SCSI  host adapter in your system, you'll find a subdirectory
 named after  the driver for this adapter in /proc/scsi. You'll also see a list
-of all recognized SCSI devices in /proc/scsi:
+of all recognized SCSI devices in /proc/scsi::
 
-  >cat /proc/scsi/scsi 
-  Attached devices: 
-  Host: scsi0 Channel: 00 Id: 00 Lun: 00 
-    Vendor: IBM      Model: DGHS09U          Rev: 03E0 
-    Type:   Direct-Access                    ANSI SCSI revision: 03 
-  Host: scsi0 Channel: 00 Id: 06 Lun: 00 
-    Vendor: PIONEER  Model: CD-ROM DR-U06S   Rev: 1.04 
-    Type:   CD-ROM                           ANSI SCSI revision: 02 
+  >cat /proc/scsi/scsi
+  Attached devices:
+  Host: scsi0 Channel: 00 Id: 00 Lun: 00
+    Vendor: IBM      Model: DGHS09U          Rev: 03E0
+    Type:   Direct-Access                    ANSI SCSI revision: 03
+  Host: scsi0 Channel: 00 Id: 06 Lun: 00
+    Vendor: PIONEER  Model: CD-ROM DR-U06S   Rev: 1.04
+    Type:   CD-ROM                           ANSI SCSI revision: 02
 
 
 The directory  named  after  the driver has one file for each adapter found in
 the system.  These  files  contain information about the controller, including
 the used  IRQ  and  the  IO  address range. The amount of information shown is
 dependent on  the adapter you use. The example shows the output for an Adaptec
-AHA-2940 SCSI adapter:
-
-  > cat /proc/scsi/aic7xxx/0 
-   
-  Adaptec AIC7xxx driver version: 5.1.19/3.2.4 
-  Compile Options: 
-    TCQ Enabled By Default : Disabled 
-    AIC7XXX_PROC_STATS     : Disabled 
-    AIC7XXX_RESET_DELAY    : 5 
-  Adapter Configuration: 
-             SCSI Adapter: Adaptec AHA-294X Ultra SCSI host adapter 
-                             Ultra Wide Controller 
-      PCI MMAPed I/O Base: 0xeb001000 
-   Adapter SEEPROM Config: SEEPROM found and used. 
-        Adaptec SCSI BIOS: Enabled 
-                      IRQ: 10 
-                     SCBs: Active 0, Max Active 2, 
-                           Allocated 15, HW 16, Page 255 
-               Interrupts: 160328 
-        BIOS Control Word: 0x18b6 
-     Adapter Control Word: 0x005b 
-     Extended Translation: Enabled 
-  Disconnect Enable Flags: 0xffff 
-       Ultra Enable Flags: 0x0001 
-   Tag Queue Enable Flags: 0x0000 
-  Ordered Queue Tag Flags: 0x0000 
-  Default Tag Queue Depth: 8 
-      Tagged Queue By Device array for aic7xxx host instance 0: 
-        {255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255} 
-      Actual queue depth per device for aic7xxx host instance 0: 
-        {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1} 
-  Statistics: 
-  (scsi0:0:0:0) 
-    Device using Wide/Sync transfers at 40.0 MByte/sec, offset 8 
-    Transinfo settings: current(12/8/1/0), goal(12/8/1/0), user(12/15/1/0) 
-    Total transfers 160151 (74577 reads and 85574 writes) 
-  (scsi0:0:6:0) 
-    Device using Narrow/Sync transfers at 5.0 MByte/sec, offset 15 
-    Transinfo settings: current(50/15/0/0), goal(50/15/0/0), user(50/15/0/0) 
-    Total transfers 0 (0 reads and 0 writes) 
+AHA-2940 SCSI adapter::
+
+  > cat /proc/scsi/aic7xxx/0
+
+  Adaptec AIC7xxx driver version: 5.1.19/3.2.4
+  Compile Options:
+    TCQ Enabled By Default : Disabled
+    AIC7XXX_PROC_STATS     : Disabled
+    AIC7XXX_RESET_DELAY    : 5
+  Adapter Configuration:
+             SCSI Adapter: Adaptec AHA-294X Ultra SCSI host adapter
+                             Ultra Wide Controller
+      PCI MMAPed I/O Base: 0xeb001000
+   Adapter SEEPROM Config: SEEPROM found and used.
+        Adaptec SCSI BIOS: Enabled
+                      IRQ: 10
+                     SCBs: Active 0, Max Active 2,
+                           Allocated 15, HW 16, Page 255
+               Interrupts: 160328
+        BIOS Control Word: 0x18b6
+     Adapter Control Word: 0x005b
+     Extended Translation: Enabled
+  Disconnect Enable Flags: 0xffff
+       Ultra Enable Flags: 0x0001
+   Tag Queue Enable Flags: 0x0000
+  Ordered Queue Tag Flags: 0x0000
+  Default Tag Queue Depth: 8
+      Tagged Queue By Device array for aic7xxx host instance 0:
+        {255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255}
+      Actual queue depth per device for aic7xxx host instance 0:
+        {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}
+  Statistics:
+  (scsi0:0:0:0)
+    Device using Wide/Sync transfers at 40.0 MByte/sec, offset 8
+    Transinfo settings: current(12/8/1/0), goal(12/8/1/0), user(12/15/1/0)
+    Total transfers 160151 (74577 reads and 85574 writes)
+  (scsi0:0:6:0)
+    Device using Narrow/Sync transfers at 5.0 MByte/sec, offset 15
+    Transinfo settings: current(50/15/0/0), goal(50/15/0/0), user(50/15/0/0)
+    Total transfers 0 (0 reads and 0 writes)
 
 
 1.6 Parallel port info in /proc/parport
@@ -1296,18 +1387,20 @@ number (0,1,2,...).
 These directories contain the four files shown in Table 1-10.
 
 
-Table 1-10: Files in /proc/parport
-..............................................................................
- File      Content                                                             
- autoprobe Any IEEE-1284 device ID information that has been acquired.         
+.. table:: Table 1-10: Files in /proc/parport
+
+ ========= ====================================================================
+ File      Content
+ ========= ====================================================================
+ autoprobe Any IEEE-1284 device ID information that has been acquired.
  devices   list of the device drivers using that port. A + will appear by the
            name of the device currently using the port (it might not appear
-           against any). 
- hardware  Parallel port's base address, IRQ line and DMA channel.             
+           against any).
+ hardware  Parallel port's base address, IRQ line and DMA channel.
  irq       IRQ that parport is using for that port. This is in a separate
            file to allow you to alter it by writing a new value in (IRQ
-           number or none). 
-..............................................................................
+           number or none).
+ ========= ====================================================================
 
 1.7 TTY info in /proc/tty
 -------------------------
@@ -1317,29 +1410,31 @@ directory /proc/tty.You'll  find  entries  for drivers and line disciplines in
 this directory, as shown in Table 1-11.
 
 
-Table 1-11: Files in /proc/tty
-..............................................................................
- File          Content                                        
- drivers       list of drivers and their usage                
- ldiscs        registered line disciplines                    
- driver/serial usage statistic and status of single tty lines 
-..............................................................................
+.. table:: Table 1-11: Files in /proc/tty
+
+ ============= ==============================================
+ File          Content
+ ============= ==============================================
+ drivers       list of drivers and their usage
+ ldiscs        registered line disciplines
+ driver/serial usage statistic and status of single tty lines
+ ============= ==============================================
 
 To see  which  tty's  are  currently in use, you can simply look into the file
-/proc/tty/drivers:
-
-  > cat /proc/tty/drivers 
-  pty_slave            /dev/pts      136   0-255 pty:slave 
-  pty_master           /dev/ptm      128   0-255 pty:master 
-  pty_slave            /dev/ttyp       3   0-255 pty:slave 
-  pty_master           /dev/pty        2   0-255 pty:master 
-  serial               /dev/cua        5   64-67 serial:callout 
-  serial               /dev/ttyS       4   64-67 serial 
-  /dev/tty0            /dev/tty0       4       0 system:vtmaster 
-  /dev/ptmx            /dev/ptmx       5       2 system 
-  /dev/console         /dev/console    5       1 system:console 
-  /dev/tty             /dev/tty        5       0 system:/dev/tty 
-  unknown              /dev/tty        4    1-63 console 
+/proc/tty/drivers::
+
+  > cat /proc/tty/drivers
+  pty_slave            /dev/pts      136   0-255 pty:slave
+  pty_master           /dev/ptm      128   0-255 pty:master
+  pty_slave            /dev/ttyp       3   0-255 pty:slave
+  pty_master           /dev/pty        2   0-255 pty:master
+  serial               /dev/cua        5   64-67 serial:callout
+  serial               /dev/ttyS       4   64-67 serial
+  /dev/tty0            /dev/tty0       4       0 system:vtmaster
+  /dev/ptmx            /dev/ptmx       5       2 system
+  /dev/console         /dev/console    5       1 system:console
+  /dev/tty             /dev/tty        5       0 system:/dev/tty
+  unknown              /dev/tty        4    1-63 console
 
 
 1.8 Miscellaneous kernel statistics in /proc/stat
@@ -1347,7 +1442,7 @@ To see  which  tty's  are  currently in use, you can simply look into the file
 
 Various pieces   of  information about  kernel activity  are  available in the
 /proc/stat file.  All  of  the numbers reported  in  this file are  aggregates
-since the system first booted.  For a quick look, simply cat the file:
+since the system first booted.  For a quick look, simply cat the file::
 
   > cat /proc/stat
   cpu  2255 34 2290 22625563 6290 127 456 0 0 0
@@ -1372,6 +1467,7 @@ second).  The meanings of the columns are as follows, from left to right:
 - idle: twiddling thumbs
 - iowait: In a word, iowait stands for waiting for I/O to complete. But there
   are several problems:
+
   1. Cpu will not wait for I/O to complete, iowait is the time that a task is
      waiting for I/O to complete. When cpu goes into idle state for
      outstanding task io, another task will be scheduled on this CPU.
@@ -1379,6 +1475,7 @@ second).  The meanings of the columns are as follows, from left to right:
      on any CPU, so the iowait of each CPU is difficult to calculate.
   3. The value of iowait field in /proc/stat will decrease in certain
      conditions.
+
   So, the iowait is not reliable by reading from /proc/stat.
 - irq: servicing interrupts
 - softirq: servicing softirqs
@@ -1422,18 +1519,19 @@ Information about mounted ext4 file systems can be found in
 /proc/fs/ext4/dm-0).   The files in each per-device directory are shown
 in Table 1-12, below.
 
-Table 1-12: Files in /proc/fs/ext4/<devname>
-..............................................................................
- File            Content                                        
+.. table:: Table 1-12: Files in /proc/fs/ext4/<devname>
+
+ ==============  ==========================================================
+ File            Content
  mb_groups       details of multiblock allocator buddy cache of free blocks
-..............................................................................
+ ==============  ==========================================================
 
 2.0 /proc/consoles
 ------------------
 Shows registered system console lines.
 
 To see which character device lines are currently used for the system console
-/dev/console, you may simply look into the file /proc/consoles:
+/dev/console, you may simply look into the file /proc/consoles::
 
   > cat /proc/consoles
   tty0                 -WU (ECp)       4:7
@@ -1441,41 +1539,45 @@ To see which character device lines are currently used for the system console
 
 The columns are:
 
-  device               name of the device
-  operations           R = can do read operations
-                       W = can do write operations
-                       U = can do unblank
-  flags                E = it is enabled
-                       C = it is preferred console
-                       B = it is primary boot console
-                       p = it is used for printk buffer
-                       b = it is not a TTY but a Braille device
-                       a = it is safe to use when cpu is offline
-  major:minor          major and minor number of the device separated by a colon
++--------------------+-------------------------------------------------------+
+| device             | name of the device                                    |
++====================+=======================================================+
+| operations         | * R = can do read operations                          |
+|                    | * W = can do write operations                         |
+|                    | * U = can do unblank                                  |
++--------------------+-------------------------------------------------------+
+| flags              | * E = it is enabled                                   |
+|                    | * C = it is preferred console                         |
+|                    | * B = it is primary boot console                      |
+|                    | * p = it is used for printk buffer                    |
+|                    | * b = it is not a TTY but a Braille device            |
+|                    | * a = it is safe to use when cpu is offline           |
++--------------------+-------------------------------------------------------+
+| major:minor        | major and minor number of the device separated by a   |
+|                    | colon                                                 |
++--------------------+-------------------------------------------------------+
 
-------------------------------------------------------------------------------
 Summary
-------------------------------------------------------------------------------
+-------
+
 The /proc file system serves information about the running system. It not only
 allows access to process data but also allows you to request the kernel status
 by reading files in the hierarchy.
 
 The directory  structure  of /proc reflects the types of information and makes
 it easy, if not obvious, where to look for specific data.
-------------------------------------------------------------------------------
 
-------------------------------------------------------------------------------
-CHAPTER 2: MODIFYING SYSTEM PARAMETERS
-------------------------------------------------------------------------------
+Chapter 2: Modifying System Parameters
+======================================
 
-------------------------------------------------------------------------------
 In This Chapter
-------------------------------------------------------------------------------
+---------------
+
 * Modifying kernel parameters by writing into files found in /proc/sys
 * Exploring the files which modify certain parameters
 * Review of the /proc/sys file tree
-------------------------------------------------------------------------------
 
+------------------------------------------------------------------------------
 
 A very  interesting part of /proc is the directory /proc/sys. This is not only
 a source  of  information,  it also allows you to change parameters within the
@@ -1503,19 +1605,18 @@ kernels, and became part of it in version 2.2.1 of the Linux kernel.
 Please see: Documentation/admin-guide/sysctl/ directory for descriptions of these
 entries.
 
-------------------------------------------------------------------------------
 Summary
-------------------------------------------------------------------------------
+-------
+
 Certain aspects  of  kernel  behavior  can be modified at runtime, without the
 need to  recompile  the kernel, or even to reboot the system. The files in the
 /proc/sys tree  can  not only be read, but also modified. You can use the echo
 command to write value into these files, thereby changing the default settings
 of the kernel.
-------------------------------------------------------------------------------
 
-------------------------------------------------------------------------------
-CHAPTER 3: PER-PROCESS PARAMETERS
-------------------------------------------------------------------------------
+
+Chapter 3: Per-process Parameters
+=================================
 
 3.1 /proc/<pid>/oom_adj & /proc/<pid>/oom_score_adj- Adjust the oom-killer score
 --------------------------------------------------------------------------------
@@ -1588,26 +1689,28 @@ process should be killed in an out-of-memory situation.
 This file contains IO statistics for each running process
 
 Example
--------
+~~~~~~~
+
+::
 
-test:/tmp # dd if=/dev/zero of=/tmp/test.dat &
-[1] 3828
+    test:/tmp # dd if=/dev/zero of=/tmp/test.dat &
+    [1] 3828
 
-test:/tmp # cat /proc/3828/io
-rchar: 323934931
-wchar: 323929600
-syscr: 632687
-syscw: 632675
-read_bytes: 0
-write_bytes: 323932160
-cancelled_write_bytes: 0
+    test:/tmp # cat /proc/3828/io
+    rchar: 323934931
+    wchar: 323929600
+    syscr: 632687
+    syscw: 632675
+    read_bytes: 0
+    write_bytes: 323932160
+    cancelled_write_bytes: 0
 
 
 Description
------------
+~~~~~~~~~~~
 
 rchar
------
+^^^^^
 
 I/O counter: chars read
 The number of bytes which this task has caused to be read from storage. This
@@ -1618,7 +1721,7 @@ pagecache)
 
 
 wchar
------
+^^^^^
 
 I/O counter: chars written
 The number of bytes which this task has caused, or shall cause to be written
@@ -1626,7 +1729,7 @@ to disk. Similar caveats apply here as with rchar.
 
 
 syscr
------
+^^^^^
 
 I/O counter: read syscalls
 Attempt to count the number of read I/O operations, i.e. syscalls like read()
@@ -1634,7 +1737,7 @@ and pread().
 
 
 syscw
------
+^^^^^
 
 I/O counter: write syscalls
 Attempt to count the number of write I/O operations, i.e. syscalls like
@@ -1642,7 +1745,7 @@ write() and pwrite().
 
 
 read_bytes
-----------
+^^^^^^^^^^
 
 I/O counter: bytes read
 Attempt to count the number of bytes which this process really did cause to
@@ -1652,7 +1755,7 @@ CIFS at a later time>
 
 
 write_bytes
------------
+^^^^^^^^^^^
 
 I/O counter: bytes written
 Attempt to count the number of bytes which this process caused to be sent to
@@ -1660,7 +1763,7 @@ the storage layer. This is done at page-dirtying time.
 
 
 cancelled_write_bytes
----------------------
+^^^^^^^^^^^^^^^^^^^^^
 
 The big inaccuracy here is truncate. If a process writes 1MB to a file and
 then deletes the file, it will in fact perform no writeout. But it will have
@@ -1673,12 +1776,11 @@ from the truncating task's write_bytes, but there is information loss in doing
 that.
 
 
-Note
-----
+.. Note::
 
-At its current implementation state, this is a bit racy on 32-bit machines: if
-process A reads process B's /proc/pid/io while process B is updating one of
-those 64-bit counters, process A could see an intermediate result.
+   At its current implementation state, this is a bit racy on 32-bit machines:
+   if process A reads process B's /proc/pid/io while process B is updating one
+   of those 64-bit counters, process A could see an intermediate result.
 
 
 More information about this can be found within the taskstats documentation in
@@ -1698,12 +1800,13 @@ of memory types. If a bit of the bitmask is set, memory segments of the
 corresponding memory type are dumped, otherwise they are not dumped.
 
 The following 9 memory types are supported:
+
   - (bit 0) anonymous private memory
   - (bit 1) anonymous shared memory
   - (bit 2) file-backed private memory
   - (bit 3) file-backed shared memory
   - (bit 4) ELF header pages in file-backed private memory areas (it is
-            effective only if the bit 2 is cleared)
+    effective only if the bit 2 is cleared)
   - (bit 5) hugetlb private memory
   - (bit 6) hugetlb shared memory
   - (bit 7) DAX private memory
@@ -1719,13 +1822,13 @@ The default value of coredump_filter is 0x33; this means all anonymous memory
 segments, ELF header pages and hugetlb private memory are dumped.
 
 If you don't want to dump all shared memory segments attached to pid 1234,
-write 0x31 to the process's proc file.
+write 0x31 to the process's proc file::
 
   $ echo 0x31 > /proc/1234/coredump_filter
 
 When a new process is created, the process inherits the bitmask status from its
 parent. It is useful to set up coredump_filter before the program runs.
-For example:
+For example::
 
   $ echo 0x7 > /proc/self/coredump_filter
   $ ./some_program
@@ -1733,35 +1836,37 @@ For example:
 3.5    /proc/<pid>/mountinfo - Information about mounts
 --------------------------------------------------------
 
-This file contains lines of the form:
+This file contains lines of the form::
 
-36 35 98:0 /mnt1 /mnt2 rw,noatime master:1 - ext3 /dev/root rw,errors=continue
-(1)(2)(3)   (4)   (5)      (6)      (7)   (8) (9)   (10)         (11)
+    36 35 98:0 /mnt1 /mnt2 rw,noatime master:1 - ext3 /dev/root rw,errors=continue
+    (1)(2)(3)   (4)   (5)      (6)      (7)   (8) (9)   (10)         (11)
 
-(1) mount ID:  unique identifier of the mount (may be reused after umount)
-(2) parent ID:  ID of parent (or of self for the top of the mount tree)
-(3) major:minor:  value of st_dev for files on filesystem
-(4) root:  root of the mount within the filesystem
-(5) mount point:  mount point relative to the process's root
-(6) mount options:  per mount options
-(7) optional fields:  zero or more fields of the form "tag[:value]"
-(8) separator:  marks the end of the optional fields
-(9) filesystem type:  name of filesystem of the form "type[.subtype]"
-(10) mount source:  filesystem specific information or "none"
-(11) super options:  per super block options
+    (1) mount ID:  unique identifier of the mount (may be reused after umount)
+    (2) parent ID:  ID of parent (or of self for the top of the mount tree)
+    (3) major:minor:  value of st_dev for files on filesystem
+    (4) root:  root of the mount within the filesystem
+    (5) mount point:  mount point relative to the process's root
+    (6) mount options:  per mount options
+    (7) optional fields:  zero or more fields of the form "tag[:value]"
+    (8) separator:  marks the end of the optional fields
+    (9) filesystem type:  name of filesystem of the form "type[.subtype]"
+    (10) mount source:  filesystem specific information or "none"
+    (11) super options:  per super block options
 
 Parsers should ignore all unrecognised optional fields.  Currently the
 possible optional fields are:
 
-shared:X  mount is shared in peer group X
-master:X  mount is slave to peer group X
-propagate_from:X  mount is slave and receives propagation from peer group X (*)
-unbindable  mount is unbindable
+================  ==============================================================
+shared:X          mount is shared in peer group X
+master:X          mount is slave to peer group X
+propagate_from:X  mount is slave and receives propagation from peer group X [#]_
+unbindable        mount is unbindable
+================  ==============================================================
 
-(*) X is the closest dominant peer group under the process's root.  If
-X is the immediate master of the mount, or if there's no dominant peer
-group under the same root, then only the "master:X" field is present
-and not the "propagate_from:X" field.
+.. [#] X is the closest dominant peer group under the process's root.  If
+       X is the immediate master of the mount, or if there's no dominant peer
+       group under the same root, then only the "master:X" field is present
+       and not the "propagate_from:X" field.
 
 For more information on mount propagation see:
 
@@ -1804,77 +1909,86 @@ created with [see open(2) for details] and 'mnt_id' represents mount ID of
 the file system containing the opened file [see 3.5 /proc/<pid>/mountinfo
 for details].
 
-A typical output is
+A typical output is::
 
        pos:    0
        flags:  0100002
        mnt_id: 19
 
-All locks associated with a file descriptor are shown in its fdinfo too.
+All locks associated with a file descriptor are shown in its fdinfo too::
 
-lock:       1: FLOCK  ADVISORY  WRITE 359 00:13:11691 0 EOF
+    lock:       1: FLOCK  ADVISORY  WRITE 359 00:13:11691 0 EOF
 
 The files such as eventfd, fsnotify, signalfd, epoll among the regular pos/flags
 pair provide additional information particular to the objects they represent.
 
-       Eventfd files
-       ~~~~~~~~~~~~~
+Eventfd files
+~~~~~~~~~~~~~
+
+::
+
        pos:    0
        flags:  04002
        mnt_id: 9
        eventfd-count:  5a
 
-       where 'eventfd-count' is hex value of a counter.
+where 'eventfd-count' is hex value of a counter.
+
+Signalfd files
+~~~~~~~~~~~~~~
+
+::
 
-       Signalfd files
-       ~~~~~~~~~~~~~~
        pos:    0
        flags:  04002
        mnt_id: 9
        sigmask:        0000000000000200
 
-       where 'sigmask' is hex value of the signal mask associated
-       with a file.
+where 'sigmask' is hex value of the signal mask associated
+with a file.
+
+Epoll files
+~~~~~~~~~~~
+
+::
 
-       Epoll files
-       ~~~~~~~~~~~
        pos:    0
        flags:  02
        mnt_id: 9
        tfd:        5 events:       1d data: ffffffffffffffff pos:0 ino:61af sdev:7
 
-       where 'tfd' is a target file descriptor number in decimal form,
-       'events' is events mask being watched and the 'data' is data
-       associated with a target [see epoll(7) for more details].
+where 'tfd' is a target file descriptor number in decimal form,
+'events' is events mask being watched and the 'data' is data
+associated with a target [see epoll(7) for more details].
 
-       The 'pos' is current offset of the target file in decimal form
-       [see lseek(2)], 'ino' and 'sdev' are inode and device numbers
-       where target file resides, all in hex format.
+The 'pos' is current offset of the target file in decimal form
+[see lseek(2)], 'ino' and 'sdev' are inode and device numbers
+where target file resides, all in hex format.
 
-       Fsnotify files
-       ~~~~~~~~~~~~~~
-       For inotify files the format is the following
+Fsnotify files
+~~~~~~~~~~~~~~
+For inotify files the format is the following::
 
        pos:    0
        flags:  02000000
        inotify wd:3 ino:9e7e sdev:800013 mask:800afce ignored_mask:0 fhandle-bytes:8 fhandle-type:1 f_handle:7e9e0000640d1b6d
 
-       where 'wd' is a watch descriptor in decimal form, ie a target file
-       descriptor number, 'ino' and 'sdev' are inode and device where the
-       target file resides and the 'mask' is the mask of events, all in hex
-       form [see inotify(7) for more details].
+where 'wd' is a watch descriptor in decimal form, ie a target file
+descriptor number, 'ino' and 'sdev' are inode and device where the
+target file resides and the 'mask' is the mask of events, all in hex
+form [see inotify(7) for more details].
 
-       If the kernel was built with exportfs support, the path to the target
-       file is encoded as a file handle.  The file handle is provided by three
-       fields 'fhandle-bytes', 'fhandle-type' and 'f_handle', all in hex
-       format.
+If the kernel was built with exportfs support, the path to the target
+file is encoded as a file handle.  The file handle is provided by three
+fields 'fhandle-bytes', 'fhandle-type' and 'f_handle', all in hex
+format.
 
-       If the kernel is built without exportfs support the file handle won't be
-       printed out.
+If the kernel is built without exportfs support the file handle won't be
+printed out.
 
-       If there is no inotify mark attached yet the 'inotify' line will be omitted.
+If there is no inotify mark attached yet the 'inotify' line will be omitted.
 
-       For fanotify files the format is
+For fanotify files the format is::
 
        pos:    0
        flags:  02
@@ -1883,20 +1997,22 @@ pair provide additional information particular to the objects they represent.
        fanotify mnt_id:12 mflags:40 mask:38 ignored_mask:40000003
        fanotify ino:4f969 sdev:800013 mflags:0 mask:3b ignored_mask:40000000 fhandle-bytes:8 fhandle-type:1 f_handle:69f90400c275b5b4
 
-       where fanotify 'flags' and 'event-flags' are values used in fanotify_init
-       call, 'mnt_id' is the mount point identifier, 'mflags' is the value of
-       flags associated with mark which are tracked separately from events
-       mask. 'ino', 'sdev' are target inode and device, 'mask' is the events
-       mask and 'ignored_mask' is the mask of events which are to be ignored.
-       All in hex format. Incorporation of 'mflags', 'mask' and 'ignored_mask'
-       does provide information about flags and mask used in fanotify_mark
-       call [see fsnotify manpage for details].
+where fanotify 'flags' and 'event-flags' are values used in fanotify_init
+call, 'mnt_id' is the mount point identifier, 'mflags' is the value of
+flags associated with mark which are tracked separately from events
+mask. 'ino', 'sdev' are target inode and device, 'mask' is the events
+mask and 'ignored_mask' is the mask of events which are to be ignored.
+All in hex format. Incorporation of 'mflags', 'mask' and 'ignored_mask'
+does provide information about flags and mask used in fanotify_mark
+call [see fsnotify manpage for details].
+
+While the first three lines are mandatory and always printed, the rest is
+optional and may be omitted if no marks created yet.
 
-       While the first three lines are mandatory and always printed, the rest is
-       optional and may be omitted if no marks created yet.
+Timerfd files
+~~~~~~~~~~~~~
 
-       Timerfd files
-       ~~~~~~~~~~~~~
+::
 
        pos:    0
        flags:  02
@@ -1907,18 +2023,18 @@ pair provide additional information particular to the objects they represent.
        it_value: (0, 49406829)
        it_interval: (1, 0)
 
-       where 'clockid' is the clock type and 'ticks' is the number of the timer expirations
-       that have occurred [see timerfd_create(2) for details]. 'settime flags' are
-       flags in octal form been used to setup the timer [see timerfd_settime(2) for
-       details]. 'it_value' is remaining time until the timer exiration.
-       'it_interval' is the interval for the timer. Note the timer might be set up
-       with TIMER_ABSTIME option which will be shown in 'settime flags', but 'it_value'
-       still exhibits timer's remaining time.
+where 'clockid' is the clock type and 'ticks' is the number of the timer expirations
+that have occurred [see timerfd_create(2) for details]. 'settime flags' are
+flags in octal form been used to setup the timer [see timerfd_settime(2) for
+details]. 'it_value' is remaining time until the timer exiration.
+'it_interval' is the interval for the timer. Note the timer might be set up
+with TIMER_ABSTIME option which will be shown in 'settime flags', but 'it_value'
+still exhibits timer's remaining time.
 
 3.9    /proc/<pid>/map_files - Information about memory mapped files
 ---------------------------------------------------------------------
 This directory contains symbolic links which represent memory mapped files
-the process is maintaining.  Example output:
+the process is maintaining.  Example output::
 
      | lr-------- 1 root root 64 Jan 27 11:24 333c600000-333c620000 -> /usr/lib64/ld-2.18.so
      | lr-------- 1 root root 64 Jan 27 11:24 333c81f000-333c820000 -> /usr/lib64/ld-2.18.so
@@ -1976,17 +2092,22 @@ When CONFIG_PROC_PID_ARCH_STATUS is enabled, this file displays the
 architecture specific status of the task.
 
 Example
--------
+~~~~~~~
+
+::
+
  $ cat /proc/6753/arch_status
  AVX512_elapsed_ms:      8
 
 Description
------------
+~~~~~~~~~~~
 
 x86 specific entries:
----------------------
- AVX512_elapsed_ms:
- ------------------
+~~~~~~~~~~~~~~~~~~~~~
+
+AVX512_elapsed_ms:
+^^^^^^^^^^^^^^^^^^
+
   If AVX512 is supported on the machine, this entry shows the milliseconds
   elapsed since the last time AVX512 usage was recorded. The recording
   happens on a best effort basis when a task is scheduled out. This means
@@ -2010,17 +2131,18 @@ x86 specific entries:
   the task is unlikely an AVX512 user, but depends on the workload and the
   scheduling scenario, it also could be a false negative mentioned above.
 
-------------------------------------------------------------------------------
 Configuring procfs
-------------------------------------------------------------------------------
+------------------
 
 4.1    Mount options
 ---------------------
 
 The following mount options are supported:
 
+       =========       ========================================================
        hidepid=        Set /proc/<pid>/ access mode.
        gid=            Set the group authorized to learn processes information.
+       =========       ========================================================
 
 hidepid=0 means classic mode - everybody may access all /proc/<pid>/ directories
 (default).
similarity index 98%
rename from Documentation/filesystems/qnx6.txt
rename to Documentation/filesystems/qnx6.rst
index 48ea68f..b713083 100644 (file)
@@ -1,3 +1,6 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+===================
 The QNX6 Filesystem
 ===================
 
@@ -14,10 +17,12 @@ Specification
 
 qnx6fs shares many properties with traditional Unix filesystems. It has the
 concepts of blocks, inodes and directories.
+
 On QNX it is possible to create little endian and big endian qnx6 filesystems.
 This feature makes it possible to create and use a different endianness fs
 for the target (QNX is used on quite a range of embedded systems) platform
 running on a different endianness.
+
 The Linux driver handles endianness transparently. (LE and BE)
 
 Blocks
@@ -26,6 +31,7 @@ Blocks
 The space in the device or file is split up into blocks. These are a fixed
 size of 512, 1024, 2048 or 4096, which is decided when the filesystem is
 created.
+
 Blockpointers are 32bit, so the maximum space that can be addressed is
 2^32 * 4096 bytes or 16TB
 
@@ -50,6 +56,7 @@ Each of these root nodes holds information like total size of the stored
 data and the addressing levels in that specific tree.
 If the level value is 0, up to 16 direct blocks can be addressed by each
 node.
+
 Level 1 adds an additional indirect addressing level where each indirect
 addressing block holds up to blocksize / 4 bytes pointers to data blocks.
 Level 2 adds an additional indirect addressing block level (so, already up
@@ -57,11 +64,13 @@ to 16 * 256 * 256 = 1048576 blocks that can be addressed by such a tree).
 
 Unused block pointers are always set to ~0 - regardless of root node,
 indirect addressing blocks or inodes.
+
 Data leaves are always on the lowest level. So no data is stored on upper
 tree levels.
 
 The first Superblock is located at 0x2000. (0x2000 is the bootblock size)
 The Audi MMI 3G first superblock directly starts at byte 0.
+
 Second superblock position can either be calculated from the superblock
 information (total number of filesystem blocks) or by taking the highest
 device address, zeroing the last 3 bytes and then subtracting 0x1000 from
@@ -84,6 +93,7 @@ Object mode field is POSIX format. (which makes things easier)
 
 There are also pointers to the first 16 blocks, if the object data can be
 addressed with 16 direct blocks.
+
 For more than 16 blocks an indirect addressing in form of another tree is
 used. (scheme is the same as the one used for the superblock root nodes)
 
@@ -96,13 +106,18 @@ Directories
 A directory is a filesystem object and has an inode just like a file.
 It is a specially formatted file containing records which associate each
 name with an inode number.
+
 '.' inode number points to the directory inode
+
 '..' inode number points to the parent directory inode
+
 Eeach filename record additionally got a filename length field.
 
 One special case are long filenames or subdirectory names.
+
 These got set a filename length field of 0xff in the corresponding directory
 record plus the longfile inode number also stored in that record.
+
 With that longfilename inode number, the longfilename tree can be walked
 starting with the superblock longfilename root node pointers.
 
@@ -111,6 +126,7 @@ Special files
 
 Symbolic links are also filesystem objects with inodes. They got a specific
 bit in the inode mode field identifying them as symbolic link.
+
 The directory entry file inode pointer points to the target file inode.
 
 Hard links got an inode, a directory entry, but a specific mode bit set,
@@ -126,9 +142,11 @@ Long filenames
 
 Long filenames are stored in a separate addressing tree. The staring point
 is the longfilename root node in the active superblock.
+
 Each data block (tree leaves) holds one long filename. That filename is
 limited to 510 bytes. The first two starting bytes are used as length field
 for the actual filename.
+
 If that structure shall fit for all allowed blocksizes, it is clear why there
 is a limit of 510 bytes for the actual filename stored.
 
@@ -138,6 +156,7 @@ Bitmap
 The qnx6fs filesystem allocation bitmap is stored in a tree under bitmap
 root node in the superblock and each bit in the bitmap represents one
 filesystem block.
+
 The first block is block 0, which starts 0x1000 after superblock start.
 So for a normal qnx6fs 0x3000 (bootblock + superblock) is the physical
 address at which block 0 is located.
@@ -149,11 +168,14 @@ Bitmap system area
 ------------------
 
 The bitmap itself is divided into three parts.
+
 First the system area, that is split into two halves.
+
 Then userspace.
 
 The requirement for a static, fixed preallocated system area comes from how
 qnx6fs deals with writes.
+
 Each superblock got it's own half of the system area. So superblock #1
 always uses blocks from the lower half while superblock #2 just writes to
 blocks represented by the upper half bitmap system area bits.
@@ -1,5 +1,11 @@
-ramfs, rootfs and initramfs
+.. SPDX-License-Identifier: GPL-2.0
+
+===========================
+Ramfs, rootfs and initramfs
+===========================
+
 October 17, 2005
+
 Rob Landley <rob@landley.net>
 =============================
 
@@ -99,14 +105,14 @@ out of that.
 All this differs from the old initrd in several ways:
 
   - The old initrd was always a separate file, while the initramfs archive is
-    linked into the linux kernel image.  (The directory linux-*/usr is devoted
-    to generating this archive during the build.)
+    linked into the linux kernel image.  (The directory ``linux-*/usr`` is
+    devoted to generating this archive during the build.)
 
   - The old initrd file was a gzipped filesystem image (in some file format,
     such as ext2, that needed a driver built into the kernel), while the new
     initramfs archive is a gzipped cpio archive (like tar only simpler,
-    see cpio(1) and Documentation/driver-api/early-userspace/buffer-format.rst).  The
-    kernel's cpio extraction code is not only extremely small, it's also
+    see cpio(1) and Documentation/driver-api/early-userspace/buffer-format.rst).
+    The kernel's cpio extraction code is not only extremely small, it's also
     __init text and data that can be discarded during the boot process.
 
   - The program run by the old initrd (which was called /initrd, not /init) did
@@ -139,7 +145,7 @@ and living in usr/Kconfig) can be used to specify a source for the
 initramfs archive, which will automatically be incorporated into the
 resulting binary.  This option can point to an existing gzipped cpio
 archive, a directory containing files to be archived, or a text file
-specification such as the following example:
+specification such as the following example::
 
   dir /dev 755 0 0
   nod /dev/console 644 0 0 c 5 1
@@ -175,12 +181,12 @@ or extracting your own preprepared cpio files to feed to the kernel build
 (instead of a config file or directory).
 
 The following command line can extract a cpio image (either by the above script
-or by the kernel build) back into its component files:
+or by the kernel build) back into its component files::
 
   cpio -i -d -H newc -F initramfs_data.cpio --no-absolute-filenames
 
 The following shell script can create a prebuilt cpio archive you can
-use in place of the above config file:
+use in place of the above config file::
 
   #!/bin/sh
 
@@ -202,14 +208,17 @@ use in place of the above config file:
     exit 1
   fi
 
-Note: The cpio man page contains some bad advice that will break your initramfs
-archive if you follow it.  It says "A typical way to generate the list
-of filenames is with the find command; you should give find the -depth option
-to minimize problems with permissions on directories that are unwritable or not
-searchable."  Don't do this when creating initramfs.cpio.gz images, it won't
-work.  The Linux kernel cpio extractor won't create files in a directory that
-doesn't exist, so the directory entries must go before the files that go in
-those directories.  The above script gets them in the right order.
+.. Note::
+
+   The cpio man page contains some bad advice that will break your initramfs
+   archive if you follow it.  It says "A typical way to generate the list
+   of filenames is with the find command; you should give find the -depth
+   option to minimize problems with permissions on directories that are
+   unwritable or not searchable."  Don't do this when creating
+   initramfs.cpio.gz images, it won't work.  The Linux kernel cpio extractor
+   won't create files in a directory that doesn't exist, so the directory
+   entries must go before the files that go in those directories.
+   The above script gets them in the right order.
 
 External initramfs images:
 --------------------------
@@ -236,9 +245,10 @@ An initramfs archive is a complete self-contained root filesystem for Linux.
 If you don't already understand what shared libraries, devices, and paths
 you need to get a minimal root filesystem up and running, here are some
 references:
-http://www.tldp.org/HOWTO/Bootdisk-HOWTO/
-http://www.tldp.org/HOWTO/From-PowerUp-To-Bash-Prompt-HOWTO.html
-http://www.linuxfromscratch.org/lfs/view/stable/
+
+- http://www.tldp.org/HOWTO/Bootdisk-HOWTO/
+- http://www.tldp.org/HOWTO/From-PowerUp-To-Bash-Prompt-HOWTO.html
+- http://www.linuxfromscratch.org/lfs/view/stable/
 
 The "klibc" package (http://www.kernel.org/pub/linux/libs/klibc) is
 designed to be a tiny C library to statically link early userspace
@@ -255,7 +265,7 @@ name lookups, even when otherwise statically linked.)
 
 A good first step is to get initramfs to run a statically linked "hello world"
 program as init, and test it under an emulator like qemu (www.qemu.org) or
-User Mode Linux, like so:
+User Mode Linux, like so::
 
   cat > hello.c << EOF
   #include <stdio.h>
@@ -326,8 +336,8 @@ the above threads) is:
 
    explained his reasoning:
 
-      http://www.uwsg.iu.edu/hypermail/linux/kernel/0112.2/1550.html
-      http://www.uwsg.iu.edu/hypermail/linux/kernel/0112.2/1638.html
+     - http://www.uwsg.iu.edu/hypermail/linux/kernel/0112.2/1550.html
+     - http://www.uwsg.iu.edu/hypermail/linux/kernel/0112.2/1638.html
 
    and, most importantly, designed and implemented the initramfs code.
 
similarity index 91%
rename from Documentation/filesystems/relay.txt
rename to Documentation/filesystems/relay.rst
index cd709a9..04ad083 100644 (file)
@@ -1,3 +1,6 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+==================================
 relay interface (formerly relayfs)
 ==================================
 
@@ -108,6 +111,7 @@ The relay interface implements basic file operations for user space
 access to relay channel buffer data.  Here are the file operations
 that are available and some comments regarding their behavior:
 
+=========== ============================================================
 open()     enables user to open an _existing_ channel buffer.
 
 mmap()      results in channel buffer being mapped into the caller's
@@ -136,13 +140,16 @@ poll()      POLLIN/POLLRDNORM/POLLERR supported.  User applications are
 close()     decrements the channel buffer's refcount.  When the refcount
            reaches 0, i.e. when no process or kernel client has the
            buffer open, the channel buffer is freed.
+=========== ============================================================
 
 In order for a user application to make use of relay files, the
-host filesystem must be mounted.  For example,
+host filesystem must be mounted.  For example::
 
        mount -t debugfs debugfs /sys/kernel/debug
 
-NOTE:   the host filesystem doesn't need to be mounted for kernel
+.. Note::
+
+       the host filesystem doesn't need to be mounted for kernel
        clients to create or use channels - it only needs to be
        mounted when user space applications need access to the buffer
        data.
@@ -154,7 +161,7 @@ The relay interface kernel API
 Here's a summary of the API the relay interface provides to in-kernel clients:
 
 TBD(curr. line MT:/API/)
-  channel management functions:
+  channel management functions::
 
     relay_open(base_filename, parent, subbuf_size, n_subbufs,
                callbacks, private_data)
@@ -162,17 +169,17 @@ TBD(curr. line MT:/API/)
     relay_flush(chan)
     relay_reset(chan)
 
-  channel management typically called on instigation of userspace:
+  channel management typically called on instigation of userspace::
 
     relay_subbufs_consumed(chan, cpu, subbufs_consumed)
 
-  write functions:
+  write functions::
 
     relay_write(chan, data, length)
     __relay_write(chan, data, length)
     relay_reserve(chan, length)
 
-  callbacks:
+  callbacks::
 
     subbuf_start(buf, subbuf, prev_subbuf, prev_padding)
     buf_mapped(buf, filp)
@@ -180,7 +187,7 @@ TBD(curr. line MT:/API/)
     create_buf_file(filename, parent, mode, buf, is_global)
     remove_buf_file(dentry)
 
-  helper functions:
+  helper functions::
 
     relay_buf_full(buf)
     subbuf_start_reserve(buf, length)
@@ -215,41 +222,41 @@ the file(s) created in create_buf_file() and is called during
 relay_close().
 
 Here are some typical definitions for these callbacks, in this case
-using debugfs:
-
-/*
- * create_buf_file() callback.  Creates relay file in debugfs.
- */
-static struct dentry *create_buf_file_handler(const char *filename,
-                                              struct dentry *parent,
-                                              umode_t mode,
-                                              struct rchan_buf *buf,
-                                              int *is_global)
-{
-        return debugfs_create_file(filename, mode, parent, buf,
-                                  &relay_file_operations);
-}
-
-/*
- * remove_buf_file() callback.  Removes relay file from debugfs.
- */
-static int remove_buf_file_handler(struct dentry *dentry)
-{
-        debugfs_remove(dentry);
-
-        return 0;
-}
-
-/*
- * relay interface callbacks
- */
-static struct rchan_callbacks relay_callbacks =
-{
-        .create_buf_file = create_buf_file_handler,
-        .remove_buf_file = remove_buf_file_handler,
-};
-
-And an example relay_open() invocation using them:
+using debugfs::
+
+    /*
   * create_buf_file() callback.  Creates relay file in debugfs.
   */
+    static struct dentry *create_buf_file_handler(const char *filename,
+                                               struct dentry *parent,
+                                               umode_t mode,
+                                               struct rchan_buf *buf,
+                                               int *is_global)
+    {
+           return debugfs_create_file(filename, mode, parent, buf,
+                                   &relay_file_operations);
+    }
+
+    /*
   * remove_buf_file() callback.  Removes relay file from debugfs.
   */
+    static int remove_buf_file_handler(struct dentry *dentry)
+    {
+           debugfs_remove(dentry);
+
+           return 0;
+    }
+
+    /*
   * relay interface callbacks
   */
+    static struct rchan_callbacks relay_callbacks =
+    {
+           .create_buf_file = create_buf_file_handler,
+           .remove_buf_file = remove_buf_file_handler,
+    };
+
+And an example relay_open() invocation using them::
 
   chan = relay_open("cpu", NULL, SUBBUF_SIZE, N_SUBBUFS, &relay_callbacks, NULL);
 
@@ -339,23 +346,23 @@ whether or not to actually move on to the next sub-buffer.
 
 To implement 'no-overwrite' mode, the userspace client would provide
 an implementation of the subbuf_start() callback something like the
-following:
+following::
 
-static int subbuf_start(struct rchan_buf *buf,
-                        void *subbuf,
-                       void *prev_subbuf,
-                       unsigned int prev_padding)
-{
-       if (prev_subbuf)
-               *((unsigned *)prev_subbuf) = prev_padding;
+    static int subbuf_start(struct rchan_buf *buf,
+                           void *subbuf,
+                           void *prev_subbuf,
+                           unsigned int prev_padding)
+    {
+           if (prev_subbuf)
+                   *((unsigned *)prev_subbuf) = prev_padding;
 
-       if (relay_buf_full(buf))
-               return 0;
+           if (relay_buf_full(buf))
+                   return 0;
 
-       subbuf_start_reserve(buf, sizeof(unsigned int));
+           subbuf_start_reserve(buf, sizeof(unsigned int));
 
-       return 1;
-}
+           return 1;
+    }
 
 If the current buffer is full, i.e. all sub-buffers remain unconsumed,
 the callback returns 0 to indicate that the buffer switch should not
@@ -370,20 +377,20 @@ ready sub-buffers will relay_buf_full() return 0, in which case the
 buffer switch can continue.
 
 The implementation of the subbuf_start() callback for 'overwrite' mode
-would be very similar:
+would be very similar::
 
-static int subbuf_start(struct rchan_buf *buf,
-                        void *subbuf,
-                       void *prev_subbuf,
-                       size_t prev_padding)
-{
-       if (prev_subbuf)
-               *((unsigned *)prev_subbuf) = prev_padding;
+    static int subbuf_start(struct rchan_buf *buf,
+                           void *subbuf,
+                           void *prev_subbuf,
+                           size_t prev_padding)
+    {
+           if (prev_subbuf)
+                   *((unsigned *)prev_subbuf) = prev_padding;
 
-       subbuf_start_reserve(buf, sizeof(unsigned int));
+           subbuf_start_reserve(buf, sizeof(unsigned int));
 
-       return 1;
-}
+           return 1;
+    }
 
 In this case, the relay_buf_full() check is meaningless and the
 callback always returns 1, causing the buffer switch to occur
similarity index 86%
rename from Documentation/filesystems/romfs.txt
rename to Documentation/filesystems/romfs.rst
index e2b07cc..465b11e 100644 (file)
@@ -1,4 +1,8 @@
-ROMFS - ROM FILE SYSTEM
+.. SPDX-License-Identifier: GPL-2.0
+
+=======================
+ROMFS - ROM File System
+=======================
 
 This is a quite dumb, read only filesystem, mainly for initial RAM
 disks of installation disks.  It has grown up by the need of having
@@ -51,9 +55,9 @@ the 16 byte padding for the name and the contents, also 16+14+15 = 45
 bytes.  This is quite rare however, since most file names are longer
 than 3 bytes, and shorter than 15 bytes.
 
-The layout of the filesystem is the following:
+The layout of the filesystem is the following::
 
-offset     content
+ offset            content
 
        +---+---+---+---+
   0    | - | r | o | m |  \
@@ -84,9 +88,9 @@ the source.  This algorithm was chosen because although it's not quite
 reliable, it does not require any tables, and it is very simple.
 
 The following bytes are now part of the file system; each file header
-must begin on a 16 byte boundary.
+must begin on a 16 byte boundary::
 
-offset     content
+ offset            content
 
        +---+---+---+---+
   0    | next filehdr|X|       The offset of the next file header
@@ -114,7 +118,9 @@ file is user and group 0, this should never be a problem for the
 intended use.  The mapping of the 8 possible values to file types is
 the following:
 
+==     =============== ============================================
          mapping               spec.info means
+==     =============== ============================================
  0     hard link       link destination [file header]
  1     directory       first file's header
  2     regular file    unused, must be zero [MBZ]
@@ -123,6 +129,7 @@ the following:
  5     char device                 - " -
  6     socket          unused, MBZ
  7     fifo            unused, MBZ
+==     =============== ============================================
 
 Note that hard links are specifically marked in this filesystem, but
 they will behave as you can expect (i.e. share the inode number).
@@ -158,24 +165,24 @@ to romfs-subscribe@shadow.banki.hu, the content is irrelevant.
 Pending issues:
 
 - Permissions and owner information are pretty essential features of a
-Un*x like system, but romfs does not provide the full possibilities.
-I have never found this limiting, but others might.
+  Un*x like system, but romfs does not provide the full possibilities.
+  I have never found this limiting, but others might.
 
 - The file system is read only, so it can be very small, but in case
-one would want to write _anything_ to a file system, he still needs
-a writable file system, thus negating the size advantages.  Possible
-solutions: implement write access as a compile-time option, or a new,
-similarly small writable filesystem for RAM disks.
+  one would want to write _anything_ to a file system, he still needs
+  a writable file system, thus negating the size advantages.  Possible
+  solutions: implement write access as a compile-time option, or a new,
+  similarly small writable filesystem for RAM disks.
 
 - Since the files are only required to have alignment on a 16 byte
-boundary, it is currently possibly suboptimal to read or execute files
-from the filesystem.  It might be resolved by reordering file data to
-have most of it (i.e. except the start and the end) laying at "natural"
-boundaries, thus it would be possible to directly map a big portion of
-the file contents to the mm subsystem.
+  boundary, it is currently possibly suboptimal to read or execute files
+  from the filesystem.  It might be resolved by reordering file data to
+  have most of it (i.e. except the start and the end) laying at "natural"
+  boundaries, thus it would be possible to directly map a big portion of
+  the file contents to the mm subsystem.
 
 - Compression might be an useful feature, but memory is quite a
-limiting factor in my eyes.
+  limiting factor in my eyes.
 
 - Where it is used?
 
@@ -183,4 +190,5 @@ limiting factor in my eyes.
 
 
 Have fun,
+
 Janos Farkas <chexum@shadow.banki.hu>
similarity index 91%
rename from Documentation/filesystems/squashfs.txt
rename to Documentation/filesystems/squashfs.rst
index e5274f8..df42106 100644 (file)
@@ -1,7 +1,11 @@
-SQUASHFS 4.0 FILESYSTEM
+.. SPDX-License-Identifier: GPL-2.0
+
+=======================
+Squashfs 4.0 Filesystem
 =======================
 
 Squashfs is a compressed read-only filesystem for Linux.
+
 It uses zlib, lz4, lzo, or xz compression to compress files, inodes and
 directories.  Inodes in the system are very small and all blocks are packed to
 minimise data overhead. Block sizes greater than 4K are supported up to a
@@ -15,31 +19,33 @@ needed.
 Mailing list: squashfs-devel@lists.sourceforge.net
 Web site: www.squashfs.org
 
-1. FILESYSTEM FEATURES
+1. Filesystem Features
 ----------------------
 
 Squashfs filesystem features versus Cramfs:
 
+==============================         =========               ==========
                                Squashfs                Cramfs
-
-Max filesystem size:           2^64                    256 MiB
-Max file size:                 ~ 2 TiB                 16 MiB
-Max files:                     unlimited               unlimited
-Max directories:               unlimited               unlimited
-Max entries per directory:     unlimited               unlimited
-Max block size:                        1 MiB                   4 KiB
-Metadata compression:          yes                     no
-Directory indexes:             yes                     no
-Sparse file support:           yes                     no
-Tail-end packing (fragments):  yes                     no
-Exportable (NFS etc.):         yes                     no
-Hard link support:             yes                     no
-"." and ".." in readdir:       yes                     no
-Real inode numbers:            yes                     no
-32-bit uids/gids:              yes                     no
-File creation time:            yes                     no
-Xattr support:                 yes                     no
-ACL support:                   no                      no
+==============================         =========               ==========
+Max filesystem size            2^64                    256 MiB
+Max file size                  ~ 2 TiB                 16 MiB
+Max files                      unlimited               unlimited
+Max directories                        unlimited               unlimited
+Max entries per directory      unlimited               unlimited
+Max block size                 1 MiB                   4 KiB
+Metadata compression           yes                     no
+Directory indexes              yes                     no
+Sparse file support            yes                     no
+Tail-end packing (fragments)   yes                     no
+Exportable (NFS etc.)          yes                     no
+Hard link support              yes                     no
+"." and ".." in readdir                yes                     no
+Real inode numbers             yes                     no
+32-bit uids/gids               yes                     no
+File creation time             yes                     no
+Xattr support                  yes                     no
+ACL support                    no                      no
+==============================         =========               ==========
 
 Squashfs compresses data, inodes and directories.  In addition, inode and
 directory data are highly compacted, and packed on byte boundaries.  Each
@@ -47,7 +53,7 @@ compressed inode is on average 8 bytes in length (the exact length varies on
 file type, i.e. regular file, directory, symbolic link, and block/char device
 inodes have different sizes).
 
-2. USING SQUASHFS
+2. Using Squashfs
 -----------------
 
 As squashfs is a read-only filesystem, the mksquashfs program must be used to
@@ -58,11 +64,11 @@ obtained from this site also.
 The squashfs-tools development tree is now located on kernel.org
        git://git.kernel.org/pub/scm/fs/squashfs/squashfs-tools.git
 
-3. SQUASHFS FILESYSTEM DESIGN
+3. Squashfs Filesystem Design
 -----------------------------
 
 A squashfs filesystem consists of a maximum of nine parts, packed together on a
-byte alignment:
+byte alignment::
 
         ---------------
        |  superblock   |
@@ -229,15 +235,15 @@ location of the xattr list inside each inode, a 32-bit xattr id
 is stored.  This xattr id is mapped into the location of the xattr
 list using a second xattr id lookup table.
 
-4. TODOS AND OUTSTANDING ISSUES
+4. TODOs and Outstanding Issues
 -------------------------------
 
-4.1 Todo list
+4.1 TODO list
 -------------
 
 Implement ACL support.
 
-4.2 Squashfs internal cache
+4.2 Squashfs Internal Cache
 ---------------------------
 
 Blocks in Squashfs are compressed.  To avoid repeatedly decompressing
similarity index 56%
rename from Documentation/filesystems/sysfs.txt
rename to Documentation/filesystems/sysfs.rst
index ddf15b1..290891c 100644 (file)
@@ -1,32 +1,36 @@
+.. SPDX-License-Identifier: GPL-2.0
 
-sysfs - _The_ filesystem for exporting kernel objects. 
+=====================================================
+sysfs - _The_ filesystem for exporting kernel objects
+=====================================================
 
 Patrick Mochel <mochel@osdl.org>
+
 Mike Murphy <mamurph@cs.clemson.edu>
 
-Revised:    16 August 2011
-Original:   10 January 2003
+:Revised:    16 August 2011
+:Original:   10 January 2003
 
 
 What it is:
 ~~~~~~~~~~~
 
 sysfs is a ram-based filesystem initially based on ramfs. It provides
-a means to export kernel data structures, their attributes, and the 
-linkages between them to userspace. 
+a means to export kernel data structures, their attributes, and the
+linkages between them to userspace.
 
 sysfs is tied inherently to the kobject infrastructure. Please read
 Documentation/kobject.txt for more information concerning the kobject
-interface. 
+interface.
 
 
 Using sysfs
 ~~~~~~~~~~~
 
 sysfs is always compiled in if CONFIG_SYSFS is defined. You can access
-it by doing:
+it by doing::
 
-    mount -t sysfs sysfs /sys 
+    mount -t sysfs sysfs /sys
 
 
 Directory Creation
@@ -37,7 +41,7 @@ created for it in sysfs. That directory is created as a subdirectory
 of the kobject's parent, expressing internal object hierarchies to
 userspace. Top-level directories in sysfs represent the common
 ancestors of object hierarchies; i.e. the subsystems the objects
-belong to. 
+belong to.
 
 Sysfs internally stores a pointer to the kobject that implements a
 directory in the kernfs_node object associated with the directory. In
@@ -58,63 +62,63 @@ attributes.
 Attributes should be ASCII text files, preferably with only one value
 per file. It is noted that it may not be efficient to contain only one
 value per file, so it is socially acceptable to express an array of
-values of the same type. 
+values of the same type.
 
 Mixing types, expressing multiple lines of data, and doing fancy
 formatting of data is heavily frowned upon. Doing these things may get
-you publicly humiliated and your code rewritten without notice. 
+you publicly humiliated and your code rewritten without notice.
 
 
-An attribute definition is simply:
+An attribute definition is simply::
 
-struct attribute {
-        char                    * name;
-        struct module          *owner;
-        umode_t                 mode;
-};
+    struct attribute {
+           char                    * name;
+           struct module               *owner;
+           umode_t                 mode;
+    };
 
 
-int sysfs_create_file(struct kobject * kobj, const struct attribute * attr);
-void sysfs_remove_file(struct kobject * kobj, const struct attribute * attr);
+    int sysfs_create_file(struct kobject * kobj, const struct attribute * attr);
+    void sysfs_remove_file(struct kobject * kobj, const struct attribute * attr);
 
 
 A bare attribute contains no means to read or write the value of the
 attribute. Subsystems are encouraged to define their own attribute
 structure and wrapper functions for adding and removing attributes for
-a specific object type. 
+a specific object type.
 
-For example, the driver model defines struct device_attribute like:
+For example, the driver model defines struct device_attribute like::
 
-struct device_attribute {
-       struct attribute        attr;
-       ssize_t (*show)(struct device *dev, struct device_attribute *attr,
-                       char *buf);
-       ssize_t (*store)(struct device *dev, struct device_attribute *attr,
-                        const char *buf, size_t count);
-};
+    struct device_attribute {
+           struct attribute    attr;
+           ssize_t (*show)(struct device *dev, struct device_attribute *attr,
+                           char *buf);
+           ssize_t (*store)(struct device *dev, struct device_attribute *attr,
+                           const char *buf, size_t count);
+    };
 
-int device_create_file(struct device *, const struct device_attribute *);
-void device_remove_file(struct device *, const struct device_attribute *);
+    int device_create_file(struct device *, const struct device_attribute *);
+    void device_remove_file(struct device *, const struct device_attribute *);
 
-It also defines this helper for defining device attributes: 
+It also defines this helper for defining device attributes::
 
-#define DEVICE_ATTR(_name, _mode, _show, _store) \
-struct device_attribute dev_attr_##_name = __ATTR(_name, _mode, _show, _store)
+    #define DEVICE_ATTR(_name, _mode, _show, _store) \
+    struct device_attribute dev_attr_##_name = __ATTR(_name, _mode, _show, _store)
 
-For example, declaring
+For example, declaring::
 
-static DEVICE_ATTR(foo, S_IWUSR | S_IRUGO, show_foo, store_foo);
+    static DEVICE_ATTR(foo, S_IWUSR | S_IRUGO, show_foo, store_foo);
 
-is equivalent to doing:
+is equivalent to doing::
 
-static struct device_attribute dev_attr_foo = {
-       .attr = {
-               .name = "foo",
-               .mode = S_IWUSR | S_IRUGO,
-       },
-       .show = show_foo,
-       .store = store_foo,
-};
+    static struct device_attribute dev_attr_foo = {
+           .attr = {
+                   .name = "foo",
+                   .mode = S_IWUSR | S_IRUGO,
+           },
+           .show = show_foo,
+           .store = store_foo,
+    };
 
 Note as stated in include/linux/kernel.h "OTHER_WRITABLE?  Generally
 considered a bad idea." so trying to set a sysfs file writable for
@@ -127,15 +131,21 @@ readable. The above case could be shortened to:
 static struct device_attribute dev_attr_foo = __ATTR_RW(foo);
 
 the list of helpers available to define your wrapper function is:
-__ATTR_RO(name): assumes default name_show and mode 0444
-__ATTR_WO(name): assumes a name_store only and is restricted to mode
+
+__ATTR_RO(name):
+                assumes default name_show and mode 0444
+__ATTR_WO(name):
+                assumes a name_store only and is restricted to mode
                  0200 that is root write access only.
-__ATTR_RO_MODE(name, mode): fore more restrictive RO access currently
+__ATTR_RO_MODE(name, mode):
+                fore more restrictive RO access currently
                  only use case is the EFI System Resource Table
                  (see drivers/firmware/efi/esrt.c)
-__ATTR_RW(name): assumes default name_show, name_store and setting
+__ATTR_RW(name):
+                assumes default name_show, name_store and setting
                  mode to 0644.
-__ATTR_NULL: which sets the name to NULL and is used as end of list
+__ATTR_NULL:
+                which sets the name to NULL and is used as end of list
                  indicator (see: kernel/workqueue.c)
 
 Subsystem-Specific Callbacks
@@ -143,12 +153,12 @@ Subsystem-Specific Callbacks
 
 When a subsystem defines a new attribute type, it must implement a
 set of sysfs operations for forwarding read and write calls to the
-show and store methods of the attribute owners
+show and store methods of the attribute owners::
 
-struct sysfs_ops {
-        ssize_t (*show)(struct kobject *, struct attribute *, char *);
-        ssize_t (*store)(struct kobject *, struct attribute *, const char *, size_t);
-};
+    struct sysfs_ops {
+           ssize_t (*show)(struct kobject *, struct attribute *, char *);
+           ssize_t (*store)(struct kobject *, struct attribute *, const char *, size_t);
+    };
 
 [ Subsystems should have already defined a struct kobj_type as a
 descriptor for this type, which is where the sysfs_ops pointer is
@@ -157,29 +167,29 @@ stored. See the kobject documentation for more information. ]
 When a file is read or written, sysfs calls the appropriate method
 for the type. The method then translates the generic struct kobject
 and struct attribute pointers to the appropriate pointer types, and
-calls the associated methods. 
+calls the associated methods.
 
 
-To illustrate:
+To illustrate::
 
-#define to_dev(obj) container_of(obj, struct device, kobj)
-#define to_dev_attr(_attr) container_of(_attr, struct device_attribute, attr)
+    #define to_dev(obj) container_of(obj, struct device, kobj)
+    #define to_dev_attr(_attr) container_of(_attr, struct device_attribute, attr)
 
-static ssize_t dev_attr_show(struct kobject *kobj, struct attribute *attr,
-                             char *buf)
-{
-        struct device_attribute *dev_attr = to_dev_attr(attr);
-        struct device *dev = to_dev(kobj);
-        ssize_t ret = -EIO;
+    static ssize_t dev_attr_show(struct kobject *kobj, struct attribute *attr,
+                               char *buf)
+    {
+           struct device_attribute *dev_attr = to_dev_attr(attr);
+           struct device *dev = to_dev(kobj);
+           ssize_t ret = -EIO;
 
-        if (dev_attr->show)
-                ret = dev_attr->show(dev, dev_attr, buf);
-        if (ret >= (ssize_t)PAGE_SIZE) {
-                printk("dev_attr_show: %pS returned bad count\n",
-                                dev_attr->show);
-        }
-        return ret;
-}
+           if (dev_attr->show)
+                   ret = dev_attr->show(dev, dev_attr, buf);
+           if (ret >= (ssize_t)PAGE_SIZE) {
+                   printk("dev_attr_show: %pS returned bad count\n",
+                                   dev_attr->show);
+           }
+           return ret;
+    }
 
 
 
@@ -188,11 +198,11 @@ Reading/Writing Attribute Data
 
 To read or write attributes, show() or store() methods must be
 specified when declaring the attribute. The method types should be as
-simple as those defined for device attributes:
+simple as those defined for device attributes::
 
-ssize_t (*show)(struct device *dev, struct device_attribute *attr, char *buf);
-ssize_t (*store)(struct device *dev, struct device_attribute *attr,
-                 const char *buf, size_t count);
+    ssize_t (*show)(struct device *dev, struct device_attribute *attr, char *buf);
+    ssize_t (*store)(struct device *dev, struct device_attribute *attr,
+                   const char *buf, size_t count);
 
 IOW, they should take only an object, an attribute, and a buffer as parameters.
 
@@ -200,11 +210,11 @@ IOW, they should take only an object, an attribute, and a buffer as parameters.
 sysfs allocates a buffer of size (PAGE_SIZE) and passes it to the
 method. Sysfs will call the method exactly once for each read or
 write. This forces the following behavior on the method
-implementations: 
+implementations:
 
-- On read(2), the show() method should fill the entire buffer. 
+- On read(2), the show() method should fill the entire buffer.
   Recall that an attribute should only be exporting one value, or an
-  array of similar values, so this shouldn't be that expensive. 
+  array of similar values, so this shouldn't be that expensive.
 
   This allows userspace to do partial reads and forward seeks
   arbitrarily over the entire file at will. If userspace seeks back to
@@ -218,10 +228,10 @@ implementations:
 
   When writing sysfs files, userspace processes should first read the
   entire file, modify the values it wishes to change, then write the
-  entire buffer back. 
+  entire buffer back.
 
   Attribute method implementations should operate on an identical
-  buffer when reading and writing values. 
+  buffer when reading and writing values.
 
 Other notes:
 
@@ -229,7 +239,7 @@ Other notes:
   file position.
 
 - The buffer will always be PAGE_SIZE bytes in length. On i386, this
-  is 4096. 
+  is 4096.
 
 - show() methods should return the number of bytes printed into the
   buffer. This is the return value of scnprintf().
@@ -246,31 +256,31 @@ Other notes:
   through, be sure to return an error.
 
 - The object passed to the methods will be pinned in memory via sysfs
-  referencing counting its embedded object. However, the physical 
-  entity (e.g. device) the object represents may not be present. Be 
-  sure to have a way to check this, if necessary. 
+  referencing counting its embedded object. However, the physical
+  entity (e.g. device) the object represents may not be present. Be
+  sure to have a way to check this, if necessary.
 
 
-A very simple (and naive) implementation of a device attribute is:
+A very simple (and naive) implementation of a device attribute is::
 
-static ssize_t show_name(struct device *dev, struct device_attribute *attr,
-                         char *buf)
-{
-       return scnprintf(buf, PAGE_SIZE, "%s\n", dev->name);
-}
+    static ssize_t show_name(struct device *dev, struct device_attribute *attr,
+                           char *buf)
+    {
+           return scnprintf(buf, PAGE_SIZE, "%s\n", dev->name);
+    }
 
-static ssize_t store_name(struct device *dev, struct device_attribute *attr,
-                          const char *buf, size_t count)
-{
-        snprintf(dev->name, sizeof(dev->name), "%.*s",
-                 (int)min(count, sizeof(dev->name) - 1), buf);
-       return count;
-}
+    static ssize_t store_name(struct device *dev, struct device_attribute *attr,
+                           const char *buf, size_t count)
+    {
+           snprintf(dev->name, sizeof(dev->name), "%.*s",
+                   (int)min(count, sizeof(dev->name) - 1), buf);
+           return count;
+    }
 
-static DEVICE_ATTR(name, S_IRUGO, show_name, store_name);
+    static DEVICE_ATTR(name, S_IRUGO, show_name, store_name);
 
 
-(Note that the real implementation doesn't allow userspace to set the 
+(Note that the real implementation doesn't allow userspace to set the
 name for a device.)
 
 
@@ -278,25 +288,25 @@ Top Level Directory Layout
 ~~~~~~~~~~~~~~~~~~~~~~~~~~
 
 The sysfs directory arrangement exposes the relationship of kernel
-data structures. 
+data structures.
 
-The top level sysfs directory looks like:
+The top level sysfs directory looks like::
 
-block/
-bus/
-class/
-dev/
-devices/
-firmware/
-net/
-fs/
+    block/
+    bus/
+    class/
+    dev/
+    devices/
+    firmware/
+    net/
+    fs/
 
 devices/ contains a filesystem representation of the device tree. It maps
 directly to the internal kernel device tree, which is a hierarchy of
-struct device. 
+struct device.
 
 bus/ contains flat directory layout of the various bus types in the
-kernel. Each bus's directory contains two subdirectories:
+kernel. Each bus's directory contains two subdirectories::
 
        devices/
        drivers/
@@ -331,71 +341,71 @@ Current Interfaces
 The following interface layers currently exist in sysfs:
 
 
-devices (include/linux/device.h)
-----------------------------------
-Structure:
+devices (include/linux/device.h)
+--------------------------------
+Structure::
 
-struct device_attribute {
-       struct attribute        attr;
-       ssize_t (*show)(struct device *dev, struct device_attribute *attr,
-                       char *buf);
-       ssize_t (*store)(struct device *dev, struct device_attribute *attr,
-                        const char *buf, size_t count);
-};
+    struct device_attribute {
+           struct attribute    attr;
+           ssize_t (*show)(struct device *dev, struct device_attribute *attr,
+                           char *buf);
+           ssize_t (*store)(struct device *dev, struct device_attribute *attr,
+                           const char *buf, size_t count);
+    };
 
-Declaring:
+Declaring::
 
-DEVICE_ATTR(_name, _mode, _show, _store);
+    DEVICE_ATTR(_name, _mode, _show, _store);
 
-Creation/Removal:
+Creation/Removal::
 
-int device_create_file(struct device *dev, const struct device_attribute * attr);
-void device_remove_file(struct device *dev, const struct device_attribute * attr);
+    int device_create_file(struct device *dev, const struct device_attribute * attr);
+    void device_remove_file(struct device *dev, const struct device_attribute * attr);
 
 
-bus drivers (include/linux/device.h)
---------------------------------------
-Structure:
+bus drivers (include/linux/device.h)
+------------------------------------
+Structure::
 
-struct bus_attribute {
-        struct attribute        attr;
-        ssize_t (*show)(struct bus_type *, char * buf);
-        ssize_t (*store)(struct bus_type *, const char * buf, size_t count);
-};
+    struct bus_attribute {
+           struct attribute        attr;
+           ssize_t (*show)(struct bus_type *, char * buf);
+           ssize_t (*store)(struct bus_type *, const char * buf, size_t count);
+    };
 
-Declaring:
+Declaring::
 
-static BUS_ATTR_RW(name);
-static BUS_ATTR_RO(name);
-static BUS_ATTR_WO(name);
+    static BUS_ATTR_RW(name);
+    static BUS_ATTR_RO(name);
+    static BUS_ATTR_WO(name);
 
-Creation/Removal:
+Creation/Removal::
 
-int bus_create_file(struct bus_type *, struct bus_attribute *);
-void bus_remove_file(struct bus_type *, struct bus_attribute *);
+    int bus_create_file(struct bus_type *, struct bus_attribute *);
+    void bus_remove_file(struct bus_type *, struct bus_attribute *);
 
 
-device drivers (include/linux/device.h)
------------------------------------------
+device drivers (include/linux/device.h)
+---------------------------------------
 
-Structure:
+Structure::
 
-struct driver_attribute {
-        struct attribute        attr;
-        ssize_t (*show)(struct device_driver *, char * buf);
-        ssize_t (*store)(struct device_driver *, const char * buf,
-                         size_t count);
-};
+    struct driver_attribute {
+           struct attribute        attr;
+           ssize_t (*show)(struct device_driver *, char * buf);
+           ssize_t (*store)(struct device_driver *, const char * buf,
+                           size_t count);
+    };
 
-Declaring:
+Declaring::
 
-DRIVER_ATTR_RO(_name)
-DRIVER_ATTR_RW(_name)
+    DRIVER_ATTR_RO(_name)
+    DRIVER_ATTR_RW(_name)
 
-Creation/Removal:
+Creation/Removal::
 
-int driver_create_file(struct device_driver *, const struct driver_attribute *);
-void driver_remove_file(struct device_driver *, const struct driver_attribute *);
+    int driver_create_file(struct device_driver *, const struct driver_attribute *);
+    void driver_remove_file(struct device_driver *, const struct driver_attribute *);
 
 
 Documentation
similarity index 73%
rename from Documentation/filesystems/sysv-fs.txt
rename to Documentation/filesystems/sysv-fs.rst
index 253b50d..89e4091 100644 (file)
@@ -1,25 +1,40 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+==================
+SystemV Filesystem
+==================
+
 It implements all of
   - Xenix FS,
   - SystemV/386 FS,
   - Coherent FS.
 
 To install:
+
 * Answer the 'System V and Coherent filesystem support' question with 'y'
   when configuring the kernel.
-* To mount a disk or a partition, use
+* To mount a disk or a partition, use::
+
     mount [-r] -t sysv device mountpoint
-  The file system type names
+
+  The file system type names::
+
                -t sysv
                -t xenix
                -t coherent
+
   may be used interchangeably, but the last two will eventually disappear.
 
 Bugs in the present implementation:
+
 - Coherent FS:
+
   - The "free list interleave" n:m is currently ignored.
   - Only file systems with no filesystem name and no pack name are recognized.
-  (See Coherent "man mkfs" for a description of these features.)
+    (See Coherent "man mkfs" for a description of these features.)
+
 - SystemV Release 2 FS:
+
   The superblock is only searched in the blocks 9, 15, 18, which
   corresponds to the beginning of track 1 on floppy disks. No support
   for this FS on hard disk yet.
@@ -28,12 +43,14 @@ Bugs in the present implementation:
 These filesystems are rather similar. Here is a comparison with Minix FS:
 
 * Linux fdisk reports on partitions
+
   - Minix FS     0x81 Linux/Minix
   - Xenix FS     ??
   - SystemV FS   ??
   - Coherent FS  0x08 AIX bootable
 
 * Size of a block or zone (data allocation unit on disk)
+
   - Minix FS     1024
   - Xenix FS     1024 (also 512 ??)
   - SystemV FS   1024 (also 512 and 2048)
@@ -45,37 +62,51 @@ These filesystems are rather similar. Here is a comparison with Minix FS:
   all the block numbers (including the super block) are offset by one track.
 
 * Byte ordering of "short" (16 bit entities) on disk:
+
   - Minix FS     little endian  0 1
   - Xenix FS     little endian  0 1
   - SystemV FS   little endian  0 1
   - Coherent FS  little endian  0 1
+
   Of course, this affects only the file system, not the data of files on it!
 
 * Byte ordering of "long" (32 bit entities) on disk:
+
   - Minix FS     little endian  0 1 2 3
   - Xenix FS     little endian  0 1 2 3
   - SystemV FS   little endian  0 1 2 3
   - Coherent FS  PDP-11         2 3 0 1
+
   Of course, this affects only the file system, not the data of files on it!
 
 * Inode on disk: "short", 0 means non-existent, the root dir ino is:
-  - Minix FS                            1
-  - Xenix FS, SystemV FS, Coherent FS   2
+
+  =================================  ==
+  Minix FS                            1
+  Xenix FS, SystemV FS, Coherent FS   2
+  =================================  ==
 
 * Maximum number of hard links to a file:
-  - Minix FS     250
-  - Xenix FS     ??
-  - SystemV FS   ??
-  - Coherent FS  >=10000
+
+  ===========  =========
+  Minix FS     250
+  Xenix FS     ??
+  SystemV FS   ??
+  Coherent FS  >=10000
+  ===========  =========
 
 * Free inode management:
-  - Minix FS                             a bitmap
+
+  - Minix FS
+      a bitmap
   - Xenix FS, SystemV FS, Coherent FS
       There is a cache of a certain number of free inodes in the super-block.
       When it is exhausted, new free inodes are found using a linear search.
 
 * Free block management:
-  - Minix FS                             a bitmap
+
+  - Minix FS
+      a bitmap
   - Xenix FS, SystemV FS, Coherent FS
       Free blocks are organized in a "free list". Maybe a misleading term,
       since it is not true that every free block contains a pointer to
@@ -86,13 +117,18 @@ These filesystems are rather similar. Here is a comparison with Minix FS:
       0 on Xenix FS and SystemV FS, with a block zeroed out on Coherent FS.
 
 * Super-block location:
-  - Minix FS     block 1 = bytes 1024..2047
-  - Xenix FS     block 1 = bytes 1024..2047
-  - SystemV FS   bytes 512..1023
-  - Coherent FS  block 1 = bytes 512..1023
+
+  ===========  ==========================
+  Minix FS     block 1 = bytes 1024..2047
+  Xenix FS     block 1 = bytes 1024..2047
+  SystemV FS   bytes 512..1023
+  Coherent FS  block 1 = bytes 512..1023
+  ===========  ==========================
 
 * Super-block layout:
-  - Minix FS
+
+  - Minix FS::
+
                     unsigned short s_ninodes;
                     unsigned short s_nzones;
                     unsigned short s_imap_blocks;
@@ -101,7 +137,9 @@ These filesystems are rather similar. Here is a comparison with Minix FS:
                     unsigned short s_log_zone_size;
                     unsigned long s_max_size;
                     unsigned short s_magic;
-  - Xenix FS, SystemV FS, Coherent FS
+
+  - Xenix FS, SystemV FS, Coherent FS::
+
                     unsigned short s_firstdatazone;
                     unsigned long  s_nzones;
                     unsigned short s_fzone_count;
@@ -120,23 +158,33 @@ These filesystems are rather similar. Here is a comparison with Minix FS:
                     unsigned short s_interleave_m,s_interleave_n; -- Coherent FS only
                     char           s_fname[6];
                     char           s_fpack[6];
+
     then they differ considerably:
-        Xenix FS
+
+        Xenix FS::
+
                     char           s_clean;
                     char           s_fill[371];
                     long           s_magic;
                     long           s_type;
-        SystemV FS
+
+        SystemV FS::
+
                     long           s_fill[12 or 14];
                     long           s_state;
                     long           s_magic;
                     long           s_type;
-        Coherent FS
+
+        Coherent FS::
+
                     unsigned long  s_unique;
+
     Note that Coherent FS has no magic.
 
 * Inode layout:
-  - Minix FS
+
+  - Minix FS::
+
                     unsigned short i_mode;
                     unsigned short i_uid;
                     unsigned long  i_size;
@@ -144,7 +192,9 @@ These filesystems are rather similar. Here is a comparison with Minix FS:
                     unsigned char  i_gid;
                     unsigned char  i_nlinks;
                     unsigned short i_zone[7+1+1];
-  - Xenix FS, SystemV FS, Coherent FS
+
+  - Xenix FS, SystemV FS, Coherent FS::
+
                     unsigned short i_mode;
                     unsigned short i_nlink;
                     unsigned short i_uid;
@@ -155,38 +205,55 @@ These filesystems are rather similar. Here is a comparison with Minix FS:
                     unsigned long  i_mtime;
                     unsigned long  i_ctime;
 
+
 * Regular file data blocks are organized as
-  - Minix FS
-               7 direct blocks
-               1 indirect block (pointers to blocks)
-               1 double-indirect block (pointer to pointers to blocks)
-  - Xenix FS, SystemV FS, Coherent FS
-              10 direct blocks
-               1 indirect block (pointers to blocks)
-               1 double-indirect block (pointer to pointers to blocks)
-               1 triple-indirect block (pointer to pointers to pointers to blocks)
 
-* Inode size, inodes per block
-  - Minix FS        32   32
-  - Xenix FS        64   16
-  - SystemV FS      64   16
-  - Coherent FS     64    8
+  - Minix FS:
+
+             - 7 direct blocks
+            - 1 indirect block (pointers to blocks)
+             - 1 double-indirect block (pointer to pointers to blocks)
+
+  - Xenix FS, SystemV FS, Coherent FS:
+
+             - 10 direct blocks
+             -  1 indirect block (pointers to blocks)
+             -  1 double-indirect block (pointer to pointers to blocks)
+             -  1 triple-indirect block (pointer to pointers to pointers to blocks)
+
+
+  ===========  ==========   ================
+               Inode size   inodes per block
+  ===========  ==========   ================
+  Minix FS        32        32
+  Xenix FS        64        16
+  SystemV FS      64        16
+  Coherent FS     64        8
+  ===========  ==========   ================
 
 * Directory entry on disk
-  - Minix FS
+
+  - Minix FS::
+
                     unsigned short inode;
                     char name[14/30];
-  - Xenix FS, SystemV FS, Coherent FS
+
+  - Xenix FS, SystemV FS, Coherent FS::
+
                     unsigned short inode;
                     char name[14];
 
-* Dir entry size, dir entries per block
-  - Minix FS     16/32    64/32
-  - Xenix FS     16       64
-  - SystemV FS   16       64
-  - Coherent FS  16       32
+  ===========    ==============    =====================
+                 Dir entry size    dir entries per block
+  ===========    ==============    =====================
+  Minix FS       16/32             64/32
+  Xenix FS       16                64
+  SystemV FS     16                64
+  Coherent FS    16                32
+  ===========    ==============    =====================
 
 * How to implement symbolic links such that the host fsck doesn't scream:
+
   - Minix FS     normal
   - Xenix FS     kludge: as regular files with  chmod 1000
   - SystemV FS   ??
similarity index 86%
rename from Documentation/filesystems/tmpfs.txt
rename to Documentation/filesystems/tmpfs.rst
index 5ecbc03..4e95929 100644 (file)
@@ -1,3 +1,9 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+=====
+Tmpfs
+=====
+
 Tmpfs is a file system which keeps all files in virtual memory.
 
 
@@ -14,7 +20,7 @@ If you compare it to ramfs (which was the template to create tmpfs)
 you gain swapping and limit checking. Another similar thing is the RAM
 disk (/dev/ram*), which simulates a fixed size hard disk in physical
 RAM, where you have to create an ordinary filesystem on top. Ramdisks
-cannot swap and you do not have the possibility to resize them. 
+cannot swap and you do not have the possibility to resize them.
 
 Since tmpfs lives completely in the page cache and on swap, all tmpfs
 pages will be shown as "Shmem" in /proc/meminfo and "Shared" in
@@ -26,7 +32,7 @@ tmpfs has the following uses:
 
 1) There is always a kernel internal mount which you will not see at
    all. This is used for shared anonymous mappings and SYSV shared
-   memory. 
+   memory.
 
    This mount does not depend on CONFIG_TMPFS. If CONFIG_TMPFS is not
    set, the user visible part of tmpfs is not build. But the internal
@@ -34,7 +40,7 @@ tmpfs has the following uses:
 
 2) glibc 2.2 and above expects tmpfs to be mounted at /dev/shm for
    POSIX shared memory (shm_open, shm_unlink). Adding the following
-   line to /etc/fstab should take care of this:
+   line to /etc/fstab should take care of this::
 
        tmpfs   /dev/shm        tmpfs   defaults        0 0
 
@@ -56,15 +62,17 @@ tmpfs has the following uses:
 
 tmpfs has three mount options for sizing:
 
-size:      The limit of allocated bytes for this tmpfs instance. The 
+=========  ============================================================
+size       The limit of allocated bytes for this tmpfs instance. The
            default is half of your physical RAM without swap. If you
            oversize your tmpfs instances the machine will deadlock
            since the OOM handler will not be able to free that memory.
-nr_blocks: The same as size, but in blocks of PAGE_SIZE.
-nr_inodes: The maximum number of inodes for this instance. The default
+nr_blocks  The same as size, but in blocks of PAGE_SIZE.
+nr_inodes  The maximum number of inodes for this instance. The default
            is half of the number of your physical RAM pages, or (on a
            machine with highmem) the number of lowmem RAM pages,
            whichever is the lower.
+=========  ============================================================
 
 These parameters accept a suffix k, m or g for kilo, mega and giga and
 can be changed on remount.  The size parameter also accepts a suffix %
@@ -82,6 +90,7 @@ tmpfs has a mount option to set the NUMA memory allocation policy for
 all files in that instance (if CONFIG_NUMA is enabled) - which can be
 adjusted on the fly via 'mount -o remount ...'
 
+======================== ==============================================
 mpol=default             use the process allocation policy
                          (see set_mempolicy(2))
 mpol=prefer:Node         prefers to allocate memory from the given Node
@@ -89,6 +98,7 @@ mpol=bind:NodeList       allocates memory only from nodes in NodeList
 mpol=interleave          prefers to allocate from each node in turn
 mpol=interleave:NodeList allocates from each node of NodeList in turn
 mpol=local              prefers to allocate memory from the local node
+======================== ==============================================
 
 NodeList format is a comma-separated list of decimal numbers and ranges,
 a range being two hyphen-separated decimal numbers, the smallest and
@@ -98,9 +108,9 @@ A memory policy with a valid NodeList will be saved, as specified, for
 use at file creation time.  When a task allocates a file in the file
 system, the mount option memory policy will be applied with a NodeList,
 if any, modified by the calling task's cpuset constraints
-[See Documentation/admin-guide/cgroup-v1/cpusets.rst] and any optional flags, listed
-below.  If the resulting NodeLists is the empty set, the effective memory
-policy for the file will revert to "default" policy.
+[See Documentation/admin-guide/cgroup-v1/cpusets.rst] and any optional flags,
+listed below.  If the resulting NodeLists is the empty set, the effective
+memory policy for the file will revert to "default" policy.
 
 NUMA memory allocation policies have optional flags that can be used in
 conjunction with their modes.  These optional flags can be specified
@@ -109,6 +119,8 @@ See Documentation/admin-guide/mm/numa_memory_policy.rst for a list of
 all available memory allocation policy mode flags and their effect on
 memory policy.
 
+::
+
        =static         is equivalent to        MPOL_F_STATIC_NODES
        =relative       is equivalent to        MPOL_F_RELATIVE_NODES
 
@@ -128,9 +140,11 @@ on MountPoint, by 'mount -o remount,mpol=Policy:NodeList MountPoint'.
 To specify the initial root directory you can use the following mount
 options:
 
-mode:  The permissions as an octal number
-uid:   The user id 
-gid:   The group id
+====   ==================================
+mode   The permissions as an octal number
+uid    The user id
+gid    The group id
+====   ==================================
 
 These options do not have any effect on remount. You can change these
 parameters with chmod(1), chown(1) and chgrp(1) on a mounted filesystem.
@@ -141,9 +155,9 @@ will give you tmpfs instance on /mytmpfs which can allocate 10GB
 RAM/SWAP in 10240 inodes and it is only accessible by root.
 
 
-Author:
+:Author:
    Christoph Rohland <cr@sap.com>, 1.12.01
-Updated:
+:Updated:
    Hugh Dickins, 4 June 2007
-Updated:
+:Updated:
    KOSAKI Motohiro, 16 Mar 2010
index 6a9584f..16efd72 100644 (file)
@@ -1,3 +1,5 @@
+.. SPDX-License-Identifier: GPL-2.0
+
 :orphan:
 
 .. UBIFS Authentication
@@ -92,11 +94,11 @@ UBIFS Index & Tree Node Cache
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
 Basic on-flash UBIFS entities are called *nodes*. UBIFS knows different types
-of nodes. Eg. data nodes (`struct ubifs_data_node`) which store chunks of file
-contents or inode nodes (`struct ubifs_ino_node`) which represent VFS inodes.
-Almost all types of nodes share a common header (`ubifs_ch`) containing basic
+of nodes. Eg. data nodes (``struct ubifs_data_node``) which store chunks of file
+contents or inode nodes (``struct ubifs_ino_node``) which represent VFS inodes.
+Almost all types of nodes share a common header (``ubifs_ch``) containing basic
 information like node type, node length, a sequence number, etc. (see
-`fs/ubifs/ubifs-media.h`in kernel source). Exceptions are entries of the LPT
+``fs/ubifs/ubifs-media.h`` in kernel source). Exceptions are entries of the LPT
 and some less important node types like padding nodes which are used to pad
 unusable content at the end of LEBs.
 
similarity index 91%
rename from Documentation/filesystems/ubifs.txt
rename to Documentation/filesystems/ubifs.rst
index acc8044..e6ee997 100644 (file)
@@ -1,5 +1,11 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+===============
+UBI File System
+===============
+
 Introduction
-=============
+============
 
 UBIFS file-system stands for UBI File System. UBI stands for "Unsorted
 Block Images". UBIFS is a flash file system, which means it is designed
@@ -79,6 +85,7 @@ Mount options
 
 (*) == default.
 
+====================   =======================================================
 bulk_read              read more in one go to take advantage of flash
                        media that read faster sequentially
 no_bulk_read (*)       do not bulk-read
@@ -98,6 +105,7 @@ auth_key=            specify the key used for authenticating the filesystem.
 auth_hash_name=                The hash algorithm used for authentication. Used for
                        both hashing and for creating HMACs. Typical values
                        include "sha256" or "sha512"
+====================   =======================================================
 
 
 Quick usage instructions
@@ -107,12 +115,14 @@ The UBI volume to mount is specified using "ubiX_Y" or "ubiX:NAME" syntax,
 where "X" is UBI device number, "Y" is UBI volume number, and "NAME" is
 UBI volume name.
 
-Mount volume 0 on UBI device 0 to /mnt/ubifs:
-$ mount -t ubifs ubi0_0 /mnt/ubifs
+Mount volume 0 on UBI device 0 to /mnt/ubifs::
+
+    $ mount -t ubifs ubi0_0 /mnt/ubifs
 
 Mount "rootfs" volume of UBI device 0 to /mnt/ubifs ("rootfs" is volume
-name):
-$ mount -t ubifs ubi0:rootfs /mnt/ubifs
+name)::
+
+    $ mount -t ubifs ubi0:rootfs /mnt/ubifs
 
 The following is an example of the kernel boot arguments to attach mtd0
 to UBI and mount volume "rootfs":
@@ -122,5 +132,6 @@ References
 ==========
 
 UBIFS documentation and FAQ/HOWTO at the MTD web site:
-http://www.linux-mtd.infradead.org/doc/ubifs.html
-http://www.linux-mtd.infradead.org/faq/ubifs.html
+
+- http://www.linux-mtd.infradead.org/doc/ubifs.html
+- http://www.linux-mtd.infradead.org/faq/ubifs.html
similarity index 83%
rename from Documentation/filesystems/udf.txt
rename to Documentation/filesystems/udf.rst
index e2f2faf..d9badbf 100644 (file)
@@ -1,6 +1,8 @@
-*
-* Documentation/filesystems/udf.txt
-*
+.. SPDX-License-Identifier: GPL-2.0
+
+===============
+UDF file system
+===============
 
 If you encounter problems with reading UDF discs using this driver,
 please report them according to MAINTAINERS file.
@@ -18,8 +20,10 @@ performance due to very poor read-modify-write support supplied internally
 by drive firmware.
 
 -------------------------------------------------------------------------------
+
 The following mount options are supported:
 
+       ===========     ======================================
        gid=            Set the default group.
        umask=          Set the default umask.
        mode=           Set the default file permissions.
@@ -34,6 +38,7 @@ The following mount options are supported:
        longad          Use long ad's (default)
        nostrict        Unset strict conformance
        iocharset=      Set the NLS character set
+       ===========     ======================================
 
 The uid= and gid= options need a bit more explaining.  They will accept a
 decimal numeric value and all inodes on that mount will then appear as
@@ -47,13 +52,17 @@ the interactive user will always see the files on the disk as belonging to him.
 
 The remaining are for debugging and disaster recovery:
 
-       novrs           Skip volume sequence recognition 
+       =====           ================================
+       novrs           Skip volume sequence recognition
+       =====           ================================
 
 The following expect a offset from 0.
 
+       ==========      =================================================
        session=        Set the CDROM session (default= last session)
        anchor=         Override standard anchor location. (default= 256)
        lastblock=      Set the last block of the filesystem/
+       ==========      =================================================
 
 -------------------------------------------------------------------------------
 
@@ -62,5 +71,5 @@ For the latest version and toolset see:
        https://github.com/pali/udftools
 
 Documentation on UDF and ECMA 167 is available FREE from:
-       http://www.osta.org/
-       http://www.ecma-international.org/
+       http://www.osta.org/
+       http://www.ecma-international.org/
index 4f338e3..e06e495 100644 (file)
@@ -1,5 +1,7 @@
 .. SPDX-License-Identifier: GPL-2.0
 
+.. _virtiofs_index:
+
 ===================================================
 virtiofs: virtio-fs host<->guest shared file system
 ===================================================
similarity index 90%
rename from Documentation/filesystems/zonefs.txt
rename to Documentation/filesystems/zonefs.rst
index 78813c3..71d845c 100644 (file)
@@ -1,4 +1,8 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+================================================
 ZoneFS - Zone filesystem for Zoned block devices
+================================================
 
 Introduction
 ============
@@ -29,6 +33,7 @@ Zoned block devices
 Zoned storage devices belong to a class of storage devices with an address
 space that is divided into zones. A zone is a group of consecutive LBAs and all
 zones are contiguous (there are no LBA gaps). Zones may have different types.
+
 * Conventional zones: there are no access constraints to LBAs belonging to
   conventional zones. Any read or write access can be executed, similarly to a
   regular block device.
@@ -158,6 +163,7 @@ Format options
 --------------
 
 Several optional features of zonefs can be enabled at format time.
+
 * Conventional zone aggregation: ranges of contiguous conventional zones can be
   aggregated into a single larger file instead of the default one file per zone.
 * File ownership: The owner UID and GID of zone files is by default 0 (root)
@@ -249,7 +255,7 @@ permissions.
 Further action taken by zonefs I/O error recovery can be controlled by the user
 with the "errors=xxx" mount option. The table below summarizes the result of
 zonefs I/O error processing depending on the mount option and on the zone
-conditions.
+conditions::
 
     +--------------+-----------+-----------------------------------------+
     |              |           |            Post error state             |
@@ -275,6 +281,7 @@ conditions.
     +--------------+-----------+-----------------------------------------+
 
 Further notes:
+
 * The "errors=remount-ro" mount option is the default behavior of zonefs I/O
   error processing if no errors mount option is specified.
 * With the "errors=remount-ro" mount option, the change of the file access
@@ -302,6 +309,7 @@ Mount options
 zonefs define the "errors=<behavior>" mount option to allow the user to specify
 zonefs behavior in response to I/O errors, inode size inconsistencies or zone
 condition changes. The defined behaviors are as follow:
+
 * remount-ro (default)
 * zone-ro
 * zone-offline
@@ -333,78 +341,78 @@ Examples
 --------
 
 The following formats a 15TB host-managed SMR HDD with 256 MB zones
-with the conventional zones aggregation feature enabled.
+with the conventional zones aggregation feature enabled::
 
-# mkzonefs -o aggr_cnv /dev/sdX
-# mount -t zonefs /dev/sdX /mnt
-# ls -l /mnt/
-total 0
-dr-xr-xr-x 2 root root     1 Nov 25 13:23 cnv
-dr-xr-xr-x 2 root root 55356 Nov 25 13:23 seq
+    # mkzonefs -o aggr_cnv /dev/sdX
+    # mount -t zonefs /dev/sdX /mnt
+    # ls -l /mnt/
+    total 0
+    dr-xr-xr-x 2 root root     1 Nov 25 13:23 cnv
+    dr-xr-xr-x 2 root root 55356 Nov 25 13:23 seq
 
 The size of the zone files sub-directories indicate the number of files
 existing for each type of zones. In this example, there is only one
 conventional zone file (all conventional zones are aggregated under a single
-file).
+file)::
 
-# ls -l /mnt/cnv
-total 137101312
--rw-r----- 1 root root 140391743488 Nov 25 13:23 0
+    # ls -l /mnt/cnv
+    total 137101312
+    -rw-r----- 1 root root 140391743488 Nov 25 13:23 0
 
-This aggregated conventional zone file can be used as a regular file.
+This aggregated conventional zone file can be used as a regular file::
 
-# mkfs.ext4 /mnt/cnv/0
-# mount -o loop /mnt/cnv/0 /data
+    # mkfs.ext4 /mnt/cnv/0
+    # mount -o loop /mnt/cnv/0 /data
 
 The "seq" sub-directory grouping files for sequential write zones has in this
-example 55356 zones.
+example 55356 zones::
 
-# ls -lv /mnt/seq
-total 14511243264
--rw-r----- 1 root root 0 Nov 25 13:23 0
--rw-r----- 1 root root 0 Nov 25 13:23 1
--rw-r----- 1 root root 0 Nov 25 13:23 2
-...
--rw-r----- 1 root root 0 Nov 25 13:23 55354
--rw-r----- 1 root root 0 Nov 25 13:23 55355
+    # ls -lv /mnt/seq
+    total 14511243264
+    -rw-r----- 1 root root 0 Nov 25 13:23 0
+    -rw-r----- 1 root root 0 Nov 25 13:23 1
+    -rw-r----- 1 root root 0 Nov 25 13:23 2
+    ...
+    -rw-r----- 1 root root 0 Nov 25 13:23 55354
+    -rw-r----- 1 root root 0 Nov 25 13:23 55355
 
 For sequential write zone files, the file size changes as data is appended at
-the end of the file, similarly to any regular file system.
+the end of the file, similarly to any regular file system::
 
-# dd if=/dev/zero of=/mnt/seq/0 bs=4096 count=1 conv=notrunc oflag=direct
-1+0 records in
-1+0 records out
-4096 bytes (4.1 kB, 4.0 KiB) copied, 0.00044121 s, 9.3 MB/s
+    # dd if=/dev/zero of=/mnt/seq/0 bs=4096 count=1 conv=notrunc oflag=direct
+    1+0 records in
+    1+0 records out
+    4096 bytes (4.1 kB, 4.0 KiB) copied, 0.00044121 s, 9.3 MB/s
 
-# ls -l /mnt/seq/0
--rw-r----- 1 root root 4096 Nov 25 13:23 /mnt/seq/0
+    # ls -l /mnt/seq/0
+    -rw-r----- 1 root root 4096 Nov 25 13:23 /mnt/seq/0
 
 The written file can be truncated to the zone size, preventing any further
-write operation.
+write operation::
 
-# truncate -s 268435456 /mnt/seq/0
-# ls -l /mnt/seq/0
--rw-r----- 1 root root 268435456 Nov 25 13:49 /mnt/seq/0
+    # truncate -s 268435456 /mnt/seq/0
+    # ls -l /mnt/seq/0
+    -rw-r----- 1 root root 268435456 Nov 25 13:49 /mnt/seq/0
 
 Truncation to 0 size allows freeing the file zone storage space and restart
-append-writes to the file.
+append-writes to the file::
 
-# truncate -s 0 /mnt/seq/0
-# ls -l /mnt/seq/0
--rw-r----- 1 root root 0 Nov 25 13:49 /mnt/seq/0
+    # truncate -s 0 /mnt/seq/0
+    # ls -l /mnt/seq/0
+    -rw-r----- 1 root root 0 Nov 25 13:49 /mnt/seq/0
 
 Since files are statically mapped to zones on the disk, the number of blocks of
-a file as reported by stat() and fstat() indicates the size of the file zone.
-
-# stat /mnt/seq/0
-  File: /mnt/seq/0
-  Size: 0              Blocks: 524288     IO Block: 4096   regular empty file
-Device: 870h/2160d     Inode: 50431       Links: 1
-Access: (0640/-rw-r-----)  Uid: (    0/    root)   Gid: (    0/    root)
-Access: 2019-11-25 13:23:57.048971997 +0900
-Modify: 2019-11-25 13:52:25.553805765 +0900
-Change: 2019-11-25 13:52:25.553805765 +0900
- Birth: -
+a file as reported by stat() and fstat() indicates the size of the file zone::
+
+    # stat /mnt/seq/0
+    File: /mnt/seq/0
+    Size: 0            Blocks: 524288     IO Block: 4096   regular empty file
+    Device: 870h/2160d Inode: 50431       Links: 1
+    Access: (0640/-rw-r-----)  Uid: (    0/    root)   Gid: (    0/    root)
+    Access: 2019-11-25 13:23:57.048971997 +0900
+    Modify: 2019-11-25 13:52:25.553805765 +0900
+    Change: 2019-11-25 13:52:25.553805765 +0900
   Birth: -
 
 The number of blocks of the file ("Blocks") in units of 512B blocks gives the
 maximum file size of 524288 * 512 B = 256 MB, corresponding to the device zone
index e539c42..cc74e24 100644 (file)
@@ -207,10 +207,10 @@ DPIO
 CSR firmware support for DMC
 ----------------------------
 
-.. kernel-doc:: drivers/gpu/drm/i915/intel_csr.c
+.. kernel-doc:: drivers/gpu/drm/i915/display/intel_csr.c
    :doc: csr support for dmc
 
-.. kernel-doc:: drivers/gpu/drm/i915/intel_csr.c
+.. kernel-doc:: drivers/gpu/drm/i915/display/intel_csr.c
    :internal:
 
 Video BIOS Table (VBT)
index e99d0bd..6fdad61 100644 (file)
@@ -131,7 +131,6 @@ needed).
    usb/index
    PCI/index
    misc-devices/index
-   mic/index
    scheduler/index
 
 Architecture-agnostic documentation
similarity index 98%
rename from Documentation/core-api/gcc-plugins.rst
rename to Documentation/kbuild/gcc-plugins.rst
index 8502f24..4b1c10f 100644 (file)
@@ -72,6 +72,10 @@ e.g., on Ubuntu for gcc-4.9::
 
        apt-get install gcc-4.9-plugin-dev
 
+Or on Fedora::
+
+       dnf install gcc-plugin-devel
+
 Enable a GCC plugin based feature in the kernel config::
 
        CONFIG_GCC_PLUGIN_CYC_COMPLEXITY = y
index 0f144fa..82daf2e 100644 (file)
@@ -19,6 +19,7 @@ Kernel Build System
 
     issues
     reproducible-builds
+    gcc-plugins
 
 .. only::  subproject and html
 
index d62aacb..eed2136 100644 (file)
@@ -601,7 +601,7 @@ Defined in ``include/linux/export.h``
 
 This is the variant of `EXPORT_SYMBOL()` that allows specifying a symbol
 namespace. Symbol Namespaces are documented in
-``Documentation/core-api/symbol-namespaces.rst``.
+:doc:`../core-api/symbol-namespaces`
 
 :c:func:`EXPORT_SYMBOL_NS_GPL()`
 --------------------------------
@@ -610,7 +610,7 @@ Defined in ``include/linux/export.h``
 
 This is the variant of `EXPORT_SYMBOL_GPL()` that allows specifying a symbol
 namespace. Symbol Namespaces are documented in
-``Documentation/core-api/symbol-namespaces.rst``.
+:doc:`../core-api/symbol-namespaces`
 
 Routines and Conventions
 ========================
index a8518ac..6ed806e 100644 (file)
@@ -150,17 +150,17 @@ Locking Only In User Context
 If you have a data structure which is only ever accessed from user
 context, then you can use a simple mutex (``include/linux/mutex.h``) to
 protect it. This is the most trivial case: you initialize the mutex.
-Then you can call :c:func:`mutex_lock_interruptible()` to grab the
-mutex, and :c:func:`mutex_unlock()` to release it. There is also a
-:c:func:`mutex_lock()`, which should be avoided, because it will
+Then you can call mutex_lock_interruptible() to grab the
+mutex, and mutex_unlock() to release it. There is also a
+mutex_lock(), which should be avoided, because it will
 not return if a signal is received.
 
 Example: ``net/netfilter/nf_sockopt.c`` allows registration of new
-:c:func:`setsockopt()` and :c:func:`getsockopt()` calls, with
-:c:func:`nf_register_sockopt()`. Registration and de-registration
+setsockopt() and getsockopt() calls, with
+nf_register_sockopt(). Registration and de-registration
 are only done on module load and unload (and boot time, where there is
 no concurrency), and the list of registrations is only consulted for an
-unknown :c:func:`setsockopt()` or :c:func:`getsockopt()` system
+unknown setsockopt() or getsockopt() system
 call. The ``nf_sockopt_mutex`` is perfect to protect this, especially
 since the setsockopt and getsockopt calls may well sleep.
 
@@ -170,19 +170,19 @@ Locking Between User Context and Softirqs
 If a softirq shares data with user context, you have two problems.
 Firstly, the current user context can be interrupted by a softirq, and
 secondly, the critical region could be entered from another CPU. This is
-where :c:func:`spin_lock_bh()` (``include/linux/spinlock.h``) is
+where spin_lock_bh() (``include/linux/spinlock.h``) is
 used. It disables softirqs on that CPU, then grabs the lock.
-:c:func:`spin_unlock_bh()` does the reverse. (The '_bh' suffix is
+spin_unlock_bh() does the reverse. (The '_bh' suffix is
 a historical reference to "Bottom Halves", the old name for software
 interrupts. It should really be called spin_lock_softirq()' in a
 perfect world).
 
-Note that you can also use :c:func:`spin_lock_irq()` or
-:c:func:`spin_lock_irqsave()` here, which stop hardware interrupts
+Note that you can also use spin_lock_irq() or
+spin_lock_irqsave() here, which stop hardware interrupts
 as well: see `Hard IRQ Context <#hard-irq-context>`__.
 
 This works perfectly for UP as well: the spin lock vanishes, and this
-macro simply becomes :c:func:`local_bh_disable()`
+macro simply becomes local_bh_disable()
 (``include/linux/interrupt.h``), which protects you from the softirq
 being run.
 
@@ -216,8 +216,8 @@ Different Tasklets/Timers
 ~~~~~~~~~~~~~~~~~~~~~~~~~
 
 If another tasklet/timer wants to share data with your tasklet or timer
-, you will both need to use :c:func:`spin_lock()` and
-:c:func:`spin_unlock()` calls. :c:func:`spin_lock_bh()` is
+, you will both need to use spin_lock() and
+spin_unlock() calls. spin_lock_bh() is
 unnecessary here, as you are already in a tasklet, and none will be run
 on the same CPU.
 
@@ -234,14 +234,14 @@ The same softirq can run on the other CPUs: you can use a per-CPU array
 going so far as to use a softirq, you probably care about scalable
 performance enough to justify the extra complexity.
 
-You'll need to use :c:func:`spin_lock()` and
-:c:func:`spin_unlock()` for shared data.
+You'll need to use spin_lock() and
+spin_unlock() for shared data.
 
 Different Softirqs
 ~~~~~~~~~~~~~~~~~~
 
-You'll need to use :c:func:`spin_lock()` and
-:c:func:`spin_unlock()` for shared data, whether it be a timer,
+You'll need to use spin_lock() and
+spin_unlock() for shared data, whether it be a timer,
 tasklet, different softirq or the same or another softirq: any of them
 could be running on a different CPU.
 
@@ -259,38 +259,38 @@ If a hardware irq handler shares data with a softirq, you have two
 concerns. Firstly, the softirq processing can be interrupted by a
 hardware interrupt, and secondly, the critical region could be entered
 by a hardware interrupt on another CPU. This is where
-:c:func:`spin_lock_irq()` is used. It is defined to disable
+spin_lock_irq() is used. It is defined to disable
 interrupts on that cpu, then grab the lock.
-:c:func:`spin_unlock_irq()` does the reverse.
+spin_unlock_irq() does the reverse.
 
-The irq handler does not to use :c:func:`spin_lock_irq()`, because
+The irq handler does not need to use spin_lock_irq(), because
 the softirq cannot run while the irq handler is running: it can use
-:c:func:`spin_lock()`, which is slightly faster. The only exception
+spin_lock(), which is slightly faster. The only exception
 would be if a different hardware irq handler uses the same lock:
-:c:func:`spin_lock_irq()` will stop that from interrupting us.
+spin_lock_irq() will stop that from interrupting us.
 
 This works perfectly for UP as well: the spin lock vanishes, and this
-macro simply becomes :c:func:`local_irq_disable()`
+macro simply becomes local_irq_disable()
 (``include/asm/smp.h``), which protects you from the softirq/tasklet/BH
 being run.
 
-:c:func:`spin_lock_irqsave()` (``include/linux/spinlock.h``) is a
+spin_lock_irqsave() (``include/linux/spinlock.h``) is a
 variant which saves whether interrupts were on or off in a flags word,
-which is passed to :c:func:`spin_unlock_irqrestore()`. This means
+which is passed to spin_unlock_irqrestore(). This means
 that the same code can be used inside an hard irq handler (where
 interrupts are already off) and in softirqs (where the irq disabling is
 required).
 
 Note that softirqs (and hence tasklets and timers) are run on return
-from hardware interrupts, so :c:func:`spin_lock_irq()` also stops
-these. In that sense, :c:func:`spin_lock_irqsave()` is the most
+from hardware interrupts, so spin_lock_irq() also stops
+these. In that sense, spin_lock_irqsave() is the most
 general and powerful locking function.
 
 Locking Between Two Hard IRQ Handlers
 -------------------------------------
 
 It is rare to have to share data between two IRQ handlers, but if you
-do, :c:func:`spin_lock_irqsave()` should be used: it is
+do, spin_lock_irqsave() should be used: it is
 architecture-specific whether all interrupts are disabled inside irq
 handlers themselves.
 
@@ -304,11 +304,11 @@ Pete Zaitcev gives the following summary:
    (``copy_from_user*(`` or ``kmalloc(x,GFP_KERNEL)``).
 
 -  Otherwise (== data can be touched in an interrupt), use
-   :c:func:`spin_lock_irqsave()` and
-   :c:func:`spin_unlock_irqrestore()`.
+   spin_lock_irqsave() and
+   spin_unlock_irqrestore().
 
 -  Avoid holding spinlock for more than 5 lines of code and across any
-   function call (except accessors like :c:func:`readb()`).
+   function call (except accessors like readb()).
 
 Table of Minimum Requirements
 -----------------------------
@@ -320,7 +320,7 @@ particular thread can only run on one CPU at a time, but if it needs
 shares data with another thread, locking is required).
 
 Remember the advice above: you can always use
-:c:func:`spin_lock_irqsave()`, which is a superset of all other
+spin_lock_irqsave(), which is a superset of all other
 spinlock primitives.
 
 ============== ============= ============= ========= ========= ========= ========= ======= ======= ============== ==============
@@ -363,13 +363,13 @@ They can be used if you need no access to the data protected with the
 lock when some other thread is holding the lock. You should acquire the
 lock later if you then need access to the data protected with the lock.
 
-:c:func:`spin_trylock()` does not spin but returns non-zero if it
+spin_trylock() does not spin but returns non-zero if it
 acquires the spinlock on the first try or 0 if not. This function can be
-used in all contexts like :c:func:`spin_lock()`: you must have
+used in all contexts like spin_lock(): you must have
 disabled the contexts that might interrupt you and acquire the spin
 lock.
 
-:c:func:`mutex_trylock()` does not suspend your task but returns
+mutex_trylock() does not suspend your task but returns
 non-zero if it could lock the mutex on the first try or 0 if not. This
 function cannot be safely used in hardware or software interrupt
 contexts despite not sleeping.
@@ -490,14 +490,14 @@ easy, since we copy the data for the user, and never let them access the
 objects directly.
 
 There is a slight (and common) optimization here: in
-:c:func:`cache_add()` we set up the fields of the object before
+cache_add() we set up the fields of the object before
 grabbing the lock. This is safe, as no-one else can access it until we
 put it in cache.
 
 Accessing From Interrupt Context
 --------------------------------
 
-Now consider the case where :c:func:`cache_find()` can be called
+Now consider the case where cache_find() can be called
 from interrupt context: either a hardware interrupt or a softirq. An
 example would be a timer which deletes object from the cache.
 
@@ -566,16 +566,16 @@ which are taken away, and the ``+`` are lines which are added.
              return ret;
      }
 
-Note that the :c:func:`spin_lock_irqsave()` will turn off
+Note that the spin_lock_irqsave() will turn off
 interrupts if they are on, otherwise does nothing (if we are already in
 an interrupt handler), hence these functions are safe to call from any
 context.
 
-Unfortunately, :c:func:`cache_add()` calls :c:func:`kmalloc()`
+Unfortunately, cache_add() calls kmalloc()
 with the ``GFP_KERNEL`` flag, which is only legal in user context. I
-have assumed that :c:func:`cache_add()` is still only called in
+have assumed that cache_add() is still only called in
 user context, otherwise this should become a parameter to
-:c:func:`cache_add()`.
+cache_add().
 
 Exposing Objects Outside This File
 ----------------------------------
@@ -592,7 +592,7 @@ This makes locking trickier, as it is no longer all in one place.
 The second problem is the lifetime problem: if another structure keeps a
 pointer to an object, it presumably expects that pointer to remain
 valid. Unfortunately, this is only guaranteed while you hold the lock,
-otherwise someone might call :c:func:`cache_delete()` and even
+otherwise someone might call cache_delete() and even
 worse, add another object, re-using the same address.
 
 As there is only one lock, you can't hold it forever: no-one else would
@@ -693,8 +693,8 @@ Here is the code::
 
 We encapsulate the reference counting in the standard 'get' and 'put'
 functions. Now we can return the object itself from
-:c:func:`cache_find()` which has the advantage that the user can
-now sleep holding the object (eg. to :c:func:`copy_to_user()` to
+cache_find() which has the advantage that the user can
+now sleep holding the object (eg. to copy_to_user() to
 name to userspace).
 
 The other point to note is that I said a reference should be held for
@@ -710,7 +710,7 @@ number of atomic operations defined in ``include/asm/atomic.h``: these
 are guaranteed to be seen atomically from all CPUs in the system, so no
 lock is required. In this case, it is simpler than using spinlocks,
 although for anything non-trivial using spinlocks is clearer. The
-:c:func:`atomic_inc()` and :c:func:`atomic_dec_and_test()`
+atomic_inc() and atomic_dec_and_test()
 are used instead of the standard increment and decrement operators, and
 the lock is no longer used to protect the reference count itself.
 
@@ -802,7 +802,7 @@ name to change, there are three possibilities:
 -  You can make ``cache_lock`` non-static, and tell people to grab that
    lock before changing the name in any object.
 
--  You can provide a :c:func:`cache_obj_rename()` which grabs this
+-  You can provide a cache_obj_rename() which grabs this
    lock and changes the name for the caller, and tell everyone to use
    that function.
 
@@ -861,11 +861,11 @@ Note that I decide that the popularity count should be protected by the
 ``cache_lock`` rather than the per-object lock: this is because it (like
 the :c:type:`struct list_head <list_head>` inside the object)
 is logically part of the infrastructure. This way, I don't need to grab
-the lock of every object in :c:func:`__cache_add()` when seeking
+the lock of every object in __cache_add() when seeking
 the least popular.
 
 I also decided that the id member is unchangeable, so I don't need to
-grab each object lock in :c:func:`__cache_find()` to examine the
+grab each object lock in __cache_find() to examine the
 id: the object lock is only used by a caller who wants to read or write
 the name field.
 
@@ -887,7 +887,7 @@ trivial to diagnose: not a
 stay-up-five-nights-talk-to-fluffy-code-bunnies kind of problem.
 
 For a slightly more complex case, imagine you have a region shared by a
-softirq and user context. If you use a :c:func:`spin_lock()` call
+softirq and user context. If you use a spin_lock() call
 to protect it, it is possible that the user context will be interrupted
 by the softirq while it holds the lock, and the softirq will then spin
 forever trying to get the same lock.
@@ -985,12 +985,12 @@ you might do the following::
 
 
 Sooner or later, this will crash on SMP, because a timer can have just
-gone off before the :c:func:`spin_lock_bh()`, and it will only get
-the lock after we :c:func:`spin_unlock_bh()`, and then try to free
+gone off before the spin_lock_bh(), and it will only get
+the lock after we spin_unlock_bh(), and then try to free
 the element (which has already been freed!).
 
 This can be avoided by checking the result of
-:c:func:`del_timer()`: if it returns 1, the timer has been deleted.
+del_timer(): if it returns 1, the timer has been deleted.
 If 0, it means (in this case) that it is currently running, so we can
 do::
 
@@ -1012,9 +1012,9 @@ do::
 
 
 Another common problem is deleting timers which restart themselves (by
-calling :c:func:`add_timer()` at the end of their timer function).
+calling add_timer() at the end of their timer function).
 Because this is a fairly common case which is prone to races, you should
-use :c:func:`del_timer_sync()` (``include/linux/timer.h``) to
+use del_timer_sync() (``include/linux/timer.h``) to
 handle this case. It returns the number of times the timer had to be
 deleted before we finally stopped it from adding itself back in.
 
@@ -1086,7 +1086,7 @@ adding ``new`` to a single linked list called ``list``::
             list->next = new;
 
 
-The :c:func:`wmb()` is a write memory barrier. It ensures that the
+The wmb() is a write memory barrier. It ensures that the
 first operation (setting the new element's ``next`` pointer) is complete
 and will be seen by all CPUs, before the second operation is (putting
 the new element into the list). This is important, since modern
@@ -1097,7 +1097,7 @@ rest of the list.
 
 Fortunately, there is a function to do this for standard
 :c:type:`struct list_head <list_head>` lists:
-:c:func:`list_add_rcu()` (``include/linux/list.h``).
+list_add_rcu() (``include/linux/list.h``).
 
 Removing an element from the list is even simpler: we replace the
 pointer to the old element with a pointer to its successor, and readers
@@ -1108,7 +1108,7 @@ will either see it, or skip over it.
             list->next = old->next;
 
 
-There is :c:func:`list_del_rcu()` (``include/linux/list.h``) which
+There is list_del_rcu() (``include/linux/list.h``) which
 does this (the normal version poisons the old object, which we don't
 want).
 
@@ -1116,9 +1116,9 @@ The reader must also be careful: some CPUs can look through the ``next``
 pointer to start reading the contents of the next element early, but
 don't realize that the pre-fetched contents is wrong when the ``next``
 pointer changes underneath them. Once again, there is a
-:c:func:`list_for_each_entry_rcu()` (``include/linux/list.h``)
+list_for_each_entry_rcu() (``include/linux/list.h``)
 to help you. Of course, writers can just use
-:c:func:`list_for_each_entry()`, since there cannot be two
+list_for_each_entry(), since there cannot be two
 simultaneous writers.
 
 Our final dilemma is this: when can we actually destroy the removed
@@ -1127,14 +1127,14 @@ the list right now: if we free this element and the ``next`` pointer
 changes, the reader will jump off into garbage and crash. We need to
 wait until we know that all the readers who were traversing the list
 when we deleted the element are finished. We use
-:c:func:`call_rcu()` to register a callback which will actually
+call_rcu() to register a callback which will actually
 destroy the object once all pre-existing readers are finished.
-Alternatively, :c:func:`synchronize_rcu()` may be used to block
+Alternatively, synchronize_rcu() may be used to block
 until all pre-existing are finished.
 
 But how does Read Copy Update know when the readers are finished? The
 method is this: firstly, the readers always traverse the list inside
-:c:func:`rcu_read_lock()`/:c:func:`rcu_read_unlock()` pairs:
+rcu_read_lock()/rcu_read_unlock() pairs:
 these simply disable preemption so the reader won't go to sleep while
 reading the list.
 
@@ -1223,12 +1223,12 @@ this is the fundamental idea.
      }
 
 Note that the reader will alter the popularity member in
-:c:func:`__cache_find()`, and now it doesn't hold a lock. One
+__cache_find(), and now it doesn't hold a lock. One
 solution would be to make it an ``atomic_t``, but for this usage, we
 don't really care about races: an approximate result is good enough, so
 I didn't change it.
 
-The result is that :c:func:`cache_find()` requires no
+The result is that cache_find() requires no
 synchronization with any other functions, so is almost as fast on SMP as
 it would be on UP.
 
@@ -1240,9 +1240,9 @@ and put the reference count.
 
 Now, because the 'read lock' in RCU is simply disabling preemption, a
 caller which always has preemption disabled between calling
-:c:func:`cache_find()` and :c:func:`object_put()` does not
+cache_find() and object_put() does not
 need to actually get and put the reference count: we could expose
-:c:func:`__cache_find()` by making it non-static, and such
+__cache_find() by making it non-static, and such
 callers could simply call that.
 
 The benefit here is that the reference count is not written to: the
@@ -1260,11 +1260,11 @@ counter. Nice and simple.
 If that was too slow (it's usually not, but if you've got a really big
 machine to test on and can show that it is), you could instead use a
 counter for each CPU, then none of them need an exclusive lock. See
-:c:func:`DEFINE_PER_CPU()`, :c:func:`get_cpu_var()` and
-:c:func:`put_cpu_var()` (``include/linux/percpu.h``).
+DEFINE_PER_CPU(), get_cpu_var() and
+put_cpu_var() (``include/linux/percpu.h``).
 
 Of particular use for simple per-cpu counters is the ``local_t`` type,
-and the :c:func:`cpu_local_inc()` and related functions, which are
+and the cpu_local_inc() and related functions, which are
 more efficient than simple code on some architectures
 (``include/asm/local.h``).
 
@@ -1289,10 +1289,10 @@ irq handler doesn't use a lock, and all other accesses are done as so::
         enable_irq(irq);
         spin_unlock(&lock);
 
-The :c:func:`disable_irq()` prevents the irq handler from running
+The disable_irq() prevents the irq handler from running
 (and waits for it to finish if it's currently running on other CPUs).
 The spinlock prevents any other accesses happening at the same time.
-Naturally, this is slower than just a :c:func:`spin_lock_irq()`
+Naturally, this is slower than just a spin_lock_irq()
 call, so it only makes sense if this type of access happens extremely
 rarely.
 
@@ -1315,22 +1315,22 @@ from user context, and can sleep.
 
 -  Accesses to userspace:
 
-   -  :c:func:`copy_from_user()`
+   -  copy_from_user()
 
-   -  :c:func:`copy_to_user()`
+   -  copy_to_user()
 
-   -  :c:func:`get_user()`
+   -  get_user()
 
-   -  :c:func:`put_user()`
+   -  put_user()
 
--  :c:func:`kmalloc(GFP_KERNEL) <kmalloc>`
+-  kmalloc(GP_KERNEL) <kmalloc>`
 
--  :c:func:`mutex_lock_interruptible()` and
-   :c:func:`mutex_lock()`
+-  mutex_lock_interruptible() and
+   mutex_lock()
 
-   There is a :c:func:`mutex_trylock()` which does not sleep.
+   There is a mutex_trylock() which does not sleep.
    Still, it must not be used inside interrupt context since its
-   implementation is not safe for that. :c:func:`mutex_unlock()`
+   implementation is not safe for that. mutex_unlock()
    will also never sleep. It cannot be used in interrupt context either
    since a mutex must be released by the same task that acquired it.
 
@@ -1340,11 +1340,11 @@ Some Functions Which Don't Sleep
 Some functions are safe to call from any context, or holding almost any
 lock.
 
--  :c:func:`printk()`
+-  printk()
 
--  :c:func:`kfree()`
+-  kfree()
 
--  :c:func:`add_timer()` and :c:func:`del_timer()`
+-  add_timer() and del_timer()
 
 Mutex API reference
 ===================
@@ -1400,26 +1400,26 @@ preemption
 
 bh
   Bottom Half: for historical reasons, functions with '_bh' in them often
-  now refer to any software interrupt, e.g. :c:func:`spin_lock_bh()`
+  now refer to any software interrupt, e.g. spin_lock_bh()
   blocks any software interrupt on the current CPU. Bottom halves are
   deprecated, and will eventually be replaced by tasklets. Only one bottom
   half will be running at any time.
 
 Hardware Interrupt / Hardware IRQ
-  Hardware interrupt request. :c:func:`in_irq()` returns true in a
+  Hardware interrupt request. in_irq() returns true in a
   hardware interrupt handler.
 
 Interrupt Context
   Not user context: processing a hardware irq or software irq. Indicated
-  by the :c:func:`in_interrupt()` macro returning true.
+  by the in_interrupt() macro returning true.
 
 SMP
   Symmetric Multi-Processor: kernels compiled for multiple-CPU machines.
   (``CONFIG_SMP=y``).
 
 Software Interrupt / softirq
-  Software interrupt handler. :c:func:`in_irq()` returns false;
-  :c:func:`in_softirq()` returns true. Tasklets and softirqs both
+  Software interrupt handler. in_irq() returns false;
+  in_softirq() returns true. Tasklets and softirqs both
   fall into the category of 'software interrupts'.
 
   Strictly speaking a softirq is one of up to 32 enumerated software
index 3af3841..c61eea6 100644 (file)
@@ -128,6 +128,10 @@ since we already have a valid pointer that we own a refcount for.  The
 put needs no lock because nothing tries to get the data without
 already holding a pointer.
 
+In the above example, kref_put() will be called 2 times in both success
+and error paths. This is necessary because the reference count got
+incremented 2 times by kref_init() and kref_get().
+
 Note that the "before" in rule 1 is very important.  You should never
 do something like::
 
index b20800c..5129019 100644 (file)
@@ -291,8 +291,8 @@ and QUERYMENU. And G/S_CTRL as well as G/TRY/S_EXT_CTRLS are automatically suppo
    In practice the basic usage as described above is sufficient for most drivers.
 
 
-Inheriting Controls
--------------------
+Inheriting Sub-device Controls
+------------------------------
 
 When a sub-device is registered with a V4L2 driver by calling
 v4l2_device_register_subdev() and the ctrl_handler fields of both v4l2_subdev
@@ -757,8 +757,8 @@ attempting to find another control from the same handler will deadlock.
 It is recommended not to use this function from inside the control ops.
 
 
-Inheriting Controls
--------------------
+Preventing Controls inheritance
+-------------------------------
 
 When one control handler is added to another using v4l2_ctrl_add_handler, then
 by default all controls from one are merged to the other. But a subdev might
index f11c5da..c1dcd26 100644 (file)
@@ -20,4 +20,5 @@ fit into other categories.
    isl29003
    lis3lv02d
    max6875
+   mic/index
    xilinx_sdfec
index 38a4edc..10e1109 100644 (file)
@@ -908,8 +908,8 @@ A TLP probe packet is sent.
 
 A packet loss is detected and recovered by TLP.
 
-TCP Fast Open
-=============
+TCP Fast Open description
+=========================
 TCP Fast Open is a technology which allows data transfer before the
 3-way handshake complete. Please refer the `TCP Fast Open wiki`_ for a
 general description.
index 363736d..df136c8 100644 (file)
@@ -8,8 +8,8 @@ Protected Execution Facility
 .. contents::
     :depth: 3
 
-Protected Execution Facility
-############################
+Introduction
+############
 
     Protected Execution Facility (PEF) is an architectural change for
     POWER 9 that enables Secure Virtual Machines (SVMs). DD2.3 chips
index ae020d8..b21b5b2 100644 (file)
@@ -18,18 +18,18 @@ major kernel release happening every two or three months.  The recent
 release history looks like this:
 
        ======  =================
-       4.11    April 30, 2017
-       4.12    July 2, 2017
-       4.13    September 3, 2017
-       4.14    November 12, 2017
-       4.15    January 28, 2018
-       4.16    April 1, 2018
+       5.0     March 3, 2019
+       5.1     May 5, 2019
+       5.2     July 7, 2019
+       5.3     September 15, 2019
+       5.4     November 24, 2019
+       5.5     January 6, 2020
        ======  =================
 
-Every 4.x release is a major kernel release with new features, internal
-API changes, and more.  A typical 4.x release contain about 13,000
-changesets with changes to several hundred thousand lines of code.  4.x is
-thus the leading edge of Linux kernel development; the kernel uses a
+Every 5.x release is a major kernel release with new features, internal
+API changes, and more.  A typical release can contain about 13,000
+changesets with changes to several hundred thousand lines of code.  5.x is
+the leading edge of Linux kernel development; the kernel uses a
 rolling development model which is continually integrating major changes.
 
 A relatively straightforward discipline is followed with regard to the
@@ -48,9 +48,9 @@ detail later on).
 
 The merge window lasts for approximately two weeks.  At the end of this
 time, Linus Torvalds will declare that the window is closed and release the
-first of the "rc" kernels.  For the kernel which is destined to be 2.6.40,
+first of the "rc" kernels.  For the kernel which is destined to be 5.6,
 for example, the release which happens at the end of the merge window will
-be called 2.6.40-rc1.  The -rc1 release is the signal that the time to
+be called 5.6-rc1.  The -rc1 release is the signal that the time to
 merge new features has passed, and that the time to stabilize the next
 kernel has begun.
 
@@ -67,22 +67,23 @@ add at any time).
 As fixes make their way into the mainline, the patch rate will slow over
 time.  Linus releases new -rc kernels about once a week; a normal series
 will get up to somewhere between -rc6 and -rc9 before the kernel is
-considered to be sufficiently stable and the final 2.6.x release is made.
+considered to be sufficiently stable and the final release is made.
 At that point the whole process starts over again.
 
-As an example, here is how the 4.16 development cycle went (all dates in
-2018):
+As an example, here is how the 5.4 development cycle went (all dates in
+2019):
 
        ==============  ===============================
-       January 28      4.15 stable release
-       February 11     4.16-rc1, merge window closes
-       February 18     4.16-rc2
-       February 25     4.16-rc3
-       March 4         4.16-rc4
-       March 11        4.16-rc5
-       March 18        4.16-rc6
-       March 25        4.16-rc7
-       April 1         4.16 stable release
+       September 15    5.3 stable release
+       September 30    5.4-rc1, merge window closes
+       October 6       5.4-rc2
+       October 13      5.4-rc3
+       October 20      5.4-rc4
+       October 27      5.4-rc5
+       November 3      5.4-rc6
+       November 10     5.4-rc7
+       November 17     5.4-rc8
+       November 24     5.4 stable release
        ==============  ===============================
 
 How do the developers decide when to close the development cycle and create
@@ -98,43 +99,44 @@ release is made.  In the real world, this kind of perfection is hard to
 achieve; there are just too many variables in a project of this size.
 There comes a point where delaying the final release just makes the problem
 worse; the pile of changes waiting for the next merge window will grow
-larger, creating even more regressions the next time around.  So most 4.x
+larger, creating even more regressions the next time around.  So most 5.x
 kernels go out with a handful of known regressions though, hopefully, none
 of them are serious.
 
 Once a stable release is made, its ongoing maintenance is passed off to the
-"stable team," currently consisting of Greg Kroah-Hartman.  The stable team
-will release occasional updates to the stable release using the 4.x.y
-numbering scheme.  To be considered for an update release, a patch must (1)
-fix a significant bug, and (2) already be merged into the mainline for the
-next development kernel.  Kernels will typically receive stable updates for
-a little more than one development cycle past their initial release.  So,
-for example, the 4.13 kernel's history looked like:
+"stable team," currently Greg Kroah-Hartman. The stable team will release
+occasional updates to the stable release using the 5.x.y numbering scheme.
+To be considered for an update release, a patch must (1) fix a significant
+bug, and (2) already be merged into the mainline for the next development
+kernel. Kernels will typically receive stable updates for a little more
+than one development cycle past their initial release. So, for example, the
+5.2 kernel's history looked like this (all dates in 2019):
 
        ==============  ===============================
-       September 3     4.13 stable release
-       September 13    4.13.1
-       September 20    4.13.2
-       September 27    4.13.3
-       October 5       4.13.4
-       October 12      4.13.5
+       September 15    5.2 stable release
+       July 14         5.2.1
+       July 21         5.2.2
+       July 26         5.2.3
+       July 28         5.2.4
+       July 31         5.2.5
        ...             ...
-       November 24     4.13.16
+       October 11      5.2.21
        ==============  ===============================
 
-4.13.16 was the final stable update of the 4.13 release.
+5.2.21 was the final stable update of the 5.2 release.
 
 Some kernels are designated "long term" kernels; they will receive support
 for a longer period.  As of this writing, the current long term kernels
 and their maintainers are:
 
-       ======  ======================  ==============================
-       3.16    Ben Hutchings           (very long-term stable kernel)
-       4.1     Sasha Levin
-       4.4     Greg Kroah-Hartman      (very long-term stable kernel)
-       4.9     Greg Kroah-Hartman
-       4.14    Greg Kroah-Hartman
-       ======  ======================  ==============================
+       ======  ================================        =======================
+       3.16    Ben Hutchings                           (very long-term kernel)
+       4.4     Greg Kroah-Hartman & Sasha Levin        (very long-term kernel)
+       4.9     Greg Kroah-Hartman & Sasha Levin
+       4.14    Greg Kroah-Hartman & Sasha Levin
+       4.19    Greg Kroah-Hartman & Sasha Levin
+       5.4     Greg Kroah-Hartman & Sasha Levin
+       ======  ================================        =======================
 
 The selection of a kernel for long-term support is purely a matter of a
 maintainer having the need and the time to maintain that release.  There
@@ -215,12 +217,12 @@ How patches get into the Kernel
 -------------------------------
 
 There is exactly one person who can merge patches into the mainline kernel
-repository: Linus Torvalds.  But, of the over 9,500 patches which went
-into the 2.6.38 kernel, only 112 (around 1.3%) were directly chosen by Linus
-himself.  The kernel project has long since grown to a size where no single
-developer could possibly inspect and select every patch unassisted.  The
-way the kernel developers have addressed this growth is through the use of
-a lieutenant system built around a chain of trust.
+repository: Linus Torvalds. But, for example, of the over 9,500 patches
+which went into the 2.6.38 kernel, only 112 (around 1.3%) were directly
+chosen by Linus himself. The kernel project has long since grown to a size
+where no single developer could possibly inspect and select every patch
+unassisted. The way the kernel developers have addressed this growth is
+through the use of a lieutenant system built around a chain of trust.
 
 The kernel code base is logically broken down into a set of subsystems:
 networking, specific architecture support, memory management, video
index edb296c..acb2f1b 100644 (file)
@@ -284,9 +284,9 @@ context lines.
 4) Naming
 ---------
 
-C is a Spartan language, and so should your naming be.  Unlike Modula-2
-and Pascal programmers, C programmers do not use cute names like
-ThisVariableIsATemporaryCounter.  A C programmer would call that
+C is a Spartan language, and your naming conventions should follow suit.
+Unlike Modula-2 and Pascal programmers, C programmers do not use cute
+names like ThisVariableIsATemporaryCounter. A C programmer would call that
 variable ``tmp``, which is much easier to write, and not the least more
 difficult to understand.
 
@@ -300,9 +300,9 @@ that counts the number of active users, you should call that
 ``count_active_users()`` or similar, you should **not** call it ``cntusr()``.
 
 Encoding the type of a function into the name (so-called Hungarian
-notation) is brain damaged - the compiler knows the types anyway and can
-check those, and it only confuses the programmer.  No wonder MicroSoft
-makes buggy programs.
+notation) is asinine - the compiler knows the types anyway and can check
+those, and it only confuses the programmer. No wonder Microsoft makes buggy
+programs.
 
 LOCAL variable names should be short, and to the point.  If you have
 some random integer loop counter, it should probably be called ``i``.
@@ -806,9 +806,9 @@ covers RTL which is used frequently with assembly language in the kernel.
 ----------------------------
 
 Kernel developers like to be seen as literate. Do mind the spelling
-of kernel messages to make a good impression. Do not use crippled
-words like ``dont``; use ``do not`` or ``don't`` instead.  Make the messages
-concise, clear, and unambiguous.
+of kernel messages to make a good impression. Do not use incorrect
+contractions like ``dont``; use ``do not`` or ``don't`` instead. Make the
+messages concise, clear, and unambiguous.
 
 Kernel messages do not have to be terminated with a period.
 
index 179f2a5..652e2aa 100644 (file)
@@ -29,6 +29,28 @@ a header file, it isn't the full solution. Such interfaces must either
 be fully removed from the kernel, or added to this file to discourage
 others from using them in the future.
 
+BUG() and BUG_ON()
+------------------
+Use WARN() and WARN_ON() instead, and handle the "impossible"
+error condition as gracefully as possible. While the BUG()-family
+of APIs were originally designed to act as an "impossible situation"
+assert and to kill a kernel thread "safely", they turn out to just be
+too risky. (e.g. "In what order do locks need to be released? Have
+various states been restored?") Very commonly, using BUG() will
+destabilize a system or entirely break it, which makes it impossible
+to debug or even get viable crash reports. Linus has `very strong
+<https://lore.kernel.org/lkml/CA+55aFy6jNLsywVYdGp83AMrXBo_P-pkjkphPGrO=82SPKCpLQ@mail.gmail.com/>`_
+feelings `about this
+<https://lore.kernel.org/lkml/CAHk-=whDHsbK3HTOpTF=ue_o04onRwTEaK_ZoJp_fjbqq4+=Jw@mail.gmail.com/>`_.
+
+Note that the WARN()-family should only be used for "expected to
+be unreachable" situations. If you want to warn about "reachable
+but undesirable" situations, please use the pr_warn()-family of
+functions. System owners may have set the *panic_on_warn* sysctl,
+to make sure their systems do not continue running in the face of
+"unreachable" conditions. (For example, see commits like `this one
+<https://git.kernel.org/linus/d4689846881d160a4d12a514e991a740bcb5d65a>`_.)
+
 open-coded arithmetic in allocator arguments
 --------------------------------------------
 Dynamic size calculations (especially multiplication) should not be
@@ -63,51 +85,73 @@ Instead, use the helper::
 
        header = kzalloc(struct_size(header, item, count), GFP_KERNEL);
 
-See :c:func:`array_size`, :c:func:`array3_size`, and :c:func:`struct_size`,
-for more details as well as the related :c:func:`check_add_overflow` and
-:c:func:`check_mul_overflow` family of functions.
+See array_size(), array3_size(), and struct_size(),
+for more details as well as the related check_add_overflow() and
+check_mul_overflow() family of functions.
 
 simple_strtol(), simple_strtoll(), simple_strtoul(), simple_strtoull()
 ----------------------------------------------------------------------
-The :c:func:`simple_strtol`, :c:func:`simple_strtoll`,
-:c:func:`simple_strtoul`, and :c:func:`simple_strtoull` functions
+The simple_strtol(), simple_strtoll(),
+simple_strtoul(), and simple_strtoull() functions
 explicitly ignore overflows, which may lead to unexpected results
-in callers. The respective :c:func:`kstrtol`, :c:func:`kstrtoll`,
-:c:func:`kstrtoul`, and :c:func:`kstrtoull` functions tend to be the
+in callers. The respective kstrtol(), kstrtoll(),
+kstrtoul(), and kstrtoull() functions tend to be the
 correct replacements, though note that those require the string to be
 NUL or newline terminated.
 
 strcpy()
 --------
-:c:func:`strcpy` performs no bounds checking on the destination
+strcpy() performs no bounds checking on the destination
 buffer. This could result in linear overflows beyond the
 end of the buffer, leading to all kinds of misbehaviors. While
 `CONFIG_FORTIFY_SOURCE=y` and various compiler flags help reduce the
 risk of using this function, there is no good reason to add new uses of
-this function. The safe replacement is :c:func:`strscpy`.
+this function. The safe replacement is strscpy().
 
 strncpy() on NUL-terminated strings
 -----------------------------------
-Use of :c:func:`strncpy` does not guarantee that the destination buffer
+Use of strncpy() does not guarantee that the destination buffer
 will be NUL terminated. This can lead to various linear read overflows
 and other misbehavior due to the missing termination. It also NUL-pads the
 destination buffer if the source contents are shorter than the destination
 buffer size, which may be a needless performance penalty for callers using
-only NUL-terminated strings. The safe replacement is :c:func:`strscpy`.
-(Users of :c:func:`strscpy` still needing NUL-padding will need an
-explicit :c:func:`memset` added.)
+only NUL-terminated strings. The safe replacement is strscpy().
+(Users of strscpy() still needing NUL-padding should instead
+use strscpy_pad().)
 
-If a caller is using non-NUL-terminated strings, :c:func:`strncpy()` can
+If a caller is using non-NUL-terminated strings, strncpy()() can
 still be used, but destinations should be marked with the `__nonstring
 <https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html>`_
 attribute to avoid future compiler warnings.
 
 strlcpy()
 ---------
-:c:func:`strlcpy` reads the entire source buffer first, possibly exceeding
+strlcpy() reads the entire source buffer first, possibly exceeding
 the given limit of bytes to copy. This is inefficient and can lead to
 linear read overflows if a source string is not NUL-terminated. The
-safe replacement is :c:func:`strscpy`.
+safe replacement is strscpy().
+
+%p format specifier
+-------------------
+Traditionally, using "%p" in format strings would lead to regular address
+exposure flaws in dmesg, proc, sysfs, etc. Instead of leaving these to
+be exploitable, all "%p" uses in the kernel are being printed as a hashed
+value, rendering them unusable for addressing. New uses of "%p" should not
+be added to the kernel. For text addresses, using "%pS" is likely better,
+as it produces the more useful symbol name instead. For nearly everything
+else, just do not add "%p" at all.
+
+Paraphrasing Linus's current `guidance <https://lore.kernel.org/lkml/CA+55aFwQEd_d40g4mUCSsVRZzrFPUJt74vc6PPpb675hYNXcKw@mail.gmail.com/>`_:
+
+- If the hashed "%p" value is pointless, ask yourself whether the pointer
+  itself is important. Maybe it should be removed entirely?
+- If you really think the true pointer value is important, why is some
+  system state or user privilege level considered "special"? If you think
+  you can justify it (in comments and commit log) well enough to stand
+  up to Linus's scrutiny, maybe you can use "%px", along with making sure
+  you have sensible permissions.
+
+And finally, know that a toggle for "%p" hashing will `not be accepted <https://lore.kernel.org/lkml/CA+55aFwieC1-nAs+NFq9RTwaR8ef9hWa4MjNBWL41F-8wM49eA@mail.gmail.com/>`_.
 
 Variable Length Arrays (VLAs)
 -----------------------------
@@ -122,27 +166,37 @@ memory adjacent to the stack (when built without `CONFIG_VMAP_STACK=y`)
 
 Implicit switch case fall-through
 ---------------------------------
-The C language allows switch cases to "fall-through" when a "break" statement
-is missing at the end of a case. This, however, introduces ambiguity in the
-code, as it's not always clear if the missing break is intentional or a bug.
+The C language allows switch cases to fall through to the next case
+when a "break" statement is missing at the end of a case. This, however,
+introduces ambiguity in the code, as it's not always clear if the missing
+break is intentional or a bug. For example, it's not obvious just from
+looking at the code if `STATE_ONE` is intentionally designed to fall
+through into `STATE_TWO`::
+
+       switch (value) {
+       case STATE_ONE:
+               do_something();
+       case STATE_TWO:
+               do_other();
+               break;
+       default:
+               WARN("unknown state");
+       }
 
 As there have been a long list of flaws `due to missing "break" statements
 <https://cwe.mitre.org/data/definitions/484.html>`_, we no longer allow
-"implicit fall-through".
-
-In order to identify intentional fall-through cases, we have adopted a
-pseudo-keyword macro 'fallthrough' which expands to gcc's extension
-__attribute__((__fallthrough__)).  `Statement Attributes
-<https://gcc.gnu.org/onlinedocs/gcc/Statement-Attributes.html>`_
-
-When the C17/C18  [[fallthrough]] syntax is more commonly supported by
+implicit fall-through. In order to identify intentional fall-through
+cases, we have adopted a pseudo-keyword macro "fallthrough" which
+expands to gcc's extension `__attribute__((__fallthrough__))
+<https://gcc.gnu.org/onlinedocs/gcc/Statement-Attributes.html>`_.
+(When the C17/C18  `[[fallthrough]]` syntax is more commonly supported by
 C compilers, static analyzers, and IDEs, we can switch to using that syntax
-for the macro pseudo-keyword.
+for the macro pseudo-keyword.)
 
 All switch/case blocks must end in one of:
 
-       break;
-       fallthrough;
-       continue;
-       goto <label>;
-       return [expression];
+* break;
+* fallthrough;
+* continue;
+* goto <label>;
+* return [expression];
index 5273d06..c9e4ce2 100644 (file)
@@ -237,9 +237,9 @@ using Mutt to send patches through Gmail::
 
 The Mutt docs have lots more information:
 
-    http://dev.mutt.org/trac/wiki/UseCases/Gmail
+    https://gitlab.com/muttmua/mutt/-/wikis/UseCases/Gmail
 
-    http://dev.mutt.org/doc/manual.html
+    http://www.mutt.org/doc/manual/
 
 Pine (TUI)
 **********
index b6f5a37..70791e1 100644 (file)
@@ -243,10 +243,10 @@ branches.  These different branches are:
 Mainline tree
 ~~~~~~~~~~~~~
 
-Mainline tree are maintained by Linus Torvalds, and can be found at
+The mainline tree is maintained by Linus Torvalds, and can be found at
 https://kernel.org or in the repo.  Its development process is as follows:
 
-  - As soon as a new kernel is released a two weeks window is open,
+  - As soon as a new kernel is released a two week window is open,
     during this period of time maintainers can submit big diffs to
     Linus, usually the patches that have already been included in the
     linux-next for a few weeks.  The preferred way to submit big changes
@@ -281,8 +281,9 @@ Various stable trees with multiple major numbers
 
 Kernels with 3-part versions are -stable kernels. They contain
 relatively small and critical fixes for security problems or significant
-regressions discovered in a given major mainline release, with the first
-2-part of version number are the same correspondingly.
+regressions discovered in a given major mainline release. Each release
+in a major stable series increments the third part of the version
+number, keeping the first two parts the same.
 
 This is the recommended branch for users who want the most recent stable
 kernel and are not interested in helping test development/experimental
@@ -359,10 +360,10 @@ Managing bug reports
 
 One of the best ways to put into practice your hacking skills is by fixing
 bugs reported by other people. Not only you will help to make the kernel
-more stable, you'll learn to fix real world problems and you will improve
-your skills, and other developers will be aware of your presence. Fixing
-bugs is one of the best ways to get merits among other developers, because
-not many people like wasting time fixing other people's bugs.
+more stable, but you'll also learn to fix real world problems and you will
+improve your skills, and other developers will be aware of your presence.
+Fixing bugs is one of the best ways to get merits among other developers,
+because not many people like wasting time fixing other people's bugs.
 
 To work in the already reported bug reports, go to https://bugzilla.kernel.org.
 
index 7a45a8e..9d6d0ac 100644 (file)
@@ -313,7 +313,7 @@ On-line docs
       :URL: http://www.linuxjournal.com/article.php?sid=2391
       :Date: 1997
       :Keywords: RAID, MD driver.
-      :Description: Linux Journal Kernel Korner article. Here is its
+      :Description: Linux Journal Kernel Korner article.
       :Abstract: *A description of the implementation of the RAID-1,
         RAID-4 and RAID-5 personalities of the MD device driver in the
         Linux kernel, providing users with high performance and reliable,
@@ -338,7 +338,7 @@ On-line docs
       :Date: 1996
       :Keywords: device driver, module, loading/unloading modules,
         allocating resources.
-      :Description: Linux Journal Kernel Korner article. Here is its
+      :Description: Linux Journal Kernel Korner article.
       :Abstract: *This is the first of a series of four articles
         co-authored by Alessandro Rubini and Georg Zezchwitz which present
         a practical approach to writing Linux device drivers as kernel
@@ -354,7 +354,7 @@ On-line docs
       :Keywords: character driver, init_module, clean_up module,
         autodetection, mayor number, minor number, file operations,
         open(), close().
-      :Description: Linux Journal Kernel Korner article. Here is its
+      :Description: Linux Journal Kernel Korner article.
       :Abstract: *This article, the second of four, introduces part of
         the actual code to create custom module implementing a character
         device driver. It describes the code for module initialization and
@@ -367,7 +367,7 @@ On-line docs
       :Date: 1996
       :Keywords: read(), write(), select(), ioctl(), blocking/non
         blocking mode, interrupt handler.
-      :Description: Linux Journal Kernel Korner article. Here is its
+      :Description: Linux Journal Kernel Korner article.
       :Abstract: *This article, the third of four on writing character
         device drivers, introduces concepts of reading, writing, and using
         ioctl-calls*.
@@ -378,7 +378,7 @@ On-line docs
       :URL: http://www.linuxjournal.com/article.php?sid=1222
       :Date: 1996
       :Keywords: interrupts, irqs, DMA, bottom halves, task queues.
-      :Description: Linux Journal Kernel Korner article. Here is its
+      :Description: Linux Journal Kernel Korner article.
       :Abstract: *This is the fourth in a series of articles about
         writing character device drivers as loadable kernel modules. This
         month, we further investigate the field of interrupt handling.
index 186753f..dfbc69b 100644 (file)
@@ -227,7 +227,7 @@ incompetence will grudgingly admit that you at least didn't try to weasel
 out of it.
 
 Then make the developer who really screwed up (if you can find them) know
-**in_private** that they screwed up.  Not just so they can avoid it in the
+**in private** that they screwed up.  Not just so they can avoid it in the
 future, but so that they know they owe you one.  And, perhaps even more
 importantly, they're also likely the person who can fix it.  Because, let's
 face it, it sure ain't you.
index 2a4be1c..537f047 100644 (file)
@@ -299,7 +299,6 @@ Summary:
    scsi_host_alloc - return a new scsi_host instance whose refcount==1
    scsi_host_get - increments Scsi_Host instance's refcount
    scsi_host_put - decrements Scsi_Host instance's refcount (free if 0)
-   scsi_partsize - parse partition table into cylinders, heads + sectors
    scsi_register - create and register a scsi host adapter instance.
    scsi_remove_device - detach and remove a SCSI device
    scsi_remove_host - detach and remove all SCSI devices owned by host
@@ -473,26 +472,6 @@ void scsi_host_put(struct Scsi_Host *shost)
 
 
 /**
- * scsi_partsize - parse partition table into cylinders, heads + sectors
- * @buf: pointer to partition table
- * @capacity: size of (total) disk in 512 byte sectors
- * @cyls: outputs number of cylinders calculated via this pointer
- * @hds: outputs number of heads calculated via this pointer
- * @secs: outputs number of sectors calculated via this pointer
- *
- *      Returns 0 on success, -1 on failure
- *
- *      Might block: no
- *
- *      Notes: Caller owns memory returned (free with kfree() )
- *
- *      Defined in: drivers/scsi/scsicam.c
- **/
-int scsi_partsize(unsigned char *buf, unsigned long capacity,
-                  unsigned int *cyls, unsigned int *hds, unsigned int *secs)
-
-
-/**
  * scsi_register - create and register a scsi host adapter instance.
  * @sht:        pointer to scsi host template
  * @privsize:   extra bytes to allocate in hostdata array (which is the
index 9965821..4eba68c 100644 (file)
@@ -128,8 +128,8 @@ then when you can be absolutely certain that the outputs will never be
 transmitted out of the kernel. This is only remotely useful over `jhash` as a
 means of mitigating hashtable flooding denial of service attacks.
 
-Generating a key
-================
+Generating a HalfSipHash key
+============================
 
 Keys should always be generated from a cryptographically secure source of
 random numbers, either using get_random_bytes or get_random_once:
@@ -139,8 +139,8 @@ get_random_bytes(&key, sizeof(key));
 
 If you're not deriving your key from here, you're doing it wrong.
 
-Using the functions
-===================
+Using the HalfSipHash functions
+===============================
 
 There are two variants of the function, one that takes a list of integers, and
 one that takes a buffer::
index a7b4267..e47047e 100644 (file)
@@ -5,7 +5,7 @@ TCM Userspace Design
 
 .. Contents:
 
-   1) TCM Userspace Design
+   1) Design
      a) Background
      b) Benefits
      c) Design constraints
@@ -23,8 +23,8 @@ TCM Userspace Design
    3) A final note
 
 
-TCM Userspace Design
-====================
+Design
+======
 
 TCM is another name for LIO, an in-kernel iSCSI target (server).
 Existing TCM targets run in the kernel.  TCMU (TCM in Userspace)
index ed79b22..4a2ebe0 100644 (file)
@@ -342,7 +342,8 @@ section of Documentation/trace/ftrace.rst), but there are major
 differences and the implementation isn't currently tied to it in any
 way, so beware about making generalizations between the two.
 
-Note: Writing into trace_marker (See Documentation/trace/ftrace.rst)
+.. Note::
+     Writing into trace_marker (See Documentation/trace/ftrace.rst)
      can also enable triggers that are written into
      /sys/kernel/tracing/events/ftrace/print/trigger
 
@@ -569,14 +570,14 @@ The first creates the event in one step, using synth_event_create().
 In this method, the name of the event to create and an array defining
 the fields is supplied to synth_event_create().  If successful, a
 synthetic event with that name and fields will exist following that
-call.  For example, to create a new "schedtest" synthetic event:
+call.  For example, to create a new "schedtest" synthetic event::
 
   ret = synth_event_create("schedtest", sched_fields,
                            ARRAY_SIZE(sched_fields), THIS_MODULE);
 
 The sched_fields param in this example points to an array of struct
 synth_field_desc, each of which describes an event field by type and
-name:
+name::
 
   static struct synth_field_desc sched_fields[] = {
         { .type = "pid_t",              .name = "next_pid_field" },
@@ -615,7 +616,7 @@ synth_event_gen_cmd_array_start(), the user should create and
 initialize a dynevent_cmd object using synth_event_cmd_init().
 
 For example, to create a new "schedtest" synthetic event with two
-fields:
+fields::
 
   struct dynevent_cmd cmd;
   char *buf;
@@ -631,7 +632,7 @@ fields:
                                   "u64", "ts_ns");
 
 Alternatively, using an array of struct synth_field_desc fields
-containing the same information:
+containing the same information::
 
   ret = synth_event_gen_cmd_array_start(&cmd, "schedtest", THIS_MODULE,
                                         fields, n_fields);
@@ -640,7 +641,7 @@ Once the synthetic event object has been created, it can then be
 populated with more fields.  Fields are added one by one using
 synth_event_add_field(), supplying the dynevent_cmd object, a field
 type, and a field name.  For example, to add a new int field named
-"intfield", the following call should be made:
+"intfield", the following call should be made::
 
   ret = synth_event_add_field(&cmd, "int", "intfield");
 
@@ -649,7 +650,7 @@ the field is considered to be an array.
 
 A group of fields can also be added all at once using an array of
 synth_field_desc with add_synth_fields().  For example, this would add
-just the first four sched_fields:
+just the first four sched_fields::
 
   ret = synth_event_add_fields(&cmd, sched_fields, 4);
 
@@ -658,7 +659,7 @@ synth_event_add_field_str() can be used to add it as-is; it will
 also automatically append a ';' to the string.
 
 Once all the fields have been added, the event should be finalized and
-registered by calling the synth_event_gen_cmd_end() function:
+registered by calling the synth_event_gen_cmd_end() function::
 
   ret = synth_event_gen_cmd_end(&cmd);
 
@@ -691,7 +692,7 @@ trace array)), along with an variable number of u64 args, one for each
 synthetic event field, and the number of values being passed.
 
 So, to trace an event corresponding to the synthetic event definition
-above, code like the following could be used:
+above, code like the following could be used::
 
   ret = synth_event_trace(create_synth_test, 7, /* number of values */
                           444,             /* next_pid_field */
@@ -715,7 +716,7 @@ trace array)), along with an array of u64, one for each synthetic
 event field.
 
 To trace an event corresponding to the synthetic event definition
-above, code like the following could be used:
+above, code like the following could be used::
 
   u64 vals[7];
 
@@ -739,7 +740,7 @@ In order to trace a synthetic event, a pointer to the trace event file
 is needed.  The trace_get_event_file() function can be used to get
 it - it will find the file in the given trace instance (in this case
 NULL since the top trace array is being used) while at the same time
-preventing the instance containing it from going away:
+preventing the instance containing it from going away::
 
        schedtest_event_file = trace_get_event_file(NULL, "synthetic",
                                                    "schedtest");
@@ -751,31 +752,31 @@ To enable a synthetic event from the kernel, trace_array_set_clr_event()
 can be used (which is not specific to synthetic events, so does need
 the "synthetic" system name to be specified explicitly).
 
-To enable the event, pass 'true' to it:
+To enable the event, pass 'true' to it::
 
        trace_array_set_clr_event(schedtest_event_file->tr,
                                  "synthetic", "schedtest", true);
 
-To disable it pass false:
+To disable it pass false::
 
        trace_array_set_clr_event(schedtest_event_file->tr,
                                  "synthetic", "schedtest", false);
 
 Finally, synth_event_trace_array() can be used to actually trace the
-event, which should be visible in the trace buffer afterwards:
+event, which should be visible in the trace buffer afterwards::
 
        ret = synth_event_trace_array(schedtest_event_file, vals,
                                      ARRAY_SIZE(vals));
 
 To remove the synthetic event, the event should be disabled, and the
-trace instance should be 'put' back using trace_put_event_file():
+trace instance should be 'put' back using trace_put_event_file()::
 
        trace_array_set_clr_event(schedtest_event_file->tr,
                                  "synthetic", "schedtest", false);
        trace_put_event_file(schedtest_event_file);
 
 If those have been successful, synth_event_delete() can be called to
-remove the event:
+remove the event::
 
        ret = synth_event_delete("schedtest");
 
@@ -784,7 +785,7 @@ remove the event:
 
 To trace a synthetic using the piecewise method described above, the
 synth_event_trace_start() function is used to 'open' the synthetic
-event trace:
+event trace::
 
        struct synth_trace_state trace_state;
 
@@ -809,7 +810,7 @@ along with the value to set the next field in the event.  After each
 field is set, the 'cursor' points to the next field, which will be set
 by the subsequent call, continuing until all the fields have been set
 in order.  The same sequence of calls as in the above examples using
-this method would be (without error-handling code):
+this method would be (without error-handling code)::
 
        /* next_pid_field */
        ret = synth_event_add_next_val(777, &trace_state);
@@ -837,7 +838,7 @@ used.  Each call is passed the same synth_trace_state object used in
 the synth_event_trace_start(), along with the field name of the field
 to set and the value to set it to.  The same sequence of calls as in
 the above examples using this method would be (without error-handling
-code):
+code)::
 
        ret = synth_event_add_val("next_pid_field", 777, &trace_state);
        ret = synth_event_add_val("next_comm_field", (u64)"silly putty",
@@ -855,7 +856,7 @@ can be used but not both at the same time.
 
 Finally, the event won't be actually traced until it's 'closed',
 which is done using synth_event_trace_end(), which takes only the
-struct synth_trace_state object used in the previous calls:
+struct synth_trace_state object used in the previous calls::
 
        ret = synth_event_trace_end(&trace_state);
 
@@ -878,7 +879,7 @@ function.  Before calling kprobe_event_gen_cmd_start(), the user
 should create and initialize a dynevent_cmd object using
 kprobe_event_cmd_init().
 
-For example, to create a new "schedtest" kprobe event with two fields:
+For example, to create a new "schedtest" kprobe event with two fields::
 
   struct dynevent_cmd cmd;
   char *buf;
@@ -900,18 +901,18 @@ Once the kprobe event object has been created, it can then be
 populated with more fields.  Fields can be added using
 kprobe_event_add_fields(), supplying the dynevent_cmd object along
 with a variable arg list of probe fields.  For example, to add a
-couple additional fields, the following call could be made:
+couple additional fields, the following call could be made::
 
   ret = kprobe_event_add_fields(&cmd, "flags=%cx", "mode=+4($stack)");
 
 Once all the fields have been added, the event should be finalized and
 registered by calling the kprobe_event_gen_cmd_end() or
 kretprobe_event_gen_cmd_end() functions, depending on whether a kprobe
-or kretprobe command was started:
+or kretprobe command was started::
 
   ret = kprobe_event_gen_cmd_end(&cmd);
 
-or
+or::
 
   ret = kretprobe_event_gen_cmd_end(&cmd);
 
@@ -920,13 +921,13 @@ events.
 
 Similarly, a kretprobe event can be created using
 kretprobe_event_gen_cmd_start() with a probe name and location and
-additional params such as $retval:
+additional params such as $retval::
 
   ret = kretprobe_event_gen_cmd_start(&cmd, "gen_kretprobe_test",
                                       "do_sys_open", "$retval");
 
 Similar to the synthetic event case, code like the following can be
-used to enable the newly created kprobe event:
+used to enable the newly created kprobe event::
 
   gen_kprobe_test = trace_get_event_file(NULL, "kprobes", "gen_kprobe_test");
 
@@ -934,7 +935,7 @@ used to enable the newly created kprobe event:
                                   "kprobes", "gen_kprobe_test", true);
 
 Finally, also similar to synthetic events, the following code can be
-used to give the kprobe event file back and delete the event:
+used to give the kprobe event file back and delete the event::
 
   trace_put_event_file(gen_kprobe_test);
 
@@ -963,7 +964,7 @@ are described below.
 
 The first step in building a new command string is to create and
 initialize an instance of a dynevent_cmd.  Here, for instance, we
-create a dynevent_cmd on the stack and initialize it:
+create a dynevent_cmd on the stack and initialize it::
 
   struct dynevent_cmd cmd;
   char *buf;
@@ -989,7 +990,7 @@ calls to argument-adding functions.
 To add a single argument, define and initialize a struct dynevent_arg
 or struct dynevent_arg_pair object.  Here's an example of the simplest
 possible arg addition, which is simply to append the given string as
-a whitespace-separated argument to the command:
+a whitespace-separated argument to the command::
 
   struct dynevent_arg arg;
 
@@ -1007,7 +1008,7 @@ the arg.
 Here's another more complicated example using an 'arg pair', which is
 used to create an argument that consists of a couple components added
 together as a unit, for example, a 'type field_name;' arg or a simple
-expression arg e.g. 'flags=%cx':
+expression arg e.g. 'flags=%cx'::
 
   struct dynevent_arg_pair arg_pair;
 
@@ -1031,7 +1032,7 @@ Any number of dynevent_*_add() calls can be made to build up the string
 (until its length surpasses cmd->maxlen).  When all the arguments have
 been added and the command string is complete, the only thing left to
 do is run the command, which happens by simply calling
-dynevent_create():
+dynevent_create()::
 
   ret = dynevent_create(&cmd);
 
index 8489ead..7e2456b 100644 (file)
@@ -1,6 +1,6 @@
 .. include:: ../disclaimer-ita.rst
 
-:Original: :ref:`Documentation/process/stable-kernel-rules.rst <stable_kernel_rules>`
+:Original: :ref:`Documentation/networking/netdev-FAQ.rst <netdev-FAQ>`
 
 .. _it_netdev-FAQ:
 
index f4b0063..c4fc9d3 100644 (file)
@@ -8,26 +8,26 @@
 Linguaggio di programmazione
 ============================
 
-Il kernel è scritto nel linguaggio di programmazione C [c-language]_.
-Più precisamente, il kernel viene compilato con ``gcc`` [gcc]_ usando
-l'opzione ``-std=gnu89`` [gcc-c-dialect-options]_: il dialetto GNU
+Il kernel è scritto nel linguaggio di programmazione C [it-c-language]_.
+Più precisamente, il kernel viene compilato con ``gcc`` [it-gcc]_ usando
+l'opzione ``-std=gnu89`` [it-gcc-c-dialect-options]_: il dialetto GNU
 dello standard ISO C90 (con l'aggiunta di alcune funzionalità da C99)
 
-Questo dialetto contiene diverse estensioni al linguaggio [gnu-extensions]_,
+Questo dialetto contiene diverse estensioni al linguaggio [it-gnu-extensions]_,
 e molte di queste vengono usate sistematicamente dal kernel.
 
 Il kernel offre un certo livello di supporto per la compilazione con ``clang``
-[clang]_ e ``icc`` [icc]_ su diverse architetture, tuttavia in questo momento
+[it-clang]_ e ``icc`` [it-icc]_ su diverse architetture, tuttavia in questo momento
 il supporto non è completo e richiede delle patch aggiuntive.
 
 Attributi
 ---------
 
 Una delle estensioni più comuni e usate nel kernel sono gli attributi
-[gcc-attribute-syntax]_. Gli attributi permettono di aggiungere una semantica,
+[it-gcc-attribute-syntax]_. Gli attributi permettono di aggiungere una semantica,
 definita dell'implementazione, alle entità del linguaggio (come le variabili,
 le funzioni o i tipi) senza dover fare importanti modifiche sintattiche al
-linguaggio stesso (come l'aggiunta di nuove parole chiave) [n2049]_.
+linguaggio stesso (come l'aggiunta di nuove parole chiave) [it-n2049]_.
 
 In alcuni casi, gli attributi sono opzionali (ovvero un compilatore che non
 dovesse supportarli dovrebbe produrre comunque codice corretto, anche se
@@ -41,11 +41,11 @@ possono usare e/o per accorciare il codice.
 Per maggiori informazioni consultate il file d'intestazione
 ``include/linux/compiler_attributes.h``.
 
-.. [c-language] http://www.open-std.org/jtc1/sc22/wg14/www/standards
-.. [gcc] https://gcc.gnu.org
-.. [clang] https://clang.llvm.org
-.. [icc] https://software.intel.com/en-us/c-compilers
-.. [gcc-c-dialect-options] https://gcc.gnu.org/onlinedocs/gcc/C-Dialect-Options.html
-.. [gnu-extensions] https://gcc.gnu.org/onlinedocs/gcc/C-Extensions.html
-.. [gcc-attribute-syntax] https://gcc.gnu.org/onlinedocs/gcc/Attribute-Syntax.html
-.. [n2049] http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2049.pdf
+.. [it-c-language] http://www.open-std.org/jtc1/sc22/wg14/www/standards
+.. [it-gcc] https://gcc.gnu.org
+.. [it-clang] https://clang.llvm.org
+.. [it-icc] https://software.intel.com/en-us/c-compilers
+.. [it-gcc-c-dialect-options] https://gcc.gnu.org/onlinedocs/gcc/C-Dialect-Options.html
+.. [it-gnu-extensions] https://gcc.gnu.org/onlinedocs/gcc/C-Extensions.html
+.. [it-gcc-attribute-syntax] https://gcc.gnu.org/onlinedocs/gcc/Attribute-Syntax.html
+.. [it-n2049] http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2049.pdf
diff --git a/Documentation/translations/zh_CN/filesystems/index.rst b/Documentation/translations/zh_CN/filesystems/index.rst
new file mode 100644 (file)
index 0000000..14f155e
--- /dev/null
@@ -0,0 +1,27 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+.. include:: ../disclaimer-zh_CN.rst
+
+:Original: :ref:`Documentation/filesystems/index.rst <filesystems_index>`
+:Translator: Wang Wenhu <wenhu.wang@vivo.com>
+
+.. _cn_filesystems_index:
+
+========================
+Linux Kernel中的文件系统
+========================
+
+这份正在开发的手册或许在未来某个辉煌的日子里以易懂的形式将Linux虚拟\
+文件系统(VFS)层以及基于其上的各种文件系统如何工作呈现给大家。当前\
+可以看到下面的内容。
+
+文件系统
+========
+
+文件系统实现文档。
+
+.. toctree::
+   :maxdepth: 2
+
+   virtiofs
+
diff --git a/Documentation/translations/zh_CN/filesystems/virtiofs.rst b/Documentation/translations/zh_CN/filesystems/virtiofs.rst
new file mode 100644 (file)
index 0000000..09bc9e0
--- /dev/null
@@ -0,0 +1,58 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+.. include:: ../disclaimer-zh_CN.rst
+
+:Original: :ref:`Documentation/filesystems/virtiofs.rst <virtiofs_index>`
+
+译者
+::
+
+       中文版维护者: 王文虎 Wang Wenhu <wenhu.wang@vivo.com>
+       中文版翻译者: 王文虎 Wang Wenhu <wenhu.wang@vivo.com>
+       中文版校译者: 王文虎 Wang Wenhu <wenhu.wang@vivo.com>
+
+===========================================
+virtiofs: virtio-fs 主机<->客机共享文件系统
+===========================================
+
+- Copyright (C) 2020 Vivo Communication Technology Co. Ltd.
+
+介绍
+====
+Linux的virtiofs文件系统实现了一个半虚拟化VIRTIO类型“virtio-fs”设备的驱动,通过该\
+类型设备实现客机<->主机文件系统共享。它允许客机挂载一个已经导出到主机的目录。
+
+客机通常需要访问主机或者远程系统上的文件。使用场景包括:在新客机安装时让文件对其\
+可见;从主机上的根文件系统启动;对无状态或临时客机提供持久存储和在客机之间共享目录。
+
+尽管在某些任务可能通过使用已有的网络文件系统完成,但是却需要非常难以自动化的配置\
+步骤,且将存储网络暴露给客机。而virtio-fs设备通过提供不经过网络的文件系统访问文件\
+的设计方式解决了这些问题。
+
+另外,virto-fs设备发挥了主客机共存的优点提高了性能,并且提供了网络文件系统所不具备
+的一些语义功能。
+
+用法
+====
+以``myfs``标签将文件系统挂载到``/mnt``:
+
+.. code-block:: sh
+
+  guest# mount -t virtiofs myfs /mnt
+
+请查阅 https://virtio-fs.gitlab.io/ 了解配置QEMU和virtiofsd守护程序的详细信息。
+
+内幕
+====
+由于virtio-fs设备将FUSE协议用于文件系统请求,因此Linux的virtiofs文件系统与FUSE文\
+件系统客户端紧密集成在一起。客机充当FUSE客户端而主机充当FUSE服务器,内核与用户空\
+间之间的/dev/fuse接口由virtio-fs设备接口代替。
+
+FUSE请求被置于虚拟队列中由主机处理。主机填充缓冲区中的响应部分,而客机处理请求的完成部分。
+
+将/dev/fuse映射到虚拟队列需要解决/dev/fuse和虚拟队列之间语义上的差异。每次读取\
+/dev/fuse设备时,FUSE客户端都可以选择要传输的请求,从而可以使某些请求优先于其他\
+请求。虚拟队列有其队列语义,无法更改已入队请求的顺序。在虚拟队列已满的情况下尤
+其关键,因为此时不可能加入高优先级的请求。为了解决此差异,virtio-fs设备采用“hiprio”\
+(高优先级)虚拟队列,专门用于有别于普通请求的高优先级请求。
+
index d316553..76850a5 100644 (file)
@@ -14,6 +14,7 @@
    :maxdepth: 2
 
    process/index
+   filesystems/index
 
 目录和表格
 ----------
index 1f8127b..7bb3086 100644 (file)
@@ -1,4 +1,4 @@
-Chinese translated version of Documentation/io_ordering.txt
+Chinese translated version of Documentation/driver-api/io_ordering.rst
 
 If you have any comment or update to the content, please contact the
 original document maintainer directly.  However, if you have a problem
@@ -8,7 +8,7 @@ or if there is a problem with the translation.
 
 Chinese maintainer: Lin Yongting <linyongting@gmail.com>
 ---------------------------------------------------------------------
-Documentation/io_ordering.txt 的中文翻译
+Documentation/driver-api/io_ordering.rst 的中文翻译
 
 如果想评论或更新本文的内容,请直接联系原文档的维护者。如果你使用英文
 交流有困难的话,也可以向中文版维护者求助。如果本翻译更新不及时或者翻
index 41aba21..9ff9945 100644 (file)
@@ -5,7 +5,7 @@
 
 .. _cn_development_posting:
 
-发补丁
+发补丁
 ========
 
 迟早,当您的工作准备好提交给社区进行审查,并最终包含到主线内核中时。不出所料,
index 2e91370..f759eda 100644 (file)
@@ -266,7 +266,6 @@ Code  Seq#    Include File                                           Comments
 'o'   01-A1  `linux/dvb/*.h`                                         DVB
 'p'   00-0F  linux/phantom.h                                         conflict! (OpenHaptics needs this)
 'p'   00-1F  linux/rtc.h                                             conflict!
-'p'   00-3F  linux/mc146818rtc.h                                     conflict!
 'p'   40-7F  linux/nvram.h
 'p'   80-9F  linux/ppdev.h                                           user-space parport
                                                                      <mailto:tim@cyberelk.net>
index ed6d4b0..81a3938 100644 (file)
@@ -257,6 +257,9 @@ the fault, in our case the actual value is c0199ff5:
 the original assembly code: > 3:      movl $-14,%eax
 and linked in vmlinux     : > c0199ff5 <.fixup+10b5> movl   $0xfffffff2,%eax
 
+If the fixup was able to handle the exception, control flow may be returned
+to the instruction after the one that triggered the fault, ie. local label 2b.
+
 The assembly code::
 
  > .section __ex_table,"a"
@@ -344,3 +347,14 @@ pointer which points to one of:
      it as special.
 
 More functions can easily be added.
+
+CONFIG_BUILDTIME_TABLE_SORT allows the __ex_table section to be sorted post
+link of the kernel image, via a host utility scripts/sorttable. It will set the
+symbol main_extable_sort_needed to 0, avoiding sorting the __ex_table section
+at boot time. With the exception table sorted, at runtime when an exception
+occurs we can quickly lookup the __ex_table entry via binary search.
+
+This is not just a boot time optimization, some architectures require this
+table to be sorted in order to handle exceptions relatively early in the boot
+process. For example, i386 makes use of this form of exception handling before
+paging support is even enabled!
index 9dae6b4..099f13d 100644 (file)
@@ -95,9 +95,10 @@ and any RMRR's processed::
 When DMAR is enabled for use, you will notice..
 
 PCI-DMA: Using DMAR IOMMU
+-------------------------
 
 Fault reporting
----------------
+^^^^^^^^^^^^^^^
 
 ::
 
index f3975fb..36b6b98 100644 (file)
@@ -214,7 +214,7 @@ Q:  http://patchwork.kernel.org/project/v9fs-devel/list/
 T:     git git://git.kernel.org/pub/scm/linux/kernel/git/ericvh/v9fs.git
 T:     git git://github.com/martinetd/linux.git
 S:     Maintained
-F:     Documentation/filesystems/9p.txt
+F:     Documentation/filesystems/9p.rst
 F:     fs/9p/
 F:     net/9p/
 F:     include/net/9p/
@@ -584,7 +584,7 @@ AFFS FILE SYSTEM
 M:     David Sterba <dsterba@suse.com>
 L:     linux-fsdevel@vger.kernel.org
 S:     Odd Fixes
-F:     Documentation/filesystems/affs.txt
+F:     Documentation/filesystems/affs.rst
 F:     fs/affs/
 
 AFS FILESYSTEM
@@ -593,7 +593,7 @@ L:  linux-afs@lists.infradead.org
 S:     Supported
 F:     fs/afs/
 F:     include/trace/events/afs.h
-F:     Documentation/filesystems/afs.txt
+F:     Documentation/filesystems/afs.rst
 W:     https://www.infradead.org/~dhowells/kafs/
 
 AGPGART DRIVER
@@ -3063,7 +3063,7 @@ M:        Luis de Bethencourt <luisbg@kernel.org>
 M:     Salah Triki <salah.triki@gmail.com>
 S:     Maintained
 T:     git git://git.kernel.org/pub/scm/linux/kernel/git/luisbg/linux-befs.git
-F:     Documentation/filesystems/befs.txt
+F:     Documentation/filesystems/befs.rst
 F:     fs/befs/
 
 BFQ I/O SCHEDULER
@@ -3077,7 +3077,7 @@ F:        Documentation/block/bfq-iosched.rst
 BFS FILE SYSTEM
 M:     "Tigran A. Aivazian" <aivazian.tigran@gmail.com>
 S:     Maintained
-F:     Documentation/filesystems/bfs.txt
+F:     Documentation/filesystems/bfs.rst
 F:     fs/bfs/
 F:     include/uapi/linux/bfs_fs.h
 
@@ -3610,7 +3610,7 @@ W:        http://btrfs.wiki.kernel.org/
 Q:     http://patchwork.kernel.org/project/linux-btrfs/list/
 T:     git git://git.kernel.org/pub/scm/linux/kernel/git/mason/linux-btrfs.git
 S:     Maintained
-F:     Documentation/filesystems/btrfs.txt
+F:     Documentation/filesystems/btrfs.rst
 F:     fs/btrfs/
 F:     include/linux/btrfs*
 F:     include/uapi/linux/btrfs*
@@ -3907,7 +3907,7 @@ W:        http://ceph.com/
 T:     git git://git.kernel.org/pub/scm/linux/kernel/git/sage/ceph-client.git
 T:     git git://github.com/ceph/ceph-client.git
 S:     Supported
-F:     Documentation/filesystems/ceph.txt
+F:     Documentation/filesystems/ceph.rst
 F:     fs/ceph/
 
 CERTIFICATE HANDLING
@@ -4423,7 +4423,7 @@ F:        include/linux/cpuidle.h
 CRAMFS FILESYSTEM
 M:     Nicolas Pitre <nico@fluxnic.net>
 S:     Maintained
-F:     Documentation/filesystems/cramfs.txt
+F:     Documentation/filesystems/cramfs.rst
 F:     fs/cramfs/
 
 CREATIVE SB0540
@@ -5201,7 +5201,7 @@ M:        Greg Kroah-Hartman <gregkh@linuxfoundation.org>
 R:     "Rafael J. Wysocki" <rafael@kernel.org>
 T:     git git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core.git
 S:     Supported
-F:     Documentation/kobject.txt
+F:     Documentation/core-api/kobject.rst
 F:     drivers/base/
 F:     fs/debugfs/
 F:     fs/sysfs/
@@ -5938,7 +5938,7 @@ W:        http://ecryptfs.org
 W:     https://launchpad.net/ecryptfs
 T:     git git://git.kernel.org/pub/scm/linux/kernel/git/tyhicks/ecryptfs.git
 S:     Odd Fixes
-F:     Documentation/filesystems/ecryptfs.txt
+F:     Documentation/filesystems/ecryptfs.rst
 F:     fs/ecryptfs/
 
 EDAC-AMD64
@@ -6254,12 +6254,12 @@ F:      drivers/video/fbdev/s1d13xxxfb.c
 F:     include/video/s1d13xxxfb.h
 
 EROFS FILE SYSTEM
-M:     Gao Xiang <gaoxiang25@huawei.com>
+M:     Gao Xiang <xiang@kernel.org>
 M:     Chao Yu <yuchao0@huawei.com>
 L:     linux-erofs@lists.ozlabs.org
 S:     Maintained
 T:     git git://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs.git
-F:     Documentation/filesystems/erofs.txt
+F:     Documentation/filesystems/erofs.rst
 F:     fs/erofs/
 F:     include/trace/events/erofs.h
 
@@ -6320,7 +6320,7 @@ EXT2 FILE SYSTEM
 M:     Jan Kara <jack@suse.com>
 L:     linux-ext4@vger.kernel.org
 S:     Maintained
-F:     Documentation/filesystems/ext2.txt
+F:     Documentation/filesystems/ext2.rst
 F:     fs/ext2/
 F:     include/linux/ext2*
 
@@ -6394,7 +6394,7 @@ L:        linux-f2fs-devel@lists.sourceforge.net
 W:     https://f2fs.wiki.kernel.org/
 T:     git git://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs.git
 S:     Maintained
-F:     Documentation/filesystems/f2fs.txt
+F:     Documentation/filesystems/f2fs.rst
 F:     Documentation/ABI/testing/sysfs-fs-f2fs
 F:     fs/f2fs/
 F:     include/linux/f2fs_fs.h
@@ -6939,7 +6939,7 @@ S:        Maintained
 F:     scripts/gcc-plugins/
 F:     scripts/gcc-plugin.sh
 F:     scripts/Makefile.gcc-plugins
-F:     Documentation/core-api/gcc-plugins.rst
+F:     Documentation/kbuild/gcc-plugins.rst
 
 GASKET DRIVER FRAMEWORK
 M:     Rob Springer <rspringer@google.com>
@@ -7436,13 +7436,13 @@ F:      drivers/infiniband/hw/hfi1
 HFS FILESYSTEM
 L:     linux-fsdevel@vger.kernel.org
 S:     Orphan
-F:     Documentation/filesystems/hfs.txt
+F:     Documentation/filesystems/hfs.rst
 F:     fs/hfs/
 
 HFSPLUS FILESYSTEM
 L:     linux-fsdevel@vger.kernel.org
 S:     Orphan
-F:     Documentation/filesystems/hfsplus.txt
+F:     Documentation/filesystems/hfsplus.rst
 F:     fs/hfsplus/
 
 HGA FRAMEBUFFER DRIVER
@@ -8320,7 +8320,7 @@ M:        Jan Kara <jack@suse.cz>
 R:     Amir Goldstein <amir73il@gmail.com>
 L:     linux-fsdevel@vger.kernel.org
 S:     Maintained
-F:     Documentation/filesystems/inotify.txt
+F:     Documentation/filesystems/inotify.rst
 F:     fs/notify/inotify/
 F:     include/linux/inotify.h
 F:     include/uapi/linux/inotify.h
@@ -8580,15 +8580,15 @@ M:      Ashutosh Dixit <ashutosh.dixit@intel.com>
 S:     Supported
 W:     https://github.com/sudeepdutt/mic
 W:     http://software.intel.com/en-us/mic-developer
+F:     Documentation/misc-devices/mic/
+F:     drivers/dma/mic_x100_dma.c
+F:     drivers/dma/mic_x100_dma.h
+F:     drivers/misc/mic/
 F:     include/linux/mic_bus.h
 F:     include/linux/scif.h
 F:     include/uapi/linux/mic_common.h
 F:     include/uapi/linux/mic_ioctl.h
 F:     include/uapi/linux/scif_ioctl.h
-F:     drivers/misc/mic/
-F:     drivers/dma/mic_x100_dma.c
-F:     drivers/dma/mic_x100_dma.h
-F:     Documentation/mic/
 
 INTEL PMC CORE DRIVER
 M:     Rajneesh Bhardwaj <rajneesh.bhardwaj@intel.com>
@@ -9286,8 +9286,8 @@ L:        keyrings@vger.kernel.org
 S:     Supported
 F:     Documentation/security/keys/trusted-encrypted.rst
 F:     include/keys/trusted-type.h
-F:     security/keys/trusted.c
-F:     include/keys/trusted.h
+F:     include/keys/trusted_tpm.h
+F:     security/keys/trusted-keys/
 
 KEYS/KEYRINGS
 M:     David Howells <dhowells@redhat.com>
@@ -11800,7 +11800,7 @@ W:      https://nilfs.sourceforge.io/
 W:     https://nilfs.osdn.jp/
 T:     git git://github.com/konis/nilfs2.git
 S:     Supported
-F:     Documentation/filesystems/nilfs2.txt
+F:     Documentation/filesystems/nilfs2.rst
 F:     fs/nilfs2/
 F:     include/trace/events/nilfs2.h
 F:     include/uapi/linux/nilfs2_api.h
@@ -11909,7 +11909,7 @@ L:      linux-ntfs-dev@lists.sourceforge.net
 W:     http://www.tuxera.com/
 T:     git git://git.kernel.org/pub/scm/linux/kernel/git/aia21/ntfs.git
 S:     Supported
-F:     Documentation/filesystems/ntfs.txt
+F:     Documentation/filesystems/ntfs.rst
 F:     fs/ntfs/
 
 NUBUS SUBSYSTEM
@@ -12255,7 +12255,7 @@ OMFS FILESYSTEM
 M:     Bob Copeland <me@bobcopeland.com>
 L:     linux-karma-devel@lists.sourceforge.net
 S:     Maintained
-F:     Documentation/filesystems/omfs.txt
+F:     Documentation/filesystems/omfs.rst
 F:     fs/omfs/
 
 OMNIKEY CARDMAN 4000 DRIVER
@@ -12504,8 +12504,8 @@ M:      Joseph Qi <joseph.qi@linux.alibaba.com>
 L:     ocfs2-devel@oss.oracle.com (moderated for non-subscribers)
 W:     http://ocfs2.wiki.kernel.org
 S:     Supported
-F:     Documentation/filesystems/ocfs2.txt
-F:     Documentation/filesystems/dlmfs.txt
+F:     Documentation/filesystems/ocfs2.rst
+F:     Documentation/filesystems/dlmfs.rst
 F:     fs/ocfs2/
 
 ORANGEFS FILESYSTEM
@@ -12515,7 +12515,7 @@ L:      devel@lists.orangefs.org
 T:     git git://git.kernel.org/pub/scm/linux/kernel/git/hubcap/linux.git
 S:     Supported
 F:     fs/orangefs/
-F:     Documentation/filesystems/orangefs.txt
+F:     Documentation/filesystems/orangefs.rst
 
 ORINOCO DRIVER
 L:     linux-wireless@vger.kernel.org
@@ -13477,7 +13477,7 @@ S:      Maintained
 F:     fs/proc/
 F:     include/linux/proc_fs.h
 F:     tools/testing/selftests/proc/
-F:     Documentation/filesystems/proc.txt
+F:     Documentation/filesystems/proc.rst
 
 PROC SYSCTL
 M:     Luis Chamberlain <mcgrof@kernel.org>
@@ -15744,7 +15744,7 @@ L:      squashfs-devel@lists.sourceforge.net (subscribers-only)
 W:     http://squashfs.org.uk
 T:     git git://git.kernel.org/pub/scm/linux/kernel/git/pkl/squashfs-next.git
 S:     Maintained
-F:     Documentation/filesystems/squashfs.txt
+F:     Documentation/filesystems/squashfs.rst
 F:     fs/squashfs/
 
 SRM (Alpha) environment access
@@ -16189,7 +16189,7 @@ F:      drivers/platform/x86/system76_acpi.c
 SYSV FILESYSTEM
 M:     Christoph Hellwig <hch@infradead.org>
 S:     Maintained
-F:     Documentation/filesystems/sysv-fs.txt
+F:     Documentation/filesystems/sysv-fs.rst
 F:     fs/sysv/
 F:     include/linux/sysv_fs.h
 
@@ -17054,7 +17054,7 @@ T:      git git://git.kernel.org/pub/scm/linux/kernel/git/rw/ubifs.git next
 T:     git git://git.kernel.org/pub/scm/linux/kernel/git/rw/ubifs.git fixes
 W:     http://www.linux-mtd.infradead.org/doc/ubifs.html
 S:     Supported
-F:     Documentation/filesystems/ubifs.txt
+F:     Documentation/filesystems/ubifs.rst
 F:     fs/ubifs/
 
 UCLINUX (M68KNOMMU AND COLDFIRE)
@@ -17073,7 +17073,7 @@ F:      arch/m68k/include/asm/*_no.*
 UDF FILESYSTEM
 M:     Jan Kara <jack@suse.com>
 S:     Maintained
-F:     Documentation/filesystems/udf.txt
+F:     Documentation/filesystems/udf.rst
 F:     fs/udf/
 
 UDRAW TABLET
@@ -18512,7 +18512,7 @@ L:      linux-fsdevel@vger.kernel.org
 T:     git git://git.kernel.org/pub/scm/linux/kernel/git/dlemoal/zonefs.git
 S:     Maintained
 F:     fs/zonefs/
-F:     Documentation/filesystems/zonefs.txt
+F:     Documentation/filesystems/zonefs.rst
 
 ZPOOL COMPRESSED PAGE STORAGE API
 M:     Dan Streetman <ddstreet@ieee.org>
index f4fe4d0..79fa327 100644 (file)
@@ -8,16 +8,18 @@
  */
 #ifndef __ASM_ARM_FLOPPY_H
 #define __ASM_ARM_FLOPPY_H
-#if 0
-#include <mach/floppy.h>
-#endif
 
-#define fd_outb(val,port)                      \
-       do {                                    \
-               if ((port) == (u32)FD_DOR)      \
-                       fd_setdor((val));       \
-               else                            \
-                       outb((val),(port));     \
+#define fd_outb(val,port)                                              \
+       do {                                                            \
+               int new_val = (val);                                    \
+               if (((port) & 7) == FD_DOR) {                           \
+                       if (new_val & 0xf0)                             \
+                               new_val = (new_val & 0x0c) |            \
+                                         floppy_selects[new_val & 3];  \
+                       else                                            \
+                               new_val &= 0x0c;                        \
+               }                                                       \
+               outb(new_val, (port));                                  \
        } while(0)
 
 #define fd_inb(port)           inb((port))
@@ -53,69 +55,7 @@ static inline int fd_dma_setup(void *data, unsigned int length,
  * to a non-zero track, and then restoring it to track 0.  If an error occurs,
  * then there is no floppy drive present.       [to be put back in again]
  */
-static unsigned char floppy_selects[2][4] =
-{
-       { 0x10, 0x21, 0x23, 0x33 },
-       { 0x10, 0x21, 0x23, 0x33 }
-};
-
-#define fd_setdor(dor)                                                         \
-do {                                                                           \
-       int new_dor = (dor);                                                    \
-       if (new_dor & 0xf0)                                                     \
-               new_dor = (new_dor & 0x0c) | floppy_selects[fdc][new_dor & 3];  \
-       else                                                                    \
-               new_dor &= 0x0c;                                                \
-       outb(new_dor, FD_DOR);                                                  \
-} while (0)
-
-/*
- * Someday, we'll automatically detect which drives are present...
- */
-static inline void fd_scandrives (void)
-{
-#if 0
-       int floppy, drive_count;
-
-       fd_disable_irq();
-       raw_cmd = &default_raw_cmd;
-       raw_cmd->flags = FD_RAW_SPIN | FD_RAW_NEED_SEEK;
-       raw_cmd->track = 0;
-       raw_cmd->rate = ?;
-       drive_count = 0;
-       for (floppy = 0; floppy < 4; floppy ++) {
-               current_drive = drive_count;
-               /*
-                * Turn on floppy motor
-                */
-               if (start_motor(redo_fd_request))
-                       continue;
-               /*
-                * Set up FDC
-                */
-               fdc_specify();
-               /*
-                * Tell FDC to recalibrate
-                */
-               output_byte(FD_RECALIBRATE);
-               LAST_OUT(UNIT(floppy));
-               /* wait for command to complete */
-               if (!successful) {
-                       int i;
-                       for (i = drive_count; i < 3; i--)
-                               floppy_selects[fdc][i] = floppy_selects[fdc][i + 1];
-                       floppy_selects[fdc][3] = 0;
-                       floppy -= 1;
-               } else
-                       drive_count++;
-       }
-#else
-       floppy_selects[0][0] = 0x10;
-       floppy_selects[0][1] = 0x21;
-       floppy_selects[0][2] = 0x23;
-       floppy_selects[0][3] = 0x33;
-#endif
-}
+static unsigned char floppy_selects[4] = { 0x10, 0x21, 0x23, 0x33 };
 
 #define FDC1 (0x3f0)
 
@@ -135,9 +75,7 @@ static inline void fd_scandrives (void)
  */
 static void driveswap(int *ints, int dummy, int dummy2)
 {
-       floppy_selects[0][0] ^= floppy_selects[0][1];
-       floppy_selects[0][1] ^= floppy_selects[0][0];
-       floppy_selects[0][0] ^= floppy_selects[0][1];
+       swap(floppy_selects[0], floppy_selects[1]);
 }
 
 #define EXTRA_FLOPPY_PARAMS ,{ "driveswap", &driveswap, NULL, 0, 0 }
index 40712e4..c3a6304 100644 (file)
@@ -118,12 +118,11 @@ static int __init nfhd_init_one(int id, u32 blocks, u32 bsize)
        dev->bsize = bsize;
        dev->bshift = ffs(bsize) - 10;
 
-       dev->queue = blk_alloc_queue(GFP_KERNEL);
+       dev->queue = blk_alloc_queue(nfhd_make_request, NUMA_NO_NODE);
        if (dev->queue == NULL)
                goto free_dev;
 
        dev->queue->queuedata = dev;
-       blk_queue_make_request(dev->queue, nfhd_make_request);
        blk_queue_logical_block_size(dev->queue, bsize);
 
        dev->disk = alloc_disk(16);
index 3ca74e1..bd4e7c3 100644 (file)
@@ -27,7 +27,7 @@ extern void __uc32_iounmap(volatile void __iomem *addr);
  * ioremap and friends.
  *
  * ioremap takes a PCI memory address, as specified in
- * Documentation/io-mapping.txt.
+ * Documentation/driver-api/io-mapping.rst.
  *
  */
 #define ioremap(cookie, size)          __uc32_ioremap(cookie, size)
index 8331098..49322b6 100644 (file)
@@ -267,13 +267,12 @@ static int __init simdisk_setup(struct simdisk *dev, int which,
        spin_lock_init(&dev->lock);
        dev->users = 0;
 
-       dev->queue = blk_alloc_queue(GFP_KERNEL);
+       dev->queue = blk_alloc_queue(simdisk_make_request, NUMA_NO_NODE);
        if (dev->queue == NULL) {
                pr_err("blk_alloc_queue failed\n");
                goto out_alloc_queue;
        }
 
-       blk_queue_make_request(dev->queue, simdisk_make_request);
        dev->queue->queuedata = dev;
 
        dev->gd = alloc_disk(SIMDISK_MINORS);
index 1a43750..206b96e 100644 (file)
@@ -8,8 +8,7 @@ obj-$(CONFIG_BLOCK) := bio.o elevator.o blk-core.o blk-sysfs.o \
                        blk-exec.o blk-merge.o blk-softirq.o blk-timeout.o \
                        blk-lib.o blk-mq.o blk-mq-tag.o blk-stat.o \
                        blk-mq-sysfs.o blk-mq-cpumap.o blk-mq-sched.o ioctl.o \
-                       genhd.o partition-generic.o ioprio.o \
-                       badblocks.o partitions/ blk-rq-qos.o
+                       genhd.o ioprio.o badblocks.o partitions/ blk-rq-qos.o
 
 obj-$(CONFIG_BOUNCE)           += bounce.o
 obj-$(CONFIG_BLK_SCSI_REQUEST) += scsi_ioctl.o
index f0ff665..68882b9 100644 (file)
@@ -642,6 +642,12 @@ void bfq_bfqq_move(struct bfq_data *bfqd, struct bfq_queue *bfqq,
 {
        struct bfq_entity *entity = &bfqq->entity;
 
+       /*
+        * Get extra reference to prevent bfqq from being freed in
+        * next possible expire or deactivate.
+        */
+       bfqq->ref++;
+
        /* If bfqq is empty, then bfq_bfqq_expire also invokes
         * bfq_del_bfqq_busy, thereby removing bfqq and its entity
         * from data structures related to current group. Otherwise we
@@ -652,12 +658,6 @@ void bfq_bfqq_move(struct bfq_data *bfqd, struct bfq_queue *bfqq,
                bfq_bfqq_expire(bfqd, bfqd->in_service_queue,
                                false, BFQQE_PREEMPTED);
 
-       /*
-        * get extra reference to prevent bfqq from being freed in
-        * next possible deactivate
-        */
-       bfqq->ref++;
-
        if (bfq_bfqq_busy(bfqq))
                bfq_deactivate_bfqq(bfqd, bfqq, false, false);
        else if (entity->on_st_or_in_serv)
@@ -677,7 +677,7 @@ void bfq_bfqq_move(struct bfq_data *bfqd, struct bfq_queue *bfqq,
 
        if (!bfqd->in_service_queue && !bfqd->rq_in_driver)
                bfq_schedule_dispatch(bfqd);
-       /* release extra ref taken above */
+       /* release extra ref taken above, bfqq may happen to be freed now */
        bfq_put_queue(bfqq);
 }
 
@@ -714,10 +714,7 @@ static struct bfq_group *__bfq_bic_change_cgroup(struct bfq_data *bfqd,
 
                if (entity->sched_data != &bfqg->sched_data) {
                        bic_set_bfqq(bic, NULL, 0);
-                       bfq_log_bfqq(bfqd, async_bfqq,
-                                    "bic_change_group: %p %d",
-                                    async_bfqq, async_bfqq->ref);
-                       bfq_put_queue(async_bfqq);
+                       bfq_release_process_ref(bfqd, async_bfqq);
                }
        }
 
@@ -818,39 +815,53 @@ static void bfq_flush_idle_tree(struct bfq_service_tree *st)
 /**
  * bfq_reparent_leaf_entity - move leaf entity to the root_group.
  * @bfqd: the device data structure with the root group.
- * @entity: the entity to move.
+ * @entity: the entity to move, if entity is a leaf; or the parent entity
+ *         of an active leaf entity to move, if entity is not a leaf.
  */
 static void bfq_reparent_leaf_entity(struct bfq_data *bfqd,
-                                    struct bfq_entity *entity)
+                                    struct bfq_entity *entity,
+                                    int ioprio_class)
 {
-       struct bfq_queue *bfqq = bfq_entity_to_bfqq(entity);
+       struct bfq_queue *bfqq;
+       struct bfq_entity *child_entity = entity;
 
+       while (child_entity->my_sched_data) { /* leaf not reached yet */
+               struct bfq_sched_data *child_sd = child_entity->my_sched_data;
+               struct bfq_service_tree *child_st = child_sd->service_tree +
+                       ioprio_class;
+               struct rb_root *child_active = &child_st->active;
+
+               child_entity = bfq_entity_of(rb_first(child_active));
+
+               if (!child_entity)
+                       child_entity = child_sd->in_service_entity;
+       }
+
+       bfqq = bfq_entity_to_bfqq(child_entity);
        bfq_bfqq_move(bfqd, bfqq, bfqd->root_group);
 }
 
 /**
- * bfq_reparent_active_entities - move to the root group all active
- *                                entities.
+ * bfq_reparent_active_queues - move to the root group all active queues.
  * @bfqd: the device data structure with the root group.
  * @bfqg: the group to move from.
- * @st: the service tree with the entities.
+ * @st: the service tree to start the search from.
  */
-static void bfq_reparent_active_entities(struct bfq_data *bfqd,
-                                        struct bfq_group *bfqg,
-                                        struct bfq_service_tree *st)
+static void bfq_reparent_active_queues(struct bfq_data *bfqd,
+                                      struct bfq_group *bfqg,
+                                      struct bfq_service_tree *st,
+                                      int ioprio_class)
 {
        struct rb_root *active = &st->active;
-       struct bfq_entity *entity = NULL;
-
-       if (!RB_EMPTY_ROOT(&st->active))
-               entity = bfq_entity_of(rb_first(active));
+       struct bfq_entity *entity;
 
-       for (; entity ; entity = bfq_entity_of(rb_first(active)))
-               bfq_reparent_leaf_entity(bfqd, entity);
+       while ((entity = bfq_entity_of(rb_first(active))))
+               bfq_reparent_leaf_entity(bfqd, entity, ioprio_class);
 
        if (bfqg->sched_data.in_service_entity)
                bfq_reparent_leaf_entity(bfqd,
-                       bfqg->sched_data.in_service_entity);
+                                        bfqg->sched_data.in_service_entity,
+                                        ioprio_class);
 }
 
 /**
@@ -883,13 +894,6 @@ static void bfq_pd_offline(struct blkg_policy_data *pd)
                st = bfqg->sched_data.service_tree + i;
 
                /*
-                * The idle tree may still contain bfq_queues belonging
-                * to exited task because they never migrated to a different
-                * cgroup from the one being destroyed now.
-                */
-               bfq_flush_idle_tree(st);
-
-               /*
                 * It may happen that some queues are still active
                 * (busy) upon group destruction (if the corresponding
                 * processes have been forced to terminate). We move
@@ -901,7 +905,20 @@ static void bfq_pd_offline(struct blkg_policy_data *pd)
                 * There is no need to put the sync queues, as the
                 * scheduler has taken no reference.
                 */
-               bfq_reparent_active_entities(bfqd, bfqg, st);
+               bfq_reparent_active_queues(bfqd, bfqg, st, i);
+
+               /*
+                * The idle tree may still contain bfq_queues
+                * belonging to exited task because they never
+                * migrated to a different cgroup from the one being
+                * destroyed now. In addition, even
+                * bfq_reparent_active_queues() may happen to add some
+                * entities to the idle tree. It happens if, in some
+                * of the calls to bfq_bfqq_move() performed by
+                * bfq_reparent_active_queues(), the queue to move is
+                * empty and gets expired.
+                */
+               bfq_flush_idle_tree(st);
        }
 
        __bfq_deactivate_entity(entity, false);
index 8c436ab..78ba57e 100644 (file)
@@ -2716,8 +2716,6 @@ static void bfq_bfqq_save_state(struct bfq_queue *bfqq)
        }
 }
 
-
-static
 void bfq_release_process_ref(struct bfq_data *bfqd, struct bfq_queue *bfqq)
 {
        /*
@@ -6215,20 +6213,28 @@ static struct bfq_queue *bfq_init_rq(struct request *rq)
        return bfqq;
 }
 
-static void bfq_idle_slice_timer_body(struct bfq_queue *bfqq)
+static void
+bfq_idle_slice_timer_body(struct bfq_data *bfqd, struct bfq_queue *bfqq)
 {
-       struct bfq_data *bfqd = bfqq->bfqd;
        enum bfqq_expiration reason;
        unsigned long flags;
 
        spin_lock_irqsave(&bfqd->lock, flags);
-       bfq_clear_bfqq_wait_request(bfqq);
 
+       /*
+        * Considering that bfqq may be in race, we should firstly check
+        * whether bfqq is in service before doing something on it. If
+        * the bfqq in race is not in service, it has already been expired
+        * through __bfq_bfqq_expire func and its wait_request flags has
+        * been cleared in __bfq_bfqd_reset_in_service func.
+        */
        if (bfqq != bfqd->in_service_queue) {
                spin_unlock_irqrestore(&bfqd->lock, flags);
                return;
        }
 
+       bfq_clear_bfqq_wait_request(bfqq);
+
        if (bfq_bfqq_budget_timeout(bfqq))
                /*
                 * Also here the queue can be safely expired
@@ -6273,7 +6279,7 @@ static enum hrtimer_restart bfq_idle_slice_timer(struct hrtimer *timer)
         * early.
         */
        if (bfqq)
-               bfq_idle_slice_timer_body(bfqq);
+               bfq_idle_slice_timer_body(bfqd, bfqq);
 
        return HRTIMER_NORESTART;
 }
index d1233af..cd224aa 100644 (file)
@@ -955,6 +955,7 @@ void bfq_bfqq_expire(struct bfq_data *bfqd, struct bfq_queue *bfqq,
                     bool compensate, enum bfqq_expiration reason);
 void bfq_put_queue(struct bfq_queue *bfqq);
 void bfq_end_wr_async_queues(struct bfq_data *bfqd, struct bfq_group *bfqg);
+void bfq_release_process_ref(struct bfq_data *bfqd, struct bfq_queue *bfqq);
 void bfq_schedule_dispatch(struct bfq_data *bfqd);
 void bfq_put_async_queues(struct bfq_data *bfqd, struct bfq_group *bfqg);
 
index 94d6972..21cbaa6 100644 (file)
@@ -17,6 +17,7 @@
 #include <linux/cgroup.h>
 #include <linux/blk-cgroup.h>
 #include <linux/highmem.h>
+#include <linux/sched/sysctl.h>
 
 #include <trace/events/block.h>
 #include "blk.h"
@@ -588,6 +589,49 @@ void bio_truncate(struct bio *bio, unsigned new_size)
 }
 
 /**
+ * guard_bio_eod - truncate a BIO to fit the block device
+ * @bio:       bio to truncate
+ *
+ * This allows us to do IO even on the odd last sectors of a device, even if the
+ * block size is some multiple of the physical sector size.
+ *
+ * We'll just truncate the bio to the size of the device, and clear the end of
+ * the buffer head manually.  Truly out-of-range accesses will turn into actual
+ * I/O errors, this only handles the "we need to be able to do I/O at the final
+ * sector" case.
+ */
+void guard_bio_eod(struct bio *bio)
+{
+       sector_t maxsector;
+       struct hd_struct *part;
+
+       rcu_read_lock();
+       part = __disk_get_part(bio->bi_disk, bio->bi_partno);
+       if (part)
+               maxsector = part_nr_sects_read(part);
+       else
+               maxsector = get_capacity(bio->bi_disk);
+       rcu_read_unlock();
+
+       if (!maxsector)
+               return;
+
+       /*
+        * If the *whole* IO is past the end of the device,
+        * let it through, and the IO layer will turn it into
+        * an EIO.
+        */
+       if (unlikely(bio->bi_iter.bi_sector >= maxsector))
+               return;
+
+       maxsector -= bio->bi_iter.bi_sector;
+       if (likely((bio->bi_iter.bi_size >> 9) <= maxsector))
+               return;
+
+       bio_truncate(bio, maxsector << 9);
+}
+
+/**
  * bio_put - release a reference to a bio
  * @bio:   bio to release reference to
  *
@@ -679,6 +723,12 @@ struct bio *bio_clone_fast(struct bio *bio, gfp_t gfp_mask, struct bio_set *bs)
 }
 EXPORT_SYMBOL(bio_clone_fast);
 
+const char *bio_devname(struct bio *bio, char *buf)
+{
+       return disk_name(bio->bi_disk, bio->bi_partno, buf);
+}
+EXPORT_SYMBOL(bio_devname);
+
 static inline bool page_is_mergeable(const struct bio_vec *bv,
                struct page *page, unsigned int len, unsigned int off,
                bool *same_page)
@@ -730,7 +780,7 @@ static bool bio_try_merge_pc_page(struct request_queue *q, struct bio *bio,
  *
  *     This should only be used by passthrough bios.
  */
-static int __bio_add_pc_page(struct request_queue *q, struct bio *bio,
+int __bio_add_pc_page(struct request_queue *q, struct bio *bio,
                struct page *page, unsigned int len, unsigned int offset,
                bool *same_page)
 {
@@ -1019,12 +1069,21 @@ static void submit_bio_wait_endio(struct bio *bio)
 int submit_bio_wait(struct bio *bio)
 {
        DECLARE_COMPLETION_ONSTACK_MAP(done, bio->bi_disk->lockdep_map);
+       unsigned long hang_check;
 
        bio->bi_private = &done;
        bio->bi_end_io = submit_bio_wait_endio;
        bio->bi_opf |= REQ_SYNC;
        submit_bio(bio);
-       wait_for_completion_io(&done);
+
+       /* Prevent hang_check timer from firing at us during very long I/O */
+       hang_check = sysctl_hung_task_timeout_secs;
+       if (hang_check)
+               while (!wait_for_completion_io_timeout(&done,
+                                       hang_check * (HZ/2)))
+                       ;
+       else
+               wait_for_completion_io(&done);
 
        return blk_status_to_errno(bio->bi_status);
 }
@@ -1135,90 +1194,6 @@ void bio_list_copy_data(struct bio *dst, struct bio *src)
 }
 EXPORT_SYMBOL(bio_list_copy_data);
 
-struct bio_map_data {
-       int is_our_pages;
-       struct iov_iter iter;
-       struct iovec iov[];
-};
-
-static struct bio_map_data *bio_alloc_map_data(struct iov_iter *data,
-                                              gfp_t gfp_mask)
-{
-       struct bio_map_data *bmd;
-       if (data->nr_segs > UIO_MAXIOV)
-               return NULL;
-
-       bmd = kmalloc(struct_size(bmd, iov, data->nr_segs), gfp_mask);
-       if (!bmd)
-               return NULL;
-       memcpy(bmd->iov, data->iov, sizeof(struct iovec) * data->nr_segs);
-       bmd->iter = *data;
-       bmd->iter.iov = bmd->iov;
-       return bmd;
-}
-
-/**
- * bio_copy_from_iter - copy all pages from iov_iter to bio
- * @bio: The &struct bio which describes the I/O as destination
- * @iter: iov_iter as source
- *
- * Copy all pages from iov_iter to bio.
- * Returns 0 on success, or error on failure.
- */
-static int bio_copy_from_iter(struct bio *bio, struct iov_iter *iter)
-{
-       struct bio_vec *bvec;
-       struct bvec_iter_all iter_all;
-
-       bio_for_each_segment_all(bvec, bio, iter_all) {
-               ssize_t ret;
-
-               ret = copy_page_from_iter(bvec->bv_page,
-                                         bvec->bv_offset,
-                                         bvec->bv_len,
-                                         iter);
-
-               if (!iov_iter_count(iter))
-                       break;
-
-               if (ret < bvec->bv_len)
-                       return -EFAULT;
-       }
-
-       return 0;
-}
-
-/**
- * bio_copy_to_iter - copy all pages from bio to iov_iter
- * @bio: The &struct bio which describes the I/O as source
- * @iter: iov_iter as destination
- *
- * Copy all pages from bio to iov_iter.
- * Returns 0 on success, or error on failure.
- */
-static int bio_copy_to_iter(struct bio *bio, struct iov_iter iter)
-{
-       struct bio_vec *bvec;
-       struct bvec_iter_all iter_all;
-
-       bio_for_each_segment_all(bvec, bio, iter_all) {
-               ssize_t ret;
-
-               ret = copy_page_to_iter(bvec->bv_page,
-                                       bvec->bv_offset,
-                                       bvec->bv_len,
-                                       &iter);
-
-               if (!iov_iter_count(&iter))
-                       break;
-
-               if (ret < bvec->bv_len)
-                       return -EFAULT;
-       }
-
-       return 0;
-}
-
 void bio_free_pages(struct bio *bio)
 {
        struct bio_vec *bvec;
@@ -1229,430 +1204,6 @@ void bio_free_pages(struct bio *bio)
 }
 EXPORT_SYMBOL(bio_free_pages);
 
-/**
- *     bio_uncopy_user -       finish previously mapped bio
- *     @bio: bio being terminated
- *
- *     Free pages allocated from bio_copy_user_iov() and write back data
- *     to user space in case of a read.
- */
-int bio_uncopy_user(struct bio *bio)
-{
-       struct bio_map_data *bmd = bio->bi_private;
-       int ret = 0;
-
-       if (!bio_flagged(bio, BIO_NULL_MAPPED)) {
-               /*
-                * if we're in a workqueue, the request is orphaned, so
-                * don't copy into a random user address space, just free
-                * and return -EINTR so user space doesn't expect any data.
-                */
-               if (!current->mm)
-                       ret = -EINTR;
-               else if (bio_data_dir(bio) == READ)
-                       ret = bio_copy_to_iter(bio, bmd->iter);
-               if (bmd->is_our_pages)
-                       bio_free_pages(bio);
-       }
-       kfree(bmd);
-       bio_put(bio);
-       return ret;
-}
-
-/**
- *     bio_copy_user_iov       -       copy user data to bio
- *     @q:             destination block queue
- *     @map_data:      pointer to the rq_map_data holding pages (if necessary)
- *     @iter:          iovec iterator
- *     @gfp_mask:      memory allocation flags
- *
- *     Prepares and returns a bio for indirect user io, bouncing data
- *     to/from kernel pages as necessary. Must be paired with
- *     call bio_uncopy_user() on io completion.
- */
-struct bio *bio_copy_user_iov(struct request_queue *q,
-                             struct rq_map_data *map_data,
-                             struct iov_iter *iter,
-                             gfp_t gfp_mask)
-{
-       struct bio_map_data *bmd;
-       struct page *page;
-       struct bio *bio;
-       int i = 0, ret;
-       int nr_pages;
-       unsigned int len = iter->count;
-       unsigned int offset = map_data ? offset_in_page(map_data->offset) : 0;
-
-       bmd = bio_alloc_map_data(iter, gfp_mask);
-       if (!bmd)
-               return ERR_PTR(-ENOMEM);
-
-       /*
-        * We need to do a deep copy of the iov_iter including the iovecs.
-        * The caller provided iov might point to an on-stack or otherwise
-        * shortlived one.
-        */
-       bmd->is_our_pages = map_data ? 0 : 1;
-
-       nr_pages = DIV_ROUND_UP(offset + len, PAGE_SIZE);
-       if (nr_pages > BIO_MAX_PAGES)
-               nr_pages = BIO_MAX_PAGES;
-
-       ret = -ENOMEM;
-       bio = bio_kmalloc(gfp_mask, nr_pages);
-       if (!bio)
-               goto out_bmd;
-
-       ret = 0;
-
-       if (map_data) {
-               nr_pages = 1 << map_data->page_order;
-               i = map_data->offset / PAGE_SIZE;
-       }
-       while (len) {
-               unsigned int bytes = PAGE_SIZE;
-
-               bytes -= offset;
-
-               if (bytes > len)
-                       bytes = len;
-
-               if (map_data) {
-                       if (i == map_data->nr_entries * nr_pages) {
-                               ret = -ENOMEM;
-                               break;
-                       }
-
-                       page = map_data->pages[i / nr_pages];
-                       page += (i % nr_pages);
-
-                       i++;
-               } else {
-                       page = alloc_page(q->bounce_gfp | gfp_mask);
-                       if (!page) {
-                               ret = -ENOMEM;
-                               break;
-                       }
-               }
-
-               if (bio_add_pc_page(q, bio, page, bytes, offset) < bytes) {
-                       if (!map_data)
-                               __free_page(page);
-                       break;
-               }
-
-               len -= bytes;
-               offset = 0;
-       }
-
-       if (ret)
-               goto cleanup;
-
-       if (map_data)
-               map_data->offset += bio->bi_iter.bi_size;
-
-       /*
-        * success
-        */
-       if ((iov_iter_rw(iter) == WRITE && (!map_data || !map_data->null_mapped)) ||
-           (map_data && map_data->from_user)) {
-               ret = bio_copy_from_iter(bio, iter);
-               if (ret)
-                       goto cleanup;
-       } else {
-               if (bmd->is_our_pages)
-                       zero_fill_bio(bio);
-               iov_iter_advance(iter, bio->bi_iter.bi_size);
-       }
-
-       bio->bi_private = bmd;
-       if (map_data && map_data->null_mapped)
-               bio_set_flag(bio, BIO_NULL_MAPPED);
-       return bio;
-cleanup:
-       if (!map_data)
-               bio_free_pages(bio);
-       bio_put(bio);
-out_bmd:
-       kfree(bmd);
-       return ERR_PTR(ret);
-}
-
-/**
- *     bio_map_user_iov - map user iovec into bio
- *     @q:             the struct request_queue for the bio
- *     @iter:          iovec iterator
- *     @gfp_mask:      memory allocation flags
- *
- *     Map the user space address into a bio suitable for io to a block
- *     device. Returns an error pointer in case of error.
- */
-struct bio *bio_map_user_iov(struct request_queue *q,
-                            struct iov_iter *iter,
-                            gfp_t gfp_mask)
-{
-       int j;
-       struct bio *bio;
-       int ret;
-
-       if (!iov_iter_count(iter))
-               return ERR_PTR(-EINVAL);
-
-       bio = bio_kmalloc(gfp_mask, iov_iter_npages(iter, BIO_MAX_PAGES));
-       if (!bio)
-               return ERR_PTR(-ENOMEM);
-
-       while (iov_iter_count(iter)) {
-               struct page **pages;
-               ssize_t bytes;
-               size_t offs, added = 0;
-               int npages;
-
-               bytes = iov_iter_get_pages_alloc(iter, &pages, LONG_MAX, &offs);
-               if (unlikely(bytes <= 0)) {
-                       ret = bytes ? bytes : -EFAULT;
-                       goto out_unmap;
-               }
-
-               npages = DIV_ROUND_UP(offs + bytes, PAGE_SIZE);
-
-               if (unlikely(offs & queue_dma_alignment(q))) {
-                       ret = -EINVAL;
-                       j = 0;
-               } else {
-                       for (j = 0; j < npages; j++) {
-                               struct page *page = pages[j];
-                               unsigned int n = PAGE_SIZE - offs;
-                               bool same_page = false;
-
-                               if (n > bytes)
-                                       n = bytes;
-
-                               if (!__bio_add_pc_page(q, bio, page, n, offs,
-                                               &same_page)) {
-                                       if (same_page)
-                                               put_page(page);
-                                       break;
-                               }
-
-                               added += n;
-                               bytes -= n;
-                               offs = 0;
-                       }
-                       iov_iter_advance(iter, added);
-               }
-               /*
-                * release the pages we didn't map into the bio, if any
-                */
-               while (j < npages)
-                       put_page(pages[j++]);
-               kvfree(pages);
-               /* couldn't stuff something into bio? */
-               if (bytes)
-                       break;
-       }
-
-       bio_set_flag(bio, BIO_USER_MAPPED);
-
-       /*
-        * subtle -- if bio_map_user_iov() ended up bouncing a bio,
-        * it would normally disappear when its bi_end_io is run.
-        * however, we need it for the unmap, so grab an extra
-        * reference to it
-        */
-       bio_get(bio);
-       return bio;
-
- out_unmap:
-       bio_release_pages(bio, false);
-       bio_put(bio);
-       return ERR_PTR(ret);
-}
-
-/**
- *     bio_unmap_user  -       unmap a bio
- *     @bio:           the bio being unmapped
- *
- *     Unmap a bio previously mapped by bio_map_user_iov(). Must be called from
- *     process context.
- *
- *     bio_unmap_user() may sleep.
- */
-void bio_unmap_user(struct bio *bio)
-{
-       bio_release_pages(bio, bio_data_dir(bio) == READ);
-       bio_put(bio);
-       bio_put(bio);
-}
-
-static void bio_invalidate_vmalloc_pages(struct bio *bio)
-{
-#ifdef ARCH_HAS_FLUSH_KERNEL_DCACHE_PAGE
-       if (bio->bi_private && !op_is_write(bio_op(bio))) {
-               unsigned long i, len = 0;
-
-               for (i = 0; i < bio->bi_vcnt; i++)
-                       len += bio->bi_io_vec[i].bv_len;
-               invalidate_kernel_vmap_range(bio->bi_private, len);
-       }
-#endif
-}
-
-static void bio_map_kern_endio(struct bio *bio)
-{
-       bio_invalidate_vmalloc_pages(bio);
-       bio_put(bio);
-}
-
-/**
- *     bio_map_kern    -       map kernel address into bio
- *     @q: the struct request_queue for the bio
- *     @data: pointer to buffer to map
- *     @len: length in bytes
- *     @gfp_mask: allocation flags for bio allocation
- *
- *     Map the kernel address into a bio suitable for io to a block
- *     device. Returns an error pointer in case of error.
- */
-struct bio *bio_map_kern(struct request_queue *q, void *data, unsigned int len,
-                        gfp_t gfp_mask)
-{
-       unsigned long kaddr = (unsigned long)data;
-       unsigned long end = (kaddr + len + PAGE_SIZE - 1) >> PAGE_SHIFT;
-       unsigned long start = kaddr >> PAGE_SHIFT;
-       const int nr_pages = end - start;
-       bool is_vmalloc = is_vmalloc_addr(data);
-       struct page *page;
-       int offset, i;
-       struct bio *bio;
-
-       bio = bio_kmalloc(gfp_mask, nr_pages);
-       if (!bio)
-               return ERR_PTR(-ENOMEM);
-
-       if (is_vmalloc) {
-               flush_kernel_vmap_range(data, len);
-               bio->bi_private = data;
-       }
-
-       offset = offset_in_page(kaddr);
-       for (i = 0; i < nr_pages; i++) {
-               unsigned int bytes = PAGE_SIZE - offset;
-
-               if (len <= 0)
-                       break;
-
-               if (bytes > len)
-                       bytes = len;
-
-               if (!is_vmalloc)
-                       page = virt_to_page(data);
-               else
-                       page = vmalloc_to_page(data);
-               if (bio_add_pc_page(q, bio, page, bytes,
-                                   offset) < bytes) {
-                       /* we don't support partial mappings */
-                       bio_put(bio);
-                       return ERR_PTR(-EINVAL);
-               }
-
-               data += bytes;
-               len -= bytes;
-               offset = 0;
-       }
-
-       bio->bi_end_io = bio_map_kern_endio;
-       return bio;
-}
-
-static void bio_copy_kern_endio(struct bio *bio)
-{
-       bio_free_pages(bio);
-       bio_put(bio);
-}
-
-static void bio_copy_kern_endio_read(struct bio *bio)
-{
-       char *p = bio->bi_private;
-       struct bio_vec *bvec;
-       struct bvec_iter_all iter_all;
-
-       bio_for_each_segment_all(bvec, bio, iter_all) {
-               memcpy(p, page_address(bvec->bv_page), bvec->bv_len);
-               p += bvec->bv_len;
-       }
-
-       bio_copy_kern_endio(bio);
-}
-
-/**
- *     bio_copy_kern   -       copy kernel address into bio
- *     @q: the struct request_queue for the bio
- *     @data: pointer to buffer to copy
- *     @len: length in bytes
- *     @gfp_mask: allocation flags for bio and page allocation
- *     @reading: data direction is READ
- *
- *     copy the kernel address into a bio suitable for io to a block
- *     device. Returns an error pointer in case of error.
- */
-struct bio *bio_copy_kern(struct request_queue *q, void *data, unsigned int len,
-                         gfp_t gfp_mask, int reading)
-{
-       unsigned long kaddr = (unsigned long)data;
-       unsigned long end = (kaddr + len + PAGE_SIZE - 1) >> PAGE_SHIFT;
-       unsigned long start = kaddr >> PAGE_SHIFT;
-       struct bio *bio;
-       void *p = data;
-       int nr_pages = 0;
-
-       /*
-        * Overflow, abort
-        */
-       if (end < start)
-               return ERR_PTR(-EINVAL);
-
-       nr_pages = end - start;
-       bio = bio_kmalloc(gfp_mask, nr_pages);
-       if (!bio)
-               return ERR_PTR(-ENOMEM);
-
-       while (len) {
-               struct page *page;
-               unsigned int bytes = PAGE_SIZE;
-
-               if (bytes > len)
-                       bytes = len;
-
-               page = alloc_page(q->bounce_gfp | gfp_mask);
-               if (!page)
-                       goto cleanup;
-
-               if (!reading)
-                       memcpy(page_address(page), p, bytes);
-
-               if (bio_add_pc_page(q, bio, page, bytes, 0) < bytes)
-                       break;
-
-               len -= bytes;
-               p += bytes;
-       }
-
-       if (reading) {
-               bio->bi_end_io = bio_copy_kern_endio_read;
-               bio->bi_private = data;
-       } else {
-               bio->bi_end_io = bio_copy_kern_endio;
-       }
-
-       return bio;
-
-cleanup:
-       bio_free_pages(bio);
-       bio_put(bio);
-       return ERR_PTR(-ENOMEM);
-}
-
 /*
  * bio_set_pages_dirty() and bio_check_pages_dirty() are support functions
  * for performing direct-IO in BIOs.
@@ -1752,14 +1303,14 @@ defer:
        schedule_work(&bio_dirty_work);
 }
 
-void update_io_ticks(struct hd_struct *part, unsigned long now)
+void update_io_ticks(struct hd_struct *part, unsigned long now, bool end)
 {
        unsigned long stamp;
 again:
        stamp = READ_ONCE(part->stamp);
        if (unlikely(stamp != now)) {
                if (likely(cmpxchg(&part->stamp, stamp, now) == stamp)) {
-                       __part_stat_add(part, io_ticks, 1);
+                       __part_stat_add(part, io_ticks, end ? now - stamp : 1);
                }
        }
        if (part->partno) {
@@ -1775,7 +1326,7 @@ void generic_start_io_acct(struct request_queue *q, int op,
 
        part_stat_lock();
 
-       update_io_ticks(part, jiffies);
+       update_io_ticks(part, jiffies, false);
        part_stat_inc(part, ios[sgrp]);
        part_stat_add(part, sectors[sgrp], sectors);
        part_inc_in_flight(q, part, op_is_write(op));
@@ -1793,9 +1344,8 @@ void generic_end_io_acct(struct request_queue *q, int req_op,
 
        part_stat_lock();
 
-       update_io_ticks(part, now);
+       update_io_ticks(part, now, true);
        part_stat_add(part, nsecs[sgrp], jiffies_to_nsecs(duration));
-       part_stat_add(part, time_in_queue, duration);
        part_dec_in_flight(q, part, op_is_write(req_op));
 
        part_stat_unlock();
index a229b94..c15a260 100644 (file)
@@ -1010,7 +1010,7 @@ unlock:
  * blkcg_init_queue - initialize blkcg part of request queue
  * @q: request_queue to initialize
  *
- * Called from blk_alloc_queue_node(). Responsible for initializing blkcg
+ * Called from __blk_alloc_queue(). Responsible for initializing blkcg
  * part of new request_queue @q.
  *
  * RETURNS:
index 60dc955..7e4a1da 100644 (file)
@@ -346,7 +346,6 @@ void blk_cleanup_queue(struct request_queue *q)
 
        blk_queue_flag_set(QUEUE_FLAG_NOMERGES, q);
        blk_queue_flag_set(QUEUE_FLAG_NOXMERGES, q);
-       blk_queue_flag_set(QUEUE_FLAG_DYING, q);
 
        /*
         * Drain all requests queued before DYING marking. Set DEAD flag to
@@ -389,12 +388,6 @@ void blk_cleanup_queue(struct request_queue *q)
 }
 EXPORT_SYMBOL(blk_cleanup_queue);
 
-struct request_queue *blk_alloc_queue(gfp_t gfp_mask)
-{
-       return blk_alloc_queue_node(gfp_mask, NUMA_NO_NODE);
-}
-EXPORT_SYMBOL(blk_alloc_queue);
-
 /**
  * blk_queue_enter() - try to increase q->q_usage_counter
  * @q: request queue pointer
@@ -471,24 +464,19 @@ static void blk_timeout_work(struct work_struct *work)
 {
 }
 
-/**
- * blk_alloc_queue_node - allocate a request queue
- * @gfp_mask: memory allocation flags
- * @node_id: NUMA node to allocate memory from
- */
-struct request_queue *blk_alloc_queue_node(gfp_t gfp_mask, int node_id)
+struct request_queue *__blk_alloc_queue(int node_id)
 {
        struct request_queue *q;
        int ret;
 
        q = kmem_cache_alloc_node(blk_requestq_cachep,
-                               gfp_mask | __GFP_ZERO, node_id);
+                               GFP_KERNEL | __GFP_ZERO, node_id);
        if (!q)
                return NULL;
 
        q->last_merge = NULL;
 
-       q->id = ida_simple_get(&blk_queue_ida, 0, 0, gfp_mask);
+       q->id = ida_simple_get(&blk_queue_ida, 0, 0, GFP_KERNEL);
        if (q->id < 0)
                goto fail_q;
 
@@ -496,7 +484,7 @@ struct request_queue *blk_alloc_queue_node(gfp_t gfp_mask, int node_id)
        if (ret)
                goto fail_id;
 
-       q->backing_dev_info = bdi_alloc_node(gfp_mask, node_id);
+       q->backing_dev_info = bdi_alloc_node(GFP_KERNEL, node_id);
        if (!q->backing_dev_info)
                goto fail_split;
 
@@ -542,6 +530,9 @@ struct request_queue *blk_alloc_queue_node(gfp_t gfp_mask, int node_id)
        if (blkcg_init_queue(q))
                goto fail_ref;
 
+       blk_queue_dma_alignment(q, 511);
+       blk_set_default_limits(&q->limits);
+
        return q;
 
 fail_ref:
@@ -558,7 +549,22 @@ fail_q:
        kmem_cache_free(blk_requestq_cachep, q);
        return NULL;
 }
-EXPORT_SYMBOL(blk_alloc_queue_node);
+
+struct request_queue *blk_alloc_queue(make_request_fn make_request, int node_id)
+{
+       struct request_queue *q;
+
+       if (WARN_ON_ONCE(!make_request))
+               return NULL;
+
+       q = __blk_alloc_queue(node_id);
+       if (!q)
+               return NULL;
+       q->make_request_fn = make_request;
+       q->nr_requests = BLKDEV_MAX_RQ;
+       return q;
+}
+EXPORT_SYMBOL(blk_alloc_queue);
 
 bool blk_get_queue(struct request_queue *q)
 {
@@ -1121,10 +1127,9 @@ blk_qc_t direct_make_request(struct bio *bio)
 
        if (unlikely(blk_queue_enter(q, nowait ? BLK_MQ_REQ_NOWAIT : 0))) {
                if (nowait && !blk_queue_dying(q))
-                       bio->bi_status = BLK_STS_AGAIN;
+                       bio_wouldblock_error(bio);
                else
-                       bio->bi_status = BLK_STS_IOERR;
-               bio_endio(bio);
+                       bio_io_error(bio);
                return BLK_QC_T_NONE;
        }
 
@@ -1203,7 +1208,7 @@ EXPORT_SYMBOL(submit_bio);
 
 /**
  * blk_cloned_rq_check_limits - Helper function to check a cloned request
- *                              for new the queue limits
+ *                              for the new queue limits
  * @q:  the queue
  * @rq: the request being checked
  *
@@ -1339,10 +1344,9 @@ void blk_account_io_done(struct request *req, u64 now)
                part_stat_lock();
                part = req->part;
 
-               update_io_ticks(part, jiffies);
+               update_io_ticks(part, jiffies, true);
                part_stat_inc(part, ios[sgrp]);
                part_stat_add(part, nsecs[sgrp], now - req->start_time_ns);
-               part_stat_add(part, time_in_queue, nsecs_to_jiffies64(now - req->start_time_ns));
                part_dec_in_flight(req->q, part, rq_data_dir(req));
 
                hd_struct_put(part);
@@ -1381,7 +1385,7 @@ void blk_account_io_start(struct request *rq, bool new_io)
                rq->part = part;
        }
 
-       update_io_ticks(part, jiffies);
+       update_io_ticks(part, jiffies, false);
 
        part_stat_unlock();
 }
@@ -1583,23 +1587,6 @@ void blk_rq_unprep_clone(struct request *rq)
 }
 EXPORT_SYMBOL_GPL(blk_rq_unprep_clone);
 
-/*
- * Copy attributes of the original request to the clone request.
- * The actual data parts (e.g. ->cmd, ->sense) are not copied.
- */
-static void __blk_rq_prep_clone(struct request *dst, struct request *src)
-{
-       dst->__sector = blk_rq_pos(src);
-       dst->__data_len = blk_rq_bytes(src);
-       if (src->rq_flags & RQF_SPECIAL_PAYLOAD) {
-               dst->rq_flags |= RQF_SPECIAL_PAYLOAD;
-               dst->special_vec = src->special_vec;
-       }
-       dst->nr_phys_segments = src->nr_phys_segments;
-       dst->ioprio = src->ioprio;
-       dst->extra_len = src->extra_len;
-}
-
 /**
  * blk_rq_prep_clone - Helper function to setup clone request
  * @rq: the request to be setup
@@ -1612,8 +1599,6 @@ static void __blk_rq_prep_clone(struct request *dst, struct request *src)
  *
  * Description:
  *     Clones bios in @rq_src to @rq, and copies attributes of @rq_src to @rq.
- *     The actual data parts of @rq_src (e.g. ->cmd, ->sense)
- *     are not copied, and copying such parts is the caller's responsibility.
  *     Also, pages which the original bios are pointing to are not copied
  *     and the cloned bios just point same pages.
  *     So cloned bios must be completed before original bios, which means
@@ -1644,7 +1629,16 @@ int blk_rq_prep_clone(struct request *rq, struct request *rq_src,
                        rq->bio = rq->biotail = bio;
        }
 
-       __blk_rq_prep_clone(rq, rq_src);
+       /* Copy attributes of the original request to the clone request. */
+       rq->__sector = blk_rq_pos(rq_src);
+       rq->__data_len = blk_rq_bytes(rq_src);
+       if (rq_src->rq_flags & RQF_SPECIAL_PAYLOAD) {
+               rq->rq_flags |= RQF_SPECIAL_PAYLOAD;
+               rq->special_vec = rq_src->special_vec;
+       }
+       rq->nr_phys_segments = rq_src->nr_phys_segments;
+       rq->ioprio = rq_src->ioprio;
+       rq->extra_len = rq_src->extra_len;
 
        return 0;
 
index 5cc775b..c7f396e 100644 (file)
@@ -160,9 +160,6 @@ static void blk_account_io_flush(struct request *rq)
  *
  * CONTEXT:
  * spin_lock_irq(fq->mq_flush_lock)
- *
- * RETURNS:
- * %true if requests were added to the dispatch queue, %false otherwise.
  */
 static void blk_flush_complete_seq(struct request *rq,
                                   struct blk_flush_queue *fq,
@@ -457,15 +454,6 @@ int blkdev_issue_flush(struct block_device *bdev, gfp_t gfp_mask,
        if (!q)
                return -ENXIO;
 
-       /*
-        * some block devices may not have their queue correctly set up here
-        * (e.g. loop device without a backing file) and so issuing a flush
-        * here will panic. Ensure there is a request function before issuing
-        * the flush.
-        */
-       if (!q->make_request_fn)
-               return -ENXIO;
-
        bio = bio_alloc(gfp_mask, 0);
        bio_set_dev(bio, bdev);
        bio->bi_opf = REQ_OP_WRITE | REQ_PREFLUSH;
@@ -485,8 +473,8 @@ int blkdev_issue_flush(struct block_device *bdev, gfp_t gfp_mask,
 }
 EXPORT_SYMBOL(blkdev_issue_flush);
 
-struct blk_flush_queue *blk_alloc_flush_queue(struct request_queue *q,
-               int node, int cmd_size, gfp_t flags)
+struct blk_flush_queue *blk_alloc_flush_queue(int node, int cmd_size,
+                                             gfp_t flags)
 {
        struct blk_flush_queue *fq;
        int rq_sz = sizeof(struct request);
index 5ed59ac..9df50fb 100644 (file)
@@ -84,6 +84,7 @@ static void ioc_destroy_icq(struct io_cq *icq)
         * making it impossible to determine icq_cache.  Record it in @icq.
         */
        icq->__rcu_icq_cache = et->icq_cache;
+       icq->flags |= ICQ_DESTROYED;
        call_rcu(&icq->__rcu_head, icq_free_icq_rcu);
 }
 
@@ -212,15 +213,21 @@ static void __ioc_clear_queue(struct list_head *icq_list)
 {
        unsigned long flags;
 
+       rcu_read_lock();
        while (!list_empty(icq_list)) {
                struct io_cq *icq = list_entry(icq_list->next,
                                                struct io_cq, q_node);
                struct io_context *ioc = icq->ioc;
 
                spin_lock_irqsave(&ioc->lock, flags);
+               if (icq->flags & ICQ_DESTROYED) {
+                       spin_unlock_irqrestore(&ioc->lock, flags);
+                       continue;
+               }
                ioc_destroy_icq(icq);
                spin_unlock_irqrestore(&ioc->lock, flags);
        }
+       rcu_read_unlock();
 }
 
 /**
index 9a599cc..db35ee6 100644 (file)
@@ -46,9 +46,6 @@
  * If needed, tools/cgroup/iocost_coef_gen.py can be used to generate
  * device-specific coefficients.
  *
- * If needed, tools/cgroup/iocost_coef_gen.py can be used to generate
- * device-specific coefficients.
- *
  * 2. Control Strategy
  *
  * The device virtual time (vtime) is used as the primary control metric.
index b079026..b72c361 100644 (file)
 
 #include "blk.h"
 
+struct bio_map_data {
+       int is_our_pages;
+       struct iov_iter iter;
+       struct iovec iov[];
+};
+
+static struct bio_map_data *bio_alloc_map_data(struct iov_iter *data,
+                                              gfp_t gfp_mask)
+{
+       struct bio_map_data *bmd;
+
+       if (data->nr_segs > UIO_MAXIOV)
+               return NULL;
+
+       bmd = kmalloc(struct_size(bmd, iov, data->nr_segs), gfp_mask);
+       if (!bmd)
+               return NULL;
+       memcpy(bmd->iov, data->iov, sizeof(struct iovec) * data->nr_segs);
+       bmd->iter = *data;
+       bmd->iter.iov = bmd->iov;
+       return bmd;
+}
+
+/**
+ * bio_copy_from_iter - copy all pages from iov_iter to bio
+ * @bio: The &struct bio which describes the I/O as destination
+ * @iter: iov_iter as source
+ *
+ * Copy all pages from iov_iter to bio.
+ * Returns 0 on success, or error on failure.
+ */
+static int bio_copy_from_iter(struct bio *bio, struct iov_iter *iter)
+{
+       struct bio_vec *bvec;
+       struct bvec_iter_all iter_all;
+
+       bio_for_each_segment_all(bvec, bio, iter_all) {
+               ssize_t ret;
+
+               ret = copy_page_from_iter(bvec->bv_page,
+                                         bvec->bv_offset,
+                                         bvec->bv_len,
+                                         iter);
+
+               if (!iov_iter_count(iter))
+                       break;
+
+               if (ret < bvec->bv_len)
+                       return -EFAULT;
+       }
+
+       return 0;
+}
+
+/**
+ * bio_copy_to_iter - copy all pages from bio to iov_iter
+ * @bio: The &struct bio which describes the I/O as source
+ * @iter: iov_iter as destination
+ *
+ * Copy all pages from bio to iov_iter.
+ * Returns 0 on success, or error on failure.
+ */
+static int bio_copy_to_iter(struct bio *bio, struct iov_iter iter)
+{
+       struct bio_vec *bvec;
+       struct bvec_iter_all iter_all;
+
+       bio_for_each_segment_all(bvec, bio, iter_all) {
+               ssize_t ret;
+
+               ret = copy_page_to_iter(bvec->bv_page,
+                                       bvec->bv_offset,
+                                       bvec->bv_len,
+                                       &iter);
+
+               if (!iov_iter_count(&iter))
+                       break;
+
+               if (ret < bvec->bv_len)
+                       return -EFAULT;
+       }
+
+       return 0;
+}
+
+/**
+ *     bio_uncopy_user -       finish previously mapped bio
+ *     @bio: bio being terminated
+ *
+ *     Free pages allocated from bio_copy_user_iov() and write back data
+ *     to user space in case of a read.
+ */
+static int bio_uncopy_user(struct bio *bio)
+{
+       struct bio_map_data *bmd = bio->bi_private;
+       int ret = 0;
+
+       if (!bio_flagged(bio, BIO_NULL_MAPPED)) {
+               /*
+                * if we're in a workqueue, the request is orphaned, so
+                * don't copy into a random user address space, just free
+                * and return -EINTR so user space doesn't expect any data.
+                */
+               if (!current->mm)
+                       ret = -EINTR;
+               else if (bio_data_dir(bio) == READ)
+                       ret = bio_copy_to_iter(bio, bmd->iter);
+               if (bmd->is_our_pages)
+                       bio_free_pages(bio);
+       }
+       kfree(bmd);
+       bio_put(bio);
+       return ret;
+}
+
+/**
+ *     bio_copy_user_iov       -       copy user data to bio
+ *     @q:             destination block queue
+ *     @map_data:      pointer to the rq_map_data holding pages (if necessary)
+ *     @iter:          iovec iterator
+ *     @gfp_mask:      memory allocation flags
+ *
+ *     Prepares and returns a bio for indirect user io, bouncing data
+ *     to/from kernel pages as necessary. Must be paired with
+ *     call bio_uncopy_user() on io completion.
+ */
+static struct bio *bio_copy_user_iov(struct request_queue *q,
+               struct rq_map_data *map_data, struct iov_iter *iter,
+               gfp_t gfp_mask)
+{
+       struct bio_map_data *bmd;
+       struct page *page;
+       struct bio *bio;
+       int i = 0, ret;
+       int nr_pages;
+       unsigned int len = iter->count;
+       unsigned int offset = map_data ? offset_in_page(map_data->offset) : 0;
+
+       bmd = bio_alloc_map_data(iter, gfp_mask);
+       if (!bmd)
+               return ERR_PTR(-ENOMEM);
+
+       /*
+        * We need to do a deep copy of the iov_iter including the iovecs.
+        * The caller provided iov might point to an on-stack or otherwise
+        * shortlived one.
+        */
+       bmd->is_our_pages = map_data ? 0 : 1;
+
+       nr_pages = DIV_ROUND_UP(offset + len, PAGE_SIZE);
+       if (nr_pages > BIO_MAX_PAGES)
+               nr_pages = BIO_MAX_PAGES;
+
+       ret = -ENOMEM;
+       bio = bio_kmalloc(gfp_mask, nr_pages);
+       if (!bio)
+               goto out_bmd;
+
+       ret = 0;
+
+       if (map_data) {
+               nr_pages = 1 << map_data->page_order;
+               i = map_data->offset / PAGE_SIZE;
+       }
+       while (len) {
+               unsigned int bytes = PAGE_SIZE;
+
+               bytes -= offset;
+
+               if (bytes > len)
+                       bytes = len;
+
+               if (map_data) {
+                       if (i == map_data->nr_entries * nr_pages) {
+                               ret = -ENOMEM;
+                               break;
+                       }
+
+                       page = map_data->pages[i / nr_pages];
+                       page += (i % nr_pages);
+
+                       i++;
+               } else {
+                       page = alloc_page(q->bounce_gfp | gfp_mask);
+                       if (!page) {
+                               ret = -ENOMEM;
+                               break;
+                       }
+               }
+
+               if (bio_add_pc_page(q, bio, page, bytes, offset) < bytes) {
+                       if (!map_data)
+                               __free_page(page);
+                       break;
+               }
+
+               len -= bytes;
+               offset = 0;
+       }
+
+       if (ret)
+               goto cleanup;
+
+       if (map_data)
+               map_data->offset += bio->bi_iter.bi_size;
+
+       /*
+        * success
+        */
+       if ((iov_iter_rw(iter) == WRITE &&
+            (!map_data || !map_data->null_mapped)) ||
+           (map_data && map_data->from_user)) {
+               ret = bio_copy_from_iter(bio, iter);
+               if (ret)
+                       goto cleanup;
+       } else {
+               if (bmd->is_our_pages)
+                       zero_fill_bio(bio);
+               iov_iter_advance(iter, bio->bi_iter.bi_size);
+       }
+
+       bio->bi_private = bmd;
+       if (map_data && map_data->null_mapped)
+               bio_set_flag(bio, BIO_NULL_MAPPED);
+       return bio;
+cleanup:
+       if (!map_data)
+               bio_free_pages(bio);
+       bio_put(bio);
+out_bmd:
+       kfree(bmd);
+       return ERR_PTR(ret);
+}
+
+/**
+ *     bio_map_user_iov - map user iovec into bio
+ *     @q:             the struct request_queue for the bio
+ *     @iter:          iovec iterator
+ *     @gfp_mask:      memory allocation flags
+ *
+ *     Map the user space address into a bio suitable for io to a block
+ *     device. Returns an error pointer in case of error.
+ */
+static struct bio *bio_map_user_iov(struct request_queue *q,
+               struct iov_iter *iter, gfp_t gfp_mask)
+{
+       int j;
+       struct bio *bio;
+       int ret;
+
+       if (!iov_iter_count(iter))
+               return ERR_PTR(-EINVAL);
+
+       bio = bio_kmalloc(gfp_mask, iov_iter_npages(iter, BIO_MAX_PAGES));
+       if (!bio)
+               return ERR_PTR(-ENOMEM);
+
+       while (iov_iter_count(iter)) {
+               struct page **pages;
+               ssize_t bytes;
+               size_t offs, added = 0;
+               int npages;
+
+               bytes = iov_iter_get_pages_alloc(iter, &pages, LONG_MAX, &offs);
+               if (unlikely(bytes <= 0)) {
+                       ret = bytes ? bytes : -EFAULT;
+                       goto out_unmap;
+               }
+
+               npages = DIV_ROUND_UP(offs + bytes, PAGE_SIZE);
+
+               if (unlikely(offs & queue_dma_alignment(q))) {
+                       ret = -EINVAL;
+                       j = 0;
+               } else {
+                       for (j = 0; j < npages; j++) {
+                               struct page *page = pages[j];
+                               unsigned int n = PAGE_SIZE - offs;
+                               bool same_page = false;
+
+                               if (n > bytes)
+                                       n = bytes;
+
+                               if (!__bio_add_pc_page(q, bio, page, n, offs,
+                                               &same_page)) {
+                                       if (same_page)
+                                               put_page(page);
+                                       break;
+                               }
+
+                               added += n;
+                               bytes -= n;
+                               offs = 0;
+                       }
+                       iov_iter_advance(iter, added);
+               }
+               /*
+                * release the pages we didn't map into the bio, if any
+                */
+               while (j < npages)
+                       put_page(pages[j++]);
+               kvfree(pages);
+               /* couldn't stuff something into bio? */
+               if (bytes)
+                       break;
+       }
+
+       bio_set_flag(bio, BIO_USER_MAPPED);
+
+       /*
+        * subtle -- if bio_map_user_iov() ended up bouncing a bio,
+        * it would normally disappear when its bi_end_io is run.
+        * however, we need it for the unmap, so grab an extra
+        * reference to it
+        */
+       bio_get(bio);
+       return bio;
+
+ out_unmap:
+       bio_release_pages(bio, false);
+       bio_put(bio);
+       return ERR_PTR(ret);
+}
+
+/**
+ *     bio_unmap_user  -       unmap a bio
+ *     @bio:           the bio being unmapped
+ *
+ *     Unmap a bio previously mapped by bio_map_user_iov(). Must be called from
+ *     process context.
+ *
+ *     bio_unmap_user() may sleep.
+ */
+static void bio_unmap_user(struct bio *bio)
+{
+       bio_release_pages(bio, bio_data_dir(bio) == READ);
+       bio_put(bio);
+       bio_put(bio);
+}
+
+static void bio_invalidate_vmalloc_pages(struct bio *bio)
+{
+#ifdef ARCH_HAS_FLUSH_KERNEL_DCACHE_PAGE
+       if (bio->bi_private && !op_is_write(bio_op(bio))) {
+               unsigned long i, len = 0;
+
+               for (i = 0; i < bio->bi_vcnt; i++)
+                       len += bio->bi_io_vec[i].bv_len;
+               invalidate_kernel_vmap_range(bio->bi_private, len);
+       }
+#endif
+}
+
+static void bio_map_kern_endio(struct bio *bio)
+{
+       bio_invalidate_vmalloc_pages(bio);
+       bio_put(bio);
+}
+
+/**
+ *     bio_map_kern    -       map kernel address into bio
+ *     @q: the struct request_queue for the bio
+ *     @data: pointer to buffer to map
+ *     @len: length in bytes
+ *     @gfp_mask: allocation flags for bio allocation
+ *
+ *     Map the kernel address into a bio suitable for io to a block
+ *     device. Returns an error pointer in case of error.
+ */
+static struct bio *bio_map_kern(struct request_queue *q, void *data,
+               unsigned int len, gfp_t gfp_mask)
+{
+       unsigned long kaddr = (unsigned long)data;
+       unsigned long end = (kaddr + len + PAGE_SIZE - 1) >> PAGE_SHIFT;
+       unsigned long start = kaddr >> PAGE_SHIFT;
+       const int nr_pages = end - start;
+       bool is_vmalloc = is_vmalloc_addr(data);
+       struct page *page;
+       int offset, i;
+       struct bio *bio;
+
+       bio = bio_kmalloc(gfp_mask, nr_pages);
+       if (!bio)
+               return ERR_PTR(-ENOMEM);
+
+       if (is_vmalloc) {
+               flush_kernel_vmap_range(data, len);
+               bio->bi_private = data;
+       }
+
+       offset = offset_in_page(kaddr);
+       for (i = 0; i < nr_pages; i++) {
+               unsigned int bytes = PAGE_SIZE - offset;
+
+               if (len <= 0)
+                       break;
+
+               if (bytes > len)
+                       bytes = len;
+
+               if (!is_vmalloc)
+                       page = virt_to_page(data);
+               else
+                       page = vmalloc_to_page(data);
+               if (bio_add_pc_page(q, bio, page, bytes,
+                                   offset) < bytes) {
+                       /* we don't support partial mappings */
+                       bio_put(bio);
+                       return ERR_PTR(-EINVAL);
+               }
+
+               data += bytes;
+               len -= bytes;
+               offset = 0;
+       }
+
+       bio->bi_end_io = bio_map_kern_endio;
+       return bio;
+}
+
+static void bio_copy_kern_endio(struct bio *bio)
+{
+       bio_free_pages(bio);
+       bio_put(bio);
+}
+
+static void bio_copy_kern_endio_read(struct bio *bio)
+{
+       char *p = bio->bi_private;
+       struct bio_vec *bvec;
+       struct bvec_iter_all iter_all;
+
+       bio_for_each_segment_all(bvec, bio, iter_all) {
+               memcpy(p, page_address(bvec->bv_page), bvec->bv_len);
+               p += bvec->bv_len;
+       }
+
+       bio_copy_kern_endio(bio);
+}
+
+/**
+ *     bio_copy_kern   -       copy kernel address into bio
+ *     @q: the struct request_queue for the bio
+ *     @data: pointer to buffer to copy
+ *     @len: length in bytes
+ *     @gfp_mask: allocation flags for bio and page allocation
+ *     @reading: data direction is READ
+ *
+ *     copy the kernel address into a bio suitable for io to a block
+ *     device. Returns an error pointer in case of error.
+ */
+static struct bio *bio_copy_kern(struct request_queue *q, void *data,
+               unsigned int len, gfp_t gfp_mask, int reading)
+{
+       unsigned long kaddr = (unsigned long)data;
+       unsigned long end = (kaddr + len + PAGE_SIZE - 1) >> PAGE_SHIFT;
+       unsigned long start = kaddr >> PAGE_SHIFT;
+       struct bio *bio;
+       void *p = data;
+       int nr_pages = 0;
+
+       /*
+        * Overflow, abort
+        */
+       if (end < start)
+               return ERR_PTR(-EINVAL);
+
+       nr_pages = end - start;
+       bio = bio_kmalloc(gfp_mask, nr_pages);
+       if (!bio)
+               return ERR_PTR(-ENOMEM);
+
+       while (len) {
+               struct page *page;
+               unsigned int bytes = PAGE_SIZE;
+
+               if (bytes > len)
+                       bytes = len;
+
+               page = alloc_page(q->bounce_gfp | gfp_mask);
+               if (!page)
+                       goto cleanup;
+
+               if (!reading)
+                       memcpy(page_address(page), p, bytes);
+
+               if (bio_add_pc_page(q, bio, page, bytes, 0) < bytes)
+                       break;
+
+               len -= bytes;
+               p += bytes;
+       }
+
+       if (reading) {
+               bio->bi_end_io = bio_copy_kern_endio_read;
+               bio->bi_private = data;
+       } else {
+               bio->bi_end_io = bio_copy_kern_endio;
+       }
+
+       return bio;
+
+cleanup:
+       bio_free_pages(bio);
+       bio_put(bio);
+       return ERR_PTR(-ENOMEM);
+}
+
 /*
  * Append a bio to a passthrough request.  Only works if the bio can be merged
  * into the request based on the driver constraints.
index d92088d..f6291ce 100644 (file)
@@ -1178,6 +1178,23 @@ static void blk_mq_update_dispatch_busy(struct blk_mq_hw_ctx *hctx, bool busy)
 
 #define BLK_MQ_RESOURCE_DELAY  3               /* ms units */
 
+static void blk_mq_handle_dev_resource(struct request *rq,
+                                      struct list_head *list)
+{
+       struct request *next =
+               list_first_entry_or_null(list, struct request, queuelist);
+
+       /*
+        * If an I/O scheduler has been configured and we got a driver tag for
+        * the next request already, free it.
+        */
+       if (next)
+               blk_mq_put_driver_tag(next);
+
+       list_add(&rq->queuelist, list);
+       __blk_mq_requeue_request(rq);
+}
+
 /*
  * Returns true if we did some work AND can potentially do more.
  */
@@ -1245,17 +1262,7 @@ bool blk_mq_dispatch_rq_list(struct request_queue *q, struct list_head *list,
 
                ret = q->mq_ops->queue_rq(hctx, &bd);
                if (ret == BLK_STS_RESOURCE || ret == BLK_STS_DEV_RESOURCE) {
-                       /*
-                        * If an I/O scheduler has been configured and we got a
-                        * driver tag for the next request already, free it
-                        * again.
-                        */
-                       if (!list_empty(list)) {
-                               nxt = list_first_entry(list, struct request, queuelist);
-                               blk_mq_put_driver_tag(nxt);
-                       }
-                       list_add(&rq->queuelist, list);
-                       __blk_mq_requeue_request(rq);
+                       blk_mq_handle_dev_resource(rq, list);
                        break;
                }
 
@@ -2409,8 +2416,7 @@ blk_mq_alloc_hctx(struct request_queue *q, struct blk_mq_tag_set *set,
        init_waitqueue_func_entry(&hctx->dispatch_wait, blk_mq_dispatch_wake);
        INIT_LIST_HEAD(&hctx->dispatch_wait.entry);
 
-       hctx->fq = blk_alloc_flush_queue(q, hctx->numa_node, set->cmd_size,
-                       gfp);
+       hctx->fq = blk_alloc_flush_queue(hctx->numa_node, set->cmd_size, gfp);
        if (!hctx->fq)
                goto free_bitmap;
 
@@ -2718,13 +2724,15 @@ void blk_mq_release(struct request_queue *q)
        blk_mq_sysfs_deinit(q);
 }
 
-struct request_queue *blk_mq_init_queue(struct blk_mq_tag_set *set)
+struct request_queue *blk_mq_init_queue_data(struct blk_mq_tag_set *set,
+               void *queuedata)
 {
        struct request_queue *uninit_q, *q;
 
-       uninit_q = blk_alloc_queue_node(GFP_KERNEL, set->numa_node);
+       uninit_q = __blk_alloc_queue(set->numa_node);
        if (!uninit_q)
                return ERR_PTR(-ENOMEM);
+       uninit_q->queuedata = queuedata;
 
        /*
         * Initialize the queue without an elevator. device_add_disk() will do
@@ -2736,6 +2744,12 @@ struct request_queue *blk_mq_init_queue(struct blk_mq_tag_set *set)
 
        return q;
 }
+EXPORT_SYMBOL_GPL(blk_mq_init_queue_data);
+
+struct request_queue *blk_mq_init_queue(struct blk_mq_tag_set *set)
+{
+       return blk_mq_init_queue_data(set, NULL);
+}
 EXPORT_SYMBOL(blk_mq_init_queue);
 
 /*
@@ -2824,7 +2838,6 @@ static void blk_mq_realloc_hw_ctxs(struct blk_mq_tag_set *set,
                        memcpy(new_hctxs, hctxs, q->nr_hw_queues *
                               sizeof(*hctxs));
                q->queue_hw_ctx = new_hctxs;
-               q->nr_hw_queues = set->nr_hw_queues;
                kfree(hctxs);
                hctxs = new_hctxs;
        }
@@ -2926,11 +2939,7 @@ struct request_queue *blk_mq_init_allocated_queue(struct blk_mq_tag_set *set,
        INIT_LIST_HEAD(&q->requeue_list);
        spin_lock_init(&q->requeue_lock);
 
-       blk_queue_make_request(q, blk_mq_make_request);
-
-       /*
-        * Do this after blk_queue_make_request() overrides it...
-        */
+       q->make_request_fn = blk_mq_make_request;
        q->nr_requests = set->queue_depth;
 
        /*
@@ -3023,6 +3032,14 @@ static int blk_mq_alloc_rq_maps(struct blk_mq_tag_set *set)
 
 static int blk_mq_update_queue_map(struct blk_mq_tag_set *set)
 {
+       /*
+        * blk_mq_map_queues() and multiple .map_queues() implementations
+        * expect that set->map[HCTX_TYPE_DEFAULT].nr_queues is set to the
+        * number of hardware queues.
+        */
+       if (set->nr_maps == 1)
+               set->map[HCTX_TYPE_DEFAULT].nr_queues = set->nr_hw_queues;
+
        if (set->ops->map_queues && !is_kdump_kernel()) {
                int i;
 
index c8eda2e..14397b4 100644 (file)
@@ -87,42 +87,6 @@ void blk_set_stacking_limits(struct queue_limits *lim)
 EXPORT_SYMBOL(blk_set_stacking_limits);
 
 /**
- * blk_queue_make_request - define an alternate make_request function for a device
- * @q:  the request queue for the device to be affected
- * @mfn: the alternate make_request function
- *
- * Description:
- *    The normal way for &struct bios to be passed to a device
- *    driver is for them to be collected into requests on a request
- *    queue, and then to allow the device driver to select requests
- *    off that queue when it is ready.  This works well for many block
- *    devices. However some block devices (typically virtual devices
- *    such as md or lvm) do not benefit from the processing on the
- *    request queue, and are served best by having the requests passed
- *    directly to them.  This can be achieved by providing a function
- *    to blk_queue_make_request().
- *
- * Caveat:
- *    The driver that does this *must* be able to deal appropriately
- *    with buffers in "highmemory". This can be accomplished by either calling
- *    kmap_atomic() to get a temporary kernel mapping, or by calling
- *    blk_queue_bounce() to create a buffer in normal memory.
- **/
-void blk_queue_make_request(struct request_queue *q, make_request_fn *mfn)
-{
-       /*
-        * set defaults
-        */
-       q->nr_requests = BLKDEV_MAX_RQ;
-
-       q->make_request_fn = mfn;
-       blk_queue_dma_alignment(q, 511);
-
-       blk_set_default_limits(&q->limits);
-}
-EXPORT_SYMBOL(blk_queue_make_request);
-
-/**
  * blk_queue_bounce_limit - set bounce buffer limit for queue
  * @q: the request queue for the device
  * @max_addr: the maximum address the device can handle
@@ -664,6 +628,9 @@ void disk_stack_limits(struct gendisk *disk, struct block_device *bdev,
                printk(KERN_NOTICE "%s: Warning: Device %s is misaligned\n",
                       top, bottom);
        }
+
+       t->backing_dev_info->io_pages =
+               t->limits.max_sectors >> (PAGE_SHIFT - 9);
 }
 EXPORT_SYMBOL(disk_stack_limits);
 
index 05741c6..f87956e 100644 (file)
 
 #include "blk.h"
 
+#define ZONE_COND_NAME(name) [BLK_ZONE_COND_##name] = #name
+static const char *const zone_cond_name[] = {
+       ZONE_COND_NAME(NOT_WP),
+       ZONE_COND_NAME(EMPTY),
+       ZONE_COND_NAME(IMP_OPEN),
+       ZONE_COND_NAME(EXP_OPEN),
+       ZONE_COND_NAME(CLOSED),
+       ZONE_COND_NAME(READONLY),
+       ZONE_COND_NAME(FULL),
+       ZONE_COND_NAME(OFFLINE),
+};
+#undef ZONE_COND_NAME
+
+/**
+ * blk_zone_cond_str - Return string XXX in BLK_ZONE_COND_XXX.
+ * @zone_cond: BLK_ZONE_COND_XXX.
+ *
+ * Description: Centralize block layer function to convert BLK_ZONE_COND_XXX
+ * into string format. Useful in the debugging and tracing zone conditions. For
+ * invalid BLK_ZONE_COND_XXX it returns string "UNKNOWN".
+ */
+const char *blk_zone_cond_str(enum blk_zone_cond zone_cond)
+{
+       static const char *zone_cond_str = "UNKNOWN";
+
+       if (zone_cond < ARRAY_SIZE(zone_cond_name) && zone_cond_name[zone_cond])
+               zone_cond_str = zone_cond_name[zone_cond];
+
+       return zone_cond_str;
+}
+EXPORT_SYMBOL_GPL(blk_zone_cond_str);
+
 static inline sector_t blk_zone_start(struct request_queue *q,
                                      sector_t sector)
 {
@@ -173,7 +205,7 @@ int blkdev_zone_mgmt(struct block_device *bdev, enum req_opf op,
        if (!op_is_zone_mgmt(op))
                return -EOPNOTSUPP;
 
-       if (!nr_sectors || end_sector > capacity)
+       if (end_sector <= sector || end_sector > capacity)
                /* Out of range */
                return -EINVAL;
 
index 0b88843..0a94ec6 100644 (file)
@@ -4,6 +4,7 @@
 
 #include <linux/idr.h>
 #include <linux/blk-mq.h>
+#include <linux/part_stat.h>
 #include <xen/xen.h>
 #include "blk-mq.h"
 #include "blk-mq-sched.h"
@@ -55,8 +56,8 @@ is_flush_rq(struct request *req, struct blk_mq_hw_ctx *hctx)
        return hctx->fq->flush_rq == req;
 }
 
-struct blk_flush_queue *blk_alloc_flush_queue(struct request_queue *q,
-               int node, int cmd_size, gfp_t flags);
+struct blk_flush_queue *blk_alloc_flush_queue(int node, int cmd_size,
+                                             gfp_t flags);
 void blk_free_flush_queue(struct blk_flush_queue *q);
 
 void blk_freeze_queue(struct request_queue *q);
@@ -149,6 +150,9 @@ static inline bool integrity_req_gap_front_merge(struct request *req,
        return bvec_gap_to_prev(req->q, &bip->bip_vec[bip->bip_vcnt - 1],
                                bip_next->bip_vec[0].bv_offset);
 }
+
+void blk_integrity_add(struct gendisk *);
+void blk_integrity_del(struct gendisk *);
 #else /* CONFIG_BLK_DEV_INTEGRITY */
 static inline bool integrity_req_gap_back_merge(struct request *req,
                struct bio *next)
@@ -171,6 +175,12 @@ static inline bool bio_integrity_endio(struct bio *bio)
 static inline void bio_integrity_free(struct bio *bio)
 {
 }
+static inline void blk_integrity_add(struct gendisk *disk)
+{
+}
+static inline void blk_integrity_del(struct gendisk *disk)
+{
+}
 #endif /* CONFIG_BLK_DEV_INTEGRITY */
 
 unsigned long blk_rq_timeout(unsigned long timeout);
@@ -214,6 +224,17 @@ static inline void elevator_exit(struct request_queue *q,
 
 struct hd_struct *__disk_get_part(struct gendisk *disk, int partno);
 
+ssize_t part_size_show(struct device *dev, struct device_attribute *attr,
+               char *buf);
+ssize_t part_stat_show(struct device *dev, struct device_attribute *attr,
+               char *buf);
+ssize_t part_inflight_show(struct device *dev, struct device_attribute *attr,
+               char *buf);
+ssize_t part_fail_show(struct device *dev, struct device_attribute *attr,
+               char *buf);
+ssize_t part_fail_store(struct device *dev, struct device_attribute *attr,
+               const char *buf, size_t count);
+
 #ifdef CONFIG_FAIL_IO_TIMEOUT
 int blk_should_fake_timeout(struct request_queue *);
 ssize_t part_timeout_show(struct device *, struct device_attribute *, char *);
@@ -354,4 +375,117 @@ void blk_queue_free_zone_bitmaps(struct request_queue *q);
 static inline void blk_queue_free_zone_bitmaps(struct request_queue *q) {}
 #endif
 
+void part_dec_in_flight(struct request_queue *q, struct hd_struct *part,
+                       int rw);
+void part_inc_in_flight(struct request_queue *q, struct hd_struct *part,
+                       int rw);
+void update_io_ticks(struct hd_struct *part, unsigned long now, bool end);
+struct hd_struct *disk_map_sector_rcu(struct gendisk *disk, sector_t sector);
+
+int blk_alloc_devt(struct hd_struct *part, dev_t *devt);
+void blk_free_devt(dev_t devt);
+void blk_invalidate_devt(dev_t devt);
+char *disk_name(struct gendisk *hd, int partno, char *buf);
+#define ADDPART_FLAG_NONE      0
+#define ADDPART_FLAG_RAID      1
+#define ADDPART_FLAG_WHOLEDISK 2
+struct hd_struct *__must_check add_partition(struct gendisk *disk, int partno,
+               sector_t start, sector_t len, int flags,
+               struct partition_meta_info *info);
+void __delete_partition(struct percpu_ref *ref);
+void delete_partition(struct gendisk *disk, int partno);
+int disk_expand_part_tbl(struct gendisk *disk, int target);
+
+static inline int hd_ref_init(struct hd_struct *part)
+{
+       if (percpu_ref_init(&part->ref, __delete_partition, 0,
+                               GFP_KERNEL))
+               return -ENOMEM;
+       return 0;
+}
+
+static inline void hd_struct_get(struct hd_struct *part)
+{
+       percpu_ref_get(&part->ref);
+}
+
+static inline int hd_struct_try_get(struct hd_struct *part)
+{
+       return percpu_ref_tryget_live(&part->ref);
+}
+
+static inline void hd_struct_put(struct hd_struct *part)
+{
+       percpu_ref_put(&part->ref);
+}
+
+static inline void hd_struct_kill(struct hd_struct *part)
+{
+       percpu_ref_kill(&part->ref);
+}
+
+static inline void hd_free_part(struct hd_struct *part)
+{
+       free_part_stats(part);
+       kfree(part->info);
+       percpu_ref_exit(&part->ref);
+}
+
+/*
+ * Any access of part->nr_sects which is not protected by partition
+ * bd_mutex or gendisk bdev bd_mutex, should be done using this
+ * accessor function.
+ *
+ * Code written along the lines of i_size_read() and i_size_write().
+ * CONFIG_PREEMPTION case optimizes the case of UP kernel with preemption
+ * on.
+ */
+static inline sector_t part_nr_sects_read(struct hd_struct *part)
+{
+#if BITS_PER_LONG==32 && defined(CONFIG_SMP)
+       sector_t nr_sects;
+       unsigned seq;
+       do {
+               seq = read_seqcount_begin(&part->nr_sects_seq);
+               nr_sects = part->nr_sects;
+       } while (read_seqcount_retry(&part->nr_sects_seq, seq));
+       return nr_sects;
+#elif BITS_PER_LONG==32 && defined(CONFIG_PREEMPTION)
+       sector_t nr_sects;
+
+       preempt_disable();
+       nr_sects = part->nr_sects;
+       preempt_enable();
+       return nr_sects;
+#else
+       return part->nr_sects;
+#endif
+}
+
+/*
+ * Should be called with mutex lock held (typically bd_mutex) of partition
+ * to provide mutual exlusion among writers otherwise seqcount might be
+ * left in wrong state leaving the readers spinning infinitely.
+ */
+static inline void part_nr_sects_write(struct hd_struct *part, sector_t size)
+{
+#if BITS_PER_LONG==32 && defined(CONFIG_SMP)
+       write_seqcount_begin(&part->nr_sects_seq);
+       part->nr_sects = size;
+       write_seqcount_end(&part->nr_sects_seq);
+#elif BITS_PER_LONG==32 && defined(CONFIG_PREEMPTION)
+       preempt_disable();
+       part->nr_sects = size;
+       preempt_enable();
+#else
+       part->nr_sects = size;
+#endif
+}
+
+struct request_queue *__blk_alloc_queue(int node_id);
+
+int __bio_add_pc_page(struct request_queue *q, struct bio *bio,
+               struct page *page, unsigned int len, unsigned int offset,
+               bool *same_page);
+
 #endif /* BLK_INTERNAL_H */
index 9c2e13c..06b642b 100644 (file)
@@ -4,6 +4,7 @@
  */
 
 #include <linux/module.h>
+#include <linux/ctype.h>
 #include <linux/fs.h>
 #include <linux/genhd.h>
 #include <linux/kdev_t.h>
@@ -26,7 +27,7 @@
 #include "blk.h"
 
 static DEFINE_MUTEX(block_class_lock);
-struct kobject *block_depr;
+static struct kobject *block_depr;
 
 /* for extended dynamic devt allocation, currently only one major is used */
 #define NR_EXT_DEVT            (1 << MINORBITS)
@@ -46,6 +47,78 @@ static void disk_add_events(struct gendisk *disk);
 static void disk_del_events(struct gendisk *disk);
 static void disk_release_events(struct gendisk *disk);
 
+/*
+ * Set disk capacity and notify if the size is not currently
+ * zero and will not be set to zero
+ */
+void set_capacity_revalidate_and_notify(struct gendisk *disk, sector_t size,
+                                       bool revalidate)
+{
+       sector_t capacity = get_capacity(disk);
+
+       set_capacity(disk, size);
+
+       if (revalidate)
+               revalidate_disk(disk);
+
+       if (capacity != size && capacity != 0 && size != 0) {
+               char *envp[] = { "RESIZE=1", NULL };
+
+               kobject_uevent_env(&disk_to_dev(disk)->kobj, KOBJ_CHANGE, envp);
+       }
+}
+
+EXPORT_SYMBOL_GPL(set_capacity_revalidate_and_notify);
+
+/*
+ * Format the device name of the indicated disk into the supplied buffer and
+ * return a pointer to that same buffer for convenience.
+ */
+char *disk_name(struct gendisk *hd, int partno, char *buf)
+{
+       if (!partno)
+               snprintf(buf, BDEVNAME_SIZE, "%s", hd->disk_name);
+       else if (isdigit(hd->disk_name[strlen(hd->disk_name)-1]))
+               snprintf(buf, BDEVNAME_SIZE, "%sp%d", hd->disk_name, partno);
+       else
+               snprintf(buf, BDEVNAME_SIZE, "%s%d", hd->disk_name, partno);
+
+       return buf;
+}
+
+const char *bdevname(struct block_device *bdev, char *buf)
+{
+       return disk_name(bdev->bd_disk, bdev->bd_part->partno, buf);
+}
+EXPORT_SYMBOL(bdevname);
+
+#ifdef CONFIG_SMP
+static void part_stat_read_all(struct hd_struct *part, struct disk_stats *stat)
+{
+       int cpu;
+
+       memset(stat, 0, sizeof(struct disk_stats));
+       for_each_possible_cpu(cpu) {
+               struct disk_stats *ptr = per_cpu_ptr(part->dkstats, cpu);
+               int group;
+
+               for (group = 0; group < NR_STAT_GROUPS; group++) {
+                       stat->nsecs[group] += ptr->nsecs[group];
+                       stat->sectors[group] += ptr->sectors[group];
+                       stat->ios[group] += ptr->ios[group];
+                       stat->merges[group] += ptr->merges[group];
+               }
+
+               stat->io_ticks += ptr->io_ticks;
+       }
+}
+#else /* CONFIG_SMP */
+static void part_stat_read_all(struct hd_struct *part, struct disk_stats *stat)
+{
+       memcpy(stat, &part->dkstats, sizeof(struct disk_stats));
+}
+#endif /* CONFIG_SMP */
+
 void part_inc_in_flight(struct request_queue *q, struct hd_struct *part, int rw)
 {
        if (queue_is_mq(q))
@@ -66,7 +139,8 @@ void part_dec_in_flight(struct request_queue *q, struct hd_struct *part, int rw)
                part_stat_local_dec(&part_to_disk(part)->part0, in_flight[rw]);
 }
 
-unsigned int part_in_flight(struct request_queue *q, struct hd_struct *part)
+static unsigned int part_in_flight(struct request_queue *q,
+               struct hd_struct *part)
 {
        int cpu;
        unsigned int inflight;
@@ -86,8 +160,8 @@ unsigned int part_in_flight(struct request_queue *q, struct hd_struct *part)
        return inflight;
 }
 
-void part_in_flight_rw(struct request_queue *q, struct hd_struct *part,
-                      unsigned int inflight[2])
+static void part_in_flight_rw(struct request_queue *q, struct hd_struct *part,
+               unsigned int inflight[2])
 {
        int cpu;
 
@@ -143,7 +217,6 @@ struct hd_struct *disk_get_part(struct gendisk *disk, int partno)
 
        return part;
 }
-EXPORT_SYMBOL_GPL(disk_get_part);
 
 /**
  * disk_part_iter_init - initialize partition iterator
@@ -299,7 +372,6 @@ struct hd_struct *disk_map_sector_rcu(struct gendisk *disk, sector_t sector)
        }
        return &disk->part0;
 }
-EXPORT_SYMBOL_GPL(disk_map_sector_rcu);
 
 /**
  * disk_has_partitions
@@ -944,7 +1016,6 @@ struct gendisk *get_gendisk(dev_t devt, int *partno)
        }
        return disk;
 }
-EXPORT_SYMBOL(get_gendisk);
 
 /**
  * bdget_disk - do bdget() by gendisk and partition number
@@ -1190,6 +1261,67 @@ static ssize_t disk_ro_show(struct device *dev,
        return sprintf(buf, "%d\n", get_disk_ro(disk) ? 1 : 0);
 }
 
+ssize_t part_size_show(struct device *dev,
+                      struct device_attribute *attr, char *buf)
+{
+       struct hd_struct *p = dev_to_part(dev);
+
+       return sprintf(buf, "%llu\n",
+               (unsigned long long)part_nr_sects_read(p));
+}
+
+ssize_t part_stat_show(struct device *dev,
+                      struct device_attribute *attr, char *buf)
+{
+       struct hd_struct *p = dev_to_part(dev);
+       struct request_queue *q = part_to_disk(p)->queue;
+       struct disk_stats stat;
+       unsigned int inflight;
+
+       part_stat_read_all(p, &stat);
+       inflight = part_in_flight(q, p);
+
+       return sprintf(buf,
+               "%8lu %8lu %8llu %8u "
+               "%8lu %8lu %8llu %8u "
+               "%8u %8u %8u "
+               "%8lu %8lu %8llu %8u "
+               "%8lu %8u"
+               "\n",
+               stat.ios[STAT_READ],
+               stat.merges[STAT_READ],
+               (unsigned long long)stat.sectors[STAT_READ],
+               (unsigned int)div_u64(stat.nsecs[STAT_READ], NSEC_PER_MSEC),
+               stat.ios[STAT_WRITE],
+               stat.merges[STAT_WRITE],
+               (unsigned long long)stat.sectors[STAT_WRITE],
+               (unsigned int)div_u64(stat.nsecs[STAT_WRITE], NSEC_PER_MSEC),
+               inflight,
+               jiffies_to_msecs(stat.io_ticks),
+               (unsigned int)div_u64(stat.nsecs[STAT_READ] +
+                                     stat.nsecs[STAT_WRITE] +
+                                     stat.nsecs[STAT_DISCARD] +
+                                     stat.nsecs[STAT_FLUSH],
+                                               NSEC_PER_MSEC),
+               stat.ios[STAT_DISCARD],
+               stat.merges[STAT_DISCARD],
+               (unsigned long long)stat.sectors[STAT_DISCARD],
+               (unsigned int)div_u64(stat.nsecs[STAT_DISCARD], NSEC_PER_MSEC),
+               stat.ios[STAT_FLUSH],
+               (unsigned int)div_u64(stat.nsecs[STAT_FLUSH], NSEC_PER_MSEC));
+}
+
+ssize_t part_inflight_show(struct device *dev, struct device_attribute *attr,
+                          char *buf)
+{
+       struct hd_struct *p = dev_to_part(dev);
+       struct request_queue *q = part_to_disk(p)->queue;
+       unsigned int inflight[2];
+
+       part_in_flight_rw(q, p, inflight);
+       return sprintf(buf, "%8u %8u\n", inflight[0], inflight[1]);
+}
+
 static ssize_t disk_capability_show(struct device *dev,
                                    struct device_attribute *attr, char *buf)
 {
@@ -1228,10 +1360,33 @@ static DEVICE_ATTR(capability, 0444, disk_capability_show, NULL);
 static DEVICE_ATTR(stat, 0444, part_stat_show, NULL);
 static DEVICE_ATTR(inflight, 0444, part_inflight_show, NULL);
 static DEVICE_ATTR(badblocks, 0644, disk_badblocks_show, disk_badblocks_store);
+
 #ifdef CONFIG_FAIL_MAKE_REQUEST
+ssize_t part_fail_show(struct device *dev,
+                      struct device_attribute *attr, char *buf)
+{
+       struct hd_struct *p = dev_to_part(dev);
+
+       return sprintf(buf, "%d\n", p->make_it_fail);
+}
+
+ssize_t part_fail_store(struct device *dev,
+                       struct device_attribute *attr,
+                       const char *buf, size_t count)
+{
+       struct hd_struct *p = dev_to_part(dev);
+       int i;
+
+       if (count > 0 && sscanf(buf, "%d", &i) > 0)
+               p->make_it_fail = (i == 0) ? 0 : 1;
+
+       return count;
+}
+
 static struct device_attribute dev_attr_fail =
        __ATTR(make-it-fail, 0644, part_fail_show, part_fail_store);
-#endif
+#endif /* CONFIG_FAIL_MAKE_REQUEST */
+
 #ifdef CONFIG_FAIL_IO_TIMEOUT
 static struct device_attribute dev_attr_fail_timeout =
        __ATTR(io-timeout-fail, 0644, part_timeout_show, part_timeout_store);
@@ -1378,8 +1533,8 @@ static char *block_devnode(struct device *dev, umode_t *mode,
 {
        struct gendisk *disk = dev_to_disk(dev);
 
-       if (disk->devnode)
-               return disk->devnode(disk, mode);
+       if (disk->fops->devnode)
+               return disk->fops->devnode(disk, mode);
        return NULL;
 }
 
@@ -1405,6 +1560,7 @@ static int diskstats_show(struct seq_file *seqf, void *v)
        struct hd_struct *hd;
        char buf[BDEVNAME_SIZE];
        unsigned int inflight;
+       struct disk_stats stat;
 
        /*
        if (&disk_to_dev(gp)->kobj.entry == block_class.devices.next)
@@ -1416,7 +1572,9 @@ static int diskstats_show(struct seq_file *seqf, void *v)
 
        disk_part_iter_init(&piter, gp, DISK_PITER_INCL_EMPTY_PART0);
        while ((hd = disk_part_iter_next(&piter))) {
+               part_stat_read_all(hd, &stat);
                inflight = part_in_flight(gp->queue, hd);
+
                seq_printf(seqf, "%4d %7d %s "
                           "%lu %lu %lu %u "
                           "%lu %lu %lu %u "
@@ -1426,23 +1584,31 @@ static int diskstats_show(struct seq_file *seqf, void *v)
                           "\n",
                           MAJOR(part_devt(hd)), MINOR(part_devt(hd)),
                           disk_name(gp, hd->partno, buf),
-                          part_stat_read(hd, ios[STAT_READ]),
-                          part_stat_read(hd, merges[STAT_READ]),
-                          part_stat_read(hd, sectors[STAT_READ]),
-                          (unsigned int)part_stat_read_msecs(hd, STAT_READ),
-                          part_stat_read(hd, ios[STAT_WRITE]),
-                          part_stat_read(hd, merges[STAT_WRITE]),
-                          part_stat_read(hd, sectors[STAT_WRITE]),
-                          (unsigned int)part_stat_read_msecs(hd, STAT_WRITE),
+                          stat.ios[STAT_READ],
+                          stat.merges[STAT_READ],
+                          stat.sectors[STAT_READ],
+                          (unsigned int)div_u64(stat.nsecs[STAT_READ],
+                                                       NSEC_PER_MSEC),
+                          stat.ios[STAT_WRITE],
+                          stat.merges[STAT_WRITE],
+                          stat.sectors[STAT_WRITE],
+                          (unsigned int)div_u64(stat.nsecs[STAT_WRITE],
+                                                       NSEC_PER_MSEC),
                           inflight,
-                          jiffies_to_msecs(part_stat_read(hd, io_ticks)),
-                          jiffies_to_msecs(part_stat_read(hd, time_in_queue)),
-                          part_stat_read(hd, ios[STAT_DISCARD]),
-                          part_stat_read(hd, merges[STAT_DISCARD]),
-                          part_stat_read(hd, sectors[STAT_DISCARD]),
-                          (unsigned int)part_stat_read_msecs(hd, STAT_DISCARD),
-                          part_stat_read(hd, ios[STAT_FLUSH]),
-                          (unsigned int)part_stat_read_msecs(hd, STAT_FLUSH)
+                          jiffies_to_msecs(stat.io_ticks),
+                          (unsigned int)div_u64(stat.nsecs[STAT_READ] +
+                                                stat.nsecs[STAT_WRITE] +
+                                                stat.nsecs[STAT_DISCARD] +
+                                                stat.nsecs[STAT_FLUSH],
+                                                       NSEC_PER_MSEC),
+                          stat.ios[STAT_DISCARD],
+                          stat.merges[STAT_DISCARD],
+                          stat.sectors[STAT_DISCARD],
+                          (unsigned int)div_u64(stat.nsecs[STAT_DISCARD],
+                                                NSEC_PER_MSEC),
+                          stat.ios[STAT_FLUSH],
+                          (unsigned int)div_u64(stat.nsecs[STAT_FLUSH],
+                                                NSEC_PER_MSEC)
                        );
        }
        disk_part_iter_exit(&piter);
@@ -1499,7 +1665,6 @@ dev_t blk_lookup_devt(const char *name, int partno)
        class_dev_iter_exit(&iter);
        return devt;
 }
-EXPORT_SYMBOL(blk_lookup_devt);
 
 struct gendisk *__alloc_disk_node(int minors, int node_id)
 {
index 127194b..6e827de 100644 (file)
@@ -11,6 +11,7 @@
 #include <linux/blktrace_api.h>
 #include <linux/pr.h>
 #include <linux/uaccess.h>
+#include "blk.h"
 
 static int blkpg_do_ioctl(struct block_device *bdev,
                          struct blkpg_partition __user *upart, int op)
index 325cbba..b486b3e 100644 (file)
@@ -36,6 +36,7 @@ enum opal_response_token {
 
 #define DTAERROR_NO_METHOD_STATUS 0x89
 #define GENERIC_HOST_SESSION_NUM 0x41
+#define FIRST_TPER_SESSION_NUM 4096
 
 #define TPER_SYNC_SUPPORTED 0x01
 #define MBR_ENABLED_MASK 0x10
index 2f276b6..a7f05cd 100644 (file)
@@ -3,8 +3,7 @@
 # Makefile for the linux kernel.
 #
 
-obj-$(CONFIG_BLOCK) := check.o
-
+obj-$(CONFIG_BLOCK) += core.o
 obj-$(CONFIG_ACORN_PARTITION) += acorn.o
 obj-$(CONFIG_AMIGA_PARTITION) += amiga.o
 obj-$(CONFIG_ATARI_PARTITION) += atari.o
index 7587700..c64c57b 100644 (file)
@@ -11,7 +11,6 @@
 #include <linux/adfs_fs.h>
 
 #include "check.h"
-#include "acorn.h"
 
 /*
  * Partition types. (Oh for reusability)
diff --git a/block/partitions/acorn.h b/block/partitions/acorn.h
deleted file mode 100644 (file)
index 67b0660..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 */
-/*
- * linux/fs/partitions/acorn.h
- *
- * Copyright (C) 1996-2001 Russell King.
- *
- *  I _hate_ this partitioning mess - why can't we have one defined
- *  format, and everyone stick to it?
- */
-
-int adfspart_check_CUMANA(struct parsed_partitions *state);
-int adfspart_check_ADFS(struct parsed_partitions *state);
-int adfspart_check_ICS(struct parsed_partitions *state);
-int adfspart_check_POWERTEC(struct parsed_partitions *state);
-int adfspart_check_EESOX(struct parsed_partitions *state);
index 903f3ed..c7b4fd1 100644 (file)
@@ -6,7 +6,6 @@
  */
 
 #include "check.h"
-#include "aix.h"
 
 struct lvm_rec {
        char lvm_id[4]; /* "_LVM" */
diff --git a/block/partitions/aix.h b/block/partitions/aix.h
deleted file mode 100644 (file)
index b4449f0..0000000
+++ /dev/null
@@ -1,2 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 */
-extern int aix_partition(struct parsed_partitions *state);
index 5609366..9526491 100644 (file)
@@ -14,7 +14,6 @@
 #include <linux/affs_hardblocks.h>
 
 #include "check.h"
-#include "amiga.h"
 
 static __inline__ u32
 checksum_block(__be32 *m, int size)
@@ -42,9 +41,8 @@ int amiga_partition(struct parsed_partitions *state)
                        goto rdb_done;
                data = read_part_sector(state, blk, &sect);
                if (!data) {
-                       if (warn_no_part)
-                               pr_err("Dev %s: unable to read RDB block %d\n",
-                                      bdevname(state->bdev, b), blk);
+                       pr_err("Dev %s: unable to read RDB block %d\n",
+                              bdevname(state->bdev, b), blk);
                        res = -1;
                        goto rdb_done;
                }
@@ -85,9 +83,8 @@ int amiga_partition(struct parsed_partitions *state)
                blk *= blksize; /* Read in terms partition table understands */
                data = read_part_sector(state, blk, &sect);
                if (!data) {
-                       if (warn_no_part)
-                               pr_err("Dev %s: unable to read partition block %d\n",
-                                      bdevname(state->bdev, b), blk);
+                       pr_err("Dev %s: unable to read partition block %d\n",
+                              bdevname(state->bdev, b), blk);
                        res = -1;
                        goto rdb_done;
                }
diff --git a/block/partitions/amiga.h b/block/partitions/amiga.h
deleted file mode 100644 (file)
index 7e63f4d..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 */
-/*
- *  fs/partitions/amiga.h
- */
-
-int amiga_partition(struct parsed_partitions *state);
-
index 01c2b94..6782024 100644 (file)
@@ -34,4 +34,3 @@ struct rootsector
   u16 checksum;                        /* checksum for bootable disks */
 } __packed;
 
-int atari_partition(struct parsed_partitions *state);
diff --git a/block/partitions/check.c b/block/partitions/check.c
deleted file mode 100644 (file)
index ffe408f..0000000
+++ /dev/null
@@ -1,198 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0
-/*
- *  fs/partitions/check.c
- *
- *  Code extracted from drivers/block/genhd.c
- *  Copyright (C) 1991-1998  Linus Torvalds
- *  Re-organised Feb 1998 Russell King
- *
- *  We now have independent partition support from the
- *  block drivers, which allows all the partition code to
- *  be grouped in one location, and it to be mostly self
- *  contained.
- *
- *  Added needed MAJORS for new pairs, {hdi,hdj}, {hdk,hdl}
- */
-
-#include <linux/slab.h>
-#include <linux/vmalloc.h>
-#include <linux/ctype.h>
-#include <linux/genhd.h>
-
-#include "check.h"
-
-#include "acorn.h"
-#include "amiga.h"
-#include "atari.h"
-#include "ldm.h"
-#include "mac.h"
-#include "msdos.h"
-#include "osf.h"
-#include "sgi.h"
-#include "sun.h"
-#include "ibm.h"
-#include "ultrix.h"
-#include "efi.h"
-#include "karma.h"
-#include "sysv68.h"
-#include "cmdline.h"
-
-int warn_no_part = 1; /*This is ugly: should make genhd removable media aware*/
-
-static int (*check_part[])(struct parsed_partitions *) = {
-       /*
-        * Probe partition formats with tables at disk address 0
-        * that also have an ADFS boot block at 0xdc0.
-        */
-#ifdef CONFIG_ACORN_PARTITION_ICS
-       adfspart_check_ICS,
-#endif
-#ifdef CONFIG_ACORN_PARTITION_POWERTEC
-       adfspart_check_POWERTEC,
-#endif
-#ifdef CONFIG_ACORN_PARTITION_EESOX
-       adfspart_check_EESOX,
-#endif
-
-       /*
-        * Now move on to formats that only have partition info at
-        * disk address 0xdc0.  Since these may also have stale
-        * PC/BIOS partition tables, they need to come before
-        * the msdos entry.
-        */
-#ifdef CONFIG_ACORN_PARTITION_CUMANA
-       adfspart_check_CUMANA,
-#endif
-#ifdef CONFIG_ACORN_PARTITION_ADFS
-       adfspart_check_ADFS,
-#endif
-
-#ifdef CONFIG_CMDLINE_PARTITION
-       cmdline_partition,
-#endif
-#ifdef CONFIG_EFI_PARTITION
-       efi_partition,          /* this must come before msdos */
-#endif
-#ifdef CONFIG_SGI_PARTITION
-       sgi_partition,
-#endif
-#ifdef CONFIG_LDM_PARTITION
-       ldm_partition,          /* this must come before msdos */
-#endif
-#ifdef CONFIG_MSDOS_PARTITION
-       msdos_partition,
-#endif
-#ifdef CONFIG_OSF_PARTITION
-       osf_partition,
-#endif
-#ifdef CONFIG_SUN_PARTITION
-       sun_partition,
-#endif
-#ifdef CONFIG_AMIGA_PARTITION
-       amiga_partition,
-#endif
-#ifdef CONFIG_ATARI_PARTITION
-       atari_partition,
-#endif
-#ifdef CONFIG_MAC_PARTITION
-       mac_partition,
-#endif
-#ifdef CONFIG_ULTRIX_PARTITION
-       ultrix_partition,
-#endif
-#ifdef CONFIG_IBM_PARTITION
-       ibm_partition,
-#endif
-#ifdef CONFIG_KARMA_PARTITION
-       karma_partition,
-#endif
-#ifdef CONFIG_SYSV68_PARTITION
-       sysv68_partition,
-#endif
-       NULL
-};
-
-static struct parsed_partitions *allocate_partitions(struct gendisk *hd)
-{
-       struct parsed_partitions *state;
-       int nr;
-
-       state = kzalloc(sizeof(*state), GFP_KERNEL);
-       if (!state)
-               return NULL;
-
-       nr = disk_max_parts(hd);
-       state->parts = vzalloc(array_size(nr, sizeof(state->parts[0])));
-       if (!state->parts) {
-               kfree(state);
-               return NULL;
-       }
-
-       state->limit = nr;
-
-       return state;
-}
-
-void free_partitions(struct parsed_partitions *state)
-{
-       vfree(state->parts);
-       kfree(state);
-}
-
-struct parsed_partitions *
-check_partition(struct gendisk *hd, struct block_device *bdev)
-{
-       struct parsed_partitions *state;
-       int i, res, err;
-
-       state = allocate_partitions(hd);
-       if (!state)
-               return NULL;
-       state->pp_buf = (char *)__get_free_page(GFP_KERNEL);
-       if (!state->pp_buf) {
-               free_partitions(state);
-               return NULL;
-       }
-       state->pp_buf[0] = '\0';
-
-       state->bdev = bdev;
-       disk_name(hd, 0, state->name);
-       snprintf(state->pp_buf, PAGE_SIZE, " %s:", state->name);
-       if (isdigit(state->name[strlen(state->name)-1]))
-               sprintf(state->name, "p");
-
-       i = res = err = 0;
-       while (!res && check_part[i]) {
-               memset(state->parts, 0, state->limit * sizeof(state->parts[0]));
-               res = check_part[i++](state);
-               if (res < 0) {
-                       /* We have hit an I/O error which we don't report now.
-                       * But record it, and let the others do their job.
-                       */
-                       err = res;
-                       res = 0;
-               }
-
-       }
-       if (res > 0) {
-               printk(KERN_INFO "%s", state->pp_buf);
-
-               free_page((unsigned long)state->pp_buf);
-               return state;
-       }
-       if (state->access_beyond_eod)
-               err = -ENOSPC;
-       if (err)
-       /* The partition is unrecognized. So report I/O errors if there were any */
-               res = err;
-       if (res) {
-               if (warn_no_part)
-                       strlcat(state->pp_buf,
-                               " unable to read partition table\n", PAGE_SIZE);
-               printk(KERN_INFO "%s", state->pp_buf);
-       }
-
-       free_page((unsigned long)state->pp_buf);
-       free_partitions(state);
-       return ERR_PTR(res);
-}
index 6042f76..c577e9e 100644 (file)
@@ -2,6 +2,7 @@
 #include <linux/pagemap.h>
 #include <linux/blkdev.h>
 #include <linux/genhd.h>
+#include "../blk.h"
 
 /*
  * add_gd_partition adds a partitions details to the devices partition
@@ -23,19 +24,14 @@ struct parsed_partitions {
        char *pp_buf;
 };
 
-void free_partitions(struct parsed_partitions *state);
+typedef struct {
+       struct page *v;
+} Sector;
 
-struct parsed_partitions *
-check_partition(struct gendisk *, struct block_device *);
-
-static inline void *read_part_sector(struct parsed_partitions *state,
-                                    sector_t n, Sector *p)
+void *read_part_sector(struct parsed_partitions *state, sector_t n, Sector *p);
+static inline void put_dev_sector(Sector p)
 {
-       if (n >= get_capacity(state->bdev->bd_disk)) {
-               state->access_beyond_eod = true;
-               return NULL;
-       }
-       return read_dev_sector(state->bdev, n, p);
+       put_page(p.v);
 }
 
 static inline void
@@ -51,5 +47,24 @@ put_partition(struct parsed_partitions *p, int n, sector_t from, sector_t size)
        }
 }
 
-extern int warn_no_part;
-
+/* detection routines go here in alphabetical order: */
+int adfspart_check_ADFS(struct parsed_partitions *state);
+int adfspart_check_CUMANA(struct parsed_partitions *state);
+int adfspart_check_EESOX(struct parsed_partitions *state);
+int adfspart_check_ICS(struct parsed_partitions *state);
+int adfspart_check_POWERTEC(struct parsed_partitions *state);
+int aix_partition(struct parsed_partitions *state);
+int amiga_partition(struct parsed_partitions *state);
+int atari_partition(struct parsed_partitions *state);
+int cmdline_partition(struct parsed_partitions *state);
+int efi_partition(struct parsed_partitions *state);
+int ibm_partition(struct parsed_partitions *);
+int karma_partition(struct parsed_partitions *state);
+int ldm_partition(struct parsed_partitions *state);
+int mac_partition(struct parsed_partitions *state);
+int msdos_partition(struct parsed_partitions *state);
+int osf_partition(struct parsed_partitions *state);
+int sgi_partition(struct parsed_partitions *state);
+int sun_partition(struct parsed_partitions *state);
+int sysv68_partition(struct parsed_partitions *state);
+int ultrix_partition(struct parsed_partitions *state);
index f1edd54..8f545c3 100644 (file)
@@ -18,7 +18,6 @@
 #include <linux/cmdline-parser.h>
 
 #include "check.h"
-#include "cmdline.h"
 
 static char *cmdline;
 static struct cmdline_parts *bdev_parts;
diff --git a/block/partitions/cmdline.h b/block/partitions/cmdline.h
deleted file mode 100644 (file)
index e64a316..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 */
-
-int cmdline_partition(struct parsed_partitions *state);
similarity index 72%
rename from block/partition-generic.c
rename to block/partitions/core.c
index 564fae7..b79c451 100644 (file)
 // SPDX-License-Identifier: GPL-2.0
 /*
- *  Code extracted from drivers/block/genhd.c
- *  Copyright (C) 1991-1998  Linus Torvalds
- *  Re-organised Feb 1998 Russell King
- *
- *  We now have independent partition support from the
- *  block drivers, which allows all the partition code to
- *  be grouped in one location, and it to be mostly self
- *  contained.
+ * Copyright (C) 1991-1998  Linus Torvalds
+ * Re-organised Feb 1998 Russell King
  */
-
-#include <linux/init.h>
-#include <linux/module.h>
 #include <linux/fs.h>
 #include <linux/slab.h>
-#include <linux/kmod.h>
 #include <linux/ctype.h>
 #include <linux/genhd.h>
+#include <linux/vmalloc.h>
 #include <linux/blktrace_api.h>
+#include <linux/raid/detect.h>
+#include "check.h"
 
-#include "partitions/check.h"
+static int (*check_part[])(struct parsed_partitions *) = {
+       /*
+        * Probe partition formats with tables at disk address 0
+        * that also have an ADFS boot block at 0xdc0.
+        */
+#ifdef CONFIG_ACORN_PARTITION_ICS
+       adfspart_check_ICS,
+#endif
+#ifdef CONFIG_ACORN_PARTITION_POWERTEC
+       adfspart_check_POWERTEC,
+#endif
+#ifdef CONFIG_ACORN_PARTITION_EESOX
+       adfspart_check_EESOX,
+#endif
 
-#ifdef CONFIG_BLK_DEV_MD
-extern void md_autodetect_dev(dev_t dev);
+       /*
+        * Now move on to formats that only have partition info at
+        * disk address 0xdc0.  Since these may also have stale
+        * PC/BIOS partition tables, they need to come before
+        * the msdos entry.
+        */
+#ifdef CONFIG_ACORN_PARTITION_CUMANA
+       adfspart_check_CUMANA,
+#endif
+#ifdef CONFIG_ACORN_PARTITION_ADFS
+       adfspart_check_ADFS,
 #endif
-/*
- * disk_name() is used by partition check code and the genhd driver.
- * It formats the devicename of the indicated disk into
- * the supplied buffer (of size at least 32), and returns
- * a pointer to that same buffer (for convenience).
- */
 
-char *disk_name(struct gendisk *hd, int partno, char *buf)
+#ifdef CONFIG_CMDLINE_PARTITION
+       cmdline_partition,
+#endif
+#ifdef CONFIG_EFI_PARTITION
+       efi_partition,          /* this must come before msdos */
+#endif
+#ifdef CONFIG_SGI_PARTITION
+       sgi_partition,
+#endif
+#ifdef CONFIG_LDM_PARTITION
+       ldm_partition,          /* this must come before msdos */
+#endif
+#ifdef CONFIG_MSDOS_PARTITION
+       msdos_partition,
+#endif
+#ifdef CONFIG_OSF_PARTITION
+       osf_partition,
+#endif
+#ifdef CONFIG_SUN_PARTITION
+       sun_partition,
+#endif
+#ifdef CONFIG_AMIGA_PARTITION
+       amiga_partition,
+#endif
+#ifdef CONFIG_ATARI_PARTITION
+       atari_partition,
+#endif
+#ifdef CONFIG_MAC_PARTITION
+       mac_partition,
+#endif
+#ifdef CONFIG_ULTRIX_PARTITION
+       ultrix_partition,
+#endif
+#ifdef CONFIG_IBM_PARTITION
+       ibm_partition,
+#endif
+#ifdef CONFIG_KARMA_PARTITION
+       karma_partition,
+#endif
+#ifdef CONFIG_SYSV68_PARTITION
+       sysv68_partition,
+#endif
+       NULL
+};
+
+static struct parsed_partitions *allocate_partitions(struct gendisk *hd)
 {
-       if (!partno)
-               snprintf(buf, BDEVNAME_SIZE, "%s", hd->disk_name);
-       else if (isdigit(hd->disk_name[strlen(hd->disk_name)-1]))
-               snprintf(buf, BDEVNAME_SIZE, "%sp%d", hd->disk_name, partno);
-       else
-               snprintf(buf, BDEVNAME_SIZE, "%s%d", hd->disk_name, partno);
+       struct parsed_partitions *state;
+       int nr;
 
-       return buf;
-}
+       state = kzalloc(sizeof(*state), GFP_KERNEL);
+       if (!state)
+               return NULL;
 
-const char *bdevname(struct block_device *bdev, char *buf)
-{
-       return disk_name(bdev->bd_disk, bdev->bd_part->partno, buf);
-}
+       nr = disk_max_parts(hd);
+       state->parts = vzalloc(array_size(nr, sizeof(state->parts[0])));
+       if (!state->parts) {
+               kfree(state);
+               return NULL;
+       }
 
-EXPORT_SYMBOL(bdevname);
+       state->limit = nr;
 
-const char *bio_devname(struct bio *bio, char *buf)
-{
-       return disk_name(bio->bi_disk, bio->bi_partno, buf);
+       return state;
 }
-EXPORT_SYMBOL(bio_devname);
 
-/*
- * There's very little reason to use this, you should really
- * have a struct block_device just about everywhere and use
- * bdevname() instead.
- */
-const char *__bdevname(dev_t dev, char *buffer)
+static void free_partitions(struct parsed_partitions *state)
 {
-       scnprintf(buffer, BDEVNAME_SIZE, "unknown-block(%u,%u)",
-                               MAJOR(dev), MINOR(dev));
-       return buffer;
+       vfree(state->parts);
+       kfree(state);
 }
 
-EXPORT_SYMBOL(__bdevname);
+static struct parsed_partitions *check_partition(struct gendisk *hd,
+               struct block_device *bdev)
+{
+       struct parsed_partitions *state;
+       int i, res, err;
+
+       state = allocate_partitions(hd);
+       if (!state)
+               return NULL;
+       state->pp_buf = (char *)__get_free_page(GFP_KERNEL);
+       if (!state->pp_buf) {
+               free_partitions(state);
+               return NULL;
+       }
+       state->pp_buf[0] = '\0';
+
+       state->bdev = bdev;
+       disk_name(hd, 0, state->name);
+       snprintf(state->pp_buf, PAGE_SIZE, " %s:", state->name);
+       if (isdigit(state->name[strlen(state->name)-1]))
+               sprintf(state->name, "p");
+
+       i = res = err = 0;
+       while (!res && check_part[i]) {
+               memset(state->parts, 0, state->limit * sizeof(state->parts[0]));
+               res = check_part[i++](state);
+               if (res < 0) {
+                       /*
+                        * We have hit an I/O error which we don't report now.
+                        * But record it, and let the others do their job.
+                        */
+                       err = res;
+                       res = 0;
+               }
+
+       }
+       if (res > 0) {
+               printk(KERN_INFO "%s", state->pp_buf);
+
+               free_page((unsigned long)state->pp_buf);
+               return state;
+       }
+       if (state->access_beyond_eod)
+               err = -ENOSPC;
+       /*
+        * The partition is unrecognized. So report I/O errors if there were any
+        */
+       if (err)
+               res = err;
+       if (res) {
+               strlcat(state->pp_buf,
+                       " unable to read partition table\n", PAGE_SIZE);
+               printk(KERN_INFO "%s", state->pp_buf);
+       }
+
+       free_page((unsigned long)state->pp_buf);
+       free_partitions(state);
+       return ERR_PTR(res);
+}
 
 static ssize_t part_partition_show(struct device *dev,
                                   struct device_attribute *attr, char *buf)
@@ -87,13 +188,6 @@ static ssize_t part_start_show(struct device *dev,
        return sprintf(buf, "%llu\n",(unsigned long long)p->start_sect);
 }
 
-ssize_t part_size_show(struct device *dev,
-                      struct device_attribute *attr, char *buf)
-{
-       struct hd_struct *p = dev_to_part(dev);
-       return sprintf(buf, "%llu\n",(unsigned long long)part_nr_sects_read(p));
-}
-
 static ssize_t part_ro_show(struct device *dev,
                            struct device_attribute *attr, char *buf)
 {
@@ -115,74 +209,6 @@ static ssize_t part_discard_alignment_show(struct device *dev,
        return sprintf(buf, "%u\n", p->discard_alignment);
 }
 
-ssize_t part_stat_show(struct device *dev,
-                      struct device_attribute *attr, char *buf)
-{
-       struct hd_struct *p = dev_to_part(dev);
-       struct request_queue *q = part_to_disk(p)->queue;
-       unsigned int inflight;
-
-       inflight = part_in_flight(q, p);
-       return sprintf(buf,
-               "%8lu %8lu %8llu %8u "
-               "%8lu %8lu %8llu %8u "
-               "%8u %8u %8u "
-               "%8lu %8lu %8llu %8u "
-               "%8lu %8u"
-               "\n",
-               part_stat_read(p, ios[STAT_READ]),
-               part_stat_read(p, merges[STAT_READ]),
-               (unsigned long long)part_stat_read(p, sectors[STAT_READ]),
-               (unsigned int)part_stat_read_msecs(p, STAT_READ),
-               part_stat_read(p, ios[STAT_WRITE]),
-               part_stat_read(p, merges[STAT_WRITE]),
-               (unsigned long long)part_stat_read(p, sectors[STAT_WRITE]),
-               (unsigned int)part_stat_read_msecs(p, STAT_WRITE),
-               inflight,
-               jiffies_to_msecs(part_stat_read(p, io_ticks)),
-               jiffies_to_msecs(part_stat_read(p, time_in_queue)),
-               part_stat_read(p, ios[STAT_DISCARD]),
-               part_stat_read(p, merges[STAT_DISCARD]),
-               (unsigned long long)part_stat_read(p, sectors[STAT_DISCARD]),
-               (unsigned int)part_stat_read_msecs(p, STAT_DISCARD),
-               part_stat_read(p, ios[STAT_FLUSH]),
-               (unsigned int)part_stat_read_msecs(p, STAT_FLUSH));
-}
-
-ssize_t part_inflight_show(struct device *dev, struct device_attribute *attr,
-                          char *buf)
-{
-       struct hd_struct *p = dev_to_part(dev);
-       struct request_queue *q = part_to_disk(p)->queue;
-       unsigned int inflight[2];
-
-       part_in_flight_rw(q, p, inflight);
-       return sprintf(buf, "%8u %8u\n", inflight[0], inflight[1]);
-}
-
-#ifdef CONFIG_FAIL_MAKE_REQUEST
-ssize_t part_fail_show(struct device *dev,
-                      struct device_attribute *attr, char *buf)
-{
-       struct hd_struct *p = dev_to_part(dev);
-
-       return sprintf(buf, "%d\n", p->make_it_fail);
-}
-
-ssize_t part_fail_store(struct device *dev,
-                       struct device_attribute *attr,
-                       const char *buf, size_t count)
-{
-       struct hd_struct *p = dev_to_part(dev);
-       int i;
-
-       if (count > 0 && sscanf(buf, "%d", &i) > 0)
-               p->make_it_fail = (i == 0) ? 0 : 1;
-
-       return count;
-}
-#endif
-
 static DEVICE_ATTR(partition, 0444, part_partition_show, NULL);
 static DEVICE_ATTR(start, 0444, part_start_show, NULL);
 static DEVICE_ATTR(size, 0444, part_size_show, NULL);
@@ -369,7 +395,9 @@ struct hd_struct *add_partition(struct gendisk *disk, int partno,
        p->policy = get_disk_ro(disk);
 
        if (info) {
-               struct partition_meta_info *pinfo = alloc_part_info(disk);
+               struct partition_meta_info *pinfo;
+
+               pinfo = kzalloc_node(sizeof(*pinfo), GFP_KERNEL, disk->node_id);
                if (!pinfo) {
                        err = -ENOMEM;
                        goto out_free_stats;
@@ -428,7 +456,7 @@ struct hd_struct *add_partition(struct gendisk *disk, int partno,
        return p;
 
 out_free_info:
-       free_part_info(p);
+       kfree(p->info);
 out_free_stats:
        free_part_stats(p);
 out_free:
@@ -525,10 +553,10 @@ static bool blk_add_partition(struct gendisk *disk, struct block_device *bdev,
                return true;
        }
 
-#ifdef CONFIG_BLK_DEV_MD
-       if (state->parts[p].flags & ADDPART_FLAG_RAID)
+       if (IS_BUILTIN(CONFIG_BLK_DEV_MD) &&
+           (state->parts[p].flags & ADDPART_FLAG_RAID))
                md_autodetect_dev(part_to_dev(part)->devt);
-#endif
+
        return true;
 }
 
@@ -602,22 +630,29 @@ out_free_state:
        return ret;
 }
 
-unsigned char *read_dev_sector(struct block_device *bdev, sector_t n, Sector *p)
+void *read_part_sector(struct parsed_partitions *state, sector_t n, Sector *p)
 {
-       struct address_space *mapping = bdev->bd_inode->i_mapping;
+       struct address_space *mapping = state->bdev->bd_inode->i_mapping;
        struct page *page;
 
-       page = read_mapping_page(mapping, (pgoff_t)(n >> (PAGE_SHIFT-9)), NULL);
-       if (!IS_ERR(page)) {
-               if (PageError(page))
-                       goto fail;
-               p->v = page;
-               return (unsigned char *)page_address(page) +  ((n & ((1 << (PAGE_SHIFT - 9)) - 1)) << 9);
-fail:
-               put_page(page);
+       if (n >= get_capacity(state->bdev->bd_disk)) {
+               state->access_beyond_eod = true;
+               return NULL;
        }
+
+       page = read_mapping_page(mapping,
+                       (pgoff_t)(n >> (PAGE_SHIFT - 9)), NULL);
+       if (IS_ERR(page))
+               goto out;
+       if (PageError(page))
+               goto out_put_page;
+
+       p->v = page;
+       return (unsigned char *)page_address(page) +
+                       ((n & ((1 << (PAGE_SHIFT - 9)) - 1)) << SECTOR_SHIFT);
+out_put_page:
+       put_page(page);
+out:
        p->v = NULL;
        return NULL;
 }
-
-EXPORT_SYMBOL(read_dev_sector);
index 3e85761..907bac5 100644 (file)
@@ -113,7 +113,4 @@ typedef struct _legacy_mbr {
        __le16 signature;
 } __packed legacy_mbr;
 
-/* Functions */
-extern int efi_partition(struct parsed_partitions *state);
-
 #endif
index a5d480f..073faa6 100644 (file)
@@ -15,7 +15,6 @@
 #include <asm/vtoc.h>
 
 #include "check.h"
-#include "ibm.h"
 
 
 union label_t {
diff --git a/block/partitions/ibm.h b/block/partitions/ibm.h
deleted file mode 100644 (file)
index 8bf13fe..0000000
+++ /dev/null
@@ -1,2 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 */
-int ibm_partition(struct parsed_partitions *);
index 59812d7..4d93512 100644 (file)
@@ -8,9 +8,10 @@
  */
 
 #include "check.h"
-#include "karma.h"
 #include <linux/compiler.h>
 
+#define KARMA_LABEL_MAGIC              0xAB56
+
 int karma_partition(struct parsed_partitions *state)
 {
        int i;
diff --git a/block/partitions/karma.h b/block/partitions/karma.h
deleted file mode 100644 (file)
index 48e074d..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 */
-/*
- *  fs/partitions/karma.h
- */
-
-#define KARMA_LABEL_MAGIC              0xAB56
-
-int karma_partition(struct parsed_partitions *state);
-
index a2d97ee..6fdfcb4 100644 (file)
 #include <linux/stringify.h>
 #include <linux/kernel.h>
 #include <linux/uuid.h>
+#include <linux/msdos_partition.h>
 
 #include "ldm.h"
 #include "check.h"
-#include "msdos.h"
 
 /*
  * ldm_debug/info/error/crit - Output an error message
@@ -493,7 +493,7 @@ static bool ldm_validate_partition_table(struct parsed_partitions *state)
 {
        Sector sect;
        u8 *data;
-       struct partition *p;
+       struct msdos_partition *p;
        int i;
        bool result = false;
 
@@ -508,7 +508,7 @@ static bool ldm_validate_partition_table(struct parsed_partitions *state)
        if (*(__le16*) (data + 0x01FE) != cpu_to_le16 (MSDOS_LABEL_MAGIC))
                goto out;
 
-       p = (struct partition*)(data + 0x01BE);
+       p = (struct msdos_partition *)(data + 0x01BE);
        for (i = 0; i < 4; i++, p++)
                if (SYS_IND (p) == LDM_PARTITION) {
                        result = true;
index 1ca63e9..841580a 100644 (file)
@@ -193,7 +193,5 @@ struct ldmdb {                              /* Cache of the database */
        struct list_head v_part;
 };
 
-int ldm_partition(struct parsed_partitions *state);
-
 #endif /* _FS_PT_LDM_H_ */
 
index 453ed29..0e41c9d 100644 (file)
@@ -42,4 +42,3 @@ struct mac_driver_desc {
     /* ... more stuff */
 };
 
-int mac_partition(struct parsed_partitions *state);
index 82c44f7..8f2fcc0 100644 (file)
  *  Check partition table on IDE disks for common CHS translations
  *
  *  Re-organised Feb 1998 Russell King
+ *
+ *  BSD disklabel support by Yossi Gottlieb <yogo@math.tau.ac.il>
+ *  updated by Marc Espie <Marc.Espie@openbsd.org>
+ *
+ *  Unixware slices support by Andrzej Krzysztofowicz <ankry@mif.pg.gda.pl>
+ *  and Krzysztof G. Baranowski <kgb@knm.org.pl>
  */
 #include <linux/msdos_fs.h>
+#include <linux/msdos_partition.h>
 
 #include "check.h"
-#include "msdos.h"
 #include "efi.h"
-#include "aix.h"
 
 /*
  * Many architectures don't like unaligned accesses, while
 
 #define SYS_IND(p)     get_unaligned(&p->sys_ind)
 
-static inline sector_t nr_sects(struct partition *p)
+static inline sector_t nr_sects(struct msdos_partition *p)
 {
        return (sector_t)get_unaligned_le32(&p->nr_sects);
 }
 
-static inline sector_t start_sect(struct partition *p)
+static inline sector_t start_sect(struct msdos_partition *p)
 {
        return (sector_t)get_unaligned_le32(&p->start_sect);
 }
 
-static inline int is_extended_partition(struct partition *p)
+static inline int is_extended_partition(struct msdos_partition *p)
 {
        return (SYS_IND(p) == DOS_EXTENDED_PARTITION ||
                SYS_IND(p) == WIN98_EXTENDED_PARTITION ||
@@ -68,7 +73,7 @@ msdos_magic_present(unsigned char *p)
 #define AIX_LABEL_MAGIC4       0xC1
 static int aix_magic_present(struct parsed_partitions *state, unsigned char *p)
 {
-       struct partition *pt = (struct partition *) (p + 0x1be);
+       struct msdos_partition *pt = (struct msdos_partition *) (p + 0x1be);
        Sector sect;
        unsigned char *d;
        int slot, ret = 0;
@@ -78,13 +83,19 @@ static int aix_magic_present(struct parsed_partitions *state, unsigned char *p)
                p[2] == AIX_LABEL_MAGIC3 &&
                p[3] == AIX_LABEL_MAGIC4))
                return 0;
-       /* Assume the partition table is valid if Linux partitions exists */
+
+       /*
+        * Assume the partition table is valid if Linux partitions exists.
+        * Note that old Solaris/x86 partitions use the same indicator as
+        * Linux swap partitions, so we consider that a Linux partition as
+        * well.
+        */
        for (slot = 1; slot <= 4; slot++, pt++) {
-               if (pt->sys_ind == LINUX_SWAP_PARTITION ||
-                       pt->sys_ind == LINUX_RAID_PARTITION ||
-                       pt->sys_ind == LINUX_DATA_PARTITION ||
-                       pt->sys_ind == LINUX_LVM_PARTITION ||
-                       is_extended_partition(pt))
+               if (pt->sys_ind == SOLARIS_X86_PARTITION ||
+                   pt->sys_ind == LINUX_RAID_PARTITION ||
+                   pt->sys_ind == LINUX_DATA_PARTITION ||
+                   pt->sys_ind == LINUX_LVM_PARTITION ||
+                   is_extended_partition(pt))
                        return 0;
        }
        d = read_part_sector(state, 7, &sect);
@@ -122,7 +133,7 @@ static void parse_extended(struct parsed_partitions *state,
                           sector_t first_sector, sector_t first_size,
                           u32 disksig)
 {
-       struct partition *p;
+       struct msdos_partition *p;
        Sector sect;
        unsigned char *data;
        sector_t this_sector, this_size;
@@ -146,7 +157,7 @@ static void parse_extended(struct parsed_partitions *state,
                if (!msdos_magic_present(data + 510))
                        goto done;
 
-               p = (struct partition *) (data + 0x1be);
+               p = (struct msdos_partition *) (data + 0x1be);
 
                /*
                 * Usually, the first entry is the real data partition,
@@ -210,6 +221,30 @@ done:
        put_dev_sector(sect);
 }
 
+#define SOLARIS_X86_NUMSLICE   16
+#define SOLARIS_X86_VTOC_SANE  (0x600DDEEEUL)
+
+struct solaris_x86_slice {
+       __le16 s_tag;           /* ID tag of partition */
+       __le16 s_flag;          /* permission flags */
+       __le32 s_start;         /* start sector no of partition */
+       __le32 s_size;          /* # of blocks in partition */
+};
+
+struct solaris_x86_vtoc {
+       unsigned int v_bootinfo[3];     /* info needed by mboot */
+       __le32 v_sanity;                /* to verify vtoc sanity */
+       __le32 v_version;               /* layout version */
+       char    v_volume[8];            /* volume name */
+       __le16  v_sectorsz;             /* sector size in bytes */
+       __le16  v_nparts;               /* number of partitions */
+       unsigned int v_reserved[10];    /* free space */
+       struct solaris_x86_slice
+               v_slice[SOLARIS_X86_NUMSLICE]; /* slice headers */
+       unsigned int timestamp[SOLARIS_X86_NUMSLICE]; /* timestamp */
+       char    v_asciilabel[128];      /* for compatibility */
+};
+
 /* james@bpgc.com: Solaris has a nasty indicator: 0x82 which also
    indicates linux swap.  Be careful before believing this is Solaris. */
 
@@ -265,6 +300,54 @@ static void parse_solaris_x86(struct parsed_partitions *state,
 #endif
 }
 
+/* check against BSD src/sys/sys/disklabel.h for consistency */
+#define BSD_DISKMAGIC  (0x82564557UL)  /* The disk magic number */
+#define BSD_MAXPARTITIONS      16
+#define OPENBSD_MAXPARTITIONS  16
+#define BSD_FS_UNUSED          0 /* disklabel unused partition entry ID */
+struct bsd_disklabel {
+       __le32  d_magic;                /* the magic number */
+       __s16   d_type;                 /* drive type */
+       __s16   d_subtype;              /* controller/d_type specific */
+       char    d_typename[16];         /* type name, e.g. "eagle" */
+       char    d_packname[16];         /* pack identifier */
+       __u32   d_secsize;              /* # of bytes per sector */
+       __u32   d_nsectors;             /* # of data sectors per track */
+       __u32   d_ntracks;              /* # of tracks per cylinder */
+       __u32   d_ncylinders;           /* # of data cylinders per unit */
+       __u32   d_secpercyl;            /* # of data sectors per cylinder */
+       __u32   d_secperunit;           /* # of data sectors per unit */
+       __u16   d_sparespertrack;       /* # of spare sectors per track */
+       __u16   d_sparespercyl;         /* # of spare sectors per cylinder */
+       __u32   d_acylinders;           /* # of alt. cylinders per unit */
+       __u16   d_rpm;                  /* rotational speed */
+       __u16   d_interleave;           /* hardware sector interleave */
+       __u16   d_trackskew;            /* sector 0 skew, per track */
+       __u16   d_cylskew;              /* sector 0 skew, per cylinder */
+       __u32   d_headswitch;           /* head switch time, usec */
+       __u32   d_trkseek;              /* track-to-track seek, usec */
+       __u32   d_flags;                /* generic flags */
+#define NDDATA 5
+       __u32   d_drivedata[NDDATA];    /* drive-type specific information */
+#define NSPARE 5
+       __u32   d_spare[NSPARE];        /* reserved for future use */
+       __le32  d_magic2;               /* the magic number (again) */
+       __le16  d_checksum;             /* xor of data incl. partitions */
+
+                       /* filesystem and partition information: */
+       __le16  d_npartitions;          /* number of partitions in following */
+       __le32  d_bbsize;               /* size of boot area at sn0, bytes */
+       __le32  d_sbsize;               /* max size of fs superblock, bytes */
+       struct  bsd_partition {         /* the partition table */
+               __le32  p_size;         /* number of sectors in partition */
+               __le32  p_offset;       /* starting sector */
+               __le32  p_fsize;        /* filesystem basic fragment size */
+               __u8    p_fstype;       /* filesystem type, see below */
+               __u8    p_frag;         /* filesystem fragments per block */
+               __le16  p_cpg;          /* filesystem cylinders per group */
+       } d_partitions[BSD_MAXPARTITIONS];      /* actually may be more */
+};
+
 #if defined(CONFIG_BSD_DISKLABEL)
 /*
  * Create devices for BSD partitions listed in a disklabel, under a
@@ -349,6 +432,51 @@ static void parse_openbsd(struct parsed_partitions *state,
 #endif
 }
 
+#define UNIXWARE_DISKMAGIC     (0xCA5E600DUL)  /* The disk magic number */
+#define UNIXWARE_DISKMAGIC2    (0x600DDEEEUL)  /* The slice table magic nr */
+#define UNIXWARE_NUMSLICE      16
+#define UNIXWARE_FS_UNUSED     0               /* Unused slice entry ID */
+
+struct unixware_slice {
+       __le16   s_label;       /* label */
+       __le16   s_flags;       /* permission flags */
+       __le32   start_sect;    /* starting sector */
+       __le32   nr_sects;      /* number of sectors in slice */
+};
+
+struct unixware_disklabel {
+       __le32  d_type;                 /* drive type */
+       __le32  d_magic;                /* the magic number */
+       __le32  d_version;              /* version number */
+       char    d_serial[12];           /* serial number of the device */
+       __le32  d_ncylinders;           /* # of data cylinders per device */
+       __le32  d_ntracks;              /* # of tracks per cylinder */
+       __le32  d_nsectors;             /* # of data sectors per track */
+       __le32  d_secsize;              /* # of bytes per sector */
+       __le32  d_part_start;           /* # of first sector of this partition*/
+       __le32  d_unknown1[12];         /* ? */
+       __le32  d_alt_tbl;              /* byte offset of alternate table */
+       __le32  d_alt_len;              /* byte length of alternate table */
+       __le32  d_phys_cyl;             /* # of physical cylinders per device */
+       __le32  d_phys_trk;             /* # of physical tracks per cylinder */
+       __le32  d_phys_sec;             /* # of physical sectors per track */
+       __le32  d_phys_bytes;           /* # of physical bytes per sector */
+       __le32  d_unknown2;             /* ? */
+       __le32  d_unknown3;             /* ? */
+       __le32  d_pad[8];               /* pad */
+
+       struct unixware_vtoc {
+               __le32  v_magic;                /* the magic number */
+               __le32  v_version;              /* version number */
+               char    v_name[8];              /* volume name */
+               __le16  v_nslices;              /* # of slices */
+               __le16  v_unknown1;             /* ? */
+               __le32  v_reserved[10];         /* reserved */
+               struct unixware_slice
+                       v_slice[UNIXWARE_NUMSLICE];     /* slice headers */
+       } vtoc;
+};  /* 408 */
+
 /*
  * Create devices for Unixware partitions listed in a disklabel, under a
  * dos-like partition. See parse_extended() for more information.
@@ -392,6 +520,8 @@ static void parse_unixware(struct parsed_partitions *state,
 #endif
 }
 
+#define MINIX_NR_SUBPARTITIONS  4
+
 /*
  * Minix 2.0.0/2.0.2 subpartition support.
  * Anand Krishnamurthy <anandk@wiproge.med.ge.com>
@@ -403,14 +533,14 @@ static void parse_minix(struct parsed_partitions *state,
 #ifdef CONFIG_MINIX_SUBPARTITION
        Sector sect;
        unsigned char *data;
-       struct partition *p;
+       struct msdos_partition *p;
        int i;
 
        data = read_part_sector(state, offset, &sect);
        if (!data)
                return;
 
-       p = (struct partition *)(data + 0x1be);
+       p = (struct msdos_partition *)(data + 0x1be);
 
        /* The first sector of a Minix partition can have either
         * a secondary MBR describing its subpartitions, or
@@ -454,7 +584,7 @@ int msdos_partition(struct parsed_partitions *state)
        sector_t sector_size = bdev_logical_block_size(state->bdev) / 512;
        Sector sect;
        unsigned char *data;
-       struct partition *p;
+       struct msdos_partition *p;
        struct fat_boot_sector *fb;
        int slot;
        u32 disksig;
@@ -488,7 +618,7 @@ int msdos_partition(struct parsed_partitions *state)
         * partition table. Reject this in case the boot indicator
         * is not 0 or 0x80.
         */
-       p = (struct partition *) (data + 0x1be);
+       p = (struct msdos_partition *) (data + 0x1be);
        for (slot = 1; slot <= 4; slot++, p++) {
                if (p->boot_ind != 0 && p->boot_ind != 0x80) {
                        /*
@@ -510,7 +640,7 @@ int msdos_partition(struct parsed_partitions *state)
        }
 
 #ifdef CONFIG_EFI_PARTITION
-       p = (struct partition *) (data + 0x1be);
+       p = (struct msdos_partition *) (data + 0x1be);
        for (slot = 1 ; slot <= 4 ; slot++, p++) {
                /* If this is an EFI GPT disk, msdos should ignore it. */
                if (SYS_IND(p) == EFI_PMBR_OSTYPE_EFI_GPT) {
@@ -519,7 +649,7 @@ int msdos_partition(struct parsed_partitions *state)
                }
        }
 #endif
-       p = (struct partition *) (data + 0x1be);
+       p = (struct msdos_partition *) (data + 0x1be);
 
        disksig = le32_to_cpup((__le32 *)(data + 0x1b8));
 
@@ -566,7 +696,7 @@ int msdos_partition(struct parsed_partitions *state)
        strlcat(state->pp_buf, "\n", PAGE_SIZE);
 
        /* second pass - output for each on a separate line */
-       p = (struct partition *) (0x1be + data);
+       p = (struct msdos_partition *) (0x1be + data);
        for (slot = 1 ; slot <= 4 ; slot++, p++) {
                unsigned char id = SYS_IND(p);
                int n;
diff --git a/block/partitions/msdos.h b/block/partitions/msdos.h
deleted file mode 100644 (file)
index fcacfc4..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 */
-/*
- *  fs/partitions/msdos.h
- */
-
-#define MSDOS_LABEL_MAGIC              0xAA55
-
-int msdos_partition(struct parsed_partitions *state);
-
index 4b87397..84560d0 100644 (file)
@@ -9,9 +9,9 @@
  */
 
 #include "check.h"
-#include "osf.h"
 
 #define MAX_OSF_PARTITIONS 18
+#define DISKLABELMAGIC (0x82564557UL)
 
 int osf_partition(struct parsed_partitions *state)
 {
diff --git a/block/partitions/osf.h b/block/partitions/osf.h
deleted file mode 100644 (file)
index 4d8088e..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 */
-/*
- *  fs/partitions/osf.h
- */
-
-#define DISKLABELMAGIC (0x82564557UL)
-
-int osf_partition(struct parsed_partitions *state);
index d7b421c..4273f1b 100644 (file)
@@ -6,7 +6,12 @@
  */
 
 #include "check.h"
-#include "sgi.h"
+
+#define SGI_LABEL_MAGIC 0x0be5a941
+
+enum {
+       LINUX_RAID_PARTITION = 0xfd,    /* autodetect RAID partition */
+};
 
 struct sgi_disklabel {
        __be32 magic_mushroom;          /* Big fat spliff... */
diff --git a/block/partitions/sgi.h b/block/partitions/sgi.h
deleted file mode 100644 (file)
index a5b77c3..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 */
-/*
- *  fs/partitions/sgi.h
- */
-
-extern int sgi_partition(struct parsed_partitions *state);
-
-#define SGI_LABEL_MAGIC 0x0be5a941
-
index 90f3672..47dc53e 100644 (file)
@@ -9,7 +9,14 @@
  */
 
 #include "check.h"
-#include "sun.h"
+
+#define SUN_LABEL_MAGIC          0xDABE
+#define SUN_VTOC_SANITY          0x600DDEEE
+
+enum {
+       SUN_WHOLE_DISK = 5,
+       LINUX_RAID_PARTITION = 0xfd,    /* autodetect RAID partition */
+};
 
 int sun_partition(struct parsed_partitions *state)
 {
diff --git a/block/partitions/sun.h b/block/partitions/sun.h
deleted file mode 100644 (file)
index ae1b9ee..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 */
-/*
- *  fs/partitions/sun.h
- */
-
-#define SUN_LABEL_MAGIC          0xDABE
-#define SUN_VTOC_SANITY          0x600DDEEE
-
-int sun_partition(struct parsed_partitions *state);
index 92e8108..6f6257f 100644 (file)
@@ -6,7 +6,6 @@
  */
 
 #include "check.h"
-#include "sysv68.h"
 
 /*
  *     Volume ID structure: on first 256-bytes sector of disk
diff --git a/block/partitions/sysv68.h b/block/partitions/sysv68.h
deleted file mode 100644 (file)
index 4fb6b8e..0000000
+++ /dev/null
@@ -1,2 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 */
-extern int sysv68_partition(struct parsed_partitions *state);
index ecd0d73..4aaa810 100644 (file)
@@ -8,7 +8,6 @@
  */
 
 #include "check.h"
-#include "ultrix.h"
 
 int ultrix_partition(struct parsed_partitions *state)
 {
diff --git a/block/partitions/ultrix.h b/block/partitions/ultrix.h
deleted file mode 100644 (file)
index 9f676ce..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 */
-/*
- *  fs/partitions/ultrix.h
- */
-
-int ultrix_partition(struct parsed_partitions *state);
index 880cc57..daafadb 100644 (file)
@@ -1056,7 +1056,7 @@ static int start_opal_session_cont(struct opal_dev *dev)
        hsn = response_get_u64(&dev->parsed, 4);
        tsn = response_get_u64(&dev->parsed, 5);
 
-       if (hsn == 0 && tsn == 0) {
+       if (hsn != GENERIC_HOST_SESSION_NUM || tsn < FIRST_TPER_SESSION_NUM) {
                pr_debug("Couldn't authenticate session\n");
                return -EPERM;
        }
index a6beb2c..05ecdce 100644 (file)
@@ -34,6 +34,12 @@ if ATA
 config ATA_NONSTANDARD
        bool
 
+config SATA_HOST
+       bool
+
+config PATA_TIMINGS
+       bool
+
 config ATA_VERBOSE_ERROR
        bool "Verbose ATA error reporting"
        default y
@@ -45,9 +51,26 @@ config ATA_VERBOSE_ERROR
 
          If unsure, say Y.
 
+config ATA_FORCE
+       bool "\"libata.force=\" kernel parameter support" if EXPERT
+       default y
+       help
+         This option adds support for "libata.force=" kernel parameter for
+         forcing configuration settings.
+
+         For further information, please read
+         <file:Documentation/admin-guide/kernel-parameters.txt>.
+
+         This option will enlarge the kernel by approx. 3KB. Disable it if
+         kernel size is more important than ability to override the default
+         configuration settings.
+
+         If unsure, say Y.
+
 config ATA_ACPI
        bool "ATA ACPI Support"
        depends on ACPI
+       select PATA_TIMINGS
        default y
        help
          This option adds support for ATA-related ACPI objects.
@@ -73,6 +96,7 @@ config SATA_ZPODD
 
 config SATA_PMP
        bool "SATA Port Multiplier support"
+       depends on SATA_HOST
        default y
        help
          This option adds support for SATA Port Multipliers
@@ -85,6 +109,7 @@ comment "Controllers with non-SFF native interface"
 config SATA_AHCI
        tristate "AHCI SATA support"
        depends on PCI
+       select SATA_HOST
        help
          This option enables support for AHCI Serial ATA.
 
@@ -111,6 +136,7 @@ config SATA_MOBILE_LPM_POLICY
 
 config SATA_AHCI_PLATFORM
        tristate "Platform AHCI SATA support"
+       select SATA_HOST
        help
          This option enables support for Platform AHCI Serial ATA
          controllers.
@@ -121,6 +147,7 @@ config AHCI_BRCM
        tristate "Broadcom AHCI SATA support"
        depends on ARCH_BRCMSTB || BMIPS_GENERIC || ARCH_BCM_NSP || \
                   ARCH_BCM_63XX
+       select SATA_HOST
        help
          This option enables support for the AHCI SATA3 controller found on
          Broadcom SoC's.
@@ -130,6 +157,7 @@ config AHCI_BRCM
 config AHCI_DA850
        tristate "DaVinci DA850 AHCI SATA support"
        depends on ARCH_DAVINCI_DA850
+       select SATA_HOST
        help
          This option enables support for the DaVinci DA850 SoC's
          onboard AHCI SATA.
@@ -139,6 +167,7 @@ config AHCI_DA850
 config AHCI_DM816
        tristate "DaVinci DM816 AHCI SATA support"
        depends on ARCH_OMAP2PLUS
+       select SATA_HOST
        help
          This option enables support for the DaVinci DM816 SoC's
          onboard AHCI SATA controller.
@@ -148,6 +177,7 @@ config AHCI_DM816
 config AHCI_ST
        tristate "ST AHCI SATA support"
        depends on ARCH_STI
+       select SATA_HOST
        help
          This option enables support for ST AHCI SATA controller.
 
@@ -157,6 +187,7 @@ config AHCI_IMX
        tristate "Freescale i.MX AHCI SATA support"
        depends on MFD_SYSCON && (ARCH_MXC || COMPILE_TEST)
        depends on (HWMON && (THERMAL || !THERMAL_OF)) || !HWMON
+       select SATA_HOST
        help
          This option enables support for the Freescale i.MX SoC's
          onboard AHCI SATA.
@@ -166,6 +197,7 @@ config AHCI_IMX
 config AHCI_CEVA
        tristate "CEVA AHCI SATA support"
        depends on OF
+       select SATA_HOST
        help
          This option enables support for the CEVA AHCI SATA.
          It can be found on the Xilinx Zynq UltraScale+ MPSoC.
@@ -176,6 +208,7 @@ config AHCI_MTK
        tristate "MediaTek AHCI SATA support"
        depends on ARCH_MEDIATEK
        select MFD_SYSCON
+       select SATA_HOST
        help
          This option enables support for the MediaTek SoC's
          onboard AHCI SATA controller.
@@ -185,6 +218,7 @@ config AHCI_MTK
 config AHCI_MVEBU
        tristate "Marvell EBU AHCI SATA support"
        depends on ARCH_MVEBU
+       select SATA_HOST
        help
          This option enables support for the Marvebu EBU SoC's
          onboard AHCI SATA.
@@ -203,6 +237,7 @@ config AHCI_OCTEON
 config AHCI_SUNXI
        tristate "Allwinner sunxi AHCI SATA support"
        depends on ARCH_SUNXI
+       select SATA_HOST
        help
          This option enables support for the Allwinner sunxi SoC's
          onboard AHCI SATA.
@@ -212,6 +247,7 @@ config AHCI_SUNXI
 config AHCI_TEGRA
        tristate "NVIDIA Tegra AHCI SATA support"
        depends on ARCH_TEGRA
+       select SATA_HOST
        help
          This option enables support for the NVIDIA Tegra SoC's
          onboard AHCI SATA.
@@ -221,12 +257,14 @@ config AHCI_TEGRA
 config AHCI_XGENE
        tristate "APM X-Gene 6.0Gbps AHCI SATA host controller support"
        depends on PHY_XGENE
+       select SATA_HOST
        help
         This option enables support for APM X-Gene SoC SATA host controller.
 
 config AHCI_QORIQ
        tristate "Freescale QorIQ AHCI SATA support"
        depends on OF
+       select SATA_HOST
        help
          This option enables support for the Freescale QorIQ AHCI SoC's
          onboard AHCI SATA.
@@ -236,6 +274,7 @@ config AHCI_QORIQ
 config SATA_FSL
        tristate "Freescale 3.0Gbps SATA support"
        depends on FSL_SOC
+       select SATA_HOST
        help
          This option enables support for Freescale 3.0Gbps SATA controller.
          It can be found on MPC837x and MPC8315.
@@ -245,6 +284,7 @@ config SATA_FSL
 config SATA_GEMINI
        tristate "Gemini SATA bridge support"
        depends on ARCH_GEMINI || COMPILE_TEST
+       select SATA_HOST
        default ARCH_GEMINI
        help
          This enabled support for the FTIDE010 to SATA bridge
@@ -255,6 +295,7 @@ config SATA_GEMINI
 config SATA_AHCI_SEATTLE
        tristate "AMD Seattle 6.0Gbps AHCI SATA host controller support"
        depends on ARCH_SEATTLE
+       select SATA_HOST
        help
         This option enables support for AMD Seattle SATA host controller.
 
@@ -263,12 +304,14 @@ config SATA_AHCI_SEATTLE
 config SATA_INIC162X
        tristate "Initio 162x SATA support (Very Experimental)"
        depends on PCI
+       select SATA_HOST
        help
          This option enables support for Initio 162x Serial ATA.
 
 config SATA_ACARD_AHCI
        tristate "ACard AHCI variant (ATP 8620)"
        depends on PCI
+       select SATA_HOST
        help
          This option enables support for Acard.
 
@@ -277,6 +320,7 @@ config SATA_ACARD_AHCI
 config SATA_SIL24
        tristate "Silicon Image 3124/3132 SATA support"
        depends on PCI
+       select SATA_HOST
        help
          This option enables support for Silicon Image 3124/3132 Serial ATA.
 
@@ -317,6 +361,7 @@ config PDC_ADMA
 config PATA_OCTEON_CF
        tristate "OCTEON Boot Bus Compact Flash support"
        depends on CAVIUM_OCTEON_SOC
+       select PATA_TIMINGS
        help
          This option enables a polled compact flash driver for use with
          compact flash cards attached to the OCTEON boot bus.
@@ -326,6 +371,7 @@ config PATA_OCTEON_CF
 config SATA_QSTOR
        tristate "Pacific Digital SATA QStor support"
        depends on PCI
+       select SATA_HOST
        help
          This option enables support for Pacific Digital Serial ATA QStor.
 
@@ -334,6 +380,7 @@ config SATA_QSTOR
 config SATA_SX4
        tristate "Promise SATA SX4 support (Experimental)"
        depends on PCI
+       select SATA_HOST
        help
          This option enables support for Promise Serial ATA SX4.
 
@@ -357,6 +404,7 @@ comment "SATA SFF controllers with BMDMA"
 config ATA_PIIX
        tristate "Intel ESB, ICH, PIIX3, PIIX4 PATA/SATA support"
        depends on PCI
+       select SATA_HOST
        help
          This option enables support for ICH5/6/7/8 Serial ATA
          and support for PATA on the Intel ESB/ICH/PIIX3/PIIX4 series
@@ -368,6 +416,7 @@ config SATA_DWC
        tristate "DesignWare Cores SATA support"
        depends on DMADEVICES
        select GENERIC_PHY
+       select SATA_HOST
        help
          This option enables support for the on-chip SATA controller of the
          AppliedMicro processor 460EX.
@@ -398,6 +447,7 @@ config SATA_DWC_VDEBUG
 config SATA_HIGHBANK
        tristate "Calxeda Highbank SATA support"
        depends on ARCH_HIGHBANK || COMPILE_TEST
+       select SATA_HOST
        help
          This option enables support for the Calxeda Highbank SoC's
          onboard SATA.
@@ -409,6 +459,7 @@ config SATA_MV
        depends on PCI || ARCH_DOVE || ARCH_MV78XX0 || \
                   ARCH_MVEBU || ARCH_ORION5X || COMPILE_TEST
        select GENERIC_PHY
+       select SATA_HOST
        help
          This option enables support for the Marvell Serial ATA family.
          Currently supports 88SX[56]0[48][01] PCI(-X) chips,
@@ -419,6 +470,7 @@ config SATA_MV
 config SATA_NV
        tristate "NVIDIA SATA support"
        depends on PCI
+       select SATA_HOST
        help
          This option enables support for NVIDIA Serial ATA.
 
@@ -427,6 +479,7 @@ config SATA_NV
 config SATA_PROMISE
        tristate "Promise SATA TX2/TX4 support"
        depends on PCI
+       select SATA_HOST
        help
          This option enables support for Promise Serial ATA TX2/TX4.
 
@@ -435,6 +488,7 @@ config SATA_PROMISE
 config SATA_RCAR
        tristate "Renesas R-Car SATA support"
        depends on ARCH_RENESAS || COMPILE_TEST
+       select SATA_HOST
        help
          This option enables support for Renesas R-Car Serial ATA.
 
@@ -443,6 +497,7 @@ config SATA_RCAR
 config SATA_SIL
        tristate "Silicon Image SATA support"
        depends on PCI
+       select SATA_HOST
        help
          This option enables support for Silicon Image Serial ATA.
 
@@ -452,6 +507,7 @@ config SATA_SIS
        tristate "SiS 964/965/966/180 SATA support"
        depends on PCI
        select PATA_SIS
+       select SATA_HOST
        help
          This option enables support for SiS Serial ATA on
          SiS 964/965/966/180 and Parallel ATA on SiS 180.
@@ -462,6 +518,7 @@ config SATA_SIS
 config SATA_SVW
        tristate "ServerWorks Frodo / Apple K2 SATA support"
        depends on PCI
+       select SATA_HOST
        help
          This option enables support for Broadcom/Serverworks/Apple K2
          SATA support.
@@ -471,6 +528,7 @@ config SATA_SVW
 config SATA_ULI
        tristate "ULi Electronics SATA support"
        depends on PCI
+       select SATA_HOST
        help
          This option enables support for ULi Electronics SATA.
 
@@ -479,6 +537,7 @@ config SATA_ULI
 config SATA_VIA
        tristate "VIA SATA support"
        depends on PCI
+       select SATA_HOST
        help
          This option enables support for VIA Serial ATA.
 
@@ -487,6 +546,7 @@ config SATA_VIA
 config SATA_VITESSE
        tristate "VITESSE VSC-7174 / INTEL 31244 SATA support"
        depends on PCI
+       select SATA_HOST
        help
          This option enables support for Vitesse VSC7174 and Intel 31244 Serial ATA.
 
@@ -497,6 +557,7 @@ comment "PATA SFF controllers with BMDMA"
 config PATA_ALI
        tristate "ALi PATA support"
        depends on PCI
+       select PATA_TIMINGS
        help
          This option enables support for the ALi ATA interfaces
          found on the many ALi chipsets.
@@ -506,6 +567,7 @@ config PATA_ALI
 config PATA_AMD
        tristate "AMD/NVidia PATA support"
        depends on PCI
+       select PATA_TIMINGS
        help
          This option enables support for the AMD and NVidia PATA
          interfaces found on the chipsets for Athlon/Athlon64.
@@ -540,6 +602,7 @@ config PATA_ATIIXP
 config PATA_ATP867X
        tristate "ARTOP/Acard ATP867X PATA support"
        depends on PCI
+       select PATA_TIMINGS
        help
          This option enables support for ARTOP/Acard ATP867X PATA
          controllers.
@@ -549,6 +612,7 @@ config PATA_ATP867X
 config PATA_BK3710
        tristate "Palmchip BK3710 PATA support"
        depends on ARCH_DAVINCI
+       select PATA_TIMINGS
        help
          This option enables support for the integrated IDE controller on
          the TI DaVinci SoC.
@@ -558,6 +622,7 @@ config PATA_BK3710
 config PATA_CMD64X
        tristate "CMD64x PATA support"
        depends on PCI
+       select PATA_TIMINGS
        help
          This option enables support for the CMD64x series chips
          except for the CMD640.
@@ -603,6 +668,7 @@ config PATA_CS5536
 config PATA_CYPRESS
        tristate "Cypress CY82C693 PATA support (Very Experimental)"
        depends on PCI
+       select PATA_TIMINGS
        help
          This option enables support for the Cypress/Contaq CY82C693
          chipset found in some Alpha systems
@@ -621,6 +687,7 @@ config PATA_EFAR
 config PATA_EP93XX
        tristate "Cirrus Logic EP93xx PATA support"
        depends on ARCH_EP93XX
+       select PATA_TIMINGS
        help
          This option enables support for the PATA controller in
          the Cirrus Logic EP9312 and EP9315 ARM CPU.
@@ -685,6 +752,7 @@ config PATA_HPT3X3_DMA
 config PATA_ICSIDE
        tristate "Acorn ICS PATA support"
        depends on ARM && ARCH_ACORN
+       select PATA_TIMINGS
        help
          On Acorn systems, say Y here if you wish to use the ICS PATA
          interface card.  This is not required for ICS partition support.
@@ -693,6 +761,7 @@ config PATA_ICSIDE
 config PATA_IMX
        tristate "PATA support for Freescale iMX"
        depends on ARCH_MXC
+       select PATA_TIMINGS
        help
          This option enables support for the PATA host available on Freescale
           iMX SoCs.
@@ -778,6 +847,7 @@ config PATA_NINJA32
 config PATA_NS87415
        tristate "Nat Semi NS87415 PATA support"
        depends on PCI
+       select PATA_TIMINGS
        help
          This option enables support for the National Semiconductor
          NS87415 PCI-IDE controller.
@@ -902,6 +972,7 @@ config PATA_TRIFLEX
 config PATA_VIA
        tristate "VIA PATA support"
        depends on PCI
+       select PATA_TIMINGS
        help
          This option enables support for the VIA PATA interfaces
          found on the many VIA chipsets.
@@ -935,6 +1006,7 @@ comment "PIO-only SFF controllers"
 config PATA_CMD640_PCI
        tristate "CMD640 PCI PATA support (Experimental)"
        depends on PCI
+       select PATA_TIMINGS
        help
          This option enables support for the CMD640 PCI IDE
          interface chip. Only the primary channel is currently
@@ -1005,6 +1077,7 @@ config PATA_MPIIX
 config PATA_NS87410
        tristate "Nat Semi NS87410 PATA support"
        depends on PCI
+       select PATA_TIMINGS
        help
          This option enables support for the National Semiconductor
          NS87410 PCI-IDE controller.
@@ -1085,6 +1158,7 @@ config PATA_RZ1000
 config PATA_SAMSUNG_CF
        tristate "Samsung SoC PATA support"
        depends on SAMSUNG_DEV_IDE
+       select PATA_TIMINGS
        help
          This option enables basic support for Samsung's S3C/S5P board
          PATA controllers via the new ATA layer
@@ -1104,6 +1178,7 @@ comment "Generic fallback / legacy drivers"
 config PATA_ACPI
        tristate "ACPI firmware driver for PATA"
        depends on ATA_ACPI && ATA_BMDMA && PCI
+       select PATA_TIMINGS
        help
          This option enables an ACPI method driver which drives
          motherboard PATA controller interfaces through the ACPI
@@ -1113,6 +1188,7 @@ config PATA_ACPI
 config ATA_GENERIC
        tristate "Generic ATA support"
        depends on PCI && ATA_BMDMA
+       select SATA_HOST
        help
          This option enables support for generic BIOS configured
          ATA controllers via the new ATA layer
@@ -1122,6 +1198,7 @@ config ATA_GENERIC
 config PATA_LEGACY
        tristate "Legacy ISA PATA support (Experimental)"
        depends on (ISA || PCI)
+       select PATA_TIMINGS
        help
          This option enables support for ISA/VLB/PCI bus legacy PATA
          ports and allows them to be accessed via the new ATA layer.
index d8cc2e0..b8aebfb 100644 (file)
@@ -123,7 +123,9 @@ obj-$(CONFIG_PATA_LEGACY)   += pata_legacy.o
 
 libata-y       := libata-core.o libata-scsi.o libata-eh.o \
        libata-transport.o libata-trace.o
+libata-$(CONFIG_SATA_HOST)     += libata-sata.o
 libata-$(CONFIG_ATA_SFF)       += libata-sff.o
 libata-$(CONFIG_SATA_PMP)      += libata-pmp.o
 libata-$(CONFIG_ATA_ACPI)      += libata-acpi.o
 libata-$(CONFIG_SATA_ZPODD)    += libata-zpodd.o
+libata-$(CONFIG_PATA_TIMINGS)  += libata-pata-timings.o
index 11ea1af..ad0185c 100644 (file)
@@ -40,6 +40,7 @@
 enum {
        AHCI_PCI_BAR_STA2X11    = 0,
        AHCI_PCI_BAR_CAVIUM     = 0,
+       AHCI_PCI_BAR_LOONGSON   = 0,
        AHCI_PCI_BAR_ENMOTUS    = 2,
        AHCI_PCI_BAR_CAVIUM_GEN5        = 4,
        AHCI_PCI_BAR_STANDARD   = 5,
@@ -245,6 +246,7 @@ static const struct ata_port_info ahci_port_info[] = {
 
 static const struct pci_device_id ahci_pci_tbl[] = {
        /* Intel */
+       { PCI_VDEVICE(INTEL, 0x06d6), board_ahci }, /* Comet Lake PCH-H RAID */
        { PCI_VDEVICE(INTEL, 0x2652), board_ahci }, /* ICH6 */
        { PCI_VDEVICE(INTEL, 0x2653), board_ahci }, /* ICH6M */
        { PCI_VDEVICE(INTEL, 0x27c1), board_ahci }, /* ICH7 */
@@ -401,6 +403,8 @@ static const struct pci_device_id ahci_pci_tbl[] = {
        { PCI_VDEVICE(INTEL, 0xa252), board_ahci }, /* Lewisburg RAID*/
        { PCI_VDEVICE(INTEL, 0xa256), board_ahci }, /* Lewisburg RAID*/
        { PCI_VDEVICE(INTEL, 0xa356), board_ahci }, /* Cannon Lake PCH-H RAID */
+       { PCI_VDEVICE(INTEL, 0x06d7), board_ahci }, /* Comet Lake-H RAID */
+       { PCI_VDEVICE(INTEL, 0xa386), board_ahci }, /* Comet Lake PCH-V RAID */
        { PCI_VDEVICE(INTEL, 0x0f22), board_ahci_mobile }, /* Bay Trail AHCI */
        { PCI_VDEVICE(INTEL, 0x0f23), board_ahci_mobile }, /* Bay Trail AHCI */
        { PCI_VDEVICE(INTEL, 0x22a3), board_ahci_mobile }, /* Cherry Tr. AHCI */
@@ -589,6 +593,9 @@ static const struct pci_device_id ahci_pci_tbl[] = {
        /* Enmotus */
        { PCI_DEVICE(0x1c44, 0x8000), board_ahci },
 
+       /* Loongson */
+       { PCI_VDEVICE(LOONGSON, 0x7a08), board_ahci },
+
        /* Generic, PCI class code for AHCI */
        { PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID,
          PCI_CLASS_STORAGE_SATA_AHCI, 0xffffff, board_ahci },
@@ -1680,6 +1687,9 @@ static int ahci_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
                        ahci_pci_bar = AHCI_PCI_BAR_CAVIUM;
                if (pdev->device == 0xa084)
                        ahci_pci_bar = AHCI_PCI_BAR_CAVIUM_GEN5;
+       } else if (pdev->vendor == PCI_VENDOR_ID_LOONGSON) {
+               if (pdev->device == 0x7a08)
+                       ahci_pci_bar = AHCI_PCI_BAR_LOONGSON;
        }
 
        /* acquire resources */
index 42c8728..beca5f9 100644 (file)
@@ -2,10 +2,6 @@
 /*
  *  libata-core.c - helper library for ATA
  *
- *  Maintained by:  Tejun Heo <tj@kernel.org>
- *                 Please ALWAYS copy linux-ide@vger.kernel.org
- *                 on emails.
- *
  *  Copyright 2003-2004 Red Hat, Inc.  All rights reserved.
  *  Copyright 2003-2004 Jeff Garzik
  *
  *     http://www.compactflash.org (CF)
  *     http://www.qic.org (QIC157 - Tape and DSC)
  *     http://www.ce-ata.org (CE-ATA: not supported)
+ *
+ * libata is essentially a library of internal helper functions for
+ * low-level ATA host controller drivers.  As such, the API/ABI is
+ * likely to change as new drivers are added and updated.
+ * Do not depend on ABI/API stability.
  */
 
 #include <linux/kernel.h>
@@ -56,6 +57,7 @@
 #include <linux/leds.h>
 #include <linux/pm_runtime.h>
 #include <linux/platform_device.h>
+#include <asm/setup.h>
 
 #define CREATE_TRACE_POINTS
 #include <trace/events/libata.h>
 #include "libata.h"
 #include "libata-transport.h"
 
-/* debounce timing parameters in msecs { interval, duration, timeout } */
-const unsigned long sata_deb_timing_normal[]           = {   5,  100, 2000 };
-const unsigned long sata_deb_timing_hotplug[]          = {  25,  500, 2000 };
-const unsigned long sata_deb_timing_long[]             = { 100, 2000, 5000 };
-
 const struct ata_port_operations ata_base_port_ops = {
        .prereset               = ata_std_prereset,
        .postreset              = ata_std_postreset,
@@ -82,6 +79,7 @@ const struct ata_port_operations sata_port_ops = {
        .qc_defer               = ata_std_qc_defer,
        .hardreset              = sata_std_hardreset,
 };
+EXPORT_SYMBOL_GPL(sata_port_ops);
 
 static unsigned int ata_dev_init_params(struct ata_device *dev,
                                        u16 heads, u16 sectors);
@@ -91,14 +89,15 @@ static unsigned long ata_dev_blacklisted(const struct ata_device *dev);
 
 atomic_t ata_print_id = ATOMIC_INIT(0);
 
+#ifdef CONFIG_ATA_FORCE
 struct ata_force_param {
        const char      *name;
-       unsigned int    cbl;
-       int             spd_limit;
+       u8              cbl;
+       u8              spd_limit;
        unsigned long   xfer_mask;
        unsigned int    horkage_on;
        unsigned int    horkage_off;
-       unsigned int    lflags;
+       u16             lflags;
 };
 
 struct ata_force_ent {
@@ -110,10 +109,11 @@ struct ata_force_ent {
 static struct ata_force_ent *ata_force_tbl;
 static int ata_force_tbl_size;
 
-static char ata_force_param_buf[PAGE_SIZE] __initdata;
+static char ata_force_param_buf[COMMAND_LINE_SIZE] __initdata;
 /* param_buf is thrown away after initialization, disallow read */
 module_param_string(force, ata_force_param_buf, sizeof(ata_force_param_buf), 0);
 MODULE_PARM_DESC(force, "Force ATA configurations including cable type, link speed and transfer mode (see Documentation/admin-guide/kernel-parameters.rst for details)");
+#endif
 
 static int atapi_enabled = 1;
 module_param(atapi_enabled, int, 0444);
@@ -224,6 +224,7 @@ struct ata_link *ata_link_next(struct ata_link *link, struct ata_port *ap,
 
        return NULL;
 }
+EXPORT_SYMBOL_GPL(ata_link_next);
 
 /**
  *     ata_dev_next - device iteration helper
@@ -277,6 +278,7 @@ struct ata_device *ata_dev_next(struct ata_device *dev, struct ata_link *link,
                goto next;
        return dev;
 }
+EXPORT_SYMBOL_GPL(ata_dev_next);
 
 /**
  *     ata_dev_phys_link - find physical link for a device
@@ -303,6 +305,7 @@ struct ata_link *ata_dev_phys_link(struct ata_device *dev)
        return ap->slave_link;
 }
 
+#ifdef CONFIG_ATA_FORCE
 /**
  *     ata_force_cbl - force cable type according to libata.force
  *     @ap: ATA port of interest
@@ -483,6 +486,11 @@ static void ata_force_horkage(struct ata_device *dev)
                               fe->param.name);
        }
 }
+#else
+static inline void ata_force_link_limits(struct ata_link *link) { }
+static inline void ata_force_xfermask(struct ata_device *dev) { }
+static inline void ata_force_horkage(struct ata_device *dev) { }
+#endif
 
 /**
  *     atapi_cmd_type - Determine ATAPI command type from SCSI opcode
@@ -521,79 +529,7 @@ int atapi_cmd_type(u8 opcode)
                return ATAPI_MISC;
        }
 }
-
-/**
- *     ata_tf_to_fis - Convert ATA taskfile to SATA FIS structure
- *     @tf: Taskfile to convert
- *     @pmp: Port multiplier port
- *     @is_cmd: This FIS is for command
- *     @fis: Buffer into which data will output
- *
- *     Converts a standard ATA taskfile to a Serial ATA
- *     FIS structure (Register - Host to Device).
- *
- *     LOCKING:
- *     Inherited from caller.
- */
-void ata_tf_to_fis(const struct ata_taskfile *tf, u8 pmp, int is_cmd, u8 *fis)
-{
-       fis[0] = 0x27;                  /* Register - Host to Device FIS */
-       fis[1] = pmp & 0xf;             /* Port multiplier number*/
-       if (is_cmd)
-               fis[1] |= (1 << 7);     /* bit 7 indicates Command FIS */
-
-       fis[2] = tf->command;
-       fis[3] = tf->feature;
-
-       fis[4] = tf->lbal;
-       fis[5] = tf->lbam;
-       fis[6] = tf->lbah;
-       fis[7] = tf->device;
-
-       fis[8] = tf->hob_lbal;
-       fis[9] = tf->hob_lbam;
-       fis[10] = tf->hob_lbah;
-       fis[11] = tf->hob_feature;
-
-       fis[12] = tf->nsect;
-       fis[13] = tf->hob_nsect;
-       fis[14] = 0;
-       fis[15] = tf->ctl;
-
-       fis[16] = tf->auxiliary & 0xff;
-       fis[17] = (tf->auxiliary >> 8) & 0xff;
-       fis[18] = (tf->auxiliary >> 16) & 0xff;
-       fis[19] = (tf->auxiliary >> 24) & 0xff;
-}
-
-/**
- *     ata_tf_from_fis - Convert SATA FIS to ATA taskfile
- *     @fis: Buffer from which data will be input
- *     @tf: Taskfile to output
- *
- *     Converts a serial ATA FIS structure to a standard ATA taskfile.
- *
- *     LOCKING:
- *     Inherited from caller.
- */
-
-void ata_tf_from_fis(const u8 *fis, struct ata_taskfile *tf)
-{
-       tf->command     = fis[2];       /* status */
-       tf->feature     = fis[3];       /* error */
-
-       tf->lbal        = fis[4];
-       tf->lbam        = fis[5];
-       tf->lbah        = fis[6];
-       tf->device      = fis[7];
-
-       tf->hob_lbal    = fis[8];
-       tf->hob_lbam    = fis[9];
-       tf->hob_lbah    = fis[10];
-
-       tf->nsect       = fis[12];
-       tf->hob_nsect   = fis[13];
-}
+EXPORT_SYMBOL_GPL(atapi_cmd_type);
 
 static const u8 ata_rw_cmds[] = {
        /* pio multi */
@@ -868,6 +804,7 @@ unsigned long ata_pack_xfermask(unsigned long pio_mask,
                ((mwdma_mask << ATA_SHIFT_MWDMA) & ATA_MASK_MWDMA) |
                ((udma_mask << ATA_SHIFT_UDMA) & ATA_MASK_UDMA);
 }
+EXPORT_SYMBOL_GPL(ata_pack_xfermask);
 
 /**
  *     ata_unpack_xfermask - Unpack xfer_mask into pio, mwdma and udma masks
@@ -923,6 +860,7 @@ u8 ata_xfer_mask2mode(unsigned long xfer_mask)
                        return ent->base + highbit - ent->shift;
        return 0xff;
 }
+EXPORT_SYMBOL_GPL(ata_xfer_mask2mode);
 
 /**
  *     ata_xfer_mode2mask - Find matching xfer_mask for XFER_*
@@ -946,6 +884,7 @@ unsigned long ata_xfer_mode2mask(u8 xfer_mode)
                                & ~((1 << ent->shift) - 1);
        return 0;
 }
+EXPORT_SYMBOL_GPL(ata_xfer_mode2mask);
 
 /**
  *     ata_xfer_mode2shift - Find matching xfer_shift for XFER_*
@@ -968,6 +907,7 @@ int ata_xfer_mode2shift(unsigned long xfer_mode)
                        return ent->shift;
        return -1;
 }
+EXPORT_SYMBOL_GPL(ata_xfer_mode2shift);
 
 /**
  *     ata_mode_string - convert xfer_mask to string
@@ -1014,6 +954,7 @@ const char *ata_mode_string(unsigned long xfer_mask)
                return xfer_mode_str[highbit];
        return "<n/a>";
 }
+EXPORT_SYMBOL_GPL(ata_mode_string);
 
 const char *sata_spd_string(unsigned int spd)
 {
@@ -1094,6 +1035,7 @@ unsigned int ata_dev_classify(const struct ata_taskfile *tf)
        DPRINTK("unknown device\n");
        return ATA_DEV_UNKNOWN;
 }
+EXPORT_SYMBOL_GPL(ata_dev_classify);
 
 /**
  *     ata_id_string - Convert IDENTIFY DEVICE page into string
@@ -1130,6 +1072,7 @@ void ata_id_string(const u16 *id, unsigned char *s,
                len -= 2;
        }
 }
+EXPORT_SYMBOL_GPL(ata_id_string);
 
 /**
  *     ata_id_c_string - Convert IDENTIFY DEVICE page into C string
@@ -1157,6 +1100,7 @@ void ata_id_c_string(const u16 *id, unsigned char *s,
                p--;
        *p = '\0';
 }
+EXPORT_SYMBOL_GPL(ata_id_c_string);
 
 static u64 ata_id_n_sectors(const u16 *id)
 {
@@ -1514,6 +1458,7 @@ unsigned long ata_id_xfermask(const u16 *id)
 
        return ata_pack_xfermask(pio_mask, mwdma_mask, udma_mask);
 }
+EXPORT_SYMBOL_GPL(ata_id_xfermask);
 
 static void ata_qc_complete_internal(struct ata_queued_cmd *qc)
 {
@@ -1771,6 +1716,7 @@ unsigned int ata_pio_need_iordy(const struct ata_device *adev)
                return 1;
        return 0;
 }
+EXPORT_SYMBOL_GPL(ata_pio_need_iordy);
 
 /**
  *     ata_pio_mask_no_iordy   -       Return the non IORDY mask
@@ -1811,6 +1757,7 @@ unsigned int ata_do_dev_read_id(struct ata_device *dev,
        return ata_exec_internal(dev, tf, NULL, DMA_FROM_DEVICE,
                                     id, sizeof(id[0]) * ATA_ID_WORDS, 0);
 }
+EXPORT_SYMBOL_GPL(ata_do_dev_read_id);
 
 /**
  *     ata_dev_read_id - Read ID data from the specified device
@@ -2265,6 +2212,8 @@ static int ata_dev_config_ncq(struct ata_device *dev,
                desc[0] = '\0';
                return 0;
        }
+       if (!IS_ENABLED(CONFIG_SATA_HOST))
+               return 0;
        if (dev->horkage & ATA_HORKAGE_NONCQ) {
                snprintf(desc, desc_sz, "NCQ (not used)");
                return 0;
@@ -2783,6 +2732,7 @@ int ata_cable_40wire(struct ata_port *ap)
 {
        return ATA_CBL_PATA40;
 }
+EXPORT_SYMBOL_GPL(ata_cable_40wire);
 
 /**
  *     ata_cable_80wire        -       return 80 wire cable type
@@ -2796,6 +2746,7 @@ int ata_cable_80wire(struct ata_port *ap)
 {
        return ATA_CBL_PATA80;
 }
+EXPORT_SYMBOL_GPL(ata_cable_80wire);
 
 /**
  *     ata_cable_unknown       -       return unknown PATA cable.
@@ -2808,6 +2759,7 @@ int ata_cable_unknown(struct ata_port *ap)
 {
        return ATA_CBL_PATA_UNK;
 }
+EXPORT_SYMBOL_GPL(ata_cable_unknown);
 
 /**
  *     ata_cable_ignore        -       return ignored PATA cable.
@@ -2820,6 +2772,7 @@ int ata_cable_ignore(struct ata_port *ap)
 {
        return ATA_CBL_PATA_IGN;
 }
+EXPORT_SYMBOL_GPL(ata_cable_ignore);
 
 /**
  *     ata_cable_sata  -       return SATA cable type
@@ -2832,6 +2785,7 @@ int ata_cable_sata(struct ata_port *ap)
 {
        return ATA_CBL_SATA;
 }
+EXPORT_SYMBOL_GPL(ata_cable_sata);
 
 /**
  *     ata_bus_probe - Reset and probe ATA bus
@@ -3014,6 +2968,7 @@ struct ata_device *ata_dev_pair(struct ata_device *adev)
                return NULL;
        return pair;
 }
+EXPORT_SYMBOL_GPL(ata_dev_pair);
 
 /**
  *     sata_down_spd_limit - adjust SATA spd limit downward
@@ -3095,252 +3050,7 @@ int sata_down_spd_limit(struct ata_link *link, u32 spd_limit)
        return 0;
 }
 
-static int __sata_set_spd_needed(struct ata_link *link, u32 *scontrol)
-{
-       struct ata_link *host_link = &link->ap->link;
-       u32 limit, target, spd;
-
-       limit = link->sata_spd_limit;
-
-       /* Don't configure downstream link faster than upstream link.
-        * It doesn't speed up anything and some PMPs choke on such
-        * configuration.
-        */
-       if (!ata_is_host_link(link) && host_link->sata_spd)
-               limit &= (1 << host_link->sata_spd) - 1;
-
-       if (limit == UINT_MAX)
-               target = 0;
-       else
-               target = fls(limit);
-
-       spd = (*scontrol >> 4) & 0xf;
-       *scontrol = (*scontrol & ~0xf0) | ((target & 0xf) << 4);
-
-       return spd != target;
-}
-
-/**
- *     sata_set_spd_needed - is SATA spd configuration needed
- *     @link: Link in question
- *
- *     Test whether the spd limit in SControl matches
- *     @link->sata_spd_limit.  This function is used to determine
- *     whether hardreset is necessary to apply SATA spd
- *     configuration.
- *
- *     LOCKING:
- *     Inherited from caller.
- *
- *     RETURNS:
- *     1 if SATA spd configuration is needed, 0 otherwise.
- */
-static int sata_set_spd_needed(struct ata_link *link)
-{
-       u32 scontrol;
-
-       if (sata_scr_read(link, SCR_CONTROL, &scontrol))
-               return 1;
-
-       return __sata_set_spd_needed(link, &scontrol);
-}
-
-/**
- *     sata_set_spd - set SATA spd according to spd limit
- *     @link: Link to set SATA spd for
- *
- *     Set SATA spd of @link according to sata_spd_limit.
- *
- *     LOCKING:
- *     Inherited from caller.
- *
- *     RETURNS:
- *     0 if spd doesn't need to be changed, 1 if spd has been
- *     changed.  Negative errno if SCR registers are inaccessible.
- */
-int sata_set_spd(struct ata_link *link)
-{
-       u32 scontrol;
-       int rc;
-
-       if ((rc = sata_scr_read(link, SCR_CONTROL, &scontrol)))
-               return rc;
-
-       if (!__sata_set_spd_needed(link, &scontrol))
-               return 0;
-
-       if ((rc = sata_scr_write(link, SCR_CONTROL, scontrol)))
-               return rc;
-
-       return 1;
-}
-
-/*
- * This mode timing computation functionality is ported over from
- * drivers/ide/ide-timing.h and was originally written by Vojtech Pavlik
- */
-/*
- * PIO 0-4, MWDMA 0-2 and UDMA 0-6 timings (in nanoseconds).
- * These were taken from ATA/ATAPI-6 standard, rev 0a, except
- * for UDMA6, which is currently supported only by Maxtor drives.
- *
- * For PIO 5/6 MWDMA 3/4 see the CFA specification 3.0.
- */
-
-static const struct ata_timing ata_timing[] = {
-/*     { XFER_PIO_SLOW, 120, 290, 240, 960, 290, 240, 0,  960,   0 }, */
-       { XFER_PIO_0,     70, 290, 240, 600, 165, 150, 0,  600,   0 },
-       { XFER_PIO_1,     50, 290,  93, 383, 125, 100, 0,  383,   0 },
-       { XFER_PIO_2,     30, 290,  40, 330, 100,  90, 0,  240,   0 },
-       { XFER_PIO_3,     30,  80,  70, 180,  80,  70, 0,  180,   0 },
-       { XFER_PIO_4,     25,  70,  25, 120,  70,  25, 0,  120,   0 },
-       { XFER_PIO_5,     15,  65,  25, 100,  65,  25, 0,  100,   0 },
-       { XFER_PIO_6,     10,  55,  20,  80,  55,  20, 0,   80,   0 },
-
-       { XFER_SW_DMA_0, 120,   0,   0,   0, 480, 480, 50, 960,   0 },
-       { XFER_SW_DMA_1,  90,   0,   0,   0, 240, 240, 30, 480,   0 },
-       { XFER_SW_DMA_2,  60,   0,   0,   0, 120, 120, 20, 240,   0 },
-
-       { XFER_MW_DMA_0,  60,   0,   0,   0, 215, 215, 20, 480,   0 },
-       { XFER_MW_DMA_1,  45,   0,   0,   0,  80,  50, 5,  150,   0 },
-       { XFER_MW_DMA_2,  25,   0,   0,   0,  70,  25, 5,  120,   0 },
-       { XFER_MW_DMA_3,  25,   0,   0,   0,  65,  25, 5,  100,   0 },
-       { XFER_MW_DMA_4,  25,   0,   0,   0,  55,  20, 5,   80,   0 },
-
-/*     { XFER_UDMA_SLOW,  0,   0,   0,   0,   0,   0, 0,    0, 150 }, */
-       { XFER_UDMA_0,     0,   0,   0,   0,   0,   0, 0,    0, 120 },
-       { XFER_UDMA_1,     0,   0,   0,   0,   0,   0, 0,    0,  80 },
-       { XFER_UDMA_2,     0,   0,   0,   0,   0,   0, 0,    0,  60 },
-       { XFER_UDMA_3,     0,   0,   0,   0,   0,   0, 0,    0,  45 },
-       { XFER_UDMA_4,     0,   0,   0,   0,   0,   0, 0,    0,  30 },
-       { XFER_UDMA_5,     0,   0,   0,   0,   0,   0, 0,    0,  20 },
-       { XFER_UDMA_6,     0,   0,   0,   0,   0,   0, 0,    0,  15 },
-
-       { 0xFF }
-};
-
-#define ENOUGH(v, unit)                (((v)-1)/(unit)+1)
-#define EZ(v, unit)            ((v)?ENOUGH(((v) * 1000), unit):0)
-
-static void ata_timing_quantize(const struct ata_timing *t, struct ata_timing *q, int T, int UT)
-{
-       q->setup        = EZ(t->setup,       T);
-       q->act8b        = EZ(t->act8b,       T);
-       q->rec8b        = EZ(t->rec8b,       T);
-       q->cyc8b        = EZ(t->cyc8b,       T);
-       q->active       = EZ(t->active,      T);
-       q->recover      = EZ(t->recover,     T);
-       q->dmack_hold   = EZ(t->dmack_hold,  T);
-       q->cycle        = EZ(t->cycle,       T);
-       q->udma         = EZ(t->udma,       UT);
-}
-
-void ata_timing_merge(const struct ata_timing *a, const struct ata_timing *b,
-                     struct ata_timing *m, unsigned int what)
-{
-       if (what & ATA_TIMING_SETUP  ) m->setup   = max(a->setup,   b->setup);
-       if (what & ATA_TIMING_ACT8B  ) m->act8b   = max(a->act8b,   b->act8b);
-       if (what & ATA_TIMING_REC8B  ) m->rec8b   = max(a->rec8b,   b->rec8b);
-       if (what & ATA_TIMING_CYC8B  ) m->cyc8b   = max(a->cyc8b,   b->cyc8b);
-       if (what & ATA_TIMING_ACTIVE ) m->active  = max(a->active,  b->active);
-       if (what & ATA_TIMING_RECOVER) m->recover = max(a->recover, b->recover);
-       if (what & ATA_TIMING_DMACK_HOLD) m->dmack_hold = max(a->dmack_hold, b->dmack_hold);
-       if (what & ATA_TIMING_CYCLE  ) m->cycle   = max(a->cycle,   b->cycle);
-       if (what & ATA_TIMING_UDMA   ) m->udma    = max(a->udma,    b->udma);
-}
-
-const struct ata_timing *ata_timing_find_mode(u8 xfer_mode)
-{
-       const struct ata_timing *t = ata_timing;
-
-       while (xfer_mode > t->mode)
-               t++;
-
-       if (xfer_mode == t->mode)
-               return t;
-
-       WARN_ONCE(true, "%s: unable to find timing for xfer_mode 0x%x\n",
-                       __func__, xfer_mode);
-
-       return NULL;
-}
-
-int ata_timing_compute(struct ata_device *adev, unsigned short speed,
-                      struct ata_timing *t, int T, int UT)
-{
-       const u16 *id = adev->id;
-       const struct ata_timing *s;
-       struct ata_timing p;
-
-       /*
-        * Find the mode.
-        */
-
-       if (!(s = ata_timing_find_mode(speed)))
-               return -EINVAL;
-
-       memcpy(t, s, sizeof(*s));
-
-       /*
-        * If the drive is an EIDE drive, it can tell us it needs extended
-        * PIO/MW_DMA cycle timing.
-        */
-
-       if (id[ATA_ID_FIELD_VALID] & 2) {       /* EIDE drive */
-               memset(&p, 0, sizeof(p));
-
-               if (speed >= XFER_PIO_0 && speed < XFER_SW_DMA_0) {
-                       if (speed <= XFER_PIO_2)
-                               p.cycle = p.cyc8b = id[ATA_ID_EIDE_PIO];
-                       else if ((speed <= XFER_PIO_4) ||
-                                (speed == XFER_PIO_5 && !ata_id_is_cfa(id)))
-                               p.cycle = p.cyc8b = id[ATA_ID_EIDE_PIO_IORDY];
-               } else if (speed >= XFER_MW_DMA_0 && speed <= XFER_MW_DMA_2)
-                       p.cycle = id[ATA_ID_EIDE_DMA_MIN];
-
-               ata_timing_merge(&p, t, t, ATA_TIMING_CYCLE | ATA_TIMING_CYC8B);
-       }
-
-       /*
-        * Convert the timing to bus clock counts.
-        */
-
-       ata_timing_quantize(t, t, T, UT);
-
-       /*
-        * Even in DMA/UDMA modes we still use PIO access for IDENTIFY,
-        * S.M.A.R.T * and some other commands. We have to ensure that the
-        * DMA cycle timing is slower/equal than the fastest PIO timing.
-        */
-
-       if (speed > XFER_PIO_6) {
-               ata_timing_compute(adev, adev->pio_mode, &p, T, UT);
-               ata_timing_merge(&p, t, t, ATA_TIMING_ALL);
-       }
-
-       /*
-        * Lengthen active & recovery time so that cycle time is correct.
-        */
-
-       if (t->act8b + t->rec8b < t->cyc8b) {
-               t->act8b += (t->cyc8b - (t->act8b + t->rec8b)) / 2;
-               t->rec8b = t->cyc8b - t->act8b;
-       }
-
-       if (t->active + t->recover < t->cycle) {
-               t->active += (t->cycle - (t->active + t->recover)) / 2;
-               t->recover = t->cycle - t->active;
-       }
-
-       /* In a few cases quantisation may produce enough errors to
-          leave t->cycle too low for the sum of active and recovery
-          if so we must correct this */
-       if (t->active + t->recover > t->cycle)
-               t->cycle = t->active + t->recover;
-
-       return 0;
-}
-
+#ifdef CONFIG_ATA_ACPI
 /**
  *     ata_timing_cycle2mode - find xfer mode for the specified cycle duration
  *     @xfer_shift: ATA_SHIFT_* value for transfer type to examine.
@@ -3391,6 +3101,7 @@ u8 ata_timing_cycle2mode(unsigned int xfer_shift, int cycle)
 
        return last_mode;
 }
+#endif
 
 /**
  *     ata_down_xfermask_limit - adjust dev xfer masks downward
@@ -3662,6 +3373,7 @@ int ata_do_set_mode(struct ata_link *link, struct ata_device **r_failed_dev)
                *r_failed_dev = dev;
        return rc;
 }
+EXPORT_SYMBOL_GPL(ata_do_set_mode);
 
 /**
  *     ata_wait_ready - wait for link to become ready
@@ -3771,216 +3483,7 @@ int ata_wait_after_reset(struct ata_link *link, unsigned long deadline,
 
        return ata_wait_ready(link, deadline, check_ready);
 }
-
-/**
- *     sata_link_debounce - debounce SATA phy status
- *     @link: ATA link to debounce SATA phy status for
- *     @params: timing parameters { interval, duration, timeout } in msec
- *     @deadline: deadline jiffies for the operation
- *
- *     Make sure SStatus of @link reaches stable state, determined by
- *     holding the same value where DET is not 1 for @duration polled
- *     every @interval, before @timeout.  Timeout constraints the
- *     beginning of the stable state.  Because DET gets stuck at 1 on
- *     some controllers after hot unplugging, this functions waits
- *     until timeout then returns 0 if DET is stable at 1.
- *
- *     @timeout is further limited by @deadline.  The sooner of the
- *     two is used.
- *
- *     LOCKING:
- *     Kernel thread context (may sleep)
- *
- *     RETURNS:
- *     0 on success, -errno on failure.
- */
-int sata_link_debounce(struct ata_link *link, const unsigned long *params,
-                      unsigned long deadline)
-{
-       unsigned long interval = params[0];
-       unsigned long duration = params[1];
-       unsigned long last_jiffies, t;
-       u32 last, cur;
-       int rc;
-
-       t = ata_deadline(jiffies, params[2]);
-       if (time_before(t, deadline))
-               deadline = t;
-
-       if ((rc = sata_scr_read(link, SCR_STATUS, &cur)))
-               return rc;
-       cur &= 0xf;
-
-       last = cur;
-       last_jiffies = jiffies;
-
-       while (1) {
-               ata_msleep(link->ap, interval);
-               if ((rc = sata_scr_read(link, SCR_STATUS, &cur)))
-                       return rc;
-               cur &= 0xf;
-
-               /* DET stable? */
-               if (cur == last) {
-                       if (cur == 1 && time_before(jiffies, deadline))
-                               continue;
-                       if (time_after(jiffies,
-                                      ata_deadline(last_jiffies, duration)))
-                               return 0;
-                       continue;
-               }
-
-               /* unstable, start over */
-               last = cur;
-               last_jiffies = jiffies;
-
-               /* Check deadline.  If debouncing failed, return
-                * -EPIPE to tell upper layer to lower link speed.
-                */
-               if (time_after(jiffies, deadline))
-                       return -EPIPE;
-       }
-}
-
-/**
- *     sata_link_resume - resume SATA link
- *     @link: ATA link to resume SATA
- *     @params: timing parameters { interval, duration, timeout } in msec
- *     @deadline: deadline jiffies for the operation
- *
- *     Resume SATA phy @link and debounce it.
- *
- *     LOCKING:
- *     Kernel thread context (may sleep)
- *
- *     RETURNS:
- *     0 on success, -errno on failure.
- */
-int sata_link_resume(struct ata_link *link, const unsigned long *params,
-                    unsigned long deadline)
-{
-       int tries = ATA_LINK_RESUME_TRIES;
-       u32 scontrol, serror;
-       int rc;
-
-       if ((rc = sata_scr_read(link, SCR_CONTROL, &scontrol)))
-               return rc;
-
-       /*
-        * Writes to SControl sometimes get ignored under certain
-        * controllers (ata_piix SIDPR).  Make sure DET actually is
-        * cleared.
-        */
-       do {
-               scontrol = (scontrol & 0x0f0) | 0x300;
-               if ((rc = sata_scr_write(link, SCR_CONTROL, scontrol)))
-                       return rc;
-               /*
-                * Some PHYs react badly if SStatus is pounded
-                * immediately after resuming.  Delay 200ms before
-                * debouncing.
-                */
-               if (!(link->flags & ATA_LFLAG_NO_DB_DELAY))
-                       ata_msleep(link->ap, 200);
-
-               /* is SControl restored correctly? */
-               if ((rc = sata_scr_read(link, SCR_CONTROL, &scontrol)))
-                       return rc;
-       } while ((scontrol & 0xf0f) != 0x300 && --tries);
-
-       if ((scontrol & 0xf0f) != 0x300) {
-               ata_link_warn(link, "failed to resume link (SControl %X)\n",
-                            scontrol);
-               return 0;
-       }
-
-       if (tries < ATA_LINK_RESUME_TRIES)
-               ata_link_warn(link, "link resume succeeded after %d retries\n",
-                             ATA_LINK_RESUME_TRIES - tries);
-
-       if ((rc = sata_link_debounce(link, params, deadline)))
-               return rc;
-
-       /* clear SError, some PHYs require this even for SRST to work */
-       if (!(rc = sata_scr_read(link, SCR_ERROR, &serror)))
-               rc = sata_scr_write(link, SCR_ERROR, serror);
-
-       return rc != -EINVAL ? rc : 0;
-}
-
-/**
- *     sata_link_scr_lpm - manipulate SControl IPM and SPM fields
- *     @link: ATA link to manipulate SControl for
- *     @policy: LPM policy to configure
- *     @spm_wakeup: initiate LPM transition to active state
- *
- *     Manipulate the IPM field of the SControl register of @link
- *     according to @policy.  If @policy is ATA_LPM_MAX_POWER and
- *     @spm_wakeup is %true, the SPM field is manipulated to wake up
- *     the link.  This function also clears PHYRDY_CHG before
- *     returning.
- *
- *     LOCKING:
- *     EH context.
- *
- *     RETURNS:
- *     0 on success, -errno otherwise.
- */
-int sata_link_scr_lpm(struct ata_link *link, enum ata_lpm_policy policy,
-                     bool spm_wakeup)
-{
-       struct ata_eh_context *ehc = &link->eh_context;
-       bool woken_up = false;
-       u32 scontrol;
-       int rc;
-
-       rc = sata_scr_read(link, SCR_CONTROL, &scontrol);
-       if (rc)
-               return rc;
-
-       switch (policy) {
-       case ATA_LPM_MAX_POWER:
-               /* disable all LPM transitions */
-               scontrol |= (0x7 << 8);
-               /* initiate transition to active state */
-               if (spm_wakeup) {
-                       scontrol |= (0x4 << 12);
-                       woken_up = true;
-               }
-               break;
-       case ATA_LPM_MED_POWER:
-               /* allow LPM to PARTIAL */
-               scontrol &= ~(0x1 << 8);
-               scontrol |= (0x6 << 8);
-               break;
-       case ATA_LPM_MED_POWER_WITH_DIPM:
-       case ATA_LPM_MIN_POWER_WITH_PARTIAL:
-       case ATA_LPM_MIN_POWER:
-               if (ata_link_nr_enabled(link) > 0)
-                       /* no restrictions on LPM transitions */
-                       scontrol &= ~(0x7 << 8);
-               else {
-                       /* empty port, power off */
-                       scontrol &= ~0xf;
-                       scontrol |= (0x1 << 2);
-               }
-               break;
-       default:
-               WARN_ON(1);
-       }
-
-       rc = sata_scr_write(link, SCR_CONTROL, scontrol);
-       if (rc)
-               return rc;
-
-       /* give the link time to transit out of LPM state */
-       if (woken_up)
-               msleep(10);
-
-       /* clear PHYRDY_CHG from SError */
-       ehc->i.serror &= ~SERR_PHYRDY_CHG;
-       return sata_scr_write(link, SCR_ERROR, SERR_PHYRDY_CHG);
-}
+EXPORT_SYMBOL_GPL(ata_wait_after_reset);
 
 /**
  *     ata_std_prereset - prepare for reset
@@ -4026,118 +3529,7 @@ int ata_std_prereset(struct ata_link *link, unsigned long deadline)
 
        return 0;
 }
-
-/**
- *     sata_link_hardreset - reset link via SATA phy reset
- *     @link: link to reset
- *     @timing: timing parameters { interval, duration, timeout } in msec
- *     @deadline: deadline jiffies for the operation
- *     @online: optional out parameter indicating link onlineness
- *     @check_ready: optional callback to check link readiness
- *
- *     SATA phy-reset @link using DET bits of SControl register.
- *     After hardreset, link readiness is waited upon using
- *     ata_wait_ready() if @check_ready is specified.  LLDs are
- *     allowed to not specify @check_ready and wait itself after this
- *     function returns.  Device classification is LLD's
- *     responsibility.
- *
- *     *@online is set to one iff reset succeeded and @link is online
- *     after reset.
- *
- *     LOCKING:
- *     Kernel thread context (may sleep)
- *
- *     RETURNS:
- *     0 on success, -errno otherwise.
- */
-int sata_link_hardreset(struct ata_link *link, const unsigned long *timing,
-                       unsigned long deadline,
-                       bool *online, int (*check_ready)(struct ata_link *))
-{
-       u32 scontrol;
-       int rc;
-
-       DPRINTK("ENTER\n");
-
-       if (online)
-               *online = false;
-
-       if (sata_set_spd_needed(link)) {
-               /* SATA spec says nothing about how to reconfigure
-                * spd.  To be on the safe side, turn off phy during
-                * reconfiguration.  This works for at least ICH7 AHCI
-                * and Sil3124.
-                */
-               if ((rc = sata_scr_read(link, SCR_CONTROL, &scontrol)))
-                       goto out;
-
-               scontrol = (scontrol & 0x0f0) | 0x304;
-
-               if ((rc = sata_scr_write(link, SCR_CONTROL, scontrol)))
-                       goto out;
-
-               sata_set_spd(link);
-       }
-
-       /* issue phy wake/reset */
-       if ((rc = sata_scr_read(link, SCR_CONTROL, &scontrol)))
-               goto out;
-
-       scontrol = (scontrol & 0x0f0) | 0x301;
-
-       if ((rc = sata_scr_write_flush(link, SCR_CONTROL, scontrol)))
-               goto out;
-
-       /* Couldn't find anything in SATA I/II specs, but AHCI-1.1
-        * 10.4.2 says at least 1 ms.
-        */
-       ata_msleep(link->ap, 1);
-
-       /* bring link back */
-       rc = sata_link_resume(link, timing, deadline);
-       if (rc)
-               goto out;
-       /* if link is offline nothing more to do */
-       if (ata_phys_link_offline(link))
-               goto out;
-
-       /* Link is online.  From this point, -ENODEV too is an error. */
-       if (online)
-               *online = true;
-
-       if (sata_pmp_supported(link->ap) && ata_is_host_link(link)) {
-               /* If PMP is supported, we have to do follow-up SRST.
-                * Some PMPs don't send D2H Reg FIS after hardreset if
-                * the first port is empty.  Wait only for
-                * ATA_TMOUT_PMP_SRST_WAIT.
-                */
-               if (check_ready) {
-                       unsigned long pmp_deadline;
-
-                       pmp_deadline = ata_deadline(jiffies,
-                                                   ATA_TMOUT_PMP_SRST_WAIT);
-                       if (time_after(pmp_deadline, deadline))
-                               pmp_deadline = deadline;
-                       ata_wait_ready(link, pmp_deadline, check_ready);
-               }
-               rc = -EAGAIN;
-               goto out;
-       }
-
-       rc = 0;
-       if (check_ready)
-               rc = ata_wait_ready(link, deadline, check_ready);
- out:
-       if (rc && rc != -EAGAIN) {
-               /* online is set iff link is online && reset succeeded */
-               if (online)
-                       *online = false;
-               ata_link_err(link, "COMRESET failed (errno=%d)\n", rc);
-       }
-       DPRINTK("EXIT, rc=%d\n", rc);
-       return rc;
-}
+EXPORT_SYMBOL_GPL(ata_std_prereset);
 
 /**
  *     sata_std_hardreset - COMRESET w/o waiting or classification
@@ -4164,6 +3556,7 @@ int sata_std_hardreset(struct ata_link *link, unsigned int *class,
        rc = sata_link_hardreset(link, timing, deadline, &online, NULL);
        return online ? -EAGAIN : rc;
 }
+EXPORT_SYMBOL_GPL(sata_std_hardreset);
 
 /**
  *     ata_std_postreset - standard postreset callback
@@ -4192,6 +3585,7 @@ void ata_std_postreset(struct ata_link *link, unsigned int *classes)
 
        DPRINTK("EXIT\n");
 }
+EXPORT_SYMBOL_GPL(ata_std_postreset);
 
 /**
  *     ata_dev_same_device - Determine whether new ID matches configured device
@@ -4979,11 +4373,13 @@ int ata_std_qc_defer(struct ata_queued_cmd *qc)
 
        return ATA_DEFER_LINK;
 }
+EXPORT_SYMBOL_GPL(ata_std_qc_defer);
 
 enum ata_completion_errors ata_noop_qc_prep(struct ata_queued_cmd *qc)
 {
        return AC_ERR_OK;
 }
+EXPORT_SYMBOL_GPL(ata_noop_qc_prep);
 
 /**
  *     ata_sg_init - Associate command with scatter-gather table.
@@ -5327,6 +4723,7 @@ void ata_qc_complete(struct ata_queued_cmd *qc)
                __ata_qc_complete(qc);
        }
 }
+EXPORT_SYMBOL_GPL(ata_qc_complete);
 
 /**
  *     ata_qc_get_active - get bitmask of active qcs
@@ -5353,64 +4750,6 @@ u64 ata_qc_get_active(struct ata_port *ap)
 EXPORT_SYMBOL_GPL(ata_qc_get_active);
 
 /**
- *     ata_qc_complete_multiple - Complete multiple qcs successfully
- *     @ap: port in question
- *     @qc_active: new qc_active mask
- *
- *     Complete in-flight commands.  This functions is meant to be
- *     called from low-level driver's interrupt routine to complete
- *     requests normally.  ap->qc_active and @qc_active is compared
- *     and commands are completed accordingly.
- *
- *     Always use this function when completing multiple NCQ commands
- *     from IRQ handlers instead of calling ata_qc_complete()
- *     multiple times to keep IRQ expect status properly in sync.
- *
- *     LOCKING:
- *     spin_lock_irqsave(host lock)
- *
- *     RETURNS:
- *     Number of completed commands on success, -errno otherwise.
- */
-int ata_qc_complete_multiple(struct ata_port *ap, u64 qc_active)
-{
-       u64 done_mask, ap_qc_active = ap->qc_active;
-       int nr_done = 0;
-
-       /*
-        * If the internal tag is set on ap->qc_active, then we care about
-        * bit0 on the passed in qc_active mask. Move that bit up to match
-        * the internal tag.
-        */
-       if (ap_qc_active & (1ULL << ATA_TAG_INTERNAL)) {
-               qc_active |= (qc_active & 0x01) << ATA_TAG_INTERNAL;
-               qc_active ^= qc_active & 0x01;
-       }
-
-       done_mask = ap_qc_active ^ qc_active;
-
-       if (unlikely(done_mask & qc_active)) {
-               ata_port_err(ap, "illegal qc_active transition (%08llx->%08llx)\n",
-                            ap->qc_active, qc_active);
-               return -EINVAL;
-       }
-
-       while (done_mask) {
-               struct ata_queued_cmd *qc;
-               unsigned int tag = __ffs64(done_mask);
-
-               qc = ata_qc_from_tag(ap, tag);
-               if (qc) {
-                       ata_qc_complete(qc);
-                       nr_done++;
-               }
-               done_mask &= ~(1ULL << tag);
-       }
-
-       return nr_done;
-}
-
-/**
  *     ata_qc_issue - issue taskfile to device
  *     @qc: command to issue to device
  *
@@ -5486,111 +4825,6 @@ err:
 }
 
 /**
- *     sata_scr_valid - test whether SCRs are accessible
- *     @link: ATA link to test SCR accessibility for
- *
- *     Test whether SCRs are accessible for @link.
- *
- *     LOCKING:
- *     None.
- *
- *     RETURNS:
- *     1 if SCRs are accessible, 0 otherwise.
- */
-int sata_scr_valid(struct ata_link *link)
-{
-       struct ata_port *ap = link->ap;
-
-       return (ap->flags & ATA_FLAG_SATA) && ap->ops->scr_read;
-}
-
-/**
- *     sata_scr_read - read SCR register of the specified port
- *     @link: ATA link to read SCR for
- *     @reg: SCR to read
- *     @val: Place to store read value
- *
- *     Read SCR register @reg of @link into *@val.  This function is
- *     guaranteed to succeed if @link is ap->link, the cable type of
- *     the port is SATA and the port implements ->scr_read.
- *
- *     LOCKING:
- *     None if @link is ap->link.  Kernel thread context otherwise.
- *
- *     RETURNS:
- *     0 on success, negative errno on failure.
- */
-int sata_scr_read(struct ata_link *link, int reg, u32 *val)
-{
-       if (ata_is_host_link(link)) {
-               if (sata_scr_valid(link))
-                       return link->ap->ops->scr_read(link, reg, val);
-               return -EOPNOTSUPP;
-       }
-
-       return sata_pmp_scr_read(link, reg, val);
-}
-
-/**
- *     sata_scr_write - write SCR register of the specified port
- *     @link: ATA link to write SCR for
- *     @reg: SCR to write
- *     @val: value to write
- *
- *     Write @val to SCR register @reg of @link.  This function is
- *     guaranteed to succeed if @link is ap->link, the cable type of
- *     the port is SATA and the port implements ->scr_read.
- *
- *     LOCKING:
- *     None if @link is ap->link.  Kernel thread context otherwise.
- *
- *     RETURNS:
- *     0 on success, negative errno on failure.
- */
-int sata_scr_write(struct ata_link *link, int reg, u32 val)
-{
-       if (ata_is_host_link(link)) {
-               if (sata_scr_valid(link))
-                       return link->ap->ops->scr_write(link, reg, val);
-               return -EOPNOTSUPP;
-       }
-
-       return sata_pmp_scr_write(link, reg, val);
-}
-
-/**
- *     sata_scr_write_flush - write SCR register of the specified port and flush
- *     @link: ATA link to write SCR for
- *     @reg: SCR to write
- *     @val: value to write
- *
- *     This function is identical to sata_scr_write() except that this
- *     function performs flush after writing to the register.
- *
- *     LOCKING:
- *     None if @link is ap->link.  Kernel thread context otherwise.
- *
- *     RETURNS:
- *     0 on success, negative errno on failure.
- */
-int sata_scr_write_flush(struct ata_link *link, int reg, u32 val)
-{
-       if (ata_is_host_link(link)) {
-               int rc;
-
-               if (sata_scr_valid(link)) {
-                       rc = link->ap->ops->scr_write(link, reg, val);
-                       if (rc == 0)
-                               rc = link->ap->ops->scr_read(link, reg, &val);
-                       return rc;
-               }
-               return -EOPNOTSUPP;
-       }
-
-       return sata_pmp_scr_write(link, reg, val);
-}
-
-/**
  *     ata_phys_link_online - test whether the given link is online
  *     @link: ATA link to test
  *
@@ -5663,6 +4897,7 @@ bool ata_link_online(struct ata_link *link)
        return ata_phys_link_online(link) ||
                (slave && ata_phys_link_online(slave));
 }
+EXPORT_SYMBOL_GPL(ata_link_online);
 
 /**
  *     ata_link_offline - test whether the given link is offline
@@ -5689,6 +4924,7 @@ bool ata_link_offline(struct ata_link *link)
        return ata_phys_link_offline(link) &&
                (!slave || ata_phys_link_offline(slave));
 }
+EXPORT_SYMBOL_GPL(ata_link_offline);
 
 #ifdef CONFIG_PM
 static void ata_port_request_pm(struct ata_port *ap, pm_message_t mesg,
@@ -5875,6 +5111,7 @@ int ata_host_suspend(struct ata_host *host, pm_message_t mesg)
        host->dev->power.power_state = mesg;
        return 0;
 }
+EXPORT_SYMBOL_GPL(ata_host_suspend);
 
 /**
  *     ata_host_resume - resume host
@@ -5886,6 +5123,7 @@ void ata_host_resume(struct ata_host *host)
 {
        host->dev->power.power_state = PMSG_ON;
 }
+EXPORT_SYMBOL_GPL(ata_host_resume);
 #endif
 
 const struct device_type ata_port_type = {
@@ -6105,6 +5343,7 @@ void ata_host_put(struct ata_host *host)
 {
        kref_put(&host->kref, ata_host_release);
 }
+EXPORT_SYMBOL_GPL(ata_host_put);
 
 /**
  *     ata_host_alloc - allocate and init basic ATA host resources
@@ -6178,6 +5417,7 @@ struct ata_host *ata_host_alloc(struct device *dev, int max_ports)
        kfree(host);
        return NULL;
 }
+EXPORT_SYMBOL_GPL(ata_host_alloc);
 
 /**
  *     ata_host_alloc_pinfo - alloc host and init with port_info array
@@ -6226,68 +5466,7 @@ struct ata_host *ata_host_alloc_pinfo(struct device *dev,
 
        return host;
 }
-
-/**
- *     ata_slave_link_init - initialize slave link
- *     @ap: port to initialize slave link for
- *
- *     Create and initialize slave link for @ap.  This enables slave
- *     link handling on the port.
- *
- *     In libata, a port contains links and a link contains devices.
- *     There is single host link but if a PMP is attached to it,
- *     there can be multiple fan-out links.  On SATA, there's usually
- *     a single device connected to a link but PATA and SATA
- *     controllers emulating TF based interface can have two - master
- *     and slave.
- *
- *     However, there are a few controllers which don't fit into this
- *     abstraction too well - SATA controllers which emulate TF
- *     interface with both master and slave devices but also have
- *     separate SCR register sets for each device.  These controllers
- *     need separate links for physical link handling
- *     (e.g. onlineness, link speed) but should be treated like a
- *     traditional M/S controller for everything else (e.g. command
- *     issue, softreset).
- *
- *     slave_link is libata's way of handling this class of
- *     controllers without impacting core layer too much.  For
- *     anything other than physical link handling, the default host
- *     link is used for both master and slave.  For physical link
- *     handling, separate @ap->slave_link is used.  All dirty details
- *     are implemented inside libata core layer.  From LLD's POV, the
- *     only difference is that prereset, hardreset and postreset are
- *     called once more for the slave link, so the reset sequence
- *     looks like the following.
- *
- *     prereset(M) -> prereset(S) -> hardreset(M) -> hardreset(S) ->
- *     softreset(M) -> postreset(M) -> postreset(S)
- *
- *     Note that softreset is called only for the master.  Softreset
- *     resets both M/S by definition, so SRST on master should handle
- *     both (the standard method will work just fine).
- *
- *     LOCKING:
- *     Should be called before host is registered.
- *
- *     RETURNS:
- *     0 on success, -errno on failure.
- */
-int ata_slave_link_init(struct ata_port *ap)
-{
-       struct ata_link *link;
-
-       WARN_ON(ap->slave_link);
-       WARN_ON(ap->flags & ATA_FLAG_PMP);
-
-       link = kzalloc(sizeof(*link), GFP_KERNEL);
-       if (!link)
-               return -ENOMEM;
-
-       ata_link_init(ap, link, 1);
-       ap->slave_link = link;
-       return 0;
-}
+EXPORT_SYMBOL_GPL(ata_host_alloc_pinfo);
 
 static void ata_host_stop(struct device *gendev, void *res)
 {
@@ -6436,6 +5615,7 @@ int ata_host_start(struct ata_host *host)
        devres_free(start_dr);
        return rc;
 }
+EXPORT_SYMBOL_GPL(ata_host_start);
 
 /**
  *     ata_sas_host_init - Initialize a host struct for sas (ipr, libsas)
@@ -6454,6 +5634,7 @@ void ata_host_init(struct ata_host *host, struct device *dev,
        host->ops = ops;
        kref_init(&host->kref);
 }
+EXPORT_SYMBOL_GPL(ata_host_init);
 
 void __ata_port_probe(struct ata_port *ap)
 {
@@ -6609,6 +5790,7 @@ int ata_host_register(struct ata_host *host, struct scsi_host_template *sht)
        return rc;
 
 }
+EXPORT_SYMBOL_GPL(ata_host_register);
 
 /**
  *     ata_host_activate - start host, request IRQ and register it
@@ -6671,6 +5853,7 @@ int ata_host_activate(struct ata_host *host, int irq,
 
        return rc;
 }
+EXPORT_SYMBOL_GPL(ata_host_activate);
 
 /**
  *     ata_port_detach - Detach ATA port in preparation of device removal
@@ -6746,6 +5929,7 @@ void ata_host_detach(struct ata_host *host)
        /* the host is dead now, dissociate ACPI */
        ata_acpi_dissociate(host);
 }
+EXPORT_SYMBOL_GPL(ata_host_detach);
 
 #ifdef CONFIG_PCI
 
@@ -6766,6 +5950,7 @@ void ata_pci_remove_one(struct pci_dev *pdev)
 
        ata_host_detach(host);
 }
+EXPORT_SYMBOL_GPL(ata_pci_remove_one);
 
 void ata_pci_shutdown_one(struct pci_dev *pdev)
 {
@@ -6786,6 +5971,7 @@ void ata_pci_shutdown_one(struct pci_dev *pdev)
                        ap->ops->port_stop(ap);
        }
 }
+EXPORT_SYMBOL_GPL(ata_pci_shutdown_one);
 
 /* move to PCI subsystem */
 int pci_test_config_bits(struct pci_dev *pdev, const struct pci_bits *bits)
@@ -6820,6 +6006,7 @@ int pci_test_config_bits(struct pci_dev *pdev, const struct pci_bits *bits)
 
        return (tmp == bits->val) ? 1 : 0;
 }
+EXPORT_SYMBOL_GPL(pci_test_config_bits);
 
 #ifdef CONFIG_PM
 void ata_pci_device_do_suspend(struct pci_dev *pdev, pm_message_t mesg)
@@ -6830,6 +6017,7 @@ void ata_pci_device_do_suspend(struct pci_dev *pdev, pm_message_t mesg)
        if (mesg.event & PM_EVENT_SLEEP)
                pci_set_power_state(pdev, PCI_D3hot);
 }
+EXPORT_SYMBOL_GPL(ata_pci_device_do_suspend);
 
 int ata_pci_device_do_resume(struct pci_dev *pdev)
 {
@@ -6848,6 +6036,7 @@ int ata_pci_device_do_resume(struct pci_dev *pdev)
        pci_set_master(pdev);
        return 0;
 }
+EXPORT_SYMBOL_GPL(ata_pci_device_do_resume);
 
 int ata_pci_device_suspend(struct pci_dev *pdev, pm_message_t mesg)
 {
@@ -6862,6 +6051,7 @@ int ata_pci_device_suspend(struct pci_dev *pdev, pm_message_t mesg)
 
        return 0;
 }
+EXPORT_SYMBOL_GPL(ata_pci_device_suspend);
 
 int ata_pci_device_resume(struct pci_dev *pdev)
 {
@@ -6873,8 +6063,8 @@ int ata_pci_device_resume(struct pci_dev *pdev)
                ata_host_resume(host);
        return rc;
 }
+EXPORT_SYMBOL_GPL(ata_pci_device_resume);
 #endif /* CONFIG_PM */
-
 #endif /* CONFIG_PCI */
 
 /**
@@ -6896,7 +6086,9 @@ int ata_platform_remove_one(struct platform_device *pdev)
 
        return 0;
 }
+EXPORT_SYMBOL_GPL(ata_platform_remove_one);
 
+#ifdef CONFIG_ATA_FORCE
 static int __init ata_parse_force_one(char **cur,
                                      struct ata_force_ent *force_ent,
                                      const char **reason)
@@ -7076,6 +6268,15 @@ static void __init ata_parse_force_param(void)
        ata_force_tbl_size = idx;
 }
 
+static void ata_free_force_param(void)
+{
+       kfree(ata_force_tbl);
+}
+#else
+static inline void ata_parse_force_param(void) { }
+static inline void ata_free_force_param(void) { }
+#endif
+
 static int __init ata_init(void)
 {
        int rc;
@@ -7084,7 +6285,7 @@ static int __init ata_init(void)
 
        rc = ata_sff_init();
        if (rc) {
-               kfree(ata_force_tbl);
+               ata_free_force_param();
                return rc;
        }
 
@@ -7108,7 +6309,7 @@ static void __exit ata_exit(void)
        ata_release_transport(ata_scsi_transport_template);
        libata_transport_exit();
        ata_sff_exit();
-       kfree(ata_force_tbl);
+       ata_free_force_param();
 }
 
 subsys_initcall(ata_init);
@@ -7120,6 +6321,7 @@ int ata_ratelimit(void)
 {
        return __ratelimit(&ratelimit);
 }
+EXPORT_SYMBOL_GPL(ata_ratelimit);
 
 /**
  *     ata_msleep - ATA EH owner aware msleep
@@ -7152,6 +6354,7 @@ void ata_msleep(struct ata_port *ap, unsigned int msecs)
        if (owns_eh)
                ata_eh_acquire(ap);
 }
+EXPORT_SYMBOL_GPL(ata_msleep);
 
 /**
  *     ata_wait_register - wait until register value changes
@@ -7198,38 +6401,7 @@ u32 ata_wait_register(struct ata_port *ap, void __iomem *reg, u32 mask, u32 val,
 
        return tmp;
 }
-
-/**
- *     sata_lpm_ignore_phy_events - test if PHY event should be ignored
- *     @link: Link receiving the event
- *
- *     Test whether the received PHY event has to be ignored or not.
- *
- *     LOCKING:
- *     None:
- *
- *     RETURNS:
- *     True if the event has to be ignored.
- */
-bool sata_lpm_ignore_phy_events(struct ata_link *link)
-{
-       unsigned long lpm_timeout = link->last_lpm_change +
-                                   msecs_to_jiffies(ATA_TMOUT_SPURIOUS_PHY);
-
-       /* if LPM is enabled, PHYRDY doesn't mean anything */
-       if (link->lpm_policy > ATA_LPM_MAX_POWER)
-               return true;
-
-       /* ignore the first PHY event after the LPM policy changed
-        * as it is might be spurious
-        */
-       if ((link->flags & ATA_LFLAG_CHANGED) &&
-           time_before(jiffies, lpm_timeout))
-               return true;
-
-       return false;
-}
-EXPORT_SYMBOL_GPL(sata_lpm_ignore_phy_events);
+EXPORT_SYMBOL_GPL(ata_wait_register);
 
 /*
  * Dummy port_ops
@@ -7251,10 +6423,12 @@ struct ata_port_operations ata_dummy_port_ops = {
        .sched_eh               = ata_std_sched_eh,
        .end_eh                 = ata_std_end_eh,
 };
+EXPORT_SYMBOL_GPL(ata_dummy_port_ops);
 
 const struct ata_port_info ata_dummy_port_info = {
        .port_ops               = &ata_dummy_port_ops,
 };
+EXPORT_SYMBOL_GPL(ata_dummy_port_info);
 
 /*
  * Utility print functions
@@ -7322,127 +6496,3 @@ void ata_print_version(const struct device *dev, const char *version)
        dev_printk(KERN_DEBUG, dev, "version %s\n", version);
 }
 EXPORT_SYMBOL(ata_print_version);
-
-/*
- * libata is essentially a library of internal helper functions for
- * low-level ATA host controller drivers.  As such, the API/ABI is
- * likely to change as new drivers are added and updated.
- * Do not depend on ABI/API stability.
- */
-EXPORT_SYMBOL_GPL(sata_deb_timing_normal);
-EXPORT_SYMBOL_GPL(sata_deb_timing_hotplug);
-EXPORT_SYMBOL_GPL(sata_deb_timing_long);
-EXPORT_SYMBOL_GPL(ata_base_port_ops);
-EXPORT_SYMBOL_GPL(sata_port_ops);
-EXPORT_SYMBOL_GPL(ata_dummy_port_ops);
-EXPORT_SYMBOL_GPL(ata_dummy_port_info);
-EXPORT_SYMBOL_GPL(ata_link_next);
-EXPORT_SYMBOL_GPL(ata_dev_next);
-EXPORT_SYMBOL_GPL(ata_std_bios_param);
-EXPORT_SYMBOL_GPL(ata_scsi_unlock_native_capacity);
-EXPORT_SYMBOL_GPL(ata_host_init);
-EXPORT_SYMBOL_GPL(ata_host_alloc);
-EXPORT_SYMBOL_GPL(ata_host_alloc_pinfo);
-EXPORT_SYMBOL_GPL(ata_slave_link_init);
-EXPORT_SYMBOL_GPL(ata_host_start);
-EXPORT_SYMBOL_GPL(ata_host_register);
-EXPORT_SYMBOL_GPL(ata_host_activate);
-EXPORT_SYMBOL_GPL(ata_host_detach);
-EXPORT_SYMBOL_GPL(ata_sg_init);
-EXPORT_SYMBOL_GPL(ata_qc_complete);
-EXPORT_SYMBOL_GPL(ata_qc_complete_multiple);
-EXPORT_SYMBOL_GPL(atapi_cmd_type);
-EXPORT_SYMBOL_GPL(ata_tf_to_fis);
-EXPORT_SYMBOL_GPL(ata_tf_from_fis);
-EXPORT_SYMBOL_GPL(ata_pack_xfermask);
-EXPORT_SYMBOL_GPL(ata_unpack_xfermask);
-EXPORT_SYMBOL_GPL(ata_xfer_mask2mode);
-EXPORT_SYMBOL_GPL(ata_xfer_mode2mask);
-EXPORT_SYMBOL_GPL(ata_xfer_mode2shift);
-EXPORT_SYMBOL_GPL(ata_mode_string);
-EXPORT_SYMBOL_GPL(ata_id_xfermask);
-EXPORT_SYMBOL_GPL(ata_do_set_mode);
-EXPORT_SYMBOL_GPL(ata_std_qc_defer);
-EXPORT_SYMBOL_GPL(ata_noop_qc_prep);
-EXPORT_SYMBOL_GPL(ata_dev_disable);
-EXPORT_SYMBOL_GPL(sata_set_spd);
-EXPORT_SYMBOL_GPL(ata_wait_after_reset);
-EXPORT_SYMBOL_GPL(sata_link_debounce);
-EXPORT_SYMBOL_GPL(sata_link_resume);
-EXPORT_SYMBOL_GPL(sata_link_scr_lpm);
-EXPORT_SYMBOL_GPL(ata_std_prereset);
-EXPORT_SYMBOL_GPL(sata_link_hardreset);
-EXPORT_SYMBOL_GPL(sata_std_hardreset);
-EXPORT_SYMBOL_GPL(ata_std_postreset);
-EXPORT_SYMBOL_GPL(ata_dev_classify);
-EXPORT_SYMBOL_GPL(ata_dev_pair);
-EXPORT_SYMBOL_GPL(ata_ratelimit);
-EXPORT_SYMBOL_GPL(ata_msleep);
-EXPORT_SYMBOL_GPL(ata_wait_register);
-EXPORT_SYMBOL_GPL(ata_scsi_queuecmd);
-EXPORT_SYMBOL_GPL(ata_scsi_slave_config);
-EXPORT_SYMBOL_GPL(ata_scsi_slave_destroy);
-EXPORT_SYMBOL_GPL(ata_scsi_change_queue_depth);
-EXPORT_SYMBOL_GPL(__ata_change_queue_depth);
-EXPORT_SYMBOL_GPL(sata_scr_valid);
-EXPORT_SYMBOL_GPL(sata_scr_read);
-EXPORT_SYMBOL_GPL(sata_scr_write);
-EXPORT_SYMBOL_GPL(sata_scr_write_flush);
-EXPORT_SYMBOL_GPL(ata_link_online);
-EXPORT_SYMBOL_GPL(ata_link_offline);
-#ifdef CONFIG_PM
-EXPORT_SYMBOL_GPL(ata_host_suspend);
-EXPORT_SYMBOL_GPL(ata_host_resume);
-#endif /* CONFIG_PM */
-EXPORT_SYMBOL_GPL(ata_id_string);
-EXPORT_SYMBOL_GPL(ata_id_c_string);
-EXPORT_SYMBOL_GPL(ata_do_dev_read_id);
-EXPORT_SYMBOL_GPL(ata_scsi_simulate);
-
-EXPORT_SYMBOL_GPL(ata_pio_need_iordy);
-EXPORT_SYMBOL_GPL(ata_timing_find_mode);
-EXPORT_SYMBOL_GPL(ata_timing_compute);
-EXPORT_SYMBOL_GPL(ata_timing_merge);
-EXPORT_SYMBOL_GPL(ata_timing_cycle2mode);
-
-#ifdef CONFIG_PCI
-EXPORT_SYMBOL_GPL(pci_test_config_bits);
-EXPORT_SYMBOL_GPL(ata_pci_shutdown_one);
-EXPORT_SYMBOL_GPL(ata_pci_remove_one);
-#ifdef CONFIG_PM
-EXPORT_SYMBOL_GPL(ata_pci_device_do_suspend);
-EXPORT_SYMBOL_GPL(ata_pci_device_do_resume);
-EXPORT_SYMBOL_GPL(ata_pci_device_suspend);
-EXPORT_SYMBOL_GPL(ata_pci_device_resume);
-#endif /* CONFIG_PM */
-#endif /* CONFIG_PCI */
-
-EXPORT_SYMBOL_GPL(ata_platform_remove_one);
-
-EXPORT_SYMBOL_GPL(__ata_ehi_push_desc);
-EXPORT_SYMBOL_GPL(ata_ehi_push_desc);
-EXPORT_SYMBOL_GPL(ata_ehi_clear_desc);
-EXPORT_SYMBOL_GPL(ata_port_desc);
-#ifdef CONFIG_PCI
-EXPORT_SYMBOL_GPL(ata_port_pbar_desc);
-#endif /* CONFIG_PCI */
-EXPORT_SYMBOL_GPL(ata_port_schedule_eh);
-EXPORT_SYMBOL_GPL(ata_link_abort);
-EXPORT_SYMBOL_GPL(ata_port_abort);
-EXPORT_SYMBOL_GPL(ata_port_freeze);
-EXPORT_SYMBOL_GPL(sata_async_notification);
-EXPORT_SYMBOL_GPL(ata_eh_freeze_port);
-EXPORT_SYMBOL_GPL(ata_eh_thaw_port);
-EXPORT_SYMBOL_GPL(ata_eh_qc_complete);
-EXPORT_SYMBOL_GPL(ata_eh_qc_retry);
-EXPORT_SYMBOL_GPL(ata_eh_analyze_ncq_error);
-EXPORT_SYMBOL_GPL(ata_do_eh);
-EXPORT_SYMBOL_GPL(ata_std_error_handler);
-
-EXPORT_SYMBOL_GPL(ata_cable_40wire);
-EXPORT_SYMBOL_GPL(ata_cable_80wire);
-EXPORT_SYMBOL_GPL(ata_cable_unknown);
-EXPORT_SYMBOL_GPL(ata_cable_ignore);
-EXPORT_SYMBOL_GPL(ata_cable_sata);
-EXPORT_SYMBOL_GPL(ata_host_get);
-EXPORT_SYMBOL_GPL(ata_host_put);
index 3bfd9da..474c6c3 100644 (file)
@@ -2,10 +2,6 @@
 /*
  *  libata-eh.c - libata error handling
  *
- *  Maintained by:  Tejun Heo <tj@kernel.org>
- *                 Please ALWAYS copy linux-ide@vger.kernel.org
- *                 on emails.
- *
  *  Copyright 2006 Tejun Heo <htejun@gmail.com>
  *
  *  libata documentation is available via 'make {ps|pdf}docs',
@@ -184,6 +180,7 @@ void __ata_ehi_push_desc(struct ata_eh_info *ehi, const char *fmt, ...)
        __ata_ehi_pushv_desc(ehi, fmt, args);
        va_end(args);
 }
+EXPORT_SYMBOL_GPL(__ata_ehi_push_desc);
 
 /**
  *     ata_ehi_push_desc - push error description with separator
@@ -207,6 +204,7 @@ void ata_ehi_push_desc(struct ata_eh_info *ehi, const char *fmt, ...)
        __ata_ehi_pushv_desc(ehi, fmt, args);
        va_end(args);
 }
+EXPORT_SYMBOL_GPL(ata_ehi_push_desc);
 
 /**
  *     ata_ehi_clear_desc - clean error description
@@ -222,6 +220,7 @@ void ata_ehi_clear_desc(struct ata_eh_info *ehi)
        ehi->desc[0] = '\0';
        ehi->desc_len = 0;
 }
+EXPORT_SYMBOL_GPL(ata_ehi_clear_desc);
 
 /**
  *     ata_port_desc - append port description
@@ -249,9 +248,9 @@ void ata_port_desc(struct ata_port *ap, const char *fmt, ...)
        __ata_ehi_pushv_desc(&ap->link.eh_info, fmt, args);
        va_end(args);
 }
+EXPORT_SYMBOL_GPL(ata_port_desc);
 
 #ifdef CONFIG_PCI
-
 /**
  *     ata_port_pbar_desc - append PCI BAR description
  *     @ap: target ATA port
@@ -288,7 +287,7 @@ void ata_port_pbar_desc(struct ata_port *ap, int bar, ssize_t offset,
                ata_port_desc(ap, "%s 0x%llx", name,
                                start + (unsigned long long)offset);
 }
-
+EXPORT_SYMBOL_GPL(ata_port_pbar_desc);
 #endif /* CONFIG_PCI */
 
 static int ata_lookup_timeout_table(u8 cmd)
@@ -973,6 +972,7 @@ void ata_port_schedule_eh(struct ata_port *ap)
        /* see: ata_std_sched_eh, unless you know better */
        ap->ops->sched_eh(ap);
 }
+EXPORT_SYMBOL_GPL(ata_port_schedule_eh);
 
 static int ata_do_link_abort(struct ata_port *ap, struct ata_link *link)
 {
@@ -1015,6 +1015,7 @@ int ata_link_abort(struct ata_link *link)
 {
        return ata_do_link_abort(link->ap, link);
 }
+EXPORT_SYMBOL_GPL(ata_link_abort);
 
 /**
  *     ata_port_abort - abort all qc's on the port
@@ -1032,6 +1033,7 @@ int ata_port_abort(struct ata_port *ap)
 {
        return ata_do_link_abort(ap, NULL);
 }
+EXPORT_SYMBOL_GPL(ata_port_abort);
 
 /**
  *     __ata_port_freeze - freeze port
@@ -1088,79 +1090,7 @@ int ata_port_freeze(struct ata_port *ap)
 
        return nr_aborted;
 }
-
-/**
- *     sata_async_notification - SATA async notification handler
- *     @ap: ATA port where async notification is received
- *
- *     Handler to be called when async notification via SDB FIS is
- *     received.  This function schedules EH if necessary.
- *
- *     LOCKING:
- *     spin_lock_irqsave(host lock)
- *
- *     RETURNS:
- *     1 if EH is scheduled, 0 otherwise.
- */
-int sata_async_notification(struct ata_port *ap)
-{
-       u32 sntf;
-       int rc;
-
-       if (!(ap->flags & ATA_FLAG_AN))
-               return 0;
-
-       rc = sata_scr_read(&ap->link, SCR_NOTIFICATION, &sntf);
-       if (rc == 0)
-               sata_scr_write(&ap->link, SCR_NOTIFICATION, sntf);
-
-       if (!sata_pmp_attached(ap) || rc) {
-               /* PMP is not attached or SNTF is not available */
-               if (!sata_pmp_attached(ap)) {
-                       /* PMP is not attached.  Check whether ATAPI
-                        * AN is configured.  If so, notify media
-                        * change.
-                        */
-                       struct ata_device *dev = ap->link.device;
-
-                       if ((dev->class == ATA_DEV_ATAPI) &&
-                           (dev->flags & ATA_DFLAG_AN))
-                               ata_scsi_media_change_notify(dev);
-                       return 0;
-               } else {
-                       /* PMP is attached but SNTF is not available.
-                        * ATAPI async media change notification is
-                        * not used.  The PMP must be reporting PHY
-                        * status change, schedule EH.
-                        */
-                       ata_port_schedule_eh(ap);
-                       return 1;
-               }
-       } else {
-               /* PMP is attached and SNTF is available */
-               struct ata_link *link;
-
-               /* check and notify ATAPI AN */
-               ata_for_each_link(link, ap, EDGE) {
-                       if (!(sntf & (1 << link->pmp)))
-                               continue;
-
-                       if ((link->device->class == ATA_DEV_ATAPI) &&
-                           (link->device->flags & ATA_DFLAG_AN))
-                               ata_scsi_media_change_notify(link->device);
-               }
-
-               /* If PMP is reporting that PHY status of some
-                * downstream ports has changed, schedule EH.
-                */
-               if (sntf & (1 << SATA_PMP_CTRL_PORT)) {
-                       ata_port_schedule_eh(ap);
-                       return 1;
-               }
-
-               return 0;
-       }
-}
+EXPORT_SYMBOL_GPL(ata_port_freeze);
 
 /**
  *     ata_eh_freeze_port - EH helper to freeze port
@@ -1182,6 +1112,7 @@ void ata_eh_freeze_port(struct ata_port *ap)
        __ata_port_freeze(ap);
        spin_unlock_irqrestore(ap->lock, flags);
 }
+EXPORT_SYMBOL_GPL(ata_eh_freeze_port);
 
 /**
  *     ata_port_thaw_port - EH helper to thaw port
@@ -1289,6 +1220,7 @@ void ata_dev_disable(struct ata_device *dev)
         */
        ata_ering_clear(&dev->ering);
 }
+EXPORT_SYMBOL_GPL(ata_dev_disable);
 
 /**
  *     ata_eh_detach_dev - detach ATA device
@@ -1420,62 +1352,6 @@ static const char *ata_err_string(unsigned int err_mask)
 }
 
 /**
- *     ata_eh_read_log_10h - Read log page 10h for NCQ error details
- *     @dev: Device to read log page 10h from
- *     @tag: Resulting tag of the failed command
- *     @tf: Resulting taskfile registers of the failed command
- *
- *     Read log page 10h to obtain NCQ error details and clear error
- *     condition.
- *
- *     LOCKING:
- *     Kernel thread context (may sleep).
- *
- *     RETURNS:
- *     0 on success, -errno otherwise.
- */
-static int ata_eh_read_log_10h(struct ata_device *dev,
-                              int *tag, struct ata_taskfile *tf)
-{
-       u8 *buf = dev->link->ap->sector_buf;
-       unsigned int err_mask;
-       u8 csum;
-       int i;
-
-       err_mask = ata_read_log_page(dev, ATA_LOG_SATA_NCQ, 0, buf, 1);
-       if (err_mask)
-               return -EIO;
-
-       csum = 0;
-       for (i = 0; i < ATA_SECT_SIZE; i++)
-               csum += buf[i];
-       if (csum)
-               ata_dev_warn(dev, "invalid checksum 0x%x on log page 10h\n",
-                            csum);
-
-       if (buf[0] & 0x80)
-               return -ENOENT;
-
-       *tag = buf[0] & 0x1f;
-
-       tf->command = buf[2];
-       tf->feature = buf[3];
-       tf->lbal = buf[4];
-       tf->lbam = buf[5];
-       tf->lbah = buf[6];
-       tf->device = buf[7];
-       tf->hob_lbal = buf[8];
-       tf->hob_lbam = buf[9];
-       tf->hob_lbah = buf[10];
-       tf->nsect = buf[12];
-       tf->hob_nsect = buf[13];
-       if (dev->class == ATA_DEV_ZAC && ata_id_has_ncq_autosense(dev->id))
-               tf->auxiliary = buf[14] << 16 | buf[15] << 8 | buf[16];
-
-       return 0;
-}
-
-/**
  *     atapi_eh_tur - perform ATAPI TEST_UNIT_READY
  *     @dev: target ATAPI device
  *     @r_sense_key: out parameter for sense_key
@@ -1659,80 +1535,6 @@ static void ata_eh_analyze_serror(struct ata_link *link)
 }
 
 /**
- *     ata_eh_analyze_ncq_error - analyze NCQ error
- *     @link: ATA link to analyze NCQ error for
- *
- *     Read log page 10h, determine the offending qc and acquire
- *     error status TF.  For NCQ device errors, all LLDDs have to do
- *     is setting AC_ERR_DEV in ehi->err_mask.  This function takes
- *     care of the rest.
- *
- *     LOCKING:
- *     Kernel thread context (may sleep).
- */
-void ata_eh_analyze_ncq_error(struct ata_link *link)
-{
-       struct ata_port *ap = link->ap;
-       struct ata_eh_context *ehc = &link->eh_context;
-       struct ata_device *dev = link->device;
-       struct ata_queued_cmd *qc;
-       struct ata_taskfile tf;
-       int tag, rc;
-
-       /* if frozen, we can't do much */
-       if (ap->pflags & ATA_PFLAG_FROZEN)
-               return;
-
-       /* is it NCQ device error? */
-       if (!link->sactive || !(ehc->i.err_mask & AC_ERR_DEV))
-               return;
-
-       /* has LLDD analyzed already? */
-       ata_qc_for_each_raw(ap, qc, tag) {
-               if (!(qc->flags & ATA_QCFLAG_FAILED))
-                       continue;
-
-               if (qc->err_mask)
-                       return;
-       }
-
-       /* okay, this error is ours */
-       memset(&tf, 0, sizeof(tf));
-       rc = ata_eh_read_log_10h(dev, &tag, &tf);
-       if (rc) {
-               ata_link_err(link, "failed to read log page 10h (errno=%d)\n",
-                            rc);
-               return;
-       }
-
-       if (!(link->sactive & (1 << tag))) {
-               ata_link_err(link, "log page 10h reported inactive tag %d\n",
-                            tag);
-               return;
-       }
-
-       /* we've got the perpetrator, condemn it */
-       qc = __ata_qc_from_tag(ap, tag);
-       memcpy(&qc->result_tf, &tf, sizeof(tf));
-       qc->result_tf.flags = ATA_TFLAG_ISADDR | ATA_TFLAG_LBA | ATA_TFLAG_LBA48;
-       qc->err_mask |= AC_ERR_DEV | AC_ERR_NCQ;
-       if (dev->class == ATA_DEV_ZAC &&
-           ((qc->result_tf.command & ATA_SENSE) || qc->result_tf.auxiliary)) {
-               char sense_key, asc, ascq;
-
-               sense_key = (qc->result_tf.auxiliary >> 16) & 0xff;
-               asc = (qc->result_tf.auxiliary >> 8) & 0xff;
-               ascq = qc->result_tf.auxiliary & 0xff;
-               ata_scsi_set_sense(dev, qc->scsicmd, sense_key, asc, ascq);
-               ata_scsi_set_sense_information(dev, qc->scsicmd,
-                                              &qc->result_tf);
-               qc->flags |= ATA_QCFLAG_SENSE_VALID;
-       }
-
-       ehc->i.err_mask &= ~AC_ERR_DEV;
-}
-
-/**
  *     ata_eh_analyze_tf - analyze taskfile of a failed qc
  *     @qc: qc to analyze
  *     @tf: Taskfile registers to analyze
@@ -3436,7 +3238,8 @@ static int ata_eh_set_lpm(struct ata_link *link, enum ata_lpm_policy policy,
        int rc;
 
        /* if the link or host doesn't do LPM, noop */
-       if ((link->flags & ATA_LFLAG_NO_LPM) || (ap && !ap->ops->set_lpm))
+       if (!IS_ENABLED(CONFIG_SATA_HOST) ||
+           (link->flags & ATA_LFLAG_NO_LPM) || (ap && !ap->ops->set_lpm))
                return 0;
 
        /*
@@ -4052,6 +3855,7 @@ void ata_std_error_handler(struct ata_port *ap)
 
        ata_do_eh(ap, ops->prereset, ops->softreset, hardreset, ops->postreset);
 }
+EXPORT_SYMBOL_GPL(ata_std_error_handler);
 
 #ifdef CONFIG_PM
 /**
diff --git a/drivers/ata/libata-pata-timings.c b/drivers/ata/libata-pata-timings.c
new file mode 100644 (file)
index 0000000..af34122
--- /dev/null
@@ -0,0 +1,192 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ *  Helper library for PATA timings
+ *
+ *  Copyright 2003-2004 Red Hat, Inc.  All rights reserved.
+ *  Copyright 2003-2004 Jeff Garzik
+ */
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/libata.h>
+
+/*
+ * This mode timing computation functionality is ported over from
+ * drivers/ide/ide-timing.h and was originally written by Vojtech Pavlik
+ */
+/*
+ * PIO 0-4, MWDMA 0-2 and UDMA 0-6 timings (in nanoseconds).
+ * These were taken from ATA/ATAPI-6 standard, rev 0a, except
+ * for UDMA6, which is currently supported only by Maxtor drives.
+ *
+ * For PIO 5/6 MWDMA 3/4 see the CFA specification 3.0.
+ */
+
+static const struct ata_timing ata_timing[] = {
+/*     { XFER_PIO_SLOW, 120, 290, 240, 960, 290, 240, 0,  960,   0 }, */
+       { XFER_PIO_0,     70, 290, 240, 600, 165, 150, 0,  600,   0 },
+       { XFER_PIO_1,     50, 290,  93, 383, 125, 100, 0,  383,   0 },
+       { XFER_PIO_2,     30, 290,  40, 330, 100,  90, 0,  240,   0 },
+       { XFER_PIO_3,     30,  80,  70, 180,  80,  70, 0,  180,   0 },
+       { XFER_PIO_4,     25,  70,  25, 120,  70,  25, 0,  120,   0 },
+       { XFER_PIO_5,     15,  65,  25, 100,  65,  25, 0,  100,   0 },
+       { XFER_PIO_6,     10,  55,  20,  80,  55,  20, 0,   80,   0 },
+
+       { XFER_SW_DMA_0, 120,   0,   0,   0, 480, 480, 50, 960,   0 },
+       { XFER_SW_DMA_1,  90,   0,   0,   0, 240, 240, 30, 480,   0 },
+       { XFER_SW_DMA_2,  60,   0,   0,   0, 120, 120, 20, 240,   0 },
+
+       { XFER_MW_DMA_0,  60,   0,   0,   0, 215, 215, 20, 480,   0 },
+       { XFER_MW_DMA_1,  45,   0,   0,   0,  80,  50, 5,  150,   0 },
+       { XFER_MW_DMA_2,  25,   0,   0,   0,  70,  25, 5,  120,   0 },
+       { XFER_MW_DMA_3,  25,   0,   0,   0,  65,  25, 5,  100,   0 },
+       { XFER_MW_DMA_4,  25,   0,   0,   0,  55,  20, 5,   80,   0 },
+
+/*     { XFER_UDMA_SLOW,  0,   0,   0,   0,   0,   0, 0,    0, 150 }, */
+       { XFER_UDMA_0,     0,   0,   0,   0,   0,   0, 0,    0, 120 },
+       { XFER_UDMA_1,     0,   0,   0,   0,   0,   0, 0,    0,  80 },
+       { XFER_UDMA_2,     0,   0,   0,   0,   0,   0, 0,    0,  60 },
+       { XFER_UDMA_3,     0,   0,   0,   0,   0,   0, 0,    0,  45 },
+       { XFER_UDMA_4,     0,   0,   0,   0,   0,   0, 0,    0,  30 },
+       { XFER_UDMA_5,     0,   0,   0,   0,   0,   0, 0,    0,  20 },
+       { XFER_UDMA_6,     0,   0,   0,   0,   0,   0, 0,    0,  15 },
+
+       { 0xFF }
+};
+
+#define ENOUGH(v, unit)                (((v)-1)/(unit)+1)
+#define EZ(v, unit)            ((v)?ENOUGH(((v) * 1000), unit):0)
+
+static void ata_timing_quantize(const struct ata_timing *t,
+                               struct ata_timing *q, int T, int UT)
+{
+       q->setup        = EZ(t->setup,       T);
+       q->act8b        = EZ(t->act8b,       T);
+       q->rec8b        = EZ(t->rec8b,       T);
+       q->cyc8b        = EZ(t->cyc8b,       T);
+       q->active       = EZ(t->active,      T);
+       q->recover      = EZ(t->recover,     T);
+       q->dmack_hold   = EZ(t->dmack_hold,  T);
+       q->cycle        = EZ(t->cycle,       T);
+       q->udma         = EZ(t->udma,       UT);
+}
+
+void ata_timing_merge(const struct ata_timing *a, const struct ata_timing *b,
+                     struct ata_timing *m, unsigned int what)
+{
+       if (what & ATA_TIMING_SETUP)
+               m->setup = max(a->setup, b->setup);
+       if (what & ATA_TIMING_ACT8B)
+               m->act8b = max(a->act8b, b->act8b);
+       if (what & ATA_TIMING_REC8B)
+               m->rec8b = max(a->rec8b, b->rec8b);
+       if (what & ATA_TIMING_CYC8B)
+               m->cyc8b = max(a->cyc8b, b->cyc8b);
+       if (what & ATA_TIMING_ACTIVE)
+               m->active = max(a->active, b->active);
+       if (what & ATA_TIMING_RECOVER)
+               m->recover = max(a->recover, b->recover);
+       if (what & ATA_TIMING_DMACK_HOLD)
+               m->dmack_hold = max(a->dmack_hold, b->dmack_hold);
+       if (what & ATA_TIMING_CYCLE)
+               m->cycle = max(a->cycle, b->cycle);
+       if (what & ATA_TIMING_UDMA)
+               m->udma = max(a->udma, b->udma);
+}
+EXPORT_SYMBOL_GPL(ata_timing_merge);
+
+const struct ata_timing *ata_timing_find_mode(u8 xfer_mode)
+{
+       const struct ata_timing *t = ata_timing;
+
+       while (xfer_mode > t->mode)
+               t++;
+
+       if (xfer_mode == t->mode)
+               return t;
+
+       WARN_ONCE(true, "%s: unable to find timing for xfer_mode 0x%x\n",
+                       __func__, xfer_mode);
+
+       return NULL;
+}
+EXPORT_SYMBOL_GPL(ata_timing_find_mode);
+
+int ata_timing_compute(struct ata_device *adev, unsigned short speed,
+                      struct ata_timing *t, int T, int UT)
+{
+       const u16 *id = adev->id;
+       const struct ata_timing *s;
+       struct ata_timing p;
+
+       /*
+        * Find the mode.
+        */
+       s = ata_timing_find_mode(speed);
+       if (!s)
+               return -EINVAL;
+
+       memcpy(t, s, sizeof(*s));
+
+       /*
+        * If the drive is an EIDE drive, it can tell us it needs extended
+        * PIO/MW_DMA cycle timing.
+        */
+
+       if (id[ATA_ID_FIELD_VALID] & 2) {       /* EIDE drive */
+               memset(&p, 0, sizeof(p));
+
+               if (speed >= XFER_PIO_0 && speed < XFER_SW_DMA_0) {
+                       if (speed <= XFER_PIO_2)
+                               p.cycle = p.cyc8b = id[ATA_ID_EIDE_PIO];
+                       else if ((speed <= XFER_PIO_4) ||
+                                (speed == XFER_PIO_5 && !ata_id_is_cfa(id)))
+                               p.cycle = p.cyc8b = id[ATA_ID_EIDE_PIO_IORDY];
+               } else if (speed >= XFER_MW_DMA_0 && speed <= XFER_MW_DMA_2)
+                       p.cycle = id[ATA_ID_EIDE_DMA_MIN];
+
+               ata_timing_merge(&p, t, t, ATA_TIMING_CYCLE | ATA_TIMING_CYC8B);
+       }
+
+       /*
+        * Convert the timing to bus clock counts.
+        */
+
+       ata_timing_quantize(t, t, T, UT);
+
+       /*
+        * Even in DMA/UDMA modes we still use PIO access for IDENTIFY,
+        * S.M.A.R.T * and some other commands. We have to ensure that the
+        * DMA cycle timing is slower/equal than the fastest PIO timing.
+        */
+
+       if (speed > XFER_PIO_6) {
+               ata_timing_compute(adev, adev->pio_mode, &p, T, UT);
+               ata_timing_merge(&p, t, t, ATA_TIMING_ALL);
+       }
+
+       /*
+        * Lengthen active & recovery time so that cycle time is correct.
+        */
+
+       if (t->act8b + t->rec8b < t->cyc8b) {
+               t->act8b += (t->cyc8b - (t->act8b + t->rec8b)) / 2;
+               t->rec8b = t->cyc8b - t->act8b;
+       }
+
+       if (t->active + t->recover < t->cycle) {
+               t->active += (t->cycle - (t->active + t->recover)) / 2;
+               t->recover = t->cycle - t->active;
+       }
+
+       /*
+        * In a few cases quantisation may produce enough errors to
+        * leave t->cycle too low for the sum of active and recovery
+        * if so we must correct this.
+        */
+       if (t->active + t->recover > t->cycle)
+               t->cycle = t->active + t->recover;
+
+       return 0;
+}
+EXPORT_SYMBOL_GPL(ata_timing_compute);
diff --git a/drivers/ata/libata-sata.c b/drivers/ata/libata-sata.c
new file mode 100644 (file)
index 0000000..c16423e
--- /dev/null
@@ -0,0 +1,1483 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ *  SATA specific part of ATA helper library
+ *
+ *  Copyright 2003-2004 Red Hat, Inc.  All rights reserved.
+ *  Copyright 2003-2004 Jeff Garzik
+ *  Copyright 2006 Tejun Heo <htejun@gmail.com>
+ */
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <scsi/scsi_cmnd.h>
+#include <scsi/scsi_device.h>
+#include <linux/libata.h>
+
+#include "libata.h"
+#include "libata-transport.h"
+
+/* debounce timing parameters in msecs { interval, duration, timeout } */
+const unsigned long sata_deb_timing_normal[]           = {   5,  100, 2000 };
+EXPORT_SYMBOL_GPL(sata_deb_timing_normal);
+const unsigned long sata_deb_timing_hotplug[]          = {  25,  500, 2000 };
+EXPORT_SYMBOL_GPL(sata_deb_timing_hotplug);
+const unsigned long sata_deb_timing_long[]             = { 100, 2000, 5000 };
+EXPORT_SYMBOL_GPL(sata_deb_timing_long);
+
+/**
+ *     sata_scr_valid - test whether SCRs are accessible
+ *     @link: ATA link to test SCR accessibility for
+ *
+ *     Test whether SCRs are accessible for @link.
+ *
+ *     LOCKING:
+ *     None.
+ *
+ *     RETURNS:
+ *     1 if SCRs are accessible, 0 otherwise.
+ */
+int sata_scr_valid(struct ata_link *link)
+{
+       struct ata_port *ap = link->ap;
+
+       return (ap->flags & ATA_FLAG_SATA) && ap->ops->scr_read;
+}
+EXPORT_SYMBOL_GPL(sata_scr_valid);
+
+/**
+ *     sata_scr_read - read SCR register of the specified port
+ *     @link: ATA link to read SCR for
+ *     @reg: SCR to read
+ *     @val: Place to store read value
+ *
+ *     Read SCR register @reg of @link into *@val.  This function is
+ *     guaranteed to succeed if @link is ap->link, the cable type of
+ *     the port is SATA and the port implements ->scr_read.
+ *
+ *     LOCKING:
+ *     None if @link is ap->link.  Kernel thread context otherwise.
+ *
+ *     RETURNS:
+ *     0 on success, negative errno on failure.
+ */
+int sata_scr_read(struct ata_link *link, int reg, u32 *val)
+{
+       if (ata_is_host_link(link)) {
+               if (sata_scr_valid(link))
+                       return link->ap->ops->scr_read(link, reg, val);
+               return -EOPNOTSUPP;
+       }
+
+       return sata_pmp_scr_read(link, reg, val);
+}
+EXPORT_SYMBOL_GPL(sata_scr_read);
+
+/**
+ *     sata_scr_write - write SCR register of the specified port
+ *     @link: ATA link to write SCR for
+ *     @reg: SCR to write
+ *     @val: value to write
+ *
+ *     Write @val to SCR register @reg of @link.  This function is
+ *     guaranteed to succeed if @link is ap->link, the cable type of
+ *     the port is SATA and the port implements ->scr_read.
+ *
+ *     LOCKING:
+ *     None if @link is ap->link.  Kernel thread context otherwise.
+ *
+ *     RETURNS:
+ *     0 on success, negative errno on failure.
+ */
+int sata_scr_write(struct ata_link *link, int reg, u32 val)
+{
+       if (ata_is_host_link(link)) {
+               if (sata_scr_valid(link))
+                       return link->ap->ops->scr_write(link, reg, val);
+               return -EOPNOTSUPP;
+       }
+
+       return sata_pmp_scr_write(link, reg, val);
+}
+EXPORT_SYMBOL_GPL(sata_scr_write);
+
+/**
+ *     sata_scr_write_flush - write SCR register of the specified port and flush
+ *     @link: ATA link to write SCR for
+ *     @reg: SCR to write
+ *     @val: value to write
+ *
+ *     This function is identical to sata_scr_write() except that this
+ *     function performs flush after writing to the register.
+ *
+ *     LOCKING:
+ *     None if @link is ap->link.  Kernel thread context otherwise.
+ *
+ *     RETURNS:
+ *     0 on success, negative errno on failure.
+ */
+int sata_scr_write_flush(struct ata_link *link, int reg, u32 val)
+{
+       if (ata_is_host_link(link)) {
+               int rc;
+
+               if (sata_scr_valid(link)) {
+                       rc = link->ap->ops->scr_write(link, reg, val);
+                       if (rc == 0)
+                               rc = link->ap->ops->scr_read(link, reg, &val);
+                       return rc;
+               }
+               return -EOPNOTSUPP;
+       }
+
+       return sata_pmp_scr_write(link, reg, val);
+}
+EXPORT_SYMBOL_GPL(sata_scr_write_flush);
+
+/**
+ *     ata_tf_to_fis - Convert ATA taskfile to SATA FIS structure
+ *     @tf: Taskfile to convert
+ *     @pmp: Port multiplier port
+ *     @is_cmd: This FIS is for command
+ *     @fis: Buffer into which data will output
+ *
+ *     Converts a standard ATA taskfile to a Serial ATA
+ *     FIS structure (Register - Host to Device).
+ *
+ *     LOCKING:
+ *     Inherited from caller.
+ */
+void ata_tf_to_fis(const struct ata_taskfile *tf, u8 pmp, int is_cmd, u8 *fis)
+{
+       fis[0] = 0x27;                  /* Register - Host to Device FIS */
+       fis[1] = pmp & 0xf;             /* Port multiplier number*/
+       if (is_cmd)
+               fis[1] |= (1 << 7);     /* bit 7 indicates Command FIS */
+
+       fis[2] = tf->command;
+       fis[3] = tf->feature;
+
+       fis[4] = tf->lbal;
+       fis[5] = tf->lbam;
+       fis[6] = tf->lbah;
+       fis[7] = tf->device;
+
+       fis[8] = tf->hob_lbal;
+       fis[9] = tf->hob_lbam;
+       fis[10] = tf->hob_lbah;
+       fis[11] = tf->hob_feature;
+
+       fis[12] = tf->nsect;
+       fis[13] = tf->hob_nsect;
+       fis[14] = 0;
+       fis[15] = tf->ctl;
+
+       fis[16] = tf->auxiliary & 0xff;
+       fis[17] = (tf->auxiliary >> 8) & 0xff;
+       fis[18] = (tf->auxiliary >> 16) & 0xff;
+       fis[19] = (tf->auxiliary >> 24) & 0xff;
+}
+EXPORT_SYMBOL_GPL(ata_tf_to_fis);
+
+/**
+ *     ata_tf_from_fis - Convert SATA FIS to ATA taskfile
+ *     @fis: Buffer from which data will be input
+ *     @tf: Taskfile to output
+ *
+ *     Converts a serial ATA FIS structure to a standard ATA taskfile.
+ *
+ *     LOCKING:
+ *     Inherited from caller.
+ */
+
+void ata_tf_from_fis(const u8 *fis, struct ata_taskfile *tf)
+{
+       tf->command     = fis[2];       /* status */
+       tf->feature     = fis[3];       /* error */
+
+       tf->lbal        = fis[4];
+       tf->lbam        = fis[5];
+       tf->lbah        = fis[6];
+       tf->device      = fis[7];
+
+       tf->hob_lbal    = fis[8];
+       tf->hob_lbam    = fis[9];
+       tf->hob_lbah    = fis[10];
+
+       tf->nsect       = fis[12];
+       tf->hob_nsect   = fis[13];
+}
+EXPORT_SYMBOL_GPL(ata_tf_from_fis);
+
+/**
+ *     sata_link_debounce - debounce SATA phy status
+ *     @link: ATA link to debounce SATA phy status for
+ *     @params: timing parameters { interval, duration, timeout } in msec
+ *     @deadline: deadline jiffies for the operation
+ *
+ *     Make sure SStatus of @link reaches stable state, determined by
+ *     holding the same value where DET is not 1 for @duration polled
+ *     every @interval, before @timeout.  Timeout constraints the
+ *     beginning of the stable state.  Because DET gets stuck at 1 on
+ *     some controllers after hot unplugging, this functions waits
+ *     until timeout then returns 0 if DET is stable at 1.
+ *
+ *     @timeout is further limited by @deadline.  The sooner of the
+ *     two is used.
+ *
+ *     LOCKING:
+ *     Kernel thread context (may sleep)
+ *
+ *     RETURNS:
+ *     0 on success, -errno on failure.
+ */
+int sata_link_debounce(struct ata_link *link, const unsigned long *params,
+                      unsigned long deadline)
+{
+       unsigned long interval = params[0];
+       unsigned long duration = params[1];
+       unsigned long last_jiffies, t;
+       u32 last, cur;
+       int rc;
+
+       t = ata_deadline(jiffies, params[2]);
+       if (time_before(t, deadline))
+               deadline = t;
+
+       if ((rc = sata_scr_read(link, SCR_STATUS, &cur)))
+               return rc;
+       cur &= 0xf;
+
+       last = cur;
+       last_jiffies = jiffies;
+
+       while (1) {
+               ata_msleep(link->ap, interval);
+               if ((rc = sata_scr_read(link, SCR_STATUS, &cur)))
+                       return rc;
+               cur &= 0xf;
+
+               /* DET stable? */
+               if (cur == last) {
+                       if (cur == 1 && time_before(jiffies, deadline))
+                               continue;
+                       if (time_after(jiffies,
+                                      ata_deadline(last_jiffies, duration)))
+                               return 0;
+                       continue;
+               }
+
+               /* unstable, start over */
+               last = cur;
+               last_jiffies = jiffies;
+
+               /* Check deadline.  If debouncing failed, return
+                * -EPIPE to tell upper layer to lower link speed.
+                */
+               if (time_after(jiffies, deadline))
+                       return -EPIPE;
+       }
+}
+EXPORT_SYMBOL_GPL(sata_link_debounce);
+
+/**
+ *     sata_link_resume - resume SATA link
+ *     @link: ATA link to resume SATA
+ *     @params: timing parameters { interval, duration, timeout } in msec
+ *     @deadline: deadline jiffies for the operation
+ *
+ *     Resume SATA phy @link and debounce it.
+ *
+ *     LOCKING:
+ *     Kernel thread context (may sleep)
+ *
+ *     RETURNS:
+ *     0 on success, -errno on failure.
+ */
+int sata_link_resume(struct ata_link *link, const unsigned long *params,
+                    unsigned long deadline)
+{
+       int tries = ATA_LINK_RESUME_TRIES;
+       u32 scontrol, serror;
+       int rc;
+
+       if ((rc = sata_scr_read(link, SCR_CONTROL, &scontrol)))
+               return rc;
+
+       /*
+        * Writes to SControl sometimes get ignored under certain
+        * controllers (ata_piix SIDPR).  Make sure DET actually is
+        * cleared.
+        */
+       do {
+               scontrol = (scontrol & 0x0f0) | 0x300;
+               if ((rc = sata_scr_write(link, SCR_CONTROL, scontrol)))
+                       return rc;
+               /*
+                * Some PHYs react badly if SStatus is pounded
+                * immediately after resuming.  Delay 200ms before
+                * debouncing.
+                */
+               if (!(link->flags & ATA_LFLAG_NO_DB_DELAY))
+                       ata_msleep(link->ap, 200);
+
+               /* is SControl restored correctly? */
+               if ((rc = sata_scr_read(link, SCR_CONTROL, &scontrol)))
+                       return rc;
+       } while ((scontrol & 0xf0f) != 0x300 && --tries);
+
+       if ((scontrol & 0xf0f) != 0x300) {
+               ata_link_warn(link, "failed to resume link (SControl %X)\n",
+                            scontrol);
+               return 0;
+       }
+
+       if (tries < ATA_LINK_RESUME_TRIES)
+               ata_link_warn(link, "link resume succeeded after %d retries\n",
+                             ATA_LINK_RESUME_TRIES - tries);
+
+       if ((rc = sata_link_debounce(link, params, deadline)))
+               return rc;
+
+       /* clear SError, some PHYs require this even for SRST to work */
+       if (!(rc = sata_scr_read(link, SCR_ERROR, &serror)))
+               rc = sata_scr_write(link, SCR_ERROR, serror);
+
+       return rc != -EINVAL ? rc : 0;
+}
+EXPORT_SYMBOL_GPL(sata_link_resume);
+
+/**
+ *     sata_link_scr_lpm - manipulate SControl IPM and SPM fields
+ *     @link: ATA link to manipulate SControl for
+ *     @policy: LPM policy to configure
+ *     @spm_wakeup: initiate LPM transition to active state
+ *
+ *     Manipulate the IPM field of the SControl register of @link
+ *     according to @policy.  If @policy is ATA_LPM_MAX_POWER and
+ *     @spm_wakeup is %true, the SPM field is manipulated to wake up
+ *     the link.  This function also clears PHYRDY_CHG before
+ *     returning.
+ *
+ *     LOCKING:
+ *     EH context.
+ *
+ *     RETURNS:
+ *     0 on success, -errno otherwise.
+ */
+int sata_link_scr_lpm(struct ata_link *link, enum ata_lpm_policy policy,
+                     bool spm_wakeup)
+{
+       struct ata_eh_context *ehc = &link->eh_context;
+       bool woken_up = false;
+       u32 scontrol;
+       int rc;
+
+       rc = sata_scr_read(link, SCR_CONTROL, &scontrol);
+       if (rc)
+               return rc;
+
+       switch (policy) {
+       case ATA_LPM_MAX_POWER:
+               /* disable all LPM transitions */
+               scontrol |= (0x7 << 8);
+               /* initiate transition to active state */
+               if (spm_wakeup) {
+                       scontrol |= (0x4 << 12);
+                       woken_up = true;
+               }
+               break;
+       case ATA_LPM_MED_POWER:
+               /* allow LPM to PARTIAL */
+               scontrol &= ~(0x1 << 8);
+               scontrol |= (0x6 << 8);
+               break;
+       case ATA_LPM_MED_POWER_WITH_DIPM:
+       case ATA_LPM_MIN_POWER_WITH_PARTIAL:
+       case ATA_LPM_MIN_POWER:
+               if (ata_link_nr_enabled(link) > 0)
+                       /* no restrictions on LPM transitions */
+                       scontrol &= ~(0x7 << 8);
+               else {
+                       /* empty port, power off */
+                       scontrol &= ~0xf;
+                       scontrol |= (0x1 << 2);
+               }
+               break;
+       default:
+               WARN_ON(1);
+       }
+
+       rc = sata_scr_write(link, SCR_CONTROL, scontrol);
+       if (rc)
+               return rc;
+
+       /* give the link time to transit out of LPM state */
+       if (woken_up)
+               msleep(10);
+
+       /* clear PHYRDY_CHG from SError */
+       ehc->i.serror &= ~SERR_PHYRDY_CHG;
+       return sata_scr_write(link, SCR_ERROR, SERR_PHYRDY_CHG);
+}
+EXPORT_SYMBOL_GPL(sata_link_scr_lpm);
+
+static int __sata_set_spd_needed(struct ata_link *link, u32 *scontrol)
+{
+       struct ata_link *host_link = &link->ap->link;
+       u32 limit, target, spd;
+
+       limit = link->sata_spd_limit;
+
+       /* Don't configure downstream link faster than upstream link.
+        * It doesn't speed up anything and some PMPs choke on such
+        * configuration.
+        */
+       if (!ata_is_host_link(link) && host_link->sata_spd)
+               limit &= (1 << host_link->sata_spd) - 1;
+
+       if (limit == UINT_MAX)
+               target = 0;
+       else
+               target = fls(limit);
+
+       spd = (*scontrol >> 4) & 0xf;
+       *scontrol = (*scontrol & ~0xf0) | ((target & 0xf) << 4);
+
+       return spd != target;
+}
+
+/**
+ *     sata_set_spd_needed - is SATA spd configuration needed
+ *     @link: Link in question
+ *
+ *     Test whether the spd limit in SControl matches
+ *     @link->sata_spd_limit.  This function is used to determine
+ *     whether hardreset is necessary to apply SATA spd
+ *     configuration.
+ *
+ *     LOCKING:
+ *     Inherited from caller.
+ *
+ *     RETURNS:
+ *     1 if SATA spd configuration is needed, 0 otherwise.
+ */
+static int sata_set_spd_needed(struct ata_link *link)
+{
+       u32 scontrol;
+
+       if (sata_scr_read(link, SCR_CONTROL, &scontrol))
+               return 1;
+
+       return __sata_set_spd_needed(link, &scontrol);
+}
+
+/**
+ *     sata_set_spd - set SATA spd according to spd limit
+ *     @link: Link to set SATA spd for
+ *
+ *     Set SATA spd of @link according to sata_spd_limit.
+ *
+ *     LOCKING:
+ *     Inherited from caller.
+ *
+ *     RETURNS:
+ *     0 if spd doesn't need to be changed, 1 if spd has been
+ *     changed.  Negative errno if SCR registers are inaccessible.
+ */
+int sata_set_spd(struct ata_link *link)
+{
+       u32 scontrol;
+       int rc;
+
+       if ((rc = sata_scr_read(link, SCR_CONTROL, &scontrol)))
+               return rc;
+
+       if (!__sata_set_spd_needed(link, &scontrol))
+               return 0;
+
+       if ((rc = sata_scr_write(link, SCR_CONTROL, scontrol)))
+               return rc;
+
+       return 1;
+}
+EXPORT_SYMBOL_GPL(sata_set_spd);
+
+/**
+ *     sata_link_hardreset - reset link via SATA phy reset
+ *     @link: link to reset
+ *     @timing: timing parameters { interval, duration, timeout } in msec
+ *     @deadline: deadline jiffies for the operation
+ *     @online: optional out parameter indicating link onlineness
+ *     @check_ready: optional callback to check link readiness
+ *
+ *     SATA phy-reset @link using DET bits of SControl register.
+ *     After hardreset, link readiness is waited upon using
+ *     ata_wait_ready() if @check_ready is specified.  LLDs are
+ *     allowed to not specify @check_ready and wait itself after this
+ *     function returns.  Device classification is LLD's
+ *     responsibility.
+ *
+ *     *@online is set to one iff reset succeeded and @link is online
+ *     after reset.
+ *
+ *     LOCKING:
+ *     Kernel thread context (may sleep)
+ *
+ *     RETURNS:
+ *     0 on success, -errno otherwise.
+ */
+int sata_link_hardreset(struct ata_link *link, const unsigned long *timing,
+                       unsigned long deadline,
+                       bool *online, int (*check_ready)(struct ata_link *))
+{
+       u32 scontrol;
+       int rc;
+
+       DPRINTK("ENTER\n");
+
+       if (online)
+               *online = false;
+
+       if (sata_set_spd_needed(link)) {
+               /* SATA spec says nothing about how to reconfigure
+                * spd.  To be on the safe side, turn off phy during
+                * reconfiguration.  This works for at least ICH7 AHCI
+                * and Sil3124.
+                */
+               if ((rc = sata_scr_read(link, SCR_CONTROL, &scontrol)))
+                       goto out;
+
+               scontrol = (scontrol & 0x0f0) | 0x304;
+
+               if ((rc = sata_scr_write(link, SCR_CONTROL, scontrol)))
+                       goto out;
+
+               sata_set_spd(link);
+       }
+
+       /* issue phy wake/reset */
+       if ((rc = sata_scr_read(link, SCR_CONTROL, &scontrol)))
+               goto out;
+
+       scontrol = (scontrol & 0x0f0) | 0x301;
+
+       if ((rc = sata_scr_write_flush(link, SCR_CONTROL, scontrol)))
+               goto out;
+
+       /* Couldn't find anything in SATA I/II specs, but AHCI-1.1
+        * 10.4.2 says at least 1 ms.
+        */
+       ata_msleep(link->ap, 1);
+
+       /* bring link back */
+       rc = sata_link_resume(link, timing, deadline);
+       if (rc)
+               goto out;
+       /* if link is offline nothing more to do */
+       if (ata_phys_link_offline(link))
+               goto out;
+
+       /* Link is online.  From this point, -ENODEV too is an error. */
+       if (online)
+               *online = true;
+
+       if (sata_pmp_supported(link->ap) && ata_is_host_link(link)) {
+               /* If PMP is supported, we have to do follow-up SRST.
+                * Some PMPs don't send D2H Reg FIS after hardreset if
+                * the first port is empty.  Wait only for
+                * ATA_TMOUT_PMP_SRST_WAIT.
+                */
+               if (check_ready) {
+                       unsigned long pmp_deadline;
+
+                       pmp_deadline = ata_deadline(jiffies,
+                                                   ATA_TMOUT_PMP_SRST_WAIT);
+                       if (time_after(pmp_deadline, deadline))
+                               pmp_deadline = deadline;
+                       ata_wait_ready(link, pmp_deadline, check_ready);
+               }
+               rc = -EAGAIN;
+               goto out;
+       }
+
+       rc = 0;
+       if (check_ready)
+               rc = ata_wait_ready(link, deadline, check_ready);
+ out:
+       if (rc && rc != -EAGAIN) {
+               /* online is set iff link is online && reset succeeded */
+               if (online)
+                       *online = false;
+               ata_link_err(link, "COMRESET failed (errno=%d)\n", rc);
+       }
+       DPRINTK("EXIT, rc=%d\n", rc);
+       return rc;
+}
+EXPORT_SYMBOL_GPL(sata_link_hardreset);
+
+/**
+ *     ata_qc_complete_multiple - Complete multiple qcs successfully
+ *     @ap: port in question
+ *     @qc_active: new qc_active mask
+ *
+ *     Complete in-flight commands.  This functions is meant to be
+ *     called from low-level driver's interrupt routine to complete
+ *     requests normally.  ap->qc_active and @qc_active is compared
+ *     and commands are completed accordingly.
+ *
+ *     Always use this function when completing multiple NCQ commands
+ *     from IRQ handlers instead of calling ata_qc_complete()
+ *     multiple times to keep IRQ expect status properly in sync.
+ *
+ *     LOCKING:
+ *     spin_lock_irqsave(host lock)
+ *
+ *     RETURNS:
+ *     Number of completed commands on success, -errno otherwise.
+ */
+int ata_qc_complete_multiple(struct ata_port *ap, u64 qc_active)
+{
+       u64 done_mask, ap_qc_active = ap->qc_active;
+       int nr_done = 0;
+
+       /*
+        * If the internal tag is set on ap->qc_active, then we care about
+        * bit0 on the passed in qc_active mask. Move that bit up to match
+        * the internal tag.
+        */
+       if (ap_qc_active & (1ULL << ATA_TAG_INTERNAL)) {
+               qc_active |= (qc_active & 0x01) << ATA_TAG_INTERNAL;
+               qc_active ^= qc_active & 0x01;
+       }
+
+       done_mask = ap_qc_active ^ qc_active;
+
+       if (unlikely(done_mask & qc_active)) {
+               ata_port_err(ap, "illegal qc_active transition (%08llx->%08llx)\n",
+                            ap->qc_active, qc_active);
+               return -EINVAL;
+       }
+
+       while (done_mask) {
+               struct ata_queued_cmd *qc;
+               unsigned int tag = __ffs64(done_mask);
+
+               qc = ata_qc_from_tag(ap, tag);
+               if (qc) {
+                       ata_qc_complete(qc);
+                       nr_done++;
+               }
+               done_mask &= ~(1ULL << tag);
+       }
+
+       return nr_done;
+}
+EXPORT_SYMBOL_GPL(ata_qc_complete_multiple);
+
+/**
+ *     ata_slave_link_init - initialize slave link
+ *     @ap: port to initialize slave link for
+ *
+ *     Create and initialize slave link for @ap.  This enables slave
+ *     link handling on the port.
+ *
+ *     In libata, a port contains links and a link contains devices.
+ *     There is single host link but if a PMP is attached to it,
+ *     there can be multiple fan-out links.  On SATA, there's usually
+ *     a single device connected to a link but PATA and SATA
+ *     controllers emulating TF based interface can have two - master
+ *     and slave.
+ *
+ *     However, there are a few controllers which don't fit into this
+ *     abstraction too well - SATA controllers which emulate TF
+ *     interface with both master and slave devices but also have
+ *     separate SCR register sets for each device.  These controllers
+ *     need separate links for physical link handling
+ *     (e.g. onlineness, link speed) but should be treated like a
+ *     traditional M/S controller for everything else (e.g. command
+ *     issue, softreset).
+ *
+ *     slave_link is libata's way of handling this class of
+ *     controllers without impacting core layer too much.  For
+ *     anything other than physical link handling, the default host
+ *     link is used for both master and slave.  For physical link
+ *     handling, separate @ap->slave_link is used.  All dirty details
+ *     are implemented inside libata core layer.  From LLD's POV, the
+ *     only difference is that prereset, hardreset and postreset are
+ *     called once more for the slave link, so the reset sequence
+ *     looks like the following.
+ *
+ *     prereset(M) -> prereset(S) -> hardreset(M) -> hardreset(S) ->
+ *     softreset(M) -> postreset(M) -> postreset(S)
+ *
+ *     Note that softreset is called only for the master.  Softreset
+ *     resets both M/S by definition, so SRST on master should handle
+ *     both (the standard method will work just fine).
+ *
+ *     LOCKING:
+ *     Should be called before host is registered.
+ *
+ *     RETURNS:
+ *     0 on success, -errno on failure.
+ */
+int ata_slave_link_init(struct ata_port *ap)
+{
+       struct ata_link *link;
+
+       WARN_ON(ap->slave_link);
+       WARN_ON(ap->flags & ATA_FLAG_PMP);
+
+       link = kzalloc(sizeof(*link), GFP_KERNEL);
+       if (!link)
+               return -ENOMEM;
+
+       ata_link_init(ap, link, 1);
+       ap->slave_link = link;
+       return 0;
+}
+EXPORT_SYMBOL_GPL(ata_slave_link_init);
+
+/**
+ *     sata_lpm_ignore_phy_events - test if PHY event should be ignored
+ *     @link: Link receiving the event
+ *
+ *     Test whether the received PHY event has to be ignored or not.
+ *
+ *     LOCKING:
+ *     None:
+ *
+ *     RETURNS:
+ *     True if the event has to be ignored.
+ */
+bool sata_lpm_ignore_phy_events(struct ata_link *link)
+{
+       unsigned long lpm_timeout = link->last_lpm_change +
+                                   msecs_to_jiffies(ATA_TMOUT_SPURIOUS_PHY);
+
+       /* if LPM is enabled, PHYRDY doesn't mean anything */
+       if (link->lpm_policy > ATA_LPM_MAX_POWER)
+               return true;
+
+       /* ignore the first PHY event after the LPM policy changed
+        * as it is might be spurious
+        */
+       if ((link->flags & ATA_LFLAG_CHANGED) &&
+           time_before(jiffies, lpm_timeout))
+               return true;
+
+       return false;
+}
+EXPORT_SYMBOL_GPL(sata_lpm_ignore_phy_events);
+
+static const char *ata_lpm_policy_names[] = {
+       [ATA_LPM_UNKNOWN]               = "max_performance",
+       [ATA_LPM_MAX_POWER]             = "max_performance",
+       [ATA_LPM_MED_POWER]             = "medium_power",
+       [ATA_LPM_MED_POWER_WITH_DIPM]   = "med_power_with_dipm",
+       [ATA_LPM_MIN_POWER_WITH_PARTIAL] = "min_power_with_partial",
+       [ATA_LPM_MIN_POWER]             = "min_power",
+};
+
+static ssize_t ata_scsi_lpm_store(struct device *device,
+                                 struct device_attribute *attr,
+                                 const char *buf, size_t count)
+{
+       struct Scsi_Host *shost = class_to_shost(device);
+       struct ata_port *ap = ata_shost_to_port(shost);
+       struct ata_link *link;
+       struct ata_device *dev;
+       enum ata_lpm_policy policy;
+       unsigned long flags;
+
+       /* UNKNOWN is internal state, iterate from MAX_POWER */
+       for (policy = ATA_LPM_MAX_POWER;
+            policy < ARRAY_SIZE(ata_lpm_policy_names); policy++) {
+               const char *name = ata_lpm_policy_names[policy];
+
+               if (strncmp(name, buf, strlen(name)) == 0)
+                       break;
+       }
+       if (policy == ARRAY_SIZE(ata_lpm_policy_names))
+               return -EINVAL;
+
+       spin_lock_irqsave(ap->lock, flags);
+
+       ata_for_each_link(link, ap, EDGE) {
+               ata_for_each_dev(dev, &ap->link, ENABLED) {
+                       if (dev->horkage & ATA_HORKAGE_NOLPM) {
+                               count = -EOPNOTSUPP;
+                               goto out_unlock;
+                       }
+               }
+       }
+
+       ap->target_lpm_policy = policy;
+       ata_port_schedule_eh(ap);
+out_unlock:
+       spin_unlock_irqrestore(ap->lock, flags);
+       return count;
+}
+
+static ssize_t ata_scsi_lpm_show(struct device *dev,
+                                struct device_attribute *attr, char *buf)
+{
+       struct Scsi_Host *shost = class_to_shost(dev);
+       struct ata_port *ap = ata_shost_to_port(shost);
+
+       if (ap->target_lpm_policy >= ARRAY_SIZE(ata_lpm_policy_names))
+               return -EINVAL;
+
+       return snprintf(buf, PAGE_SIZE, "%s\n",
+                       ata_lpm_policy_names[ap->target_lpm_policy]);
+}
+DEVICE_ATTR(link_power_management_policy, S_IRUGO | S_IWUSR,
+           ata_scsi_lpm_show, ata_scsi_lpm_store);
+EXPORT_SYMBOL_GPL(dev_attr_link_power_management_policy);
+
+static ssize_t ata_ncq_prio_enable_show(struct device *device,
+                                       struct device_attribute *attr,
+                                       char *buf)
+{
+       struct scsi_device *sdev = to_scsi_device(device);
+       struct ata_port *ap;
+       struct ata_device *dev;
+       bool ncq_prio_enable;
+       int rc = 0;
+
+       ap = ata_shost_to_port(sdev->host);
+
+       spin_lock_irq(ap->lock);
+       dev = ata_scsi_find_dev(ap, sdev);
+       if (!dev) {
+               rc = -ENODEV;
+               goto unlock;
+       }
+
+       ncq_prio_enable = dev->flags & ATA_DFLAG_NCQ_PRIO_ENABLE;
+
+unlock:
+       spin_unlock_irq(ap->lock);
+
+       return rc ? rc : snprintf(buf, 20, "%u\n", ncq_prio_enable);
+}
+
+static ssize_t ata_ncq_prio_enable_store(struct device *device,
+                                        struct device_attribute *attr,
+                                        const char *buf, size_t len)
+{
+       struct scsi_device *sdev = to_scsi_device(device);
+       struct ata_port *ap;
+       struct ata_device *dev;
+       long int input;
+       int rc;
+
+       rc = kstrtol(buf, 10, &input);
+       if (rc)
+               return rc;
+       if ((input < 0) || (input > 1))
+               return -EINVAL;
+
+       ap = ata_shost_to_port(sdev->host);
+       dev = ata_scsi_find_dev(ap, sdev);
+       if (unlikely(!dev))
+               return  -ENODEV;
+
+       spin_lock_irq(ap->lock);
+       if (input)
+               dev->flags |= ATA_DFLAG_NCQ_PRIO_ENABLE;
+       else
+               dev->flags &= ~ATA_DFLAG_NCQ_PRIO_ENABLE;
+
+       dev->link->eh_info.action |= ATA_EH_REVALIDATE;
+       dev->link->eh_info.flags |= ATA_EHI_QUIET;
+       ata_port_schedule_eh(ap);
+       spin_unlock_irq(ap->lock);
+
+       ata_port_wait_eh(ap);
+
+       if (input) {
+               spin_lock_irq(ap->lock);
+               if (!(dev->flags & ATA_DFLAG_NCQ_PRIO)) {
+                       dev->flags &= ~ATA_DFLAG_NCQ_PRIO_ENABLE;
+                       rc = -EIO;
+               }
+               spin_unlock_irq(ap->lock);
+       }
+
+       return rc ? rc : len;
+}
+
+DEVICE_ATTR(ncq_prio_enable, S_IRUGO | S_IWUSR,
+           ata_ncq_prio_enable_show, ata_ncq_prio_enable_store);
+EXPORT_SYMBOL_GPL(dev_attr_ncq_prio_enable);
+
+struct device_attribute *ata_ncq_sdev_attrs[] = {
+       &dev_attr_unload_heads,
+       &dev_attr_ncq_prio_enable,
+       NULL
+};
+EXPORT_SYMBOL_GPL(ata_ncq_sdev_attrs);
+
+static ssize_t
+ata_scsi_em_message_store(struct device *dev, struct device_attribute *attr,
+                         const char *buf, size_t count)
+{
+       struct Scsi_Host *shost = class_to_shost(dev);
+       struct ata_port *ap = ata_shost_to_port(shost);
+       if (ap->ops->em_store && (ap->flags & ATA_FLAG_EM))
+               return ap->ops->em_store(ap, buf, count);
+       return -EINVAL;
+}
+
+static ssize_t
+ata_scsi_em_message_show(struct device *dev, struct device_attribute *attr,
+                        char *buf)
+{
+       struct Scsi_Host *shost = class_to_shost(dev);
+       struct ata_port *ap = ata_shost_to_port(shost);
+
+       if (ap->ops->em_show && (ap->flags & ATA_FLAG_EM))
+               return ap->ops->em_show(ap, buf);
+       return -EINVAL;
+}
+DEVICE_ATTR(em_message, S_IRUGO | S_IWUSR,
+               ata_scsi_em_message_show, ata_scsi_em_message_store);
+EXPORT_SYMBOL_GPL(dev_attr_em_message);
+
+static ssize_t
+ata_scsi_em_message_type_show(struct device *dev, struct device_attribute *attr,
+                             char *buf)
+{
+       struct Scsi_Host *shost = class_to_shost(dev);
+       struct ata_port *ap = ata_shost_to_port(shost);
+
+       return snprintf(buf, 23, "%d\n", ap->em_message_type);
+}
+DEVICE_ATTR(em_message_type, S_IRUGO,
+                 ata_scsi_em_message_type_show, NULL);
+EXPORT_SYMBOL_GPL(dev_attr_em_message_type);
+
+static ssize_t
+ata_scsi_activity_show(struct device *dev, struct device_attribute *attr,
+               char *buf)
+{
+       struct scsi_device *sdev = to_scsi_device(dev);
+       struct ata_port *ap = ata_shost_to_port(sdev->host);
+       struct ata_device *atadev = ata_scsi_find_dev(ap, sdev);
+
+       if (atadev && ap->ops->sw_activity_show &&
+           (ap->flags & ATA_FLAG_SW_ACTIVITY))
+               return ap->ops->sw_activity_show(atadev, buf);
+       return -EINVAL;
+}
+
+static ssize_t
+ata_scsi_activity_store(struct device *dev, struct device_attribute *attr,
+       const char *buf, size_t count)
+{
+       struct scsi_device *sdev = to_scsi_device(dev);
+       struct ata_port *ap = ata_shost_to_port(sdev->host);
+       struct ata_device *atadev = ata_scsi_find_dev(ap, sdev);
+       enum sw_activity val;
+       int rc;
+
+       if (atadev && ap->ops->sw_activity_store &&
+           (ap->flags & ATA_FLAG_SW_ACTIVITY)) {
+               val = simple_strtoul(buf, NULL, 0);
+               switch (val) {
+               case OFF: case BLINK_ON: case BLINK_OFF:
+                       rc = ap->ops->sw_activity_store(atadev, val);
+                       if (!rc)
+                               return count;
+                       else
+                               return rc;
+               }
+       }
+       return -EINVAL;
+}
+DEVICE_ATTR(sw_activity, S_IWUSR | S_IRUGO, ata_scsi_activity_show,
+                       ata_scsi_activity_store);
+EXPORT_SYMBOL_GPL(dev_attr_sw_activity);
+
+/**
+ *     __ata_change_queue_depth - helper for ata_scsi_change_queue_depth
+ *     @ap: ATA port to which the device change the queue depth
+ *     @sdev: SCSI device to configure queue depth for
+ *     @queue_depth: new queue depth
+ *
+ *     libsas and libata have different approaches for associating a sdev to
+ *     its ata_port.
+ *
+ */
+int __ata_change_queue_depth(struct ata_port *ap, struct scsi_device *sdev,
+                            int queue_depth)
+{
+       struct ata_device *dev;
+       unsigned long flags;
+
+       if (queue_depth < 1 || queue_depth == sdev->queue_depth)
+               return sdev->queue_depth;
+
+       dev = ata_scsi_find_dev(ap, sdev);
+       if (!dev || !ata_dev_enabled(dev))
+               return sdev->queue_depth;
+
+       /* NCQ enabled? */
+       spin_lock_irqsave(ap->lock, flags);
+       dev->flags &= ~ATA_DFLAG_NCQ_OFF;
+       if (queue_depth == 1 || !ata_ncq_enabled(dev)) {
+               dev->flags |= ATA_DFLAG_NCQ_OFF;
+               queue_depth = 1;
+       }
+       spin_unlock_irqrestore(ap->lock, flags);
+
+       /* limit and apply queue depth */
+       queue_depth = min(queue_depth, sdev->host->can_queue);
+       queue_depth = min(queue_depth, ata_id_queue_depth(dev->id));
+       queue_depth = min(queue_depth, ATA_MAX_QUEUE);
+
+       if (sdev->queue_depth == queue_depth)
+               return -EINVAL;
+
+       return scsi_change_queue_depth(sdev, queue_depth);
+}
+EXPORT_SYMBOL_GPL(__ata_change_queue_depth);
+
+/**
+ *     ata_scsi_change_queue_depth - SCSI callback for queue depth config
+ *     @sdev: SCSI device to configure queue depth for
+ *     @queue_depth: new queue depth
+ *
+ *     This is libata standard hostt->change_queue_depth callback.
+ *     SCSI will call into this callback when user tries to set queue
+ *     depth via sysfs.
+ *
+ *     LOCKING:
+ *     SCSI layer (we don't care)
+ *
+ *     RETURNS:
+ *     Newly configured queue depth.
+ */
+int ata_scsi_change_queue_depth(struct scsi_device *sdev, int queue_depth)
+{
+       struct ata_port *ap = ata_shost_to_port(sdev->host);
+
+       return __ata_change_queue_depth(ap, sdev, queue_depth);
+}
+EXPORT_SYMBOL_GPL(ata_scsi_change_queue_depth);
+
+/**
+ *     port_alloc - Allocate port for a SAS attached SATA device
+ *     @host: ATA host container for all SAS ports
+ *     @port_info: Information from low-level host driver
+ *     @shost: SCSI host that the scsi device is attached to
+ *
+ *     LOCKING:
+ *     PCI/etc. bus probe sem.
+ *
+ *     RETURNS:
+ *     ata_port pointer on success / NULL on failure.
+ */
+
+struct ata_port *ata_sas_port_alloc(struct ata_host *host,
+                                   struct ata_port_info *port_info,
+                                   struct Scsi_Host *shost)
+{
+       struct ata_port *ap;
+
+       ap = ata_port_alloc(host);
+       if (!ap)
+               return NULL;
+
+       ap->port_no = 0;
+       ap->lock = &host->lock;
+       ap->pio_mask = port_info->pio_mask;
+       ap->mwdma_mask = port_info->mwdma_mask;
+       ap->udma_mask = port_info->udma_mask;
+       ap->flags |= port_info->flags;
+       ap->ops = port_info->port_ops;
+       ap->cbl = ATA_CBL_SATA;
+
+       return ap;
+}
+EXPORT_SYMBOL_GPL(ata_sas_port_alloc);
+
+/**
+ *     ata_sas_port_start - Set port up for dma.
+ *     @ap: Port to initialize
+ *
+ *     Called just after data structures for each port are
+ *     initialized.
+ *
+ *     May be used as the port_start() entry in ata_port_operations.
+ *
+ *     LOCKING:
+ *     Inherited from caller.
+ */
+int ata_sas_port_start(struct ata_port *ap)
+{
+       /*
+        * the port is marked as frozen at allocation time, but if we don't
+        * have new eh, we won't thaw it
+        */
+       if (!ap->ops->error_handler)
+               ap->pflags &= ~ATA_PFLAG_FROZEN;
+       return 0;
+}
+EXPORT_SYMBOL_GPL(ata_sas_port_start);
+
+/**
+ *     ata_port_stop - Undo ata_sas_port_start()
+ *     @ap: Port to shut down
+ *
+ *     May be used as the port_stop() entry in ata_port_operations.
+ *
+ *     LOCKING:
+ *     Inherited from caller.
+ */
+
+void ata_sas_port_stop(struct ata_port *ap)
+{
+}
+EXPORT_SYMBOL_GPL(ata_sas_port_stop);
+
+/**
+ * ata_sas_async_probe - simply schedule probing and return
+ * @ap: Port to probe
+ *
+ * For batch scheduling of probe for sas attached ata devices, assumes
+ * the port has already been through ata_sas_port_init()
+ */
+void ata_sas_async_probe(struct ata_port *ap)
+{
+       __ata_port_probe(ap);
+}
+EXPORT_SYMBOL_GPL(ata_sas_async_probe);
+
+int ata_sas_sync_probe(struct ata_port *ap)
+{
+       return ata_port_probe(ap);
+}
+EXPORT_SYMBOL_GPL(ata_sas_sync_probe);
+
+
+/**
+ *     ata_sas_port_init - Initialize a SATA device
+ *     @ap: SATA port to initialize
+ *
+ *     LOCKING:
+ *     PCI/etc. bus probe sem.
+ *
+ *     RETURNS:
+ *     Zero on success, non-zero on error.
+ */
+
+int ata_sas_port_init(struct ata_port *ap)
+{
+       int rc = ap->ops->port_start(ap);
+
+       if (rc)
+               return rc;
+       ap->print_id = atomic_inc_return(&ata_print_id);
+       return 0;
+}
+EXPORT_SYMBOL_GPL(ata_sas_port_init);
+
+int ata_sas_tport_add(struct device *parent, struct ata_port *ap)
+{
+       return ata_tport_add(parent, ap);
+}
+EXPORT_SYMBOL_GPL(ata_sas_tport_add);
+
+void ata_sas_tport_delete(struct ata_port *ap)
+{
+       ata_tport_delete(ap);
+}
+EXPORT_SYMBOL_GPL(ata_sas_tport_delete);
+
+/**
+ *     ata_sas_port_destroy - Destroy a SATA port allocated by ata_sas_port_alloc
+ *     @ap: SATA port to destroy
+ *
+ */
+
+void ata_sas_port_destroy(struct ata_port *ap)
+{
+       if (ap->ops->port_stop)
+               ap->ops->port_stop(ap);
+       kfree(ap);
+}
+EXPORT_SYMBOL_GPL(ata_sas_port_destroy);
+
+/**
+ *     ata_sas_slave_configure - Default slave_config routine for libata devices
+ *     @sdev: SCSI device to configure
+ *     @ap: ATA port to which SCSI device is attached
+ *
+ *     RETURNS:
+ *     Zero.
+ */
+
+int ata_sas_slave_configure(struct scsi_device *sdev, struct ata_port *ap)
+{
+       ata_scsi_sdev_config(sdev);
+       ata_scsi_dev_config(sdev, ap->link.device);
+       return 0;
+}
+EXPORT_SYMBOL_GPL(ata_sas_slave_configure);
+
+/**
+ *     ata_sas_queuecmd - Issue SCSI cdb to libata-managed device
+ *     @cmd: SCSI command to be sent
+ *     @ap:    ATA port to which the command is being sent
+ *
+ *     RETURNS:
+ *     Return value from __ata_scsi_queuecmd() if @cmd can be queued,
+ *     0 otherwise.
+ */
+
+int ata_sas_queuecmd(struct scsi_cmnd *cmd, struct ata_port *ap)
+{
+       int rc = 0;
+
+       ata_scsi_dump_cdb(ap, cmd);
+
+       if (likely(ata_dev_enabled(ap->link.device)))
+               rc = __ata_scsi_queuecmd(cmd, ap->link.device);
+       else {
+               cmd->result = (DID_BAD_TARGET << 16);
+               cmd->scsi_done(cmd);
+       }
+       return rc;
+}
+EXPORT_SYMBOL_GPL(ata_sas_queuecmd);
+
+int ata_sas_allocate_tag(struct ata_port *ap)
+{
+       unsigned int max_queue = ap->host->n_tags;
+       unsigned int i, tag;
+
+       for (i = 0, tag = ap->sas_last_tag + 1; i < max_queue; i++, tag++) {
+               tag = tag < max_queue ? tag : 0;
+
+               /* the last tag is reserved for internal command. */
+               if (ata_tag_internal(tag))
+                       continue;
+
+               if (!test_and_set_bit(tag, &ap->sas_tag_allocated)) {
+                       ap->sas_last_tag = tag;
+                       return tag;
+               }
+       }
+       return -1;
+}
+
+void ata_sas_free_tag(unsigned int tag, struct ata_port *ap)
+{
+       clear_bit(tag, &ap->sas_tag_allocated);
+}
+
+/**
+ *     sata_async_notification - SATA async notification handler
+ *     @ap: ATA port where async notification is received
+ *
+ *     Handler to be called when async notification via SDB FIS is
+ *     received.  This function schedules EH if necessary.
+ *
+ *     LOCKING:
+ *     spin_lock_irqsave(host lock)
+ *
+ *     RETURNS:
+ *     1 if EH is scheduled, 0 otherwise.
+ */
+int sata_async_notification(struct ata_port *ap)
+{
+       u32 sntf;
+       int rc;
+
+       if (!(ap->flags & ATA_FLAG_AN))
+               return 0;
+
+       rc = sata_scr_read(&ap->link, SCR_NOTIFICATION, &sntf);
+       if (rc == 0)
+               sata_scr_write(&ap->link, SCR_NOTIFICATION, sntf);
+
+       if (!sata_pmp_attached(ap) || rc) {
+               /* PMP is not attached or SNTF is not available */
+               if (!sata_pmp_attached(ap)) {
+                       /* PMP is not attached.  Check whether ATAPI
+                        * AN is configured.  If so, notify media
+                        * change.
+                        */
+                       struct ata_device *dev = ap->link.device;
+
+                       if ((dev->class == ATA_DEV_ATAPI) &&
+                           (dev->flags & ATA_DFLAG_AN))
+                               ata_scsi_media_change_notify(dev);
+                       return 0;
+               } else {
+                       /* PMP is attached but SNTF is not available.
+                        * ATAPI async media change notification is
+                        * not used.  The PMP must be reporting PHY
+                        * status change, schedule EH.
+                        */
+                       ata_port_schedule_eh(ap);
+                       return 1;
+               }
+       } else {
+               /* PMP is attached and SNTF is available */
+               struct ata_link *link;
+
+               /* check and notify ATAPI AN */
+               ata_for_each_link(link, ap, EDGE) {
+                       if (!(sntf & (1 << link->pmp)))
+                               continue;
+
+                       if ((link->device->class == ATA_DEV_ATAPI) &&
+                           (link->device->flags & ATA_DFLAG_AN))
+                               ata_scsi_media_change_notify(link->device);
+               }
+
+               /* If PMP is reporting that PHY status of some
+                * downstream ports has changed, schedule EH.
+                */
+               if (sntf & (1 << SATA_PMP_CTRL_PORT)) {
+                       ata_port_schedule_eh(ap);
+                       return 1;
+               }
+
+               return 0;
+       }
+}
+EXPORT_SYMBOL_GPL(sata_async_notification);
+
+/**
+ *     ata_eh_read_log_10h - Read log page 10h for NCQ error details
+ *     @dev: Device to read log page 10h from
+ *     @tag: Resulting tag of the failed command
+ *     @tf: Resulting taskfile registers of the failed command
+ *
+ *     Read log page 10h to obtain NCQ error details and clear error
+ *     condition.
+ *
+ *     LOCKING:
+ *     Kernel thread context (may sleep).
+ *
+ *     RETURNS:
+ *     0 on success, -errno otherwise.
+ */
+static int ata_eh_read_log_10h(struct ata_device *dev,
+                              int *tag, struct ata_taskfile *tf)
+{
+       u8 *buf = dev->link->ap->sector_buf;
+       unsigned int err_mask;
+       u8 csum;
+       int i;
+
+       err_mask = ata_read_log_page(dev, ATA_LOG_SATA_NCQ, 0, buf, 1);
+       if (err_mask)
+               return -EIO;
+
+       csum = 0;
+       for (i = 0; i < ATA_SECT_SIZE; i++)
+               csum += buf[i];
+       if (csum)
+               ata_dev_warn(dev, "invalid checksum 0x%x on log page 10h\n",
+                            csum);
+
+       if (buf[0] & 0x80)
+               return -ENOENT;
+
+       *tag = buf[0] & 0x1f;
+
+       tf->command = buf[2];
+       tf->feature = buf[3];
+       tf->lbal = buf[4];
+       tf->lbam = buf[5];
+       tf->lbah = buf[6];
+       tf->device = buf[7];
+       tf->hob_lbal = buf[8];
+       tf->hob_lbam = buf[9];
+       tf->hob_lbah = buf[10];
+       tf->nsect = buf[12];
+       tf->hob_nsect = buf[13];
+       if (dev->class == ATA_DEV_ZAC && ata_id_has_ncq_autosense(dev->id))
+               tf->auxiliary = buf[14] << 16 | buf[15] << 8 | buf[16];
+
+       return 0;
+}
+
+/**
+ *     ata_eh_analyze_ncq_error - analyze NCQ error
+ *     @link: ATA link to analyze NCQ error for
+ *
+ *     Read log page 10h, determine the offending qc and acquire
+ *     error status TF.  For NCQ device errors, all LLDDs have to do
+ *     is setting AC_ERR_DEV in ehi->err_mask.  This function takes
+ *     care of the rest.
+ *
+ *     LOCKING:
+ *     Kernel thread context (may sleep).
+ */
+void ata_eh_analyze_ncq_error(struct ata_link *link)
+{
+       struct ata_port *ap = link->ap;
+       struct ata_eh_context *ehc = &link->eh_context;
+       struct ata_device *dev = link->device;
+       struct ata_queued_cmd *qc;
+       struct ata_taskfile tf;
+       int tag, rc;
+
+       /* if frozen, we can't do much */
+       if (ap->pflags & ATA_PFLAG_FROZEN)
+               return;
+
+       /* is it NCQ device error? */
+       if (!link->sactive || !(ehc->i.err_mask & AC_ERR_DEV))
+               return;
+
+       /* has LLDD analyzed already? */
+       ata_qc_for_each_raw(ap, qc, tag) {
+               if (!(qc->flags & ATA_QCFLAG_FAILED))
+                       continue;
+
+               if (qc->err_mask)
+                       return;
+       }
+
+       /* okay, this error is ours */
+       memset(&tf, 0, sizeof(tf));
+       rc = ata_eh_read_log_10h(dev, &tag, &tf);
+       if (rc) {
+               ata_link_err(link, "failed to read log page 10h (errno=%d)\n",
+                            rc);
+               return;
+       }
+
+       if (!(link->sactive & (1 << tag))) {
+               ata_link_err(link, "log page 10h reported inactive tag %d\n",
+                            tag);
+               return;
+       }
+
+       /* we've got the perpetrator, condemn it */
+       qc = __ata_qc_from_tag(ap, tag);
+       memcpy(&qc->result_tf, &tf, sizeof(tf));
+       qc->result_tf.flags = ATA_TFLAG_ISADDR | ATA_TFLAG_LBA | ATA_TFLAG_LBA48;
+       qc->err_mask |= AC_ERR_DEV | AC_ERR_NCQ;
+       if (dev->class == ATA_DEV_ZAC &&
+           ((qc->result_tf.command & ATA_SENSE) || qc->result_tf.auxiliary)) {
+               char sense_key, asc, ascq;
+
+               sense_key = (qc->result_tf.auxiliary >> 16) & 0xff;
+               asc = (qc->result_tf.auxiliary >> 8) & 0xff;
+               ascq = qc->result_tf.auxiliary & 0xff;
+               ata_scsi_set_sense(dev, qc->scsicmd, sense_key, asc, ascq);
+               ata_scsi_set_sense_information(dev, qc->scsicmd,
+                                              &qc->result_tf);
+               qc->flags |= ATA_QCFLAG_SENSE_VALID;
+       }
+
+       ehc->i.err_mask &= ~AC_ERR_DEV;
+}
+EXPORT_SYMBOL_GPL(ata_eh_analyze_ncq_error);
index eb2eb59..36e588d 100644 (file)
@@ -2,10 +2,6 @@
 /*
  *  libata-scsi.c - helper library for ATA
  *
- *  Maintained by:  Tejun Heo <tj@kernel.org>
- *                 Please ALWAYS copy linux-ide@vger.kernel.org
- *                 on emails.
- *
  *  Copyright 2003-2004 Red Hat, Inc.  All rights reserved.
  *  Copyright 2003-2004 Jeff Garzik
  *
 #include <linux/suspend.h>
 #include <asm/unaligned.h>
 #include <linux/ioprio.h>
+#include <linux/of.h>
 
 #include "libata.h"
 #include "libata-transport.h"
 
-#define ATA_SCSI_RBUF_SIZE     4096
+#define ATA_SCSI_RBUF_SIZE     576
 
 static DEFINE_SPINLOCK(ata_scsi_rbuf_lock);
 static u8 ata_scsi_rbuf[ATA_SCSI_RBUF_SIZE];
@@ -49,8 +46,6 @@ typedef unsigned int (*ata_xlat_func_t)(struct ata_queued_cmd *qc);
 
 static struct ata_device *__ata_scsi_find_dev(struct ata_port *ap,
                                        const struct scsi_device *scsidev);
-static struct ata_device *ata_scsi_find_dev(struct ata_port *ap,
-                                           const struct scsi_device *scsidev);
 
 #define RW_RECOVERY_MPAGE 0x1
 #define RW_RECOVERY_MPAGE_LEN 12
@@ -90,71 +85,6 @@ static const u8 def_control_mpage[CONTROL_MPAGE_LEN] = {
        0, 30   /* extended self test time, see 05-359r1 */
 };
 
-static const char *ata_lpm_policy_names[] = {
-       [ATA_LPM_UNKNOWN]               = "max_performance",
-       [ATA_LPM_MAX_POWER]             = "max_performance",
-       [ATA_LPM_MED_POWER]             = "medium_power",
-       [ATA_LPM_MED_POWER_WITH_DIPM]   = "med_power_with_dipm",
-       [ATA_LPM_MIN_POWER_WITH_PARTIAL] = "min_power_with_partial",
-       [ATA_LPM_MIN_POWER]             = "min_power",
-};
-
-static ssize_t ata_scsi_lpm_store(struct device *device,
-                                 struct device_attribute *attr,
-                                 const char *buf, size_t count)
-{
-       struct Scsi_Host *shost = class_to_shost(device);
-       struct ata_port *ap = ata_shost_to_port(shost);
-       struct ata_link *link;
-       struct ata_device *dev;
-       enum ata_lpm_policy policy;
-       unsigned long flags;
-
-       /* UNKNOWN is internal state, iterate from MAX_POWER */
-       for (policy = ATA_LPM_MAX_POWER;
-            policy < ARRAY_SIZE(ata_lpm_policy_names); policy++) {
-               const char *name = ata_lpm_policy_names[policy];
-
-               if (strncmp(name, buf, strlen(name)) == 0)
-                       break;
-       }
-       if (policy == ARRAY_SIZE(ata_lpm_policy_names))
-               return -EINVAL;
-
-       spin_lock_irqsave(ap->lock, flags);
-
-       ata_for_each_link(link, ap, EDGE) {
-               ata_for_each_dev(dev, &ap->link, ENABLED) {
-                       if (dev->horkage & ATA_HORKAGE_NOLPM) {
-                               count = -EOPNOTSUPP;
-                               goto out_unlock;
-                       }
-               }
-       }
-
-       ap->target_lpm_policy = policy;
-       ata_port_schedule_eh(ap);
-out_unlock:
-       spin_unlock_irqrestore(ap->lock, flags);
-       return count;
-}
-
-static ssize_t ata_scsi_lpm_show(struct device *dev,
-                                struct device_attribute *attr, char *buf)
-{
-       struct Scsi_Host *shost = class_to_shost(dev);
-       struct ata_port *ap = ata_shost_to_port(shost);
-
-       if (ap->target_lpm_policy >= ARRAY_SIZE(ata_lpm_policy_names))
-               return -EINVAL;
-
-       return snprintf(buf, PAGE_SIZE, "%s\n",
-                       ata_lpm_policy_names[ap->target_lpm_policy]);
-}
-DEVICE_ATTR(link_power_management_policy, S_IRUGO | S_IWUSR,
-           ata_scsi_lpm_show, ata_scsi_lpm_store);
-EXPORT_SYMBOL_GPL(dev_attr_link_power_management_policy);
-
 static ssize_t ata_scsi_park_show(struct device *device,
                                  struct device_attribute *attr, char *buf)
 {
@@ -258,83 +188,6 @@ DEVICE_ATTR(unload_heads, S_IRUGO | S_IWUSR,
            ata_scsi_park_show, ata_scsi_park_store);
 EXPORT_SYMBOL_GPL(dev_attr_unload_heads);
 
-static ssize_t ata_ncq_prio_enable_show(struct device *device,
-                                       struct device_attribute *attr,
-                                       char *buf)
-{
-       struct scsi_device *sdev = to_scsi_device(device);
-       struct ata_port *ap;
-       struct ata_device *dev;
-       bool ncq_prio_enable;
-       int rc = 0;
-
-       ap = ata_shost_to_port(sdev->host);
-
-       spin_lock_irq(ap->lock);
-       dev = ata_scsi_find_dev(ap, sdev);
-       if (!dev) {
-               rc = -ENODEV;
-               goto unlock;
-       }
-
-       ncq_prio_enable = dev->flags & ATA_DFLAG_NCQ_PRIO_ENABLE;
-
-unlock:
-       spin_unlock_irq(ap->lock);
-
-       return rc ? rc : snprintf(buf, 20, "%u\n", ncq_prio_enable);
-}
-
-static ssize_t ata_ncq_prio_enable_store(struct device *device,
-                                        struct device_attribute *attr,
-                                        const char *buf, size_t len)
-{
-       struct scsi_device *sdev = to_scsi_device(device);
-       struct ata_port *ap;
-       struct ata_device *dev;
-       long int input;
-       int rc;
-
-       rc = kstrtol(buf, 10, &input);
-       if (rc)
-               return rc;
-       if ((input < 0) || (input > 1))
-               return -EINVAL;
-
-       ap = ata_shost_to_port(sdev->host);
-       dev = ata_scsi_find_dev(ap, sdev);
-       if (unlikely(!dev))
-               return  -ENODEV;
-
-       spin_lock_irq(ap->lock);
-       if (input)
-               dev->flags |= ATA_DFLAG_NCQ_PRIO_ENABLE;
-       else
-               dev->flags &= ~ATA_DFLAG_NCQ_PRIO_ENABLE;
-
-       dev->link->eh_info.action |= ATA_EH_REVALIDATE;
-       dev->link->eh_info.flags |= ATA_EHI_QUIET;
-       ata_port_schedule_eh(ap);
-       spin_unlock_irq(ap->lock);
-
-       ata_port_wait_eh(ap);
-
-       if (input) {
-               spin_lock_irq(ap->lock);
-               if (!(dev->flags & ATA_DFLAG_NCQ_PRIO)) {
-                       dev->flags &= ~ATA_DFLAG_NCQ_PRIO_ENABLE;
-                       rc = -EIO;
-               }
-               spin_unlock_irq(ap->lock);
-       }
-
-       return rc ? rc : len;
-}
-
-DEVICE_ATTR(ncq_prio_enable, S_IRUGO | S_IWUSR,
-           ata_ncq_prio_enable_show, ata_ncq_prio_enable_store);
-EXPORT_SYMBOL_GPL(dev_attr_ncq_prio_enable);
-
 void ata_scsi_set_sense(struct ata_device *dev, struct scsi_cmnd *cmd,
                        u8 sk, u8 asc, u8 ascq)
 {
@@ -383,90 +236,8 @@ static void ata_scsi_set_invalid_parameter(struct ata_device *dev,
                                     field, 0xff, 0);
 }
 
-static ssize_t
-ata_scsi_em_message_store(struct device *dev, struct device_attribute *attr,
-                         const char *buf, size_t count)
-{
-       struct Scsi_Host *shost = class_to_shost(dev);
-       struct ata_port *ap = ata_shost_to_port(shost);
-       if (ap->ops->em_store && (ap->flags & ATA_FLAG_EM))
-               return ap->ops->em_store(ap, buf, count);
-       return -EINVAL;
-}
-
-static ssize_t
-ata_scsi_em_message_show(struct device *dev, struct device_attribute *attr,
-                        char *buf)
-{
-       struct Scsi_Host *shost = class_to_shost(dev);
-       struct ata_port *ap = ata_shost_to_port(shost);
-
-       if (ap->ops->em_show && (ap->flags & ATA_FLAG_EM))
-               return ap->ops->em_show(ap, buf);
-       return -EINVAL;
-}
-DEVICE_ATTR(em_message, S_IRUGO | S_IWUSR,
-               ata_scsi_em_message_show, ata_scsi_em_message_store);
-EXPORT_SYMBOL_GPL(dev_attr_em_message);
-
-static ssize_t
-ata_scsi_em_message_type_show(struct device *dev, struct device_attribute *attr,
-                             char *buf)
-{
-       struct Scsi_Host *shost = class_to_shost(dev);
-       struct ata_port *ap = ata_shost_to_port(shost);
-
-       return snprintf(buf, 23, "%d\n", ap->em_message_type);
-}
-DEVICE_ATTR(em_message_type, S_IRUGO,
-                 ata_scsi_em_message_type_show, NULL);
-EXPORT_SYMBOL_GPL(dev_attr_em_message_type);
-
-static ssize_t
-ata_scsi_activity_show(struct device *dev, struct device_attribute *attr,
-               char *buf)
-{
-       struct scsi_device *sdev = to_scsi_device(dev);
-       struct ata_port *ap = ata_shost_to_port(sdev->host);
-       struct ata_device *atadev = ata_scsi_find_dev(ap, sdev);
-
-       if (atadev && ap->ops->sw_activity_show &&
-           (ap->flags & ATA_FLAG_SW_ACTIVITY))
-               return ap->ops->sw_activity_show(atadev, buf);
-       return -EINVAL;
-}
-
-static ssize_t
-ata_scsi_activity_store(struct device *dev, struct device_attribute *attr,
-       const char *buf, size_t count)
-{
-       struct scsi_device *sdev = to_scsi_device(dev);
-       struct ata_port *ap = ata_shost_to_port(sdev->host);
-       struct ata_device *atadev = ata_scsi_find_dev(ap, sdev);
-       enum sw_activity val;
-       int rc;
-
-       if (atadev && ap->ops->sw_activity_store &&
-           (ap->flags & ATA_FLAG_SW_ACTIVITY)) {
-               val = simple_strtoul(buf, NULL, 0);
-               switch (val) {
-               case OFF: case BLINK_ON: case BLINK_OFF:
-                       rc = ap->ops->sw_activity_store(atadev, val);
-                       if (!rc)
-                               return count;
-                       else
-                               return rc;
-               }
-       }
-       return -EINVAL;
-}
-DEVICE_ATTR(sw_activity, S_IWUSR | S_IRUGO, ata_scsi_activity_show,
-                       ata_scsi_activity_store);
-EXPORT_SYMBOL_GPL(dev_attr_sw_activity);
-
 struct device_attribute *ata_common_sdev_attrs[] = {
        &dev_attr_unload_heads,
-       &dev_attr_ncq_prio_enable,
        NULL
 };
 EXPORT_SYMBOL_GPL(ata_common_sdev_attrs);
@@ -499,6 +270,7 @@ int ata_std_bios_param(struct scsi_device *sdev, struct block_device *bdev,
 
        return 0;
 }
+EXPORT_SYMBOL_GPL(ata_std_bios_param);
 
 /**
  *     ata_scsi_unlock_native_capacity - unlock native capacity
@@ -528,6 +300,7 @@ void ata_scsi_unlock_native_capacity(struct scsi_device *sdev)
        spin_unlock_irqrestore(ap->lock, flags);
        ata_port_wait_eh(ap);
 }
+EXPORT_SYMBOL_GPL(ata_scsi_unlock_native_capacity);
 
 /**
  *     ata_get_identity - Handler for HDIO_GET_IDENTITY ioctl
@@ -1215,7 +988,7 @@ static void ata_gen_ata_sense(struct ata_queued_cmd *qc)
        scsi_set_sense_information(sb, SCSI_SENSE_BUFFERSIZE, block);
 }
 
-static void ata_scsi_sdev_config(struct scsi_device *sdev)
+void ata_scsi_sdev_config(struct scsi_device *sdev)
 {
        sdev->use_10_for_rw = 1;
        sdev->use_10_for_ms = 1;
@@ -1255,8 +1028,7 @@ static int atapi_drain_needed(struct request *rq)
        return atapi_cmd_type(scsi_req(rq)->cmd[0]) == ATAPI_MISC;
 }
 
-static int ata_scsi_dev_config(struct scsi_device *sdev,
-                              struct ata_device *dev)
+int ata_scsi_dev_config(struct scsi_device *sdev, struct ata_device *dev)
 {
        struct request_queue *q = sdev->request_queue;
 
@@ -1344,6 +1116,7 @@ int ata_scsi_slave_config(struct scsi_device *sdev)
 
        return rc;
 }
+EXPORT_SYMBOL_GPL(ata_scsi_slave_config);
 
 /**
  *     ata_scsi_slave_destroy - SCSI device is about to be destroyed
@@ -1383,71 +1156,7 @@ void ata_scsi_slave_destroy(struct scsi_device *sdev)
        q->dma_drain_buffer = NULL;
        q->dma_drain_size = 0;
 }
-
-/**
- *     __ata_change_queue_depth - helper for ata_scsi_change_queue_depth
- *     @ap: ATA port to which the device change the queue depth
- *     @sdev: SCSI device to configure queue depth for
- *     @queue_depth: new queue depth
- *
- *     libsas and libata have different approaches for associating a sdev to
- *     its ata_port.
- *
- */
-int __ata_change_queue_depth(struct ata_port *ap, struct scsi_device *sdev,
-                            int queue_depth)
-{
-       struct ata_device *dev;
-       unsigned long flags;
-
-       if (queue_depth < 1 || queue_depth == sdev->queue_depth)
-               return sdev->queue_depth;
-
-       dev = ata_scsi_find_dev(ap, sdev);
-       if (!dev || !ata_dev_enabled(dev))
-               return sdev->queue_depth;
-
-       /* NCQ enabled? */
-       spin_lock_irqsave(ap->lock, flags);
-       dev->flags &= ~ATA_DFLAG_NCQ_OFF;
-       if (queue_depth == 1 || !ata_ncq_enabled(dev)) {
-               dev->flags |= ATA_DFLAG_NCQ_OFF;
-               queue_depth = 1;
-       }
-       spin_unlock_irqrestore(ap->lock, flags);
-
-       /* limit and apply queue depth */
-       queue_depth = min(queue_depth, sdev->host->can_queue);
-       queue_depth = min(queue_depth, ata_id_queue_depth(dev->id));
-       queue_depth = min(queue_depth, ATA_MAX_QUEUE);
-
-       if (sdev->queue_depth == queue_depth)
-               return -EINVAL;
-
-       return scsi_change_queue_depth(sdev, queue_depth);
-}
-
-/**
- *     ata_scsi_change_queue_depth - SCSI callback for queue depth config
- *     @sdev: SCSI device to configure queue depth for
- *     @queue_depth: new queue depth
- *
- *     This is libata standard hostt->change_queue_depth callback.
- *     SCSI will call into this callback when user tries to set queue
- *     depth via sysfs.
- *
- *     LOCKING:
- *     SCSI layer (we don't care)
- *
- *     RETURNS:
- *     Newly configured queue depth.
- */
-int ata_scsi_change_queue_depth(struct scsi_device *sdev, int queue_depth)
-{
-       struct ata_port *ap = ata_shost_to_port(sdev->host);
-
-       return __ata_change_queue_depth(ap, sdev, queue_depth);
-}
+EXPORT_SYMBOL_GPL(ata_scsi_slave_destroy);
 
 /**
  *     ata_scsi_start_stop_xlat - Translate SCSI START STOP UNIT command
@@ -2354,10 +2063,6 @@ static unsigned int ata_scsiop_inq_83(struct ata_scsi_args *args, u8 *rbuf)
  */
 static unsigned int ata_scsiop_inq_89(struct ata_scsi_args *args, u8 *rbuf)
 {
-       struct ata_taskfile tf;
-
-       memset(&tf, 0, sizeof(tf));
-
        rbuf[1] = 0x89;                 /* our page code */
        rbuf[2] = (0x238 >> 8);         /* page size fixed at 238h */
        rbuf[3] = (0x238 & 0xff);
@@ -2366,14 +2071,14 @@ static unsigned int ata_scsiop_inq_89(struct ata_scsi_args *args, u8 *rbuf)
        memcpy(&rbuf[16], "libata          ", 16);
        memcpy(&rbuf[32], DRV_VERSION, 4);
 
-       /* we don't store the ATA device signature, so we fake it */
-
-       tf.command = ATA_DRDY;          /* really, this is Status reg */
-       tf.lbal = 0x1;
-       tf.nsect = 0x1;
-
-       ata_tf_to_fis(&tf, 0, 1, &rbuf[36]);    /* TODO: PMP? */
        rbuf[36] = 0x34;                /* force D2H Reg FIS (34h) */
+       rbuf[37] = (1 << 7);            /* bit 7 indicates Command FIS */
+                                       /* TODO: PMP? */
+
+       /* we don't store the ATA device signature, so we fake it */
+       rbuf[38] = ATA_DRDY;            /* really, this is Status reg */
+       rbuf[40] = 0x1;
+       rbuf[48] = 0x1;
 
        rbuf[56] = ATA_CMD_ID_ATA;
 
@@ -3089,7 +2794,7 @@ static struct ata_device *__ata_scsi_find_dev(struct ata_port *ap,
  *     RETURNS:
  *     Associated ATA device, or %NULL if not found.
  */
-static struct ata_device *
+struct ata_device *
 ata_scsi_find_dev(struct ata_port *ap, const struct scsi_device *scsidev)
 {
        struct ata_device *dev = __ata_scsi_find_dev(ap, scsidev);
@@ -4299,8 +4004,7 @@ static inline ata_xlat_func_t ata_get_xlat_func(struct ata_device *dev, u8 cmd)
  *     Prints the contents of a SCSI command via printk().
  */
 
-static inline void ata_scsi_dump_cdb(struct ata_port *ap,
-                                    struct scsi_cmnd *cmd)
+void ata_scsi_dump_cdb(struct ata_port *ap, struct scsi_cmnd *cmd)
 {
 #ifdef ATA_VERBOSE_DEBUG
        struct scsi_device *scsidev = cmd->device;
@@ -4312,8 +4016,7 @@ static inline void ata_scsi_dump_cdb(struct ata_port *ap,
 #endif
 }
 
-static inline int __ata_scsi_queuecmd(struct scsi_cmnd *scmd,
-                                     struct ata_device *dev)
+int __ata_scsi_queuecmd(struct scsi_cmnd *scmd, struct ata_device *dev)
 {
        u8 scsi_op = scmd->cmnd[0];
        ata_xlat_func_t xlat_func;
@@ -4407,6 +4110,7 @@ int ata_scsi_queuecmd(struct Scsi_Host *shost, struct scsi_cmnd *cmd)
 
        return rc;
 }
+EXPORT_SYMBOL_GPL(ata_scsi_queuecmd);
 
 /**
  *     ata_scsi_simulate - simulate SCSI command on ATA device
@@ -4562,26 +4266,51 @@ int ata_scsi_add_hosts(struct ata_host *host, struct scsi_host_template *sht)
                 */
                shost->max_host_blocked = 1;
 
-               rc = scsi_add_host_with_dma(ap->scsi_host,
-                                               &ap->tdev, ap->host->dev);
+               rc = scsi_add_host_with_dma(shost, &ap->tdev, ap->host->dev);
                if (rc)
-                       goto err_add;
+                       goto err_alloc;
        }
 
        return 0;
 
- err_add:
-       scsi_host_put(host->ports[i]->scsi_host);
  err_alloc:
        while (--i >= 0) {
                struct Scsi_Host *shost = host->ports[i]->scsi_host;
 
+               /* scsi_host_put() is in ata_devres_release() */
                scsi_remove_host(shost);
-               scsi_host_put(shost);
        }
        return rc;
 }
 
+#ifdef CONFIG_OF
+static void ata_scsi_assign_ofnode(struct ata_device *dev, struct ata_port *ap)
+{
+       struct scsi_device *sdev = dev->sdev;
+       struct device *d = ap->host->dev;
+       struct device_node *np = d->of_node;
+       struct device_node *child;
+
+       for_each_available_child_of_node(np, child) {
+               int ret;
+               u32 val;
+
+               ret = of_property_read_u32(child, "reg", &val);
+               if (ret)
+                       continue;
+               if (val == dev->devno) {
+                       dev_dbg(d, "found matching device node\n");
+                       sdev->sdev_gendev.of_node = child;
+                       return;
+               }
+       }
+}
+#else
+static void ata_scsi_assign_ofnode(struct ata_device *dev, struct ata_port *ap)
+{
+}
+#endif
+
 void ata_scsi_scan_host(struct ata_port *ap, int sync)
 {
        int tries = 5;
@@ -4607,6 +4336,7 @@ void ata_scsi_scan_host(struct ata_port *ap, int sync)
                                                 NULL);
                        if (!IS_ERR(sdev)) {
                                dev->sdev = sdev;
+                               ata_scsi_assign_ofnode(dev, ap);
                                scsi_device_put(sdev);
                        } else {
                                dev->sdev = NULL;
@@ -4929,214 +4659,3 @@ void ata_scsi_dev_rescan(struct work_struct *work)
        spin_unlock_irqrestore(ap->lock, flags);
        mutex_unlock(&ap->scsi_scan_mutex);
 }
-
-/**
- *     ata_sas_port_alloc - Allocate port for a SAS attached SATA device
- *     @host: ATA host container for all SAS ports
- *     @port_info: Information from low-level host driver
- *     @shost: SCSI host that the scsi device is attached to
- *
- *     LOCKING:
- *     PCI/etc. bus probe sem.
- *
- *     RETURNS:
- *     ata_port pointer on success / NULL on failure.
- */
-
-struct ata_port *ata_sas_port_alloc(struct ata_host *host,
-                                   struct ata_port_info *port_info,
-                                   struct Scsi_Host *shost)
-{
-       struct ata_port *ap;
-
-       ap = ata_port_alloc(host);
-       if (!ap)
-               return NULL;
-
-       ap->port_no = 0;
-       ap->lock = &host->lock;
-       ap->pio_mask = port_info->pio_mask;
-       ap->mwdma_mask = port_info->mwdma_mask;
-       ap->udma_mask = port_info->udma_mask;
-       ap->flags |= port_info->flags;
-       ap->ops = port_info->port_ops;
-       ap->cbl = ATA_CBL_SATA;
-
-       return ap;
-}
-EXPORT_SYMBOL_GPL(ata_sas_port_alloc);
-
-/**
- *     ata_sas_port_start - Set port up for dma.
- *     @ap: Port to initialize
- *
- *     Called just after data structures for each port are
- *     initialized.
- *
- *     May be used as the port_start() entry in ata_port_operations.
- *
- *     LOCKING:
- *     Inherited from caller.
- */
-int ata_sas_port_start(struct ata_port *ap)
-{
-       /*
-        * the port is marked as frozen at allocation time, but if we don't
-        * have new eh, we won't thaw it
-        */
-       if (!ap->ops->error_handler)
-               ap->pflags &= ~ATA_PFLAG_FROZEN;
-       return 0;
-}
-EXPORT_SYMBOL_GPL(ata_sas_port_start);
-
-/**
- *     ata_port_stop - Undo ata_sas_port_start()
- *     @ap: Port to shut down
- *
- *     May be used as the port_stop() entry in ata_port_operations.
- *
- *     LOCKING:
- *     Inherited from caller.
- */
-
-void ata_sas_port_stop(struct ata_port *ap)
-{
-}
-EXPORT_SYMBOL_GPL(ata_sas_port_stop);
-
-/**
- * ata_sas_async_probe - simply schedule probing and return
- * @ap: Port to probe
- *
- * For batch scheduling of probe for sas attached ata devices, assumes
- * the port has already been through ata_sas_port_init()
- */
-void ata_sas_async_probe(struct ata_port *ap)
-{
-       __ata_port_probe(ap);
-}
-EXPORT_SYMBOL_GPL(ata_sas_async_probe);
-
-int ata_sas_sync_probe(struct ata_port *ap)
-{
-       return ata_port_probe(ap);
-}
-EXPORT_SYMBOL_GPL(ata_sas_sync_probe);
-
-
-/**
- *     ata_sas_port_init - Initialize a SATA device
- *     @ap: SATA port to initialize
- *
- *     LOCKING:
- *     PCI/etc. bus probe sem.
- *
- *     RETURNS:
- *     Zero on success, non-zero on error.
- */
-
-int ata_sas_port_init(struct ata_port *ap)
-{
-       int rc = ap->ops->port_start(ap);
-
-       if (rc)
-               return rc;
-       ap->print_id = atomic_inc_return(&ata_print_id);
-       return 0;
-}
-EXPORT_SYMBOL_GPL(ata_sas_port_init);
-
-int ata_sas_tport_add(struct device *parent, struct ata_port *ap)
-{
-       return ata_tport_add(parent, ap);
-}
-EXPORT_SYMBOL_GPL(ata_sas_tport_add);
-
-void ata_sas_tport_delete(struct ata_port *ap)
-{
-       ata_tport_delete(ap);
-}
-EXPORT_SYMBOL_GPL(ata_sas_tport_delete);
-
-/**
- *     ata_sas_port_destroy - Destroy a SATA port allocated by ata_sas_port_alloc
- *     @ap: SATA port to destroy
- *
- */
-
-void ata_sas_port_destroy(struct ata_port *ap)
-{
-       if (ap->ops->port_stop)
-               ap->ops->port_stop(ap);
-       kfree(ap);
-}
-EXPORT_SYMBOL_GPL(ata_sas_port_destroy);
-
-/**
- *     ata_sas_slave_configure - Default slave_config routine for libata devices
- *     @sdev: SCSI device to configure
- *     @ap: ATA port to which SCSI device is attached
- *
- *     RETURNS:
- *     Zero.
- */
-
-int ata_sas_slave_configure(struct scsi_device *sdev, struct ata_port *ap)
-{
-       ata_scsi_sdev_config(sdev);
-       ata_scsi_dev_config(sdev, ap->link.device);
-       return 0;
-}
-EXPORT_SYMBOL_GPL(ata_sas_slave_configure);
-
-/**
- *     ata_sas_queuecmd - Issue SCSI cdb to libata-managed device
- *     @cmd: SCSI command to be sent
- *     @ap:    ATA port to which the command is being sent
- *
- *     RETURNS:
- *     Return value from __ata_scsi_queuecmd() if @cmd can be queued,
- *     0 otherwise.
- */
-
-int ata_sas_queuecmd(struct scsi_cmnd *cmd, struct ata_port *ap)
-{
-       int rc = 0;
-
-       ata_scsi_dump_cdb(ap, cmd);
-
-       if (likely(ata_dev_enabled(ap->link.device)))
-               rc = __ata_scsi_queuecmd(cmd, ap->link.device);
-       else {
-               cmd->result = (DID_BAD_TARGET << 16);
-               cmd->scsi_done(cmd);
-       }
-       return rc;
-}
-EXPORT_SYMBOL_GPL(ata_sas_queuecmd);
-
-int ata_sas_allocate_tag(struct ata_port *ap)
-{
-       unsigned int max_queue = ap->host->n_tags;
-       unsigned int i, tag;
-
-       for (i = 0, tag = ap->sas_last_tag + 1; i < max_queue; i++, tag++) {
-               tag = tag < max_queue ? tag : 0;
-
-               /* the last tag is reserved for internal command. */
-               if (ata_tag_internal(tag))
-                       continue;
-
-               if (!test_and_set_bit(tag, &ap->sas_tag_allocated)) {
-                       ap->sas_last_tag = tag;
-                       return tag;
-               }
-       }
-       return -1;
-}
-
-void ata_sas_free_tag(unsigned int tag, struct ata_port *ap)
-{
-       clear_bit(tag, &ap->sas_tag_allocated);
-}
index 038db94..ae7189d 100644 (file)
@@ -2,10 +2,6 @@
 /*
  *  libata-sff.c - helper library for PCI IDE BMDMA
  *
- *  Maintained by:  Tejun Heo <tj@kernel.org>
- *                 Please ALWAYS copy linux-ide@vger.kernel.org
- *                 on emails.
- *
  *  Copyright 2003-2006 Red Hat, Inc.  All rights reserved.
  *  Copyright 2003-2006 Jeff Garzik
  *
index 12a505b..6a40e3c 100644 (file)
@@ -208,7 +208,7 @@ show_ata_port_##name(struct device *dev,                            \
 {                                                                      \
        struct ata_port *ap = transport_class_to_port(dev);             \
                                                                        \
-       return snprintf(buf, 20, format_string, cast ap->field);        \
+       return scnprintf(buf, 20, format_string, cast ap->field);       \
 }
 
 #define ata_port_simple_attr(field, name, format_string, type)         \
@@ -479,7 +479,7 @@ show_ata_dev_##field(struct device *dev,                            \
 {                                                                      \
        struct ata_device *ata_dev = transport_class_to_dev(dev);       \
                                                                        \
-       return snprintf(buf, 20, format_string, cast ata_dev->field);   \
+       return scnprintf(buf, 20, format_string, cast ata_dev->field);  \
 }
 
 #define ata_dev_simple_attr(field, format_string, type)        \
@@ -533,7 +533,7 @@ show_ata_dev_id(struct device *dev,
        if (ata_dev->class == ATA_DEV_PMP)
                return 0;
        for(i=0;i<ATA_ID_WORDS;i++)  {
-               written += snprintf(buf+written, 20, "%04x%c",
+               written += scnprintf(buf+written, 20, "%04x%c",
                                    ata_dev->id[i],
                                    ((i+1) & 7) ? ' ' : '\n');
        }
@@ -552,7 +552,7 @@ show_ata_dev_gscr(struct device *dev,
        if (ata_dev->class != ATA_DEV_PMP)
                return 0;
        for(i=0;i<SATA_PMP_GSCR_DWORDS;i++)  {
-               written += snprintf(buf+written, 20, "%08x%c",
+               written += scnprintf(buf+written, 20, "%08x%c",
                                    ata_dev->gscr[i],
                                    ((i+1) & 3) ? ' ' : '\n');
        }
@@ -581,7 +581,7 @@ show_ata_dev_trim(struct device *dev,
        else
                mode = "unqueued";
 
-       return snprintf(buf, 20, "%s\n", mode);
+       return scnprintf(buf, 20, "%s\n", mode);
 }
 
 static DEVICE_ATTR(trim, S_IRUGO, show_ata_dev_trim, NULL);
index cd8090a..68cdd81 100644 (file)
@@ -37,7 +37,11 @@ extern int libata_noacpi;
 extern int libata_allow_tpm;
 extern const struct device_type ata_port_type;
 extern struct ata_link *ata_dev_phys_link(struct ata_device *dev);
+#ifdef CONFIG_ATA_FORCE
 extern void ata_force_cbl(struct ata_port *ap);
+#else
+static inline void ata_force_cbl(struct ata_port *ap) { }
+#endif
 extern u64 ata_tf_to_lba(const struct ata_taskfile *tf);
 extern u64 ata_tf_to_lba48(const struct ata_taskfile *tf);
 extern struct ata_queued_cmd *ata_qc_new_init(struct ata_device *dev, int tag);
@@ -87,6 +91,18 @@ extern unsigned int ata_read_log_page(struct ata_device *dev, u8 log,
 
 #define to_ata_port(d) container_of(d, struct ata_port, tdev)
 
+/* libata-sata.c */
+#ifdef CONFIG_SATA_HOST
+int ata_sas_allocate_tag(struct ata_port *ap);
+void ata_sas_free_tag(unsigned int tag, struct ata_port *ap);
+#else
+static inline int ata_sas_allocate_tag(struct ata_port *ap)
+{
+       return -EOPNOTSUPP;
+}
+static inline void ata_sas_free_tag(unsigned int tag, struct ata_port *ap) { }
+#endif
+
 /* libata-acpi.c */
 #ifdef CONFIG_ATA_ACPI
 extern unsigned int ata_acpi_gtf_filter;
@@ -112,6 +128,8 @@ static inline void ata_acpi_bind_dev(struct ata_device *dev) {}
 #endif
 
 /* libata-scsi.c */
+extern struct ata_device *ata_scsi_find_dev(struct ata_port *ap,
+                                           const struct scsi_device *scsidev);
 extern int ata_scsi_add_hosts(struct ata_host *host,
                              struct scsi_host_template *sht);
 extern void ata_scsi_scan_host(struct ata_port *ap, int sync);
@@ -128,9 +146,10 @@ extern void ata_scsi_dev_rescan(struct work_struct *work);
 extern int ata_bus_probe(struct ata_port *ap);
 extern int ata_scsi_user_scan(struct Scsi_Host *shost, unsigned int channel,
                              unsigned int id, u64 lun);
-int ata_sas_allocate_tag(struct ata_port *ap);
-void ata_sas_free_tag(unsigned int tag, struct ata_port *ap);
-
+void ata_scsi_sdev_config(struct scsi_device *sdev);
+int ata_scsi_dev_config(struct scsi_device *sdev, struct ata_device *dev);
+void ata_scsi_dump_cdb(struct ata_port *ap, struct scsi_cmnd *cmd);
+int __ata_scsi_queuecmd(struct scsi_cmnd *scmd, struct ata_device *dev);
 
 /* libata-eh.c */
 extern unsigned long ata_internal_cmd_timeout(struct ata_device *dev, u8 cmd);
index c451d7d..8729f78 100644 (file)
@@ -157,7 +157,6 @@ static int pdc_sata_hardreset(struct ata_link *link, unsigned int *class,
 static void pdc_error_handler(struct ata_port *ap);
 static void pdc_post_internal_cmd(struct ata_queued_cmd *qc);
 static int pdc_pata_cable_detect(struct ata_port *ap);
-static int pdc_sata_cable_detect(struct ata_port *ap);
 
 static struct scsi_host_template pdc_ata_sht = {
        ATA_BASE_SHT(DRV_NAME),
@@ -183,7 +182,7 @@ static const struct ata_port_operations pdc_common_ops = {
 
 static struct ata_port_operations pdc_sata_ops = {
        .inherits               = &pdc_common_ops,
-       .cable_detect           = pdc_sata_cable_detect,
+       .cable_detect           = ata_cable_sata,
        .freeze                 = pdc_sata_freeze,
        .thaw                   = pdc_sata_thaw,
        .scr_read               = pdc_sata_scr_read,
@@ -459,11 +458,6 @@ static int pdc_pata_cable_detect(struct ata_port *ap)
        return ATA_CBL_PATA80;
 }
 
-static int pdc_sata_cable_detect(struct ata_port *ap)
-{
-       return ATA_CBL_SATA;
-}
-
 static int pdc_sata_scr_read(struct ata_link *link,
                             unsigned int sc_reg, u32 *val)
 {
index a53cc1e..795facd 100644 (file)
@@ -6,6 +6,9 @@
 # Rewritten to use lists instead of if-statements.
 # 
 
+# needed for trace events
+ccflags-y                              += -I$(src)
+
 obj-$(CONFIG_MAC_FLOPPY)       += swim3.o
 obj-$(CONFIG_BLK_DEV_SWIM)     += swim_mod.o
 obj-$(CONFIG_BLK_DEV_FD)       += floppy.o
@@ -39,6 +42,9 @@ obj-$(CONFIG_ZRAM) += zram/
 
 obj-$(CONFIG_BLK_DEV_NULL_BLK) += null_blk.o
 null_blk-objs  := null_blk_main.o
+ifeq ($(CONFIG_BLK_DEV_ZONED), y)
+null_blk-$(CONFIG_TRACING) += null_blk_trace.o
+endif
 null_blk-$(CONFIG_BLK_DEV_ZONED) += null_blk_zoned.o
 
 skd-y          := skd_main.o
index 7b32fb6..a27804d 100644 (file)
@@ -87,9 +87,9 @@ static ssize_t aoedisk_show_netif(struct device *dev,
        if (*nd == NULL)
                return snprintf(page, PAGE_SIZE, "none\n");
        for (p = page; nd < ne; nd++)
-               p += snprintf(p, PAGE_SIZE - (p-page), "%s%s",
+               p += scnprintf(p, PAGE_SIZE - (p-page), "%s%s",
                        p == page ? "" : ",", (*nd)->name);
-       p += snprintf(p, PAGE_SIZE - (p-page), "\n");
+       p += scnprintf(p, PAGE_SIZE - (p-page), "\n");
        return p-page;
 }
 /* firmware version */
index 220c5e1..2fb25c3 100644 (file)
@@ -381,12 +381,10 @@ static struct brd_device *brd_alloc(int i)
        spin_lock_init(&brd->brd_lock);
        INIT_RADIX_TREE(&brd->brd_pages, GFP_ATOMIC);
 
-       brd->brd_queue = blk_alloc_queue(GFP_KERNEL);
+       brd->brd_queue = blk_alloc_queue(brd_make_request, NUMA_NO_NODE);
        if (!brd->brd_queue)
                goto out_free_dev;
 
-       blk_queue_make_request(brd->brd_queue, brd_make_request);
-
        /* This is so fdisk will align partitions on 4k, because of
         * direct_access API needing 4k alignment, returning a PFN
         * (This is only a problem on very small devices <= 4M,
index a18155c..c094c3c 100644 (file)
@@ -2801,7 +2801,7 @@ enum drbd_ret_code drbd_create_device(struct drbd_config_context *adm_ctx, unsig
 
        drbd_init_set_defaults(device);
 
-       q = blk_alloc_queue_node(GFP_KERNEL, NUMA_NO_NODE);
+       q = blk_alloc_queue(drbd_make_request, NUMA_NO_NODE);
        if (!q)
                goto out_no_q;
        device->rq_queue = q;
@@ -2828,7 +2828,6 @@ enum drbd_ret_code drbd_create_device(struct drbd_config_context *adm_ctx, unsig
        q->backing_dev_info->congested_fn = drbd_congested;
        q->backing_dev_info->congested_data = device;
 
-       blk_queue_make_request(q, drbd_make_request);
        blk_queue_write_cache(q, true, true);
        /* Setting the max_hw_sectors to an odd value of 8kibyte here
           This triggers a max_bio_size message upon first attach or connect */
@@ -3414,22 +3413,11 @@ int drbd_md_read(struct drbd_device *device, struct drbd_backing_dev *bdev)
  * the meta-data super block. This function sets MD_DIRTY, and starts a
  * timer that ensures that within five seconds you have to call drbd_md_sync().
  */
-#ifdef DEBUG
-void drbd_md_mark_dirty_(struct drbd_device *device, unsigned int line, const char *func)
-{
-       if (!test_and_set_bit(MD_DIRTY, &device->flags)) {
-               mod_timer(&device->md_sync_timer, jiffies + HZ);
-               device->last_md_mark_dirty.line = line;
-               device->last_md_mark_dirty.func = func;
-       }
-}
-#else
 void drbd_md_mark_dirty(struct drbd_device *device)
 {
        if (!test_and_set_bit(MD_DIRTY, &device->flags))
                mod_timer(&device->md_sync_timer, jiffies + 5*HZ);
 }
-#endif
 
 void drbd_uuid_move_history(struct drbd_device *device) __must_hold(local)
 {
index 79e2164..c15e708 100644 (file)
@@ -33,6 +33,7 @@
 #include <linux/random.h>
 #include <linux/string.h>
 #include <linux/scatterlist.h>
+#include <linux/part_stat.h>
 #include "drbd_int.h"
 #include "drbd_protocol.h"
 #include "drbd_req.h"
index b7f605c..0dc019d 100644 (file)
@@ -22,6 +22,7 @@
 #include <linux/random.h>
 #include <linux/string.h>
 #include <linux/scatterlist.h>
+#include <linux/part_stat.h>
 
 #include "drbd_int.h"
 #include "drbd_protocol.h"
index 8ef65c0..c3daa64 100644 (file)
@@ -171,7 +171,6 @@ static int print_unex = 1;
 #include <linux/kernel.h>
 #include <linux/timer.h>
 #include <linux/workqueue.h>
-#define FDPATCHES
 #include <linux/fdreg.h>
 #include <linux/fd.h>
 #include <linux/hdreg.h>
@@ -306,36 +305,26 @@ static bool initialized;
        /* reverse mapping from unit and fdc to drive */
 #define REVDRIVE(fdc, unit) ((unit) + ((fdc) << 2))
 
-#define DP     (&drive_params[current_drive])
-#define DRS    (&drive_state[current_drive])
-#define DRWE   (&write_errors[current_drive])
-#define FDCS   (&fdc_state[fdc])
-
-#define UDP    (&drive_params[drive])
-#define UDRS   (&drive_state[drive])
-#define UDRWE  (&write_errors[drive])
-#define UFDCS  (&fdc_state[FDC(drive)])
-
 #define PH_HEAD(floppy, head) (((((floppy)->stretch & 2) >> 1) ^ head) << 2)
 #define STRETCH(floppy)        ((floppy)->stretch & FD_STRETCH)
 
-/* read/write */
-#define COMMAND                (raw_cmd->cmd[0])
-#define DR_SELECT      (raw_cmd->cmd[1])
-#define TRACK          (raw_cmd->cmd[2])
-#define HEAD           (raw_cmd->cmd[3])
-#define SECTOR         (raw_cmd->cmd[4])
-#define SIZECODE       (raw_cmd->cmd[5])
-#define SECT_PER_TRACK (raw_cmd->cmd[6])
-#define GAP            (raw_cmd->cmd[7])
-#define SIZECODE2      (raw_cmd->cmd[8])
+/* read/write commands */
+#define COMMAND                        0
+#define DR_SELECT              1
+#define TRACK                  2
+#define HEAD                   3
+#define SECTOR                 4
+#define SIZECODE               5
+#define SECT_PER_TRACK         6
+#define GAP                    7
+#define SIZECODE2              8
 #define NR_RW 9
 
-/* format */
-#define F_SIZECODE     (raw_cmd->cmd[2])
-#define F_SECT_PER_TRACK (raw_cmd->cmd[3])
-#define F_GAP          (raw_cmd->cmd[4])
-#define F_FILL         (raw_cmd->cmd[5])
+/* format commands */
+#define F_SIZECODE             2
+#define F_SECT_PER_TRACK       3
+#define F_GAP                  4
+#define F_FILL                 5
 #define NR_F 6
 
 /*
@@ -351,14 +340,14 @@ static bool initialized;
 #define MAX_REPLIES 16
 static unsigned char reply_buffer[MAX_REPLIES];
 static int inr;                /* size of reply buffer, when called from interrupt */
-#define ST0            (reply_buffer[0])
-#define ST1            (reply_buffer[1])
-#define ST2            (reply_buffer[2])
-#define ST3            (reply_buffer[0])       /* result of GETSTATUS */
-#define R_TRACK                (reply_buffer[3])
-#define R_HEAD         (reply_buffer[4])
-#define R_SECTOR       (reply_buffer[5])
-#define R_SIZECODE     (reply_buffer[6])
+#define ST0            0
+#define ST1            1
+#define ST2            2
+#define ST3            0       /* result of GETSTATUS */
+#define R_TRACK                3
+#define R_HEAD         4
+#define R_SECTOR       5
+#define R_SIZECODE     6
 
 #define SEL_DLY                (2 * HZ / 100)
 
@@ -593,7 +582,7 @@ static int buffer_max = -1;
 
 /* fdc related variables, should end up in a struct */
 static struct floppy_fdc_state fdc_state[N_FDC];
-static int fdc;                        /* current fdc */
+static int current_fdc;                        /* current fdc */
 
 static struct workqueue_struct *floppy_wq;
 
@@ -604,9 +593,19 @@ static unsigned char fsector_t;    /* sector in track */
 static unsigned char in_sector_offset; /* offset within physical sector,
                                         * expressed in units of 512 bytes */
 
+static inline unsigned char fdc_inb(int fdc, int reg)
+{
+       return fd_inb(fdc_state[fdc].address + reg);
+}
+
+static inline void fdc_outb(unsigned char value, int fdc, int reg)
+{
+       fd_outb(value, fdc_state[fdc].address + reg);
+}
+
 static inline bool drive_no_geom(int drive)
 {
-       return !current_type[drive] && !ITYPE(UDRS->fd_device);
+       return !current_type[drive] && !ITYPE(drive_state[drive].fd_device);
 }
 
 #ifndef fd_eject
@@ -630,7 +629,7 @@ static inline void set_debugt(void)
 
 static inline void debugt(const char *func, const char *msg)
 {
-       if (DP->flags & DEBUGT)
+       if (drive_params[current_drive].flags & DEBUGT)
                pr_info("%s:%s dtime=%lu\n", func, msg, jiffies - debugtimer);
 }
 #else
@@ -683,10 +682,10 @@ static void __reschedule_timeout(int drive, const char *message)
                delay = 20UL * HZ;
                drive = 0;
        } else
-               delay = UDP->timeout;
+               delay = drive_params[drive].timeout;
 
        mod_delayed_work(floppy_wq, &fd_timeout, delay);
-       if (UDP->flags & FD_DEBUG)
+       if (drive_params[drive].flags & FD_DEBUG)
                DPRINT("reschedule timeout %s\n", message);
        timeout_message = message;
 }
@@ -740,33 +739,37 @@ static int disk_change(int drive)
 {
        int fdc = FDC(drive);
 
-       if (time_before(jiffies, UDRS->select_date + UDP->select_delay))
+       if (time_before(jiffies, drive_state[drive].select_date + drive_params[drive].select_delay))
                DPRINT("WARNING disk change called early\n");
-       if (!(FDCS->dor & (0x10 << UNIT(drive))) ||
-           (FDCS->dor & 3) != UNIT(drive) || fdc != FDC(drive)) {
+       if (!(fdc_state[fdc].dor & (0x10 << UNIT(drive))) ||
+           (fdc_state[fdc].dor & 3) != UNIT(drive) || fdc != FDC(drive)) {
                DPRINT("probing disk change on unselected drive\n");
                DPRINT("drive=%d fdc=%d dor=%x\n", drive, FDC(drive),
-                      (unsigned int)FDCS->dor);
+                      (unsigned int)fdc_state[fdc].dor);
        }
 
-       debug_dcl(UDP->flags,
+       debug_dcl(drive_params[drive].flags,
                  "checking disk change line for drive %d\n", drive);
-       debug_dcl(UDP->flags, "jiffies=%lu\n", jiffies);
-       debug_dcl(UDP->flags, "disk change line=%x\n", fd_inb(FD_DIR) & 0x80);
-       debug_dcl(UDP->flags, "flags=%lx\n", UDRS->flags);
-
-       if (UDP->flags & FD_BROKEN_DCL)
-               return test_bit(FD_DISK_CHANGED_BIT, &UDRS->flags);
-       if ((fd_inb(FD_DIR) ^ UDP->flags) & 0x80) {
-               set_bit(FD_VERIFY_BIT, &UDRS->flags);
+       debug_dcl(drive_params[drive].flags, "jiffies=%lu\n", jiffies);
+       debug_dcl(drive_params[drive].flags, "disk change line=%x\n",
+                 fdc_inb(fdc, FD_DIR) & 0x80);
+       debug_dcl(drive_params[drive].flags, "flags=%lx\n",
+                 drive_state[drive].flags);
+
+       if (drive_params[drive].flags & FD_BROKEN_DCL)
+               return test_bit(FD_DISK_CHANGED_BIT,
+                               &drive_state[drive].flags);
+       if ((fdc_inb(fdc, FD_DIR) ^ drive_params[drive].flags) & 0x80) {
+               set_bit(FD_VERIFY_BIT, &drive_state[drive].flags);
                                        /* verify write protection */
 
-               if (UDRS->maxblock)     /* mark it changed */
-                       set_bit(FD_DISK_CHANGED_BIT, &UDRS->flags);
+               if (drive_state[drive].maxblock)        /* mark it changed */
+                       set_bit(FD_DISK_CHANGED_BIT,
+                               &drive_state[drive].flags);
 
                /* invalidate its geometry */
-               if (UDRS->keep_data >= 0) {
-                       if ((UDP->flags & FTD_MSG) &&
+               if (drive_state[drive].keep_data >= 0) {
+                       if ((drive_params[drive].flags & FTD_MSG) &&
                            current_type[drive] != NULL)
                                DPRINT("Disk type is undefined after disk change\n");
                        current_type[drive] = NULL;
@@ -775,8 +778,8 @@ static int disk_change(int drive)
 
                return 1;
        } else {
-               UDRS->last_checked = jiffies;
-               clear_bit(FD_DISK_NEWCHANGE_BIT, &UDRS->flags);
+               drive_state[drive].last_checked = jiffies;
+               clear_bit(FD_DISK_NEWCHANGE_BIT, &drive_state[drive].flags);
        }
        return 0;
 }
@@ -799,26 +802,26 @@ static int set_dor(int fdc, char mask, char data)
        unsigned char newdor;
        unsigned char olddor;
 
-       if (FDCS->address == -1)
+       if (fdc_state[fdc].address == -1)
                return -1;
 
-       olddor = FDCS->dor;
+       olddor = fdc_state[fdc].dor;
        newdor = (olddor & mask) | data;
        if (newdor != olddor) {
                unit = olddor & 0x3;
                if (is_selected(olddor, unit) && !is_selected(newdor, unit)) {
                        drive = REVDRIVE(fdc, unit);
-                       debug_dcl(UDP->flags,
+                       debug_dcl(drive_params[drive].flags,
                                  "calling disk change from set_dor\n");
                        disk_change(drive);
                }
-               FDCS->dor = newdor;
-               fd_outb(newdor, FD_DOR);
+               fdc_state[fdc].dor = newdor;
+               fdc_outb(newdor, fdc, FD_DOR);
 
                unit = newdor & 0x3;
                if (!is_selected(olddor, unit) && is_selected(newdor, unit)) {
                        drive = REVDRIVE(fdc, unit);
-                       UDRS->select_date = jiffies;
+                       drive_state[drive].select_date = jiffies;
                }
        }
        return olddor;
@@ -826,11 +829,12 @@ static int set_dor(int fdc, char mask, char data)
 
 static void twaddle(void)
 {
-       if (DP->select_delay)
+       if (drive_params[current_drive].select_delay)
                return;
-       fd_outb(FDCS->dor & ~(0x10 << UNIT(current_drive)), FD_DOR);
-       fd_outb(FDCS->dor, FD_DOR);
-       DRS->select_date = jiffies;
+       fdc_outb(fdc_state[current_fdc].dor & ~(0x10 << UNIT(current_drive)),
+                current_fdc, FD_DOR);
+       fdc_outb(fdc_state[current_fdc].dor, current_fdc, FD_DOR);
+       drive_state[current_drive].select_date = jiffies;
 }
 
 /*
@@ -841,19 +845,20 @@ static void reset_fdc_info(int mode)
 {
        int drive;
 
-       FDCS->spec1 = FDCS->spec2 = -1;
-       FDCS->need_configure = 1;
-       FDCS->perp_mode = 1;
-       FDCS->rawcmd = 0;
+       fdc_state[current_fdc].spec1 = fdc_state[current_fdc].spec2 = -1;
+       fdc_state[current_fdc].need_configure = 1;
+       fdc_state[current_fdc].perp_mode = 1;
+       fdc_state[current_fdc].rawcmd = 0;
        for (drive = 0; drive < N_DRIVE; drive++)
-               if (FDC(drive) == fdc && (mode || UDRS->track != NEED_1_RECAL))
-                       UDRS->track = NEED_2_RECAL;
+               if (FDC(drive) == current_fdc &&
+                   (mode || drive_state[drive].track != NEED_1_RECAL))
+                       drive_state[drive].track = NEED_2_RECAL;
 }
 
 /* selects the fdc and drive, and enables the fdc's input/dma. */
 static void set_fdc(int drive)
 {
-       unsigned int new_fdc = fdc;
+       unsigned int new_fdc = current_fdc;
 
        if (drive >= 0 && drive < N_DRIVE) {
                new_fdc = FDC(drive);
@@ -863,15 +868,15 @@ static void set_fdc(int drive)
                pr_info("bad fdc value\n");
                return;
        }
-       fdc = new_fdc;
-       set_dor(fdc, ~0, 8);
+       current_fdc = new_fdc;
+       set_dor(current_fdc, ~0, 8);
 #if N_FDC > 1
-       set_dor(1 - fdc, ~8, 0);
+       set_dor(1 - current_fdc, ~8, 0);
 #endif
-       if (FDCS->rawcmd == 2)
+       if (fdc_state[current_fdc].rawcmd == 2)
                reset_fdc_info(1);
-       if (fd_inb(FD_STATUS) != STATUS_READY)
-               FDCS->reset = 1;
+       if (fdc_inb(current_fdc, FD_STATUS) != STATUS_READY)
+               fdc_state[current_fdc].reset = 1;
 }
 
 /* locks the driver */
@@ -924,19 +929,19 @@ static void floppy_off(unsigned int drive)
        unsigned long volatile delta;
        int fdc = FDC(drive);
 
-       if (!(FDCS->dor & (0x10 << UNIT(drive))))
+       if (!(fdc_state[fdc].dor & (0x10 << UNIT(drive))))
                return;
 
        del_timer(motor_off_timer + drive);
 
        /* make spindle stop in a position which minimizes spinup time
         * next time */
-       if (UDP->rps) {
-               delta = jiffies - UDRS->first_read_date + HZ -
-                   UDP->spindown_offset;
-               delta = ((delta * UDP->rps) % HZ) / UDP->rps;
+       if (drive_params[drive].rps) {
+               delta = jiffies - drive_state[drive].first_read_date + HZ -
+                   drive_params[drive].spindown_offset;
+               delta = ((delta * drive_params[drive].rps) % HZ) / drive_params[drive].rps;
                motor_off_timer[drive].expires =
-                   jiffies + UDP->spindown - delta;
+                   jiffies + drive_params[drive].spindown - delta;
        }
        add_timer(motor_off_timer + drive);
 }
@@ -952,20 +957,20 @@ static void scandrives(void)
        int drive;
        int saved_drive;
 
-       if (DP->select_delay)
+       if (drive_params[current_drive].select_delay)
                return;
 
        saved_drive = current_drive;
        for (i = 0; i < N_DRIVE; i++) {
                drive = (saved_drive + i + 1) % N_DRIVE;
-               if (UDRS->fd_ref == 0 || UDP->select_delay != 0)
+               if (drive_state[drive].fd_ref == 0 || drive_params[drive].select_delay != 0)
                        continue;       /* skip closed drives */
                set_fdc(drive);
-               if (!(set_dor(fdc, ~3, UNIT(drive) | (0x10 << UNIT(drive))) &
+               if (!(set_dor(current_fdc, ~3, UNIT(drive) | (0x10 << UNIT(drive))) &
                      (0x10 << UNIT(drive))))
                        /* switch the motor off again, if it was off to
                         * begin with */
-                       set_dor(fdc, ~(0x10 << UNIT(drive)), 0);
+                       set_dor(current_fdc, ~(0x10 << UNIT(drive)), 0);
        }
        set_fdc(saved_drive);
 }
@@ -1011,7 +1016,8 @@ static void cancel_activity(void)
  * transfer */
 static void fd_watchdog(void)
 {
-       debug_dcl(DP->flags, "calling disk change from watchdog\n");
+       debug_dcl(drive_params[current_drive].flags,
+                 "calling disk change from watchdog\n");
 
        if (disk_change(current_drive)) {
                DPRINT("disk removed during i/o\n");
@@ -1035,7 +1041,7 @@ static void main_command_interrupt(void)
 static int fd_wait_for_completion(unsigned long expires,
                                  void (*function)(void))
 {
-       if (FDCS->reset) {
+       if (fdc_state[current_fdc].reset) {
                reset_fdc();    /* do the reset during sleep to win time
                                 * if we don't need to sleep, it's a good
                                 * occasion anyways */
@@ -1063,13 +1069,13 @@ static void setup_DMA(void)
                        pr_cont("%x,", raw_cmd->cmd[i]);
                pr_cont("\n");
                cont->done(0);
-               FDCS->reset = 1;
+               fdc_state[current_fdc].reset = 1;
                return;
        }
        if (((unsigned long)raw_cmd->kernel_data) % 512) {
                pr_info("non aligned address: %p\n", raw_cmd->kernel_data);
                cont->done(0);
-               FDCS->reset = 1;
+               fdc_state[current_fdc].reset = 1;
                return;
        }
        f = claim_dma_lock();
@@ -1077,10 +1083,11 @@ static void setup_DMA(void)
 #ifdef fd_dma_setup
        if (fd_dma_setup(raw_cmd->kernel_data, raw_cmd->length,
                         (raw_cmd->flags & FD_RAW_READ) ?
-                        DMA_MODE_READ : DMA_MODE_WRITE, FDCS->address) < 0) {
+                        DMA_MODE_READ : DMA_MODE_WRITE,
+                        fdc_state[current_fdc].address) < 0) {
                release_dma_lock(f);
                cont->done(0);
-               FDCS->reset = 1;
+               fdc_state[current_fdc].reset = 1;
                return;
        }
        release_dma_lock(f);
@@ -1091,7 +1098,7 @@ static void setup_DMA(void)
                        DMA_MODE_READ : DMA_MODE_WRITE);
        fd_set_dma_addr(raw_cmd->kernel_data);
        fd_set_dma_count(raw_cmd->length);
-       virtual_dma_port = FDCS->address;
+       virtual_dma_port = fdc_state[current_fdc].address;
        fd_enable_dma();
        release_dma_lock(f);
 #endif
@@ -1105,18 +1112,18 @@ static int wait_til_ready(void)
        int status;
        int counter;
 
-       if (FDCS->reset)
+       if (fdc_state[current_fdc].reset)
                return -1;
        for (counter = 0; counter < 10000; counter++) {
-               status = fd_inb(FD_STATUS);
+               status = fdc_inb(current_fdc, FD_STATUS);
                if (status & STATUS_READY)
                        return status;
        }
        if (initialized) {
-               DPRINT("Getstatus times out (%x) on fdc %d\n", status, fdc);
+               DPRINT("Getstatus times out (%x) on fdc %d\n", status, current_fdc);
                show_floppy();
        }
-       FDCS->reset = 1;
+       fdc_state[current_fdc].reset = 1;
        return -1;
 }
 
@@ -1129,17 +1136,17 @@ static int output_byte(char byte)
                return -1;
 
        if (is_ready_state(status)) {
-               fd_outb(byte, FD_DATA);
+               fdc_outb(byte, current_fdc, FD_DATA);
                output_log[output_log_pos].data = byte;
                output_log[output_log_pos].status = status;
                output_log[output_log_pos].jiffies = jiffies;
                output_log_pos = (output_log_pos + 1) % OLOGSIZE;
                return 0;
        }
-       FDCS->reset = 1;
+       fdc_state[current_fdc].reset = 1;
        if (initialized) {
                DPRINT("Unable to send byte %x to FDC. Fdc=%x Status=%x\n",
-                      byte, fdc, status);
+                      byte, current_fdc, status);
                show_floppy();
        }
        return -1;
@@ -1162,16 +1169,16 @@ static int result(void)
                        return i;
                }
                if (status == (STATUS_DIR | STATUS_READY | STATUS_BUSY))
-                       reply_buffer[i] = fd_inb(FD_DATA);
+                       reply_buffer[i] = fdc_inb(current_fdc, FD_DATA);
                else
                        break;
        }
        if (initialized) {
                DPRINT("get result error. Fdc=%d Last status=%x Read bytes=%d\n",
-                      fdc, status, i);
+                      current_fdc, status, i);
                show_floppy();
        }
-       FDCS->reset = 1;
+       fdc_state[current_fdc].reset = 1;
        return -1;
 }
 
@@ -1208,7 +1215,7 @@ static void perpendicular_mode(void)
                default:
                        DPRINT("Invalid data rate for perpendicular mode!\n");
                        cont->done(0);
-                       FDCS->reset = 1;
+                       fdc_state[current_fdc].reset = 1;
                                        /*
                                         * convenient way to return to
                                         * redo without too much hassle
@@ -1219,12 +1226,12 @@ static void perpendicular_mode(void)
        } else
                perp_mode = 0;
 
-       if (FDCS->perp_mode == perp_mode)
+       if (fdc_state[current_fdc].perp_mode == perp_mode)
                return;
-       if (FDCS->version >= FDC_82077_ORIG) {
+       if (fdc_state[current_fdc].version >= FDC_82077_ORIG) {
                output_byte(FD_PERPENDICULAR);
                output_byte(perp_mode);
-               FDCS->perp_mode = perp_mode;
+               fdc_state[current_fdc].perp_mode = perp_mode;
        } else if (perp_mode) {
                DPRINT("perpendicular mode not supported by this FDC.\n");
        }
@@ -1279,9 +1286,10 @@ static void fdc_specify(void)
        int hlt_max_code = 0x7f;
        int hut_max_code = 0xf;
 
-       if (FDCS->need_configure && FDCS->version >= FDC_82072A) {
+       if (fdc_state[current_fdc].need_configure &&
+           fdc_state[current_fdc].version >= FDC_82072A) {
                fdc_configure();
-               FDCS->need_configure = 0;
+               fdc_state[current_fdc].need_configure = 0;
        }
 
        switch (raw_cmd->rate & 0x03) {
@@ -1290,7 +1298,7 @@ static void fdc_specify(void)
                break;
        case 1:
                dtr = 300;
-               if (FDCS->version >= FDC_82078) {
+               if (fdc_state[current_fdc].version >= FDC_82078) {
                        /* chose the default rate table, not the one
                         * where 1 = 2 Mbps */
                        output_byte(FD_DRIVESPEC);
@@ -1305,27 +1313,30 @@ static void fdc_specify(void)
                break;
        }
 
-       if (FDCS->version >= FDC_82072) {
+       if (fdc_state[current_fdc].version >= FDC_82072) {
                scale_dtr = dtr;
                hlt_max_code = 0x00;    /* 0==256msec*dtr0/dtr (not linear!) */
                hut_max_code = 0x0;     /* 0==256msec*dtr0/dtr (not linear!) */
        }
 
        /* Convert step rate from microseconds to milliseconds and 4 bits */
-       srt = 16 - DIV_ROUND_UP(DP->srt * scale_dtr / 1000, NOMINAL_DTR);
+       srt = 16 - DIV_ROUND_UP(drive_params[current_drive].srt * scale_dtr / 1000,
+                               NOMINAL_DTR);
        if (slow_floppy)
                srt = srt / 4;
 
        SUPBOUND(srt, 0xf);
        INFBOUND(srt, 0);
 
-       hlt = DIV_ROUND_UP(DP->hlt * scale_dtr / 2, NOMINAL_DTR);
+       hlt = DIV_ROUND_UP(drive_params[current_drive].hlt * scale_dtr / 2,
+                          NOMINAL_DTR);
        if (hlt < 0x01)
                hlt = 0x01;
        else if (hlt > 0x7f)
                hlt = hlt_max_code;
 
-       hut = DIV_ROUND_UP(DP->hut * scale_dtr / 16, NOMINAL_DTR);
+       hut = DIV_ROUND_UP(drive_params[current_drive].hut * scale_dtr / 16,
+                          NOMINAL_DTR);
        if (hut < 0x1)
                hut = 0x1;
        else if (hut > 0xf)
@@ -1335,11 +1346,12 @@ static void fdc_specify(void)
        spec2 = (hlt << 1) | (use_virtual_dma & 1);
 
        /* If these parameters did not change, just return with success */
-       if (FDCS->spec1 != spec1 || FDCS->spec2 != spec2) {
+       if (fdc_state[current_fdc].spec1 != spec1 ||
+           fdc_state[current_fdc].spec2 != spec2) {
                /* Go ahead and set spec1 and spec2 */
                output_byte(FD_SPECIFY);
-               output_byte(FDCS->spec1 = spec1);
-               output_byte(FDCS->spec2 = spec2);
+               output_byte(fdc_state[current_fdc].spec1 = spec1);
+               output_byte(fdc_state[current_fdc].spec2 = spec2);
        }
 }                              /* fdc_specify */
 
@@ -1350,52 +1362,55 @@ static void fdc_specify(void)
 static int fdc_dtr(void)
 {
        /* If data rate not already set to desired value, set it. */
-       if ((raw_cmd->rate & 3) == FDCS->dtr)
+       if ((raw_cmd->rate & 3) == fdc_state[current_fdc].dtr)
                return 0;
 
        /* Set dtr */
-       fd_outb(raw_cmd->rate & 3, FD_DCR);
+       fdc_outb(raw_cmd->rate & 3, current_fdc, FD_DCR);
 
        /* TODO: some FDC/drive combinations (C&T 82C711 with TEAC 1.2MB)
         * need a stabilization period of several milliseconds to be
         * enforced after data rate changes before R/W operations.
         * Pause 5 msec to avoid trouble. (Needs to be 2 jiffies)
         */
-       FDCS->dtr = raw_cmd->rate & 3;
+       fdc_state[current_fdc].dtr = raw_cmd->rate & 3;
        return fd_wait_for_completion(jiffies + 2UL * HZ / 100, floppy_ready);
 }                              /* fdc_dtr */
 
 static void tell_sector(void)
 {
        pr_cont(": track %d, head %d, sector %d, size %d",
-               R_TRACK, R_HEAD, R_SECTOR, R_SIZECODE);
+               reply_buffer[R_TRACK], reply_buffer[R_HEAD],
+               reply_buffer[R_SECTOR],
+               reply_buffer[R_SIZECODE]);
 }                              /* tell_sector */
 
 static void print_errors(void)
 {
        DPRINT("");
-       if (ST0 & ST0_ECE) {
+       if (reply_buffer[ST0] & ST0_ECE) {
                pr_cont("Recalibrate failed!");
-       } else if (ST2 & ST2_CRC) {
+       } else if (reply_buffer[ST2] & ST2_CRC) {
                pr_cont("data CRC error");
                tell_sector();
-       } else if (ST1 & ST1_CRC) {
+       } else if (reply_buffer[ST1] & ST1_CRC) {
                pr_cont("CRC error");
                tell_sector();
-       } else if ((ST1 & (ST1_MAM | ST1_ND)) ||
-                  (ST2 & ST2_MAM)) {
+       } else if ((reply_buffer[ST1] & (ST1_MAM | ST1_ND)) ||
+                  (reply_buffer[ST2] & ST2_MAM)) {
                if (!probing) {
                        pr_cont("sector not found");
                        tell_sector();
                } else
                        pr_cont("probe failed...");
-       } else if (ST2 & ST2_WC) {      /* seek error */
+       } else if (reply_buffer[ST2] & ST2_WC) {        /* seek error */
                pr_cont("wrong cylinder");
-       } else if (ST2 & ST2_BC) {      /* cylinder marked as bad */
+       } else if (reply_buffer[ST2] & ST2_BC) {        /* cylinder marked as bad */
                pr_cont("bad cylinder");
        } else {
                pr_cont("unknown error. ST[0..2] are: 0x%x 0x%x 0x%x",
-                       ST0, ST1, ST2);
+                       reply_buffer[ST0], reply_buffer[ST1],
+                       reply_buffer[ST2]);
                tell_sector();
        }
        pr_cont("\n");
@@ -1414,33 +1429,35 @@ static int interpret_errors(void)
 
        if (inr != 7) {
                DPRINT("-- FDC reply error\n");
-               FDCS->reset = 1;
+               fdc_state[current_fdc].reset = 1;
                return 1;
        }
 
        /* check IC to find cause of interrupt */
-       switch (ST0 & ST0_INTR) {
+       switch (reply_buffer[ST0] & ST0_INTR) {
        case 0x40:              /* error occurred during command execution */
-               if (ST1 & ST1_EOC)
+               if (reply_buffer[ST1] & ST1_EOC)
                        return 0;       /* occurs with pseudo-DMA */
                bad = 1;
-               if (ST1 & ST1_WP) {
+               if (reply_buffer[ST1] & ST1_WP) {
                        DPRINT("Drive is write protected\n");
-                       clear_bit(FD_DISK_WRITABLE_BIT, &DRS->flags);
+                       clear_bit(FD_DISK_WRITABLE_BIT,
+                                 &drive_state[current_drive].flags);
                        cont->done(0);
                        bad = 2;
-               } else if (ST1 & ST1_ND) {
-                       set_bit(FD_NEED_TWADDLE_BIT, &DRS->flags);
-               } else if (ST1 & ST1_OR) {
-                       if (DP->flags & FTD_MSG)
+               } else if (reply_buffer[ST1] & ST1_ND) {
+                       set_bit(FD_NEED_TWADDLE_BIT,
+                               &drive_state[current_drive].flags);
+               } else if (reply_buffer[ST1] & ST1_OR) {
+                       if (drive_params[current_drive].flags & FTD_MSG)
                                DPRINT("Over/Underrun - retrying\n");
                        bad = 0;
-               } else if (*errors >= DP->max_errors.reporting) {
+               } else if (*errors >= drive_params[current_drive].max_errors.reporting) {
                        print_errors();
                }
-               if (ST2 & ST2_WC || ST2 & ST2_BC)
+               if (reply_buffer[ST2] & ST2_WC || reply_buffer[ST2] & ST2_BC)
                        /* wrong cylinder => recal */
-                       DRS->track = NEED_2_RECAL;
+                       drive_state[current_drive].track = NEED_2_RECAL;
                return bad;
        case 0x80:              /* invalid command given */
                DPRINT("Invalid FDC command given!\n");
@@ -1473,13 +1490,13 @@ static void setup_rw_floppy(void)
                flags |= FD_RAW_INTR;
 
        if ((flags & FD_RAW_SPIN) && !(flags & FD_RAW_NO_MOTOR)) {
-               ready_date = DRS->spinup_date + DP->spinup;
+               ready_date = drive_state[current_drive].spinup_date + drive_params[current_drive].spinup;
                /* If spinup will take a long time, rerun scandrives
                 * again just before spinup completion. Beware that
                 * after scandrives, we must again wait for selection.
                 */
-               if (time_after(ready_date, jiffies + DP->select_delay)) {
-                       ready_date -= DP->select_delay;
+               if (time_after(ready_date, jiffies + drive_params[current_drive].select_delay)) {
+                       ready_date -= drive_params[current_drive].select_delay;
                        function = floppy_start;
                } else
                        function = setup_rw_floppy;
@@ -1522,44 +1539,52 @@ static int blind_seek;
 static void seek_interrupt(void)
 {
        debugt(__func__, "");
-       if (inr != 2 || (ST0 & 0xF8) != 0x20) {
+       if (inr != 2 || (reply_buffer[ST0] & 0xF8) != 0x20) {
                DPRINT("seek failed\n");
-               DRS->track = NEED_2_RECAL;
+               drive_state[current_drive].track = NEED_2_RECAL;
                cont->error();
                cont->redo();
                return;
        }
-       if (DRS->track >= 0 && DRS->track != ST1 && !blind_seek) {
-               debug_dcl(DP->flags,
+       if (drive_state[current_drive].track >= 0 &&
+           drive_state[current_drive].track != reply_buffer[ST1] &&
+           !blind_seek) {
+               debug_dcl(drive_params[current_drive].flags,
                          "clearing NEWCHANGE flag because of effective seek\n");
-               debug_dcl(DP->flags, "jiffies=%lu\n", jiffies);
-               clear_bit(FD_DISK_NEWCHANGE_BIT, &DRS->flags);
+               debug_dcl(drive_params[current_drive].flags, "jiffies=%lu\n",
+                         jiffies);
+               clear_bit(FD_DISK_NEWCHANGE_BIT,
+                         &drive_state[current_drive].flags);
                                        /* effective seek */
-               DRS->select_date = jiffies;
+               drive_state[current_drive].select_date = jiffies;
        }
-       DRS->track = ST1;
+       drive_state[current_drive].track = reply_buffer[ST1];
        floppy_ready();
 }
 
 static void check_wp(void)
 {
-       if (test_bit(FD_VERIFY_BIT, &DRS->flags)) {
+       if (test_bit(FD_VERIFY_BIT, &drive_state[current_drive].flags)) {
                                        /* check write protection */
                output_byte(FD_GETSTATUS);
                output_byte(UNIT(current_drive));
                if (result() != 1) {
-                       FDCS->reset = 1;
+                       fdc_state[current_fdc].reset = 1;
                        return;
                }
-               clear_bit(FD_VERIFY_BIT, &DRS->flags);
-               clear_bit(FD_NEED_TWADDLE_BIT, &DRS->flags);
-               debug_dcl(DP->flags,
+               clear_bit(FD_VERIFY_BIT, &drive_state[current_drive].flags);
+               clear_bit(FD_NEED_TWADDLE_BIT,
+                         &drive_state[current_drive].flags);
+               debug_dcl(drive_params[current_drive].flags,
                          "checking whether disk is write protected\n");
-               debug_dcl(DP->flags, "wp=%x\n", ST3 & 0x40);
-               if (!(ST3 & 0x40))
-                       set_bit(FD_DISK_WRITABLE_BIT, &DRS->flags);
+               debug_dcl(drive_params[current_drive].flags, "wp=%x\n",
+                         reply_buffer[ST3] & 0x40);
+               if (!(reply_buffer[ST3] & 0x40))
+                       set_bit(FD_DISK_WRITABLE_BIT,
+                               &drive_state[current_drive].flags);
                else
-                       clear_bit(FD_DISK_WRITABLE_BIT, &DRS->flags);
+                       clear_bit(FD_DISK_WRITABLE_BIT,
+                                 &drive_state[current_drive].flags);
        }
 }
 
@@ -1569,32 +1594,34 @@ static void seek_floppy(void)
 
        blind_seek = 0;
 
-       debug_dcl(DP->flags, "calling disk change from %s\n", __func__);
+       debug_dcl(drive_params[current_drive].flags,
+                 "calling disk change from %s\n", __func__);
 
-       if (!test_bit(FD_DISK_NEWCHANGE_BIT, &DRS->flags) &&
+       if (!test_bit(FD_DISK_NEWCHANGE_BIT, &drive_state[current_drive].flags) &&
            disk_change(current_drive) && (raw_cmd->flags & FD_RAW_NEED_DISK)) {
                /* the media changed flag should be cleared after the seek.
                 * If it isn't, this means that there is really no disk in
                 * the drive.
                 */
-               set_bit(FD_DISK_CHANGED_BIT, &DRS->flags);
+               set_bit(FD_DISK_CHANGED_BIT,
+                       &drive_state[current_drive].flags);
                cont->done(0);
                cont->redo();
                return;
        }
-       if (DRS->track <= NEED_1_RECAL) {
+       if (drive_state[current_drive].track <= NEED_1_RECAL) {
                recalibrate_floppy();
                return;
-       } else if (test_bit(FD_DISK_NEWCHANGE_BIT, &DRS->flags) &&
+       } else if (test_bit(FD_DISK_NEWCHANGE_BIT, &drive_state[current_drive].flags) &&
                   (raw_cmd->flags & FD_RAW_NEED_DISK) &&
-                  (DRS->track <= NO_TRACK || DRS->track == raw_cmd->track)) {
+                  (drive_state[current_drive].track <= NO_TRACK || drive_state[current_drive].track == raw_cmd->track)) {
                /* we seek to clear the media-changed condition. Does anybody
                 * know a more elegant way, which works on all drives? */
                if (raw_cmd->track)
                        track = raw_cmd->track - 1;
                else {
-                       if (DP->flags & FD_SILENT_DCL_CLEAR) {
-                               set_dor(fdc, ~(0x10 << UNIT(current_drive)), 0);
+                       if (drive_params[current_drive].flags & FD_SILENT_DCL_CLEAR) {
+                               set_dor(current_fdc, ~(0x10 << UNIT(current_drive)), 0);
                                blind_seek = 1;
                                raw_cmd->flags |= FD_RAW_NEED_SEEK;
                        }
@@ -1602,7 +1629,7 @@ static void seek_floppy(void)
                }
        } else {
                check_wp();
-               if (raw_cmd->track != DRS->track &&
+               if (raw_cmd->track != drive_state[current_drive].track &&
                    (raw_cmd->flags & FD_RAW_NEED_SEEK))
                        track = raw_cmd->track;
                else {
@@ -1625,9 +1652,9 @@ static void recal_interrupt(void)
 {
        debugt(__func__, "");
        if (inr != 2)
-               FDCS->reset = 1;
-       else if (ST0 & ST0_ECE) {
-               switch (DRS->track) {
+               fdc_state[current_fdc].reset = 1;
+       else if (reply_buffer[ST0] & ST0_ECE) {
+               switch (drive_state[current_drive].track) {
                case NEED_1_RECAL:
                        debugt(__func__, "need 1 recal");
                        /* after a second recalibrate, we still haven't
@@ -1645,11 +1672,12 @@ static void recal_interrupt(void)
                         * not to move at recalibration is to
                         * be already at track 0.) Clear the
                         * new change flag */
-                       debug_dcl(DP->flags,
+                       debug_dcl(drive_params[current_drive].flags,
                                  "clearing NEWCHANGE flag because of second recalibrate\n");
 
-                       clear_bit(FD_DISK_NEWCHANGE_BIT, &DRS->flags);
-                       DRS->select_date = jiffies;
+                       clear_bit(FD_DISK_NEWCHANGE_BIT,
+                                 &drive_state[current_drive].flags);
+                       drive_state[current_drive].select_date = jiffies;
                        /* fall through */
                default:
                        debugt(__func__, "default");
@@ -1659,11 +1687,11 @@ static void recal_interrupt(void)
                         * track 0, this might mean that we
                         * started beyond track 80.  Try
                         * again.  */
-                       DRS->track = NEED_1_RECAL;
+                       drive_state[current_drive].track = NEED_1_RECAL;
                        break;
                }
        } else
-               DRS->track = ST1;
+               drive_state[current_drive].track = reply_buffer[ST1];
        floppy_ready();
 }
 
@@ -1693,20 +1721,20 @@ irqreturn_t floppy_interrupt(int irq, void *dev_id)
        release_dma_lock(f);
 
        do_floppy = NULL;
-       if (fdc >= N_FDC || FDCS->address == -1) {
+       if (current_fdc >= N_FDC || fdc_state[current_fdc].address == -1) {
                /* we don't even know which FDC is the culprit */
                pr_info("DOR0=%x\n", fdc_state[0].dor);
-               pr_info("floppy interrupt on bizarre fdc %d\n", fdc);
+               pr_info("floppy interrupt on bizarre fdc %d\n", current_fdc);
                pr_info("handler=%ps\n", handler);
                is_alive(__func__, "bizarre fdc");
                return IRQ_NONE;
        }
 
-       FDCS->reset = 0;
+       fdc_state[current_fdc].reset = 0;
        /* We have to clear the reset flag here, because apparently on boxes
         * with level triggered interrupts (PS/2, Sparc, ...), it is needed to
-        * emit SENSEI's to clear the interrupt line. And FDCS->reset blocks the
-        * emission of the SENSEI's.
+        * emit SENSEI's to clear the interrupt line. And fdc_state[fdc].reset
+        * blocks the emission of the SENSEI's.
         * It is OK to emit floppy commands because we are in an interrupt
         * handler here, and thus we have to fear no interference of other
         * activity.
@@ -1725,11 +1753,11 @@ irqreturn_t floppy_interrupt(int irq, void *dev_id)
                        if (do_print)
                                print_result("sensei", inr);
                        max_sensei--;
-               } while ((ST0 & 0x83) != UNIT(current_drive) &&
+               } while ((reply_buffer[ST0] & 0x83) != UNIT(current_drive) &&
                         inr == 2 && max_sensei);
        }
        if (!handler) {
-               FDCS->reset = 1;
+               fdc_state[current_fdc].reset = 1;
                return IRQ_NONE;
        }
        schedule_bh(handler);
@@ -1755,7 +1783,7 @@ static void reset_interrupt(void)
 {
        debugt(__func__, "");
        result();               /* get the status ready for set_fdc */
-       if (FDCS->reset) {
+       if (fdc_state[current_fdc].reset) {
                pr_info("reset set in interrupt, calling %ps\n", cont->error);
                cont->error();  /* a reset just after a reset. BAD! */
        }
@@ -1771,7 +1799,7 @@ static void reset_fdc(void)
        unsigned long flags;
 
        do_floppy = reset_interrupt;
-       FDCS->reset = 0;
+       fdc_state[current_fdc].reset = 0;
        reset_fdc_info(0);
 
        /* Pseudo-DMA may intercept 'reset finished' interrupt.  */
@@ -1781,12 +1809,13 @@ static void reset_fdc(void)
        fd_disable_dma();
        release_dma_lock(flags);
 
-       if (FDCS->version >= FDC_82072A)
-               fd_outb(0x80 | (FDCS->dtr & 3), FD_STATUS);
+       if (fdc_state[current_fdc].version >= FDC_82072A)
+               fdc_outb(0x80 | (fdc_state[current_fdc].dtr & 3),
+                        current_fdc, FD_STATUS);
        else {
-               fd_outb(FDCS->dor & ~0x04, FD_DOR);
+               fdc_outb(fdc_state[current_fdc].dor & ~0x04, current_fdc, FD_DOR);
                udelay(FD_RESET_DELAY);
-               fd_outb(FDCS->dor, FD_DOR);
+               fdc_outb(fdc_state[current_fdc].dor, current_fdc, FD_DOR);
        }
 }
 
@@ -1813,7 +1842,7 @@ static void show_floppy(void)
        print_hex_dump(KERN_INFO, "", DUMP_PREFIX_NONE, 16, 1,
                       reply_buffer, resultsize, true);
 
-       pr_info("status=%x\n", fd_inb(FD_STATUS));
+       pr_info("status=%x\n", fdc_inb(current_fdc, FD_STATUS));
        pr_info("fdc_busy=%lu\n", fdc_busy);
        if (do_floppy)
                pr_info("do_floppy=%ps\n", do_floppy);
@@ -1850,7 +1879,7 @@ static void floppy_shutdown(struct work_struct *arg)
 
        if (initialized)
                DPRINT("floppy timeout called\n");
-       FDCS->reset = 1;
+       fdc_state[current_fdc].reset = 1;
        if (cont) {
                cont->done(0);
                cont->redo();   /* this will recall reset when needed */
@@ -1870,29 +1899,29 @@ static int start_motor(void (*function)(void))
        mask = 0xfc;
        data = UNIT(current_drive);
        if (!(raw_cmd->flags & FD_RAW_NO_MOTOR)) {
-               if (!(FDCS->dor & (0x10 << UNIT(current_drive)))) {
+               if (!(fdc_state[current_fdc].dor & (0x10 << UNIT(current_drive)))) {
                        set_debugt();
                        /* no read since this drive is running */
-                       DRS->first_read_date = 0;
+                       drive_state[current_drive].first_read_date = 0;
                        /* note motor start time if motor is not yet running */
-                       DRS->spinup_date = jiffies;
+                       drive_state[current_drive].spinup_date = jiffies;
                        data |= (0x10 << UNIT(current_drive));
                }
-       } else if (FDCS->dor & (0x10 << UNIT(current_drive)))
+       } else if (fdc_state[current_fdc].dor & (0x10 << UNIT(current_drive)))
                mask &= ~(0x10 << UNIT(current_drive));
 
        /* starts motor and selects floppy */
        del_timer(motor_off_timer + current_drive);
-       set_dor(fdc, mask, data);
+       set_dor(current_fdc, mask, data);
 
        /* wait_for_completion also schedules reset if needed. */
-       return fd_wait_for_completion(DRS->select_date + DP->select_delay,
+       return fd_wait_for_completion(drive_state[current_drive].select_date + drive_params[current_drive].select_delay,
                                      function);
 }
 
 static void floppy_ready(void)
 {
-       if (FDCS->reset) {
+       if (fdc_state[current_fdc].reset) {
                reset_fdc();
                return;
        }
@@ -1901,9 +1930,10 @@ static void floppy_ready(void)
        if (fdc_dtr())
                return;
 
-       debug_dcl(DP->flags, "calling disk change from floppy_ready\n");
+       debug_dcl(drive_params[current_drive].flags,
+                 "calling disk change from floppy_ready\n");
        if (!(raw_cmd->flags & FD_RAW_NO_MOTOR) &&
-           disk_change(current_drive) && !DP->select_delay)
+           disk_change(current_drive) && !drive_params[current_drive].select_delay)
                twaddle();      /* this clears the dcl on certain
                                 * drive/controller combinations */
 
@@ -1932,8 +1962,9 @@ static void floppy_start(void)
        reschedule_timeout(current_reqD, "floppy start");
 
        scandrives();
-       debug_dcl(DP->flags, "setting NEWCHANGE in floppy_start\n");
-       set_bit(FD_DISK_NEWCHANGE_BIT, &DRS->flags);
+       debug_dcl(drive_params[current_drive].flags,
+                 "setting NEWCHANGE in floppy_start\n");
+       set_bit(FD_DISK_NEWCHANGE_BIT, &drive_state[current_drive].flags);
        floppy_ready();
 }
 
@@ -1991,7 +2022,7 @@ static int wait_til_done(void (*handler)(void), bool interruptible)
                return -EINTR;
        }
 
-       if (FDCS->reset)
+       if (fdc_state[current_fdc].reset)
                command_status = FD_COMMAND_ERROR;
        if (command_status == FD_COMMAND_OKAY)
                ret = 0;
@@ -2032,14 +2063,14 @@ static int next_valid_format(void)
 {
        int probed_format;
 
-       probed_format = DRS->probed_format;
+       probed_format = drive_state[current_drive].probed_format;
        while (1) {
-               if (probed_format >= 8 || !DP->autodetect[probed_format]) {
-                       DRS->probed_format = 0;
+               if (probed_format >= 8 || !drive_params[current_drive].autodetect[probed_format]) {
+                       drive_state[current_drive].probed_format = 0;
                        return 1;
                }
-               if (floppy_type[DP->autodetect[probed_format]].sect) {
-                       DRS->probed_format = probed_format;
+               if (floppy_type[drive_params[current_drive].autodetect[probed_format]].sect) {
+                       drive_state[current_drive].probed_format = probed_format;
                        return 0;
                }
                probed_format++;
@@ -2051,23 +2082,23 @@ static void bad_flp_intr(void)
        int err_count;
 
        if (probing) {
-               DRS->probed_format++;
+               drive_state[current_drive].probed_format++;
                if (!next_valid_format())
                        return;
        }
        err_count = ++(*errors);
-       INFBOUND(DRWE->badness, err_count);
-       if (err_count > DP->max_errors.abort)
+       INFBOUND(write_errors[current_drive].badness, err_count);
+       if (err_count > drive_params[current_drive].max_errors.abort)
                cont->done(0);
-       if (err_count > DP->max_errors.reset)
-               FDCS->reset = 1;
-       else if (err_count > DP->max_errors.recal)
-               DRS->track = NEED_2_RECAL;
+       if (err_count > drive_params[current_drive].max_errors.reset)
+               fdc_state[current_fdc].reset = 1;
+       else if (err_count > drive_params[current_drive].max_errors.recal)
+               drive_state[current_drive].track = NEED_2_RECAL;
 }
 
 static void set_floppy(int drive)
 {
-       int type = ITYPE(UDRS->fd_device);
+       int type = ITYPE(drive_state[drive].fd_device);
 
        if (type)
                _floppy = floppy_type + type;
@@ -2113,28 +2144,28 @@ static void setup_format_params(int track)
                          FD_RAW_NEED_DISK | FD_RAW_NEED_SEEK);
        raw_cmd->rate = _floppy->rate & 0x43;
        raw_cmd->cmd_count = NR_F;
-       COMMAND = FM_MODE(_floppy, FD_FORMAT);
-       DR_SELECT = UNIT(current_drive) + PH_HEAD(_floppy, format_req.head);
-       F_SIZECODE = FD_SIZECODE(_floppy);
-       F_SECT_PER_TRACK = _floppy->sect << 2 >> F_SIZECODE;
-       F_GAP = _floppy->fmt_gap;
-       F_FILL = FD_FILL_BYTE;
+       raw_cmd->cmd[COMMAND] = FM_MODE(_floppy, FD_FORMAT);
+       raw_cmd->cmd[DR_SELECT] = UNIT(current_drive) + PH_HEAD(_floppy, format_req.head);
+       raw_cmd->cmd[F_SIZECODE] = FD_SIZECODE(_floppy);
+       raw_cmd->cmd[F_SECT_PER_TRACK] = _floppy->sect << 2 >> raw_cmd->cmd[F_SIZECODE];
+       raw_cmd->cmd[F_GAP] = _floppy->fmt_gap;
+       raw_cmd->cmd[F_FILL] = FD_FILL_BYTE;
 
        raw_cmd->kernel_data = floppy_track_buffer;
-       raw_cmd->length = 4 * F_SECT_PER_TRACK;
+       raw_cmd->length = 4 * raw_cmd->cmd[F_SECT_PER_TRACK];
 
-       if (!F_SECT_PER_TRACK)
+       if (!raw_cmd->cmd[F_SECT_PER_TRACK])
                return;
 
        /* allow for about 30ms for data transport per track */
-       head_shift = (F_SECT_PER_TRACK + 5) / 6;
+       head_shift = (raw_cmd->cmd[F_SECT_PER_TRACK] + 5) / 6;
 
        /* a ``cylinder'' is two tracks plus a little stepping time */
        track_shift = 2 * head_shift + 3;
 
        /* position of logical sector 1 on this track */
        n = (track_shift * format_req.track + head_shift * format_req.head)
-           % F_SECT_PER_TRACK;
+           % raw_cmd->cmd[F_SECT_PER_TRACK];
 
        /* determine interleave */
        il = 1;
@@ -2142,27 +2173,27 @@ static void setup_format_params(int track)
                il++;
 
        /* initialize field */
-       for (count = 0; count < F_SECT_PER_TRACK; ++count) {
+       for (count = 0; count < raw_cmd->cmd[F_SECT_PER_TRACK]; ++count) {
                here[count].track = format_req.track;
                here[count].head = format_req.head;
                here[count].sect = 0;
-               here[count].size = F_SIZECODE;
+               here[count].size = raw_cmd->cmd[F_SIZECODE];
        }
        /* place logical sectors */
-       for (count = 1; count <= F_SECT_PER_TRACK; ++count) {
+       for (count = 1; count <= raw_cmd->cmd[F_SECT_PER_TRACK]; ++count) {
                here[n].sect = count;
-               n = (n + il) % F_SECT_PER_TRACK;
+               n = (n + il) % raw_cmd->cmd[F_SECT_PER_TRACK];
                if (here[n].sect) {     /* sector busy, find next free sector */
                        ++n;
-                       if (n >= F_SECT_PER_TRACK) {
-                               n -= F_SECT_PER_TRACK;
+                       if (n >= raw_cmd->cmd[F_SECT_PER_TRACK]) {
+                               n -= raw_cmd->cmd[F_SECT_PER_TRACK];
                                while (here[n].sect)
                                        ++n;
                        }
                }
        }
        if (_floppy->stretch & FD_SECTBASEMASK) {
-               for (count = 0; count < F_SECT_PER_TRACK; count++)
+               for (count = 0; count < raw_cmd->cmd[F_SECT_PER_TRACK]; count++)
                        here[count].sect += FD_SECTBASE(_floppy) - 1;
        }
 }
@@ -2191,7 +2222,7 @@ static int do_format(int drive, struct format_descr *tmp_format_req)
 
        set_floppy(drive);
        if (!_floppy ||
-           _floppy->track > DP->tracks ||
+           _floppy->track > drive_params[current_drive].tracks ||
            tmp_format_req->track >= _floppy->track ||
            tmp_format_req->head >= _floppy->head ||
            (_floppy->sect << 2) % (1 << FD_SIZECODE(_floppy)) ||
@@ -2253,21 +2284,21 @@ static void request_done(int uptodate)
                /* maintain values for invalidation on geometry
                 * change */
                block = current_count_sectors + blk_rq_pos(req);
-               INFBOUND(DRS->maxblock, block);
+               INFBOUND(drive_state[current_drive].maxblock, block);
                if (block > _floppy->sect)
-                       DRS->maxtrack = 1;
+                       drive_state[current_drive].maxtrack = 1;
 
                floppy_end_request(req, 0);
        } else {
                if (rq_data_dir(req) == WRITE) {
                        /* record write error information */
-                       DRWE->write_errors++;
-                       if (DRWE->write_errors == 1) {
-                               DRWE->first_error_sector = blk_rq_pos(req);
-                               DRWE->first_error_generation = DRS->generation;
+                       write_errors[current_drive].write_errors++;
+                       if (write_errors[current_drive].write_errors == 1) {
+                               write_errors[current_drive].first_error_sector = blk_rq_pos(req);
+                               write_errors[current_drive].first_error_generation = drive_state[current_drive].generation;
                        }
-                       DRWE->last_error_sector = blk_rq_pos(req);
-                       DRWE->last_error_generation = DRS->generation;
+                       write_errors[current_drive].last_error_sector = blk_rq_pos(req);
+                       write_errors[current_drive].last_error_generation = drive_state[current_drive].generation;
                }
                floppy_end_request(req, BLK_STS_IOERR);
        }
@@ -2281,43 +2312,46 @@ static void rw_interrupt(void)
        int heads;
        int nr_sectors;
 
-       if (R_HEAD >= 2) {
+       if (reply_buffer[R_HEAD] >= 2) {
                /* some Toshiba floppy controllers occasionnally seem to
                 * return bogus interrupts after read/write operations, which
                 * can be recognized by a bad head number (>= 2) */
                return;
        }
 
-       if (!DRS->first_read_date)
-               DRS->first_read_date = jiffies;
+       if (!drive_state[current_drive].first_read_date)
+               drive_state[current_drive].first_read_date = jiffies;
 
        nr_sectors = 0;
-       ssize = DIV_ROUND_UP(1 << SIZECODE, 4);
+       ssize = DIV_ROUND_UP(1 << raw_cmd->cmd[SIZECODE], 4);
 
-       if (ST1 & ST1_EOC)
+       if (reply_buffer[ST1] & ST1_EOC)
                eoc = 1;
        else
                eoc = 0;
 
-       if (COMMAND & 0x80)
+       if (raw_cmd->cmd[COMMAND] & 0x80)
                heads = 2;
        else
                heads = 1;
 
-       nr_sectors = (((R_TRACK - TRACK) * heads +
-                      R_HEAD - HEAD) * SECT_PER_TRACK +
-                     R_SECTOR - SECTOR + eoc) << SIZECODE >> 2;
+       nr_sectors = (((reply_buffer[R_TRACK] - raw_cmd->cmd[TRACK]) * heads +
+                      reply_buffer[R_HEAD] - raw_cmd->cmd[HEAD]) * raw_cmd->cmd[SECT_PER_TRACK] +
+                     reply_buffer[R_SECTOR] - raw_cmd->cmd[SECTOR] + eoc) << raw_cmd->cmd[SIZECODE] >> 2;
 
        if (nr_sectors / ssize >
            DIV_ROUND_UP(in_sector_offset + current_count_sectors, ssize)) {
                DPRINT("long rw: %x instead of %lx\n",
                       nr_sectors, current_count_sectors);
-               pr_info("rs=%d s=%d\n", R_SECTOR, SECTOR);
-               pr_info("rh=%d h=%d\n", R_HEAD, HEAD);
-               pr_info("rt=%d t=%d\n", R_TRACK, TRACK);
+               pr_info("rs=%d s=%d\n", reply_buffer[R_SECTOR],
+                       raw_cmd->cmd[SECTOR]);
+               pr_info("rh=%d h=%d\n", reply_buffer[R_HEAD],
+                       raw_cmd->cmd[HEAD]);
+               pr_info("rt=%d t=%d\n", reply_buffer[R_TRACK],
+                       raw_cmd->cmd[TRACK]);
                pr_info("heads=%d eoc=%d\n", heads, eoc);
                pr_info("spt=%d st=%d ss=%d\n",
-                       SECT_PER_TRACK, fsector_t, ssize);
+                       raw_cmd->cmd[SECT_PER_TRACK], fsector_t, ssize);
                pr_info("in_sector_offset=%d\n", in_sector_offset);
        }
 
@@ -2347,7 +2381,7 @@ static void rw_interrupt(void)
        }
 
        if (probing) {
-               if (DP->flags & FTD_MSG)
+               if (drive_params[current_drive].flags & FTD_MSG)
                        DPRINT("Auto-detected floppy type %s in fd%d\n",
                               _floppy->name, current_drive);
                current_type[current_drive] = _floppy;
@@ -2355,11 +2389,11 @@ static void rw_interrupt(void)
                probing = 0;
        }
 
-       if (CT(COMMAND) != FD_READ ||
+       if (CT(raw_cmd->cmd[COMMAND]) != FD_READ ||
            raw_cmd->kernel_data == bio_data(current_req->bio)) {
                /* transfer directly from buffer */
                cont->done(1);
-       } else if (CT(COMMAND) == FD_READ) {
+       } else if (CT(raw_cmd->cmd[COMMAND]) == FD_READ) {
                buffer_track = raw_cmd->track;
                buffer_drive = current_drive;
                INFBOUND(buffer_max, nr_sectors + fsector_t);
@@ -2418,13 +2452,13 @@ static void copy_buffer(int ssize, int max_sector, int max_sector_2)
                                   min(max_sector, max_sector_2),
                                   blk_rq_sectors(current_req));
 
-       if (current_count_sectors <= 0 && CT(COMMAND) == FD_WRITE &&
+       if (current_count_sectors <= 0 && CT(raw_cmd->cmd[COMMAND]) == FD_WRITE &&
            buffer_max > fsector_t + blk_rq_sectors(current_req))
                current_count_sectors = min_t(int, buffer_max - fsector_t,
                                              blk_rq_sectors(current_req));
 
        remaining = current_count_sectors << 9;
-       if (remaining > blk_rq_bytes(current_req) && CT(COMMAND) == FD_WRITE) {
+       if (remaining > blk_rq_bytes(current_req) && CT(raw_cmd->cmd[COMMAND]) == FD_WRITE) {
                DPRINT("in copy buffer\n");
                pr_info("current_count_sectors=%ld\n", current_count_sectors);
                pr_info("remaining=%d\n", remaining >> 9);
@@ -2459,16 +2493,16 @@ static void copy_buffer(int ssize, int max_sector, int max_sector_2)
                                fsector_t, buffer_min);
                        pr_info("current_count_sectors=%ld\n",
                                current_count_sectors);
-                       if (CT(COMMAND) == FD_READ)
+                       if (CT(raw_cmd->cmd[COMMAND]) == FD_READ)
                                pr_info("read\n");
-                       if (CT(COMMAND) == FD_WRITE)
+                       if (CT(raw_cmd->cmd[COMMAND]) == FD_WRITE)
                                pr_info("write\n");
                        break;
                }
                if (((unsigned long)buffer) % 512)
                        DPRINT("%p buffer not aligned\n", buffer);
 
-               if (CT(COMMAND) == FD_READ)
+               if (CT(raw_cmd->cmd[COMMAND]) == FD_READ)
                        memcpy(buffer, dma_buffer, size);
                else
                        memcpy(dma_buffer, buffer, size);
@@ -2486,7 +2520,7 @@ static void copy_buffer(int ssize, int max_sector, int max_sector_2)
 /* work around a bug in pseudo DMA
  * (on some FDCs) pseudo DMA does not stop when the CPU stops
  * sending data.  Hence we need a different way to signal the
- * transfer length:  We use SECT_PER_TRACK.  Unfortunately, this
+ * transfer length:  We use raw_cmd->cmd[SECT_PER_TRACK].  Unfortunately, this
  * does not work with MT, hence we can only transfer one head at
  * a time
  */
@@ -2495,18 +2529,18 @@ static void virtualdmabug_workaround(void)
        int hard_sectors;
        int end_sector;
 
-       if (CT(COMMAND) == FD_WRITE) {
-               COMMAND &= ~0x80;       /* switch off multiple track mode */
+       if (CT(raw_cmd->cmd[COMMAND]) == FD_WRITE) {
+               raw_cmd->cmd[COMMAND] &= ~0x80; /* switch off multiple track mode */
 
-               hard_sectors = raw_cmd->length >> (7 + SIZECODE);
-               end_sector = SECTOR + hard_sectors - 1;
-               if (end_sector > SECT_PER_TRACK) {
+               hard_sectors = raw_cmd->length >> (7 + raw_cmd->cmd[SIZECODE]);
+               end_sector = raw_cmd->cmd[SECTOR] + hard_sectors - 1;
+               if (end_sector > raw_cmd->cmd[SECT_PER_TRACK]) {
                        pr_info("too many sectors %d > %d\n",
-                               end_sector, SECT_PER_TRACK);
+                               end_sector, raw_cmd->cmd[SECT_PER_TRACK]);
                        return;
                }
-               SECT_PER_TRACK = end_sector;
-                                       /* make sure SECT_PER_TRACK
+               raw_cmd->cmd[SECT_PER_TRACK] = end_sector;
+                                       /* make sure raw_cmd->cmd[SECT_PER_TRACK]
                                         * points to end of transfer */
        }
 }
@@ -2539,10 +2573,10 @@ static int make_raw_rw_request(void)
        raw_cmd->cmd_count = NR_RW;
        if (rq_data_dir(current_req) == READ) {
                raw_cmd->flags |= FD_RAW_READ;
-               COMMAND = FM_MODE(_floppy, FD_READ);
+               raw_cmd->cmd[COMMAND] = FM_MODE(_floppy, FD_READ);
        } else if (rq_data_dir(current_req) == WRITE) {
                raw_cmd->flags |= FD_RAW_WRITE;
-               COMMAND = FM_MODE(_floppy, FD_WRITE);
+               raw_cmd->cmd[COMMAND] = FM_MODE(_floppy, FD_WRITE);
        } else {
                DPRINT("%s: unknown command\n", __func__);
                return 0;
@@ -2550,24 +2584,24 @@ static int make_raw_rw_request(void)
 
        max_sector = _floppy->sect * _floppy->head;
 
-       TRACK = (int)blk_rq_pos(current_req) / max_sector;
+       raw_cmd->cmd[TRACK] = (int)blk_rq_pos(current_req) / max_sector;
        fsector_t = (int)blk_rq_pos(current_req) % max_sector;
-       if (_floppy->track && TRACK >= _floppy->track) {
+       if (_floppy->track && raw_cmd->cmd[TRACK] >= _floppy->track) {
                if (blk_rq_cur_sectors(current_req) & 1) {
                        current_count_sectors = 1;
                        return 1;
                } else
                        return 0;
        }
-       HEAD = fsector_t / _floppy->sect;
+       raw_cmd->cmd[HEAD] = fsector_t / _floppy->sect;
 
        if (((_floppy->stretch & (FD_SWAPSIDES | FD_SECTBASEMASK)) ||
-            test_bit(FD_NEED_TWADDLE_BIT, &DRS->flags)) &&
+            test_bit(FD_NEED_TWADDLE_BIT, &drive_state[current_drive].flags)) &&
            fsector_t < _floppy->sect)
                max_sector = _floppy->sect;
 
        /* 2M disks have phantom sectors on the first track */
-       if ((_floppy->rate & FD_2M) && (!TRACK) && (!HEAD)) {
+       if ((_floppy->rate & FD_2M) && (!raw_cmd->cmd[TRACK]) && (!raw_cmd->cmd[HEAD])) {
                max_sector = 2 * _floppy->sect / 3;
                if (fsector_t >= max_sector) {
                        current_count_sectors =
@@ -2575,23 +2609,24 @@ static int make_raw_rw_request(void)
                                  blk_rq_sectors(current_req));
                        return 1;
                }
-               SIZECODE = 2;
+               raw_cmd->cmd[SIZECODE] = 2;
        } else
-               SIZECODE = FD_SIZECODE(_floppy);
+               raw_cmd->cmd[SIZECODE] = FD_SIZECODE(_floppy);
        raw_cmd->rate = _floppy->rate & 0x43;
-       if ((_floppy->rate & FD_2M) && (TRACK || HEAD) && raw_cmd->rate == 2)
+       if ((_floppy->rate & FD_2M) &&
+           (raw_cmd->cmd[TRACK] || raw_cmd->cmd[HEAD]) && raw_cmd->rate == 2)
                raw_cmd->rate = 1;
 
-       if (SIZECODE)
-               SIZECODE2 = 0xff;
+       if (raw_cmd->cmd[SIZECODE])
+               raw_cmd->cmd[SIZECODE2] = 0xff;
        else
-               SIZECODE2 = 0x80;
-       raw_cmd->track = TRACK << STRETCH(_floppy);
-       DR_SELECT = UNIT(current_drive) + PH_HEAD(_floppy, HEAD);
-       GAP = _floppy->gap;
-       ssize = DIV_ROUND_UP(1 << SIZECODE, 4);
-       SECT_PER_TRACK = _floppy->sect << 2 >> SIZECODE;
-       SECTOR = ((fsector_t % _floppy->sect) << 2 >> SIZECODE) +
+               raw_cmd->cmd[SIZECODE2] = 0x80;
+       raw_cmd->track = raw_cmd->cmd[TRACK] << STRETCH(_floppy);
+       raw_cmd->cmd[DR_SELECT] = UNIT(current_drive) + PH_HEAD(_floppy, raw_cmd->cmd[HEAD]);
+       raw_cmd->cmd[GAP] = _floppy->gap;
+       ssize = DIV_ROUND_UP(1 << raw_cmd->cmd[SIZECODE], 4);
+       raw_cmd->cmd[SECT_PER_TRACK] = _floppy->sect << 2 >> raw_cmd->cmd[SIZECODE];
+       raw_cmd->cmd[SECTOR] = ((fsector_t % _floppy->sect) << 2 >> raw_cmd->cmd[SIZECODE]) +
            FD_SECTBASE(_floppy);
 
        /* tracksize describes the size which can be filled up with sectors
@@ -2599,24 +2634,24 @@ static int make_raw_rw_request(void)
         */
        tracksize = _floppy->sect - _floppy->sect % ssize;
        if (tracksize < _floppy->sect) {
-               SECT_PER_TRACK++;
+               raw_cmd->cmd[SECT_PER_TRACK]++;
                if (tracksize <= fsector_t % _floppy->sect)
-                       SECTOR--;
+                       raw_cmd->cmd[SECTOR]--;
 
                /* if we are beyond tracksize, fill up using smaller sectors */
                while (tracksize <= fsector_t % _floppy->sect) {
                        while (tracksize + ssize > _floppy->sect) {
-                               SIZECODE--;
+                               raw_cmd->cmd[SIZECODE]--;
                                ssize >>= 1;
                        }
-                       SECTOR++;
-                       SECT_PER_TRACK++;
+                       raw_cmd->cmd[SECTOR]++;
+                       raw_cmd->cmd[SECT_PER_TRACK]++;
                        tracksize += ssize;
                }
-               max_sector = HEAD * _floppy->sect + tracksize;
-       } else if (!TRACK && !HEAD && !(_floppy->rate & FD_2M) && probing) {
+               max_sector = raw_cmd->cmd[HEAD] * _floppy->sect + tracksize;
+       } else if (!raw_cmd->cmd[TRACK] && !raw_cmd->cmd[HEAD] && !(_floppy->rate & FD_2M) && probing) {
                max_sector = _floppy->sect;
-       } else if (!HEAD && CT(COMMAND) == FD_WRITE) {
+       } else if (!raw_cmd->cmd[HEAD] && CT(raw_cmd->cmd[COMMAND]) == FD_WRITE) {
                /* for virtual DMA bug workaround */
                max_sector = _floppy->sect;
        }
@@ -2628,12 +2663,12 @@ static int make_raw_rw_request(void)
            (current_drive == buffer_drive) &&
            (fsector_t >= buffer_min) && (fsector_t < buffer_max)) {
                /* data already in track buffer */
-               if (CT(COMMAND) == FD_READ) {
+               if (CT(raw_cmd->cmd[COMMAND]) == FD_READ) {
                        copy_buffer(1, max_sector, buffer_max);
                        return 1;
                }
        } else if (in_sector_offset || blk_rq_sectors(current_req) < ssize) {
-               if (CT(COMMAND) == FD_WRITE) {
+               if (CT(raw_cmd->cmd[COMMAND]) == FD_WRITE) {
                        unsigned int sectors;
 
                        sectors = fsector_t + blk_rq_sectors(current_req);
@@ -2644,7 +2679,7 @@ static int make_raw_rw_request(void)
                }
                raw_cmd->flags &= ~FD_RAW_WRITE;
                raw_cmd->flags |= FD_RAW_READ;
-               COMMAND = FM_MODE(_floppy, FD_READ);
+               raw_cmd->cmd[COMMAND] = FM_MODE(_floppy, FD_READ);
        } else if ((unsigned long)bio_data(current_req->bio) < MAX_DMA_ADDRESS) {
                unsigned long dma_limit;
                int direct, indirect;
@@ -2677,9 +2712,9 @@ static int make_raw_rw_request(void)
                 */
                if (!direct ||
                    (indirect * 2 > direct * 3 &&
-                    *errors < DP->max_errors.read_track &&
+                    *errors < drive_params[current_drive].max_errors.read_track &&
                     ((!probing ||
-                      (DP->read_track & (1 << DRS->probed_format)))))) {
+                      (drive_params[current_drive].read_track & (1 << drive_state[current_drive].probed_format)))))) {
                        max_size = blk_rq_sectors(current_req);
                } else {
                        raw_cmd->kernel_data = bio_data(current_req->bio);
@@ -2695,7 +2730,7 @@ static int make_raw_rw_request(void)
                }
        }
 
-       if (CT(COMMAND) == FD_READ)
+       if (CT(raw_cmd->cmd[COMMAND]) == FD_READ)
                max_size = max_sector;  /* unbounded */
 
        /* claim buffer track if needed */
@@ -2703,7 +2738,7 @@ static int make_raw_rw_request(void)
            buffer_drive != current_drive ||    /* bad drive */
            fsector_t > buffer_max ||
            fsector_t < buffer_min ||
-           ((CT(COMMAND) == FD_READ ||
+           ((CT(raw_cmd->cmd[COMMAND]) == FD_READ ||
              (!in_sector_offset && blk_rq_sectors(current_req) >= ssize)) &&
             max_sector > 2 * max_buffer_sectors + buffer_min &&
             max_size + fsector_t > 2 * max_buffer_sectors + buffer_min)) {
@@ -2715,7 +2750,7 @@ static int make_raw_rw_request(void)
        raw_cmd->kernel_data = floppy_track_buffer +
                ((aligned_sector_t - buffer_min) << 9);
 
-       if (CT(COMMAND) == FD_WRITE) {
+       if (CT(raw_cmd->cmd[COMMAND]) == FD_WRITE) {
                /* copy write buffer to track buffer.
                 * if we get here, we know that the write
                 * is either aligned or the data already in the buffer
@@ -2737,10 +2772,10 @@ static int make_raw_rw_request(void)
        raw_cmd->length <<= 9;
        if ((raw_cmd->length < current_count_sectors << 9) ||
            (raw_cmd->kernel_data != bio_data(current_req->bio) &&
-            CT(COMMAND) == FD_WRITE &&
+            CT(raw_cmd->cmd[COMMAND]) == FD_WRITE &&
             (aligned_sector_t + (raw_cmd->length >> 9) > buffer_max ||
              aligned_sector_t < buffer_min)) ||
-           raw_cmd->length % (128 << SIZECODE) ||
+           raw_cmd->length % (128 << raw_cmd->cmd[SIZECODE]) ||
            raw_cmd->length <= 0 || current_count_sectors <= 0) {
                DPRINT("fractionary current count b=%lx s=%lx\n",
                       raw_cmd->length, current_count_sectors);
@@ -2751,9 +2786,10 @@ static int make_raw_rw_request(void)
                                current_count_sectors);
                pr_info("st=%d ast=%d mse=%d msi=%d\n",
                        fsector_t, aligned_sector_t, max_sector, max_size);
-               pr_info("ssize=%x SIZECODE=%d\n", ssize, SIZECODE);
+               pr_info("ssize=%x SIZECODE=%d\n", ssize, raw_cmd->cmd[SIZECODE]);
                pr_info("command=%x SECTOR=%d HEAD=%d, TRACK=%d\n",
-                       COMMAND, SECTOR, HEAD, TRACK);
+                       raw_cmd->cmd[COMMAND], raw_cmd->cmd[SECTOR],
+                       raw_cmd->cmd[HEAD], raw_cmd->cmd[TRACK]);
                pr_info("buffer drive=%d\n", buffer_drive);
                pr_info("buffer track=%d\n", buffer_track);
                pr_info("buffer_min=%d\n", buffer_min);
@@ -2772,9 +2808,9 @@ static int make_raw_rw_request(void)
                                fsector_t, buffer_min, raw_cmd->length >> 9);
                        pr_info("current_count_sectors=%ld\n",
                                current_count_sectors);
-                       if (CT(COMMAND) == FD_READ)
+                       if (CT(raw_cmd->cmd[COMMAND]) == FD_READ)
                                pr_info("read\n");
-                       if (CT(COMMAND) == FD_WRITE)
+                       if (CT(raw_cmd->cmd[COMMAND]) == FD_WRITE)
                                pr_info("write\n");
                        return 0;
                }
@@ -2841,14 +2877,14 @@ do_request:
 
        disk_change(current_drive);
        if (test_bit(current_drive, &fake_change) ||
-           test_bit(FD_DISK_CHANGED_BIT, &DRS->flags)) {
+           test_bit(FD_DISK_CHANGED_BIT, &drive_state[current_drive].flags)) {
                DPRINT("disk absent or changed during operation\n");
                request_done(0);
                goto do_request;
        }
        if (!_floppy) { /* Autodetection */
                if (!probing) {
-                       DRS->probed_format = 0;
+                       drive_state[current_drive].probed_format = 0;
                        if (next_valid_format()) {
                                DPRINT("no autodetectable formats\n");
                                _floppy = NULL;
@@ -2857,7 +2893,7 @@ do_request:
                        }
                }
                probing = 1;
-               _floppy = floppy_type + DP->autodetect[DRS->probed_format];
+               _floppy = floppy_type + drive_params[current_drive].autodetect[drive_state[current_drive].probed_format];
        } else
                probing = 0;
        errors = &(current_req->error_count);
@@ -2867,7 +2903,7 @@ do_request:
                goto do_request;
        }
 
-       if (test_bit(FD_NEED_TWADDLE_BIT, &DRS->flags))
+       if (test_bit(FD_NEED_TWADDLE_BIT, &drive_state[current_drive].flags))
                twaddle();
        schedule_bh(floppy_start);
        debugt(__func__, "queue fd request");
@@ -2936,8 +2972,9 @@ static int poll_drive(bool interruptible, int flag)
        raw_cmd->track = 0;
        raw_cmd->cmd_count = 0;
        cont = &poll_cont;
-       debug_dcl(DP->flags, "setting NEWCHANGE in poll_drive\n");
-       set_bit(FD_DISK_NEWCHANGE_BIT, &DRS->flags);
+       debug_dcl(drive_params[current_drive].flags,
+                 "setting NEWCHANGE in poll_drive\n");
+       set_bit(FD_DISK_NEWCHANGE_BIT, &drive_state[current_drive].flags);
 
        return wait_til_done(floppy_ready, interruptible);
 }
@@ -2967,8 +3004,8 @@ static int user_reset_fdc(int drive, int arg, bool interruptible)
                return -EINTR;
 
        if (arg == FD_RESET_ALWAYS)
-               FDCS->reset = 1;
-       if (FDCS->reset) {
+               fdc_state[current_fdc].reset = 1;
+       if (fdc_state[current_fdc].reset) {
                cont = &reset_cont;
                ret = wait_til_done(reset_fdc, interruptible);
                if (ret == -EINTR)
@@ -3001,8 +3038,8 @@ static const char *drive_name(int type, int drive)
        if (type)
                floppy = floppy_type + type;
        else {
-               if (UDP->native_format)
-                       floppy = floppy_type + UDP->native_format;
+               if (drive_params[drive].native_format)
+                       floppy = floppy_type + drive_params[drive].native_format;
                else
                        return "(null)";
        }
@@ -3179,23 +3216,23 @@ static int raw_cmd_ioctl(int cmd, void __user *param)
        int ret2;
        int ret;
 
-       if (FDCS->rawcmd <= 1)
-               FDCS->rawcmd = 1;
+       if (fdc_state[current_fdc].rawcmd <= 1)
+               fdc_state[current_fdc].rawcmd = 1;
        for (drive = 0; drive < N_DRIVE; drive++) {
-               if (FDC(drive) != fdc)
+               if (FDC(drive) != current_fdc)
                        continue;
                if (drive == current_drive) {
-                       if (UDRS->fd_ref > 1) {
-                               FDCS->rawcmd = 2;
+                       if (drive_state[drive].fd_ref > 1) {
+                               fdc_state[current_fdc].rawcmd = 2;
                                break;
                        }
-               } else if (UDRS->fd_ref) {
-                       FDCS->rawcmd = 2;
+               } else if (drive_state[drive].fd_ref) {
+                       fdc_state[current_fdc].rawcmd = 2;
                        break;
                }
        }
 
-       if (FDCS->reset)
+       if (fdc_state[current_fdc].reset)
                return -EIO;
 
        ret = raw_cmd_copyin(cmd, param, &my_raw_cmd);
@@ -3207,12 +3244,13 @@ static int raw_cmd_ioctl(int cmd, void __user *param)
        raw_cmd = my_raw_cmd;
        cont = &raw_cmd_cont;
        ret = wait_til_done(floppy_start, true);
-       debug_dcl(DP->flags, "calling disk change from raw_cmd ioctl\n");
+       debug_dcl(drive_params[current_drive].flags,
+                 "calling disk change from raw_cmd ioctl\n");
 
-       if (ret != -EINTR && FDCS->reset)
+       if (ret != -EINTR && fdc_state[current_fdc].reset)
                ret = -EIO;
 
-       DRS->track = NO_TRACK;
+       drive_state[current_drive].track = NO_TRACK;
 
        ret2 = raw_cmd_copyout(cmd, param, my_raw_cmd);
        if (!ret)
@@ -3240,9 +3278,9 @@ static int set_geometry(unsigned int cmd, struct floppy_struct *g,
            (int)g->head <= 0 ||
            /* check for overflow in max_sector */
            (int)(g->sect * g->head) <= 0 ||
-           /* check for zero in F_SECT_PER_TRACK */
+           /* check for zero in raw_cmd->cmd[F_SECT_PER_TRACK] */
            (unsigned char)((g->sect << 2) >> FD_SIZECODE(g)) == 0 ||
-           g->track <= 0 || g->track > UDP->tracks >> STRETCH(g) ||
+           g->track <= 0 || g->track > drive_params[drive].tracks >> STRETCH(g) ||
            /* check if reserved bits are set */
            (g->stretch & ~(FD_STRETCH | FD_SWAPSIDES | FD_SECTBASEMASK)) != 0)
                return -EINVAL;
@@ -3285,16 +3323,16 @@ static int set_geometry(unsigned int cmd, struct floppy_struct *g,
                current_type[drive] = &user_params[drive];
                floppy_sizes[drive] = user_params[drive].size;
                if (cmd == FDDEFPRM)
-                       DRS->keep_data = -1;
+                       drive_state[current_drive].keep_data = -1;
                else
-                       DRS->keep_data = 1;
+                       drive_state[current_drive].keep_data = 1;
                /* invalidation. Invalidate only when needed, i.e.
                 * when there are already sectors in the buffer cache
                 * whose number will change. This is useful, because
                 * mtools often changes the geometry of the disk after
                 * looking at the boot block */
-               if (DRS->maxblock > user_params[drive].sect ||
-                   DRS->maxtrack ||
+               if (drive_state[current_drive].maxblock > user_params[drive].sect ||
+                   drive_state[current_drive].maxtrack ||
                    ((user_params[drive].sect ^ oldStretch) &
                     (FD_SWAPSIDES | FD_SECTBASEMASK)))
                        invalidate_drive(bdev);
@@ -3407,7 +3445,7 @@ static int fd_locked_ioctl(struct block_device *bdev, fmode_t mode, unsigned int
                    unsigned long param)
 {
        int drive = (long)bdev->bd_disk->private_data;
-       int type = ITYPE(UDRS->fd_device);
+       int type = ITYPE(drive_state[drive].fd_device);
        int i;
        int ret;
        int size;
@@ -3455,7 +3493,7 @@ static int fd_locked_ioctl(struct block_device *bdev, fmode_t mode, unsigned int
 
        switch (cmd) {
        case FDEJECT:
-               if (UDRS->fd_ref != 1)
+               if (drive_state[drive].fd_ref != 1)
                        /* somebody else has this drive open */
                        return -EBUSY;
                if (lock_fdc(drive))
@@ -3465,8 +3503,8 @@ static int fd_locked_ioctl(struct block_device *bdev, fmode_t mode, unsigned int
                 * non-Sparc architectures */
                ret = fd_eject(UNIT(drive));
 
-               set_bit(FD_DISK_CHANGED_BIT, &UDRS->flags);
-               set_bit(FD_VERIFY_BIT, &UDRS->flags);
+               set_bit(FD_DISK_CHANGED_BIT, &drive_state[drive].flags);
+               set_bit(FD_VERIFY_BIT, &drive_state[drive].flags);
                process_fd_request();
                return ret;
        case FDCLRPRM:
@@ -3474,7 +3512,7 @@ static int fd_locked_ioctl(struct block_device *bdev, fmode_t mode, unsigned int
                        return -EINTR;
                current_type[drive] = NULL;
                floppy_sizes[drive] = MAX_DISK_SIZE << 1;
-               UDRS->keep_data = 0;
+               drive_state[drive].keep_data = 0;
                return invalidate_drive(bdev);
        case FDSETPRM:
        case FDDEFPRM:
@@ -3489,17 +3527,17 @@ static int fd_locked_ioctl(struct block_device *bdev, fmode_t mode, unsigned int
                outparam = &inparam.g;
                break;
        case FDMSGON:
-               UDP->flags |= FTD_MSG;
+               drive_params[drive].flags |= FTD_MSG;
                return 0;
        case FDMSGOFF:
-               UDP->flags &= ~FTD_MSG;
+               drive_params[drive].flags &= ~FTD_MSG;
                return 0;
        case FDFMTBEG:
                if (lock_fdc(drive))
                        return -EINTR;
                if (poll_drive(true, FD_RAW_NEED_DISK) == -EINTR)
                        return -EINTR;
-               ret = UDRS->flags;
+               ret = drive_state[drive].flags;
                process_fd_request();
                if (ret & FD_VERIFY)
                        return -ENODEV;
@@ -3507,7 +3545,7 @@ static int fd_locked_ioctl(struct block_device *bdev, fmode_t mode, unsigned int
                        return -EROFS;
                return 0;
        case FDFMTTRK:
-               if (UDRS->fd_ref != 1)
+               if (drive_state[drive].fd_ref != 1)
                        return -EBUSY;
                return do_format(drive, &inparam.f);
        case FDFMTEND:
@@ -3516,13 +3554,13 @@ static int fd_locked_ioctl(struct block_device *bdev, fmode_t mode, unsigned int
                        return -EINTR;
                return invalidate_drive(bdev);
        case FDSETEMSGTRESH:
-               UDP->max_errors.reporting = (unsigned short)(param & 0x0f);
+               drive_params[drive].max_errors.reporting = (unsigned short)(param & 0x0f);
                return 0;
        case FDGETMAXERRS:
-               outparam = &UDP->max_errors;
+               outparam = &drive_params[drive].max_errors;
                break;
        case FDSETMAXERRS:
-               UDP->max_errors = inparam.max_errors;
+               drive_params[drive].max_errors = inparam.max_errors;
                break;
        case FDGETDRVTYP:
                outparam = drive_name(type, drive);
@@ -3532,10 +3570,10 @@ static int fd_locked_ioctl(struct block_device *bdev, fmode_t mode, unsigned int
                if (!valid_floppy_drive_params(inparam.dp.autodetect,
                                inparam.dp.native_format))
                        return -EINVAL;
-               *UDP = inparam.dp;
+               drive_params[drive] = inparam.dp;
                break;
        case FDGETDRVPRM:
-               outparam = UDP;
+               outparam = &drive_params[drive];
                break;
        case FDPOLLDRVSTAT:
                if (lock_fdc(drive))
@@ -3545,18 +3583,18 @@ static int fd_locked_ioctl(struct block_device *bdev, fmode_t mode, unsigned int
                process_fd_request();
                /* fall through */
        case FDGETDRVSTAT:
-               outparam = UDRS;
+               outparam = &drive_state[drive];
                break;
        case FDRESET:
                return user_reset_fdc(drive, (int)param, true);
        case FDGETFDCSTAT:
-               outparam = UFDCS;
+               outparam = &fdc_state[FDC(drive)];
                break;
        case FDWERRORCLR:
-               memset(UDRWE, 0, sizeof(*UDRWE));
+               memset(&write_errors[drive], 0, sizeof(write_errors[drive]));
                return 0;
        case FDWERRORGET:
-               outparam = UDRWE;
+               outparam = &write_errors[drive];
                break;
        case FDRAWCMD:
                if (type)
@@ -3692,7 +3730,7 @@ static int compat_set_geometry(struct block_device *bdev, fmode_t mode, unsigned
 
        mutex_lock(&floppy_mutex);
        drive = (long)bdev->bd_disk->private_data;
-       type = ITYPE(UDRS->fd_device);
+       type = ITYPE(drive_state[drive].fd_device);
        err = set_geometry(cmd == FDSETPRM32 ? FDSETPRM : FDDEFPRM,
                        &v, drive, type, bdev);
        mutex_unlock(&floppy_mutex);
@@ -3708,7 +3746,8 @@ static int compat_get_prm(int drive,
 
        memset(&v, 0, sizeof(v));
        mutex_lock(&floppy_mutex);
-       err = get_floppy_geometry(drive, ITYPE(UDRS->fd_device), &p);
+       err = get_floppy_geometry(drive, ITYPE(drive_state[drive].fd_device),
+                                 &p);
        if (err) {
                mutex_unlock(&floppy_mutex);
                return err;
@@ -3732,25 +3771,26 @@ static int compat_setdrvprm(int drive,
        if (!valid_floppy_drive_params(v.autodetect, v.native_format))
                return -EINVAL;
        mutex_lock(&floppy_mutex);
-       UDP->cmos = v.cmos;
-       UDP->max_dtr = v.max_dtr;
-       UDP->hlt = v.hlt;
-       UDP->hut = v.hut;
-       UDP->srt = v.srt;
-       UDP->spinup = v.spinup;
-       UDP->spindown = v.spindown;
-       UDP->spindown_offset = v.spindown_offset;
-       UDP->select_delay = v.select_delay;
-       UDP->rps = v.rps;
-       UDP->tracks = v.tracks;
-       UDP->timeout = v.timeout;
-       UDP->interleave_sect = v.interleave_sect;
-       UDP->max_errors = v.max_errors;
-       UDP->flags = v.flags;
-       UDP->read_track = v.read_track;
-       memcpy(UDP->autodetect, v.autodetect, sizeof(v.autodetect));
-       UDP->checkfreq = v.checkfreq;
-       UDP->native_format = v.native_format;
+       drive_params[drive].cmos = v.cmos;
+       drive_params[drive].max_dtr = v.max_dtr;
+       drive_params[drive].hlt = v.hlt;
+       drive_params[drive].hut = v.hut;
+       drive_params[drive].srt = v.srt;
+       drive_params[drive].spinup = v.spinup;
+       drive_params[drive].spindown = v.spindown;
+       drive_params[drive].spindown_offset = v.spindown_offset;
+       drive_params[drive].select_delay = v.select_delay;
+       drive_params[drive].rps = v.rps;
+       drive_params[drive].tracks = v.tracks;
+       drive_params[drive].timeout = v.timeout;
+       drive_params[drive].interleave_sect = v.interleave_sect;
+       drive_params[drive].max_errors = v.max_errors;
+       drive_params[drive].flags = v.flags;
+       drive_params[drive].read_track = v.read_track;
+       memcpy(drive_params[drive].autodetect, v.autodetect,
+              sizeof(v.autodetect));
+       drive_params[drive].checkfreq = v.checkfreq;
+       drive_params[drive].native_format = v.native_format;
        mutex_unlock(&floppy_mutex);
        return 0;
 }
@@ -3762,25 +3802,26 @@ static int compat_getdrvprm(int drive,
 
        memset(&v, 0, sizeof(struct compat_floppy_drive_params));
        mutex_lock(&floppy_mutex);
-       v.cmos = UDP->cmos;
-       v.max_dtr = UDP->max_dtr;
-       v.hlt = UDP->hlt;
-       v.hut = UDP->hut;
-       v.srt = UDP->srt;
-       v.spinup = UDP->spinup;
-       v.spindown = UDP->spindown;
-       v.spindown_offset = UDP->spindown_offset;
-       v.select_delay = UDP->select_delay;
-       v.rps = UDP->rps;
-       v.tracks = UDP->tracks;
-       v.timeout = UDP->timeout;
-       v.interleave_sect = UDP->interleave_sect;
-       v.max_errors = UDP->max_errors;
-       v.flags = UDP->flags;
-       v.read_track = UDP->read_track;
-       memcpy(v.autodetect, UDP->autodetect, sizeof(v.autodetect));
-       v.checkfreq = UDP->checkfreq;
-       v.native_format = UDP->native_format;
+       v.cmos = drive_params[drive].cmos;
+       v.max_dtr = drive_params[drive].max_dtr;
+       v.hlt = drive_params[drive].hlt;
+       v.hut = drive_params[drive].hut;
+       v.srt = drive_params[drive].srt;
+       v.spinup = drive_params[drive].spinup;
+       v.spindown = drive_params[drive].spindown;
+       v.spindown_offset = drive_params[drive].spindown_offset;
+       v.select_delay = drive_params[drive].select_delay;
+       v.rps = drive_params[drive].rps;
+       v.tracks = drive_params[drive].tracks;
+       v.timeout = drive_params[drive].timeout;
+       v.interleave_sect = drive_params[drive].interleave_sect;
+       v.max_errors = drive_params[drive].max_errors;
+       v.flags = drive_params[drive].flags;
+       v.read_track = drive_params[drive].read_track;
+       memcpy(v.autodetect, drive_params[drive].autodetect,
+              sizeof(v.autodetect));
+       v.checkfreq = drive_params[drive].checkfreq;
+       v.native_format = drive_params[drive].native_format;
        mutex_unlock(&floppy_mutex);
 
        if (copy_to_user(arg, &v, sizeof(struct compat_floppy_drive_params)))
@@ -3803,20 +3844,20 @@ static int compat_getdrvstat(int drive, bool poll,
                        goto Eintr;
                process_fd_request();
        }
-       v.spinup_date = UDRS->spinup_date;
-       v.select_date = UDRS->select_date;
-       v.first_read_date = UDRS->first_read_date;
-       v.probed_format = UDRS->probed_format;
-       v.track = UDRS->track;
-       v.maxblock = UDRS->maxblock;
-       v.maxtrack = UDRS->maxtrack;
-       v.generation = UDRS->generation;
-       v.keep_data = UDRS->keep_data;
-       v.fd_ref = UDRS->fd_ref;
-       v.fd_device = UDRS->fd_device;
-       v.last_checked = UDRS->last_checked;
-       v.dmabuf = (uintptr_t)UDRS->dmabuf;
-       v.bufblocks = UDRS->bufblocks;
+       v.spinup_date = drive_state[drive].spinup_date;
+       v.select_date = drive_state[drive].select_date;
+       v.first_read_date = drive_state[drive].first_read_date;
+       v.probed_format = drive_state[drive].probed_format;
+       v.track = drive_state[drive].track;
+       v.maxblock = drive_state[drive].maxblock;
+       v.maxtrack = drive_state[drive].maxtrack;
+       v.generation = drive_state[drive].generation;
+       v.keep_data = drive_state[drive].keep_data;
+       v.fd_ref = drive_state[drive].fd_ref;
+       v.fd_device = drive_state[drive].fd_device;
+       v.last_checked = drive_state[drive].last_checked;
+       v.dmabuf = (uintptr_t) drive_state[drive].dmabuf;
+       v.bufblocks = drive_state[drive].bufblocks;
        mutex_unlock(&floppy_mutex);
 
        if (copy_to_user(arg, &v, sizeof(struct compat_floppy_drive_struct)))
@@ -3834,7 +3875,7 @@ static int compat_getfdcstat(int drive,
        struct floppy_fdc_state v;
 
        mutex_lock(&floppy_mutex);
-       v = *UFDCS;
+       v = fdc_state[FDC(drive)];
        mutex_unlock(&floppy_mutex);
 
        memset(&v32, 0, sizeof(struct compat_floppy_fdc_state));
@@ -3864,7 +3905,7 @@ static int compat_werrorget(int drive,
 
        memset(&v32, 0, sizeof(struct compat_floppy_write_errors));
        mutex_lock(&floppy_mutex);
-       v = *UDRWE;
+       v = write_errors[drive];
        mutex_unlock(&floppy_mutex);
        v32.write_errors = v.write_errors;
        v32.first_error_sector = v.first_error_sector;
@@ -3933,16 +3974,16 @@ static void __init config_types(void)
 
        /* read drive info out of physical CMOS */
        drive = 0;
-       if (!UDP->cmos)
-               UDP->cmos = FLOPPY0_TYPE;
+       if (!drive_params[drive].cmos)
+               drive_params[drive].cmos = FLOPPY0_TYPE;
        drive = 1;
-       if (!UDP->cmos)
-               UDP->cmos = FLOPPY1_TYPE;
+       if (!drive_params[drive].cmos)
+               drive_params[drive].cmos = FLOPPY1_TYPE;
 
        /* FIXME: additional physical CMOS drive detection should go here */
 
        for (drive = 0; drive < N_DRIVE; drive++) {
-               unsigned int type = UDP->cmos;
+               unsigned int type = drive_params[drive].cmos;
                struct floppy_drive_params *params;
                const char *name = NULL;
                char temparea[32];
@@ -3972,7 +4013,7 @@ static void __init config_types(void)
 
                        pr_cont("%s fd%d is %s", prepend, drive, name);
                }
-               *UDP = *params;
+               drive_params[drive] = *params;
        }
 
        if (has_drive)
@@ -3985,11 +4026,11 @@ static void floppy_release(struct gendisk *disk, fmode_t mode)
 
        mutex_lock(&floppy_mutex);
        mutex_lock(&open_lock);
-       if (!UDRS->fd_ref--) {
+       if (!drive_state[drive].fd_ref--) {
                DPRINT("floppy_release with fd_ref == 0");
-               UDRS->fd_ref = 0;
+               drive_state[drive].fd_ref = 0;
        }
-       if (!UDRS->fd_ref)
+       if (!drive_state[drive].fd_ref)
                opened_bdev[drive] = NULL;
        mutex_unlock(&open_lock);
        mutex_unlock(&floppy_mutex);
@@ -4010,16 +4051,16 @@ static int floppy_open(struct block_device *bdev, fmode_t mode)
 
        mutex_lock(&floppy_mutex);
        mutex_lock(&open_lock);
-       old_dev = UDRS->fd_device;
+       old_dev = drive_state[drive].fd_device;
        if (opened_bdev[drive] && opened_bdev[drive] != bdev)
                goto out2;
 
-       if (!UDRS->fd_ref && (UDP->flags & FD_BROKEN_DCL)) {
-               set_bit(FD_DISK_CHANGED_BIT, &UDRS->flags);
-               set_bit(FD_VERIFY_BIT, &UDRS->flags);
+       if (!drive_state[drive].fd_ref && (drive_params[drive].flags & FD_BROKEN_DCL)) {
+               set_bit(FD_DISK_CHANGED_BIT, &drive_state[drive].flags);
+               set_bit(FD_VERIFY_BIT, &drive_state[drive].flags);
        }
 
-       UDRS->fd_ref++;
+       drive_state[drive].fd_ref++;
 
        opened_bdev[drive] = bdev;
 
@@ -4028,7 +4069,7 @@ static int floppy_open(struct block_device *bdev, fmode_t mode)
        if (!floppy_track_buffer) {
                /* if opening an ED drive, reserve a big buffer,
                 * else reserve a small one */
-               if ((UDP->cmos == 6) || (UDP->cmos == 5))
+               if ((drive_params[drive].cmos == 6) || (drive_params[drive].cmos == 5))
                        try = 64;       /* Only 48 actually useful */
                else
                        try = 32;       /* Only 24 actually useful */
@@ -4056,38 +4097,39 @@ static int floppy_open(struct block_device *bdev, fmode_t mode)
        }
 
        new_dev = MINOR(bdev->bd_dev);
-       UDRS->fd_device = new_dev;
+       drive_state[drive].fd_device = new_dev;
        set_capacity(disks[drive], floppy_sizes[new_dev]);
        if (old_dev != -1 && old_dev != new_dev) {
                if (buffer_drive == drive)
                        buffer_track = -1;
        }
 
-       if (UFDCS->rawcmd == 1)
-               UFDCS->rawcmd = 2;
+       if (fdc_state[FDC(drive)].rawcmd == 1)
+               fdc_state[FDC(drive)].rawcmd = 2;
 
        if (!(mode & FMODE_NDELAY)) {
                if (mode & (FMODE_READ|FMODE_WRITE)) {
-                       UDRS->last_checked = 0;
-                       clear_bit(FD_OPEN_SHOULD_FAIL_BIT, &UDRS->flags);
+                       drive_state[drive].last_checked = 0;
+                       clear_bit(FD_OPEN_SHOULD_FAIL_BIT,
+                                 &drive_state[drive].flags);
                        check_disk_change(bdev);
-                       if (test_bit(FD_DISK_CHANGED_BIT, &UDRS->flags))
+                       if (test_bit(FD_DISK_CHANGED_BIT, &drive_state[drive].flags))
                                goto out;
-                       if (test_bit(FD_OPEN_SHOULD_FAIL_BIT, &UDRS->flags))
+                       if (test_bit(FD_OPEN_SHOULD_FAIL_BIT, &drive_state[drive].flags))
                                goto out;
                }
                res = -EROFS;
                if ((mode & FMODE_WRITE) &&
-                   !test_bit(FD_DISK_WRITABLE_BIT, &UDRS->flags))
+                   !test_bit(FD_DISK_WRITABLE_BIT, &drive_state[drive].flags))
                        goto out;
        }
        mutex_unlock(&open_lock);
        mutex_unlock(&floppy_mutex);
        return 0;
 out:
-       UDRS->fd_ref--;
+       drive_state[drive].fd_ref--;
 
-       if (!UDRS->fd_ref)
+       if (!drive_state[drive].fd_ref)
                opened_bdev[drive] = NULL;
 out2:
        mutex_unlock(&open_lock);
@@ -4103,19 +4145,19 @@ static unsigned int floppy_check_events(struct gendisk *disk,
 {
        int drive = (long)disk->private_data;
 
-       if (test_bit(FD_DISK_CHANGED_BIT, &UDRS->flags) ||
-           test_bit(FD_VERIFY_BIT, &UDRS->flags))
+       if (test_bit(FD_DISK_CHANGED_BIT, &drive_state[drive].flags) ||
+           test_bit(FD_VERIFY_BIT, &drive_state[drive].flags))
                return DISK_EVENT_MEDIA_CHANGE;
 
-       if (time_after(jiffies, UDRS->last_checked + UDP->checkfreq)) {
+       if (time_after(jiffies, drive_state[drive].last_checked + drive_params[drive].checkfreq)) {
                if (lock_fdc(drive))
                        return 0;
                poll_drive(false, 0);
                process_fd_request();
        }
 
-       if (test_bit(FD_DISK_CHANGED_BIT, &UDRS->flags) ||
-           test_bit(FD_VERIFY_BIT, &UDRS->flags) ||
+       if (test_bit(FD_DISK_CHANGED_BIT, &drive_state[drive].flags) ||
+           test_bit(FD_VERIFY_BIT, &drive_state[drive].flags) ||
            test_bit(drive, &fake_change) ||
            drive_no_geom(drive))
                return DISK_EVENT_MEDIA_CHANGE;
@@ -4141,7 +4183,7 @@ static void floppy_rb0_cb(struct bio *bio)
        if (bio->bi_status) {
                pr_info("floppy: error %d while reading block 0\n",
                        bio->bi_status);
-               set_bit(FD_OPEN_SHOULD_FAIL_BIT, &UDRS->flags);
+               set_bit(FD_OPEN_SHOULD_FAIL_BIT, &drive_state[drive].flags);
        }
        complete(&cbdata->complete);
 }
@@ -4198,8 +4240,8 @@ static int floppy_revalidate(struct gendisk *disk)
        int cf;
        int res = 0;
 
-       if (test_bit(FD_DISK_CHANGED_BIT, &UDRS->flags) ||
-           test_bit(FD_VERIFY_BIT, &UDRS->flags) ||
+       if (test_bit(FD_DISK_CHANGED_BIT, &drive_state[drive].flags) ||
+           test_bit(FD_VERIFY_BIT, &drive_state[drive].flags) ||
            test_bit(drive, &fake_change) ||
            drive_no_geom(drive)) {
                if (WARN(atomic_read(&usage_count) == 0,
@@ -4209,20 +4251,20 @@ static int floppy_revalidate(struct gendisk *disk)
                res = lock_fdc(drive);
                if (res)
                        return res;
-               cf = (test_bit(FD_DISK_CHANGED_BIT, &UDRS->flags) ||
-                     test_bit(FD_VERIFY_BIT, &UDRS->flags));
+               cf = (test_bit(FD_DISK_CHANGED_BIT, &drive_state[drive].flags) ||
+                     test_bit(FD_VERIFY_BIT, &drive_state[drive].flags));
                if (!(cf || test_bit(drive, &fake_change) || drive_no_geom(drive))) {
                        process_fd_request();   /*already done by another thread */
                        return 0;
                }
-               UDRS->maxblock = 0;
-               UDRS->maxtrack = 0;
+               drive_state[drive].maxblock = 0;
+               drive_state[drive].maxtrack = 0;
                if (buffer_drive == drive)
                        buffer_track = -1;
                clear_bit(drive, &fake_change);
-               clear_bit(FD_DISK_CHANGED_BIT, &UDRS->flags);
+               clear_bit(FD_DISK_CHANGED_BIT, &drive_state[drive].flags);
                if (cf)
-                       UDRS->generation++;
+                       drive_state[drive].generation++;
                if (drive_no_geom(drive)) {
                        /* auto-sensing */
                        res = __floppy_read_block_0(opened_bdev[drive], drive);
@@ -4232,7 +4274,7 @@ static int floppy_revalidate(struct gendisk *disk)
                        process_fd_request();
                }
        }
-       set_capacity(disk, floppy_sizes[UDRS->fd_device]);
+       set_capacity(disk, floppy_sizes[drive_state[drive].fd_device]);
        return res;
 }
 
@@ -4261,23 +4303,23 @@ static char __init get_fdc_version(void)
        int r;
 
        output_byte(FD_DUMPREGS);       /* 82072 and better know DUMPREGS */
-       if (FDCS->reset)
+       if (fdc_state[current_fdc].reset)
                return FDC_NONE;
        r = result();
        if (r <= 0x00)
                return FDC_NONE;        /* No FDC present ??? */
        if ((r == 1) && (reply_buffer[0] == 0x80)) {
-               pr_info("FDC %d is an 8272A\n", fdc);
+               pr_info("FDC %d is an 8272A\n", current_fdc);
                return FDC_8272A;       /* 8272a/765 don't know DUMPREGS */
        }
        if (r != 10) {
                pr_info("FDC %d init: DUMPREGS: unexpected return of %d bytes.\n",
-                       fdc, r);
+                       current_fdc, r);
                return FDC_UNKNOWN;
        }
 
        if (!fdc_configure()) {
-               pr_info("FDC %d is an 82072\n", fdc);
+               pr_info("FDC %d is an 82072\n", current_fdc);
                return FDC_82072;       /* 82072 doesn't know CONFIGURE */
        }
 
@@ -4285,50 +4327,50 @@ static char __init get_fdc_version(void)
        if (need_more_output() == MORE_OUTPUT) {
                output_byte(0);
        } else {
-               pr_info("FDC %d is an 82072A\n", fdc);
+               pr_info("FDC %d is an 82072A\n", current_fdc);
                return FDC_82072A;      /* 82072A as found on Sparcs. */
        }
 
        output_byte(FD_UNLOCK);
        r = result();
        if ((r == 1) && (reply_buffer[0] == 0x80)) {
-               pr_info("FDC %d is a pre-1991 82077\n", fdc);
+               pr_info("FDC %d is a pre-1991 82077\n", current_fdc);
                return FDC_82077_ORIG;  /* Pre-1991 82077, doesn't know
                                         * LOCK/UNLOCK */
        }
        if ((r != 1) || (reply_buffer[0] != 0x00)) {
                pr_info("FDC %d init: UNLOCK: unexpected return of %d bytes.\n",
-                       fdc, r);
+                       current_fdc, r);
                return FDC_UNKNOWN;
        }
        output_byte(FD_PARTID);
        r = result();
        if (r != 1) {
                pr_info("FDC %d init: PARTID: unexpected return of %d bytes.\n",
-                       fdc, r);
+                       current_fdc, r);
                return FDC_UNKNOWN;
        }
        if (reply_buffer[0] == 0x80) {
-               pr_info("FDC %d is a post-1991 82077\n", fdc);
+               pr_info("FDC %d is a post-1991 82077\n", current_fdc);
                return FDC_82077;       /* Revised 82077AA passes all the tests */
        }
        switch (reply_buffer[0] >> 5) {
        case 0x0:
                /* Either a 82078-1 or a 82078SL running at 5Volt */
-               pr_info("FDC %d is an 82078.\n", fdc);
+               pr_info("FDC %d is an 82078.\n", current_fdc);
                return FDC_82078;
        case 0x1:
-               pr_info("FDC %d is a 44pin 82078\n", fdc);
+               pr_info("FDC %d is a 44pin 82078\n", current_fdc);
                return FDC_82078;
        case 0x2:
-               pr_info("FDC %d is a S82078B\n", fdc);
+               pr_info("FDC %d is a S82078B\n", current_fdc);
                return FDC_S82078B;
        case 0x3:
-               pr_info("FDC %d is a National Semiconductor PC87306\n", fdc);
+               pr_info("FDC %d is a National Semiconductor PC87306\n", current_fdc);
                return FDC_87306;
        default:
                pr_info("FDC %d init: 82078 variant with unknown PARTID=%d.\n",
-                       fdc, reply_buffer[0] >> 5);
+                       current_fdc, reply_buffer[0] >> 5);
                return FDC_82078_UNKN;
        }
 }                              /* get_fdc_version */
@@ -4384,7 +4426,7 @@ static void __init set_cmos(int *ints, int dummy, int dummy2)
        if (current_drive >= 4 && !FDC2)
                FDC2 = 0x370;
 #endif
-       DP->cmos = ints[2];
+       drive_params[current_drive].cmos = ints[2];
        DPRINT("setting CMOS code to %d\n", ints[2]);
 }
 
@@ -4473,7 +4515,7 @@ static ssize_t floppy_cmos_show(struct device *dev,
        int drive;
 
        drive = p->id;
-       return sprintf(buf, "%X\n", UDP->cmos);
+       return sprintf(buf, "%X\n", drive_params[drive].cmos);
 }
 
 static DEVICE_ATTR(cmos, 0444, floppy_cmos_show, NULL);
@@ -4494,7 +4536,7 @@ static int floppy_resume(struct device *dev)
        int fdc;
 
        for (fdc = 0; fdc < N_FDC; fdc++)
-               if (FDCS->address != -1)
+               if (fdc_state[fdc].address != -1)
                        user_reset_fdc(-1, FD_RESET_ALWAYS, false);
 
        return 0;
@@ -4604,16 +4646,16 @@ static int __init do_floppy_init(void)
        config_types();
 
        for (i = 0; i < N_FDC; i++) {
-               fdc = i;
-               memset(FDCS, 0, sizeof(*FDCS));
-               FDCS->dtr = -1;
-               FDCS->dor = 0x4;
+               current_fdc = i;
+               memset(&fdc_state[current_fdc], 0, sizeof(*fdc_state));
+               fdc_state[current_fdc].dtr = -1;
+               fdc_state[current_fdc].dor = 0x4;
 #if defined(__sparc__) || defined(__mc68000__)
        /*sparcs/sun3x don't have a DOR reset which we can fall back on to */
 #ifdef __mc68000__
                if (MACH_IS_SUN3X)
 #endif
-                       FDCS->version = FDC_82072A;
+                       fdc_state[current_fdc].version = FDC_82072A;
 #endif
        }
 
@@ -4628,7 +4670,7 @@ static int __init do_floppy_init(void)
        fdc_state[1].address = FDC2;
 #endif
 
-       fdc = 0;                /* reset fdc in case of unexpected interrupt */
+       current_fdc = 0;        /* reset fdc in case of unexpected interrupt */
        err = floppy_grab_irq_and_dma();
        if (err) {
                cancel_delayed_work(&fd_timeout);
@@ -4638,12 +4680,12 @@ static int __init do_floppy_init(void)
 
        /* initialise drive state */
        for (drive = 0; drive < N_DRIVE; drive++) {
-               memset(UDRS, 0, sizeof(*UDRS));
-               memset(UDRWE, 0, sizeof(*UDRWE));
-               set_bit(FD_DISK_NEWCHANGE_BIT, &UDRS->flags);
-               set_bit(FD_DISK_CHANGED_BIT, &UDRS->flags);
-               set_bit(FD_VERIFY_BIT, &UDRS->flags);
-               UDRS->fd_device = -1;
+               memset(&drive_state[drive], 0, sizeof(drive_state[drive]));
+               memset(&write_errors[drive], 0, sizeof(write_errors[drive]));
+               set_bit(FD_DISK_NEWCHANGE_BIT, &drive_state[drive].flags);
+               set_bit(FD_DISK_CHANGED_BIT, &drive_state[drive].flags);
+               set_bit(FD_VERIFY_BIT, &drive_state[drive].flags);
+               drive_state[drive].fd_device = -1;
                floppy_track_buffer = NULL;
                max_buffer_sectors = 0;
        }
@@ -4655,29 +4697,30 @@ static int __init do_floppy_init(void)
        msleep(10);
 
        for (i = 0; i < N_FDC; i++) {
-               fdc = i;
-               FDCS->driver_version = FD_DRIVER_VERSION;
+               current_fdc = i;
+               fdc_state[current_fdc].driver_version = FD_DRIVER_VERSION;
                for (unit = 0; unit < 4; unit++)
-                       FDCS->track[unit] = 0;
-               if (FDCS->address == -1)
+                       fdc_state[current_fdc].track[unit] = 0;
+               if (fdc_state[current_fdc].address == -1)
                        continue;
-               FDCS->rawcmd = 2;
+               fdc_state[current_fdc].rawcmd = 2;
                if (user_reset_fdc(-1, FD_RESET_ALWAYS, false)) {
                        /* free ioports reserved by floppy_grab_irq_and_dma() */
-                       floppy_release_regions(fdc);
-                       FDCS->address = -1;
-                       FDCS->version = FDC_NONE;
+                       floppy_release_regions(current_fdc);
+                       fdc_state[current_fdc].address = -1;
+                       fdc_state[current_fdc].version = FDC_NONE;
                        continue;
                }
                /* Try to determine the floppy controller type */
-               FDCS->version = get_fdc_version();
-               if (FDCS->version == FDC_NONE) {
+               fdc_state[current_fdc].version = get_fdc_version();
+               if (fdc_state[current_fdc].version == FDC_NONE) {
                        /* free ioports reserved by floppy_grab_irq_and_dma() */
-                       floppy_release_regions(fdc);
-                       FDCS->address = -1;
+                       floppy_release_regions(current_fdc);
+                       fdc_state[current_fdc].address = -1;
                        continue;
                }
-               if (can_use_virtual_dma == 2 && FDCS->version < FDC_82072A)
+               if (can_use_virtual_dma == 2 &&
+                   fdc_state[current_fdc].version < FDC_82072A)
                        can_use_virtual_dma = 0;
 
                have_no_fdc = 0;
@@ -4687,7 +4730,7 @@ static int __init do_floppy_init(void)
                 */
                user_reset_fdc(-1, FD_RESET_ALWAYS, false);
        }
-       fdc = 0;
+       current_fdc = 0;
        cancel_delayed_work(&fd_timeout);
        current_drive = 0;
        initialized = true;
@@ -4783,7 +4826,7 @@ static void floppy_release_allocated_regions(int fdc, const struct io_region *p)
 {
        while (p != io_regions) {
                p--;
-               release_region(FDCS->address + p->offset, p->size);
+               release_region(fdc_state[fdc].address + p->offset, p->size);
        }
 }
 
@@ -4794,10 +4837,10 @@ static int floppy_request_regions(int fdc)
        const struct io_region *p;
 
        for (p = io_regions; p < ARRAY_END(io_regions); p++) {
-               if (!request_region(FDCS->address + p->offset,
+               if (!request_region(fdc_state[fdc].address + p->offset,
                                    p->size, "floppy")) {
                        DPRINT("Floppy io-port 0x%04lx in use\n",
-                              FDCS->address + p->offset);
+                              fdc_state[fdc].address + p->offset);
                        floppy_release_allocated_regions(fdc, p);
                        return -EBUSY;
                }
@@ -4839,36 +4882,36 @@ static int floppy_grab_irq_and_dma(void)
                }
        }
 
-       for (fdc = 0; fdc < N_FDC; fdc++) {
-               if (FDCS->address != -1) {
-                       if (floppy_request_regions(fdc))
+       for (current_fdc = 0; current_fdc < N_FDC; current_fdc++) {
+               if (fdc_state[current_fdc].address != -1) {
+                       if (floppy_request_regions(current_fdc))
                                goto cleanup;
                }
        }
-       for (fdc = 0; fdc < N_FDC; fdc++) {
-               if (FDCS->address != -1) {
+       for (current_fdc = 0; current_fdc < N_FDC; current_fdc++) {
+               if (fdc_state[current_fdc].address != -1) {
                        reset_fdc_info(1);
-                       fd_outb(FDCS->dor, FD_DOR);
+                       fdc_outb(fdc_state[current_fdc].dor, current_fdc, FD_DOR);
                }
        }
-       fdc = 0;
+       current_fdc = 0;
        set_dor(0, ~0, 8);      /* avoid immediate interrupt */
 
-       for (fdc = 0; fdc < N_FDC; fdc++)
-               if (FDCS->address != -1)
-                       fd_outb(FDCS->dor, FD_DOR);
+       for (current_fdc = 0; current_fdc < N_FDC; current_fdc++)
+               if (fdc_state[current_fdc].address != -1)
+                       fdc_outb(fdc_state[current_fdc].dor, current_fdc, FD_DOR);
        /*
         * The driver will try and free resources and relies on us
         * to know if they were allocated or not.
         */
-       fdc = 0;
+       current_fdc = 0;
        irqdma_allocated = 1;
        return 0;
 cleanup:
        fd_free_irq();
        fd_free_dma();
-       while (--fdc >= 0)
-               floppy_release_regions(fdc);
+       while (--current_fdc >= 0)
+               floppy_release_regions(current_fdc);
        atomic_dec(&usage_count);
        return -1;
 }
@@ -4916,11 +4959,11 @@ static void floppy_release_irq_and_dma(void)
                pr_info("auxiliary floppy timer still active\n");
        if (work_pending(&floppy_work))
                pr_info("work still pending\n");
-       old_fdc = fdc;
-       for (fdc = 0; fdc < N_FDC; fdc++)
-               if (FDCS->address != -1)
-                       floppy_release_regions(fdc);
-       fdc = old_fdc;
+       old_fdc = current_fdc;
+       for (current_fdc = 0; current_fdc < N_FDC; current_fdc++)
+               if (fdc_state[current_fdc].address != -1)
+                       floppy_release_regions(current_fdc);
+       current_fdc = old_fdc;
 }
 
 #ifdef MODULE
index 739b372..a42c49e 100644 (file)
@@ -214,7 +214,8 @@ static void __loop_update_dio(struct loop_device *lo, bool dio)
         * LO_FLAGS_READ_ONLY, both are set from kernel, and losetup
         * will get updated by ioctl(LOOP_GET_STATUS)
         */
-       blk_mq_freeze_queue(lo->lo_queue);
+       if (lo->lo_state == Lo_bound)
+               blk_mq_freeze_queue(lo->lo_queue);
        lo->use_dio = use_dio;
        if (use_dio) {
                blk_queue_flag_clear(QUEUE_FLAG_NOMERGES, lo->lo_queue);
@@ -223,7 +224,8 @@ static void __loop_update_dio(struct loop_device *lo, bool dio)
                blk_queue_flag_set(QUEUE_FLAG_NOMERGES, lo->lo_queue);
                lo->lo_flags &= ~LO_FLAGS_DIRECT_IO;
        }
-       blk_mq_unfreeze_queue(lo->lo_queue);
+       if (lo->lo_state == Lo_bound)
+               blk_mq_unfreeze_queue(lo->lo_queue);
 }
 
 static int
@@ -1539,16 +1541,16 @@ static int loop_set_block_size(struct loop_device *lo, unsigned long arg)
        if (arg < 512 || arg > PAGE_SIZE || !is_power_of_2(arg))
                return -EINVAL;
 
-       if (lo->lo_queue->limits.logical_block_size != arg) {
-               sync_blockdev(lo->lo_device);
-               kill_bdev(lo->lo_device);
-       }
+       if (lo->lo_queue->limits.logical_block_size == arg)
+               return 0;
+
+       sync_blockdev(lo->lo_device);
+       kill_bdev(lo->lo_device);
 
        blk_mq_freeze_queue(lo->lo_queue);
 
        /* kill_bdev should have truncated all the pages */
-       if (lo->lo_queue->limits.logical_block_size != arg &&
-                       lo->lo_device->bd_inode->i_mapping->nrpages) {
+       if (lo->lo_device->bd_inode->i_mapping->nrpages) {
                err = -EAGAIN;
                pr_warn("%s: loop%d (%s) has still dirty pages (nrpages=%lu)\n",
                        __func__, lo->lo_number, lo->lo_file_name,
index 7818190..43cff01 100644 (file)
@@ -395,16 +395,19 @@ static enum blk_eh_timer_return nbd_xmit_timeout(struct request *req,
        }
        config = nbd->config;
 
-       if (config->num_connections > 1) {
+       if (config->num_connections > 1 ||
+           (config->num_connections == 1 && nbd->tag_set.timeout)) {
                dev_err_ratelimited(nbd_to_dev(nbd),
                                    "Connection timed out, retrying (%d/%d alive)\n",
                                    atomic_read(&config->live_connections),
                                    config->num_connections);
                /*
                 * Hooray we have more connections, requeue this IO, the submit
-                * path will put it on a real connection.
+                * path will put it on a real connection. Or if only one
+                * connection is configured, the submit path will wait util
+                * a new connection is reconfigured or util dead timeout.
                 */
-               if (config->socks && config->num_connections > 1) {
+               if (config->socks) {
                        if (cmd->index < config->num_connections) {
                                struct nbd_sock *nsock =
                                        config->socks[cmd->index];
@@ -431,12 +434,22 @@ static enum blk_eh_timer_return nbd_xmit_timeout(struct request *req,
                 * Userspace sets timeout=0 to disable socket disconnection,
                 * so just warn and reset the timer.
                 */
+               struct nbd_sock *nsock = config->socks[cmd->index];
                cmd->retries++;
                dev_info(nbd_to_dev(nbd), "Possible stuck request %p: control (%s@%llu,%uB). Runtime %u seconds\n",
                        req, nbdcmd_to_ascii(req_to_nbd_cmd_type(req)),
                        (unsigned long long)blk_rq_pos(req) << 9,
                        blk_rq_bytes(req), (req->timeout / HZ) * cmd->retries);
 
+               mutex_lock(&nsock->tx_lock);
+               if (cmd->cookie != nsock->cookie) {
+                       nbd_requeue_cmd(cmd);
+                       mutex_unlock(&nsock->tx_lock);
+                       mutex_unlock(&cmd->lock);
+                       nbd_config_put(nbd);
+                       return BLK_EH_DONE;
+               }
+               mutex_unlock(&nsock->tx_lock);
                mutex_unlock(&cmd->lock);
                nbd_config_put(nbd);
                return BLK_EH_RESET_TIMER;
@@ -741,14 +754,12 @@ static struct nbd_cmd *nbd_read_stat(struct nbd_device *nbd, int index)
                                dev_err(disk_to_dev(nbd->disk), "Receive data failed (result %d)\n",
                                        result);
                                /*
-                                * If we've disconnected or we only have 1
-                                * connection then we need to make sure we
+                                * If we've disconnected, we need to make sure we
                                 * complete this request, otherwise error out
                                 * and let the timeout stuff handle resubmitting
                                 * this request onto another connection.
                                 */
-                               if (nbd_disconnected(config) ||
-                                   config->num_connections <= 1) {
+                               if (nbd_disconnected(config)) {
                                        cmd->status = BLK_STS_IOERR;
                                        goto out;
                                }
@@ -825,7 +836,7 @@ static int find_fallback(struct nbd_device *nbd, int index)
 
        if (config->num_connections <= 1) {
                dev_err_ratelimited(disk_to_dev(nbd->disk),
-                                   "Attempted send on invalid socket\n");
+                                   "Dead connection, failed to find a fallback\n");
                return new_index;
        }
 
index 1330604..4e1c071 100644 (file)
@@ -23,6 +23,7 @@
 #ifdef CONFIG_BLK_DEV_NULL_BLK_FAULT_INJECTION
 static DECLARE_FAULT_ATTR(null_timeout_attr);
 static DECLARE_FAULT_ATTR(null_requeue_attr);
+static DECLARE_FAULT_ATTR(null_init_hctx_attr);
 #endif
 
 static inline u64 mb_per_tick(int mbps)
@@ -96,11 +97,21 @@ module_param_named(home_node, g_home_node, int, 0444);
 MODULE_PARM_DESC(home_node, "Home node for the device");
 
 #ifdef CONFIG_BLK_DEV_NULL_BLK_FAULT_INJECTION
+/*
+ * For more details about fault injection, please refer to
+ * Documentation/fault-injection/fault-injection.rst.
+ */
 static char g_timeout_str[80];
 module_param_string(timeout, g_timeout_str, sizeof(g_timeout_str), 0444);
+MODULE_PARM_DESC(timeout, "Fault injection. timeout=<interval>,<probability>,<space>,<times>");
 
 static char g_requeue_str[80];
 module_param_string(requeue, g_requeue_str, sizeof(g_requeue_str), 0444);
+MODULE_PARM_DESC(requeue, "Fault injection. requeue=<interval>,<probability>,<space>,<times>");
+
+static char g_init_hctx_str[80];
+module_param_string(init_hctx, g_init_hctx_str, sizeof(g_init_hctx_str), 0444);
+MODULE_PARM_DESC(init_hctx, "Fault injection to fail hctx init. init_hctx=<interval>,<probability>,<space>,<times>");
 #endif
 
 static int g_queue_mode = NULL_Q_MQ;
@@ -276,7 +287,7 @@ nullb_device_##NAME##_store(struct config_item *item, const char *page,     \
 {                                                                      \
        int (*apply_fn)(struct nullb_device *dev, TYPE new_value) = APPLY;\
        struct nullb_device *dev = to_nullb_device(item);               \
-       TYPE uninitialized_var(new_value);                              \
+       TYPE new_value = 0;                                             \
        int ret;                                                        \
                                                                        \
        ret = nullb_device_##TYPE##_attr_store(&new_value, page, count);\
@@ -302,6 +313,12 @@ static int nullb_apply_submit_queues(struct nullb_device *dev,
        if (!nullb)
                return 0;
 
+       /*
+        * Make sure that null_init_hctx() does not access nullb->queues[] past
+        * the end of that array.
+        */
+       if (submit_queues > nr_cpu_ids)
+               return -EINVAL;
        set = nullb->tag_set;
        blk_mq_update_nr_hw_queues(set, submit_queues);
        return set->nr_hw_queues == submit_queues ? 0 : -ENOMEM;
@@ -605,6 +622,7 @@ static struct nullb_cmd *__alloc_cmd(struct nullb_queue *nq)
        if (tag != -1U) {
                cmd = &nq->cmds[tag];
                cmd->tag = tag;
+               cmd->error = BLK_STS_OK;
                cmd->nq = nq;
                if (nq->dev->irqmode == NULL_IRQ_TIMER) {
                        hrtimer_init(&cmd->timer, CLOCK_MONOTONIC,
@@ -1385,6 +1403,7 @@ static blk_status_t null_queue_rq(struct blk_mq_hw_ctx *hctx,
                cmd->timer.function = null_cmd_timer_expired;
        }
        cmd->rq = bd->rq;
+       cmd->error = BLK_STS_OK;
        cmd->nq = nq;
 
        blk_mq_start_request(bd->rq);
@@ -1408,12 +1427,6 @@ static blk_status_t null_queue_rq(struct blk_mq_hw_ctx *hctx,
        return null_handle_cmd(cmd, sector, nr_sectors, req_op(bd->rq));
 }
 
-static const struct blk_mq_ops null_mq_ops = {
-       .queue_rq       = null_queue_rq,
-       .complete       = null_complete_rq,
-       .timeout        = null_timeout_rq,
-};
-
 static void cleanup_queue(struct nullb_queue *nq)
 {
        kfree(nq->tag_map);
@@ -1430,9 +1443,56 @@ static void cleanup_queues(struct nullb *nullb)
        kfree(nullb->queues);
 }
 
+static void null_exit_hctx(struct blk_mq_hw_ctx *hctx, unsigned int hctx_idx)
+{
+       struct nullb_queue *nq = hctx->driver_data;
+       struct nullb *nullb = nq->dev->nullb;
+
+       nullb->nr_queues--;
+}
+
+static void null_init_queue(struct nullb *nullb, struct nullb_queue *nq)
+{
+       init_waitqueue_head(&nq->wait);
+       nq->queue_depth = nullb->queue_depth;
+       nq->dev = nullb->dev;
+}
+
+static int null_init_hctx(struct blk_mq_hw_ctx *hctx, void *driver_data,
+                         unsigned int hctx_idx)
+{
+       struct nullb *nullb = hctx->queue->queuedata;
+       struct nullb_queue *nq;
+
+#ifdef CONFIG_BLK_DEV_NULL_BLK_FAULT_INJECTION
+       if (g_init_hctx_str[0] && should_fail(&null_init_hctx_attr, 1))
+               return -EFAULT;
+#endif
+
+       nq = &nullb->queues[hctx_idx];
+       hctx->driver_data = nq;
+       null_init_queue(nullb, nq);
+       nullb->nr_queues++;
+
+       return 0;
+}
+
+static const struct blk_mq_ops null_mq_ops = {
+       .queue_rq       = null_queue_rq,
+       .complete       = null_complete_rq,
+       .timeout        = null_timeout_rq,
+       .init_hctx      = null_init_hctx,
+       .exit_hctx      = null_exit_hctx,
+};
+
 static void null_del_dev(struct nullb *nullb)
 {
-       struct nullb_device *dev = nullb->dev;
+       struct nullb_device *dev;
+
+       if (!nullb)
+               return;
+
+       dev = nullb->dev;
 
        ida_simple_remove(&nullb_indexes, nullb->index);
 
@@ -1473,33 +1533,6 @@ static const struct block_device_operations null_ops = {
        .report_zones   = null_report_zones,
 };
 
-static void null_init_queue(struct nullb *nullb, struct nullb_queue *nq)
-{
-       BUG_ON(!nullb);
-       BUG_ON(!nq);
-
-       init_waitqueue_head(&nq->wait);
-       nq->queue_depth = nullb->queue_depth;
-       nq->dev = nullb->dev;
-}
-
-static void null_init_queues(struct nullb *nullb)
-{
-       struct request_queue *q = nullb->q;
-       struct blk_mq_hw_ctx *hctx;
-       struct nullb_queue *nq;
-       int i;
-
-       queue_for_each_hw_ctx(q, hctx, i) {
-               if (!hctx->nr_ctx || !hctx->tags)
-                       continue;
-               nq = &nullb->queues[i];
-               hctx->driver_data = nq;
-               null_init_queue(nullb, nq);
-               nullb->nr_queues++;
-       }
-}
-
 static int setup_commands(struct nullb_queue *nq)
 {
        struct nullb_cmd *cmd;
@@ -1526,8 +1559,7 @@ static int setup_commands(struct nullb_queue *nq)
 
 static int setup_queues(struct nullb *nullb)
 {
-       nullb->queues = kcalloc(nullb->dev->submit_queues,
-                               sizeof(struct nullb_queue),
+       nullb->queues = kcalloc(nr_cpu_ids, sizeof(struct nullb_queue),
                                GFP_KERNEL);
        if (!nullb->queues)
                return -ENOMEM;
@@ -1669,6 +1701,8 @@ static bool null_setup_fault(void)
                return false;
        if (!__null_setup_fault(&null_requeue_attr, g_requeue_str))
                return false;
+       if (!__null_setup_fault(&null_init_hctx_attr, g_init_hctx_str))
+               return false;
 #endif
        return true;
 }
@@ -1712,19 +1746,17 @@ static int null_add_dev(struct nullb_device *dev)
                        goto out_cleanup_queues;
 
                nullb->tag_set->timeout = 5 * HZ;
-               nullb->q = blk_mq_init_queue(nullb->tag_set);
+               nullb->q = blk_mq_init_queue_data(nullb->tag_set, nullb);
                if (IS_ERR(nullb->q)) {
                        rv = -ENOMEM;
                        goto out_cleanup_tags;
                }
-               null_init_queues(nullb);
        } else if (dev->queue_mode == NULL_Q_BIO) {
-               nullb->q = blk_alloc_queue_node(GFP_KERNEL, dev->home_node);
+               nullb->q = blk_alloc_queue(null_queue_bio, dev->home_node);
                if (!nullb->q) {
                        rv = -ENOMEM;
                        goto out_cleanup_queues;
                }
-               blk_queue_make_request(nullb->q, null_queue_bio);
                rv = init_driver_queues(nullb);
                if (rv)
                        goto out_cleanup_blk_queue;
@@ -1788,6 +1820,7 @@ out_cleanup_queues:
        cleanup_queues(nullb);
 out_free_nullb:
        kfree(nullb);
+       dev->nullb = NULL;
 out:
        return rv;
 }
diff --git a/drivers/block/null_blk_trace.c b/drivers/block/null_blk_trace.c
new file mode 100644 (file)
index 0000000..f246e7b
--- /dev/null
@@ -0,0 +1,21 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * null_blk trace related helpers.
+ *
+ * Copyright (C) 2020 Western Digital Corporation or its affiliates.
+ */
+#include "null_blk_trace.h"
+
+/*
+ * Helper to use for all null_blk traces to extract disk name.
+ */
+const char *nullb_trace_disk_name(struct trace_seq *p, char *name)
+{
+       const char *ret = trace_seq_buffer_ptr(p);
+
+       if (name && *name)
+               trace_seq_printf(p, "disk=%s, ", name);
+       trace_seq_putc(p, 0);
+
+       return ret;
+}
diff --git a/drivers/block/null_blk_trace.h b/drivers/block/null_blk_trace.h
new file mode 100644 (file)
index 0000000..4f83032
--- /dev/null
@@ -0,0 +1,79 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * null_blk device driver tracepoints.
+ *
+ * Copyright (C) 2020 Western Digital Corporation or its affiliates.
+ */
+
+#undef TRACE_SYSTEM
+#define TRACE_SYSTEM nullb
+
+#if !defined(_TRACE_NULLB_H) || defined(TRACE_HEADER_MULTI_READ)
+#define _TRACE_NULLB_H
+
+#include <linux/tracepoint.h>
+#include <linux/trace_seq.h>
+
+#include "null_blk.h"
+
+const char *nullb_trace_disk_name(struct trace_seq *p, char *name);
+
+#define __print_disk_name(name) nullb_trace_disk_name(p, name)
+
+#ifndef TRACE_HEADER_MULTI_READ
+static inline void __assign_disk_name(char *name, struct gendisk *disk)
+{
+       if (disk)
+               memcpy(name, disk->disk_name, DISK_NAME_LEN);
+       else
+               memset(name, 0, DISK_NAME_LEN);
+}
+#endif
+
+TRACE_EVENT(nullb_zone_op,
+           TP_PROTO(struct nullb_cmd *cmd, unsigned int zone_no,
+                    unsigned int zone_cond),
+           TP_ARGS(cmd, zone_no, zone_cond),
+           TP_STRUCT__entry(
+               __array(char, disk, DISK_NAME_LEN)
+               __field(enum req_opf, op)
+               __field(unsigned int, zone_no)
+               __field(unsigned int, zone_cond)
+           ),
+           TP_fast_assign(
+               __entry->op = req_op(cmd->rq);
+               __entry->zone_no = zone_no;
+               __entry->zone_cond = zone_cond;
+               __assign_disk_name(__entry->disk, cmd->rq->rq_disk);
+           ),
+           TP_printk("%s req=%-15s zone_no=%u zone_cond=%-10s",
+                     __print_disk_name(__entry->disk),
+                     blk_op_str(__entry->op),
+                     __entry->zone_no,
+                     blk_zone_cond_str(__entry->zone_cond))
+);
+
+TRACE_EVENT(nullb_report_zones,
+           TP_PROTO(struct nullb *nullb, unsigned int nr_zones),
+           TP_ARGS(nullb, nr_zones),
+           TP_STRUCT__entry(
+               __array(char, disk, DISK_NAME_LEN)
+               __field(unsigned int, nr_zones)
+           ),
+           TP_fast_assign(
+               __entry->nr_zones = nr_zones;
+               __assign_disk_name(__entry->disk, nullb->disk);
+           ),
+           TP_printk("%s nr_zones=%u",
+                     __print_disk_name(__entry->disk), __entry->nr_zones)
+);
+
+#endif /* _TRACE_NULLB_H */
+
+#undef TRACE_INCLUDE_PATH
+#define TRACE_INCLUDE_PATH .
+#undef TRACE_INCLUDE_FILE
+#define TRACE_INCLUDE_FILE null_blk_trace
+
+/* This part must be outside protection */
+#include <trace/define_trace.h>
index ed34785..673618d 100644 (file)
@@ -2,6 +2,9 @@
 #include <linux/vmalloc.h>
 #include "null_blk.h"
 
+#define CREATE_TRACE_POINTS
+#include "null_blk_trace.h"
+
 /* zone_size in MBs to sectors. */
 #define ZONE_SIZE_SHIFT                11
 
@@ -80,6 +83,8 @@ int null_report_zones(struct gendisk *disk, sector_t sector,
                return 0;
 
        nr_zones = min(nr_zones, dev->nr_zones - first_zone);
+       trace_nullb_report_zones(nullb, nr_zones);
+
        for (i = 0; i < nr_zones; i++) {
                /*
                 * Stacked DM target drivers will remap the zone information by
@@ -148,6 +153,8 @@ static blk_status_t null_zone_write(struct nullb_cmd *cmd, sector_t sector,
                /* Invalid zone condition */
                return BLK_STS_IOERR;
        }
+
+       trace_nullb_zone_op(cmd, zno, zone->cond);
        return BLK_STS_OK;
 }
 
@@ -155,7 +162,8 @@ static blk_status_t null_zone_mgmt(struct nullb_cmd *cmd, enum req_opf op,
                                   sector_t sector)
 {
        struct nullb_device *dev = cmd->nq->dev;
-       struct blk_zone *zone = &dev->zones[null_zone_no(dev, sector)];
+       unsigned int zone_no = null_zone_no(dev, sector);
+       struct blk_zone *zone = &dev->zones[zone_no];
        size_t i;
 
        switch (op) {
@@ -203,6 +211,8 @@ static blk_status_t null_zone_mgmt(struct nullb_cmd *cmd, enum req_opf op,
        default:
                return BLK_STS_NOTSUPP;
        }
+
+       trace_nullb_zone_op(cmd, zone_no, zone->cond);
        return BLK_STS_OK;
 }
 
index 5f970a7..0b944ac 100644 (file)
@@ -2493,7 +2493,6 @@ static void pkt_init_queue(struct pktcdvd_device *pd)
 {
        struct request_queue *q = pd->disk->queue;
 
-       blk_queue_make_request(q, pkt_make_request);
        blk_queue_logical_block_size(q, CD_FRAMESIZE);
        blk_queue_max_hw_sectors(q, PACKET_MAX_SECTORS);
        q->queuedata = pd;
@@ -2679,6 +2678,11 @@ static unsigned int pkt_check_events(struct gendisk *disk,
        return attached_disk->fops->check_events(attached_disk, clearing);
 }
 
+static char *pkt_devnode(struct gendisk *disk, umode_t *mode)
+{
+       return kasprintf(GFP_KERNEL, "pktcdvd/%s", disk->disk_name);
+}
+
 static const struct block_device_operations pktcdvd_ops = {
        .owner =                THIS_MODULE,
        .open =                 pkt_open,
@@ -2686,13 +2690,9 @@ static const struct block_device_operations pktcdvd_ops = {
        .ioctl =                pkt_ioctl,
        .compat_ioctl =         blkdev_compat_ptr_ioctl,
        .check_events =         pkt_check_events,
+       .devnode =              pkt_devnode,
 };
 
-static char *pktcdvd_devnode(struct gendisk *gd, umode_t *mode)
-{
-       return kasprintf(GFP_KERNEL, "pktcdvd/%s", gd->disk_name);
-}
-
 /*
  * Set up mapping from pktcdvd device to CD-ROM device.
  */
@@ -2748,9 +2748,8 @@ static int pkt_setup_dev(dev_t dev, dev_t* pkt_dev)
        disk->fops = &pktcdvd_ops;
        disk->flags = GENHD_FL_REMOVABLE;
        strcpy(disk->disk_name, pd->name);
-       disk->devnode = pktcdvd_devnode;
        disk->private_data = pd;
-       disk->queue = blk_alloc_queue(GFP_KERNEL);
+       disk->queue = blk_alloc_queue(pkt_make_request, NUMA_NO_NODE);
        if (!disk->queue)
                goto out_mem2;
 
index 4628e1a..821d4d8 100644 (file)
@@ -737,7 +737,7 @@ static int ps3vram_probe(struct ps3_system_bus_device *dev)
 
        ps3vram_proc_init(dev);
 
-       queue = blk_alloc_queue(GFP_KERNEL);
+       queue = blk_alloc_queue(ps3vram_make_request, NUMA_NO_NODE);
        if (!queue) {
                dev_err(&dev->core, "blk_alloc_queue failed\n");
                error = -ENOMEM;
@@ -746,7 +746,6 @@ static int ps3vram_probe(struct ps3_system_bus_device *dev)
 
        priv->queue = queue;
        queue->queuedata = dev;
-       blk_queue_make_request(queue, ps3vram_make_request);
        blk_queue_max_segments(queue, BLK_MAX_SEGMENTS);
        blk_queue_max_segment_size(queue, BLK_MAX_SEGMENT_SIZE);
        blk_queue_max_hw_sectors(queue, BLK_SAFE_MAX_SECTORS);
index c47d28b..8ffa826 100644 (file)
@@ -248,7 +248,7 @@ int rsxx_setup_dev(struct rsxx_cardinfo *card)
                return -ENOMEM;
        }
 
-       card->queue = blk_alloc_queue(GFP_KERNEL);
+       card->queue = blk_alloc_queue(rsxx_make_request, NUMA_NO_NODE);
        if (!card->queue) {
                dev_err(CARD_TO_DEV(card), "Failed queue alloc\n");
                unregister_blkdev(card->major, DRIVER_NAME);
@@ -269,7 +269,6 @@ int rsxx_setup_dev(struct rsxx_cardinfo *card)
                blk_queue_logical_block_size(card->queue, blk_size);
        }
 
-       blk_queue_make_request(card->queue, rsxx_make_request);
        blk_queue_max_hw_sectors(card->queue, blkdev_max_hw_sectors);
        blk_queue_physical_block_size(card->queue, RSXX_HW_BLK_SIZE);
 
index 111eb65..1914f54 100644 (file)
@@ -80,7 +80,7 @@ struct dma_tracker {
 struct dma_tracker_list {
        spinlock_t              lock;
        int                     head;
-       struct dma_tracker      list[0];
+       struct dma_tracker      list[];
 };
 
 
index 4eaf97d..d84e8a8 100644 (file)
@@ -885,11 +885,9 @@ static int mm_pci_probe(struct pci_dev *dev, const struct pci_device_id *id)
        card->biotail = &card->bio;
        spin_lock_init(&card->lock);
 
-       card->queue = blk_alloc_queue_node(GFP_KERNEL, NUMA_NO_NODE);
+       card->queue = blk_alloc_queue(mm_make_request, NUMA_NO_NODE);
        if (!card->queue)
                goto failed_alloc;
-
-       blk_queue_make_request(card->queue, mm_make_request);
        card->queue->queuedata = card;
 
        tasklet_init(&card->tasklet, process_page, (unsigned long)card);
index 0736248..f9b1e70 100644 (file)
@@ -388,18 +388,15 @@ static void virtblk_update_capacity(struct virtio_blk *vblk, bool resize)
                   cap_str_10,
                   cap_str_2);
 
-       set_capacity(vblk->disk, capacity);
+       set_capacity_revalidate_and_notify(vblk->disk, capacity, true);
 }
 
 static void virtblk_config_changed_work(struct work_struct *work)
 {
        struct virtio_blk *vblk =
                container_of(work, struct virtio_blk, config_work);
-       char *envp[] = { "RESIZE=1", NULL };
 
        virtblk_update_capacity(vblk, true);
-       revalidate_disk(vblk->disk);
-       kobject_uevent_env(&disk_to_dev(vblk->disk)->kobj, KOBJ_CHANGE, envp);
 }
 
 static void virtblk_config_changed(struct virtio_device *vdev)
index 9df516a..915cf5b 100644 (file)
@@ -2338,7 +2338,6 @@ static void blkfront_connect(struct blkfront_info *info)
        unsigned long sector_size;
        unsigned int physical_sector_size;
        unsigned int binfo;
-       char *envp[] = { "RESIZE=1", NULL };
        int err, i;
        struct blkfront_ring_info *rinfo;
 
@@ -2354,10 +2353,7 @@ static void blkfront_connect(struct blkfront_info *info)
                        return;
                printk(KERN_INFO "Setting capacity to %Lu\n",
                       sectors);
-               set_capacity(info->gd, sectors);
-               revalidate_disk(info->gd);
-               kobject_uevent_env(&disk_to_dev(info->gd)->kobj,
-                                  KOBJ_CHANGE, envp);
+               set_capacity_revalidate_and_notify(info->gd, sectors, true);
 
                return;
        case BLKIF_STATE_SUSPENDED:
index 1bdb579..ebb234f 100644 (file)
@@ -33,6 +33,7 @@
 #include <linux/sysfs.h>
 #include <linux/debugfs.h>
 #include <linux/cpuhotplug.h>
+#include <linux/part_stat.h>
 
 #include "zram_drv.h"
 
@@ -1894,7 +1895,7 @@ static int zram_add(void)
 #ifdef CONFIG_ZRAM_WRITEBACK
        spin_lock_init(&zram->wb_limit_lock);
 #endif
-       queue = blk_alloc_queue(GFP_KERNEL);
+       queue = blk_alloc_queue(zram_make_request, NUMA_NO_NODE);
        if (!queue) {
                pr_err("Error allocating disk queue for device %d\n",
                        device_id);
@@ -1902,8 +1903,6 @@ static int zram_add(void)
                goto out_free_idr;
        }
 
-       blk_queue_make_request(queue, zram_make_request);
-
        /* gendisk structure */
        zram->disk = alloc_disk(1);
        if (!zram->disk) {
index 7a0fca6..7460f23 100644 (file)
@@ -99,11 +99,8 @@ static int tpm_read_log(struct tpm_chip *chip)
  *
  * If an event log is found then the securityfs files are setup to
  * export it to userspace, otherwise nothing is done.
- *
- * Returns -ENODEV if the firmware has no event log or securityfs is not
- * supported.
  */
-int tpm_bios_log_setup(struct tpm_chip *chip)
+void tpm_bios_log_setup(struct tpm_chip *chip)
 {
        const char *name = dev_name(&chip->dev);
        unsigned int cnt;
@@ -112,7 +109,7 @@ int tpm_bios_log_setup(struct tpm_chip *chip)
 
        rc = tpm_read_log(chip);
        if (rc < 0)
-               return rc;
+               return;
        log_version = rc;
 
        cnt = 0;
@@ -158,13 +155,12 @@ int tpm_bios_log_setup(struct tpm_chip *chip)
                cnt++;
        }
 
-       return 0;
+       return;
 
 err:
-       rc = PTR_ERR(chip->bios_dir[cnt]);
        chip->bios_dir[cnt] = NULL;
        tpm_bios_log_teardown(chip);
-       return rc;
+       return;
 }
 
 void tpm_bios_log_teardown(struct tpm_chip *chip)
index af347c1..a9ce66d 100644 (file)
@@ -51,7 +51,8 @@ int tpm_read_log_of(struct tpm_chip *chip)
         * endian format. For this reason, vtpm doesn't need conversion
         * but physical tpm needs the conversion.
         */
-       if (of_property_match_string(np, "compatible", "IBM,vtpm") < 0) {
+       if (of_property_match_string(np, "compatible", "IBM,vtpm") < 0 &&
+           of_property_match_string(np, "compatible", "IBM,vtpm20") < 0) {
                size = be32_to_cpup((__force __be32 *)sizep);
                base = be64_to_cpup((__force __be64 *)basep);
        } else {
index 739b1d9..2c96977 100644 (file)
@@ -115,6 +115,7 @@ static void *tpm1_bios_measurements_next(struct seq_file *m, void *v,
        u32 converted_event_size;
        u32 converted_event_type;
 
+       (*pos)++;
        converted_event_size = do_endian_conversion(event->event_size);
 
        v += sizeof(struct tcpa_event) + converted_event_size;
@@ -132,7 +133,6 @@ static void *tpm1_bios_measurements_next(struct seq_file *m, void *v,
            ((v + sizeof(struct tcpa_event) + converted_event_size) > limit))
                return NULL;
 
-       (*pos)++;
        return v;
 }
 
index b9aeda1..e741b11 100644 (file)
@@ -94,6 +94,7 @@ static void *tpm2_bios_measurements_next(struct seq_file *m, void *v,
        size_t event_size;
        void *marker;
 
+       (*pos)++;
        event_header = log->bios_event_log;
 
        if (v == SEQ_START_TOKEN) {
@@ -118,7 +119,6 @@ static void *tpm2_bios_measurements_next(struct seq_file *m, void *v,
        if (((v + event_size) >= limit) || (event_size == 0))
                return NULL;
 
-       (*pos)++;
        return v;
 }
 
index 3d6d394..5807383 100644 (file)
@@ -596,9 +596,7 @@ int tpm_chip_register(struct tpm_chip *chip)
 
        tpm_sysfs_add_device(chip);
 
-       rc = tpm_bios_log_setup(chip);
-       if (rc != 0 && rc != -ENODEV)
-               return rc;
+       tpm_bios_log_setup(chip);
 
        tpm_add_ppi(chip);
 
index 5620747..0fbcede 100644 (file)
@@ -226,6 +226,7 @@ int tpm2_auto_startup(struct tpm_chip *chip);
 void tpm2_shutdown(struct tpm_chip *chip, u16 shutdown_type);
 unsigned long tpm2_calc_ordinal_duration(struct tpm_chip *chip, u32 ordinal);
 int tpm2_probe(struct tpm_chip *chip);
+int tpm2_get_cc_attrs_tbl(struct tpm_chip *chip);
 int tpm2_find_cc(struct tpm_chip *chip, u32 cc);
 int tpm2_init_space(struct tpm_space *space);
 void tpm2_del_space(struct tpm_chip *chip, struct tpm_space *space);
@@ -235,7 +236,7 @@ int tpm2_prepare_space(struct tpm_chip *chip, struct tpm_space *space, u8 *cmd,
 int tpm2_commit_space(struct tpm_chip *chip, struct tpm_space *space, void *buf,
                      size_t *bufsiz);
 
-int tpm_bios_log_setup(struct tpm_chip *chip);
+void tpm_bios_log_setup(struct tpm_chip *chip);
 void tpm_bios_log_teardown(struct tpm_chip *chip);
 int tpm_dev_common_init(void);
 void tpm_dev_common_exit(void);
index 7603295..76f67b1 100644 (file)
@@ -615,7 +615,7 @@ out:
        return rc;
 }
 
-static int tpm2_get_cc_attrs_tbl(struct tpm_chip *chip)
+int tpm2_get_cc_attrs_tbl(struct tpm_chip *chip)
 {
        struct tpm_buf buf;
        u32 nr_commands;
index 78cc526..1a49db9 100644 (file)
@@ -29,6 +29,7 @@ static const char tpm_ibmvtpm_driver_name[] = "tpm_ibmvtpm";
 
 static const struct vio_device_id tpm_ibmvtpm_device_table[] = {
        { "IBM,vtpm", "IBM,vtpm"},
+       { "IBM,vtpm", "IBM,vtpm20"},
        { "", "" }
 };
 MODULE_DEVICE_TABLE(vio, tpm_ibmvtpm_device_table);
@@ -571,6 +572,7 @@ static irqreturn_t ibmvtpm_interrupt(int irq, void *vtpm_instance)
         */
        while ((crq = ibmvtpm_crq_get_next(ibmvtpm)) != NULL) {
                ibmvtpm_crq_process(crq, ibmvtpm);
+               wake_up_interruptible(&ibmvtpm->crq_queue.wq);
                crq->valid = 0;
                smp_wmb();
        }
@@ -618,6 +620,7 @@ static int tpm_ibmvtpm_probe(struct vio_dev *vio_dev,
        }
 
        crq_q->num_entry = CRQ_RES_BUF_SIZE / sizeof(*crq_q->crq_addr);
+       init_waitqueue_head(&crq_q->wq);
        ibmvtpm->crq_dma_handle = dma_map_single(dev, crq_q->crq_addr,
                                                 CRQ_RES_BUF_SIZE,
                                                 DMA_BIDIRECTIONAL);
@@ -670,6 +673,20 @@ static int tpm_ibmvtpm_probe(struct vio_dev *vio_dev,
        if (rc)
                goto init_irq_cleanup;
 
+       if (!strcmp(id->compat, "IBM,vtpm20")) {
+               chip->flags |= TPM_CHIP_FLAG_TPM2;
+               rc = tpm2_get_cc_attrs_tbl(chip);
+               if (rc)
+                       goto init_irq_cleanup;
+       }
+
+       if (!wait_event_timeout(ibmvtpm->crq_queue.wq,
+                               ibmvtpm->rtce_buf != NULL,
+                               HZ)) {
+               dev_err(dev, "CRQ response timed out\n");
+               goto init_irq_cleanup;
+       }
+
        return tpm_chip_register(chip);
 init_irq_cleanup:
        do {
index 7983f1a..b92aa7d 100644 (file)
@@ -26,6 +26,7 @@ struct ibmvtpm_crq_queue {
        struct ibmvtpm_crq *crq_addr;
        u32 index;
        u32 num_entry;
+       wait_queue_head_t wq;
 };
 
 struct ibmvtpm_dev {
index 37d72e8..ea759af 100644 (file)
@@ -132,7 +132,12 @@ static void cr50_wake_if_needed(struct cr50_spi_phy *cr50_phy)
 
        if (cr50_needs_waking(cr50_phy)) {
                /* Assert CS, wait 1 msec, deassert CS */
-               struct spi_transfer spi_cs_wake = { .delay_usecs = 1000 };
+               struct spi_transfer spi_cs_wake = {
+                       .delay = {
+                               .value = 1000,
+                               .unit = SPI_DELAY_UNIT_USECS
+                       }
+               };
 
                spi_sync_transfer(phy->spi_device, &spi_cs_wake, 1);
                /* Wait for it to fully wake */
index d1754fd..d967559 100644 (file)
@@ -110,7 +110,8 @@ int tpm_tis_spi_transfer(struct tpm_tis_data *data, u32 addr, u16 len,
 
                spi_xfer.cs_change = 0;
                spi_xfer.len = transfer_len;
-               spi_xfer.delay_usecs = 5;
+               spi_xfer.delay.value = 5;
+               spi_xfer.delay.unit = SPI_DELAY_UNIT_USECS;
 
                if (in) {
                        spi_xfer.tx_buf = NULL;
index 9e2e140..bb8e60d 100644 (file)
@@ -213,40 +213,34 @@ i3c_device_match_id(struct i3c_device *i3cdev,
 {
        struct i3c_device_info devinfo;
        const struct i3c_device_id *id;
+       u16 manuf, part, ext_info;
+       bool rndpid;
 
        i3c_device_get_info(i3cdev, &devinfo);
 
-       /*
-        * The lower 32bits of the provisional ID is just filled with a random
-        * value, try to match using DCR info.
-        */
-       if (!I3C_PID_RND_LOWER_32BITS(devinfo.pid)) {
-               u16 manuf = I3C_PID_MANUF_ID(devinfo.pid);
-               u16 part = I3C_PID_PART_ID(devinfo.pid);
-               u16 ext_info = I3C_PID_EXTRA_INFO(devinfo.pid);
-
-               /* First try to match by manufacturer/part ID. */
-               for (id = id_table; id->match_flags != 0; id++) {
-                       if ((id->match_flags & I3C_MATCH_MANUF_AND_PART) !=
-                           I3C_MATCH_MANUF_AND_PART)
-                               continue;
-
-                       if (manuf != id->manuf_id || part != id->part_id)
-                               continue;
-
-                       if ((id->match_flags & I3C_MATCH_EXTRA_INFO) &&
-                           ext_info != id->extra_info)
-                               continue;
-
-                       return id;
-               }
-       }
+       manuf = I3C_PID_MANUF_ID(devinfo.pid);
+       part = I3C_PID_PART_ID(devinfo.pid);
+       ext_info = I3C_PID_EXTRA_INFO(devinfo.pid);
+       rndpid = I3C_PID_RND_LOWER_32BITS(devinfo.pid);
 
-       /* Fallback to DCR match. */
        for (id = id_table; id->match_flags != 0; id++) {
                if ((id->match_flags & I3C_MATCH_DCR) &&
-                   id->dcr == devinfo.dcr)
-                       return id;
+                   id->dcr != devinfo.dcr)
+                       continue;
+
+               if ((id->match_flags & I3C_MATCH_MANUF) &&
+                   id->manuf_id != manuf)
+                       continue;
+
+               if ((id->match_flags & I3C_MATCH_PART) &&
+                   (rndpid || id->part_id != part))
+                       continue;
+
+               if ((id->match_flags & I3C_MATCH_EXTRA_INFO) &&
+                   (rndpid || id->extra_info != ext_info))
+                       continue;
+
+               return id;
        }
 
        return NULL;
index 7f8f896..d79cd6d 100644 (file)
@@ -241,12 +241,34 @@ out:
 }
 static DEVICE_ATTR_RO(hdrcap);
 
+static ssize_t modalias_show(struct device *dev,
+                            struct device_attribute *da, char *buf)
+{
+       struct i3c_device *i3c = dev_to_i3cdev(dev);
+       struct i3c_device_info devinfo;
+       u16 manuf, part, ext;
+
+       i3c_device_get_info(i3c, &devinfo);
+       manuf = I3C_PID_MANUF_ID(devinfo.pid);
+       part = I3C_PID_PART_ID(devinfo.pid);
+       ext = I3C_PID_EXTRA_INFO(devinfo.pid);
+
+       if (I3C_PID_RND_LOWER_32BITS(devinfo.pid))
+               return sprintf(buf, "i3c:dcr%02Xmanuf%04X", devinfo.dcr,
+                              manuf);
+
+       return sprintf(buf, "i3c:dcr%02Xmanuf%04Xpart%04Xext%04X",
+                      devinfo.dcr, manuf, part, ext);
+}
+static DEVICE_ATTR_RO(modalias);
+
 static struct attribute *i3c_device_attrs[] = {
        &dev_attr_bcr.attr,
        &dev_attr_dcr.attr,
        &dev_attr_pid.attr,
        &dev_attr_dynamic_address.attr,
        &dev_attr_hdrcap.attr,
+       &dev_attr_modalias.attr,
        NULL,
 };
 ATTRIBUTE_GROUPS(i3c_device);
@@ -267,7 +289,7 @@ static int i3c_device_uevent(struct device *dev, struct kobj_uevent_env *env)
                                      devinfo.dcr, manuf);
 
        return add_uevent_var(env,
-                             "MODALIAS=i3c:dcr%02Xmanuf%04Xpart%04xext%04x",
+                             "MODALIAS=i3c:dcr%02Xmanuf%04Xpart%04Xext%04X",
                              devinfo.dcr, manuf, part, ext);
 }
 
@@ -1953,7 +1975,7 @@ of_i3c_master_add_i2c_boardinfo(struct i3c_master_controller *master,
         * DEFSLVS command.
         */
        if (boardinfo->base.flags & I2C_CLIENT_TEN) {
-               dev_err(&master->dev, "I2C device with 10 bit address not supported.");
+               dev_err(dev, "I2C device with 10 bit address not supported.");
                return -ENOTSUPP;
        }
 
@@ -2138,7 +2160,7 @@ static int i3c_master_i2c_adapter_init(struct i3c_master_controller *master)
         * correctly even if one or more i2c devices are not registered.
         */
        i3c_bus_for_each_i2cdev(&master->bus, i2cdev)
-               i2cdev->dev = i2c_new_device(adap, &i2cdev->boardinfo->base);
+               i2cdev->dev = i2c_new_client_device(adap, &i2cdev->boardinfo->base);
 
        return 0;
 }
index bd26c3b..5c5306c 100644 (file)
@@ -221,7 +221,7 @@ struct dw_i3c_xfer {
        struct completion comp;
        int ret;
        unsigned int ncmds;
-       struct dw_i3c_cmd cmds[0];
+       struct dw_i3c_cmd cmds[];
 };
 
 struct dw_i3c_master {
index 5471279..3fee8bd 100644 (file)
@@ -388,7 +388,7 @@ struct cdns_i3c_xfer {
        struct completion comp;
        int ret;
        unsigned int ncmds;
-       struct cdns_i3c_cmd cmds[0];
+       struct cdns_i3c_cmd cmds[];
 };
 
 struct cdns_i3c_data {
index 7543e39..db38a68 100644 (file)
@@ -380,12 +380,11 @@ static int nvm_create_tgt(struct nvm_dev *dev, struct nvm_ioctl_create *create)
                goto err_dev;
        }
 
-       tqueue = blk_alloc_queue_node(GFP_KERNEL, dev->q->node);
+       tqueue = blk_alloc_queue(tt->make_rq, dev->q->node);
        if (!tqueue) {
                ret = -ENOMEM;
                goto err_disk;
        }
-       blk_queue_make_request(tqueue, tt->make_rq);
 
        strlcpy(tdisk->disk_name, create->tgtname, sizeof(tdisk->disk_name));
        tdisk->flags = GENHD_FL_EXT_DEVT;
index 7d8958d..6387302 100644 (file)
@@ -37,7 +37,7 @@ static ssize_t pblk_sysfs_luns_show(struct pblk *pblk, char *page)
                        active = 0;
                        up(&rlun->wr_sem);
                }
-               sz += snprintf(page + sz, PAGE_SIZE - sz,
+               sz += scnprintf(page + sz, PAGE_SIZE - sz,
                                "pblk: pos:%d, ch:%d, lun:%d - %d\n",
                                        i,
                                        rlun->bppa.a.ch,
@@ -120,7 +120,7 @@ static ssize_t pblk_sysfs_ppaf(struct pblk *pblk, char *page)
                struct nvm_addrf_12 *ppaf = (struct nvm_addrf_12 *)&pblk->addrf;
                struct nvm_addrf_12 *gppaf = (struct nvm_addrf_12 *)&geo->addrf;
 
-               sz = snprintf(page, PAGE_SIZE,
+               sz = scnprintf(page, PAGE_SIZE,
                        "g:(b:%d)blk:%d/%d,pg:%d/%d,lun:%d/%d,ch:%d/%d,pl:%d/%d,sec:%d/%d\n",
                        pblk->addrf_len,
                        ppaf->blk_offset, ppaf->blk_len,
@@ -130,7 +130,7 @@ static ssize_t pblk_sysfs_ppaf(struct pblk *pblk, char *page)
                        ppaf->pln_offset, ppaf->pln_len,
                        ppaf->sec_offset, ppaf->sec_len);
 
-               sz += snprintf(page + sz, PAGE_SIZE - sz,
+               sz += scnprintf(page + sz, PAGE_SIZE - sz,
                        "d:blk:%d/%d,pg:%d/%d,lun:%d/%d,ch:%d/%d,pl:%d/%d,sec:%d/%d\n",
                        gppaf->blk_offset, gppaf->blk_len,
                        gppaf->pg_offset, gppaf->pg_len,
@@ -142,7 +142,7 @@ static ssize_t pblk_sysfs_ppaf(struct pblk *pblk, char *page)
                struct nvm_addrf *ppaf = &pblk->addrf;
                struct nvm_addrf *gppaf = &geo->addrf;
 
-               sz = snprintf(page, PAGE_SIZE,
+               sz = scnprintf(page, PAGE_SIZE,
                        "pblk:(s:%d)ch:%d/%d,lun:%d/%d,chk:%d/%d/sec:%d/%d\n",
                        pblk->addrf_len,
                        ppaf->ch_offset, ppaf->ch_len,
@@ -150,7 +150,7 @@ static ssize_t pblk_sysfs_ppaf(struct pblk *pblk, char *page)
                        ppaf->chk_offset, ppaf->chk_len,
                        ppaf->sec_offset, ppaf->sec_len);
 
-               sz += snprintf(page + sz, PAGE_SIZE - sz,
+               sz += scnprintf(page + sz, PAGE_SIZE - sz,
                        "device:ch:%d/%d,lun:%d/%d,chk:%d/%d,sec:%d/%d\n",
                        gppaf->ch_offset, gppaf->ch_len,
                        gppaf->lun_offset, gppaf->lun_len,
@@ -278,11 +278,11 @@ static ssize_t pblk_sysfs_lines(struct pblk *pblk, char *page)
                pblk_err(pblk, "corrupted free line list:%d/%d\n",
                                                nr_free_lines, free_line_cnt);
 
-       sz = snprintf(page, PAGE_SIZE - sz,
+       sz = scnprintf(page, PAGE_SIZE - sz,
                "line: nluns:%d, nblks:%d, nsecs:%d\n",
                geo->all_luns, lm->blk_per_line, lm->sec_per_line);
 
-       sz += snprintf(page + sz, PAGE_SIZE - sz,
+       sz += scnprintf(page + sz, PAGE_SIZE - sz,
                "lines:d:%d,l:%d-f:%d,m:%d/%d,c:%d,b:%d,co:%d(d:%d,l:%d)t:%d\n",
                                        cur_data, cur_log,
                                        nr_free_lines,
@@ -292,12 +292,12 @@ static ssize_t pblk_sysfs_lines(struct pblk *pblk, char *page)
                                        d_line_cnt, l_line_cnt,
                                        l_mg->nr_lines);
 
-       sz += snprintf(page + sz, PAGE_SIZE - sz,
+       sz += scnprintf(page + sz, PAGE_SIZE - sz,
                "GC: full:%d, high:%d, mid:%d, low:%d, empty:%d, werr: %d, queue:%d\n",
                        gc_full, gc_high, gc_mid, gc_low, gc_empty, gc_werr,
                        atomic_read(&pblk->gc.read_inflight_gc));
 
-       sz += snprintf(page + sz, PAGE_SIZE - sz,
+       sz += scnprintf(page + sz, PAGE_SIZE - sz,
                "data (%d) cur:%d, left:%d, vsc:%d, s:%d, map:%d/%d (%d)\n",
                        cur_data, cur_sec, msecs, vsc, sec_in_line,
                        map_weight, lm->sec_per_line,
@@ -313,19 +313,19 @@ static ssize_t pblk_sysfs_lines_info(struct pblk *pblk, char *page)
        struct pblk_line_meta *lm = &pblk->lm;
        ssize_t sz = 0;
 
-       sz = snprintf(page, PAGE_SIZE - sz,
+       sz = scnprintf(page, PAGE_SIZE - sz,
                                "smeta - len:%d, secs:%d\n",
                                        lm->smeta_len, lm->smeta_sec);
-       sz += snprintf(page + sz, PAGE_SIZE - sz,
+       sz += scnprintf(page + sz, PAGE_SIZE - sz,
                                "emeta - len:%d, sec:%d, bb_start:%d\n",
                                        lm->emeta_len[0], lm->emeta_sec[0],
                                        lm->emeta_bb);
-       sz += snprintf(page + sz, PAGE_SIZE - sz,
+       sz += scnprintf(page + sz, PAGE_SIZE - sz,
                                "bitmap lengths: sec:%d, blk:%d, lun:%d\n",
                                        lm->sec_bitmap_len,
                                        lm->blk_bitmap_len,
                                        lm->lun_bitmap_len);
-       sz += snprintf(page + sz, PAGE_SIZE - sz,
+       sz += scnprintf(page + sz, PAGE_SIZE - sz,
                                "blk_line:%d, sec_line:%d, sec_blk:%d\n",
                                        lm->blk_per_line,
                                        lm->sec_per_line,
@@ -344,12 +344,12 @@ static ssize_t pblk_get_write_amp(u64 user, u64 gc, u64 pad,
 {
        int sz;
 
-       sz = snprintf(page, PAGE_SIZE,
+       sz = scnprintf(page, PAGE_SIZE,
                        "user:%lld gc:%lld pad:%lld WA:",
                        user, gc, pad);
 
        if (!user) {
-               sz += snprintf(page + sz, PAGE_SIZE - sz, "NaN\n");
+               sz += scnprintf(page + sz, PAGE_SIZE - sz, "NaN\n");
        } else {
                u64 wa_int;
                u32 wa_frac;
@@ -358,7 +358,7 @@ static ssize_t pblk_get_write_amp(u64 user, u64 gc, u64 pad,
                wa_int = div64_u64(wa_int, user);
                wa_int = div_u64_rem(wa_int, 100000, &wa_frac);
 
-               sz += snprintf(page + sz, PAGE_SIZE - sz, "%llu.%05u\n",
+               sz += scnprintf(page + sz, PAGE_SIZE - sz, "%llu.%05u\n",
                                                        wa_int, wa_frac);
        }
 
@@ -401,9 +401,9 @@ static ssize_t pblk_sysfs_get_padding_dist(struct pblk *pblk, char *page)
        total = atomic64_read(&pblk->nr_flush) - pblk->nr_flush_rst;
        if (!total) {
                for (i = 0; i < (buckets + 1); i++)
-                       sz += snprintf(page + sz, PAGE_SIZE - sz,
+                       sz += scnprintf(page + sz, PAGE_SIZE - sz,
                                "%d:0 ", i);
-               sz += snprintf(page + sz, PAGE_SIZE - sz, "\n");
+               sz += scnprintf(page + sz, PAGE_SIZE - sz, "\n");
 
                return sz;
        }
@@ -411,7 +411,7 @@ static ssize_t pblk_sysfs_get_padding_dist(struct pblk *pblk, char *page)
        for (i = 0; i < buckets; i++)
                total_buckets += atomic64_read(&pblk->pad_dist[i]);
 
-       sz += snprintf(page + sz, PAGE_SIZE - sz, "0:%lld%% ",
+       sz += scnprintf(page + sz, PAGE_SIZE - sz, "0:%lld%% ",
                bucket_percentage(total - total_buckets, total));
 
        for (i = 0; i < buckets; i++) {
@@ -419,10 +419,10 @@ static ssize_t pblk_sysfs_get_padding_dist(struct pblk *pblk, char *page)
 
                p = bucket_percentage(atomic64_read(&pblk->pad_dist[i]),
                                          total);
-               sz += snprintf(page + sz, PAGE_SIZE - sz, "%d:%lld%% ",
+               sz += scnprintf(page + sz, PAGE_SIZE - sz, "%d:%lld%% ",
                                i + 1, p);
        }
-       sz += snprintf(page + sz, PAGE_SIZE - sz, "\n");
+       sz += scnprintf(page + sz, PAGE_SIZE - sz, "\n");
 
        return sz;
 }
index fa872df..72856e5 100644 (file)
 
 #define insert_lock(s, b)      ((b)->level <= (s)->lock)
 
-/*
- * These macros are for recursing down the btree - they handle the details of
- * locking and looking up nodes in the cache for you. They're best treated as
- * mere syntax when reading code that uses them.
- *
- * op->lock determines whether we take a read or a write lock at a given depth.
- * If you've got a read lock and find that you need a write lock (i.e. you're
- * going to have to split), set op->lock and return -EINTR; btree_root() will
- * call you again and you'll have the correct lock.
- */
-
-/**
- * btree - recurse down the btree on a specified key
- * @fn:                function to call, which will be passed the child node
- * @key:       key to recurse on
- * @b:         parent btree node
- * @op:                pointer to struct btree_op
- */
-#define btree(fn, key, b, op, ...)                                     \
-({                                                                     \
-       int _r, l = (b)->level - 1;                                     \
-       bool _w = l <= (op)->lock;                                      \
-       struct btree *_child = bch_btree_node_get((b)->c, op, key, l,   \
-                                                 _w, b);               \
-       if (!IS_ERR(_child)) {                                          \
-               _r = bch_btree_ ## fn(_child, op, ##__VA_ARGS__);       \
-               rw_unlock(_w, _child);                                  \
-       } else                                                          \
-               _r = PTR_ERR(_child);                                   \
-       _r;                                                             \
-})
-
-/**
- * btree_root - call a function on the root of the btree
- * @fn:                function to call, which will be passed the child node
- * @c:         cache set
- * @op:                pointer to struct btree_op
- */
-#define btree_root(fn, c, op, ...)                                     \
-({                                                                     \
-       int _r = -EINTR;                                                \
-       do {                                                            \
-               struct btree *_b = (c)->root;                           \
-               bool _w = insert_lock(op, _b);                          \
-               rw_lock(_w, _b, _b->level);                             \
-               if (_b == (c)->root &&                                  \
-                   _w == insert_lock(op, _b)) {                        \
-                       _r = bch_btree_ ## fn(_b, op, ##__VA_ARGS__);   \
-               }                                                       \
-               rw_unlock(_w, _b);                                      \
-               bch_cannibalize_unlock(c);                              \
-               if (_r == -EINTR)                                       \
-                       schedule();                                     \
-       } while (_r == -EINTR);                                         \
-                                                                       \
-       finish_wait(&(c)->btree_cache_wait, &(op)->wait);               \
-       _r;                                                             \
-})
 
 static inline struct bset *write_block(struct btree *b)
 {
@@ -1848,7 +1790,7 @@ static void bch_btree_gc(struct cache_set *c)
 
        /* if CACHE_SET_IO_DISABLE set, gc thread should stop too */
        do {
-               ret = btree_root(gc_root, c, &op, &writes, &stats);
+               ret = bcache_btree_root(gc_root, c, &op, &writes, &stats);
                closure_sync(&writes);
                cond_resched();
 
@@ -1946,7 +1888,7 @@ static int bch_btree_check_recurse(struct btree *b, struct btree_op *op)
                        }
 
                        if (p)
-                               ret = btree(check_recurse, p, b, op);
+                               ret = bcache_btree(check_recurse, p, b, op);
 
                        p = k;
                } while (p && !ret);
@@ -1955,13 +1897,176 @@ static int bch_btree_check_recurse(struct btree *b, struct btree_op *op)
        return ret;
 }
 
+
+static int bch_btree_check_thread(void *arg)
+{
+       int ret;
+       struct btree_check_info *info = arg;
+       struct btree_check_state *check_state = info->state;
+       struct cache_set *c = check_state->c;
+       struct btree_iter iter;
+       struct bkey *k, *p;
+       int cur_idx, prev_idx, skip_nr;
+       int i, n;
+
+       k = p = NULL;
+       i = n = 0;
+       cur_idx = prev_idx = 0;
+       ret = 0;
+
+       /* root node keys are checked before thread created */
+       bch_btree_iter_init(&c->root->keys, &iter, NULL);
+       k = bch_btree_iter_next_filter(&iter, &c->root->keys, bch_ptr_bad);
+       BUG_ON(!k);
+
+       p = k;
+       while (k) {
+               /*
+                * Fetch a root node key index, skip the keys which
+                * should be fetched by other threads, then check the
+                * sub-tree indexed by the fetched key.
+                */
+               spin_lock(&check_state->idx_lock);
+               cur_idx = check_state->key_idx;
+               check_state->key_idx++;
+               spin_unlock(&check_state->idx_lock);
+
+               skip_nr = cur_idx - prev_idx;
+
+               while (skip_nr) {
+                       k = bch_btree_iter_next_filter(&iter,
+                                                      &c->root->keys,
+                                                      bch_ptr_bad);
+                       if (k)
+                               p = k;
+                       else {
+                               /*
+                                * No more keys to check in root node,
+                                * current checking threads are enough,
+                                * stop creating more.
+                                */
+                               atomic_set(&check_state->enough, 1);
+                               /* Update check_state->enough earlier */
+                               smp_mb__after_atomic();
+                               goto out;
+                       }
+                       skip_nr--;
+                       cond_resched();
+               }
+
+               if (p) {
+                       struct btree_op op;
+
+                       btree_node_prefetch(c->root, p);
+                       c->gc_stats.nodes++;
+                       bch_btree_op_init(&op, 0);
+                       ret = bcache_btree(check_recurse, p, c->root, &op);
+                       if (ret)
+                               goto out;
+               }
+               p = NULL;
+               prev_idx = cur_idx;
+               cond_resched();
+       }
+
+out:
+       info->result = ret;
+       /* update check_state->started among all CPUs */
+       smp_mb__before_atomic();
+       if (atomic_dec_and_test(&check_state->started))
+               wake_up(&check_state->wait);
+
+       return ret;
+}
+
+
+
+static int bch_btree_chkthread_nr(void)
+{
+       int n = num_online_cpus()/2;
+
+       if (n == 0)
+               n = 1;
+       else if (n > BCH_BTR_CHKTHREAD_MAX)
+               n = BCH_BTR_CHKTHREAD_MAX;
+
+       return n;
+}
+
 int bch_btree_check(struct cache_set *c)
 {
-       struct btree_op op;
+       int ret = 0;
+       int i;
+       struct bkey *k = NULL;
+       struct btree_iter iter;
+       struct btree_check_state *check_state;
+       char name[32];
 
-       bch_btree_op_init(&op, SHRT_MAX);
+       /* check and mark root node keys */
+       for_each_key_filter(&c->root->keys, k, &iter, bch_ptr_invalid)
+               bch_initial_mark_key(c, c->root->level, k);
+
+       bch_initial_mark_key(c, c->root->level + 1, &c->root->key);
+
+       if (c->root->level == 0)
+               return 0;
+
+       check_state = kzalloc(sizeof(struct btree_check_state), GFP_KERNEL);
+       if (!check_state)
+               return -ENOMEM;
 
-       return btree_root(check_recurse, c, &op);
+       check_state->c = c;
+       check_state->total_threads = bch_btree_chkthread_nr();
+       check_state->key_idx = 0;
+       spin_lock_init(&check_state->idx_lock);
+       atomic_set(&check_state->started, 0);
+       atomic_set(&check_state->enough, 0);
+       init_waitqueue_head(&check_state->wait);
+
+       /*
+        * Run multiple threads to check btree nodes in parallel,
+        * if check_state->enough is non-zero, it means current
+        * running check threads are enough, unncessary to create
+        * more.
+        */
+       for (i = 0; i < check_state->total_threads; i++) {
+               /* fetch latest check_state->enough earlier */
+               smp_mb__before_atomic();
+               if (atomic_read(&check_state->enough))
+                       break;
+
+               check_state->infos[i].result = 0;
+               check_state->infos[i].state = check_state;
+               snprintf(name, sizeof(name), "bch_btrchk[%u]", i);
+               atomic_inc(&check_state->started);
+
+               check_state->infos[i].thread =
+                       kthread_run(bch_btree_check_thread,
+                                   &check_state->infos[i],
+                                   name);
+               if (IS_ERR(check_state->infos[i].thread)) {
+                       pr_err("fails to run thread bch_btrchk[%d]", i);
+                       for (--i; i >= 0; i--)
+                               kthread_stop(check_state->infos[i].thread);
+                       ret = -ENOMEM;
+                       goto out;
+               }
+       }
+
+       wait_event_interruptible(check_state->wait,
+                                atomic_read(&check_state->started) == 0 ||
+                                 test_bit(CACHE_SET_IO_DISABLE, &c->flags));
+
+       for (i = 0; i < check_state->total_threads; i++) {
+               if (check_state->infos[i].result) {
+                       ret = check_state->infos[i].result;
+                       goto out;
+               }
+       }
+
+out:
+       kfree(check_state);
+       return ret;
 }
 
 void bch_initial_gc_finish(struct cache_set *c)
@@ -2401,7 +2506,7 @@ static int bch_btree_map_nodes_recurse(struct btree *b, struct btree_op *op,
 
                while ((k = bch_btree_iter_next_filter(&iter, &b->keys,
                                                       bch_ptr_bad))) {
-                       ret = btree(map_nodes_recurse, k, b,
+                       ret = bcache_btree(map_nodes_recurse, k, b,
                                    op, from, fn, flags);
                        from = NULL;
 
@@ -2419,10 +2524,10 @@ static int bch_btree_map_nodes_recurse(struct btree *b, struct btree_op *op,
 int __bch_btree_map_nodes(struct btree_op *op, struct cache_set *c,
                          struct bkey *from, btree_map_nodes_fn *fn, int flags)
 {
-       return btree_root(map_nodes_recurse, c, op, from, fn, flags);
+       return bcache_btree_root(map_nodes_recurse, c, op, from, fn, flags);
 }
 
-static int bch_btree_map_keys_recurse(struct btree *b, struct btree_op *op,
+int bch_btree_map_keys_recurse(struct btree *b, struct btree_op *op,
                                      struct bkey *from, btree_map_keys_fn *fn,
                                      int flags)
 {
@@ -2435,7 +2540,8 @@ static int bch_btree_map_keys_recurse(struct btree *b, struct btree_op *op,
        while ((k = bch_btree_iter_next_filter(&iter, &b->keys, bch_ptr_bad))) {
                ret = !b->level
                        ? fn(op, b, k)
-                       : btree(map_keys_recurse, k, b, op, from, fn, flags);
+                       : bcache_btree(map_keys_recurse, k,
+                                      b, op, from, fn, flags);
                from = NULL;
 
                if (ret != MAP_CONTINUE)
@@ -2452,7 +2558,7 @@ static int bch_btree_map_keys_recurse(struct btree *b, struct btree_op *op,
 int bch_btree_map_keys(struct btree_op *op, struct cache_set *c,
                       struct bkey *from, btree_map_keys_fn *fn, int flags)
 {
-       return btree_root(map_keys_recurse, c, op, from, fn, flags);
+       return bcache_btree_root(map_keys_recurse, c, op, from, fn, flags);
 }
 
 /* Keybuf code */
index f4dcca4..2579699 100644 (file)
@@ -145,6 +145,9 @@ struct btree {
        struct bio              *bio;
 };
 
+
+
+
 #define BTREE_FLAG(flag)                                               \
 static inline bool btree_node_ ## flag(struct btree *b)                        \
 {      return test_bit(BTREE_NODE_ ## flag, &b->flags); }              \
@@ -216,6 +219,25 @@ struct btree_op {
        unsigned int            insert_collision:1;
 };
 
+struct btree_check_state;
+struct btree_check_info {
+       struct btree_check_state        *state;
+       struct task_struct              *thread;
+       int                             result;
+};
+
+#define BCH_BTR_CHKTHREAD_MAX  64
+struct btree_check_state {
+       struct cache_set                *c;
+       int                             total_threads;
+       int                             key_idx;
+       spinlock_t                      idx_lock;
+       atomic_t                        started;
+       atomic_t                        enough;
+       wait_queue_head_t               wait;
+       struct btree_check_info         infos[BCH_BTR_CHKTHREAD_MAX];
+};
+
 static inline void bch_btree_op_init(struct btree_op *op, int write_lock_level)
 {
        memset(op, 0, sizeof(struct btree_op));
@@ -284,6 +306,65 @@ static inline void force_wake_up_gc(struct cache_set *c)
        wake_up_gc(c);
 }
 
+/*
+ * These macros are for recursing down the btree - they handle the details of
+ * locking and looking up nodes in the cache for you. They're best treated as
+ * mere syntax when reading code that uses them.
+ *
+ * op->lock determines whether we take a read or a write lock at a given depth.
+ * If you've got a read lock and find that you need a write lock (i.e. you're
+ * going to have to split), set op->lock and return -EINTR; btree_root() will
+ * call you again and you'll have the correct lock.
+ */
+
+/**
+ * btree - recurse down the btree on a specified key
+ * @fn:                function to call, which will be passed the child node
+ * @key:       key to recurse on
+ * @b:         parent btree node
+ * @op:                pointer to struct btree_op
+ */
+#define bcache_btree(fn, key, b, op, ...)                              \
+({                                                                     \
+       int _r, l = (b)->level - 1;                                     \
+       bool _w = l <= (op)->lock;                                      \
+       struct btree *_child = bch_btree_node_get((b)->c, op, key, l,   \
+                                                 _w, b);               \
+       if (!IS_ERR(_child)) {                                          \
+               _r = bch_btree_ ## fn(_child, op, ##__VA_ARGS__);       \
+               rw_unlock(_w, _child);                                  \
+       } else                                                          \
+               _r = PTR_ERR(_child);                                   \
+       _r;                                                             \
+})
+
+/**
+ * btree_root - call a function on the root of the btree
+ * @fn:                function to call, which will be passed the child node
+ * @c:         cache set
+ * @op:                pointer to struct btree_op
+ */
+#define bcache_btree_root(fn, c, op, ...)                              \
+({                                                                     \
+       int _r = -EINTR;                                                \
+       do {                                                            \
+               struct btree *_b = (c)->root;                           \
+               bool _w = insert_lock(op, _b);                          \
+               rw_lock(_w, _b, _b->level);                             \
+               if (_b == (c)->root &&                                  \
+                   _w == insert_lock(op, _b)) {                        \
+                       _r = bch_btree_ ## fn(_b, op, ##__VA_ARGS__);   \
+               }                                                       \
+               rw_unlock(_w, _b);                                      \
+               bch_cannibalize_unlock(c);                              \
+               if (_r == -EINTR)                                       \
+                       schedule();                                     \
+       } while (_r == -EINTR);                                         \
+                                                                       \
+       finish_wait(&(c)->btree_cache_wait, &(op)->wait);               \
+       _r;                                                             \
+})
+
 #define MAP_DONE       0
 #define MAP_CONTINUE   1
 
@@ -314,6 +395,9 @@ typedef int (btree_map_keys_fn)(struct btree_op *op, struct btree *b,
                                struct bkey *k);
 int bch_btree_map_keys(struct btree_op *op, struct cache_set *c,
                       struct bkey *from, btree_map_keys_fn *fn, int flags);
+int bch_btree_map_keys_recurse(struct btree *b, struct btree_op *op,
+                              struct bkey *from, btree_map_keys_fn *fn,
+                              int flags);
 
 typedef bool (keybuf_pred_fn)(struct keybuf *buf, struct bkey *k);
 
index 820d840..71a90fb 100644 (file)
@@ -1161,8 +1161,7 @@ static void quit_max_writeback_rate(struct cache_set *c,
 
 /* Cached devices - read & write stuff */
 
-static blk_qc_t cached_dev_make_request(struct request_queue *q,
-                                       struct bio *bio)
+blk_qc_t cached_dev_make_request(struct request_queue *q, struct bio *bio)
 {
        struct search *s;
        struct bcache_device *d = bio->bi_disk->private_data;
@@ -1266,7 +1265,6 @@ void bch_cached_dev_request_init(struct cached_dev *dc)
 {
        struct gendisk *g = dc->disk.disk;
 
-       g->queue->make_request_fn               = cached_dev_make_request;
        g->queue->backing_dev_info->congested_fn = cached_dev_congested;
        dc->disk.cache_miss                     = cached_dev_cache_miss;
        dc->disk.ioctl                          = cached_dev_ioctl;
@@ -1301,8 +1299,7 @@ static void flash_dev_nodata(struct closure *cl)
        continue_at(cl, search_free, NULL);
 }
 
-static blk_qc_t flash_dev_make_request(struct request_queue *q,
-                                            struct bio *bio)
+blk_qc_t flash_dev_make_request(struct request_queue *q, struct bio *bio)
 {
        struct search *s;
        struct closure *cl;
index c64dbd7..bb005c9 100644 (file)
@@ -37,7 +37,10 @@ unsigned int bch_get_congested(const struct cache_set *c);
 void bch_data_insert(struct closure *cl);
 
 void bch_cached_dev_request_init(struct cached_dev *dc);
+blk_qc_t cached_dev_make_request(struct request_queue *q, struct bio *bio);
+
 void bch_flash_dev_request_init(struct bcache_device *d);
+blk_qc_t flash_dev_make_request(struct request_queue *q, struct bio *bio);
 
 extern struct kmem_cache *bch_search_cache;
 
index 0c3c541..d98354f 100644 (file)
@@ -816,7 +816,7 @@ static void bcache_device_free(struct bcache_device *d)
 }
 
 static int bcache_device_init(struct bcache_device *d, unsigned int block_size,
-                             sector_t sectors)
+                             sector_t sectors, make_request_fn make_request_fn)
 {
        struct request_queue *q;
        const size_t max_stripes = min_t(size_t, INT_MAX,
@@ -866,11 +866,10 @@ static int bcache_device_init(struct bcache_device *d, unsigned int block_size,
        d->disk->fops           = &bcache_ops;
        d->disk->private_data   = d;
 
-       q = blk_alloc_queue(GFP_KERNEL);
+       q = blk_alloc_queue(make_request_fn, NUMA_NO_NODE);
        if (!q)
                return -ENOMEM;
 
-       blk_queue_make_request(q, NULL);
        d->disk->queue                  = q;
        q->queuedata                    = d;
        q->backing_dev_info->congested_data = d;
@@ -1339,7 +1338,8 @@ static int cached_dev_init(struct cached_dev *dc, unsigned int block_size)
                        q->limits.raid_partial_stripes_expensive;
 
        ret = bcache_device_init(&dc->disk, block_size,
-                        dc->bdev->bd_part->nr_sects - dc->sb.data_offset);
+                        dc->bdev->bd_part->nr_sects - dc->sb.data_offset,
+                        cached_dev_make_request);
        if (ret)
                return ret;
 
@@ -1451,7 +1451,8 @@ static int flash_dev_run(struct cache_set *c, struct uuid_entry *u)
 
        kobject_init(&d->kobj, &bch_flash_dev_ktype);
 
-       if (bcache_device_init(d, block_bytes(c), u->sectors))
+       if (bcache_device_init(d, block_bytes(c), u->sectors,
+                       flash_dev_make_request))
                goto err;
 
        bcache_device_attach(d, c, u - c->uuids);
index 3470fae..3232769 100644 (file)
@@ -154,7 +154,7 @@ static ssize_t bch_snprint_string_list(char *buf,
        size_t i;
 
        for (i = 0; list[i]; i++)
-               out += snprintf(out, buf + size - out,
+               out += scnprintf(out, buf + size - out,
                                i == selected ? "[%s] " : "%s ", list[i]);
 
        out[-1] = '\n';
index 4a40f9e..3f7641f 100644 (file)
@@ -183,7 +183,7 @@ static void update_writeback_rate(struct work_struct *work)
         */
        set_bit(BCACHE_DEV_RATE_DW_RUNNING, &dc->disk.flags);
        /* paired with where BCACHE_DEV_RATE_DW_RUNNING is tested */
-       smp_mb();
+       smp_mb__after_atomic();
 
        /*
         * CACHE_SET_IO_DISABLE might be set via sysfs interface,
@@ -193,7 +193,7 @@ static void update_writeback_rate(struct work_struct *work)
            test_bit(CACHE_SET_IO_DISABLE, &c->flags)) {
                clear_bit(BCACHE_DEV_RATE_DW_RUNNING, &dc->disk.flags);
                /* paired with where BCACHE_DEV_RATE_DW_RUNNING is tested */
-               smp_mb();
+               smp_mb__after_atomic();
                return;
        }
 
@@ -229,7 +229,7 @@ static void update_writeback_rate(struct work_struct *work)
         */
        clear_bit(BCACHE_DEV_RATE_DW_RUNNING, &dc->disk.flags);
        /* paired with where BCACHE_DEV_RATE_DW_RUNNING is tested */
-       smp_mb();
+       smp_mb__after_atomic();
 }
 
 static unsigned int writeback_delay(struct cached_dev *dc,
@@ -785,7 +785,9 @@ static int sectors_dirty_init_fn(struct btree_op *_op, struct btree *b,
        return MAP_CONTINUE;
 }
 
-void bch_sectors_dirty_init(struct bcache_device *d)
+static int bch_root_node_dirty_init(struct cache_set *c,
+                                    struct bcache_device *d,
+                                    struct bkey *k)
 {
        struct sectors_dirty_init op;
        int ret;
@@ -796,8 +798,13 @@ void bch_sectors_dirty_init(struct bcache_device *d)
        op.start = KEY(op.inode, 0, 0);
 
        do {
-               ret = bch_btree_map_keys(&op.op, d->c, &op.start,
-                                        sectors_dirty_init_fn, 0);
+               ret = bcache_btree(map_keys_recurse,
+                                  k,
+                                  c->root,
+                                  &op.op,
+                                  &op.start,
+                                  sectors_dirty_init_fn,
+                                  0);
                if (ret == -EAGAIN)
                        schedule_timeout_interruptible(
                                msecs_to_jiffies(INIT_KEYS_SLEEP_MS));
@@ -806,6 +813,151 @@ void bch_sectors_dirty_init(struct bcache_device *d)
                        break;
                }
        } while (ret == -EAGAIN);
+
+       return ret;
+}
+
+static int bch_dirty_init_thread(void *arg)
+{
+       struct dirty_init_thrd_info *info = arg;
+       struct bch_dirty_init_state *state = info->state;
+       struct cache_set *c = state->c;
+       struct btree_iter iter;
+       struct bkey *k, *p;
+       int cur_idx, prev_idx, skip_nr;
+       int i;
+
+       k = p = NULL;
+       i = 0;
+       cur_idx = prev_idx = 0;
+
+       bch_btree_iter_init(&c->root->keys, &iter, NULL);
+       k = bch_btree_iter_next_filter(&iter, &c->root->keys, bch_ptr_bad);
+       BUG_ON(!k);
+
+       p = k;
+
+       while (k) {
+               spin_lock(&state->idx_lock);
+               cur_idx = state->key_idx;
+               state->key_idx++;
+               spin_unlock(&state->idx_lock);
+
+               skip_nr = cur_idx - prev_idx;
+
+               while (skip_nr) {
+                       k = bch_btree_iter_next_filter(&iter,
+                                                      &c->root->keys,
+                                                      bch_ptr_bad);
+                       if (k)
+                               p = k;
+                       else {
+                               atomic_set(&state->enough, 1);
+                               /* Update state->enough earlier */
+                               smp_mb__after_atomic();
+                               goto out;
+                       }
+                       skip_nr--;
+                       cond_resched();
+               }
+
+               if (p) {
+                       if (bch_root_node_dirty_init(c, state->d, p) < 0)
+                               goto out;
+               }
+
+               p = NULL;
+               prev_idx = cur_idx;
+               cond_resched();
+       }
+
+out:
+       /* In order to wake up state->wait in time */
+       smp_mb__before_atomic();
+       if (atomic_dec_and_test(&state->started))
+               wake_up(&state->wait);
+
+       return 0;
+}
+
+static int bch_btre_dirty_init_thread_nr(void)
+{
+       int n = num_online_cpus()/2;
+
+       if (n == 0)
+               n = 1;
+       else if (n > BCH_DIRTY_INIT_THRD_MAX)
+               n = BCH_DIRTY_INIT_THRD_MAX;
+
+       return n;
+}
+
+void bch_sectors_dirty_init(struct bcache_device *d)
+{
+       int i;
+       struct bkey *k = NULL;
+       struct btree_iter iter;
+       struct sectors_dirty_init op;
+       struct cache_set *c = d->c;
+       struct bch_dirty_init_state *state;
+       char name[32];
+
+       /* Just count root keys if no leaf node */
+       if (c->root->level == 0) {
+               bch_btree_op_init(&op.op, -1);
+               op.inode = d->id;
+               op.count = 0;
+               op.start = KEY(op.inode, 0, 0);
+
+               for_each_key_filter(&c->root->keys,
+                                   k, &iter, bch_ptr_invalid)
+                       sectors_dirty_init_fn(&op.op, c->root, k);
+               return;
+       }
+
+       state = kzalloc(sizeof(struct bch_dirty_init_state), GFP_KERNEL);
+       if (!state) {
+               pr_warn("sectors dirty init failed: cannot allocate memory");
+               return;
+       }
+
+       state->c = c;
+       state->d = d;
+       state->total_threads = bch_btre_dirty_init_thread_nr();
+       state->key_idx = 0;
+       spin_lock_init(&state->idx_lock);
+       atomic_set(&state->started, 0);
+       atomic_set(&state->enough, 0);
+       init_waitqueue_head(&state->wait);
+
+       for (i = 0; i < state->total_threads; i++) {
+               /* Fetch latest state->enough earlier */
+               smp_mb__before_atomic();
+               if (atomic_read(&state->enough))
+                       break;
+
+               state->infos[i].state = state;
+               atomic_inc(&state->started);
+               snprintf(name, sizeof(name), "bch_dirty_init[%d]", i);
+
+               state->infos[i].thread =
+                       kthread_run(bch_dirty_init_thread,
+                                   &state->infos[i],
+                                   name);
+               if (IS_ERR(state->infos[i].thread)) {
+                       pr_err("fails to run thread bch_dirty_init[%d]", i);
+                       for (--i; i >= 0; i--)
+                               kthread_stop(state->infos[i].thread);
+                       goto out;
+               }
+       }
+
+       wait_event_interruptible(state->wait,
+                atomic_read(&state->started) == 0 ||
+                test_bit(CACHE_SET_IO_DISABLE, &c->flags));
+
+out:
+       kfree(state);
 }
 
 void bch_cached_dev_writeback_init(struct cached_dev *dc)
index 4e4c681..b029843 100644 (file)
@@ -16,6 +16,7 @@
 
 #define BCH_AUTO_GC_DIRTY_THRESHOLD    50
 
+#define BCH_DIRTY_INIT_THRD_MAX        64
 /*
  * 14 (16384ths) is chosen here as something that each backing device
  * should be a reasonable fraction of the share, and not to blow up
  */
 #define WRITEBACK_SHARE_SHIFT   14
 
+struct bch_dirty_init_state;
+struct dirty_init_thrd_info {
+       struct bch_dirty_init_state     *state;
+       struct task_struct              *thread;
+};
+
+struct bch_dirty_init_state {
+       struct cache_set                *c;
+       struct bcache_device            *d;
+       int                             total_threads;
+       int                             key_idx;
+       spinlock_t                      idx_lock;
+       atomic_t                        started;
+       atomic_t                        enough;
+       wait_queue_head_t               wait;
+       struct dirty_init_thrd_info     infos[BCH_DIRTY_INIT_THRD_MAX];
+};
+
 static inline uint64_t bcache_dev_sectors_dirty(struct bcache_device *d)
 {
        uint64_t i, ret = 0;
index 0413018..753302e 100644 (file)
@@ -25,6 +25,7 @@
 #include <linux/wait.h>
 #include <linux/pr.h>
 #include <linux/refcount.h>
+#include <linux/part_stat.h>
 
 #define DM_MSG_PREFIX "core"
 
@@ -1938,16 +1939,15 @@ static struct mapped_device *alloc_dev(int minor)
        INIT_LIST_HEAD(&md->table_devices);
        spin_lock_init(&md->uevent_lock);
 
-       md->queue = blk_alloc_queue_node(GFP_KERNEL, numa_node_id);
-       if (!md->queue)
-               goto bad;
-       md->queue->queuedata = md;
        /*
         * default to bio-based required ->make_request_fn until DM
         * table is loaded and md->type established. If request-based
         * table is loaded: blk-mq will override accordingly.
         */
-       blk_queue_make_request(md->queue, dm_make_request);
+       md->queue = blk_alloc_queue(dm_make_request, numa_node_id);
+       if (!md->queue)
+               goto bad;
+       md->queue->queuedata = md;
 
        md->disk = alloc_disk_node(1, md->numa_node_id);
        if (!md->disk)
index 469f551..271e8a5 100644 (file)
 #include <linux/delay.h>
 #include <linux/raid/md_p.h>
 #include <linux/raid/md_u.h>
+#include <linux/raid/detect.h>
 #include <linux/slab.h>
 #include <linux/percpu-refcount.h>
+#include <linux/part_stat.h>
 
 #include <trace/events/block.h>
 #include "md.h"
@@ -2491,12 +2493,12 @@ static int lock_rdev(struct md_rdev *rdev, dev_t dev, int shared)
 {
        int err = 0;
        struct block_device *bdev;
-       char b[BDEVNAME_SIZE];
 
        bdev = blkdev_get_by_dev(dev, FMODE_READ|FMODE_WRITE|FMODE_EXCL,
                                 shared ? (struct md_rdev *)lock_rdev : rdev);
        if (IS_ERR(bdev)) {
-               pr_warn("md: could not open %s.\n", __bdevname(dev, b));
+               pr_warn("md: could not open device unknown-block(%u,%u).\n",
+                       MAJOR(dev), MINOR(dev));
                return PTR_ERR(bdev);
        }
        rdev->bdev = bdev;
@@ -5621,12 +5623,11 @@ static int md_alloc(dev_t dev, char *name)
                mddev->hold_active = UNTIL_STOP;
 
        error = -ENOMEM;
-       mddev->queue = blk_alloc_queue(GFP_KERNEL);
+       mddev->queue = blk_alloc_queue(md_make_request, NUMA_NO_NODE);
        if (!mddev->queue)
                goto abort;
        mddev->queue->queuedata = mddev;
 
-       blk_queue_make_request(mddev->queue, md_make_request);
        blk_set_stacking_limits(&mddev->queue->limits);
 
        disk = alloc_disk(1 << shift);
@@ -6184,7 +6185,7 @@ EXPORT_SYMBOL_GPL(md_stop_writes);
 static void mddev_detach(struct mddev *mddev)
 {
        md_bitmap_wait_behind_writes(mddev);
-       if (mddev->pers && mddev->pers->quiesce) {
+       if (mddev->pers && mddev->pers->quiesce && !mddev->suspended) {
                mddev->pers->quiesce(mddev, 1);
                mddev->pers->quiesce(mddev, 0);
        }
index 677d6f4..43751fa 100644 (file)
@@ -249,13 +249,12 @@ static int nsblk_attach_disk(struct nd_namespace_blk *nsblk)
        internal_nlba = div_u64(nsblk->size, nsblk_internal_lbasize(nsblk));
        available_disk_size = internal_nlba * nsblk_sector_size(nsblk);
 
-       q = blk_alloc_queue(GFP_KERNEL);
+       q = blk_alloc_queue(nd_blk_make_request, NUMA_NO_NODE);
        if (!q)
                return -ENOMEM;
        if (devm_add_action_or_reset(dev, nd_blk_release_queue, q))
                return -ENOMEM;
 
-       blk_queue_make_request(q, nd_blk_make_request);
        blk_queue_max_hw_sectors(q, UINT_MAX);
        blk_queue_logical_block_size(q, nsblk_sector_size(nsblk));
        blk_queue_flag_set(QUEUE_FLAG_NONROT, q);
index 0d04ea3..3b09419 100644 (file)
@@ -1521,7 +1521,7 @@ static int btt_blk_init(struct btt *btt)
        struct nd_namespace_common *ndns = nd_btt->ndns;
 
        /* create a new disk and request queue for btt */
-       btt->btt_queue = blk_alloc_queue(GFP_KERNEL);
+       btt->btt_queue = blk_alloc_queue(btt_make_request, NUMA_NO_NODE);
        if (!btt->btt_queue)
                return -ENOMEM;
 
@@ -1540,7 +1540,6 @@ static int btt_blk_init(struct btt *btt)
        btt->btt_disk->queue->backing_dev_info->capabilities |=
                        BDI_CAP_SYNCHRONOUS_IO;
 
-       blk_queue_make_request(btt->btt_queue, btt_make_request);
        blk_queue_logical_block_size(btt->btt_queue, btt->sector_size);
        blk_queue_max_hw_sectors(btt->btt_queue, UINT_MAX);
        blk_queue_flag_set(QUEUE_FLAG_NONROT, btt->btt_queue);
index 4eae441..4ffc6f7 100644 (file)
@@ -395,7 +395,7 @@ static int pmem_attach_disk(struct device *dev,
                return -EBUSY;
        }
 
-       q = blk_alloc_queue_node(GFP_KERNEL, dev_to_node(dev));
+       q = blk_alloc_queue(pmem_make_request, dev_to_node(dev));
        if (!q)
                return -ENOMEM;
 
@@ -433,7 +433,6 @@ static int pmem_attach_disk(struct device *dev,
        pmem->virt_addr = addr;
 
        blk_queue_write_cache(q, true, fua);
-       blk_queue_make_request(q, pmem_make_request);
        blk_queue_physical_block_size(q, PAGE_SIZE);
        blk_queue_logical_block_size(q, pmem_sector_size(ndns));
        blk_queue_max_hw_sectors(q, UINT_MAX);
index b9358db..9c17ed3 100644 (file)
@@ -32,8 +32,6 @@ config NVME_HWMON
          a hardware monitoring device will be created for each NVMe drive
          in the system.
 
-         If unsure, say N.
-
 config NVME_FABRICS
        tristate
 
index a4d8c90..4f907e3 100644 (file)
@@ -171,7 +171,6 @@ static void nvme_do_delete_ctrl(struct nvme_ctrl *ctrl)
        nvme_remove_namespaces(ctrl);
        ctrl->ops->delete_ctrl(ctrl);
        nvme_uninit_ctrl(ctrl);
-       nvme_put_ctrl(ctrl);
 }
 
 static void nvme_delete_ctrl_work(struct work_struct *work)
@@ -192,21 +191,16 @@ int nvme_delete_ctrl(struct nvme_ctrl *ctrl)
 }
 EXPORT_SYMBOL_GPL(nvme_delete_ctrl);
 
-static int nvme_delete_ctrl_sync(struct nvme_ctrl *ctrl)
+static void nvme_delete_ctrl_sync(struct nvme_ctrl *ctrl)
 {
-       int ret = 0;
-
        /*
         * Keep a reference until nvme_do_delete_ctrl() complete,
         * since ->delete_ctrl can free the controller.
         */
        nvme_get_ctrl(ctrl);
-       if (!nvme_change_ctrl_state(ctrl, NVME_CTRL_DELETING))
-               ret = -EBUSY;
-       if (!ret)
+       if (nvme_change_ctrl_state(ctrl, NVME_CTRL_DELETING))
                nvme_do_delete_ctrl(ctrl);
        nvme_put_ctrl(ctrl);
-       return ret;
 }
 
 static inline bool nvme_ns_has_pi(struct nvme_ns *ns)
@@ -291,11 +285,8 @@ void nvme_complete_rq(struct request *req)
                nvme_req(req)->ctrl->comp_seen = true;
 
        if (unlikely(status != BLK_STS_OK && nvme_req_needs_retry(req))) {
-               if ((req->cmd_flags & REQ_NVME_MPATH) &&
-                   blk_path_error(status)) {
-                       nvme_failover_req(req);
+               if ((req->cmd_flags & REQ_NVME_MPATH) && nvme_failover_req(req))
                        return;
-               }
 
                if (!blk_queue_dying(req->q)) {
                        nvme_retry_req(req);
@@ -1055,6 +1046,43 @@ static int nvme_identify_ctrl(struct nvme_ctrl *dev, struct nvme_id_ctrl **id)
        return error;
 }
 
+static int nvme_process_ns_desc(struct nvme_ctrl *ctrl, struct nvme_ns_ids *ids,
+               struct nvme_ns_id_desc *cur)
+{
+       const char *warn_str = "ctrl returned bogus length:";
+       void *data = cur;
+
+       switch (cur->nidt) {
+       case NVME_NIDT_EUI64:
+               if (cur->nidl != NVME_NIDT_EUI64_LEN) {
+                       dev_warn(ctrl->device, "%s %d for NVME_NIDT_EUI64\n",
+                                warn_str, cur->nidl);
+                       return -1;
+               }
+               memcpy(ids->eui64, data + sizeof(*cur), NVME_NIDT_EUI64_LEN);
+               return NVME_NIDT_EUI64_LEN;
+       case NVME_NIDT_NGUID:
+               if (cur->nidl != NVME_NIDT_NGUID_LEN) {
+                       dev_warn(ctrl->device, "%s %d for NVME_NIDT_NGUID\n",
+                                warn_str, cur->nidl);
+                       return -1;
+               }
+               memcpy(ids->nguid, data + sizeof(*cur), NVME_NIDT_NGUID_LEN);
+               return NVME_NIDT_NGUID_LEN;
+       case NVME_NIDT_UUID:
+               if (cur->nidl != NVME_NIDT_UUID_LEN) {
+                       dev_warn(ctrl->device, "%s %d for NVME_NIDT_UUID\n",
+                                warn_str, cur->nidl);
+                       return -1;
+               }
+               uuid_copy(&ids->uuid, data + sizeof(*cur));
+               return NVME_NIDT_UUID_LEN;
+       default:
+               /* Skip unknown types */
+               return cur->nidl;
+       }
+}
+
 static int nvme_identify_ns_descs(struct nvme_ctrl *ctrl, unsigned nsid,
                struct nvme_ns_ids *ids)
 {
@@ -1074,8 +1102,17 @@ static int nvme_identify_ns_descs(struct nvme_ctrl *ctrl, unsigned nsid,
 
        status = nvme_submit_sync_cmd(ctrl->admin_q, &c, data,
                                      NVME_IDENTIFY_DATA_SIZE);
-       if (status)
+       if (status) {
+               dev_warn(ctrl->device,
+                       "Identify Descriptors failed (%d)\n", status);
+                /*
+                 * Don't treat an error as fatal, as we potentially already
+                 * have a NGUID or EUI-64.
+                 */
+               if (status > 0)
+                       status = 0;
                goto free_data;
+       }
 
        for (pos = 0; pos < NVME_IDENTIFY_DATA_SIZE; pos += len) {
                struct nvme_ns_id_desc *cur = data + pos;
@@ -1083,42 +1120,9 @@ static int nvme_identify_ns_descs(struct nvme_ctrl *ctrl, unsigned nsid,
                if (cur->nidl == 0)
                        break;
 
-               switch (cur->nidt) {
-               case NVME_NIDT_EUI64:
-                       if (cur->nidl != NVME_NIDT_EUI64_LEN) {
-                               dev_warn(ctrl->device,
-                                        "ctrl returned bogus length: %d for NVME_NIDT_EUI64\n",
-                                        cur->nidl);
-                               goto free_data;
-                       }
-                       len = NVME_NIDT_EUI64_LEN;
-                       memcpy(ids->eui64, data + pos + sizeof(*cur), len);
-                       break;
-               case NVME_NIDT_NGUID:
-                       if (cur->nidl != NVME_NIDT_NGUID_LEN) {
-                               dev_warn(ctrl->device,
-                                        "ctrl returned bogus length: %d for NVME_NIDT_NGUID\n",
-                                        cur->nidl);
-                               goto free_data;
-                       }
-                       len = NVME_NIDT_NGUID_LEN;
-                       memcpy(ids->nguid, data + pos + sizeof(*cur), len);
-                       break;
-               case NVME_NIDT_UUID:
-                       if (cur->nidl != NVME_NIDT_UUID_LEN) {
-                               dev_warn(ctrl->device,
-                                        "ctrl returned bogus length: %d for NVME_NIDT_UUID\n",
-                                        cur->nidl);
-                               goto free_data;
-                       }
-                       len = NVME_NIDT_UUID_LEN;
-                       uuid_copy(&ids->uuid, data + pos + sizeof(*cur));
-                       break;
-               default:
-                       /* Skip unknown types */
-                       len = cur->nidl;
-                       break;
-               }
+               len = nvme_process_ns_desc(ctrl, ids, cur);
+               if (len < 0)
+                       goto free_data;
 
                len += sizeof(*cur);
        }
@@ -1584,6 +1588,47 @@ static int nvme_ioctl(struct block_device *bdev, fmode_t mode,
        return ret;
 }
 
+#ifdef CONFIG_COMPAT
+struct nvme_user_io32 {
+       __u8    opcode;
+       __u8    flags;
+       __u16   control;
+       __u16   nblocks;
+       __u16   rsvd;
+       __u64   metadata;
+       __u64   addr;
+       __u64   slba;
+       __u32   dsmgmt;
+       __u32   reftag;
+       __u16   apptag;
+       __u16   appmask;
+} __attribute__((__packed__));
+
+#define NVME_IOCTL_SUBMIT_IO32 _IOW('N', 0x42, struct nvme_user_io32)
+
+static int nvme_compat_ioctl(struct block_device *bdev, fmode_t mode,
+               unsigned int cmd, unsigned long arg)
+{
+       /*
+        * Corresponds to the difference of NVME_IOCTL_SUBMIT_IO
+        * between 32 bit programs and 64 bit kernel.
+        * The cause is that the results of sizeof(struct nvme_user_io),
+        * which is used to define NVME_IOCTL_SUBMIT_IO,
+        * are not same between 32 bit compiler and 64 bit compiler.
+        * NVME_IOCTL_SUBMIT_IO32 is for 64 bit kernel handling
+        * NVME_IOCTL_SUBMIT_IO issued from 32 bit programs.
+        * Other IOCTL numbers are same between 32 bit and 64 bit.
+        * So there is nothing to do regarding to other IOCTL numbers.
+        */
+       if (cmd == NVME_IOCTL_SUBMIT_IO32)
+               return nvme_ioctl(bdev, mode, NVME_IOCTL_SUBMIT_IO, arg);
+
+       return nvme_ioctl(bdev, mode, cmd, arg);
+}
+#else
+#define nvme_compat_ioctl      NULL
+#endif /* CONFIG_COMPAT */
+
 static int nvme_open(struct block_device *bdev, fmode_t mode)
 {
        struct nvme_ns *ns = bdev->bd_disk->private_data;
@@ -1721,26 +1766,15 @@ static void nvme_config_write_zeroes(struct gendisk *disk, struct nvme_ns *ns)
 static int nvme_report_ns_ids(struct nvme_ctrl *ctrl, unsigned int nsid,
                struct nvme_id_ns *id, struct nvme_ns_ids *ids)
 {
-       int ret = 0;
-
        memset(ids, 0, sizeof(*ids));
 
        if (ctrl->vs >= NVME_VS(1, 1, 0))
                memcpy(ids->eui64, id->eui64, sizeof(id->eui64));
        if (ctrl->vs >= NVME_VS(1, 2, 0))
                memcpy(ids->nguid, id->nguid, sizeof(id->nguid));
-       if (ctrl->vs >= NVME_VS(1, 3, 0)) {
-                /* Don't treat error as fatal we potentially
-                 * already have a NGUID or EUI-64
-                 */
-               ret = nvme_identify_ns_descs(ctrl, nsid, ids);
-               if (ret)
-                       dev_warn(ctrl->device,
-                                "Identify Descriptors failed (%d)\n", ret);
-               if (ret > 0)
-                       ret = 0;
-       }
-       return ret;
+       if (ctrl->vs >= NVME_VS(1, 3, 0))
+               return nvme_identify_ns_descs(ctrl, nsid, ids);
+       return 0;
 }
 
 static bool nvme_ns_ids_valid(struct nvme_ns_ids *ids)
@@ -1810,7 +1844,7 @@ static void nvme_update_disk_info(struct gendisk *disk,
            ns->lba_shift > PAGE_SHIFT)
                capacity = 0;
 
-       set_capacity(disk, capacity);
+       set_capacity_revalidate_and_notify(disk, capacity, false);
 
        nvme_config_discard(disk, ns);
        nvme_config_write_zeroes(disk, ns);
@@ -2027,7 +2061,7 @@ EXPORT_SYMBOL_GPL(nvme_sec_submit);
 static const struct block_device_operations nvme_fops = {
        .owner          = THIS_MODULE,
        .ioctl          = nvme_ioctl,
-       .compat_ioctl   = nvme_ioctl,
+       .compat_ioctl   = nvme_compat_ioctl,
        .open           = nvme_open,
        .release        = nvme_release,
        .getgeo         = nvme_getgeo,
@@ -2055,7 +2089,7 @@ const struct block_device_operations nvme_ns_head_ops = {
        .open           = nvme_ns_head_open,
        .release        = nvme_ns_head_release,
        .ioctl          = nvme_ioctl,
-       .compat_ioctl   = nvme_ioctl,
+       .compat_ioctl   = nvme_compat_ioctl,
        .getgeo         = nvme_getgeo,
        .pr_ops         = &nvme_pr_ops,
 };
@@ -2074,13 +2108,13 @@ static int nvme_wait_ready(struct nvme_ctrl *ctrl, u64 cap, bool enabled)
                if ((csts & NVME_CSTS_RDY) == bit)
                        break;
 
-               msleep(100);
+               usleep_range(1000, 2000);
                if (fatal_signal_pending(current))
                        return -EINTR;
                if (time_after(jiffies, timeout)) {
                        dev_err(ctrl->device,
-                               "Device not ready; aborting %s\n", enabled ?
-                                               "initialisation" : "reset");
+                               "Device not ready; aborting %s, CSTS=0x%x\n",
+                               enabled ? "initialisation" : "reset", csts);
                        return -ENODEV;
                }
        }
@@ -2591,8 +2625,7 @@ static bool nvme_validate_cntlid(struct nvme_subsystem *subsys,
        lockdep_assert_held(&nvme_subsystems_lock);
 
        list_for_each_entry(tmp, &subsys->ctrls, subsys_entry) {
-               if (tmp->state == NVME_CTRL_DELETING ||
-                   tmp->state == NVME_CTRL_DEAD)
+               if (nvme_state_terminal(tmp))
                        continue;
 
                if (tmp->cntlid == ctrl->cntlid) {
@@ -3193,6 +3226,10 @@ static ssize_t nvme_sysfs_delete(struct device *dev,
 {
        struct nvme_ctrl *ctrl = dev_get_drvdata(dev);
 
+       /* Can't delete non-created controllers */
+       if (!ctrl->created)
+               return -EBUSY;
+
        if (device_remove_file_self(dev, attr))
                nvme_delete_ctrl_sync(ctrl);
        return count;
@@ -3242,6 +3279,26 @@ static ssize_t nvme_sysfs_show_subsysnqn(struct device *dev,
 }
 static DEVICE_ATTR(subsysnqn, S_IRUGO, nvme_sysfs_show_subsysnqn, NULL);
 
+static ssize_t nvme_sysfs_show_hostnqn(struct device *dev,
+                                       struct device_attribute *attr,
+                                       char *buf)
+{
+       struct nvme_ctrl *ctrl = dev_get_drvdata(dev);
+
+       return snprintf(buf, PAGE_SIZE, "%s\n", ctrl->opts->host->nqn);
+}
+static DEVICE_ATTR(hostnqn, S_IRUGO, nvme_sysfs_show_hostnqn, NULL);
+
+static ssize_t nvme_sysfs_show_hostid(struct device *dev,
+                                       struct device_attribute *attr,
+                                       char *buf)
+{
+       struct nvme_ctrl *ctrl = dev_get_drvdata(dev);
+
+       return snprintf(buf, PAGE_SIZE, "%pU\n", &ctrl->opts->host->id);
+}
+static DEVICE_ATTR(hostid, S_IRUGO, nvme_sysfs_show_hostid, NULL);
+
 static ssize_t nvme_sysfs_show_address(struct device *dev,
                                         struct device_attribute *attr,
                                         char *buf)
@@ -3267,6 +3324,8 @@ static struct attribute *nvme_dev_attrs[] = {
        &dev_attr_numa_node.attr,
        &dev_attr_queue_count.attr,
        &dev_attr_sqsize.attr,
+       &dev_attr_hostnqn.attr,
+       &dev_attr_hostid.attr,
        NULL
 };
 
@@ -3280,6 +3339,10 @@ static umode_t nvme_dev_attrs_are_visible(struct kobject *kobj,
                return 0;
        if (a == &dev_attr_address.attr && !ctrl->ops->get_address)
                return 0;
+       if (a == &dev_attr_hostnqn.attr && !ctrl->opts)
+               return 0;
+       if (a == &dev_attr_hostid.attr && !ctrl->opts)
+               return 0;
 
        return a->mode;
 }
@@ -3294,7 +3357,7 @@ static const struct attribute_group *nvme_dev_attr_groups[] = {
        NULL,
 };
 
-static struct nvme_ns_head *__nvme_find_ns_head(struct nvme_subsystem *subsys,
+static struct nvme_ns_head *nvme_find_ns_head(struct nvme_subsystem *subsys,
                unsigned nsid)
 {
        struct nvme_ns_head *h;
@@ -3327,7 +3390,8 @@ static int __nvme_check_ids(struct nvme_subsystem *subsys,
 }
 
 static struct nvme_ns_head *nvme_alloc_ns_head(struct nvme_ctrl *ctrl,
-               unsigned nsid, struct nvme_id_ns *id)
+               unsigned nsid, struct nvme_id_ns *id,
+               struct nvme_ns_ids *ids)
 {
        struct nvme_ns_head *head;
        size_t size = sizeof(*head);
@@ -3350,12 +3414,9 @@ static struct nvme_ns_head *nvme_alloc_ns_head(struct nvme_ctrl *ctrl,
                goto out_ida_remove;
        head->subsys = ctrl->subsys;
        head->ns_id = nsid;
+       head->ids = *ids;
        kref_init(&head->ref);
 
-       ret = nvme_report_ns_ids(ctrl, nsid, id, &head->ids);
-       if (ret)
-               goto out_cleanup_srcu;
-
        ret = __nvme_check_ids(ctrl->subsys, head);
        if (ret) {
                dev_err(ctrl->device,
@@ -3390,24 +3451,23 @@ static int nvme_init_ns_head(struct nvme_ns *ns, unsigned nsid,
        struct nvme_ctrl *ctrl = ns->ctrl;
        bool is_shared = id->nmic & (1 << 0);
        struct nvme_ns_head *head = NULL;
+       struct nvme_ns_ids ids;
        int ret = 0;
 
+       ret = nvme_report_ns_ids(ctrl, nsid, id, &ids);
+       if (ret)
+               goto out;
+
        mutex_lock(&ctrl->subsys->lock);
        if (is_shared)
-               head = __nvme_find_ns_head(ctrl->subsys, nsid);
+               head = nvme_find_ns_head(ctrl->subsys, nsid);
        if (!head) {
-               head = nvme_alloc_ns_head(ctrl, nsid, id);
+               head = nvme_alloc_ns_head(ctrl, nsid, id, &ids);
                if (IS_ERR(head)) {
                        ret = PTR_ERR(head);
                        goto out_unlock;
                }
        } else {
-               struct nvme_ns_ids ids;
-
-               ret = nvme_report_ns_ids(ctrl, nsid, id, &ids);
-               if (ret)
-                       goto out_unlock;
-
                if (!nvme_ns_ids_equal(&head->ids, &ids)) {
                        dev_err(ctrl->device,
                                "IDs don't match for shared namespace %d\n",
@@ -3422,6 +3482,7 @@ static int nvme_init_ns_head(struct nvme_ns *ns, unsigned nsid,
 
 out_unlock:
        mutex_unlock(&ctrl->subsys->lock);
+out:
        if (ret > 0)
                ret = blk_status_to_errno(nvme_error_status(ret));
        return ret;
@@ -3480,7 +3541,7 @@ static int nvme_setup_streams_ns(struct nvme_ctrl *ctrl, struct nvme_ns *ns)
        return 0;
 }
 
-static int nvme_alloc_ns(struct nvme_ctrl *ctrl, unsigned nsid)
+static void nvme_alloc_ns(struct nvme_ctrl *ctrl, unsigned nsid)
 {
        struct nvme_ns *ns;
        struct gendisk *disk;
@@ -3490,13 +3551,11 @@ static int nvme_alloc_ns(struct nvme_ctrl *ctrl, unsigned nsid)
 
        ns = kzalloc_node(sizeof(*ns), GFP_KERNEL, node);
        if (!ns)
-               return -ENOMEM;
+               return;
 
        ns->queue = blk_mq_init_queue(ctrl->tagset);
-       if (IS_ERR(ns->queue)) {
-               ret = PTR_ERR(ns->queue);
+       if (IS_ERR(ns->queue))
                goto out_free_ns;
-       }
 
        if (ctrl->opts && ctrl->opts->data_digest)
                ns->queue->backing_dev_info->capabilities
@@ -3519,10 +3578,8 @@ static int nvme_alloc_ns(struct nvme_ctrl *ctrl, unsigned nsid)
        if (ret)
                goto out_free_queue;
 
-       if (id->ncap == 0) {
-               ret = -EINVAL;
+       if (id->ncap == 0)      /* no namespace (legacy quirk) */
                goto out_free_id;
-       }
 
        ret = nvme_init_ns_head(ns, nsid, id);
        if (ret)
@@ -3531,10 +3588,8 @@ static int nvme_alloc_ns(struct nvme_ctrl *ctrl, unsigned nsid)
        nvme_set_disk_name(disk_name, ns, ctrl, &flags);
 
        disk = alloc_disk_node(0, node);
-       if (!disk) {
-               ret = -ENOMEM;
+       if (!disk)
                goto out_unlink_ns;
-       }
 
        disk->fops = &nvme_fops;
        disk->private_data = ns;
@@ -3565,7 +3620,7 @@ static int nvme_alloc_ns(struct nvme_ctrl *ctrl, unsigned nsid)
        nvme_fault_inject_init(&ns->fault_inject, ns->disk->disk_name);
        kfree(id);
 
-       return 0;
+       return;
  out_put_disk:
        put_disk(ns->disk);
  out_unlink_ns:
@@ -3579,9 +3634,6 @@ static int nvme_alloc_ns(struct nvme_ctrl *ctrl, unsigned nsid)
        blk_cleanup_queue(ns->queue);
  out_free_ns:
        kfree(ns);
-       if (ret > 0)
-               ret = blk_status_to_errno(nvme_error_status(ret));
-       return ret;
 }
 
 static void nvme_ns_remove(struct nvme_ns *ns)
@@ -3987,6 +4039,7 @@ void nvme_start_ctrl(struct nvme_ctrl *ctrl)
                nvme_queue_scan(ctrl);
                nvme_start_queues(ctrl);
        }
+       ctrl->created = true;
 }
 EXPORT_SYMBOL_GPL(nvme_start_ctrl);
 
@@ -3995,6 +4048,7 @@ void nvme_uninit_ctrl(struct nvme_ctrl *ctrl)
        nvme_fault_inject_fini(&ctrl->fault_inject);
        dev_pm_qos_hide_latency_tolerance(ctrl->device);
        cdev_device_del(&ctrl->cdev, ctrl->device);
+       nvme_put_ctrl(ctrl);
 }
 EXPORT_SYMBOL_GPL(nvme_uninit_ctrl);
 
@@ -4077,6 +4131,7 @@ int nvme_init_ctrl(struct nvme_ctrl *ctrl, struct device *dev,
        if (ret)
                goto out_release_instance;
 
+       nvme_get_ctrl(ctrl);
        cdev_init(&ctrl->cdev, &nvme_dev_fops);
        ctrl->cdev.owner = ops->module;
        ret = cdev_device_add(&ctrl->cdev, ctrl->device);
@@ -4095,6 +4150,7 @@ int nvme_init_ctrl(struct nvme_ctrl *ctrl, struct device *dev,
 
        return 0;
 out_free_name:
+       nvme_put_ctrl(ctrl);
        kfree_const(ctrl->device->kobj.name);
 out_release_instance:
        ida_simple_remove(&nvme_instance_ida, ctrl->instance);
@@ -4299,6 +4355,7 @@ static void __exit nvme_core_exit(void)
        destroy_workqueue(nvme_delete_wq);
        destroy_workqueue(nvme_reset_wq);
        destroy_workqueue(nvme_wq);
+       ida_destroy(&nvme_instance_ida);
 }
 
 MODULE_LICENSE("GPL");
index 74b8818..2a6c819 100644 (file)
@@ -105,14 +105,14 @@ int nvmf_get_address(struct nvme_ctrl *ctrl, char *buf, int size)
        int len = 0;
 
        if (ctrl->opts->mask & NVMF_OPT_TRADDR)
-               len += snprintf(buf, size, "traddr=%s", ctrl->opts->traddr);
+               len += scnprintf(buf, size, "traddr=%s", ctrl->opts->traddr);
        if (ctrl->opts->mask & NVMF_OPT_TRSVCID)
-               len += snprintf(buf + len, size - len, "%strsvcid=%s",
+               len += scnprintf(buf + len, size - len, "%strsvcid=%s",
                                (len) ? "," : "", ctrl->opts->trsvcid);
        if (ctrl->opts->mask & NVMF_OPT_HOST_TRADDR)
-               len += snprintf(buf + len, size - len, "%shost_traddr=%s",
+               len += scnprintf(buf + len, size - len, "%shost_traddr=%s",
                                (len) ? "," : "", ctrl->opts->host_traddr);
-       len += snprintf(buf + len, size - len, "\n");
+       len += scnprintf(buf + len, size - len, "\n");
 
        return len;
 }
index 5a70ac3..a8bf2fb 100644 (file)
@@ -3181,10 +3181,7 @@ nvme_fc_init_ctrl(struct device *dev, struct nvmf_ctrl_options *opts,
                goto fail_ctrl;
        }
 
-       nvme_get_ctrl(&ctrl->ctrl);
-
        if (!queue_delayed_work(nvme_wq, &ctrl->connect_work, 0)) {
-               nvme_put_ctrl(&ctrl->ctrl);
                dev_err(ctrl->ctrl.device,
                        "NVME-FC{%d}: failed to schedule initial connect\n",
                        ctrl->cnum);
index a11900c..61bf875 100644 (file)
@@ -64,17 +64,12 @@ void nvme_set_disk_name(char *disk_name, struct nvme_ns *ns,
        }
 }
 
-void nvme_failover_req(struct request *req)
+bool nvme_failover_req(struct request *req)
 {
        struct nvme_ns *ns = req->q->queuedata;
        u16 status = nvme_req(req)->status;
        unsigned long flags;
 
-       spin_lock_irqsave(&ns->head->requeue_lock, flags);
-       blk_steal_bios(&ns->head->requeue_list, req);
-       spin_unlock_irqrestore(&ns->head->requeue_lock, flags);
-       blk_mq_end_request(req, 0);
-
        switch (status & 0x7ff) {
        case NVME_SC_ANA_TRANSITION:
        case NVME_SC_ANA_INACCESSIBLE:
@@ -103,15 +98,17 @@ void nvme_failover_req(struct request *req)
                nvme_mpath_clear_current_path(ns);
                break;
        default:
-               /*
-                * Reset the controller for any non-ANA error as we don't know
-                * what caused the error.
-                */
-               nvme_reset_ctrl(ns->ctrl);
-               break;
+               /* This was a non-ANA error so follow the normal error path. */
+               return false;
        }
 
+       spin_lock_irqsave(&ns->head->requeue_lock, flags);
+       blk_steal_bios(&ns->head->requeue_list, req);
+       spin_unlock_irqrestore(&ns->head->requeue_lock, flags);
+       blk_mq_end_request(req, 0);
+
        kblockd_schedule_work(&ns->head->requeue_work);
+       return true;
 }
 
 void nvme_kick_requeue_lists(struct nvme_ctrl *ctrl)
@@ -377,11 +374,10 @@ int nvme_mpath_alloc_disk(struct nvme_ctrl *ctrl, struct nvme_ns_head *head)
        if (!(ctrl->subsys->cmic & (1 << 1)) || !multipath)
                return 0;
 
-       q = blk_alloc_queue_node(GFP_KERNEL, ctrl->numa_node);
+       q = blk_alloc_queue(nvme_ns_head_make_request, ctrl->numa_node);
        if (!q)
                goto out;
        q->queuedata = head;
-       blk_queue_make_request(q, nvme_ns_head_make_request);
        blk_queue_flag_set(QUEUE_FLAG_NONROT, q);
        /* set to a default value for 512 until disk is validated */
        blk_queue_logical_block_size(q, 512);
index 1024fec..2e04a36 100644 (file)
@@ -259,6 +259,7 @@ struct nvme_ctrl {
        struct nvme_command ka_cmd;
        struct work_struct fw_act_work;
        unsigned long events;
+       bool created;
 
 #ifdef CONFIG_NVME_MULTIPATH
        /* asymmetric namespace access: */
@@ -550,7 +551,7 @@ void nvme_mpath_wait_freeze(struct nvme_subsystem *subsys);
 void nvme_mpath_start_freeze(struct nvme_subsystem *subsys);
 void nvme_set_disk_name(char *disk_name, struct nvme_ns *ns,
                        struct nvme_ctrl *ctrl, int *flags);
-void nvme_failover_req(struct request *req);
+bool nvme_failover_req(struct request *req);
 void nvme_kick_requeue_lists(struct nvme_ctrl *ctrl);
 int nvme_mpath_alloc_disk(struct nvme_ctrl *ctrl,struct nvme_ns_head *head);
 void nvme_mpath_add_disk(struct nvme_ns *ns, struct nvme_id_ns *id);
@@ -599,8 +600,9 @@ static inline void nvme_set_disk_name(char *disk_name, struct nvme_ns *ns,
        sprintf(disk_name, "nvme%dn%d", ctrl->instance, ns->head->instance);
 }
 
-static inline void nvme_failover_req(struct request *req)
+static inline bool nvme_failover_req(struct request *req)
 {
+       return false;
 }
 static inline void nvme_kick_requeue_lists(struct nvme_ctrl *ctrl)
 {
index d3f23d6..4e79e41 100644 (file)
@@ -971,39 +971,25 @@ static inline void nvme_handle_cqe(struct nvme_queue *nvmeq, u16 idx)
        nvme_end_request(req, cqe->status, cqe->result);
 }
 
-static void nvme_complete_cqes(struct nvme_queue *nvmeq, u16 start, u16 end)
-{
-       while (start != end) {
-               nvme_handle_cqe(nvmeq, start);
-               if (++start == nvmeq->q_depth)
-                       start = 0;
-       }
-}
-
 static inline void nvme_update_cq_head(struct nvme_queue *nvmeq)
 {
-       if (nvmeq->cq_head == nvmeq->q_depth - 1) {
+       if (++nvmeq->cq_head == nvmeq->q_depth) {
                nvmeq->cq_head = 0;
-               nvmeq->cq_phase = !nvmeq->cq_phase;
-       } else {
-               nvmeq->cq_head++;
+               nvmeq->cq_phase ^= 1;
        }
 }
 
-static inline int nvme_process_cq(struct nvme_queue *nvmeq, u16 *start,
-                                 u16 *end, unsigned int tag)
+static inline int nvme_process_cq(struct nvme_queue *nvmeq)
 {
        int found = 0;
 
-       *start = nvmeq->cq_head;
        while (nvme_cqe_pending(nvmeq)) {
-               if (tag == -1U || nvmeq->cqes[nvmeq->cq_head].command_id == tag)
-                       found++;
+               found++;
+               nvme_handle_cqe(nvmeq, nvmeq->cq_head);
                nvme_update_cq_head(nvmeq);
        }
-       *end = nvmeq->cq_head;
 
-       if (*start != *end)
+       if (found)
                nvme_ring_cq_doorbell(nvmeq);
        return found;
 }
@@ -1012,21 +998,16 @@ static irqreturn_t nvme_irq(int irq, void *data)
 {
        struct nvme_queue *nvmeq = data;
        irqreturn_t ret = IRQ_NONE;
-       u16 start, end;
 
        /*
         * The rmb/wmb pair ensures we see all updates from a previous run of
         * the irq handler, even if that was on another CPU.
         */
        rmb();
-       nvme_process_cq(nvmeq, &start, &end, -1);
+       if (nvme_process_cq(nvmeq))
+               ret = IRQ_HANDLED;
        wmb();
 
-       if (start != end) {
-               nvme_complete_cqes(nvmeq, start, end);
-               return IRQ_HANDLED;
-       }
-
        return ret;
 }
 
@@ -1039,46 +1020,30 @@ static irqreturn_t nvme_irq_check(int irq, void *data)
 }
 
 /*
- * Poll for completions any queue, including those not dedicated to polling.
+ * Poll for completions for any interrupt driven queue
  * Can be called from any context.
  */
-static int nvme_poll_irqdisable(struct nvme_queue *nvmeq, unsigned int tag)
+static void nvme_poll_irqdisable(struct nvme_queue *nvmeq)
 {
        struct pci_dev *pdev = to_pci_dev(nvmeq->dev->dev);
-       u16 start, end;
-       int found;
 
-       /*
-        * For a poll queue we need to protect against the polling thread
-        * using the CQ lock.  For normal interrupt driven threads we have
-        * to disable the interrupt to avoid racing with it.
-        */
-       if (test_bit(NVMEQ_POLLED, &nvmeq->flags)) {
-               spin_lock(&nvmeq->cq_poll_lock);
-               found = nvme_process_cq(nvmeq, &start, &end, tag);
-               spin_unlock(&nvmeq->cq_poll_lock);
-       } else {
-               disable_irq(pci_irq_vector(pdev, nvmeq->cq_vector));
-               found = nvme_process_cq(nvmeq, &start, &end, tag);
-               enable_irq(pci_irq_vector(pdev, nvmeq->cq_vector));
-       }
+       WARN_ON_ONCE(test_bit(NVMEQ_POLLED, &nvmeq->flags));
 
-       nvme_complete_cqes(nvmeq, start, end);
-       return found;
+       disable_irq(pci_irq_vector(pdev, nvmeq->cq_vector));
+       nvme_process_cq(nvmeq);
+       enable_irq(pci_irq_vector(pdev, nvmeq->cq_vector));
 }
 
 static int nvme_poll(struct blk_mq_hw_ctx *hctx)
 {
        struct nvme_queue *nvmeq = hctx->driver_data;
-       u16 start, end;
        bool found;
 
        if (!nvme_cqe_pending(nvmeq))
                return 0;
 
        spin_lock(&nvmeq->cq_poll_lock);
-       found = nvme_process_cq(nvmeq, &start, &end, -1);
-       nvme_complete_cqes(nvmeq, start, end);
+       found = nvme_process_cq(nvmeq);
        spin_unlock(&nvmeq->cq_poll_lock);
 
        return found;
@@ -1255,7 +1220,12 @@ static enum blk_eh_timer_return nvme_timeout(struct request *req, bool reserved)
        /*
         * Did we miss an interrupt?
         */
-       if (nvme_poll_irqdisable(nvmeq, req->tag)) {
+       if (test_bit(NVMEQ_POLLED, &nvmeq->flags))
+               nvme_poll(req->mq_hctx);
+       else
+               nvme_poll_irqdisable(nvmeq);
+
+       if (blk_mq_request_completed(req)) {
                dev_warn(dev->ctrl.device,
                         "I/O %d QID %d timeout, completion polled\n",
                         req->tag, nvmeq->qid);
@@ -1398,7 +1368,7 @@ static void nvme_disable_admin_queue(struct nvme_dev *dev, bool shutdown)
        else
                nvme_disable_ctrl(&dev->ctrl);
 
-       nvme_poll_irqdisable(nvmeq, -1);
+       nvme_poll_irqdisable(nvmeq);
 }
 
 /*
@@ -1409,13 +1379,10 @@ static void nvme_disable_admin_queue(struct nvme_dev *dev, bool shutdown)
  */
 static void nvme_reap_pending_cqes(struct nvme_dev *dev)
 {
-       u16 start, end;
        int i;
 
-       for (i = dev->ctrl.queue_count - 1; i > 0; i--) {
-               nvme_process_cq(&dev->queues[i], &start, &end, -1);
-               nvme_complete_cqes(&dev->queues[i], start, end);
-       }
+       for (i = dev->ctrl.queue_count - 1; i > 0; i--)
+               nvme_process_cq(&dev->queues[i]);
 }
 
 static int nvme_cmb_qdepth(struct nvme_dev *dev, int nr_io_queues,
@@ -2503,13 +2470,13 @@ static void nvme_pci_free_ctrl(struct nvme_ctrl *ctrl)
        struct nvme_dev *dev = to_nvme_dev(ctrl);
 
        nvme_dbbuf_dma_free(dev);
-       put_device(dev->dev);
        nvme_free_tagset(dev);
        if (dev->ctrl.admin_q)
                blk_put_queue(dev->ctrl.admin_q);
-       kfree(dev->queues);
        free_opal_dev(dev->ctrl.opal_dev);
        mempool_destroy(dev->iod_mempool);
+       put_device(dev->dev);
+       kfree(dev->queues);
        kfree(dev);
 }
 
@@ -2689,7 +2656,7 @@ static int nvme_pci_get_address(struct nvme_ctrl *ctrl, char *buf, int size)
 {
        struct pci_dev *pdev = to_pci_dev(to_nvme_dev(ctrl)->dev);
 
-       return snprintf(buf, size, "%s", dev_name(&pdev->dev));
+       return snprintf(buf, size, "%s\n", dev_name(&pdev->dev));
 }
 
 static const struct nvme_ctrl_ops nvme_pci_ctrl_ops = {
@@ -2835,7 +2802,6 @@ static int nvme_probe(struct pci_dev *pdev, const struct pci_device_id *id)
        dev_info(dev->ctrl.device, "pci function %s\n", dev_name(&pdev->dev));
 
        nvme_reset_ctrl(&dev->ctrl);
-       nvme_get_ctrl(&dev->ctrl);
        async_schedule(nvme_async_probe, dev);
 
        return 0;
@@ -2907,10 +2873,9 @@ static void nvme_remove(struct pci_dev *pdev)
        nvme_free_host_mem(dev);
        nvme_dev_remove_admin(dev);
        nvme_free_queues(dev, 0);
-       nvme_uninit_ctrl(&dev->ctrl);
        nvme_release_prp_pools(dev);
        nvme_dev_unmap(dev);
-       nvme_put_ctrl(&dev->ctrl);
+       nvme_uninit_ctrl(&dev->ctrl);
 }
 
 #ifdef CONFIG_PM_SLEEP
index 0fe08c4..86603d9 100644 (file)
@@ -1024,8 +1024,13 @@ static int nvme_rdma_setup_ctrl(struct nvme_rdma_ctrl *ctrl, bool new)
 
        changed = nvme_change_ctrl_state(&ctrl->ctrl, NVME_CTRL_LIVE);
        if (!changed) {
-               /* state change failure is ok if we're in DELETING state */
+               /*
+                * state change failure is ok if we're in DELETING state,
+                * unless we're during creation of a new controller to
+                * avoid races with teardown flow.
+                */
                WARN_ON_ONCE(ctrl->ctrl.state != NVME_CTRL_DELETING);
+               WARN_ON_ONCE(new);
                ret = -EINVAL;
                goto destroy_io;
        }
@@ -2045,8 +2050,6 @@ static struct nvme_ctrl *nvme_rdma_create_ctrl(struct device *dev,
        dev_info(ctrl->ctrl.device, "new ctrl: NQN \"%s\", addr %pISpcs\n",
                ctrl->ctrl.opts->subsysnqn, &ctrl->addr);
 
-       nvme_get_ctrl(&ctrl->ctrl);
-
        mutex_lock(&nvme_rdma_ctrl_mutex);
        list_add_tail(&ctrl->list, &nvme_rdma_ctrl_list);
        mutex_unlock(&nvme_rdma_ctrl_mutex);
index 49d4373..0ef14f0 100644 (file)
 
 struct nvme_tcp_queue;
 
+/* Define the socket priority to use for connections were it is desirable
+ * that the NIC consider performing optimized packet processing or filtering.
+ * A non-zero value being sufficient to indicate general consideration of any
+ * possible optimization.  Making it a module param allows for alternative
+ * values that may be unique for some NIC implementations.
+ */
+static int so_priority;
+module_param(so_priority, int, 0644);
+MODULE_PARM_DESC(so_priority, "nvme tcp socket optimize priority");
+
 enum nvme_tcp_send_state {
        NVME_TCP_SEND_CMD_PDU = 0,
        NVME_TCP_SEND_H2C_PDU,
@@ -1017,8 +1027,15 @@ static int nvme_tcp_try_send(struct nvme_tcp_queue *queue)
        if (req->state == NVME_TCP_SEND_DDGST)
                ret = nvme_tcp_try_send_ddgst(req);
 done:
-       if (ret == -EAGAIN)
+       if (ret == -EAGAIN) {
                ret = 0;
+       } else if (ret < 0) {
+               dev_err(queue->ctrl->ctrl.device,
+                       "failed to send request %d\n", ret);
+               if (ret != -EPIPE && ret != -ECONNRESET)
+                       nvme_tcp_fail_request(queue->request);
+               nvme_tcp_done_send_req(queue);
+       }
        return ret;
 }
 
@@ -1049,25 +1066,16 @@ static void nvme_tcp_io_work(struct work_struct *w)
                int result;
 
                result = nvme_tcp_try_send(queue);
-               if (result > 0) {
+               if (result > 0)
                        pending = true;
-               } else if (unlikely(result < 0)) {
-                       dev_err(queue->ctrl->ctrl.device,
-                               "failed to send request %d\n", result);
-
-                       /*
-                        * Fail the request unless peer closed the connection,
-                        * in which case error recovery flow will complete all.
-                        */
-                       if ((result != -EPIPE) && (result != -ECONNRESET))
-                               nvme_tcp_fail_request(queue->request);
-                       nvme_tcp_done_send_req(queue);
-                       return;
-               }
+               else if (unlikely(result < 0))
+                       break;
 
                result = nvme_tcp_try_recv(queue);
                if (result > 0)
                        pending = true;
+               else if (unlikely(result < 0))
+                       break;
 
                if (!pending)
                        return;
@@ -1248,13 +1256,67 @@ free_icreq:
        return ret;
 }
 
+static bool nvme_tcp_admin_queue(struct nvme_tcp_queue *queue)
+{
+       return nvme_tcp_queue_id(queue) == 0;
+}
+
+static bool nvme_tcp_default_queue(struct nvme_tcp_queue *queue)
+{
+       struct nvme_tcp_ctrl *ctrl = queue->ctrl;
+       int qid = nvme_tcp_queue_id(queue);
+
+       return !nvme_tcp_admin_queue(queue) &&
+               qid < 1 + ctrl->io_queues[HCTX_TYPE_DEFAULT];
+}
+
+static bool nvme_tcp_read_queue(struct nvme_tcp_queue *queue)
+{
+       struct nvme_tcp_ctrl *ctrl = queue->ctrl;
+       int qid = nvme_tcp_queue_id(queue);
+
+       return !nvme_tcp_admin_queue(queue) &&
+               !nvme_tcp_default_queue(queue) &&
+               qid < 1 + ctrl->io_queues[HCTX_TYPE_DEFAULT] +
+                         ctrl->io_queues[HCTX_TYPE_READ];
+}
+
+static bool nvme_tcp_poll_queue(struct nvme_tcp_queue *queue)
+{
+       struct nvme_tcp_ctrl *ctrl = queue->ctrl;
+       int qid = nvme_tcp_queue_id(queue);
+
+       return !nvme_tcp_admin_queue(queue) &&
+               !nvme_tcp_default_queue(queue) &&
+               !nvme_tcp_read_queue(queue) &&
+               qid < 1 + ctrl->io_queues[HCTX_TYPE_DEFAULT] +
+                         ctrl->io_queues[HCTX_TYPE_READ] +
+                         ctrl->io_queues[HCTX_TYPE_POLL];
+}
+
+static void nvme_tcp_set_queue_io_cpu(struct nvme_tcp_queue *queue)
+{
+       struct nvme_tcp_ctrl *ctrl = queue->ctrl;
+       int qid = nvme_tcp_queue_id(queue);
+       int n = 0;
+
+       if (nvme_tcp_default_queue(queue))
+               n = qid - 1;
+       else if (nvme_tcp_read_queue(queue))
+               n = qid - ctrl->io_queues[HCTX_TYPE_DEFAULT] - 1;
+       else if (nvme_tcp_poll_queue(queue))
+               n = qid - ctrl->io_queues[HCTX_TYPE_DEFAULT] -
+                               ctrl->io_queues[HCTX_TYPE_READ] - 1;
+       queue->io_cpu = cpumask_next_wrap(n - 1, cpu_online_mask, -1, false);
+}
+
 static int nvme_tcp_alloc_queue(struct nvme_ctrl *nctrl,
                int qid, size_t queue_size)
 {
        struct nvme_tcp_ctrl *ctrl = to_tcp_ctrl(nctrl);
        struct nvme_tcp_queue *queue = &ctrl->queues[qid];
        struct linger sol = { .l_onoff = 1, .l_linger = 0 };
-       int ret, opt, rcv_pdu_size, n;
+       int ret, opt, rcv_pdu_size;
 
        queue->ctrl = ctrl;
        INIT_LIST_HEAD(&queue->send_list);
@@ -1309,6 +1371,17 @@ static int nvme_tcp_alloc_queue(struct nvme_ctrl *nctrl,
                goto err_sock;
        }
 
+       if (so_priority > 0) {
+               ret = kernel_setsockopt(queue->sock, SOL_SOCKET, SO_PRIORITY,
+                               (char *)&so_priority, sizeof(so_priority));
+               if (ret) {
+                       dev_err(ctrl->ctrl.device,
+                               "failed to set SO_PRIORITY sock opt, ret %d\n",
+                               ret);
+                       goto err_sock;
+               }
+       }
+
        /* Set socket type of service */
        if (nctrl->opts->tos >= 0) {
                opt = nctrl->opts->tos;
@@ -1322,11 +1395,7 @@ static int nvme_tcp_alloc_queue(struct nvme_ctrl *nctrl,
        }
 
        queue->sock->sk->sk_allocation = GFP_ATOMIC;
-       if (!qid)
-               n = 0;
-       else
-               n = (qid - 1) % num_online_cpus();
-       queue->io_cpu = cpumask_next_wrap(n - 1, cpu_online_mask, -1, false);
+       nvme_tcp_set_queue_io_cpu(queue);
        queue->request = NULL;
        queue->data_remaining = 0;
        queue->ddgst_remaining = 0;
@@ -1861,8 +1930,13 @@ static int nvme_tcp_setup_ctrl(struct nvme_ctrl *ctrl, bool new)
        }
 
        if (!nvme_change_ctrl_state(ctrl, NVME_CTRL_LIVE)) {
-               /* state change failure is ok if we're in DELETING state */
+               /*
+                * state change failure is ok if we're in DELETING state,
+                * unless we're during creation of a new controller to
+                * avoid races with teardown flow.
+                */
                WARN_ON_ONCE(ctrl->state != NVME_CTRL_DELETING);
+               WARN_ON_ONCE(new);
                ret = -EINVAL;
                goto destroy_io;
        }
@@ -2359,8 +2433,6 @@ static struct nvme_ctrl *nvme_tcp_create_ctrl(struct device *dev,
        dev_info(ctrl->ctrl.device, "new ctrl: NQN \"%s\", addr %pISp\n",
                ctrl->ctrl.opts->subsysnqn, &ctrl->addr);
 
-       nvme_get_ctrl(&ctrl->ctrl);
-
        mutex_lock(&nvme_tcp_ctrl_mutex);
        list_add_tail(&ctrl->list, &nvme_tcp_ctrl_list);
        mutex_unlock(&nvme_tcp_ctrl_mutex);
index 72a7e41..9d6f75c 100644 (file)
@@ -6,6 +6,7 @@
 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
 #include <linux/module.h>
 #include <linux/rculist.h>
+#include <linux/part_stat.h>
 
 #include <generated/utsrelease.h>
 #include <asm/unaligned.h>
@@ -322,12 +323,25 @@ static void nvmet_execute_get_log_page(struct nvmet_req *req)
        nvmet_req_complete(req, NVME_SC_INVALID_FIELD | NVME_SC_DNR);
 }
 
+static void nvmet_id_set_model_number(struct nvme_id_ctrl *id,
+                                     struct nvmet_subsys *subsys)
+{
+       const char *model = NVMET_DEFAULT_CTRL_MODEL;
+       struct nvmet_subsys_model *subsys_model;
+
+       rcu_read_lock();
+       subsys_model = rcu_dereference(subsys->model);
+       if (subsys_model)
+               model = subsys_model->number;
+       memcpy_and_pad(id->mn, sizeof(id->mn), model, strlen(model), ' ');
+       rcu_read_unlock();
+}
+
 static void nvmet_execute_identify_ctrl(struct nvmet_req *req)
 {
        struct nvmet_ctrl *ctrl = req->sq->ctrl;
        struct nvme_id_ctrl *id;
        u16 status = 0;
-       const char model[] = "Linux";
 
        id = kzalloc(sizeof(*id), GFP_KERNEL);
        if (!id) {
@@ -342,7 +356,7 @@ static void nvmet_execute_identify_ctrl(struct nvmet_req *req)
        memset(id->sn, ' ', sizeof(id->sn));
        bin2hex(id->sn, &ctrl->subsys->serial,
                min(sizeof(ctrl->subsys->serial), sizeof(id->sn) / 2));
-       memcpy_and_pad(id->mn, sizeof(id->mn), model, sizeof(model) - 1, ' ');
+       nvmet_id_set_model_number(id, ctrl->subsys);
        memcpy_and_pad(id->fr, sizeof(id->fr),
                       UTS_RELEASE, strlen(UTS_RELEASE), ' ');
 
@@ -356,8 +370,12 @@ static void nvmet_execute_identify_ctrl(struct nvmet_req *req)
        /* we support multiple ports, multiples hosts and ANA: */
        id->cmic = (1 << 0) | (1 << 1) | (1 << 3);
 
-       /* no limit on data transfer sizes for now */
-       id->mdts = 0;
+       /* Limit MDTS according to transport capability */
+       if (ctrl->ops->get_mdts)
+               id->mdts = ctrl->ops->get_mdts(ctrl);
+       else
+               id->mdts = 0;
+
        id->cntlid = cpu_to_le16(ctrl->cntlid);
        id->ver = cpu_to_le32(ctrl->subsys->ver);
 
@@ -720,13 +738,22 @@ static void nvmet_execute_set_features(struct nvmet_req *req)
 {
        struct nvmet_subsys *subsys = req->sq->ctrl->subsys;
        u32 cdw10 = le32_to_cpu(req->cmd->common.cdw10);
+       u32 cdw11 = le32_to_cpu(req->cmd->common.cdw11);
        u16 status = 0;
+       u16 nsqr;
+       u16 ncqr;
 
        if (!nvmet_check_data_len(req, 0))
                return;
 
        switch (cdw10 & 0xff) {
        case NVME_FEAT_NUM_QUEUES:
+               ncqr = (cdw11 >> 16) & 0xffff;
+               nsqr = cdw11 & 0xffff;
+               if (ncqr == 0xffff || nsqr == 0xffff) {
+                       status = NVME_SC_INVALID_FIELD | NVME_SC_DNR;
+                       break;
+               }
                nvmet_set_result(req,
                        (subsys->max_qid - 1) | ((subsys->max_qid - 1) << 16));
                break;
index 98613a4..7aa1078 100644 (file)
@@ -395,14 +395,12 @@ static ssize_t nvmet_ns_device_uuid_store(struct config_item *item,
        struct nvmet_subsys *subsys = ns->subsys;
        int ret = 0;
 
-
        mutex_lock(&subsys->lock);
        if (ns->enabled) {
                ret = -EBUSY;
                goto out_unlock;
        }
 
-
        if (uuid_parse(page, &ns->uuid))
                ret = -EINVAL;
 
@@ -815,10 +813,10 @@ static ssize_t nvmet_subsys_attr_version_show(struct config_item *item,
                                (int)NVME_MAJOR(subsys->ver),
                                (int)NVME_MINOR(subsys->ver),
                                (int)NVME_TERTIARY(subsys->ver));
-       else
-               return snprintf(page, PAGE_SIZE, "%d.%d\n",
-                               (int)NVME_MAJOR(subsys->ver),
-                               (int)NVME_MINOR(subsys->ver));
+
+       return snprintf(page, PAGE_SIZE, "%d.%d\n",
+                       (int)NVME_MAJOR(subsys->ver),
+                       (int)NVME_MINOR(subsys->ver));
 }
 
 static ssize_t nvmet_subsys_attr_version_store(struct config_item *item,
@@ -828,7 +826,6 @@ static ssize_t nvmet_subsys_attr_version_store(struct config_item *item,
        int major, minor, tertiary = 0;
        int ret;
 
-
        ret = sscanf(page, "%d.%d.%d\n", &major, &minor, &tertiary);
        if (ret != 2 && ret != 3)
                return -EINVAL;
@@ -852,20 +849,151 @@ static ssize_t nvmet_subsys_attr_serial_show(struct config_item *item,
 static ssize_t nvmet_subsys_attr_serial_store(struct config_item *item,
                                              const char *page, size_t count)
 {
-       struct nvmet_subsys *subsys = to_subsys(item);
+       u64 serial;
+
+       if (sscanf(page, "%llx\n", &serial) != 1)
+               return -EINVAL;
 
        down_write(&nvmet_config_sem);
-       sscanf(page, "%llx\n", &subsys->serial);
+       to_subsys(item)->serial = serial;
        up_write(&nvmet_config_sem);
 
        return count;
 }
 CONFIGFS_ATTR(nvmet_subsys_, attr_serial);
 
+static ssize_t nvmet_subsys_attr_cntlid_min_show(struct config_item *item,
+                                                char *page)
+{
+       return snprintf(page, PAGE_SIZE, "%u\n", to_subsys(item)->cntlid_min);
+}
+
+static ssize_t nvmet_subsys_attr_cntlid_min_store(struct config_item *item,
+                                                 const char *page, size_t cnt)
+{
+       u16 cntlid_min;
+
+       if (sscanf(page, "%hu\n", &cntlid_min) != 1)
+               return -EINVAL;
+
+       if (cntlid_min == 0)
+               return -EINVAL;
+
+       down_write(&nvmet_config_sem);
+       if (cntlid_min >= to_subsys(item)->cntlid_max)
+               goto out_unlock;
+       to_subsys(item)->cntlid_min = cntlid_min;
+       up_write(&nvmet_config_sem);
+       return cnt;
+
+out_unlock:
+       up_write(&nvmet_config_sem);
+       return -EINVAL;
+}
+CONFIGFS_ATTR(nvmet_subsys_, attr_cntlid_min);
+
+static ssize_t nvmet_subsys_attr_cntlid_max_show(struct config_item *item,
+                                                char *page)
+{
+       return snprintf(page, PAGE_SIZE, "%u\n", to_subsys(item)->cntlid_max);
+}
+
+static ssize_t nvmet_subsys_attr_cntlid_max_store(struct config_item *item,
+                                                 const char *page, size_t cnt)
+{
+       u16 cntlid_max;
+
+       if (sscanf(page, "%hu\n", &cntlid_max) != 1)
+               return -EINVAL;
+
+       if (cntlid_max == 0)
+               return -EINVAL;
+
+       down_write(&nvmet_config_sem);
+       if (cntlid_max <= to_subsys(item)->cntlid_min)
+               goto out_unlock;
+       to_subsys(item)->cntlid_max = cntlid_max;
+       up_write(&nvmet_config_sem);
+       return cnt;
+
+out_unlock:
+       up_write(&nvmet_config_sem);
+       return -EINVAL;
+}
+CONFIGFS_ATTR(nvmet_subsys_, attr_cntlid_max);
+
+static ssize_t nvmet_subsys_attr_model_show(struct config_item *item,
+                                           char *page)
+{
+       struct nvmet_subsys *subsys = to_subsys(item);
+       struct nvmet_subsys_model *subsys_model;
+       char *model = NVMET_DEFAULT_CTRL_MODEL;
+       int ret;
+
+       rcu_read_lock();
+       subsys_model = rcu_dereference(subsys->model);
+       if (subsys_model)
+               model = subsys_model->number;
+       ret = snprintf(page, PAGE_SIZE, "%s\n", model);
+       rcu_read_unlock();
+
+       return ret;
+}
+
+/* See Section 1.5 of NVMe 1.4 */
+static bool nvmet_is_ascii(const char c)
+{
+       return c >= 0x20 && c <= 0x7e;
+}
+
+static ssize_t nvmet_subsys_attr_model_store(struct config_item *item,
+                                            const char *page, size_t count)
+{
+       struct nvmet_subsys *subsys = to_subsys(item);
+       struct nvmet_subsys_model *new_model;
+       char *new_model_number;
+       int pos = 0, len;
+
+       len = strcspn(page, "\n");
+       if (!len)
+               return -EINVAL;
+
+       for (pos = 0; pos < len; pos++) {
+               if (!nvmet_is_ascii(page[pos]))
+                       return -EINVAL;
+       }
+
+       new_model_number = kstrndup(page, len, GFP_KERNEL);
+       if (!new_model_number)
+               return -ENOMEM;
+
+       new_model = kzalloc(sizeof(*new_model) + len + 1, GFP_KERNEL);
+       if (!new_model) {
+               kfree(new_model_number);
+               return -ENOMEM;
+       }
+       memcpy(new_model->number, new_model_number, len);
+
+       down_write(&nvmet_config_sem);
+       mutex_lock(&subsys->lock);
+       new_model = rcu_replace_pointer(subsys->model, new_model,
+                                       mutex_is_locked(&subsys->lock));
+       mutex_unlock(&subsys->lock);
+       up_write(&nvmet_config_sem);
+
+       kfree_rcu(new_model, rcuhead);
+
+       return count;
+}
+CONFIGFS_ATTR(nvmet_subsys_, attr_model);
+
 static struct configfs_attribute *nvmet_subsys_attrs[] = {
        &nvmet_subsys_attr_attr_allow_any_host,
        &nvmet_subsys_attr_attr_version,
        &nvmet_subsys_attr_attr_serial,
+       &nvmet_subsys_attr_attr_cntlid_min,
+       &nvmet_subsys_attr_attr_cntlid_max,
+       &nvmet_subsys_attr_attr_model,
        NULL,
 };
 
index 576de77..b685f99 100644 (file)
@@ -1289,8 +1289,11 @@ u16 nvmet_alloc_ctrl(const char *subsysnqn, const char *hostnqn,
        if (!ctrl->sqs)
                goto out_free_cqs;
 
+       if (subsys->cntlid_min > subsys->cntlid_max)
+               goto out_free_cqs;
+
        ret = ida_simple_get(&cntlid_ida,
-                            NVME_CNTLID_MIN, NVME_CNTLID_MAX,
+                            subsys->cntlid_min, subsys->cntlid_max,
                             GFP_KERNEL);
        if (ret < 0) {
                status = NVME_SC_CONNECT_CTRL_BUSY | NVME_SC_DNR;
@@ -1438,7 +1441,8 @@ struct nvmet_subsys *nvmet_subsys_alloc(const char *subsysnqn,
                kfree(subsys);
                return ERR_PTR(-ENOMEM);
        }
-
+       subsys->cntlid_min = NVME_CNTLID_MIN;
+       subsys->cntlid_max = NVME_CNTLID_MAX;
        kref_init(&subsys->ref);
 
        mutex_init(&subsys->lock);
@@ -1457,6 +1461,7 @@ static void nvmet_subsys_free(struct kref *ref)
        WARN_ON_ONCE(!list_empty(&subsys->namespaces));
 
        kfree(subsys->subsysnqn);
+       kfree_rcu(subsys->model, rcuhead);
        kfree(subsys);
 }
 
index 4df4ebd..0d54e73 100644 (file)
@@ -485,7 +485,6 @@ out_destroy_admin:
 out_disable:
        dev_warn(ctrl->ctrl.device, "Removing after reset failure\n");
        nvme_uninit_ctrl(&ctrl->ctrl);
-       nvme_put_ctrl(&ctrl->ctrl);
 }
 
 static const struct nvme_ctrl_ops nvme_loop_ctrl_ops = {
@@ -618,8 +617,6 @@ static struct nvme_ctrl *nvme_loop_create_ctrl(struct device *dev,
        dev_info(ctrl->ctrl.device,
                 "new ctrl: \"%s\"\n", ctrl->ctrl.opts->subsysnqn);
 
-       nvme_get_ctrl(&ctrl->ctrl);
-
        changed = nvme_change_ctrl_state(&ctrl->ctrl, NVME_CTRL_LIVE);
        WARN_ON_ONCE(!changed);
 
index eda28b2..421dff3 100644 (file)
@@ -23,6 +23,7 @@
 #define NVMET_ASYNC_EVENTS             4
 #define NVMET_ERROR_LOG_SLOTS          128
 #define NVMET_NO_ERROR_LOC             ((u16)-1)
+#define NVMET_DEFAULT_CTRL_MODEL       "Linux"
 
 /*
  * Supported optional AENs:
@@ -202,6 +203,11 @@ struct nvmet_ctrl {
        struct nvme_error_slot  slots[NVMET_ERROR_LOG_SLOTS];
 };
 
+struct nvmet_subsys_model {
+       struct rcu_head         rcuhead;
+       char                    number[];
+};
+
 struct nvmet_subsys {
        enum nvme_subsys_type   type;
 
@@ -211,6 +217,8 @@ struct nvmet_subsys {
        struct list_head        namespaces;
        unsigned int            nr_namespaces;
        unsigned int            max_nsid;
+       u16                     cntlid_min;
+       u16                     cntlid_max;
 
        struct list_head        ctrls;
 
@@ -227,6 +235,8 @@ struct nvmet_subsys {
 
        struct config_group     namespaces_group;
        struct config_group     allowed_hosts_group;
+
+       struct nvmet_subsys_model       __rcu *model;
 };
 
 static inline struct nvmet_subsys *to_subsys(struct config_item *item)
@@ -279,6 +289,7 @@ struct nvmet_fabrics_ops {
                        struct nvmet_port *port, char *traddr);
        u16 (*install_queue)(struct nvmet_sq *nvme_sq);
        void (*discovery_chg)(struct nvmet_port *port);
+       u8 (*get_mdts)(const struct nvmet_ctrl *ctrl);
 };
 
 #define NVMET_MAX_INLINE_BIOVEC        8
index 37d262a..9e1b8c6 100644 (file)
@@ -31,6 +31,9 @@
 #define NVMET_RDMA_MAX_INLINE_SGE              4
 #define NVMET_RDMA_MAX_INLINE_DATA_SIZE                max_t(int, SZ_16K, PAGE_SIZE)
 
+/* Assume mpsmin == device_page_size == 4KB */
+#define NVMET_RDMA_MAX_MDTS                    8
+
 struct nvmet_rdma_cmd {
        struct ib_sge           sge[NVMET_RDMA_MAX_INLINE_SGE + 1];
        struct ib_cqe           cqe;
@@ -975,7 +978,7 @@ static int nvmet_rdma_create_queue_ib(struct nvmet_rdma_queue *queue)
 {
        struct ib_qp_init_attr qp_attr;
        struct nvmet_rdma_device *ndev = queue->dev;
-       int comp_vector, nr_cqe, ret, i;
+       int comp_vector, nr_cqe, ret, i, factor;
 
        /*
         * Spread the io queues across completion vectors,
@@ -1008,7 +1011,9 @@ static int nvmet_rdma_create_queue_ib(struct nvmet_rdma_queue *queue)
        qp_attr.qp_type = IB_QPT_RC;
        /* +1 for drain */
        qp_attr.cap.max_send_wr = queue->send_queue_size + 1;
-       qp_attr.cap.max_rdma_ctxs = queue->send_queue_size;
+       factor = rdma_rw_mr_factor(ndev->device, queue->cm_id->port_num,
+                                  1 << NVMET_RDMA_MAX_MDTS);
+       qp_attr.cap.max_rdma_ctxs = queue->send_queue_size * factor;
        qp_attr.cap.max_send_sge = max(ndev->device->attrs.max_sge_rd,
                                        ndev->device->attrs.max_send_sge);
 
@@ -1602,6 +1607,11 @@ static void nvmet_rdma_disc_port_addr(struct nvmet_req *req,
        }
 }
 
+static u8 nvmet_rdma_get_mdts(const struct nvmet_ctrl *ctrl)
+{
+       return NVMET_RDMA_MAX_MDTS;
+}
+
 static const struct nvmet_fabrics_ops nvmet_rdma_ops = {
        .owner                  = THIS_MODULE,
        .type                   = NVMF_TRTYPE_RDMA,
@@ -1612,6 +1622,7 @@ static const struct nvmet_fabrics_ops nvmet_rdma_ops = {
        .queue_response         = nvmet_rdma_queue_response,
        .delete_ctrl            = nvmet_rdma_delete_ctrl,
        .disc_traddr            = nvmet_rdma_disc_port_addr,
+       .get_mdts               = nvmet_rdma_get_mdts,
 };
 
 static void nvmet_rdma_remove_one(struct ib_device *ib_device, void *client_data)
index 5bb5342..f0da04e 100644 (file)
 
 #define NVMET_TCP_DEF_INLINE_DATA_SIZE (4 * PAGE_SIZE)
 
+/* Define the socket priority to use for connections were it is desirable
+ * that the NIC consider performing optimized packet processing or filtering.
+ * A non-zero value being sufficient to indicate general consideration of any
+ * possible optimization.  Making it a module param allows for alternative
+ * values that may be unique for some NIC implementations.
+ */
+static int so_priority;
+module_param(so_priority, int, 0644);
+MODULE_PARM_DESC(so_priority, "nvmet tcp socket optimize priority");
+
 #define NVMET_TCP_RECV_BUDGET          8
 #define NVMET_TCP_SEND_BUDGET          8
 #define NVMET_TCP_IO_WORK_BUDGET       64
@@ -622,7 +632,7 @@ static int nvmet_try_send_r2t(struct nvmet_tcp_cmd *cmd, bool last_in_batch)
        return 1;
 }
 
-static int nvmet_try_send_ddgst(struct nvmet_tcp_cmd *cmd)
+static int nvmet_try_send_ddgst(struct nvmet_tcp_cmd *cmd, bool last_in_batch)
 {
        struct nvmet_tcp_queue *queue = cmd->queue;
        struct msghdr msg = { .msg_flags = MSG_DONTWAIT };
@@ -632,6 +642,9 @@ static int nvmet_try_send_ddgst(struct nvmet_tcp_cmd *cmd)
        };
        int ret;
 
+       if (!last_in_batch && cmd->queue->send_list_len)
+               msg.msg_flags |= MSG_MORE;
+
        ret = kernel_sendmsg(queue->sock, &msg, &iov, 1, iov.iov_len);
        if (unlikely(ret <= 0))
                return ret;
@@ -672,7 +685,7 @@ static int nvmet_tcp_try_send_one(struct nvmet_tcp_queue *queue,
        }
 
        if (cmd->state == NVMET_TCP_SEND_DDGST) {
-               ret = nvmet_try_send_ddgst(cmd);
+               ret = nvmet_try_send_ddgst(cmd, last_in_batch);
                if (ret <= 0)
                        goto done_send;
        }
@@ -794,7 +807,7 @@ static int nvmet_tcp_handle_icreq(struct nvmet_tcp_queue *queue)
        icresp->hdr.pdo = 0;
        icresp->hdr.plen = cpu_to_le32(icresp->hdr.hlen);
        icresp->pfv = cpu_to_le16(NVME_TCP_PFV_1_0);
-       icresp->maxdata = cpu_to_le32(0xffff); /* FIXME: support r2t */
+       icresp->maxdata = cpu_to_le32(0x400000); /* 16M arbitrary limit */
        icresp->cpda = 0;
        if (queue->hdr_digest)
                icresp->digest |= NVME_TCP_HDR_DIGEST_ENABLE;
@@ -1439,6 +1452,13 @@ static int nvmet_tcp_set_queue_sock(struct nvmet_tcp_queue *queue)
        if (ret)
                return ret;
 
+       if (so_priority > 0) {
+               ret = kernel_setsockopt(sock, SOL_SOCKET, SO_PRIORITY,
+                               (char *)&so_priority, sizeof(so_priority));
+               if (ret)
+                       return ret;
+       }
+
        /* Set socket type of service */
        if (inet->rcv_tos > 0) {
                int tos = inet->rcv_tos;
@@ -1628,6 +1648,15 @@ static int nvmet_tcp_add_port(struct nvmet_port *nport)
                goto err_sock;
        }
 
+       if (so_priority > 0) {
+               ret = kernel_setsockopt(port->sock, SOL_SOCKET, SO_PRIORITY,
+                               (char *)&so_priority, sizeof(so_priority));
+               if (ret) {
+                       pr_err("failed to set SO_PRIORITY sock opt %d\n", ret);
+                       goto err_sock;
+               }
+       }
+
        ret = kernel_bind(port->sock, (struct sockaddr *)&port->addr,
                        sizeof(port->addr));
        if (ret) {
index 63502ca..80d2229 100644 (file)
@@ -636,10 +636,10 @@ dcssblk_add_store(struct device *dev, struct device_attribute *attr, const char
        }
        dev_info->gd->major = dcssblk_major;
        dev_info->gd->fops = &dcssblk_devops;
-       dev_info->dcssblk_queue = blk_alloc_queue(GFP_KERNEL);
+       dev_info->dcssblk_queue =
+               blk_alloc_queue(dcssblk_make_request, NUMA_NO_NODE);
        dev_info->gd->queue = dev_info->dcssblk_queue;
        dev_info->gd->private_data = dev_info;
-       blk_queue_make_request(dev_info->dcssblk_queue, dcssblk_make_request);
        blk_queue_logical_block_size(dev_info->dcssblk_queue, 4096);
        blk_queue_flag_set(QUEUE_FLAG_DAX, dev_info->dcssblk_queue);
 
index 3df5d68..45a04da 100644 (file)
@@ -343,14 +343,14 @@ static int __init xpram_setup_blkdev(void)
                xpram_disks[i] = alloc_disk(1);
                if (!xpram_disks[i])
                        goto out;
-               xpram_queues[i] = blk_alloc_queue(GFP_KERNEL);
+               xpram_queues[i] = blk_alloc_queue(xpram_make_request,
+                               NUMA_NO_NODE);
                if (!xpram_queues[i]) {
                        put_disk(xpram_disks[i]);
                        goto out;
                }
                blk_queue_flag_set(QUEUE_FLAG_NONROT, xpram_queues[i]);
                blk_queue_flag_clear(QUEUE_FLAG_ADD_RANDOM, xpram_queues[i]);
-               blk_queue_make_request(xpram_queues[i], xpram_make_request);
                blk_queue_logical_block_size(xpram_queues[i], 4096);
        }
 
index 3170b29..1862594 100644 (file)
@@ -36,6 +36,7 @@
 #include <linux/jiffies.h>
 #include <linux/dma-mapping.h>
 #include <linux/slab.h>
+#include <linux/msdos_partition.h>
 #include <scsi/scsicam.h>
 
 #include <asm/dma.h>
@@ -3410,9 +3411,10 @@ static int blogic_diskparam(struct scsi_device *sdev, struct block_device *dev,
           a partition table entry whose end_head matches one of the
           standard BusLogic geometry translations (64/32, 128/32, or 255/63).
         */
-       if (*(unsigned short *) (buf + 64) == 0xAA55) {
-               struct partition *part1_entry = (struct partition *) buf;
-               struct partition *part_entry = part1_entry;
+       if (*(unsigned short *) (buf + 64) == MSDOS_LABEL_MAGIC) {
+               struct msdos_partition *part1_entry =
+                               (struct msdos_partition *)buf;
+               struct msdos_partition *part_entry = part1_entry;
                int saved_cyl = diskparam->cylinders, part_no;
                unsigned char part_end_head = 0, part_end_sector = 0;
 
index a7881f8..1b6eaf8 100644 (file)
@@ -989,6 +989,7 @@ config SCSI_SYM53C8XX_MMIO
 config SCSI_IPR
        tristate "IBM Power Linux RAID adapter support"
        depends on PCI && SCSI && ATA
+       select SATA_HOST
        select FW_LOADER
        select IRQ_POLL
        select SGL_ALLOC
index ee6bc2f..0443b74 100644 (file)
@@ -33,6 +33,7 @@
 #include <linux/syscalls.h>
 #include <linux/delay.h>
 #include <linux/kthread.h>
+#include <linux/msdos_partition.h>
 
 #include <scsi/scsi.h>
 #include <scsi/scsi_cmnd.h>
@@ -328,9 +329,9 @@ static int aac_biosparm(struct scsi_device *sdev, struct block_device *bdev,
        buf = scsi_bios_ptable(bdev);
        if (!buf)
                return 0;
-       if(*(__le16 *)(buf + 0x40) == cpu_to_le16(0xaa55)) {
-               struct partition *first = (struct partition * )buf;
-               struct partition *entry = first;
+       if (*(__le16 *)(buf + 0x40) == cpu_to_le16(MSDOS_LABEL_MAGIC)) {
+               struct msdos_partition *first = (struct msdos_partition *)buf;
+               struct msdos_partition *entry = first;
                int saved_cylinders = param->cylinders;
                int num;
                unsigned char end_head, end_sec;
index 5799251..dc4fe33 100644 (file)
@@ -723,24 +723,17 @@ static int
 ahd_linux_biosparam(struct scsi_device *sdev, struct block_device *bdev,
                    sector_t capacity, int geom[])
 {
-       uint8_t *bh;
        int      heads;
        int      sectors;
        int      cylinders;
-       int      ret;
        int      extended;
        struct   ahd_softc *ahd;
 
        ahd = *((struct ahd_softc **)sdev->host->hostdata);
 
-       bh = scsi_bios_ptable(bdev);
-       if (bh) {
-               ret = scsi_partsize(bh, capacity,
-                                   &geom[2], &geom[0], &geom[1]);
-               kfree(bh);
-               if (ret != -1)
-                       return (ret);
-       }
+       if (scsi_partsize(bdev, capacity, geom))
+               return 0;
+
        heads = 64;
        sectors = 32;
        cylinders = aic_sector_div(capacity, heads, sectors);
index d5c4a0d..2edfa05 100644 (file)
@@ -695,11 +695,9 @@ static int
 ahc_linux_biosparam(struct scsi_device *sdev, struct block_device *bdev,
                    sector_t capacity, int geom[])
 {
-       uint8_t *bh;
        int      heads;
        int      sectors;
        int      cylinders;
-       int      ret;
        int      extended;
        struct   ahc_softc *ahc;
        u_int    channel;
@@ -707,14 +705,9 @@ ahc_linux_biosparam(struct scsi_device *sdev, struct block_device *bdev,
        ahc = *((struct ahc_softc **)sdev->host->hostdata);
        channel = sdev_channel(sdev);
 
-       bh = scsi_bios_ptable(bdev);
-       if (bh) {
-               ret = scsi_partsize(bh, capacity,
-                                   &geom[2], &geom[0], &geom[1]);
-               kfree(bh);
-               if (ret != -1)
-                       return (ret);
-       }
+       if (scsi_partsize(bdev, capacity, geom))
+               return 0;
+
        heads = 64;
        sectors = 32;
        cylinders = aic_sector_div(capacity, heads, sectors);
index 40dc8ea..c2c79a3 100644 (file)
@@ -353,16 +353,11 @@ static irqreturn_t arcmsr_do_interrupt(int irq, void *dev_id)
 static int arcmsr_bios_param(struct scsi_device *sdev,
                struct block_device *bdev, sector_t capacity, int *geom)
 {
-       int ret, heads, sectors, cylinders, total_capacity;
-       unsigned char *buffer;/* return copy of block device's partition table */
+       int heads, sectors, cylinders, total_capacity;
+
+       if (scsi_partsize(bdev, capacity, geom))
+               return 0;
 
-       buffer = scsi_bios_ptable(bdev);
-       if (buffer) {
-               ret = scsi_partsize(buffer, capacity, &geom[2], &geom[0], &geom[1]);
-               kfree(buffer);
-               if (ret != -1)
-                       return ret;
-       }
        total_capacity = capacity;
        heads = 64;
        sectors = 32;
index 5c6a5ef..052ee3a 100644 (file)
@@ -19,6 +19,7 @@ config SCSI_SAS_ATA
        bool "ATA support for libsas (requires libata)"
        depends on SCSI_SAS_LIBSAS
        depends on ATA = y || ATA = SCSI_SAS_LIBSAS
+       select SATA_HOST
        help
                Builds in ATA support into libsas.  Will necessitate
                the loading of libata along with libsas.
index ff6d4aa..f27ffd0 100644 (file)
@@ -2795,11 +2795,9 @@ megaraid_biosparam(struct scsi_device *sdev, struct block_device *bdev,
                    sector_t capacity, int geom[])
 {
        adapter_t       *adapter;
-       unsigned char   *bh;
        int     heads;
        int     sectors;
        int     cylinders;
-       int     rval;
 
        /* Get pointer to host config structure */
        adapter = (adapter_t *)sdev->host->hostdata;
@@ -2826,15 +2824,8 @@ megaraid_biosparam(struct scsi_device *sdev, struct block_device *bdev,
                        geom[2] = cylinders;
        }
        else {
-               bh = scsi_bios_ptable(bdev);
-
-               if( bh ) {
-                       rval = scsi_partsize(bh, capacity,
-                                           &geom[2], &geom[0], &geom[1]);
-                       kfree(bh);
-                       if( rval != -1 )
-                               return rval;
-               }
+               if (scsi_partsize(bdev, capacity, geom))
+                       return 0;
 
                dev_info(&adapter->dev->dev,
                         "invalid partition on this disk on channel %d\n",
index 44cb054..4c6c448 100644 (file)
@@ -38,6 +38,7 @@
 #include <linux/hrtimer.h>
 #include <linux/uuid.h>
 #include <linux/t10-pi.h>
+#include <linux/msdos_partition.h>
 
 #include <net/checksum.h>
 
@@ -4146,7 +4147,7 @@ static int scsi_debug_host_reset(struct scsi_cmnd *SCpnt)
 static void __init sdebug_build_parts(unsigned char *ramp,
                                      unsigned long store_size)
 {
-       struct partition *pp;
+       struct msdos_partition *pp;
        int starts[SDEBUG_MAX_PARTS + 2];
        int sectors_per_part, num_sectors, k;
        int heads_by_sects, start_sec, end_sec;
@@ -4171,7 +4172,7 @@ static void __init sdebug_build_parts(unsigned char *ramp,
 
        ramp[510] = 0x55;       /* magic partition markings */
        ramp[511] = 0xAA;
-       pp = (struct partition *)(ramp + 0x1be);
+       pp = (struct msdos_partition *)(ramp + 0x1be);
        for (k = 0; starts[k + 1]; ++k, ++pp) {
                start_sec = starts[k];
                end_sec = starts[k + 1] - 1;
index e969138..682cf08 100644 (file)
 #include <linux/genhd.h>
 #include <linux/kernel.h>
 #include <linux/blkdev.h>
+#include <linux/msdos_partition.h>
 #include <asm/unaligned.h>
 
 #include <scsi/scsicam.h>
 
-
-static int setsize(unsigned long capacity, unsigned int *cyls, unsigned int *hds,
-                  unsigned int *secs);
-
 /**
  * scsi_bios_ptable - Read PC partition table out of first sector of device.
  * @dev: from this device
@@ -35,105 +32,48 @@ static int setsize(unsigned long capacity, unsigned int *cyls, unsigned int *hds
  */
 unsigned char *scsi_bios_ptable(struct block_device *dev)
 {
-       unsigned char *res = kmalloc(66, GFP_KERNEL);
-       if (res) {
-               struct block_device *bdev = dev->bd_contains;
-               Sector sect;
-               void *data = read_dev_sector(bdev, 0, &sect);
-               if (data) {
-                       memcpy(res, data + 0x1be, 66);
-                       put_dev_sector(sect);
-               } else {
-                       kfree(res);
-                       res = NULL;
-               }
-       }
-       return res;
-}
-EXPORT_SYMBOL(scsi_bios_ptable);
-
-/**
- * scsicam_bios_param - Determine geometry of a disk in cylinders/heads/sectors.
- * @bdev: which device
- * @capacity: size of the disk in sectors
- * @ip: return value: ip[0]=heads, ip[1]=sectors, ip[2]=cylinders
- *
- * Description : determine the BIOS mapping/geometry used for a drive in a
- *      SCSI-CAM system, storing the results in ip as required
- *      by the HDIO_GETGEO ioctl().
- *
- * Returns : -1 on failure, 0 on success.
- */
-
-int scsicam_bios_param(struct block_device *bdev, sector_t capacity, int *ip)
-{
-       unsigned char *p;
-       u64 capacity64 = capacity;      /* Suppress gcc warning */
-       int ret;
-
-       p = scsi_bios_ptable(bdev);
-       if (!p)
-               return -1;
-
-       /* try to infer mapping from partition table */
-       ret = scsi_partsize(p, (unsigned long)capacity, (unsigned int *)ip + 2,
-                              (unsigned int *)ip + 0, (unsigned int *)ip + 1);
-       kfree(p);
-
-       if (ret == -1 && capacity64 < (1ULL << 32)) {
-               /* pick some standard mapping with at most 1024 cylinders,
-                  and at most 62 sectors per track - this works up to
-                  7905 MB */
-               ret = setsize((unsigned long)capacity, (unsigned int *)ip + 2,
-                      (unsigned int *)ip + 0, (unsigned int *)ip + 1);
-       }
-
-       /* if something went wrong, then apparently we have to return
-          a geometry with more than 1024 cylinders */
-       if (ret || ip[0] > 255 || ip[1] > 63) {
-               if ((capacity >> 11) > 65534) {
-                       ip[0] = 255;
-                       ip[1] = 63;
-               } else {
-                       ip[0] = 64;
-                       ip[1] = 32;
-               }
+       struct address_space *mapping = dev->bd_contains->bd_inode->i_mapping;
+       unsigned char *res = NULL;
+       struct page *page;
 
-               if (capacity > 65535*63*255)
-                       ip[2] = 65535;
-               else
-                       ip[2] = (unsigned long)capacity / (ip[0] * ip[1]);
-       }
+       page = read_mapping_page(mapping, 0, NULL);
+       if (IS_ERR(page))
+               return NULL;
 
-       return 0;
+       if (!PageError(page))
+               res = kmemdup(page_address(page) + 0x1be, 66, GFP_KERNEL);
+       put_page(page);
+       return res;
 }
-EXPORT_SYMBOL(scsicam_bios_param);
+EXPORT_SYMBOL(scsi_bios_ptable);
 
 /**
  * scsi_partsize - Parse cylinders/heads/sectors from PC partition table
- * @buf: partition table, see scsi_bios_ptable()
+ * @bdev: block device to parse
  * @capacity: size of the disk in sectors
- * @cyls: put cylinders here
- * @hds: put heads here
- * @secs: put sectors here
+ * @geom: output in form of [hds, cylinders, sectors]
  *
  * Determine the BIOS mapping/geometry used to create the partition
- * table, storing the results in @cyls, @hds, and @secs
+ * table, storing the results in @geom.
  *
- * Returns: -1 on failure, 0 on success.
+ * Returns: %false on failure, %true on success.
  */
-
-int scsi_partsize(unsigned char *buf, unsigned long capacity,
-              unsigned int *cyls, unsigned int *hds, unsigned int *secs)
+bool scsi_partsize(struct block_device *bdev, sector_t capacity, int geom[3])
 {
-       struct partition *p = (struct partition *)buf, *largest = NULL;
-       int i, largest_cyl;
        int cyl, ext_cyl, end_head, end_cyl, end_sector;
        unsigned int logical_end, physical_end, ext_physical_end;
+       struct msdos_partition *p, *largest = NULL;
+       void *buf;
+       int ret = false;
 
+       buf = scsi_bios_ptable(bdev);
+       if (!buf)
+               return false;
 
        if (*(unsigned short *) (buf + 64) == 0xAA55) {
-               for (largest_cyl = -1, i = 0; i < 4; ++i, ++p) {
+               int largest_cyl = -1, i;
+
+               for (i = 0, p = buf; i < 4; i++, p++) {
                        if (!p->sys_ind)
                                continue;
 #ifdef DEBUG
@@ -153,7 +93,7 @@ int scsi_partsize(unsigned char *buf, unsigned long capacity,
                end_sector = largest->end_sector & 0x3f;
 
                if (end_head + 1 == 0 || end_sector == 0)
-                       return -1;
+                       goto out_free_buf;
 
 #ifdef DEBUG
                printk("scsicam_bios_param : end at h = %d, c = %d, s = %d\n",
@@ -178,19 +118,24 @@ int scsi_partsize(unsigned char *buf, unsigned long capacity,
                  ,logical_end, physical_end, ext_physical_end, ext_cyl);
 #endif
 
-               if ((logical_end == physical_end) ||
-                 (end_cyl == 1023 && ext_physical_end == logical_end)) {
-                       *secs = end_sector;
-                       *hds = end_head + 1;
-                       *cyls = capacity / ((end_head + 1) * end_sector);
-                       return 0;
+               if (logical_end == physical_end ||
+                   (end_cyl == 1023 && ext_physical_end == logical_end)) {
+                       geom[0] = end_head + 1;
+                       geom[1] = end_sector;
+                       geom[2] = (unsigned long)capacity /
+                               ((end_head + 1) * end_sector);
+                       ret = true;
+                       goto out_free_buf;
                }
 #ifdef DEBUG
                printk("scsicam_bios_param : logical (%u) != physical (%u)\n",
                       logical_end, physical_end);
 #endif
        }
-       return -1;
+
+out_free_buf:
+       kfree(buf);
+       return ret;
 }
 EXPORT_SYMBOL(scsi_partsize);
 
@@ -258,3 +203,56 @@ static int setsize(unsigned long capacity, unsigned int *cyls, unsigned int *hds
        *hds = (unsigned int) heads;
        return (rv);
 }
+
+/**
+ * scsicam_bios_param - Determine geometry of a disk in cylinders/heads/sectors.
+ * @bdev: which device
+ * @capacity: size of the disk in sectors
+ * @ip: return value: ip[0]=heads, ip[1]=sectors, ip[2]=cylinders
+ *
+ * Description : determine the BIOS mapping/geometry used for a drive in a
+ *      SCSI-CAM system, storing the results in ip as required
+ *      by the HDIO_GETGEO ioctl().
+ *
+ * Returns : -1 on failure, 0 on success.
+ */
+int scsicam_bios_param(struct block_device *bdev, sector_t capacity, int *ip)
+{
+       u64 capacity64 = capacity;      /* Suppress gcc warning */
+       int ret = 0;
+
+       /* try to infer mapping from partition table */
+       if (scsi_partsize(bdev, capacity, ip))
+               return 0;
+
+       if (capacity64 < (1ULL << 32)) {
+               /*
+                * Pick some standard mapping with at most 1024 cylinders, and
+                * at most 62 sectors per track - this works up to 7905 MB.
+                */
+               ret = setsize((unsigned long)capacity, (unsigned int *)ip + 2,
+                      (unsigned int *)ip + 0, (unsigned int *)ip + 1);
+       }
+
+       /*
+        * If something went wrong, then apparently we have to return a geometry
+        * with more than 1024 cylinders.
+        */
+       if (ret || ip[0] > 255 || ip[1] > 63) {
+               if ((capacity >> 11) > 65534) {
+                       ip[0] = 255;
+                       ip[1] = 63;
+               } else {
+                       ip[0] = 64;
+                       ip[1] = 32;
+               }
+
+               if (capacity > 65535*63*255)
+                       ip[2] = 65535;
+               else
+                       ip[2] = (unsigned long)capacity / (ip[0] * ip[1]);
+       }
+
+       return 0;
+}
+EXPORT_SYMBOL(scsicam_bios_param);
index 2710a0e..a793cb0 100644 (file)
@@ -3189,7 +3189,8 @@ static int sd_revalidate_disk(struct gendisk *disk)
 
        sdkp->first_scan = 0;
 
-       set_capacity(disk, logical_to_sectors(sdp, sdkp->capacity));
+       set_capacity_revalidate_and_notify(disk,
+               logical_to_sectors(sdp, sdkp->capacity), false);
        sd_config_write_same(sdkp);
        kfree(buffer);
 
index 69bf2fb..9501880 100644 (file)
@@ -1520,10 +1520,22 @@ rescan:
        if (ret)
                return ret;
 
-       if (invalidate)
-               set_capacity(disk, 0);
-       else if (disk->fops->revalidate_disk)
-               disk->fops->revalidate_disk(disk);
+       /*
+        * Historically we only set the capacity to zero for devices that
+        * support partitions (independ of actually having partitions created).
+        * Doing that is rather inconsistent, but changing it broke legacy
+        * udisks polling for legacy ide-cdrom devices.  Use the crude check
+        * below to get the sane behavior for most device while not breaking
+        * userspace for this particular setup.
+        */
+       if (invalidate) {
+               if (disk_part_scan_enabled(disk) ||
+                   !(disk->flags & GENHD_FL_REMOVABLE))
+                       set_capacity(disk, 0);
+       } else {
+               if (disk->fops->revalidate_disk)
+                       disk->fops->revalidate_disk(disk);
+       }
 
        check_disk_size_change(disk, bdev, !invalidate);
 
index b8d2837..3f5758e 100644 (file)
@@ -3019,49 +3019,6 @@ static void end_bio_bh_io_sync(struct bio *bio)
        bio_put(bio);
 }
 
-/*
- * This allows us to do IO even on the odd last sectors
- * of a device, even if the block size is some multiple
- * of the physical sector size.
- *
- * We'll just truncate the bio to the size of the device,
- * and clear the end of the buffer head manually.
- *
- * Truly out-of-range accesses will turn into actual IO
- * errors, this only handles the "we need to be able to
- * do IO at the final sector" case.
- */
-void guard_bio_eod(struct bio *bio)
-{
-       sector_t maxsector;
-       struct hd_struct *part;
-
-       rcu_read_lock();
-       part = __disk_get_part(bio->bi_disk, bio->bi_partno);
-       if (part)
-               maxsector = part_nr_sects_read(part);
-       else
-               maxsector = get_capacity(bio->bi_disk);
-       rcu_read_unlock();
-
-       if (!maxsector)
-               return;
-
-       /*
-        * If the *whole* IO is past the end of the device,
-        * let it through, and the IO layer will turn it into
-        * an EIO.
-        */
-       if (unlikely(bio->bi_iter.bi_sector >= maxsector))
-               return;
-
-       maxsector -= bio->bi_iter.bi_sector;
-       if (likely((bio->bi_iter.bi_size >> 9) <= maxsector))
-               return;
-
-       bio_truncate(bio, maxsector << 9);
-}
-
 static int submit_bh_wbc(int op, int op_flags, struct buffer_head *bh,
                         enum rw_hint write_hint, struct writeback_control *wbc)
 {
index 5779a15..5d2d819 100644 (file)
@@ -157,17 +157,27 @@ static int z_erofs_lz4_decompress(struct z_erofs_decompress_req *rq, u8 *out)
                }
        }
 
-       ret = LZ4_decompress_safe_partial(src + inputmargin, out,
-                                         inlen, rq->outputsize,
-                                         rq->outputsize);
-       if (ret < 0) {
-               erofs_err(rq->sb, "failed to decompress, in[%u, %u] out[%u]",
-                         inlen, inputmargin, rq->outputsize);
+       /* legacy format could compress extra data in a pcluster. */
+       if (rq->partial_decoding || !support_0padding)
+               ret = LZ4_decompress_safe_partial(src + inputmargin, out,
+                                                 inlen, rq->outputsize,
+                                                 rq->outputsize);
+       else
+               ret = LZ4_decompress_safe(src + inputmargin, out,
+                                         inlen, rq->outputsize);
+
+       if (ret != rq->outputsize) {
+               erofs_err(rq->sb, "failed to decompress %d in[%u, %u] out[%u]",
+                         ret, inlen, inputmargin, rq->outputsize);
+
                WARN_ON(1);
                print_hex_dump(KERN_DEBUG, "[ in]: ", DUMP_PREFIX_OFFSET,
                               16, 1, src + inputmargin, inlen, true);
                print_hex_dump(KERN_DEBUG, "[out]: ", DUMP_PREFIX_OFFSET,
                               16, 1, out, rq->outputsize, true);
+
+               if (ret >= 0)
+                       memset(out + ret, 0, rq->outputsize - ret);
                ret = -EIO;
        }
 
index c4c6dcd..5eead7f 100644 (file)
@@ -52,8 +52,8 @@ struct erofs_sb_info {
        struct list_head list;
        struct mutex umount_mutex;
 
-       /* the dedicated workstation for compression */
-       struct radix_tree_root workstn_tree;
+       /* managed XArray arranged in physical block number */
+       struct xarray managed_pslots;
 
        /* threshold for decompression synchronously */
        unsigned int max_sync_decompress_pages;
@@ -402,8 +402,8 @@ static inline void *erofs_get_pcpubuf(unsigned int pagenr)
 int erofs_workgroup_put(struct erofs_workgroup *grp);
 struct erofs_workgroup *erofs_find_workgroup(struct super_block *sb,
                                             pgoff_t index);
-int erofs_register_workgroup(struct super_block *sb,
-                            struct erofs_workgroup *grp);
+struct erofs_workgroup *erofs_insert_workgroup(struct super_block *sb,
+                                              struct erofs_workgroup *grp);
 void erofs_workgroup_free_rcu(struct erofs_workgroup *grp);
 void erofs_shrinker_register(struct super_block *sb);
 void erofs_shrinker_unregister(struct super_block *sb);
index 057e6d7..b514c67 100644 (file)
@@ -425,7 +425,7 @@ static int erofs_fill_super(struct super_block *sb, void *data, int silent)
                sb->s_flags &= ~SB_POSIXACL;
 
 #ifdef CONFIG_EROFS_FS_ZIP
-       INIT_RADIX_TREE(&sbi->workstn_tree, GFP_ATOMIC);
+       xa_init(&sbi->managed_pslots);
 #endif
 
        /* get the root inode */
index fddc505..52d0be1 100644 (file)
@@ -37,9 +37,6 @@ void *erofs_get_pcpubuf(unsigned int pagenr)
 /* global shrink count (for all mounted EROFS instances) */
 static atomic_long_t erofs_global_shrink_cnt;
 
-#define __erofs_workgroup_get(grp)     atomic_inc(&(grp)->refcount)
-#define __erofs_workgroup_put(grp)     atomic_dec(&(grp)->refcount)
-
 static int erofs_workgroup_get(struct erofs_workgroup *grp)
 {
        int o;
@@ -66,7 +63,7 @@ struct erofs_workgroup *erofs_find_workgroup(struct super_block *sb,
 
 repeat:
        rcu_read_lock();
-       grp = radix_tree_lookup(&sbi->workstn_tree, index);
+       grp = xa_load(&sbi->managed_pslots, index);
        if (grp) {
                if (erofs_workgroup_get(grp)) {
                        /* prefer to relax rcu read side */
@@ -80,43 +77,37 @@ repeat:
        return grp;
 }
 
-int erofs_register_workgroup(struct super_block *sb,
-                            struct erofs_workgroup *grp)
+struct erofs_workgroup *erofs_insert_workgroup(struct super_block *sb,
+                                              struct erofs_workgroup *grp)
 {
-       struct erofs_sb_info *sbi;
-       int err;
-
-       /* grp shouldn't be broken or used before */
-       if (atomic_read(&grp->refcount) != 1) {
-               DBG_BUGON(1);
-               return -EINVAL;
-       }
-
-       err = radix_tree_preload(GFP_NOFS);
-       if (err)
-               return err;
-
-       sbi = EROFS_SB(sb);
-       xa_lock(&sbi->workstn_tree);
+       struct erofs_sb_info *const sbi = EROFS_SB(sb);
+       struct erofs_workgroup *pre;
 
        /*
-        * Bump up reference count before making this workgroup
-        * visible to other users in order to avoid potential UAF
-        * without serialized by workstn_lock.
+        * Bump up a reference count before making this visible
+        * to others for the XArray in order to avoid potential
+        * UAF without serialized by xa_lock.
         */
-       __erofs_workgroup_get(grp);
-
-       err = radix_tree_insert(&sbi->workstn_tree, grp->index, grp);
-       if (err)
-               /*
-                * it's safe to decrease since the workgroup isn't visible
-                * and refcount >= 2 (cannot be freezed).
-                */
-               __erofs_workgroup_put(grp);
+       atomic_inc(&grp->refcount);
 
-       xa_unlock(&sbi->workstn_tree);
-       radix_tree_preload_end();
-       return err;
+repeat:
+       xa_lock(&sbi->managed_pslots);
+       pre = __xa_cmpxchg(&sbi->managed_pslots, grp->index,
+                          NULL, grp, GFP_NOFS);
+       if (pre) {
+               if (xa_is_err(pre)) {
+                       pre = ERR_PTR(xa_err(pre));
+               } else if (erofs_workgroup_get(pre)) {
+                       /* try to legitimize the current in-tree one */
+                       xa_unlock(&sbi->managed_pslots);
+                       cond_resched();
+                       goto repeat;
+               }
+               atomic_dec(&grp->refcount);
+               grp = pre;
+       }
+       xa_unlock(&sbi->managed_pslots);
+       return grp;
 }
 
 static void  __erofs_workgroup_free(struct erofs_workgroup *grp)
@@ -155,7 +146,7 @@ static bool erofs_try_to_release_workgroup(struct erofs_sb_info *sbi,
 
        /*
         * Note that all cached pages should be unattached
-        * before deleted from the radix tree. Otherwise some
+        * before deleted from the XArray. Otherwise some
         * cached pages could be still attached to the orphan
         * old workgroup when the new one is available in the tree.
         */
@@ -169,7 +160,7 @@ static bool erofs_try_to_release_workgroup(struct erofs_sb_info *sbi,
         * however in order to avoid some race conditions, add a
         * DBG_BUGON to observe this in advance.
         */
-       DBG_BUGON(radix_tree_delete(&sbi->workstn_tree, grp->index) != grp);
+       DBG_BUGON(xa_erase(&sbi->managed_pslots, grp->index) != grp);
 
        /*
         * If managed cache is on, last refcount should indicate
@@ -182,22 +173,11 @@ static bool erofs_try_to_release_workgroup(struct erofs_sb_info *sbi,
 static unsigned long erofs_shrink_workstation(struct erofs_sb_info *sbi,
                                              unsigned long nr_shrink)
 {
-       pgoff_t first_index = 0;
-       void *batch[PAGEVEC_SIZE];
+       struct erofs_workgroup *grp;
        unsigned int freed = 0;
+       unsigned long index;
 
-       int i, found;
-repeat:
-       xa_lock(&sbi->workstn_tree);
-
-       found = radix_tree_gang_lookup(&sbi->workstn_tree,
-                                      batch, first_index, PAGEVEC_SIZE);
-
-       for (i = 0; i < found; ++i) {
-               struct erofs_workgroup *grp = batch[i];
-
-               first_index = grp->index + 1;
-
+       xa_for_each(&sbi->managed_pslots, index, grp) {
                /* try to shrink each valid workgroup */
                if (!erofs_try_to_release_workgroup(sbi, grp))
                        continue;
@@ -206,10 +186,6 @@ repeat:
                if (!--nr_shrink)
                        break;
        }
-       xa_unlock(&sbi->workstn_tree);
-
-       if (i && nr_shrink)
-               goto repeat;
        return freed;
 }
 
@@ -286,7 +262,7 @@ static unsigned long erofs_shrink_scan(struct shrinker *shrink,
                spin_unlock(&erofs_sb_list_lock);
                sbi->shrinker_run_no = run_no;
 
-               freed += erofs_shrink_workstation(sbi, nr);
+               freed += erofs_shrink_workstation(sbi, nr - freed);
 
                spin_lock(&erofs_sb_list_lock);
                /* Get the next list element before we move this one */
index 80e47f0..c4b6c9a 100644 (file)
@@ -67,16 +67,6 @@ static void z_erofs_pcluster_init_once(void *ptr)
                pcl->compressed_pages[i] = NULL;
 }
 
-static void z_erofs_pcluster_init_always(struct z_erofs_pcluster *pcl)
-{
-       struct z_erofs_collection *cl = z_erofs_primarycollection(pcl);
-
-       atomic_set(&pcl->obj.refcount, 1);
-
-       DBG_BUGON(cl->nr_pages);
-       DBG_BUGON(cl->vcnt);
-}
-
 int __init z_erofs_init_zip_subsystem(void)
 {
        pcluster_cachep = kmem_cache_create("erofs_compress",
@@ -341,26 +331,19 @@ static int z_erofs_lookup_collection(struct z_erofs_collector *clt,
                                     struct inode *inode,
                                     struct erofs_map_blocks *map)
 {
-       struct erofs_workgroup *grp;
-       struct z_erofs_pcluster *pcl;
+       struct z_erofs_pcluster *pcl = clt->pcl;
        struct z_erofs_collection *cl;
        unsigned int length;
 
-       grp = erofs_find_workgroup(inode->i_sb, map->m_pa >> PAGE_SHIFT);
-       if (!grp)
-               return -ENOENT;
-
-       pcl = container_of(grp, struct z_erofs_pcluster, obj);
+       /* to avoid unexpected loop formed by corrupted images */
        if (clt->owned_head == &pcl->next || pcl == clt->tailpcl) {
                DBG_BUGON(1);
-               erofs_workgroup_put(grp);
                return -EFSCORRUPTED;
        }
 
        cl = z_erofs_primarycollection(pcl);
        if (cl->pageofs != (map->m_la & ~PAGE_MASK)) {
                DBG_BUGON(1);
-               erofs_workgroup_put(grp);
                return -EFSCORRUPTED;
        }
 
@@ -368,7 +351,6 @@ static int z_erofs_lookup_collection(struct z_erofs_collector *clt,
        if (length & Z_EROFS_PCLUSTER_FULL_LENGTH) {
                if ((map->m_llen << Z_EROFS_PCLUSTER_LENGTH_BIT) > length) {
                        DBG_BUGON(1);
-                       erofs_workgroup_put(grp);
                        return -EFSCORRUPTED;
                }
        } else {
@@ -391,7 +373,6 @@ static int z_erofs_lookup_collection(struct z_erofs_collector *clt,
        /* clean tailpcl if the current owned_head is Z_EROFS_PCLUSTER_TAIL */
        if (clt->owned_head == Z_EROFS_PCLUSTER_TAIL)
                clt->tailpcl = NULL;
-       clt->pcl = pcl;
        clt->cl = cl;
        return 0;
 }
@@ -402,6 +383,7 @@ static int z_erofs_register_collection(struct z_erofs_collector *clt,
 {
        struct z_erofs_pcluster *pcl;
        struct z_erofs_collection *cl;
+       struct erofs_workgroup *grp;
        int err;
 
        /* no available workgroup, let's allocate one */
@@ -409,7 +391,7 @@ static int z_erofs_register_collection(struct z_erofs_collector *clt,
        if (!pcl)
                return -ENOMEM;
 
-       z_erofs_pcluster_init_always(pcl);
+       atomic_set(&pcl->obj.refcount, 1);
        pcl->obj.index = map->m_pa >> PAGE_SHIFT;
 
        pcl->length = (map->m_llen << Z_EROFS_PCLUSTER_LENGTH_BIT) |
@@ -429,19 +411,29 @@ static int z_erofs_register_collection(struct z_erofs_collector *clt,
        clt->mode = COLLECT_PRIMARY_FOLLOWED;
 
        cl = z_erofs_primarycollection(pcl);
+
+       /* must be cleaned before freeing to slab */
+       DBG_BUGON(cl->nr_pages);
+       DBG_BUGON(cl->vcnt);
+
        cl->pageofs = map->m_la & ~PAGE_MASK;
 
        /*
         * lock all primary followed works before visible to others
         * and mutex_trylock *never* fails for a new pcluster.
         */
-       mutex_trylock(&cl->lock);
+       DBG_BUGON(!mutex_trylock(&cl->lock));
 
-       err = erofs_register_workgroup(inode->i_sb, &pcl->obj);
-       if (err) {
-               mutex_unlock(&cl->lock);
-               kmem_cache_free(pcluster_cachep, pcl);
-               return -EAGAIN;
+       grp = erofs_insert_workgroup(inode->i_sb, &pcl->obj);
+       if (IS_ERR(grp)) {
+               err = PTR_ERR(grp);
+               goto err_out;
+       }
+
+       if (grp != &pcl->obj) {
+               clt->pcl = container_of(grp, struct z_erofs_pcluster, obj);
+               err = -EEXIST;
+               goto err_out;
        }
        /* used to check tail merging loop due to corrupted images */
        if (clt->owned_head == Z_EROFS_PCLUSTER_TAIL)
@@ -450,12 +442,18 @@ static int z_erofs_register_collection(struct z_erofs_collector *clt,
        clt->pcl = pcl;
        clt->cl = cl;
        return 0;
+
+err_out:
+       mutex_unlock(&cl->lock);
+       kmem_cache_free(pcluster_cachep, pcl);
+       return err;
 }
 
 static int z_erofs_collector_begin(struct z_erofs_collector *clt,
                                   struct inode *inode,
                                   struct erofs_map_blocks *map)
 {
+       struct erofs_workgroup *grp;
        int ret;
 
        DBG_BUGON(clt->cl);
@@ -469,21 +467,25 @@ static int z_erofs_collector_begin(struct z_erofs_collector *clt,
                return -EINVAL;
        }
 
-repeat:
-       ret = z_erofs_lookup_collection(clt, inode, map);
-       if (ret == -ENOENT) {
+       grp = erofs_find_workgroup(inode->i_sb, map->m_pa >> PAGE_SHIFT);
+       if (grp) {
+               clt->pcl = container_of(grp, struct z_erofs_pcluster, obj);
+       } else {
                ret = z_erofs_register_collection(clt, inode, map);
 
-               /* someone registered at the same time, give another try */
-               if (ret == -EAGAIN) {
-                       cond_resched();
-                       goto repeat;
-               }
+               if (!ret)
+                       goto out;
+               if (ret != -EEXIST)
+                       return ret;
        }
 
-       if (ret)
+       ret = z_erofs_lookup_collection(clt, inode, map);
+       if (ret) {
+               erofs_workgroup_put(&clt->pcl->obj);
                return ret;
+       }
 
+out:
        z_erofs_pagevec_ctor_init(&clt->vector, Z_EROFS_NR_INLINE_PAGEVECS,
                                  clt->cl->pagevec, clt->cl->vcnt);
 
index 0c7c4ad..c8dff4c 100644 (file)
@@ -43,7 +43,7 @@
 #include <linux/uaccess.h>
 #include <linux/iversion.h>
 #include <linux/unicode.h>
-
+#include <linux/part_stat.h>
 #include <linux/kthread.h>
 #include <linux/freezer.h>
 
@@ -927,7 +927,6 @@ void ext4_update_dynamic_rev(struct super_block *sb)
 static struct block_device *ext4_blkdev_get(dev_t dev, struct super_block *sb)
 {
        struct block_device *bdev;
-       char b[BDEVNAME_SIZE];
 
        bdev = blkdev_get_by_dev(dev, FMODE_READ|FMODE_WRITE|FMODE_EXCL, sb);
        if (IS_ERR(bdev))
@@ -935,8 +934,9 @@ static struct block_device *ext4_blkdev_get(dev_t dev, struct super_block *sb)
        return bdev;
 
 fail:
-       ext4_msg(sb, KERN_ERR, "failed to open journal device %s: %ld",
-                       __bdevname(dev, b), PTR_ERR(bdev));
+       ext4_msg(sb, KERN_ERR,
+                "failed to open journal device unknown-block(%u,%u) %ld",
+                MAJOR(dev), MINOR(dev), PTR_ERR(bdev));
        return NULL;
 }
 
index d218ebd..04bfaf6 100644 (file)
@@ -13,6 +13,7 @@
 #include <linux/seq_file.h>
 #include <linux/slab.h>
 #include <linux/proc_fs.h>
+#include <linux/part_stat.h>
 
 #include "ext4.h"
 #include "ext4_jbd2.h"
index 5355be6..088c3e7 100644 (file)
@@ -22,6 +22,7 @@
 #include <linux/bio.h>
 #include <linux/blkdev.h>
 #include <linux/quotaops.h>
+#include <linux/part_stat.h>
 #include <crypto/hash.h>
 
 #include <linux/fscrypt.h>
index 65a7a43..d398b2d 100644 (file)
@@ -24,6 +24,7 @@
 #include <linux/sysfs.h>
 #include <linux/quota.h>
 #include <linux/unicode.h>
+#include <linux/part_stat.h>
 
 #include "f2fs.h"
 #include "node.h"
index f3f280b..4d37912 100644 (file)
@@ -38,7 +38,6 @@ static inline int __sync_blockdev(struct block_device *bdev, int wait)
 /*
  * buffer.c
  */
-extern void guard_bio_eod(struct bio *bio);
 extern int __block_write_begin_int(struct page *page, loff_t pos, unsigned len,
                get_block_t *get_block, struct iomap *iomap);
 
index 5cef075..cc5cf22 100644 (file)
@@ -69,6 +69,8 @@ struct io_worker {
 #define IO_WQ_HASH_ORDER       5
 #endif
 
+#define IO_WQ_NR_HASH_BUCKETS  (1u << IO_WQ_HASH_ORDER)
+
 struct io_wqe_acct {
        unsigned nr_workers;
        unsigned max_workers;
@@ -98,6 +100,7 @@ struct io_wqe {
        struct list_head all_list;
 
        struct io_wq *wq;
+       struct io_wq_work *hash_tail[IO_WQ_NR_HASH_BUCKETS];
 };
 
 /*
@@ -107,8 +110,7 @@ struct io_wq {
        struct io_wqe **wqes;
        unsigned long state;
 
-       get_work_fn *get_work;
-       put_work_fn *put_work;
+       free_work_fn *free_work;
 
        struct task_struct *manager;
        struct user_struct *user;
@@ -376,26 +378,35 @@ static bool __io_worker_idle(struct io_wqe *wqe, struct io_worker *worker)
        return __io_worker_unuse(wqe, worker);
 }
 
-static struct io_wq_work *io_get_next_work(struct io_wqe *wqe, unsigned *hash)
+static inline unsigned int io_get_work_hash(struct io_wq_work *work)
+{
+       return work->flags >> IO_WQ_HASH_SHIFT;
+}
+
+static struct io_wq_work *io_get_next_work(struct io_wqe *wqe)
        __must_hold(wqe->lock)
 {
        struct io_wq_work_node *node, *prev;
-       struct io_wq_work *work;
+       struct io_wq_work *work, *tail;
+       unsigned int hash;
 
        wq_list_for_each(node, prev, &wqe->work_list) {
                work = container_of(node, struct io_wq_work, list);
 
                /* not hashed, can run anytime */
-               if (!(work->flags & IO_WQ_WORK_HASHED)) {
-                       wq_node_del(&wqe->work_list, node, prev);
+               if (!io_wq_is_hashed(work)) {
+                       wq_list_del(&wqe->work_list, node, prev);
                        return work;
                }
 
                /* hashed, can run if not already running */
-               *hash = work->flags >> IO_WQ_HASH_SHIFT;
-               if (!(wqe->hash_map & BIT_ULL(*hash))) {
-                       wqe->hash_map |= BIT_ULL(*hash);
-                       wq_node_del(&wqe->work_list, node, prev);
+               hash = io_get_work_hash(work);
+               if (!(wqe->hash_map & BIT(hash))) {
+                       wqe->hash_map |= BIT(hash);
+                       /* all items with this hash lie in [work, tail] */
+                       tail = wqe->hash_tail[hash];
+                       wqe->hash_tail[hash] = NULL;
+                       wq_list_cut(&wqe->work_list, &tail->list, prev);
                        return work;
                }
        }
@@ -440,16 +451,49 @@ static void io_wq_switch_creds(struct io_worker *worker,
                worker->saved_creds = old_creds;
 }
 
+static void io_impersonate_work(struct io_worker *worker,
+                               struct io_wq_work *work)
+{
+       if (work->files && current->files != work->files) {
+               task_lock(current);
+               current->files = work->files;
+               task_unlock(current);
+       }
+       if (work->fs && current->fs != work->fs)
+               current->fs = work->fs;
+       if (work->mm != worker->mm)
+               io_wq_switch_mm(worker, work);
+       if (worker->cur_creds != work->creds)
+               io_wq_switch_creds(worker, work);
+}
+
+static void io_assign_current_work(struct io_worker *worker,
+                                  struct io_wq_work *work)
+{
+       if (work) {
+               /* flush pending signals before assigning new work */
+               if (signal_pending(current))
+                       flush_signals(current);
+               cond_resched();
+       }
+
+       spin_lock_irq(&worker->lock);
+       worker->cur_work = work;
+       spin_unlock_irq(&worker->lock);
+}
+
+static void io_wqe_enqueue(struct io_wqe *wqe, struct io_wq_work *work);
+
 static void io_worker_handle_work(struct io_worker *worker)
        __releases(wqe->lock)
 {
-       struct io_wq_work *work, *old_work = NULL, *put_work = NULL;
        struct io_wqe *wqe = worker->wqe;
        struct io_wq *wq = wqe->wq;
 
        do {
-               unsigned hash = -1U;
-
+               struct io_wq_work *work;
+               unsigned int hash;
+get_next:
                /*
                 * If we got some work, mark us as busy. If we didn't, but
                 * the list isn't empty, it means we stalled on hashed work.
@@ -457,81 +501,60 @@ static void io_worker_handle_work(struct io_worker *worker)
                 * can't make progress, any work completion or insertion will
                 * clear the stalled flag.
                 */
-               work = io_get_next_work(wqe, &hash);
+               work = io_get_next_work(wqe);
                if (work)
                        __io_worker_busy(wqe, worker, work);
                else if (!wq_list_empty(&wqe->work_list))
                        wqe->flags |= IO_WQE_FLAG_STALLED;
 
                spin_unlock_irq(&wqe->lock);
-               if (put_work && wq->put_work)
-                       wq->put_work(old_work);
                if (!work)
                        break;
-next:
-               /* flush any pending signals before assigning new work */
-               if (signal_pending(current))
-                       flush_signals(current);
-
-               cond_resched();
-
-               spin_lock_irq(&worker->lock);
-               worker->cur_work = work;
-               spin_unlock_irq(&worker->lock);
-
-               if (work->flags & IO_WQ_WORK_CB)
-                       work->func(&work);
-
-               if (work->files && current->files != work->files) {
-                       task_lock(current);
-                       current->files = work->files;
-                       task_unlock(current);
-               }
-               if (work->fs && current->fs != work->fs)
-                       current->fs = work->fs;
-               if (work->mm != worker->mm)
-                       io_wq_switch_mm(worker, work);
-               if (worker->cur_creds != work->creds)
-                       io_wq_switch_creds(worker, work);
-               /*
-                * OK to set IO_WQ_WORK_CANCEL even for uncancellable work,
-                * the worker function will do the right thing.
-                */
-               if (test_bit(IO_WQ_BIT_CANCEL, &wq->state))
-                       work->flags |= IO_WQ_WORK_CANCEL;
-               if (worker->mm)
-                       work->flags |= IO_WQ_WORK_HAS_MM;
-
-               if (wq->get_work) {
-                       put_work = work;
-                       wq->get_work(work);
-               }
-
-               old_work = work;
-               work->func(&work);
-
-               spin_lock_irq(&worker->lock);
-               worker->cur_work = NULL;
-               spin_unlock_irq(&worker->lock);
-
-               spin_lock_irq(&wqe->lock);
-
-               if (hash != -1U) {
-                       wqe->hash_map &= ~BIT_ULL(hash);
-                       wqe->flags &= ~IO_WQE_FLAG_STALLED;
-               }
-               if (work && work != old_work) {
-                       spin_unlock_irq(&wqe->lock);
-
-                       if (put_work && wq->put_work) {
-                               wq->put_work(put_work);
-                               put_work = NULL;
+               io_assign_current_work(worker, work);
+
+               /* handle a whole dependent link */
+               do {
+                       struct io_wq_work *old_work, *next_hashed, *linked;
+
+                       next_hashed = wq_next_work(work);
+                       io_impersonate_work(worker, work);
+                       /*
+                        * OK to set IO_WQ_WORK_CANCEL even for uncancellable
+                        * work, the worker function will do the right thing.
+                        */
+                       if (test_bit(IO_WQ_BIT_CANCEL, &wq->state))
+                               work->flags |= IO_WQ_WORK_CANCEL;
+
+                       hash = io_get_work_hash(work);
+                       linked = old_work = work;
+                       linked->func(&linked);
+                       linked = (old_work == linked) ? NULL : linked;
+
+                       work = next_hashed;
+                       if (!work && linked && !io_wq_is_hashed(linked)) {
+                               work = linked;
+                               linked = NULL;
                        }
+                       io_assign_current_work(worker, work);
+                       wq->free_work(old_work);
+
+                       if (linked)
+                               io_wqe_enqueue(wqe, linked);
+
+                       if (hash != -1U && !next_hashed) {
+                               spin_lock_irq(&wqe->lock);
+                               wqe->hash_map &= ~BIT_ULL(hash);
+                               wqe->flags &= ~IO_WQE_FLAG_STALLED;
+                               /* dependent work is not hashed */
+                               hash = -1U;
+                               /* skip unnecessary unlock-lock wqe->lock */
+                               if (!work)
+                                       goto get_next;
+                               spin_unlock_irq(&wqe->lock);
+                       }
+               } while (work);
 
-                       /* dependent work not hashed */
-                       hash = -1U;
-                       goto next;
-               }
+               spin_lock_irq(&wqe->lock);
        } while (1);
 }
 
@@ -747,17 +770,40 @@ static bool io_wq_can_queue(struct io_wqe *wqe, struct io_wqe_acct *acct,
        return true;
 }
 
-static void io_run_cancel(struct io_wq_work *work)
+static void io_run_cancel(struct io_wq_work *work, struct io_wqe *wqe)
 {
+       struct io_wq *wq = wqe->wq;
+
        do {
                struct io_wq_work *old_work = work;
 
                work->flags |= IO_WQ_WORK_CANCEL;
                work->func(&work);
                work = (work == old_work) ? NULL : work;
+               wq->free_work(old_work);
        } while (work);
 }
 
+static void io_wqe_insert_work(struct io_wqe *wqe, struct io_wq_work *work)
+{
+       unsigned int hash;
+       struct io_wq_work *tail;
+
+       if (!io_wq_is_hashed(work)) {
+append:
+               wq_list_add_tail(&work->list, &wqe->work_list);
+               return;
+       }
+
+       hash = io_get_work_hash(work);
+       tail = wqe->hash_tail[hash];
+       wqe->hash_tail[hash] = work;
+       if (!tail)
+               goto append;
+
+       wq_list_add_after(&work->list, &tail->list, &wqe->work_list);
+}
+
 static void io_wqe_enqueue(struct io_wqe *wqe, struct io_wq_work *work)
 {
        struct io_wqe_acct *acct = io_work_get_acct(wqe, work);
@@ -771,13 +817,13 @@ static void io_wqe_enqueue(struct io_wqe *wqe, struct io_wq_work *work)
         * It's close enough to not be an issue, fork() has the same delay.
         */
        if (unlikely(!io_wq_can_queue(wqe, acct, work))) {
-               io_run_cancel(work);
+               io_run_cancel(work, wqe);
                return;
        }
 
        work_flags = work->flags;
        spin_lock_irqsave(&wqe->lock, flags);
-       wq_list_add_tail(&work->list, &wqe->work_list);
+       io_wqe_insert_work(wqe, work);
        wqe->flags &= ~IO_WQE_FLAG_STALLED;
        spin_unlock_irqrestore(&wqe->lock, flags);
 
@@ -794,19 +840,15 @@ void io_wq_enqueue(struct io_wq *wq, struct io_wq_work *work)
 }
 
 /*
- * Enqueue work, hashed by some key. Work items that hash to the same value
- * will not be done in parallel. Used to limit concurrent writes, generally
- * hashed by inode.
+ * Work items that hash to the same value will not be done in parallel.
+ * Used to limit concurrent writes, generally hashed by inode.
  */
-void io_wq_enqueue_hashed(struct io_wq *wq, struct io_wq_work *work, void *val)
+void io_wq_hash_work(struct io_wq_work *work, void *val)
 {
-       struct io_wqe *wqe = wq->wqes[numa_node_id()];
-       unsigned bit;
-
+       unsigned int bit;
 
        bit = hash_ptr(val, IO_WQ_HASH_ORDER);
        work->flags |= (IO_WQ_WORK_HASHED | (bit << IO_WQ_HASH_SHIFT));
-       io_wqe_enqueue(wqe, work);
 }
 
 static bool io_wqe_worker_send_sig(struct io_worker *worker, void *data)
@@ -856,14 +898,13 @@ void io_wq_cancel_all(struct io_wq *wq)
 }
 
 struct io_cb_cancel_data {
-       struct io_wqe *wqe;
-       work_cancel_fn *cancel;
-       void *caller_data;
+       work_cancel_fn *fn;
+       void *data;
 };
 
-static bool io_work_cancel(struct io_worker *worker, void *cancel_data)
+static bool io_wq_worker_cancel(struct io_worker *worker, void *data)
 {
-       struct io_cb_cancel_data *data = cancel_data;
+       struct io_cb_cancel_data *match = data;
        unsigned long flags;
        bool ret = false;
 
@@ -874,83 +915,7 @@ static bool io_work_cancel(struct io_worker *worker, void *cancel_data)
        spin_lock_irqsave(&worker->lock, flags);
        if (worker->cur_work &&
            !(worker->cur_work->flags & IO_WQ_WORK_NO_CANCEL) &&
-           data->cancel(worker->cur_work, data->caller_data)) {
-               send_sig(SIGINT, worker->task, 1);
-               ret = true;
-       }
-       spin_unlock_irqrestore(&worker->lock, flags);
-
-       return ret;
-}
-
-static enum io_wq_cancel io_wqe_cancel_cb_work(struct io_wqe *wqe,
-                                              work_cancel_fn *cancel,
-                                              void *cancel_data)
-{
-       struct io_cb_cancel_data data = {
-               .wqe = wqe,
-               .cancel = cancel,
-               .caller_data = cancel_data,
-       };
-       struct io_wq_work_node *node, *prev;
-       struct io_wq_work *work;
-       unsigned long flags;
-       bool found = false;
-
-       spin_lock_irqsave(&wqe->lock, flags);
-       wq_list_for_each(node, prev, &wqe->work_list) {
-               work = container_of(node, struct io_wq_work, list);
-
-               if (cancel(work, cancel_data)) {
-                       wq_node_del(&wqe->work_list, node, prev);
-                       found = true;
-                       break;
-               }
-       }
-       spin_unlock_irqrestore(&wqe->lock, flags);
-
-       if (found) {
-               io_run_cancel(work);
-               return IO_WQ_CANCEL_OK;
-       }
-
-       rcu_read_lock();
-       found = io_wq_for_each_worker(wqe, io_work_cancel, &data);
-       rcu_read_unlock();
-       return found ? IO_WQ_CANCEL_RUNNING : IO_WQ_CANCEL_NOTFOUND;
-}
-
-enum io_wq_cancel io_wq_cancel_cb(struct io_wq *wq, work_cancel_fn *cancel,
-                                 void *data)
-{
-       enum io_wq_cancel ret = IO_WQ_CANCEL_NOTFOUND;
-       int node;
-
-       for_each_node(node) {
-               struct io_wqe *wqe = wq->wqes[node];
-
-               ret = io_wqe_cancel_cb_work(wqe, cancel, data);
-               if (ret != IO_WQ_CANCEL_NOTFOUND)
-                       break;
-       }
-
-       return ret;
-}
-
-struct work_match {
-       bool (*fn)(struct io_wq_work *, void *data);
-       void *data;
-};
-
-static bool io_wq_worker_cancel(struct io_worker *worker, void *data)
-{
-       struct work_match *match = data;
-       unsigned long flags;
-       bool ret = false;
-
-       spin_lock_irqsave(&worker->lock, flags);
-       if (match->fn(worker->cur_work, match->data) &&
-           !(worker->cur_work->flags & IO_WQ_WORK_NO_CANCEL)) {
+           match->fn(worker->cur_work, match->data)) {
                send_sig(SIGINT, worker->task, 1);
                ret = true;
        }
@@ -960,7 +925,7 @@ static bool io_wq_worker_cancel(struct io_worker *worker, void *data)
 }
 
 static enum io_wq_cancel io_wqe_cancel_work(struct io_wqe *wqe,
-                                           struct work_match *match)
+                                           struct io_cb_cancel_data *match)
 {
        struct io_wq_work_node *node, *prev;
        struct io_wq_work *work;
@@ -977,7 +942,7 @@ static enum io_wq_cancel io_wqe_cancel_work(struct io_wqe *wqe,
                work = container_of(node, struct io_wq_work, list);
 
                if (match->fn(work, match->data)) {
-                       wq_node_del(&wqe->work_list, node, prev);
+                       wq_list_del(&wqe->work_list, node, prev);
                        found = true;
                        break;
                }
@@ -985,7 +950,7 @@ static enum io_wq_cancel io_wqe_cancel_work(struct io_wqe *wqe,
        spin_unlock_irqrestore(&wqe->lock, flags);
 
        if (found) {
-               io_run_cancel(work);
+               io_run_cancel(work, wqe);
                return IO_WQ_CANCEL_OK;
        }
 
@@ -1001,22 +966,16 @@ static enum io_wq_cancel io_wqe_cancel_work(struct io_wqe *wqe,
        return found ? IO_WQ_CANCEL_RUNNING : IO_WQ_CANCEL_NOTFOUND;
 }
 
-static bool io_wq_work_match(struct io_wq_work *work, void *data)
-{
-       return work == data;
-}
-
-enum io_wq_cancel io_wq_cancel_work(struct io_wq *wq, struct io_wq_work *cwork)
+enum io_wq_cancel io_wq_cancel_cb(struct io_wq *wq, work_cancel_fn *cancel,
+                                 void *data)
 {
-       struct work_match match = {
-               .fn     = io_wq_work_match,
-               .data   = cwork
+       struct io_cb_cancel_data match = {
+               .fn     = cancel,
+               .data   = data,
        };
        enum io_wq_cancel ret = IO_WQ_CANCEL_NOTFOUND;
        int node;
 
-       cwork->flags |= IO_WQ_WORK_CANCEL;
-
        for_each_node(node) {
                struct io_wqe *wqe = wq->wqes[node];
 
@@ -1028,33 +987,28 @@ enum io_wq_cancel io_wq_cancel_work(struct io_wq *wq, struct io_wq_work *cwork)
        return ret;
 }
 
+static bool io_wq_io_cb_cancel_data(struct io_wq_work *work, void *data)
+{
+       return work == data;
+}
+
+enum io_wq_cancel io_wq_cancel_work(struct io_wq *wq, struct io_wq_work *cwork)
+{
+       return io_wq_cancel_cb(wq, io_wq_io_cb_cancel_data, (void *)cwork);
+}
+
 static bool io_wq_pid_match(struct io_wq_work *work, void *data)
 {
        pid_t pid = (pid_t) (unsigned long) data;
 
-       if (work)
-               return work->task_pid == pid;
-       return false;
+       return work->task_pid == pid;
 }
 
 enum io_wq_cancel io_wq_cancel_pid(struct io_wq *wq, pid_t pid)
 {
-       struct work_match match = {
-               .fn     = io_wq_pid_match,
-               .data   = (void *) (unsigned long) pid
-       };
-       enum io_wq_cancel ret = IO_WQ_CANCEL_NOTFOUND;
-       int node;
-
-       for_each_node(node) {
-               struct io_wqe *wqe = wq->wqes[node];
+       void *data = (void *) (unsigned long) pid;
 
-               ret = io_wqe_cancel_work(wqe, &match);
-               if (ret != IO_WQ_CANCEL_NOTFOUND)
-                       break;
-       }
-
-       return ret;
+       return io_wq_cancel_cb(wq, io_wq_pid_match, data);
 }
 
 struct io_wq *io_wq_create(unsigned bounded, struct io_wq_data *data)
@@ -1062,6 +1016,9 @@ struct io_wq *io_wq_create(unsigned bounded, struct io_wq_data *data)
        int ret = -ENOMEM, node;
        struct io_wq *wq;
 
+       if (WARN_ON_ONCE(!data->free_work))
+               return ERR_PTR(-EINVAL);
+
        wq = kzalloc(sizeof(*wq), GFP_KERNEL);
        if (!wq)
                return ERR_PTR(-ENOMEM);
@@ -1072,8 +1029,7 @@ struct io_wq *io_wq_create(unsigned bounded, struct io_wq_data *data)
                return ERR_PTR(-ENOMEM);
        }
 
-       wq->get_work = data->get_work;
-       wq->put_work = data->put_work;
+       wq->free_work = data->free_work;
 
        /* caller must already hold a reference to this */
        wq->user = data->user;
@@ -1130,7 +1086,7 @@ err:
 
 bool io_wq_get(struct io_wq *wq, struct io_wq_data *data)
 {
-       if (data->get_work != wq->get_work || data->put_work != wq->put_work)
+       if (data->free_work != wq->free_work)
                return false;
 
        return refcount_inc_not_zero(&wq->use_refs);
index e5e15f2..3ee7356 100644 (file)
@@ -5,10 +5,8 @@ struct io_wq;
 
 enum {
        IO_WQ_WORK_CANCEL       = 1,
-       IO_WQ_WORK_HAS_MM       = 2,
        IO_WQ_WORK_HASHED       = 4,
        IO_WQ_WORK_UNBOUND      = 32,
-       IO_WQ_WORK_CB           = 128,
        IO_WQ_WORK_NO_CANCEL    = 256,
        IO_WQ_WORK_CONCURRENT   = 512,
 
@@ -30,6 +28,18 @@ struct io_wq_work_list {
        struct io_wq_work_node *last;
 };
 
+static inline void wq_list_add_after(struct io_wq_work_node *node,
+                                    struct io_wq_work_node *pos,
+                                    struct io_wq_work_list *list)
+{
+       struct io_wq_work_node *next = pos->next;
+
+       pos->next = node;
+       node->next = next;
+       if (!next)
+               list->last = node;
+}
+
 static inline void wq_list_add_tail(struct io_wq_work_node *node,
                                    struct io_wq_work_list *list)
 {
@@ -42,17 +52,26 @@ static inline void wq_list_add_tail(struct io_wq_work_node *node,
        }
 }
 
-static inline void wq_node_del(struct io_wq_work_list *list,
-                              struct io_wq_work_node *node,
+static inline void wq_list_cut(struct io_wq_work_list *list,
+                              struct io_wq_work_node *last,
                               struct io_wq_work_node *prev)
 {
-       if (node == list->first)
-               WRITE_ONCE(list->first, node->next);
-       if (node == list->last)
+       /* first in the list, if prev==NULL */
+       if (!prev)
+               WRITE_ONCE(list->first, last->next);
+       else
+               prev->next = last->next;
+
+       if (last == list->last)
                list->last = prev;
-       if (prev)
-               prev->next = node->next;
-       node->next = NULL;
+       last->next = NULL;
+}
+
+static inline void wq_list_del(struct io_wq_work_list *list,
+                              struct io_wq_work_node *node,
+                              struct io_wq_work_node *prev)
+{
+       wq_list_cut(list, node, prev);
 }
 
 #define wq_list_for_each(pos, prv, head)                       \
@@ -65,10 +84,7 @@ static inline void wq_node_del(struct io_wq_work_list *list,
 } while (0)
 
 struct io_wq_work {
-       union {
-               struct io_wq_work_node list;
-               void *data;
-       };
+       struct io_wq_work_node list;
        void (*func)(struct io_wq_work **);
        struct files_struct *files;
        struct mm_struct *mm;
@@ -83,14 +99,20 @@ struct io_wq_work {
                *(work) = (struct io_wq_work){ .func = _func }; \
        } while (0)                                             \
 
-typedef void (get_work_fn)(struct io_wq_work *);
-typedef void (put_work_fn)(struct io_wq_work *);
+static inline struct io_wq_work *wq_next_work(struct io_wq_work *work)
+{
+       if (!work->list.next)
+               return NULL;
+
+       return container_of(work->list.next, struct io_wq_work, list);
+}
+
+typedef void (free_work_fn)(struct io_wq_work *);
 
 struct io_wq_data {
        struct user_struct *user;
 
-       get_work_fn *get_work;
-       put_work_fn *put_work;
+       free_work_fn *free_work;
 };
 
 struct io_wq *io_wq_create(unsigned bounded, struct io_wq_data *data);
@@ -98,7 +120,12 @@ bool io_wq_get(struct io_wq *wq, struct io_wq_data *data);
 void io_wq_destroy(struct io_wq *wq);
 
 void io_wq_enqueue(struct io_wq *wq, struct io_wq_work *work);
-void io_wq_enqueue_hashed(struct io_wq *wq, struct io_wq_work *work, void *val);
+void io_wq_hash_work(struct io_wq_work *work, void *val);
+
+static inline bool io_wq_is_hashed(struct io_wq_work *work)
+{
+       return work->flags & IO_WQ_WORK_HASHED;
+}
 
 void io_wq_cancel_all(struct io_wq *wq);
 enum io_wq_cancel io_wq_cancel_work(struct io_wq *wq, struct io_wq_work *cwork);
index 3affd96..358f97b 100644 (file)
@@ -44,6 +44,7 @@
 #include <linux/errno.h>
 #include <linux/syscalls.h>
 #include <linux/compat.h>
+#include <net/compat.h>
 #include <linux/refcount.h>
 #include <linux/uio.h>
 #include <linux/bits.h>
@@ -76,6 +77,8 @@
 #include <linux/fadvise.h>
 #include <linux/eventpoll.h>
 #include <linux/fs_struct.h>
+#include <linux/splice.h>
+#include <linux/task_work.h>
 
 #define CREATE_TRACE_POINTS
 #include <trace/events/io_uring.h>
@@ -193,6 +196,13 @@ struct fixed_file_data {
        struct completion               done;
 };
 
+struct io_buffer {
+       struct list_head list;
+       __u64 addr;
+       __s32 len;
+       __u16 bid;
+};
+
 struct io_ring_ctx {
        struct {
                struct percpu_ref       refs;
@@ -270,6 +280,8 @@ struct io_ring_ctx {
        struct socket           *ring_sock;
 #endif
 
+       struct idr              io_buffer_idr;
+
        struct idr              personality_idr;
 
        struct {
@@ -290,7 +302,6 @@ struct io_ring_ctx {
 
        struct {
                spinlock_t              completion_lock;
-               struct llist_head       poll_llist;
 
                /*
                 * ->poll_list is protected by the ctx->uring_lock for
@@ -386,7 +397,9 @@ struct io_sr_msg {
                void __user             *buf;
        };
        int                             msg_flags;
+       int                             bgid;
        size_t                          len;
+       struct io_buffer                *kbuf;
 };
 
 struct io_open {
@@ -430,6 +443,24 @@ struct io_epoll {
        struct epoll_event              event;
 };
 
+struct io_splice {
+       struct file                     *file_out;
+       struct file                     *file_in;
+       loff_t                          off_out;
+       loff_t                          off_in;
+       u64                             len;
+       unsigned int                    flags;
+};
+
+struct io_provide_buf {
+       struct file                     *file;
+       __u64                           addr;
+       __s32                           len;
+       __u32                           bgid;
+       __u16                           nbufs;
+       __u16                           bid;
+};
+
 struct io_async_connect {
        struct sockaddr_storage         address;
 };
@@ -464,6 +495,7 @@ enum {
        REQ_F_LINK_BIT          = IOSQE_IO_LINK_BIT,
        REQ_F_HARDLINK_BIT      = IOSQE_IO_HARDLINK_BIT,
        REQ_F_FORCE_ASYNC_BIT   = IOSQE_ASYNC_BIT,
+       REQ_F_BUFFER_SELECT_BIT = IOSQE_BUFFER_SELECT_BIT,
 
        REQ_F_LINK_NEXT_BIT,
        REQ_F_FAIL_LINK_BIT,
@@ -479,6 +511,11 @@ enum {
        REQ_F_COMP_LOCKED_BIT,
        REQ_F_NEED_CLEANUP_BIT,
        REQ_F_OVERFLOW_BIT,
+       REQ_F_POLLED_BIT,
+       REQ_F_BUFFER_SELECTED_BIT,
+
+       /* not a real bit, just to check we're not overflowing the space */
+       __REQ_F_LAST_BIT,
 };
 
 enum {
@@ -492,6 +529,8 @@ enum {
        REQ_F_HARDLINK          = BIT(REQ_F_HARDLINK_BIT),
        /* IOSQE_ASYNC */
        REQ_F_FORCE_ASYNC       = BIT(REQ_F_FORCE_ASYNC_BIT),
+       /* IOSQE_BUFFER_SELECT */
+       REQ_F_BUFFER_SELECT     = BIT(REQ_F_BUFFER_SELECT_BIT),
 
        /* already grabbed next link */
        REQ_F_LINK_NEXT         = BIT(REQ_F_LINK_NEXT_BIT),
@@ -521,6 +560,15 @@ enum {
        REQ_F_NEED_CLEANUP      = BIT(REQ_F_NEED_CLEANUP_BIT),
        /* in overflow list */
        REQ_F_OVERFLOW          = BIT(REQ_F_OVERFLOW_BIT),
+       /* already went through poll handler */
+       REQ_F_POLLED            = BIT(REQ_F_POLLED_BIT),
+       /* buffer already selected */
+       REQ_F_BUFFER_SELECTED   = BIT(REQ_F_BUFFER_SELECTED_BIT),
+};
+
+struct async_poll {
+       struct io_poll_iocb     poll;
+       struct io_wq_work       work;
 };
 
 /*
@@ -546,32 +594,45 @@ struct io_kiocb {
                struct io_fadvise       fadvise;
                struct io_madvise       madvise;
                struct io_epoll         epoll;
+               struct io_splice        splice;
+               struct io_provide_buf   pbuf;
        };
 
        struct io_async_ctx             *io;
-       /*
-        * llist_node is only used for poll deferred completions
-        */
-       struct llist_node               llist_node;
-       bool                            in_async;
        bool                            needs_fixed_file;
        u8                              opcode;
 
        struct io_ring_ctx      *ctx;
-       union {
-               struct list_head        list;
-               struct hlist_node       hash_node;
-       };
-       struct list_head        link_list;
+       struct list_head        list;
        unsigned int            flags;
        refcount_t              refs;
+       union {
+               struct task_struct      *task;
+               unsigned long           fsize;
+       };
        u64                     user_data;
        u32                     result;
        u32                     sequence;
 
+       struct list_head        link_list;
+
        struct list_head        inflight_entry;
 
-       struct io_wq_work       work;
+       union {
+               /*
+                * Only commands that never go async can use the below fields,
+                * obviously. Right now only IORING_OP_POLL_ADD uses them, and
+                * async armed poll handlers for regular commands. The latter
+                * restore the work, if needed.
+                */
+               struct {
+                       struct callback_head    task_work;
+                       struct hlist_node       hash_node;
+                       struct async_poll       *apoll;
+                       int                     cflags;
+               };
+               struct io_wq_work       work;
+       };
 };
 
 #define IO_PLUG_THRESHOLD              2
@@ -615,6 +676,11 @@ struct io_op_def {
        unsigned                file_table : 1;
        /* needs ->fs */
        unsigned                needs_fs : 1;
+       /* set if opcode supports polled "wait" */
+       unsigned                pollin : 1;
+       unsigned                pollout : 1;
+       /* op supports buffer selection */
+       unsigned                buffer_select : 1;
 };
 
 static const struct io_op_def io_op_defs[] = {
@@ -624,6 +690,8 @@ static const struct io_op_def io_op_defs[] = {
                .needs_mm               = 1,
                .needs_file             = 1,
                .unbound_nonreg_file    = 1,
+               .pollin                 = 1,
+               .buffer_select          = 1,
        },
        [IORING_OP_WRITEV] = {
                .async_ctx              = 1,
@@ -631,6 +699,7 @@ static const struct io_op_def io_op_defs[] = {
                .needs_file             = 1,
                .hash_reg_file          = 1,
                .unbound_nonreg_file    = 1,
+               .pollout                = 1,
        },
        [IORING_OP_FSYNC] = {
                .needs_file             = 1,
@@ -638,11 +707,13 @@ static const struct io_op_def io_op_defs[] = {
        [IORING_OP_READ_FIXED] = {
                .needs_file             = 1,
                .unbound_nonreg_file    = 1,
+               .pollin                 = 1,
        },
        [IORING_OP_WRITE_FIXED] = {
                .needs_file             = 1,
                .hash_reg_file          = 1,
                .unbound_nonreg_file    = 1,
+               .pollout                = 1,
        },
        [IORING_OP_POLL_ADD] = {
                .needs_file             = 1,
@@ -658,6 +729,7 @@ static const struct io_op_def io_op_defs[] = {
                .needs_file             = 1,
                .unbound_nonreg_file    = 1,
                .needs_fs               = 1,
+               .pollout                = 1,
        },
        [IORING_OP_RECVMSG] = {
                .async_ctx              = 1,
@@ -665,6 +737,8 @@ static const struct io_op_def io_op_defs[] = {
                .needs_file             = 1,
                .unbound_nonreg_file    = 1,
                .needs_fs               = 1,
+               .pollin                 = 1,
+               .buffer_select          = 1,
        },
        [IORING_OP_TIMEOUT] = {
                .async_ctx              = 1,
@@ -676,6 +750,7 @@ static const struct io_op_def io_op_defs[] = {
                .needs_file             = 1,
                .unbound_nonreg_file    = 1,
                .file_table             = 1,
+               .pollin                 = 1,
        },
        [IORING_OP_ASYNC_CANCEL] = {},
        [IORING_OP_LINK_TIMEOUT] = {
@@ -687,6 +762,7 @@ static const struct io_op_def io_op_defs[] = {
                .needs_mm               = 1,
                .needs_file             = 1,
                .unbound_nonreg_file    = 1,
+               .pollout                = 1,
        },
        [IORING_OP_FALLOCATE] = {
                .needs_file             = 1,
@@ -715,11 +791,14 @@ static const struct io_op_def io_op_defs[] = {
                .needs_mm               = 1,
                .needs_file             = 1,
                .unbound_nonreg_file    = 1,
+               .pollin                 = 1,
+               .buffer_select          = 1,
        },
        [IORING_OP_WRITE] = {
                .needs_mm               = 1,
                .needs_file             = 1,
                .unbound_nonreg_file    = 1,
+               .pollout                = 1,
        },
        [IORING_OP_FADVISE] = {
                .needs_file             = 1,
@@ -731,11 +810,14 @@ static const struct io_op_def io_op_defs[] = {
                .needs_mm               = 1,
                .needs_file             = 1,
                .unbound_nonreg_file    = 1,
+               .pollout                = 1,
        },
        [IORING_OP_RECV] = {
                .needs_mm               = 1,
                .needs_file             = 1,
                .unbound_nonreg_file    = 1,
+               .pollin                 = 1,
+               .buffer_select          = 1,
        },
        [IORING_OP_OPENAT2] = {
                .needs_file             = 1,
@@ -747,6 +829,13 @@ static const struct io_op_def io_op_defs[] = {
                .unbound_nonreg_file    = 1,
                .file_table             = 1,
        },
+       [IORING_OP_SPLICE] = {
+               .needs_file             = 1,
+               .hash_reg_file          = 1,
+               .unbound_nonreg_file    = 1,
+       },
+       [IORING_OP_PROVIDE_BUFFERS] = {},
+       [IORING_OP_REMOVE_BUFFERS] = {},
 };
 
 static void io_wq_submit_work(struct io_wq_work **workptr);
@@ -761,6 +850,10 @@ static int __io_sqe_files_update(struct io_ring_ctx *ctx,
 static int io_grab_files(struct io_kiocb *req);
 static void io_ring_file_ref_flush(struct fixed_file_data *data);
 static void io_cleanup_req(struct io_kiocb *req);
+static int io_file_get(struct io_submit_state *state, struct io_kiocb *req,
+                      int fd, struct file **out_file, bool fixed);
+static void __io_queue_sqe(struct io_kiocb *req,
+                          const struct io_uring_sqe *sqe);
 
 static struct kmem_cache *req_cachep;
 
@@ -827,11 +920,11 @@ static struct io_ring_ctx *io_ring_ctx_alloc(struct io_uring_params *p)
        INIT_LIST_HEAD(&ctx->cq_overflow_list);
        init_completion(&ctx->completions[0]);
        init_completion(&ctx->completions[1]);
+       idr_init(&ctx->io_buffer_idr);
        idr_init(&ctx->personality_idr);
        mutex_init(&ctx->uring_lock);
        init_waitqueue_head(&ctx->wait);
        spin_lock_init(&ctx->completion_lock);
-       init_llist_head(&ctx->poll_llist);
        INIT_LIST_HEAD(&ctx->poll_list);
        INIT_LIST_HEAD(&ctx->defer_list);
        INIT_LIST_HEAD(&ctx->timeout_list);
@@ -952,15 +1045,14 @@ static inline void io_req_work_drop_env(struct io_kiocb *req)
        }
 }
 
-static inline bool io_prep_async_work(struct io_kiocb *req,
+static inline void io_prep_async_work(struct io_kiocb *req,
                                      struct io_kiocb **link)
 {
        const struct io_op_def *def = &io_op_defs[req->opcode];
-       bool do_hashed = false;
 
        if (req->flags & REQ_F_ISREG) {
                if (def->hash_reg_file)
-                       do_hashed = true;
+                       io_wq_hash_work(&req->work, file_inode(req->file));
        } else {
                if (def->unbound_nonreg_file)
                        req->work.flags |= IO_WQ_WORK_UNBOUND;
@@ -969,25 +1061,18 @@ static inline bool io_prep_async_work(struct io_kiocb *req,
        io_req_work_grab_env(req, def);
 
        *link = io_prep_linked_timeout(req);
-       return do_hashed;
 }
 
 static inline void io_queue_async_work(struct io_kiocb *req)
 {
        struct io_ring_ctx *ctx = req->ctx;
        struct io_kiocb *link;
-       bool do_hashed;
 
-       do_hashed = io_prep_async_work(req, &link);
+       io_prep_async_work(req, &link);
 
-       trace_io_uring_queue_async_work(ctx, do_hashed, req, &req->work,
-                                       req->flags);
-       if (!do_hashed) {
-               io_wq_enqueue(ctx->io_wq, &req->work);
-       } else {
-               io_wq_enqueue_hashed(ctx->io_wq, &req->work,
-                                       file_inode(req->file));
-       }
+       trace_io_uring_queue_async_work(ctx, io_wq_is_hashed(&req->work), req,
+                                       &req->work, req->flags);
+       io_wq_enqueue(ctx->io_wq, &req->work);
 
        if (link)
                io_queue_linked_timeout(link);
@@ -1054,24 +1139,19 @@ static inline bool io_should_trigger_evfd(struct io_ring_ctx *ctx)
                return false;
        if (!ctx->eventfd_async)
                return true;
-       return io_wq_current_is_worker() || in_interrupt();
+       return io_wq_current_is_worker();
 }
 
-static void __io_cqring_ev_posted(struct io_ring_ctx *ctx, bool trigger_ev)
+static void io_cqring_ev_posted(struct io_ring_ctx *ctx)
 {
        if (waitqueue_active(&ctx->wait))
                wake_up(&ctx->wait);
        if (waitqueue_active(&ctx->sqo_wait))
                wake_up(&ctx->sqo_wait);
-       if (trigger_ev)
+       if (io_should_trigger_evfd(ctx))
                eventfd_signal(ctx->cq_ev_fd, 1);
 }
 
-static void io_cqring_ev_posted(struct io_ring_ctx *ctx)
-{
-       __io_cqring_ev_posted(ctx, io_should_trigger_evfd(ctx));
-}
-
 /* Returns true if there are no backlogged entries after the flush */
 static bool io_cqring_overflow_flush(struct io_ring_ctx *ctx, bool force)
 {
@@ -1108,7 +1188,7 @@ static bool io_cqring_overflow_flush(struct io_ring_ctx *ctx, bool force)
                if (cqe) {
                        WRITE_ONCE(cqe->user_data, req->user_data);
                        WRITE_ONCE(cqe->res, req->result);
-                       WRITE_ONCE(cqe->flags, 0);
+                       WRITE_ONCE(cqe->flags, req->cflags);
                } else {
                        WRITE_ONCE(ctx->rings->cq_overflow,
                                atomic_inc_return(&ctx->cached_cq_overflow));
@@ -1132,7 +1212,7 @@ static bool io_cqring_overflow_flush(struct io_ring_ctx *ctx, bool force)
        return cqe != NULL;
 }
 
-static void io_cqring_fill_event(struct io_kiocb *req, long res)
+static void __io_cqring_fill_event(struct io_kiocb *req, long res, long cflags)
 {
        struct io_ring_ctx *ctx = req->ctx;
        struct io_uring_cqe *cqe;
@@ -1148,7 +1228,7 @@ static void io_cqring_fill_event(struct io_kiocb *req, long res)
        if (likely(cqe)) {
                WRITE_ONCE(cqe->user_data, req->user_data);
                WRITE_ONCE(cqe->res, res);
-               WRITE_ONCE(cqe->flags, 0);
+               WRITE_ONCE(cqe->flags, cflags);
        } else if (ctx->cq_overflow_flushed) {
                WRITE_ONCE(ctx->rings->cq_overflow,
                                atomic_inc_return(&ctx->cached_cq_overflow));
@@ -1160,23 +1240,34 @@ static void io_cqring_fill_event(struct io_kiocb *req, long res)
                req->flags |= REQ_F_OVERFLOW;
                refcount_inc(&req->refs);
                req->result = res;
+               req->cflags = cflags;
                list_add_tail(&req->list, &ctx->cq_overflow_list);
        }
 }
 
-static void io_cqring_add_event(struct io_kiocb *req, long res)
+static void io_cqring_fill_event(struct io_kiocb *req, long res)
+{
+       __io_cqring_fill_event(req, res, 0);
+}
+
+static void __io_cqring_add_event(struct io_kiocb *req, long res, long cflags)
 {
        struct io_ring_ctx *ctx = req->ctx;
        unsigned long flags;
 
        spin_lock_irqsave(&ctx->completion_lock, flags);
-       io_cqring_fill_event(req, res);
+       __io_cqring_fill_event(req, res, cflags);
        io_commit_cqring(ctx);
        spin_unlock_irqrestore(&ctx->completion_lock, flags);
 
        io_cqring_ev_posted(ctx);
 }
 
+static void io_cqring_add_event(struct io_kiocb *req, long res)
+{
+       __io_cqring_add_event(req, res, 0);
+}
+
 static inline bool io_is_fallback_req(struct io_kiocb *req)
 {
        return req == (struct io_kiocb *)
@@ -1246,6 +1337,15 @@ fallback:
        return NULL;
 }
 
+static inline void io_put_file(struct io_kiocb *req, struct file *file,
+                         bool fixed)
+{
+       if (fixed)
+               percpu_ref_put(&req->ctx->file_data->refs);
+       else
+               fput(file);
+}
+
 static void __io_req_do_free(struct io_kiocb *req)
 {
        if (likely(!io_is_fallback_req(req)))
@@ -1256,18 +1356,12 @@ static void __io_req_do_free(struct io_kiocb *req)
 
 static void __io_req_aux_free(struct io_kiocb *req)
 {
-       struct io_ring_ctx *ctx = req->ctx;
-
        if (req->flags & REQ_F_NEED_CLEANUP)
                io_cleanup_req(req);
 
        kfree(req->io);
-       if (req->file) {
-               if (req->flags & REQ_F_FIXED_FILE)
-                       percpu_ref_put(&ctx->file_data->refs);
-               else
-                       fput(req->file);
-       }
+       if (req->file)
+               io_put_file(req, req->file, (req->flags & REQ_F_FIXED_FILE));
 
        io_req_work_drop_env(req);
 }
@@ -1474,6 +1568,30 @@ static void io_free_req(struct io_kiocb *req)
                io_queue_async_work(nxt);
 }
 
+static void io_link_work_cb(struct io_wq_work **workptr)
+{
+       struct io_kiocb *req = container_of(*workptr, struct io_kiocb, work);
+       struct io_kiocb *link;
+
+       link = list_first_entry(&req->link_list, struct io_kiocb, link_list);
+       io_queue_linked_timeout(link);
+       io_wq_submit_work(workptr);
+}
+
+static void io_wq_assign_next(struct io_wq_work **workptr, struct io_kiocb *nxt)
+{
+       struct io_kiocb *link;
+       const struct io_op_def *def = &io_op_defs[nxt->opcode];
+
+       if ((nxt->flags & REQ_F_ISREG) && def->hash_reg_file)
+               io_wq_hash_work(&nxt->work, file_inode(nxt->file));
+
+       *workptr = &nxt->work;
+       link = io_prep_linked_timeout(nxt);
+       if (link)
+               nxt->work.func = io_link_work_cb;
+}
+
 /*
  * Drop reference to request, return next in chain (if there is one) if this
  * was the last reference to this request.
@@ -1493,6 +1611,26 @@ static void io_put_req(struct io_kiocb *req)
                io_free_req(req);
 }
 
+static void io_steal_work(struct io_kiocb *req,
+                         struct io_wq_work **workptr)
+{
+       /*
+        * It's in an io-wq worker, so there always should be at least
+        * one reference, which will be dropped in io_put_work() just
+        * after the current handler returns.
+        *
+        * It also means, that if the counter dropped to 1, then there is
+        * no asynchronous users left, so it's safe to steal the next work.
+        */
+       if (refcount_read(&req->refs) == 1) {
+               struct io_kiocb *nxt = NULL;
+
+               io_req_find_next(req, &nxt);
+               if (nxt)
+                       io_wq_assign_next(workptr, nxt);
+       }
+}
+
 /*
  * Must only be used if we don't need to care about links, usually from
  * within the completion handling itself.
@@ -1554,6 +1692,19 @@ static inline bool io_req_multi_free(struct req_batch *rb, struct io_kiocb *req)
        return true;
 }
 
+static int io_put_kbuf(struct io_kiocb *req)
+{
+       struct io_buffer *kbuf;
+       int cflags;
+
+       kbuf = (struct io_buffer *) (unsigned long) req->rw.addr;
+       cflags = kbuf->bid << IORING_CQE_BUFFER_SHIFT;
+       cflags |= IORING_CQE_F_BUFFER;
+       req->rw.addr = 0;
+       kfree(kbuf);
+       return cflags;
+}
+
 /*
  * Find and free completed poll iocbs
  */
@@ -1565,10 +1716,15 @@ static void io_iopoll_complete(struct io_ring_ctx *ctx, unsigned int *nr_events,
 
        rb.to_free = rb.need_iter = 0;
        while (!list_empty(done)) {
+               int cflags = 0;
+
                req = list_first_entry(done, struct io_kiocb, list);
                list_del(&req->list);
 
-               io_cqring_fill_event(req, req->result);
+               if (req->flags & REQ_F_BUFFER_SELECTED)
+                       cflags = io_put_kbuf(req);
+
+               __io_cqring_fill_event(req, req->result, cflags);
                (*nr_events)++;
 
                if (refcount_dec_and_test(&req->refs) &&
@@ -1577,6 +1733,8 @@ static void io_iopoll_complete(struct io_ring_ctx *ctx, unsigned int *nr_events,
        }
 
        io_commit_cqring(ctx);
+       if (ctx->flags & IORING_SETUP_SQPOLL)
+               io_cqring_ev_posted(ctx);
        io_free_req_many(ctx, &rb);
 }
 
@@ -1743,13 +1901,16 @@ static inline void req_set_fail_links(struct io_kiocb *req)
 static void io_complete_rw_common(struct kiocb *kiocb, long res)
 {
        struct io_kiocb *req = container_of(kiocb, struct io_kiocb, rw.kiocb);
+       int cflags = 0;
 
        if (kiocb->ki_flags & IOCB_WRITE)
                kiocb_end_write(req);
 
        if (res != req->result)
                req_set_fail_links(req);
-       io_cqring_add_event(req, res);
+       if (req->flags & REQ_F_BUFFER_SELECTED)
+               cflags = io_put_kbuf(req);
+       __io_cqring_add_event(req, res, cflags);
 }
 
 static void io_complete_rw(struct kiocb *kiocb, long res, long res2)
@@ -1760,17 +1921,6 @@ static void io_complete_rw(struct kiocb *kiocb, long res, long res2)
        io_put_req(req);
 }
 
-static struct io_kiocb *__io_complete_rw(struct kiocb *kiocb, long res)
-{
-       struct io_kiocb *req = container_of(kiocb, struct io_kiocb, rw.kiocb);
-       struct io_kiocb *nxt = NULL;
-
-       io_complete_rw_common(kiocb, res);
-       io_put_req_find_next(req, &nxt);
-
-       return nxt;
-}
-
 static void io_complete_rw_iopoll(struct kiocb *kiocb, long res, long res2)
 {
        struct io_kiocb *req = container_of(kiocb, struct io_kiocb, rw.kiocb);
@@ -1841,7 +1991,7 @@ static void io_file_put(struct io_submit_state *state)
  * assuming most submissions are for one file, or at least that each file
  * has more than one submission.
  */
-static struct file *io_file_get(struct io_submit_state *state, int fd)
+static struct file *__io_file_get(struct io_submit_state *state, int fd)
 {
        if (!state)
                return fget(fd);
@@ -1938,7 +2088,7 @@ static int io_prep_rw(struct io_kiocb *req, const struct io_uring_sqe *sqe,
 
        req->rw.addr = READ_ONCE(sqe->addr);
        req->rw.len = READ_ONCE(sqe->len);
-       /* we own ->private, reuse it for the buffer index */
+       /* we own ->private, reuse it for the buffer index  / buffer ID */
        req->rw.kiocb.private = (void *) (unsigned long)
                                        READ_ONCE(sqe->buf_index);
        return 0;
@@ -1965,15 +2115,14 @@ static inline void io_rw_done(struct kiocb *kiocb, ssize_t ret)
        }
 }
 
-static void kiocb_done(struct kiocb *kiocb, ssize_t ret, struct io_kiocb **nxt,
-                      bool in_async)
+static void kiocb_done(struct kiocb *kiocb, ssize_t ret)
 {
        struct io_kiocb *req = container_of(kiocb, struct io_kiocb, rw.kiocb);
 
        if (req->flags & REQ_F_CUR_POS)
                req->file->f_pos = kiocb->ki_pos;
-       if (in_async && ret >= 0 && kiocb->ki_complete == io_complete_rw)
-               *nxt = __io_complete_rw(kiocb, ret);
+       if (ret >= 0 && kiocb->ki_complete == io_complete_rw)
+               io_complete_rw(kiocb, ret, 0);
        else
                io_rw_done(kiocb, ret);
 }
@@ -2052,11 +2201,147 @@ static ssize_t io_import_fixed(struct io_kiocb *req, int rw,
        return len;
 }
 
+static void io_ring_submit_unlock(struct io_ring_ctx *ctx, bool needs_lock)
+{
+       if (needs_lock)
+               mutex_unlock(&ctx->uring_lock);
+}
+
+static void io_ring_submit_lock(struct io_ring_ctx *ctx, bool needs_lock)
+{
+       /*
+        * "Normal" inline submissions always hold the uring_lock, since we
+        * grab it from the system call. Same is true for the SQPOLL offload.
+        * The only exception is when we've detached the request and issue it
+        * from an async worker thread, grab the lock for that case.
+        */
+       if (needs_lock)
+               mutex_lock(&ctx->uring_lock);
+}
+
+static struct io_buffer *io_buffer_select(struct io_kiocb *req, size_t *len,
+                                         int bgid, struct io_buffer *kbuf,
+                                         bool needs_lock)
+{
+       struct io_buffer *head;
+
+       if (req->flags & REQ_F_BUFFER_SELECTED)
+               return kbuf;
+
+       io_ring_submit_lock(req->ctx, needs_lock);
+
+       lockdep_assert_held(&req->ctx->uring_lock);
+
+       head = idr_find(&req->ctx->io_buffer_idr, bgid);
+       if (head) {
+               if (!list_empty(&head->list)) {
+                       kbuf = list_last_entry(&head->list, struct io_buffer,
+                                                       list);
+                       list_del(&kbuf->list);
+               } else {
+                       kbuf = head;
+                       idr_remove(&req->ctx->io_buffer_idr, bgid);
+               }
+               if (*len > kbuf->len)
+                       *len = kbuf->len;
+       } else {
+               kbuf = ERR_PTR(-ENOBUFS);
+       }
+
+       io_ring_submit_unlock(req->ctx, needs_lock);
+
+       return kbuf;
+}
+
+static void __user *io_rw_buffer_select(struct io_kiocb *req, size_t *len,
+                                       bool needs_lock)
+{
+       struct io_buffer *kbuf;
+       int bgid;
+
+       kbuf = (struct io_buffer *) (unsigned long) req->rw.addr;
+       bgid = (int) (unsigned long) req->rw.kiocb.private;
+       kbuf = io_buffer_select(req, len, bgid, kbuf, needs_lock);
+       if (IS_ERR(kbuf))
+               return kbuf;
+       req->rw.addr = (u64) (unsigned long) kbuf;
+       req->flags |= REQ_F_BUFFER_SELECTED;
+       return u64_to_user_ptr(kbuf->addr);
+}
+
+#ifdef CONFIG_COMPAT
+static ssize_t io_compat_import(struct io_kiocb *req, struct iovec *iov,
+                               bool needs_lock)
+{
+       struct compat_iovec __user *uiov;
+       compat_ssize_t clen;
+       void __user *buf;
+       ssize_t len;
+
+       uiov = u64_to_user_ptr(req->rw.addr);
+       if (!access_ok(uiov, sizeof(*uiov)))
+               return -EFAULT;
+       if (__get_user(clen, &uiov->iov_len))
+               return -EFAULT;
+       if (clen < 0)
+               return -EINVAL;
+
+       len = clen;
+       buf = io_rw_buffer_select(req, &len, needs_lock);
+       if (IS_ERR(buf))
+               return PTR_ERR(buf);
+       iov[0].iov_base = buf;
+       iov[0].iov_len = (compat_size_t) len;
+       return 0;
+}
+#endif
+
+static ssize_t __io_iov_buffer_select(struct io_kiocb *req, struct iovec *iov,
+                                     bool needs_lock)
+{
+       struct iovec __user *uiov = u64_to_user_ptr(req->rw.addr);
+       void __user *buf;
+       ssize_t len;
+
+       if (copy_from_user(iov, uiov, sizeof(*uiov)))
+               return -EFAULT;
+
+       len = iov[0].iov_len;
+       if (len < 0)
+               return -EINVAL;
+       buf = io_rw_buffer_select(req, &len, needs_lock);
+       if (IS_ERR(buf))
+               return PTR_ERR(buf);
+       iov[0].iov_base = buf;
+       iov[0].iov_len = len;
+       return 0;
+}
+
+static ssize_t io_iov_buffer_select(struct io_kiocb *req, struct iovec *iov,
+                                   bool needs_lock)
+{
+       if (req->flags & REQ_F_BUFFER_SELECTED)
+               return 0;
+       if (!req->rw.len)
+               return 0;
+       else if (req->rw.len > 1)
+               return -EINVAL;
+
+#ifdef CONFIG_COMPAT
+       if (req->ctx->compat)
+               return io_compat_import(req, iov, needs_lock);
+#endif
+
+       return __io_iov_buffer_select(req, iov, needs_lock);
+}
+
 static ssize_t io_import_iovec(int rw, struct io_kiocb *req,
-                              struct iovec **iovec, struct iov_iter *iter)
+                              struct iovec **iovec, struct iov_iter *iter,
+                              bool needs_lock)
 {
        void __user *buf = u64_to_user_ptr(req->rw.addr);
        size_t sqe_len = req->rw.len;
+       ssize_t ret;
        u8 opcode;
 
        opcode = req->opcode;
@@ -2065,12 +2350,20 @@ static ssize_t io_import_iovec(int rw, struct io_kiocb *req,
                return io_import_fixed(req, rw, iter);
        }
 
-       /* buffer index only valid with fixed read/write */
-       if (req->rw.kiocb.private)
+       /* buffer index only valid with fixed read/write, or buffer select  */
+       if (req->rw.kiocb.private && !(req->flags & REQ_F_BUFFER_SELECT))
                return -EINVAL;
 
        if (opcode == IORING_OP_READ || opcode == IORING_OP_WRITE) {
-               ssize_t ret;
+               if (req->flags & REQ_F_BUFFER_SELECT) {
+                       buf = io_rw_buffer_select(req, &sqe_len, needs_lock);
+                       if (IS_ERR(buf)) {
+                               *iovec = NULL;
+                               return PTR_ERR(buf);
+                       }
+                       req->rw.len = sqe_len;
+               }
+
                ret = import_single_range(rw, buf, sqe_len, *iovec, iter);
                *iovec = NULL;
                return ret < 0 ? ret : sqe_len;
@@ -2086,6 +2379,16 @@ static ssize_t io_import_iovec(int rw, struct io_kiocb *req,
                return iorw->size;
        }
 
+       if (req->flags & REQ_F_BUFFER_SELECT) {
+               ret = io_iov_buffer_select(req, *iovec, needs_lock);
+               if (!ret) {
+                       ret = (*iovec)->iov_len;
+                       iov_iter_init(iter, rw, *iovec, 1, ret);
+               }
+               *iovec = NULL;
+               return ret;
+       }
+
 #ifdef CONFIG_COMPAT
        if (req->ctx->compat)
                return compat_import_iovec(rw, buf, sqe_len, UIO_FASTIOV,
@@ -2169,12 +2472,18 @@ static void io_req_map_rw(struct io_kiocb *req, ssize_t io_size,
        }
 }
 
+static inline int __io_alloc_async_ctx(struct io_kiocb *req)
+{
+       req->io = kmalloc(sizeof(*req->io), GFP_KERNEL);
+       return req->io == NULL;
+}
+
 static int io_alloc_async_ctx(struct io_kiocb *req)
 {
        if (!io_op_defs[req->opcode].async_ctx)
                return 0;
-       req->io = kmalloc(sizeof(*req->io), GFP_KERNEL);
-       return req->io == NULL;
+
+       return  __io_alloc_async_ctx(req);
 }
 
 static int io_setup_async_rw(struct io_kiocb *req, ssize_t io_size,
@@ -2184,7 +2493,7 @@ static int io_setup_async_rw(struct io_kiocb *req, ssize_t io_size,
        if (!io_op_defs[req->opcode].async_ctx)
                return 0;
        if (!req->io) {
-               if (io_alloc_async_ctx(req))
+               if (__io_alloc_async_ctx(req))
                        return -ENOMEM;
 
                io_req_map_rw(req, io_size, iovec, fast_iov, iter);
@@ -2213,7 +2522,7 @@ static int io_read_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe,
        io = req->io;
        io->rw.iov = io->rw.fast_iov;
        req->io = NULL;
-       ret = io_import_iovec(READ, req, &io->rw.iov, &iter);
+       ret = io_import_iovec(READ, req, &io->rw.iov, &iter, !force_nonblock);
        req->io = io;
        if (ret < 0)
                return ret;
@@ -2222,8 +2531,7 @@ static int io_read_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe,
        return 0;
 }
 
-static int io_read(struct io_kiocb *req, struct io_kiocb **nxt,
-                  bool force_nonblock)
+static int io_read(struct io_kiocb *req, bool force_nonblock)
 {
        struct iovec inline_vecs[UIO_FASTIOV], *iovec = inline_vecs;
        struct kiocb *kiocb = &req->rw.kiocb;
@@ -2231,13 +2539,13 @@ static int io_read(struct io_kiocb *req, struct io_kiocb **nxt,
        size_t iov_count;
        ssize_t io_size, ret;
 
-       ret = io_import_iovec(READ, req, &iovec, &iter);
+       ret = io_import_iovec(READ, req, &iovec, &iter, !force_nonblock);
        if (ret < 0)
                return ret;
 
        /* Ensure we clear previously set non-block flag */
        if (!force_nonblock)
-               req->rw.kiocb.ki_flags &= ~IOCB_NOWAIT;
+               kiocb->ki_flags &= ~IOCB_NOWAIT;
 
        req->result = 0;
        io_size = ret;
@@ -2248,10 +2556,8 @@ static int io_read(struct io_kiocb *req, struct io_kiocb **nxt,
         * If the file doesn't support async, mark it as REQ_F_MUST_PUNT so
         * we know to async punt it even if it was opened O_NONBLOCK
         */
-       if (force_nonblock && !io_file_supports_async(req->file)) {
-               req->flags |= REQ_F_MUST_PUNT;
+       if (force_nonblock && !io_file_supports_async(req->file))
                goto copy_iov;
-       }
 
        iov_count = iov_iter_count(&iter);
        ret = rw_verify_area(READ, req->file, &kiocb->ki_pos, iov_count);
@@ -2265,13 +2571,16 @@ static int io_read(struct io_kiocb *req, struct io_kiocb **nxt,
 
                /* Catch -EAGAIN return for forced non-blocking submission */
                if (!force_nonblock || ret2 != -EAGAIN) {
-                       kiocb_done(kiocb, ret2, nxt, req->in_async);
+                       kiocb_done(kiocb, ret2);
                } else {
 copy_iov:
                        ret = io_setup_async_rw(req, io_size, iovec,
                                                inline_vecs, &iter);
                        if (ret)
                                goto out_free;
+                       /* any defer here is final, must blocking retry */
+                       if (!(req->flags & REQ_F_NOWAIT))
+                               req->flags |= REQ_F_MUST_PUNT;
                        return -EAGAIN;
                }
        }
@@ -2295,6 +2604,8 @@ static int io_write_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe,
        if (unlikely(!(req->file->f_mode & FMODE_WRITE)))
                return -EBADF;
 
+       req->fsize = rlimit(RLIMIT_FSIZE);
+
        /* either don't need iovec imported or already have it */
        if (!req->io || req->flags & REQ_F_NEED_CLEANUP)
                return 0;
@@ -2302,7 +2613,7 @@ static int io_write_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe,
        io = req->io;
        io->rw.iov = io->rw.fast_iov;
        req->io = NULL;
-       ret = io_import_iovec(WRITE, req, &io->rw.iov, &iter);
+       ret = io_import_iovec(WRITE, req, &io->rw.iov, &iter, !force_nonblock);
        req->io = io;
        if (ret < 0)
                return ret;
@@ -2311,8 +2622,7 @@ static int io_write_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe,
        return 0;
 }
 
-static int io_write(struct io_kiocb *req, struct io_kiocb **nxt,
-                   bool force_nonblock)
+static int io_write(struct io_kiocb *req, bool force_nonblock)
 {
        struct iovec inline_vecs[UIO_FASTIOV], *iovec = inline_vecs;
        struct kiocb *kiocb = &req->rw.kiocb;
@@ -2320,7 +2630,7 @@ static int io_write(struct io_kiocb *req, struct io_kiocb **nxt,
        size_t iov_count;
        ssize_t ret, io_size;
 
-       ret = io_import_iovec(WRITE, req, &iovec, &iter);
+       ret = io_import_iovec(WRITE, req, &iovec, &iter, !force_nonblock);
        if (ret < 0)
                return ret;
 
@@ -2337,10 +2647,8 @@ static int io_write(struct io_kiocb *req, struct io_kiocb **nxt,
         * If the file doesn't support async, mark it as REQ_F_MUST_PUNT so
         * we know to async punt it even if it was opened O_NONBLOCK
         */
-       if (force_nonblock && !io_file_supports_async(req->file)) {
-               req->flags |= REQ_F_MUST_PUNT;
+       if (force_nonblock && !io_file_supports_async(req->file))
                goto copy_iov;
-       }
 
        /* file path doesn't support NOWAIT for non-direct_IO */
        if (force_nonblock && !(kiocb->ki_flags & IOCB_DIRECT) &&
@@ -2367,24 +2675,33 @@ static int io_write(struct io_kiocb *req, struct io_kiocb **nxt,
                }
                kiocb->ki_flags |= IOCB_WRITE;
 
+               if (!force_nonblock)
+                       current->signal->rlim[RLIMIT_FSIZE].rlim_cur = req->fsize;
+
                if (req->file->f_op->write_iter)
                        ret2 = call_write_iter(req->file, kiocb, &iter);
                else
                        ret2 = loop_rw_iter(WRITE, req->file, kiocb, &iter);
+
+               if (!force_nonblock)
+                       current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
+
                /*
-                * Raw bdev writes will -EOPNOTSUPP for IOCB_NOWAIT. Just
+                * Raw bdev writes will return -EOPNOTSUPP for IOCB_NOWAIT. Just
                 * retry them without IOCB_NOWAIT.
                 */
                if (ret2 == -EOPNOTSUPP && (kiocb->ki_flags & IOCB_NOWAIT))
                        ret2 = -EAGAIN;
                if (!force_nonblock || ret2 != -EAGAIN) {
-                       kiocb_done(kiocb, ret2, nxt, req->in_async);
+                       kiocb_done(kiocb, ret2);
                } else {
 copy_iov:
                        ret = io_setup_async_rw(req, io_size, iovec,
                                                inline_vecs, &iter);
                        if (ret)
                                goto out_free;
+                       /* any defer here is final, must blocking retry */
+                       req->flags |= REQ_F_MUST_PUNT;
                        return -EAGAIN;
                }
        }
@@ -2394,6 +2711,76 @@ out_free:
        return ret;
 }
 
+static int io_splice_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
+{
+       struct io_splice* sp = &req->splice;
+       unsigned int valid_flags = SPLICE_F_FD_IN_FIXED | SPLICE_F_ALL;
+       int ret;
+
+       if (req->flags & REQ_F_NEED_CLEANUP)
+               return 0;
+
+       sp->file_in = NULL;
+       sp->off_in = READ_ONCE(sqe->splice_off_in);
+       sp->off_out = READ_ONCE(sqe->off);
+       sp->len = READ_ONCE(sqe->len);
+       sp->flags = READ_ONCE(sqe->splice_flags);
+
+       if (unlikely(sp->flags & ~valid_flags))
+               return -EINVAL;
+
+       ret = io_file_get(NULL, req, READ_ONCE(sqe->splice_fd_in), &sp->file_in,
+                         (sp->flags & SPLICE_F_FD_IN_FIXED));
+       if (ret)
+               return ret;
+       req->flags |= REQ_F_NEED_CLEANUP;
+
+       if (!S_ISREG(file_inode(sp->file_in)->i_mode))
+               req->work.flags |= IO_WQ_WORK_UNBOUND;
+
+       return 0;
+}
+
+static bool io_splice_punt(struct file *file)
+{
+       if (get_pipe_info(file))
+               return false;
+       if (!io_file_supports_async(file))
+               return true;
+       return !(file->f_mode & O_NONBLOCK);
+}
+
+static int io_splice(struct io_kiocb *req, bool force_nonblock)
+{
+       struct io_splice *sp = &req->splice;
+       struct file *in = sp->file_in;
+       struct file *out = sp->file_out;
+       unsigned int flags = sp->flags & ~SPLICE_F_FD_IN_FIXED;
+       loff_t *poff_in, *poff_out;
+       long ret;
+
+       if (force_nonblock) {
+               if (io_splice_punt(in) || io_splice_punt(out))
+                       return -EAGAIN;
+               flags |= SPLICE_F_NONBLOCK;
+       }
+
+       poff_in = (sp->off_in == -1) ? NULL : &sp->off_in;
+       poff_out = (sp->off_out == -1) ? NULL : &sp->off_out;
+       ret = do_splice(in, poff_in, out, poff_out, sp->len, flags);
+       if (force_nonblock && ret == -EAGAIN)
+               return -EAGAIN;
+
+       io_put_file(req, in, (sp->flags & SPLICE_F_FD_IN_FIXED));
+       req->flags &= ~REQ_F_NEED_CLEANUP;
+
+       io_cqring_add_event(req, ret);
+       if (ret != sp->len)
+               req_set_fail_links(req);
+       io_put_req(req);
+       return 0;
+}
+
 /*
  * IORING_OP_NOP just posts a completion event, nothing else.
  */
@@ -2442,85 +2829,63 @@ static bool io_req_cancelled(struct io_kiocb *req)
        return false;
 }
 
-static void io_link_work_cb(struct io_wq_work **workptr)
-{
-       struct io_wq_work *work = *workptr;
-       struct io_kiocb *link = work->data;
-
-       io_queue_linked_timeout(link);
-       work->func = io_wq_submit_work;
-}
-
-static void io_wq_assign_next(struct io_wq_work **workptr, struct io_kiocb *nxt)
-{
-       struct io_kiocb *link;
-
-       io_prep_async_work(nxt, &link);
-       *workptr = &nxt->work;
-       if (link) {
-               nxt->work.flags |= IO_WQ_WORK_CB;
-               nxt->work.func = io_link_work_cb;
-               nxt->work.data = link;
-       }
-}
-
-static void io_fsync_finish(struct io_wq_work **workptr)
+static void __io_fsync(struct io_kiocb *req)
 {
-       struct io_kiocb *req = container_of(*workptr, struct io_kiocb, work);
        loff_t end = req->sync.off + req->sync.len;
-       struct io_kiocb *nxt = NULL;
        int ret;
 
-       if (io_req_cancelled(req))
-               return;
-
        ret = vfs_fsync_range(req->file, req->sync.off,
                                end > 0 ? end : LLONG_MAX,
                                req->sync.flags & IORING_FSYNC_DATASYNC);
        if (ret < 0)
                req_set_fail_links(req);
        io_cqring_add_event(req, ret);
-       io_put_req_find_next(req, &nxt);
-       if (nxt)
-               io_wq_assign_next(workptr, nxt);
+       io_put_req(req);
 }
 
-static int io_fsync(struct io_kiocb *req, struct io_kiocb **nxt,
-                   bool force_nonblock)
+static void io_fsync_finish(struct io_wq_work **workptr)
 {
-       struct io_wq_work *work, *old_work;
+       struct io_kiocb *req = container_of(*workptr, struct io_kiocb, work);
+
+       if (io_req_cancelled(req))
+               return;
+       __io_fsync(req);
+       io_steal_work(req, workptr);
+}
 
+static int io_fsync(struct io_kiocb *req, bool force_nonblock)
+{
        /* fsync always requires a blocking context */
        if (force_nonblock) {
-               io_put_req(req);
                req->work.func = io_fsync_finish;
                return -EAGAIN;
        }
-
-       work = old_work = &req->work;
-       io_fsync_finish(&work);
-       if (work && work != old_work)
-               *nxt = container_of(work, struct io_kiocb, work);
+       __io_fsync(req);
        return 0;
 }
 
-static void io_fallocate_finish(struct io_wq_work **workptr)
+static void __io_fallocate(struct io_kiocb *req)
 {
-       struct io_kiocb *req = container_of(*workptr, struct io_kiocb, work);
-       struct io_kiocb *nxt = NULL;
        int ret;
 
-       if (io_req_cancelled(req))
-               return;
-
+       current->signal->rlim[RLIMIT_FSIZE].rlim_cur = req->fsize;
        ret = vfs_fallocate(req->file, req->sync.mode, req->sync.off,
                                req->sync.len);
+       current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
        if (ret < 0)
                req_set_fail_links(req);
        io_cqring_add_event(req, ret);
-       io_put_req_find_next(req, &nxt);
-       if (nxt)
-               io_wq_assign_next(workptr, nxt);
+       io_put_req(req);
+}
+
+static void io_fallocate_finish(struct io_wq_work **workptr)
+{
+       struct io_kiocb *req = container_of(*workptr, struct io_kiocb, work);
+
+       if (io_req_cancelled(req))
+               return;
+       __io_fallocate(req);
+       io_steal_work(req, workptr);
 }
 
 static int io_fallocate_prep(struct io_kiocb *req,
@@ -2532,26 +2897,19 @@ static int io_fallocate_prep(struct io_kiocb *req,
        req->sync.off = READ_ONCE(sqe->off);
        req->sync.len = READ_ONCE(sqe->addr);
        req->sync.mode = READ_ONCE(sqe->len);
+       req->fsize = rlimit(RLIMIT_FSIZE);
        return 0;
 }
 
-static int io_fallocate(struct io_kiocb *req, struct io_kiocb **nxt,
-                       bool force_nonblock)
+static int io_fallocate(struct io_kiocb *req, bool force_nonblock)
 {
-       struct io_wq_work *work, *old_work;
-
        /* fallocate always requiring blocking context */
        if (force_nonblock) {
-               io_put_req(req);
                req->work.func = io_fallocate_finish;
                return -EAGAIN;
        }
 
-       work = old_work = &req->work;
-       io_fallocate_finish(&work);
-       if (work && work != old_work)
-               *nxt = container_of(work, struct io_kiocb, work);
-
+       __io_fallocate(req);
        return 0;
 }
 
@@ -2626,8 +2984,7 @@ static int io_openat2_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
        return 0;
 }
 
-static int io_openat2(struct io_kiocb *req, struct io_kiocb **nxt,
-                     bool force_nonblock)
+static int io_openat2(struct io_kiocb *req, bool force_nonblock)
 {
        struct open_flags op;
        struct file *file;
@@ -2658,15 +3015,171 @@ err:
        if (ret < 0)
                req_set_fail_links(req);
        io_cqring_add_event(req, ret);
-       io_put_req_find_next(req, nxt);
+       io_put_req(req);
        return 0;
 }
 
-static int io_openat(struct io_kiocb *req, struct io_kiocb **nxt,
-                    bool force_nonblock)
+static int io_openat(struct io_kiocb *req, bool force_nonblock)
 {
        req->open.how = build_open_how(req->open.how.flags, req->open.how.mode);
-       return io_openat2(req, nxt, force_nonblock);
+       return io_openat2(req, force_nonblock);
+}
+
+static int io_remove_buffers_prep(struct io_kiocb *req,
+                                 const struct io_uring_sqe *sqe)
+{
+       struct io_provide_buf *p = &req->pbuf;
+       u64 tmp;
+
+       if (sqe->ioprio || sqe->rw_flags || sqe->addr || sqe->len || sqe->off)
+               return -EINVAL;
+
+       tmp = READ_ONCE(sqe->fd);
+       if (!tmp || tmp > USHRT_MAX)
+               return -EINVAL;
+
+       memset(p, 0, sizeof(*p));
+       p->nbufs = tmp;
+       p->bgid = READ_ONCE(sqe->buf_group);
+       return 0;
+}
+
+static int __io_remove_buffers(struct io_ring_ctx *ctx, struct io_buffer *buf,
+                              int bgid, unsigned nbufs)
+{
+       unsigned i = 0;
+
+       /* shouldn't happen */
+       if (!nbufs)
+               return 0;
+
+       /* the head kbuf is the list itself */
+       while (!list_empty(&buf->list)) {
+               struct io_buffer *nxt;
+
+               nxt = list_first_entry(&buf->list, struct io_buffer, list);
+               list_del(&nxt->list);
+               kfree(nxt);
+               if (++i == nbufs)
+                       return i;
+       }
+       i++;
+       kfree(buf);
+       idr_remove(&ctx->io_buffer_idr, bgid);
+
+       return i;
+}
+
+static int io_remove_buffers(struct io_kiocb *req, bool force_nonblock)
+{
+       struct io_provide_buf *p = &req->pbuf;
+       struct io_ring_ctx *ctx = req->ctx;
+       struct io_buffer *head;
+       int ret = 0;
+
+       io_ring_submit_lock(ctx, !force_nonblock);
+
+       lockdep_assert_held(&ctx->uring_lock);
+
+       ret = -ENOENT;
+       head = idr_find(&ctx->io_buffer_idr, p->bgid);
+       if (head)
+               ret = __io_remove_buffers(ctx, head, p->bgid, p->nbufs);
+
+       io_ring_submit_lock(ctx, !force_nonblock);
+       if (ret < 0)
+               req_set_fail_links(req);
+       io_cqring_add_event(req, ret);
+       io_put_req(req);
+       return 0;
+}
+
+static int io_provide_buffers_prep(struct io_kiocb *req,
+                                  const struct io_uring_sqe *sqe)
+{
+       struct io_provide_buf *p = &req->pbuf;
+       u64 tmp;
+
+       if (sqe->ioprio || sqe->rw_flags)
+               return -EINVAL;
+
+       tmp = READ_ONCE(sqe->fd);
+       if (!tmp || tmp > USHRT_MAX)
+               return -E2BIG;
+       p->nbufs = tmp;
+       p->addr = READ_ONCE(sqe->addr);
+       p->len = READ_ONCE(sqe->len);
+
+       if (!access_ok(u64_to_user_ptr(p->addr), p->len))
+               return -EFAULT;
+
+       p->bgid = READ_ONCE(sqe->buf_group);
+       tmp = READ_ONCE(sqe->off);
+       if (tmp > USHRT_MAX)
+               return -E2BIG;
+       p->bid = tmp;
+       return 0;
+}
+
+static int io_add_buffers(struct io_provide_buf *pbuf, struct io_buffer **head)
+{
+       struct io_buffer *buf;
+       u64 addr = pbuf->addr;
+       int i, bid = pbuf->bid;
+
+       for (i = 0; i < pbuf->nbufs; i++) {
+               buf = kmalloc(sizeof(*buf), GFP_KERNEL);
+               if (!buf)
+                       break;
+
+               buf->addr = addr;
+               buf->len = pbuf->len;
+               buf->bid = bid;
+               addr += pbuf->len;
+               bid++;
+               if (!*head) {
+                       INIT_LIST_HEAD(&buf->list);
+                       *head = buf;
+               } else {
+                       list_add_tail(&buf->list, &(*head)->list);
+               }
+       }
+
+       return i ? i : -ENOMEM;
+}
+
+static int io_provide_buffers(struct io_kiocb *req, bool force_nonblock)
+{
+       struct io_provide_buf *p = &req->pbuf;
+       struct io_ring_ctx *ctx = req->ctx;
+       struct io_buffer *head, *list;
+       int ret = 0;
+
+       io_ring_submit_lock(ctx, !force_nonblock);
+
+       lockdep_assert_held(&ctx->uring_lock);
+
+       list = head = idr_find(&ctx->io_buffer_idr, p->bgid);
+
+       ret = io_add_buffers(p, &head);
+       if (ret < 0)
+               goto out;
+
+       if (!list) {
+               ret = idr_alloc(&ctx->io_buffer_idr, head, p->bgid, p->bgid + 1,
+                                       GFP_KERNEL);
+               if (ret < 0) {
+                       __io_remove_buffers(ctx, head, p->bgid, -1U);
+                       goto out;
+               }
+       }
+out:
+       io_ring_submit_unlock(ctx, !force_nonblock);
+       if (ret < 0)
+               req_set_fail_links(req);
+       io_cqring_add_event(req, ret);
+       io_put_req(req);
+       return 0;
 }
 
 static int io_epoll_ctl_prep(struct io_kiocb *req,
@@ -2694,8 +3207,7 @@ static int io_epoll_ctl_prep(struct io_kiocb *req,
 #endif
 }
 
-static int io_epoll_ctl(struct io_kiocb *req, struct io_kiocb **nxt,
-                       bool force_nonblock)
+static int io_epoll_ctl(struct io_kiocb *req, bool force_nonblock)
 {
 #if defined(CONFIG_EPOLL)
        struct io_epoll *ie = &req->epoll;
@@ -2708,7 +3220,7 @@ static int io_epoll_ctl(struct io_kiocb *req, struct io_kiocb **nxt,
        if (ret < 0)
                req_set_fail_links(req);
        io_cqring_add_event(req, ret);
-       io_put_req_find_next(req, nxt);
+       io_put_req(req);
        return 0;
 #else
        return -EOPNOTSUPP;
@@ -2730,8 +3242,7 @@ static int io_madvise_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
 #endif
 }
 
-static int io_madvise(struct io_kiocb *req, struct io_kiocb **nxt,
-                     bool force_nonblock)
+static int io_madvise(struct io_kiocb *req, bool force_nonblock)
 {
 #if defined(CONFIG_ADVISE_SYSCALLS) && defined(CONFIG_MMU)
        struct io_madvise *ma = &req->madvise;
@@ -2744,7 +3255,7 @@ static int io_madvise(struct io_kiocb *req, struct io_kiocb **nxt,
        if (ret < 0)
                req_set_fail_links(req);
        io_cqring_add_event(req, ret);
-       io_put_req_find_next(req, nxt);
+       io_put_req(req);
        return 0;
 #else
        return -EOPNOTSUPP;
@@ -2762,8 +3273,7 @@ static int io_fadvise_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
        return 0;
 }
 
-static int io_fadvise(struct io_kiocb *req, struct io_kiocb **nxt,
-                     bool force_nonblock)
+static int io_fadvise(struct io_kiocb *req, bool force_nonblock)
 {
        struct io_fadvise *fa = &req->fadvise;
        int ret;
@@ -2783,7 +3293,7 @@ static int io_fadvise(struct io_kiocb *req, struct io_kiocb **nxt,
        if (ret < 0)
                req_set_fail_links(req);
        io_cqring_add_event(req, ret);
-       io_put_req_find_next(req, nxt);
+       io_put_req(req);
        return 0;
 }
 
@@ -2820,8 +3330,7 @@ static int io_statx_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
        return 0;
 }
 
-static int io_statx(struct io_kiocb *req, struct io_kiocb **nxt,
-                   bool force_nonblock)
+static int io_statx(struct io_kiocb *req, bool force_nonblock)
 {
        struct io_open *ctx = &req->open;
        unsigned lookup_flags;
@@ -2858,7 +3367,7 @@ err:
        if (ret < 0)
                req_set_fail_links(req);
        io_cqring_add_event(req, ret);
-       io_put_req_find_next(req, nxt);
+       io_put_req(req);
        return 0;
 }
 
@@ -2885,7 +3394,7 @@ static int io_close_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
 }
 
 /* only called when __close_fd_get_file() is done */
-static void __io_close_finish(struct io_kiocb *req, struct io_kiocb **nxt)
+static void __io_close_finish(struct io_kiocb *req)
 {
        int ret;
 
@@ -2894,22 +3403,19 @@ static void __io_close_finish(struct io_kiocb *req, struct io_kiocb **nxt)
                req_set_fail_links(req);
        io_cqring_add_event(req, ret);
        fput(req->close.put_file);
-       io_put_req_find_next(req, nxt);
+       io_put_req(req);
 }
 
 static void io_close_finish(struct io_wq_work **workptr)
 {
        struct io_kiocb *req = container_of(*workptr, struct io_kiocb, work);
-       struct io_kiocb *nxt = NULL;
 
        /* not cancellable, don't do io_req_cancelled() */
-       __io_close_finish(req, &nxt);
-       if (nxt)
-               io_wq_assign_next(workptr, nxt);
+       __io_close_finish(req);
+       io_steal_work(req, workptr);
 }
 
-static int io_close(struct io_kiocb *req, struct io_kiocb **nxt,
-                   bool force_nonblock)
+static int io_close(struct io_kiocb *req, bool force_nonblock)
 {
        int ret;
 
@@ -2919,23 +3425,25 @@ static int io_close(struct io_kiocb *req, struct io_kiocb **nxt,
                return ret;
 
        /* if the file has a flush method, be safe and punt to async */
-       if (req->close.put_file->f_op->flush && !io_wq_current_is_worker())
-               goto eagain;
+       if (req->close.put_file->f_op->flush && force_nonblock) {
+               /* submission ref will be dropped, take it for async */
+               refcount_inc(&req->refs);
+
+               req->work.func = io_close_finish;
+               /*
+                * Do manual async queue here to avoid grabbing files - we don't
+                * need the files, and it'll cause io_close_finish() to close
+                * the file again and cause a double CQE entry for this request
+                */
+               io_queue_async_work(req);
+               return 0;
+       }
 
        /*
         * No ->flush(), safely close from here and just punt the
         * fput() to async context.
         */
-       __io_close_finish(req, nxt);
-       return 0;
-eagain:
-       req->work.func = io_close_finish;
-       /*
-        * Do manual async queue here to avoid grabbing files - we don't
-        * need the files, and it'll cause io_close_finish() to close
-        * the file again and cause a double CQE entry for this request
-        */
-       io_queue_async_work(req);
+       __io_close_finish(req);
        return 0;
 }
 
@@ -2957,47 +3465,62 @@ static int io_prep_sfr(struct io_kiocb *req, const struct io_uring_sqe *sqe)
        return 0;
 }
 
-static void io_sync_file_range_finish(struct io_wq_work **workptr)
+static void __io_sync_file_range(struct io_kiocb *req)
 {
-       struct io_kiocb *req = container_of(*workptr, struct io_kiocb, work);
-       struct io_kiocb *nxt = NULL;
        int ret;
 
-       if (io_req_cancelled(req))
-               return;
-
        ret = sync_file_range(req->file, req->sync.off, req->sync.len,
                                req->sync.flags);
        if (ret < 0)
                req_set_fail_links(req);
        io_cqring_add_event(req, ret);
-       io_put_req_find_next(req, &nxt);
+       io_put_req(req);
+}
+
+
+static void io_sync_file_range_finish(struct io_wq_work **workptr)
+{
+       struct io_kiocb *req = container_of(*workptr, struct io_kiocb, work);
+       struct io_kiocb *nxt = NULL;
+
+       if (io_req_cancelled(req))
+               return;
+       __io_sync_file_range(req);
+       io_put_req(req); /* put submission ref */
        if (nxt)
                io_wq_assign_next(workptr, nxt);
 }
 
-static int io_sync_file_range(struct io_kiocb *req, struct io_kiocb **nxt,
-                             bool force_nonblock)
+static int io_sync_file_range(struct io_kiocb *req, bool force_nonblock)
 {
-       struct io_wq_work *work, *old_work;
-
        /* sync_file_range always requires a blocking context */
        if (force_nonblock) {
-               io_put_req(req);
                req->work.func = io_sync_file_range_finish;
                return -EAGAIN;
        }
 
-       work = old_work = &req->work;
-       io_sync_file_range_finish(&work);
-       if (work && work != old_work)
-               *nxt = container_of(work, struct io_kiocb, work);
+       __io_sync_file_range(req);
        return 0;
 }
 
+#if defined(CONFIG_NET)
+static int io_setup_async_msg(struct io_kiocb *req,
+                             struct io_async_msghdr *kmsg)
+{
+       if (req->io)
+               return -EAGAIN;
+       if (io_alloc_async_ctx(req)) {
+               if (kmsg->iov != kmsg->fast_iov)
+                       kfree(kmsg->iov);
+               return -ENOMEM;
+       }
+       req->flags |= REQ_F_NEED_CLEANUP;
+       memcpy(&req->io->msg, kmsg, sizeof(*kmsg));
+       return -EAGAIN;
+}
+
 static int io_sendmsg_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
 {
-#if defined(CONFIG_NET)
        struct io_sr_msg *sr = &req->sr_msg;
        struct io_async_ctx *io = req->io;
        int ret;
@@ -3023,15 +3546,10 @@ static int io_sendmsg_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
        if (!ret)
                req->flags |= REQ_F_NEED_CLEANUP;
        return ret;
-#else
-       return -EOPNOTSUPP;
-#endif
 }
 
-static int io_sendmsg(struct io_kiocb *req, struct io_kiocb **nxt,
-                     bool force_nonblock)
+static int io_sendmsg(struct io_kiocb *req, bool force_nonblock)
 {
-#if defined(CONFIG_NET)
        struct io_async_msghdr *kmsg = NULL;
        struct socket *sock;
        int ret;
@@ -3071,18 +3589,8 @@ static int io_sendmsg(struct io_kiocb *req, struct io_kiocb **nxt,
                        flags |= MSG_DONTWAIT;
 
                ret = __sys_sendmsg_sock(sock, &kmsg->msg, flags);
-               if (force_nonblock && ret == -EAGAIN) {
-                       if (req->io)
-                               return -EAGAIN;
-                       if (io_alloc_async_ctx(req)) {
-                               if (kmsg->iov != kmsg->fast_iov)
-                                       kfree(kmsg->iov);
-                               return -ENOMEM;
-                       }
-                       req->flags |= REQ_F_NEED_CLEANUP;
-                       memcpy(&req->io->msg, &io.msg, sizeof(io.msg));
-                       return -EAGAIN;
-               }
+               if (force_nonblock && ret == -EAGAIN)
+                       return io_setup_async_msg(req, kmsg);
                if (ret == -ERESTARTSYS)
                        ret = -EINTR;
        }
@@ -3093,17 +3601,12 @@ static int io_sendmsg(struct io_kiocb *req, struct io_kiocb **nxt,
        io_cqring_add_event(req, ret);
        if (ret < 0)
                req_set_fail_links(req);
-       io_put_req_find_next(req, nxt);
+       io_put_req(req);
        return 0;
-#else
-       return -EOPNOTSUPP;
-#endif
 }
 
-static int io_send(struct io_kiocb *req, struct io_kiocb **nxt,
-                  bool force_nonblock)
+static int io_send(struct io_kiocb *req, bool force_nonblock)
 {
-#if defined(CONFIG_NET)
        struct socket *sock;
        int ret;
 
@@ -3144,17 +3647,120 @@ static int io_send(struct io_kiocb *req, struct io_kiocb **nxt,
        io_cqring_add_event(req, ret);
        if (ret < 0)
                req_set_fail_links(req);
-       io_put_req_find_next(req, nxt);
+       io_put_req(req);
        return 0;
-#else
-       return -EOPNOTSUPP;
+}
+
+static int __io_recvmsg_copy_hdr(struct io_kiocb *req, struct io_async_ctx *io)
+{
+       struct io_sr_msg *sr = &req->sr_msg;
+       struct iovec __user *uiov;
+       size_t iov_len;
+       int ret;
+
+       ret = __copy_msghdr_from_user(&io->msg.msg, sr->msg, &io->msg.uaddr,
+                                       &uiov, &iov_len);
+       if (ret)
+               return ret;
+
+       if (req->flags & REQ_F_BUFFER_SELECT) {
+               if (iov_len > 1)
+                       return -EINVAL;
+               if (copy_from_user(io->msg.iov, uiov, sizeof(*uiov)))
+                       return -EFAULT;
+               sr->len = io->msg.iov[0].iov_len;
+               iov_iter_init(&io->msg.msg.msg_iter, READ, io->msg.iov, 1,
+                               sr->len);
+               io->msg.iov = NULL;
+       } else {
+               ret = import_iovec(READ, uiov, iov_len, UIO_FASTIOV,
+                                       &io->msg.iov, &io->msg.msg.msg_iter);
+               if (ret > 0)
+                       ret = 0;
+       }
+
+       return ret;
+}
+
+#ifdef CONFIG_COMPAT
+static int __io_compat_recvmsg_copy_hdr(struct io_kiocb *req,
+                                       struct io_async_ctx *io)
+{
+       struct compat_msghdr __user *msg_compat;
+       struct io_sr_msg *sr = &req->sr_msg;
+       struct compat_iovec __user *uiov;
+       compat_uptr_t ptr;
+       compat_size_t len;
+       int ret;
+
+       msg_compat = (struct compat_msghdr __user *) sr->msg;
+       ret = __get_compat_msghdr(&io->msg.msg, msg_compat, &io->msg.uaddr,
+                                       &ptr, &len);
+       if (ret)
+               return ret;
+
+       uiov = compat_ptr(ptr);
+       if (req->flags & REQ_F_BUFFER_SELECT) {
+               compat_ssize_t clen;
+
+               if (len > 1)
+                       return -EINVAL;
+               if (!access_ok(uiov, sizeof(*uiov)))
+                       return -EFAULT;
+               if (__get_user(clen, &uiov->iov_len))
+                       return -EFAULT;
+               if (clen < 0)
+                       return -EINVAL;
+               sr->len = io->msg.iov[0].iov_len;
+               io->msg.iov = NULL;
+       } else {
+               ret = compat_import_iovec(READ, uiov, len, UIO_FASTIOV,
+                                               &io->msg.iov,
+                                               &io->msg.msg.msg_iter);
+               if (ret < 0)
+                       return ret;
+       }
+
+       return 0;
+}
+#endif
+
+static int io_recvmsg_copy_hdr(struct io_kiocb *req, struct io_async_ctx *io)
+{
+       io->msg.iov = io->msg.fast_iov;
+
+#ifdef CONFIG_COMPAT
+       if (req->ctx->compat)
+               return __io_compat_recvmsg_copy_hdr(req, io);
 #endif
+
+       return __io_recvmsg_copy_hdr(req, io);
+}
+
+static struct io_buffer *io_recv_buffer_select(struct io_kiocb *req,
+                                              int *cflags, bool needs_lock)
+{
+       struct io_sr_msg *sr = &req->sr_msg;
+       struct io_buffer *kbuf;
+
+       if (!(req->flags & REQ_F_BUFFER_SELECT))
+               return NULL;
+
+       kbuf = io_buffer_select(req, &sr->len, sr->bgid, sr->kbuf, needs_lock);
+       if (IS_ERR(kbuf))
+               return kbuf;
+
+       sr->kbuf = kbuf;
+       req->flags |= REQ_F_BUFFER_SELECTED;
+
+       *cflags = kbuf->bid << IORING_CQE_BUFFER_SHIFT;
+       *cflags |= IORING_CQE_F_BUFFER;
+       return kbuf;
 }
 
 static int io_recvmsg_prep(struct io_kiocb *req,
                           const struct io_uring_sqe *sqe)
 {
-#if defined(CONFIG_NET)
        struct io_sr_msg *sr = &req->sr_msg;
        struct io_async_ctx *io = req->io;
        int ret;
@@ -3162,6 +3768,7 @@ static int io_recvmsg_prep(struct io_kiocb *req,
        sr->msg_flags = READ_ONCE(sqe->msg_flags);
        sr->msg = u64_to_user_ptr(READ_ONCE(sqe->addr));
        sr->len = READ_ONCE(sqe->len);
+       sr->bgid = READ_ONCE(sqe->buf_group);
 
 #ifdef CONFIG_COMPAT
        if (req->ctx->compat)
@@ -3174,30 +3781,24 @@ static int io_recvmsg_prep(struct io_kiocb *req,
        if (req->flags & REQ_F_NEED_CLEANUP)
                return 0;
 
-       io->msg.iov = io->msg.fast_iov;
-       ret = recvmsg_copy_msghdr(&io->msg.msg, sr->msg, sr->msg_flags,
-                                       &io->msg.uaddr, &io->msg.iov);
+       ret = io_recvmsg_copy_hdr(req, io);
        if (!ret)
                req->flags |= REQ_F_NEED_CLEANUP;
        return ret;
-#else
-       return -EOPNOTSUPP;
-#endif
 }
 
-static int io_recvmsg(struct io_kiocb *req, struct io_kiocb **nxt,
-                     bool force_nonblock)
+static int io_recvmsg(struct io_kiocb *req, bool force_nonblock)
 {
-#if defined(CONFIG_NET)
        struct io_async_msghdr *kmsg = NULL;
        struct socket *sock;
-       int ret;
+       int ret, cflags = 0;
 
        if (unlikely(req->ctx->flags & IORING_SETUP_IOPOLL))
                return -EINVAL;
 
        sock = sock_from_file(req->file, &ret);
        if (sock) {
+               struct io_buffer *kbuf;
                struct io_async_ctx io;
                unsigned flags;
 
@@ -3209,19 +3810,23 @@ static int io_recvmsg(struct io_kiocb *req, struct io_kiocb **nxt,
                                kmsg->iov = kmsg->fast_iov;
                        kmsg->msg.msg_iter.iov = kmsg->iov;
                } else {
-                       struct io_sr_msg *sr = &req->sr_msg;
-
                        kmsg = &io.msg;
                        kmsg->msg.msg_name = &io.msg.addr;
 
-                       io.msg.iov = io.msg.fast_iov;
-                       ret = recvmsg_copy_msghdr(&io.msg.msg, sr->msg,
-                                       sr->msg_flags, &io.msg.uaddr,
-                                       &io.msg.iov);
+                       ret = io_recvmsg_copy_hdr(req, &io);
                        if (ret)
                                return ret;
                }
 
+               kbuf = io_recv_buffer_select(req, &cflags, !force_nonblock);
+               if (IS_ERR(kbuf)) {
+                       return PTR_ERR(kbuf);
+               } else if (kbuf) {
+                       kmsg->fast_iov[0].iov_base = u64_to_user_ptr(kbuf->addr);
+                       iov_iter_init(&kmsg->msg.msg_iter, READ, kmsg->iov,
+                                       1, req->sr_msg.len);
+               }
+
                flags = req->sr_msg.msg_flags;
                if (flags & MSG_DONTWAIT)
                        req->flags |= REQ_F_NOWAIT;
@@ -3230,18 +3835,8 @@ static int io_recvmsg(struct io_kiocb *req, struct io_kiocb **nxt,
 
                ret = __sys_recvmsg_sock(sock, &kmsg->msg, req->sr_msg.msg,
                                                kmsg->uaddr, flags);
-               if (force_nonblock && ret == -EAGAIN) {
-                       if (req->io)
-                               return -EAGAIN;
-                       if (io_alloc_async_ctx(req)) {
-                               if (kmsg->iov != kmsg->fast_iov)
-                                       kfree(kmsg->iov);
-                               return -ENOMEM;
-                       }
-                       memcpy(&req->io->msg, &io.msg, sizeof(io.msg));
-                       req->flags |= REQ_F_NEED_CLEANUP;
-                       return -EAGAIN;
-               }
+               if (force_nonblock && ret == -EAGAIN)
+                       return io_setup_async_msg(req, kmsg);
                if (ret == -ERESTARTSYS)
                        ret = -EINTR;
        }
@@ -3249,22 +3844,18 @@ static int io_recvmsg(struct io_kiocb *req, struct io_kiocb **nxt,
        if (kmsg && kmsg->iov != kmsg->fast_iov)
                kfree(kmsg->iov);
        req->flags &= ~REQ_F_NEED_CLEANUP;
-       io_cqring_add_event(req, ret);
+       __io_cqring_add_event(req, ret, cflags);
        if (ret < 0)
                req_set_fail_links(req);
-       io_put_req_find_next(req, nxt);
+       io_put_req(req);
        return 0;
-#else
-       return -EOPNOTSUPP;
-#endif
 }
 
-static int io_recv(struct io_kiocb *req, struct io_kiocb **nxt,
-                  bool force_nonblock)
+static int io_recv(struct io_kiocb *req, bool force_nonblock)
 {
-#if defined(CONFIG_NET)
+       struct io_buffer *kbuf = NULL;
        struct socket *sock;
-       int ret;
+       int ret, cflags = 0;
 
        if (unlikely(req->ctx->flags & IORING_SETUP_IOPOLL))
                return -EINVAL;
@@ -3272,15 +3863,25 @@ static int io_recv(struct io_kiocb *req, struct io_kiocb **nxt,
        sock = sock_from_file(req->file, &ret);
        if (sock) {
                struct io_sr_msg *sr = &req->sr_msg;
+               void __user *buf = sr->buf;
                struct msghdr msg;
                struct iovec iov;
                unsigned flags;
 
-               ret = import_single_range(READ, sr->buf, sr->len, &iov,
+               kbuf = io_recv_buffer_select(req, &cflags, !force_nonblock);
+               if (IS_ERR(kbuf))
+                       return PTR_ERR(kbuf);
+               else if (kbuf)
+                       buf = u64_to_user_ptr(kbuf->addr);
+
+               ret = import_single_range(READ, buf, sr->len, &iov,
                                                &msg.msg_iter);
-               if (ret)
+               if (ret) {
+                       kfree(kbuf);
                        return ret;
+               }
 
+               req->flags |= REQ_F_NEED_CLEANUP;
                msg.msg_name = NULL;
                msg.msg_control = NULL;
                msg.msg_controllen = 0;
@@ -3301,20 +3902,17 @@ static int io_recv(struct io_kiocb *req, struct io_kiocb **nxt,
                        ret = -EINTR;
        }
 
-       io_cqring_add_event(req, ret);
+       kfree(kbuf);
+       req->flags &= ~REQ_F_NEED_CLEANUP;
+       __io_cqring_add_event(req, ret, cflags);
        if (ret < 0)
                req_set_fail_links(req);
-       io_put_req_find_next(req, nxt);
+       io_put_req(req);
        return 0;
-#else
-       return -EOPNOTSUPP;
-#endif
 }
 
-
 static int io_accept_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
 {
-#if defined(CONFIG_NET)
        struct io_accept *accept = &req->accept;
 
        if (unlikely(req->ctx->flags & (IORING_SETUP_IOPOLL|IORING_SETUP_SQPOLL)))
@@ -3327,14 +3925,9 @@ static int io_accept_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
        accept->flags = READ_ONCE(sqe->accept_flags);
        accept->nofile = rlimit(RLIMIT_NOFILE);
        return 0;
-#else
-       return -EOPNOTSUPP;
-#endif
 }
 
-#if defined(CONFIG_NET)
-static int __io_accept(struct io_kiocb *req, struct io_kiocb **nxt,
-                      bool force_nonblock)
+static int __io_accept(struct io_kiocb *req, bool force_nonblock)
 {
        struct io_accept *accept = &req->accept;
        unsigned file_flags;
@@ -3351,44 +3944,34 @@ static int __io_accept(struct io_kiocb *req, struct io_kiocb **nxt,
        if (ret < 0)
                req_set_fail_links(req);
        io_cqring_add_event(req, ret);
-       io_put_req_find_next(req, nxt);
+       io_put_req(req);
        return 0;
 }
 
 static void io_accept_finish(struct io_wq_work **workptr)
 {
        struct io_kiocb *req = container_of(*workptr, struct io_kiocb, work);
-       struct io_kiocb *nxt = NULL;
 
        if (io_req_cancelled(req))
                return;
-       __io_accept(req, &nxt, false);
-       if (nxt)
-               io_wq_assign_next(workptr, nxt);
+       __io_accept(req, false);
+       io_steal_work(req, workptr);
 }
-#endif
 
-static int io_accept(struct io_kiocb *req, struct io_kiocb **nxt,
-                    bool force_nonblock)
+static int io_accept(struct io_kiocb *req, bool force_nonblock)
 {
-#if defined(CONFIG_NET)
        int ret;
 
-       ret = __io_accept(req, nxt, force_nonblock);
+       ret = __io_accept(req, force_nonblock);
        if (ret == -EAGAIN && force_nonblock) {
                req->work.func = io_accept_finish;
-               io_put_req(req);
                return -EAGAIN;
        }
        return 0;
-#else
-       return -EOPNOTSUPP;
-#endif
 }
 
 static int io_connect_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
 {
-#if defined(CONFIG_NET)
        struct io_connect *conn = &req->connect;
        struct io_async_ctx *io = req->io;
 
@@ -3405,15 +3988,10 @@ static int io_connect_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
 
        return move_addr_to_kernel(conn->addr, conn->addr_len,
                                        &io->connect.address);
-#else
-       return -EOPNOTSUPP;
-#endif
 }
 
-static int io_connect(struct io_kiocb *req, struct io_kiocb **nxt,
-                     bool force_nonblock)
+static int io_connect(struct io_kiocb *req, bool force_nonblock)
 {
-#if defined(CONFIG_NET)
        struct io_async_ctx __io, *io;
        unsigned file_flags;
        int ret;
@@ -3449,25 +4027,301 @@ out:
        if (ret < 0)
                req_set_fail_links(req);
        io_cqring_add_event(req, ret);
-       io_put_req_find_next(req, nxt);
+       io_put_req(req);
        return 0;
-#else
+}
+#else /* !CONFIG_NET */
+static int io_sendmsg_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
+{
        return -EOPNOTSUPP;
-#endif
 }
 
-static void io_poll_remove_one(struct io_kiocb *req)
+static int io_sendmsg(struct io_kiocb *req, bool force_nonblock)
+{
+       return -EOPNOTSUPP;
+}
+
+static int io_send(struct io_kiocb *req, bool force_nonblock)
+{
+       return -EOPNOTSUPP;
+}
+
+static int io_recvmsg_prep(struct io_kiocb *req,
+                          const struct io_uring_sqe *sqe)
+{
+       return -EOPNOTSUPP;
+}
+
+static int io_recvmsg(struct io_kiocb *req, bool force_nonblock)
+{
+       return -EOPNOTSUPP;
+}
+
+static int io_recv(struct io_kiocb *req, bool force_nonblock)
+{
+       return -EOPNOTSUPP;
+}
+
+static int io_accept_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
+{
+       return -EOPNOTSUPP;
+}
+
+static int io_accept(struct io_kiocb *req, bool force_nonblock)
+{
+       return -EOPNOTSUPP;
+}
+
+static int io_connect_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
+{
+       return -EOPNOTSUPP;
+}
+
+static int io_connect(struct io_kiocb *req, bool force_nonblock)
+{
+       return -EOPNOTSUPP;
+}
+#endif /* CONFIG_NET */
+
+struct io_poll_table {
+       struct poll_table_struct pt;
+       struct io_kiocb *req;
+       int error;
+};
+
+static void __io_queue_proc(struct io_poll_iocb *poll, struct io_poll_table *pt,
+                           struct wait_queue_head *head)
+{
+       if (unlikely(poll->head)) {
+               pt->error = -EINVAL;
+               return;
+       }
+
+       pt->error = 0;
+       poll->head = head;
+       add_wait_queue(head, &poll->wait);
+}
+
+static void io_async_queue_proc(struct file *file, struct wait_queue_head *head,
+                              struct poll_table_struct *p)
+{
+       struct io_poll_table *pt = container_of(p, struct io_poll_table, pt);
+
+       __io_queue_proc(&pt->req->apoll->poll, pt, head);
+}
+
+static int __io_async_wake(struct io_kiocb *req, struct io_poll_iocb *poll,
+                          __poll_t mask, task_work_func_t func)
+{
+       struct task_struct *tsk;
+
+       /* for instances that support it check for an event match first: */
+       if (mask && !(mask & poll->events))
+               return 0;
+
+       trace_io_uring_task_add(req->ctx, req->opcode, req->user_data, mask);
+
+       list_del_init(&poll->wait.entry);
+
+       tsk = req->task;
+       req->result = mask;
+       init_task_work(&req->task_work, func);
+       /*
+        * If this fails, then the task is exiting. If that is the case, then
+        * the exit check will ultimately cancel these work items. Hence we
+        * don't need to check here and handle it specifically.
+        */
+       task_work_add(tsk, &req->task_work, true);
+       wake_up_process(tsk);
+       return 1;
+}
+
+static void io_async_task_func(struct callback_head *cb)
+{
+       struct io_kiocb *req = container_of(cb, struct io_kiocb, task_work);
+       struct async_poll *apoll = req->apoll;
+       struct io_ring_ctx *ctx = req->ctx;
+
+       trace_io_uring_task_run(req->ctx, req->opcode, req->user_data);
+
+       WARN_ON_ONCE(!list_empty(&req->apoll->poll.wait.entry));
+
+       if (hash_hashed(&req->hash_node)) {
+               spin_lock_irq(&ctx->completion_lock);
+               hash_del(&req->hash_node);
+               spin_unlock_irq(&ctx->completion_lock);
+       }
+
+       /* restore ->work in case we need to retry again */
+       memcpy(&req->work, &apoll->work, sizeof(req->work));
+
+       __set_current_state(TASK_RUNNING);
+       mutex_lock(&ctx->uring_lock);
+       __io_queue_sqe(req, NULL);
+       mutex_unlock(&ctx->uring_lock);
+
+       kfree(apoll);
+}
+
+static int io_async_wake(struct wait_queue_entry *wait, unsigned mode, int sync,
+                       void *key)
+{
+       struct io_kiocb *req = wait->private;
+       struct io_poll_iocb *poll = &req->apoll->poll;
+
+       trace_io_uring_poll_wake(req->ctx, req->opcode, req->user_data,
+                                       key_to_poll(key));
+
+       return __io_async_wake(req, poll, key_to_poll(key), io_async_task_func);
+}
+
+static void io_poll_req_insert(struct io_kiocb *req)
+{
+       struct io_ring_ctx *ctx = req->ctx;
+       struct hlist_head *list;
+
+       list = &ctx->cancel_hash[hash_long(req->user_data, ctx->cancel_hash_bits)];
+       hlist_add_head(&req->hash_node, list);
+}
+
+static __poll_t __io_arm_poll_handler(struct io_kiocb *req,
+                                     struct io_poll_iocb *poll,
+                                     struct io_poll_table *ipt, __poll_t mask,
+                                     wait_queue_func_t wake_func)
+       __acquires(&ctx->completion_lock)
+{
+       struct io_ring_ctx *ctx = req->ctx;
+       bool cancel = false;
+
+       poll->file = req->file;
+       poll->head = NULL;
+       poll->done = poll->canceled = false;
+       poll->events = mask;
+
+       ipt->pt._key = mask;
+       ipt->req = req;
+       ipt->error = -EINVAL;
+
+       INIT_LIST_HEAD(&poll->wait.entry);
+       init_waitqueue_func_entry(&poll->wait, wake_func);
+       poll->wait.private = req;
+
+       mask = vfs_poll(req->file, &ipt->pt) & poll->events;
+
+       spin_lock_irq(&ctx->completion_lock);
+       if (likely(poll->head)) {
+               spin_lock(&poll->head->lock);
+               if (unlikely(list_empty(&poll->wait.entry))) {
+                       if (ipt->error)
+                               cancel = true;
+                       ipt->error = 0;
+                       mask = 0;
+               }
+               if (mask || ipt->error)
+                       list_del_init(&poll->wait.entry);
+               else if (cancel)
+                       WRITE_ONCE(poll->canceled, true);
+               else if (!poll->done) /* actually waiting for an event */
+                       io_poll_req_insert(req);
+               spin_unlock(&poll->head->lock);
+       }
+
+       return mask;
+}
+
+static bool io_arm_poll_handler(struct io_kiocb *req)
+{
+       const struct io_op_def *def = &io_op_defs[req->opcode];
+       struct io_ring_ctx *ctx = req->ctx;
+       struct async_poll *apoll;
+       struct io_poll_table ipt;
+       __poll_t mask, ret;
+
+       if (!req->file || !file_can_poll(req->file))
+               return false;
+       if (req->flags & (REQ_F_MUST_PUNT | REQ_F_POLLED))
+               return false;
+       if (!def->pollin && !def->pollout)
+               return false;
+
+       apoll = kmalloc(sizeof(*apoll), GFP_ATOMIC);
+       if (unlikely(!apoll))
+               return false;
+
+       req->flags |= REQ_F_POLLED;
+       memcpy(&apoll->work, &req->work, sizeof(req->work));
+
+       /*
+        * Don't need a reference here, as we're adding it to the task
+        * task_works list. If the task exits, the list is pruned.
+        */
+       req->task = current;
+       req->apoll = apoll;
+       INIT_HLIST_NODE(&req->hash_node);
+
+       mask = 0;
+       if (def->pollin)
+               mask |= POLLIN | POLLRDNORM;
+       if (def->pollout)
+               mask |= POLLOUT | POLLWRNORM;
+       mask |= POLLERR | POLLPRI;
+
+       ipt.pt._qproc = io_async_queue_proc;
+
+       ret = __io_arm_poll_handler(req, &apoll->poll, &ipt, mask,
+                                       io_async_wake);
+       if (ret) {
+               ipt.error = 0;
+               apoll->poll.done = true;
+               spin_unlock_irq(&ctx->completion_lock);
+               memcpy(&req->work, &apoll->work, sizeof(req->work));
+               kfree(apoll);
+               return false;
+       }
+       spin_unlock_irq(&ctx->completion_lock);
+       trace_io_uring_poll_arm(ctx, req->opcode, req->user_data, mask,
+                                       apoll->poll.events);
+       return true;
+}
+
+static bool __io_poll_remove_one(struct io_kiocb *req,
+                                struct io_poll_iocb *poll)
 {
-       struct io_poll_iocb *poll = &req->poll;
+       bool do_complete = false;
 
        spin_lock(&poll->head->lock);
        WRITE_ONCE(poll->canceled, true);
        if (!list_empty(&poll->wait.entry)) {
                list_del_init(&poll->wait.entry);
-               io_queue_async_work(req);
+               do_complete = true;
        }
        spin_unlock(&poll->head->lock);
+       return do_complete;
+}
+
+static bool io_poll_remove_one(struct io_kiocb *req)
+{
+       bool do_complete;
+
+       if (req->opcode == IORING_OP_POLL_ADD) {
+               do_complete = __io_poll_remove_one(req, &req->poll);
+       } else {
+               /* non-poll requests have submit ref still */
+               do_complete = __io_poll_remove_one(req, &req->apoll->poll);
+               if (do_complete)
+                       io_put_req(req);
+       }
+
        hash_del(&req->hash_node);
+
+       if (do_complete) {
+               io_cqring_fill_event(req, -ECANCELED);
+               io_commit_cqring(req->ctx);
+               req->flags |= REQ_F_COMP_LOCKED;
+               io_put_req(req);
+       }
+
+       return do_complete;
 }
 
 static void io_poll_remove_all(struct io_ring_ctx *ctx)
@@ -3485,6 +4339,8 @@ static void io_poll_remove_all(struct io_ring_ctx *ctx)
                        io_poll_remove_one(req);
        }
        spin_unlock_irq(&ctx->completion_lock);
+
+       io_cqring_ev_posted(ctx);
 }
 
 static int io_poll_cancel(struct io_ring_ctx *ctx, __u64 sqe_addr)
@@ -3494,10 +4350,11 @@ static int io_poll_cancel(struct io_ring_ctx *ctx, __u64 sqe_addr)
 
        list = &ctx->cancel_hash[hash_long(sqe_addr, ctx->cancel_hash_bits)];
        hlist_for_each_entry(req, list, hash_node) {
-               if (sqe_addr == req->user_data) {
-                       io_poll_remove_one(req);
+               if (sqe_addr != req->user_data)
+                       continue;
+               if (io_poll_remove_one(req))
                        return 0;
-               }
+               return -EALREADY;
        }
 
        return -ENOENT;
@@ -3543,186 +4400,54 @@ static void io_poll_complete(struct io_kiocb *req, __poll_t mask, int error)
        struct io_ring_ctx *ctx = req->ctx;
 
        req->poll.done = true;
-       if (error)
-               io_cqring_fill_event(req, error);
-       else
-               io_cqring_fill_event(req, mangle_poll(mask));
+       io_cqring_fill_event(req, error ? error : mangle_poll(mask));
        io_commit_cqring(ctx);
 }
 
-static void io_poll_complete_work(struct io_wq_work **workptr)
+static void io_poll_task_handler(struct io_kiocb *req, struct io_kiocb **nxt)
 {
-       struct io_wq_work *work = *workptr;
-       struct io_kiocb *req = container_of(work, struct io_kiocb, work);
-       struct io_poll_iocb *poll = &req->poll;
-       struct poll_table_struct pt = { ._key = poll->events };
        struct io_ring_ctx *ctx = req->ctx;
-       struct io_kiocb *nxt = NULL;
-       __poll_t mask = 0;
-       int ret = 0;
-
-       if (work->flags & IO_WQ_WORK_CANCEL) {
-               WRITE_ONCE(poll->canceled, true);
-               ret = -ECANCELED;
-       } else if (READ_ONCE(poll->canceled)) {
-               ret = -ECANCELED;
-       }
-
-       if (ret != -ECANCELED)
-               mask = vfs_poll(poll->file, &pt) & poll->events;
 
-       /*
-        * Note that ->ki_cancel callers also delete iocb from active_reqs after
-        * calling ->ki_cancel.  We need the ctx_lock roundtrip here to
-        * synchronize with them.  In the cancellation case the list_del_init
-        * itself is not actually needed, but harmless so we keep it in to
-        * avoid further branches in the fast path.
-        */
        spin_lock_irq(&ctx->completion_lock);
-       if (!mask && ret != -ECANCELED) {
-               add_wait_queue(poll->head, &poll->wait);
-               spin_unlock_irq(&ctx->completion_lock);
-               return;
-       }
        hash_del(&req->hash_node);
-       io_poll_complete(req, mask, ret);
+       io_poll_complete(req, req->result, 0);
+       req->flags |= REQ_F_COMP_LOCKED;
+       io_put_req_find_next(req, nxt);
        spin_unlock_irq(&ctx->completion_lock);
 
        io_cqring_ev_posted(ctx);
-
-       if (ret < 0)
-               req_set_fail_links(req);
-       io_put_req_find_next(req, &nxt);
-       if (nxt)
-               io_wq_assign_next(workptr, nxt);
 }
 
-static void __io_poll_flush(struct io_ring_ctx *ctx, struct llist_node *nodes)
+static void io_poll_task_func(struct callback_head *cb)
 {
-       struct io_kiocb *req, *tmp;
-       struct req_batch rb;
+       struct io_kiocb *req = container_of(cb, struct io_kiocb, task_work);
+       struct io_kiocb *nxt = NULL;
 
-       rb.to_free = rb.need_iter = 0;
-       spin_lock_irq(&ctx->completion_lock);
-       llist_for_each_entry_safe(req, tmp, nodes, llist_node) {
-               hash_del(&req->hash_node);
-               io_poll_complete(req, req->result, 0);
+       io_poll_task_handler(req, &nxt);
+       if (nxt) {
+               struct io_ring_ctx *ctx = nxt->ctx;
 
-               if (refcount_dec_and_test(&req->refs) &&
-                   !io_req_multi_free(&rb, req)) {
-                       req->flags |= REQ_F_COMP_LOCKED;
-                       io_free_req(req);
-               }
+               mutex_lock(&ctx->uring_lock);
+               __io_queue_sqe(nxt, NULL);
+               mutex_unlock(&ctx->uring_lock);
        }
-       spin_unlock_irq(&ctx->completion_lock);
-
-       io_cqring_ev_posted(ctx);
-       io_free_req_many(ctx, &rb);
-}
-
-static void io_poll_flush(struct io_wq_work **workptr)
-{
-       struct io_kiocb *req = container_of(*workptr, struct io_kiocb, work);
-       struct llist_node *nodes;
-
-       nodes = llist_del_all(&req->ctx->poll_llist);
-       if (nodes)
-               __io_poll_flush(req->ctx, nodes);
-}
-
-static void io_poll_trigger_evfd(struct io_wq_work **workptr)
-{
-       struct io_kiocb *req = container_of(*workptr, struct io_kiocb, work);
-
-       eventfd_signal(req->ctx->cq_ev_fd, 1);
-       io_put_req(req);
 }
 
 static int io_poll_wake(struct wait_queue_entry *wait, unsigned mode, int sync,
                        void *key)
 {
-       struct io_poll_iocb *poll = wait->private;
-       struct io_kiocb *req = container_of(poll, struct io_kiocb, poll);
-       struct io_ring_ctx *ctx = req->ctx;
-       __poll_t mask = key_to_poll(key);
-
-       /* for instances that support it check for an event match first: */
-       if (mask && !(mask & poll->events))
-               return 0;
-
-       list_del_init(&poll->wait.entry);
-
-       /*
-        * Run completion inline if we can. We're using trylock here because
-        * we are violating the completion_lock -> poll wq lock ordering.
-        * If we have a link timeout we're going to need the completion_lock
-        * for finalizing the request, mark us as having grabbed that already.
-        */
-       if (mask) {
-               unsigned long flags;
-
-               if (llist_empty(&ctx->poll_llist) &&
-                   spin_trylock_irqsave(&ctx->completion_lock, flags)) {
-                       bool trigger_ev;
-
-                       hash_del(&req->hash_node);
-                       io_poll_complete(req, mask, 0);
-
-                       trigger_ev = io_should_trigger_evfd(ctx);
-                       if (trigger_ev && eventfd_signal_count()) {
-                               trigger_ev = false;
-                               req->work.func = io_poll_trigger_evfd;
-                       } else {
-                               req->flags |= REQ_F_COMP_LOCKED;
-                               io_put_req(req);
-                               req = NULL;
-                       }
-                       spin_unlock_irqrestore(&ctx->completion_lock, flags);
-                       __io_cqring_ev_posted(ctx, trigger_ev);
-               } else {
-                       req->result = mask;
-                       req->llist_node.next = NULL;
-                       /* if the list wasn't empty, we're done */
-                       if (!llist_add(&req->llist_node, &ctx->poll_llist))
-                               req = NULL;
-                       else
-                               req->work.func = io_poll_flush;
-               }
-       }
-       if (req)
-               io_queue_async_work(req);
+       struct io_kiocb *req = wait->private;
+       struct io_poll_iocb *poll = &req->poll;
 
-       return 1;
+       return __io_async_wake(req, poll, key_to_poll(key), io_poll_task_func);
 }
 
-struct io_poll_table {
-       struct poll_table_struct pt;
-       struct io_kiocb *req;
-       int error;
-};
-
 static void io_poll_queue_proc(struct file *file, struct wait_queue_head *head,
                               struct poll_table_struct *p)
 {
        struct io_poll_table *pt = container_of(p, struct io_poll_table, pt);
 
-       if (unlikely(pt->req->poll.head)) {
-               pt->error = -EINVAL;
-               return;
-       }
-
-       pt->error = 0;
-       pt->req->poll.head = head;
-       add_wait_queue(head, &pt->req->poll.wait);
-}
-
-static void io_poll_req_insert(struct io_kiocb *req)
-{
-       struct io_ring_ctx *ctx = req->ctx;
-       struct hlist_head *list;
-
-       list = &ctx->cancel_hash[hash_long(req->user_data, ctx->cancel_hash_bits)];
-       hlist_add_head(&req->hash_node, list);
+       __io_queue_proc(&pt->req->poll, pt, head);
 }
 
 static int io_poll_add_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
@@ -3739,55 +4464,29 @@ static int io_poll_add_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe
 
        events = READ_ONCE(sqe->poll_events);
        poll->events = demangle_poll(events) | EPOLLERR | EPOLLHUP;
+
+       /*
+        * Don't need a reference here, as we're adding it to the task
+        * task_works list. If the task exits, the list is pruned.
+        */
+       req->task = current;
        return 0;
 }
 
-static int io_poll_add(struct io_kiocb *req, struct io_kiocb **nxt)
+static int io_poll_add(struct io_kiocb *req)
 {
        struct io_poll_iocb *poll = &req->poll;
        struct io_ring_ctx *ctx = req->ctx;
        struct io_poll_table ipt;
-       bool cancel = false;
        __poll_t mask;
 
-       INIT_IO_WORK(&req->work, io_poll_complete_work);
        INIT_HLIST_NODE(&req->hash_node);
-
-       poll->head = NULL;
-       poll->done = false;
-       poll->canceled = false;
-
-       ipt.pt._qproc = io_poll_queue_proc;
-       ipt.pt._key = poll->events;
-       ipt.req = req;
-       ipt.error = -EINVAL; /* same as no support for IOCB_CMD_POLL */
-
-       /* initialized the list so that we can do list_empty checks */
-       INIT_LIST_HEAD(&poll->wait.entry);
-       init_waitqueue_func_entry(&poll->wait, io_poll_wake);
-       poll->wait.private = poll;
-
        INIT_LIST_HEAD(&req->list);
+       ipt.pt._qproc = io_poll_queue_proc;
 
-       mask = vfs_poll(poll->file, &ipt.pt) & poll->events;
+       mask = __io_arm_poll_handler(req, &req->poll, &ipt, poll->events,
+                                       io_poll_wake);
 
-       spin_lock_irq(&ctx->completion_lock);
-       if (likely(poll->head)) {
-               spin_lock(&poll->head->lock);
-               if (unlikely(list_empty(&poll->wait.entry))) {
-                       if (ipt.error)
-                               cancel = true;
-                       ipt.error = 0;
-                       mask = 0;
-               }
-               if (mask || ipt.error)
-                       list_del_init(&poll->wait.entry);
-               else if (cancel)
-                       WRITE_ONCE(poll->canceled, true);
-               else if (!poll->done) /* actually waiting for an event */
-                       io_poll_req_insert(req);
-               spin_unlock(&poll->head->lock);
-       }
        if (mask) { /* no async, we'd stolen it */
                ipt.error = 0;
                io_poll_complete(req, mask, 0);
@@ -3796,7 +4495,7 @@ static int io_poll_add(struct io_kiocb *req, struct io_kiocb **nxt)
 
        if (mask) {
                io_cqring_ev_posted(ctx);
-               io_put_req_find_next(req, nxt);
+               io_put_req(req);
        }
        return ipt.error;
 }
@@ -4045,7 +4744,7 @@ static int io_async_cancel_one(struct io_ring_ctx *ctx, void *sqe_addr)
 
 static void io_async_find_and_cancel(struct io_ring_ctx *ctx,
                                     struct io_kiocb *req, __u64 sqe_addr,
-                                    struct io_kiocb **nxt, int success_ret)
+                                    int success_ret)
 {
        unsigned long flags;
        int ret;
@@ -4071,7 +4770,7 @@ done:
 
        if (ret < 0)
                req_set_fail_links(req);
-       io_put_req_find_next(req, nxt);
+       io_put_req(req);
 }
 
 static int io_async_cancel_prep(struct io_kiocb *req,
@@ -4087,11 +4786,11 @@ static int io_async_cancel_prep(struct io_kiocb *req,
        return 0;
 }
 
-static int io_async_cancel(struct io_kiocb *req, struct io_kiocb **nxt)
+static int io_async_cancel(struct io_kiocb *req)
 {
        struct io_ring_ctx *ctx = req->ctx;
 
-       io_async_find_and_cancel(ctx, req, req->cancel.addr, nxt, 0);
+       io_async_find_and_cancel(ctx, req, req->cancel.addr, 0);
        return 0;
 }
 
@@ -4226,6 +4925,15 @@ static int io_req_defer_prep(struct io_kiocb *req,
        case IORING_OP_EPOLL_CTL:
                ret = io_epoll_ctl_prep(req, sqe);
                break;
+       case IORING_OP_SPLICE:
+               ret = io_splice_prep(req, sqe);
+               break;
+       case IORING_OP_PROVIDE_BUFFERS:
+               ret = io_provide_buffers_prep(req, sqe);
+               break;
+       case IORING_OP_REMOVE_BUFFERS:
+               ret = io_remove_buffers_prep(req, sqe);
+               break;
        default:
                printk_once(KERN_WARNING "io_uring: unhandled opcode %d\n",
                                req->opcode);
@@ -4272,29 +4980,43 @@ static void io_cleanup_req(struct io_kiocb *req)
        case IORING_OP_READV:
        case IORING_OP_READ_FIXED:
        case IORING_OP_READ:
+               if (req->flags & REQ_F_BUFFER_SELECTED)
+                       kfree((void *)(unsigned long)req->rw.addr);
+               /* fallthrough */
        case IORING_OP_WRITEV:
        case IORING_OP_WRITE_FIXED:
        case IORING_OP_WRITE:
                if (io->rw.iov != io->rw.fast_iov)
                        kfree(io->rw.iov);
                break;
-       case IORING_OP_SENDMSG:
        case IORING_OP_RECVMSG:
+               if (req->flags & REQ_F_BUFFER_SELECTED)
+                       kfree(req->sr_msg.kbuf);
+               /* fallthrough */
+       case IORING_OP_SENDMSG:
                if (io->msg.iov != io->msg.fast_iov)
                        kfree(io->msg.iov);
                break;
+       case IORING_OP_RECV:
+               if (req->flags & REQ_F_BUFFER_SELECTED)
+                       kfree(req->sr_msg.kbuf);
+               break;
        case IORING_OP_OPENAT:
        case IORING_OP_OPENAT2:
        case IORING_OP_STATX:
                putname(req->open.filename);
                break;
+       case IORING_OP_SPLICE:
+               io_put_file(req, req->splice.file_in,
+                           (req->splice.flags & SPLICE_F_FD_IN_FIXED));
+               break;
        }
 
        req->flags &= ~REQ_F_NEED_CLEANUP;
 }
 
 static int io_issue_sqe(struct io_kiocb *req, const struct io_uring_sqe *sqe,
-                       struct io_kiocb **nxt, bool force_nonblock)
+                       bool force_nonblock)
 {
        struct io_ring_ctx *ctx = req->ctx;
        int ret;
@@ -4311,7 +5033,7 @@ static int io_issue_sqe(struct io_kiocb *req, const struct io_uring_sqe *sqe,
                        if (ret < 0)
                                break;
                }
-               ret = io_read(req, nxt, force_nonblock);
+               ret = io_read(req, force_nonblock);
                break;
        case IORING_OP_WRITEV:
        case IORING_OP_WRITE_FIXED:
@@ -4321,7 +5043,7 @@ static int io_issue_sqe(struct io_kiocb *req, const struct io_uring_sqe *sqe,
                        if (ret < 0)
                                break;
                }
-               ret = io_write(req, nxt, force_nonblock);
+               ret = io_write(req, force_nonblock);
                break;
        case IORING_OP_FSYNC:
                if (sqe) {
@@ -4329,7 +5051,7 @@ static int io_issue_sqe(struct io_kiocb *req, const struct io_uring_sqe *sqe,
                        if (ret < 0)
                                break;
                }
-               ret = io_fsync(req, nxt, force_nonblock);
+               ret = io_fsync(req, force_nonblock);
                break;
        case IORING_OP_POLL_ADD:
                if (sqe) {
@@ -4337,7 +5059,7 @@ static int io_issue_sqe(struct io_kiocb *req, const struct io_uring_sqe *sqe,
                        if (ret)
                                break;
                }
-               ret = io_poll_add(req, nxt);
+               ret = io_poll_add(req);
                break;
        case IORING_OP_POLL_REMOVE:
                if (sqe) {
@@ -4353,7 +5075,7 @@ static int io_issue_sqe(struct io_kiocb *req, const struct io_uring_sqe *sqe,
                        if (ret < 0)
                                break;
                }
-               ret = io_sync_file_range(req, nxt, force_nonblock);
+               ret = io_sync_file_range(req, force_nonblock);
                break;
        case IORING_OP_SENDMSG:
        case IORING_OP_SEND:
@@ -4363,9 +5085,9 @@ static int io_issue_sqe(struct io_kiocb *req, const struct io_uring_sqe *sqe,
                                break;
                }
                if (req->opcode == IORING_OP_SENDMSG)
-                       ret = io_sendmsg(req, nxt, force_nonblock);
+                       ret = io_sendmsg(req, force_nonblock);
                else
-                       ret = io_send(req, nxt, force_nonblock);
+                       ret = io_send(req, force_nonblock);
                break;
        case IORING_OP_RECVMSG:
        case IORING_OP_RECV:
@@ -4375,9 +5097,9 @@ static int io_issue_sqe(struct io_kiocb *req, const struct io_uring_sqe *sqe,
                                break;
                }
                if (req->opcode == IORING_OP_RECVMSG)
-                       ret = io_recvmsg(req, nxt, force_nonblock);
+                       ret = io_recvmsg(req, force_nonblock);
                else
-                       ret = io_recv(req, nxt, force_nonblock);
+                       ret = io_recv(req, force_nonblock);
                break;
        case IORING_OP_TIMEOUT:
                if (sqe) {
@@ -4401,7 +5123,7 @@ static int io_issue_sqe(struct io_kiocb *req, const struct io_uring_sqe *sqe,
                        if (ret)
                                break;
                }
-               ret = io_accept(req, nxt, force_nonblock);
+               ret = io_accept(req, force_nonblock);
                break;
        case IORING_OP_CONNECT:
                if (sqe) {
@@ -4409,7 +5131,7 @@ static int io_issue_sqe(struct io_kiocb *req, const struct io_uring_sqe *sqe,
                        if (ret)
                                break;
                }
-               ret = io_connect(req, nxt, force_nonblock);
+               ret = io_connect(req, force_nonblock);
                break;
        case IORING_OP_ASYNC_CANCEL:
                if (sqe) {
@@ -4417,7 +5139,7 @@ static int io_issue_sqe(struct io_kiocb *req, const struct io_uring_sqe *sqe,
                        if (ret)
                                break;
                }
-               ret = io_async_cancel(req, nxt);
+               ret = io_async_cancel(req);
                break;
        case IORING_OP_FALLOCATE:
                if (sqe) {
@@ -4425,7 +5147,7 @@ static int io_issue_sqe(struct io_kiocb *req, const struct io_uring_sqe *sqe,
                        if (ret)
                                break;
                }
-               ret = io_fallocate(req, nxt, force_nonblock);
+               ret = io_fallocate(req, force_nonblock);
                break;
        case IORING_OP_OPENAT:
                if (sqe) {
@@ -4433,7 +5155,7 @@ static int io_issue_sqe(struct io_kiocb *req, const struct io_uring_sqe *sqe,
                        if (ret)
                                break;
                }
-               ret = io_openat(req, nxt, force_nonblock);
+               ret = io_openat(req, force_nonblock);
                break;
        case IORING_OP_CLOSE:
                if (sqe) {
@@ -4441,7 +5163,7 @@ static int io_issue_sqe(struct io_kiocb *req, const struct io_uring_sqe *sqe,
                        if (ret)
                                break;
                }
-               ret = io_close(req, nxt, force_nonblock);
+               ret = io_close(req, force_nonblock);
                break;
        case IORING_OP_FILES_UPDATE:
                if (sqe) {
@@ -4457,7 +5179,7 @@ static int io_issue_sqe(struct io_kiocb *req, const struct io_uring_sqe *sqe,
                        if (ret)
                                break;
                }
-               ret = io_statx(req, nxt, force_nonblock);
+               ret = io_statx(req, force_nonblock);
                break;
        case IORING_OP_FADVISE:
                if (sqe) {
@@ -4465,7 +5187,7 @@ static int io_issue_sqe(struct io_kiocb *req, const struct io_uring_sqe *sqe,
                        if (ret)
                                break;
                }
-               ret = io_fadvise(req, nxt, force_nonblock);
+               ret = io_fadvise(req, force_nonblock);
                break;
        case IORING_OP_MADVISE:
                if (sqe) {
@@ -4473,7 +5195,7 @@ static int io_issue_sqe(struct io_kiocb *req, const struct io_uring_sqe *sqe,
                        if (ret)
                                break;
                }
-               ret = io_madvise(req, nxt, force_nonblock);
+               ret = io_madvise(req, force_nonblock);
                break;
        case IORING_OP_OPENAT2:
                if (sqe) {
@@ -4481,7 +5203,7 @@ static int io_issue_sqe(struct io_kiocb *req, const struct io_uring_sqe *sqe,
                        if (ret)
                                break;
                }
-               ret = io_openat2(req, nxt, force_nonblock);
+               ret = io_openat2(req, force_nonblock);
                break;
        case IORING_OP_EPOLL_CTL:
                if (sqe) {
@@ -4489,7 +5211,31 @@ static int io_issue_sqe(struct io_kiocb *req, const struct io_uring_sqe *sqe,
                        if (ret)
                                break;
                }
-               ret = io_epoll_ctl(req, nxt, force_nonblock);
+               ret = io_epoll_ctl(req, force_nonblock);
+               break;
+       case IORING_OP_SPLICE:
+               if (sqe) {
+                       ret = io_splice_prep(req, sqe);
+                       if (ret < 0)
+                               break;
+               }
+               ret = io_splice(req, force_nonblock);
+               break;
+       case IORING_OP_PROVIDE_BUFFERS:
+               if (sqe) {
+                       ret = io_provide_buffers_prep(req, sqe);
+                       if (ret)
+                               break;
+               }
+               ret = io_provide_buffers(req, force_nonblock);
+               break;
+       case IORING_OP_REMOVE_BUFFERS:
+               if (sqe) {
+                       ret = io_remove_buffers_prep(req, sqe);
+                       if (ret)
+                               break;
+               }
+               ret = io_remove_buffers(req, force_nonblock);
                break;
        default:
                ret = -EINVAL;
@@ -4522,7 +5268,6 @@ static void io_wq_submit_work(struct io_wq_work **workptr)
 {
        struct io_wq_work *work = *workptr;
        struct io_kiocb *req = container_of(work, struct io_kiocb, work);
-       struct io_kiocb *nxt = NULL;
        int ret = 0;
 
        /* if NO_CANCEL is set, we must still run the work */
@@ -4532,9 +5277,8 @@ static void io_wq_submit_work(struct io_wq_work **workptr)
        }
 
        if (!ret) {
-               req->in_async = true;
                do {
-                       ret = io_issue_sqe(req, NULL, &nxt, false);
+                       ret = io_issue_sqe(req, NULL, false);
                        /*
                         * We can get EAGAIN for polled IO even though we're
                         * forcing a sync submission from here, since we can't
@@ -4546,18 +5290,13 @@ static void io_wq_submit_work(struct io_wq_work **workptr)
                } while (1);
        }
 
-       /* drop submission reference */
-       io_put_req(req);
-
        if (ret) {
                req_set_fail_links(req);
                io_cqring_add_event(req, ret);
                io_put_req(req);
        }
 
-       /* if a dependent link is ready, pass it back */
-       if (!ret && nxt)
-               io_wq_assign_next(workptr, nxt);
+       io_steal_work(req, workptr);
 }
 
 static int io_req_needs_file(struct io_kiocb *req, int fd)
@@ -4578,41 +5317,52 @@ static inline struct file *io_file_from_index(struct io_ring_ctx *ctx,
        return table->files[index & IORING_FILE_TABLE_MASK];;
 }
 
-static int io_req_set_file(struct io_submit_state *state, struct io_kiocb *req,
-                          const struct io_uring_sqe *sqe)
+static int io_file_get(struct io_submit_state *state, struct io_kiocb *req,
+                       int fd, struct file **out_file, bool fixed)
 {
        struct io_ring_ctx *ctx = req->ctx;
-       unsigned flags;
-       int fd;
-
-       flags = READ_ONCE(sqe->flags);
-       fd = READ_ONCE(sqe->fd);
-
-       if (!io_req_needs_file(req, fd))
-               return 0;
+       struct file *file;
 
-       if (flags & IOSQE_FIXED_FILE) {
+       if (fixed) {
                if (unlikely(!ctx->file_data ||
                    (unsigned) fd >= ctx->nr_user_files))
                        return -EBADF;
                fd = array_index_nospec(fd, ctx->nr_user_files);
-               req->file = io_file_from_index(ctx, fd);
-               if (!req->file)
+               file = io_file_from_index(ctx, fd);
+               if (!file)
                        return -EBADF;
-               req->flags |= REQ_F_FIXED_FILE;
                percpu_ref_get(&ctx->file_data->refs);
        } else {
-               if (req->needs_fixed_file)
-                       return -EBADF;
                trace_io_uring_file_get(ctx, fd);
-               req->file = io_file_get(state, fd);
-               if (unlikely(!req->file))
+               file = __io_file_get(state, fd);
+               if (unlikely(!file))
                        return -EBADF;
        }
 
+       *out_file = file;
        return 0;
 }
 
+static int io_req_set_file(struct io_submit_state *state, struct io_kiocb *req,
+                          const struct io_uring_sqe *sqe)
+{
+       unsigned flags;
+       int fd;
+       bool fixed;
+
+       flags = READ_ONCE(sqe->flags);
+       fd = READ_ONCE(sqe->fd);
+
+       if (!io_req_needs_file(req, fd))
+               return 0;
+
+       fixed = (flags & IOSQE_FIXED_FILE);
+       if (unlikely(!fixed && req->needs_fixed_file))
+               return -EBADF;
+
+       return io_file_get(state, req, fd, &req->file, fixed);
+}
+
 static int io_grab_files(struct io_kiocb *req)
 {
        int ret = -EBADF;
@@ -4672,8 +5422,7 @@ static enum hrtimer_restart io_link_timeout_fn(struct hrtimer *timer)
 
        if (prev) {
                req_set_fail_links(prev);
-               io_async_find_and_cancel(ctx, req, prev->user_data, NULL,
-                                               -ETIME);
+               io_async_find_and_cancel(ctx, req, prev->user_data, -ETIME);
                io_put_req(prev);
        } else {
                io_cqring_add_event(req, -ETIME);
@@ -4710,6 +5459,9 @@ static struct io_kiocb *io_prep_linked_timeout(struct io_kiocb *req)
 
        if (!(req->flags & REQ_F_LINK))
                return NULL;
+       /* for polled retry, if flag is set, we already went through here */
+       if (req->flags & REQ_F_POLLED)
+               return NULL;
 
        nxt = list_first_entry_or_null(&req->link_list, struct io_kiocb,
                                        link_list);
@@ -4723,7 +5475,7 @@ static struct io_kiocb *io_prep_linked_timeout(struct io_kiocb *req)
 static void __io_queue_sqe(struct io_kiocb *req, const struct io_uring_sqe *sqe)
 {
        struct io_kiocb *linked_timeout;
-       struct io_kiocb *nxt = NULL;
+       struct io_kiocb *nxt;
        const struct cred *old_creds = NULL;
        int ret;
 
@@ -4739,7 +5491,7 @@ again:
                        old_creds = override_creds(req->work.creds);
        }
 
-       ret = io_issue_sqe(req, sqe, &nxt, true);
+       ret = io_issue_sqe(req, sqe, true);
 
        /*
         * We async punt it if the file wasn't marked NOWAIT, or if the file
@@ -4747,6 +5499,11 @@ again:
         */
        if (ret == -EAGAIN && (!(req->flags & REQ_F_NOWAIT) ||
            (req->flags & REQ_F_MUST_PUNT))) {
+               if (io_arm_poll_handler(req)) {
+                       if (linked_timeout)
+                               io_queue_linked_timeout(linked_timeout);
+                       goto exit;
+               }
 punt:
                if (io_op_defs[req->opcode].file_table) {
                        ret = io_grab_files(req);
@@ -4759,10 +5516,11 @@ punt:
                 * submit reference when the iocb is actually submitted.
                 */
                io_queue_async_work(req);
-               goto done_req;
+               goto exit;
        }
 
 err:
+       nxt = NULL;
        /* drop submission reference */
        io_put_req_find_next(req, &nxt);
 
@@ -4779,15 +5537,14 @@ err:
                req_set_fail_links(req);
                io_put_req(req);
        }
-done_req:
        if (nxt) {
                req = nxt;
-               nxt = NULL;
 
                if (req->flags & REQ_F_FORCE_ASYNC)
                        goto punt;
                goto again;
        }
+exit:
        if (old_creds)
                revert_creds(old_creds);
 }
@@ -4829,7 +5586,8 @@ static inline void io_queue_link_head(struct io_kiocb *req)
 }
 
 #define SQE_VALID_FLAGS        (IOSQE_FIXED_FILE|IOSQE_IO_DRAIN|IOSQE_IO_LINK| \
-                               IOSQE_IO_HARDLINK | IOSQE_ASYNC)
+                               IOSQE_IO_HARDLINK | IOSQE_ASYNC | \
+                               IOSQE_BUFFER_SELECT)
 
 static bool io_submit_sqe(struct io_kiocb *req, const struct io_uring_sqe *sqe,
                          struct io_submit_state *state, struct io_kiocb **link)
@@ -4846,6 +5604,12 @@ static bool io_submit_sqe(struct io_kiocb *req, const struct io_uring_sqe *sqe,
                goto err_req;
        }
 
+       if ((sqe_flags & IOSQE_BUFFER_SELECT) &&
+           !io_op_defs[req->opcode].buffer_select) {
+               ret = -EOPNOTSUPP;
+               goto err_req;
+       }
+
        id = READ_ONCE(sqe->personality);
        if (id) {
                req->work.creds = idr_find(&ctx->personality_idr, id);
@@ -4857,8 +5621,9 @@ static bool io_submit_sqe(struct io_kiocb *req, const struct io_uring_sqe *sqe,
        }
 
        /* same numerical values with corresponding REQ_F_*, safe to copy */
-       req->flags |= sqe_flags & (IOSQE_IO_DRAIN|IOSQE_IO_HARDLINK|
-                                       IOSQE_ASYNC);
+       req->flags |= sqe_flags & (IOSQE_IO_DRAIN | IOSQE_IO_HARDLINK |
+                                       IOSQE_ASYNC | IOSQE_FIXED_FILE |
+                                       IOSQE_BUFFER_SELECT);
 
        ret = io_req_set_file(state, req, sqe);
        if (unlikely(ret)) {
@@ -5079,7 +5844,6 @@ fail_req:
                        *mm = ctx->sqo_mm;
                }
 
-               req->in_async = async;
                req->needs_fixed_file = async;
                trace_io_uring_submit_sqe(ctx, req->opcode, req->user_data,
                                                true, async);
@@ -5163,6 +5927,8 @@ static int io_sq_thread(void *data)
                        if (!list_empty(&ctx->poll_list) ||
                            (!time_after(jiffies, timeout) && ret != -EBUSY &&
                            !percpu_ref_is_dying(&ctx->refs))) {
+                               if (current->task_works)
+                                       task_work_run();
                                cond_resched();
                                continue;
                        }
@@ -5194,6 +5960,10 @@ static int io_sq_thread(void *data)
                                        finish_wait(&ctx->sqo_wait, &wait);
                                        break;
                                }
+                               if (current->task_works) {
+                                       task_work_run();
+                                       continue;
+                               }
                                if (signal_pending(current))
                                        flush_signals(current);
                                schedule();
@@ -5213,6 +5983,9 @@ static int io_sq_thread(void *data)
                timeout = jiffies + ctx->sq_thread_idle;
        }
 
+       if (current->task_works)
+               task_work_run();
+
        set_fs(old_fs);
        if (cur_mm) {
                unuse_mm(cur_mm);
@@ -5277,8 +6050,13 @@ static int io_cqring_wait(struct io_ring_ctx *ctx, int min_events,
        struct io_rings *rings = ctx->rings;
        int ret = 0;
 
-       if (io_cqring_events(ctx, false) >= min_events)
-               return 0;
+       do {
+               if (io_cqring_events(ctx, false) >= min_events)
+                       return 0;
+               if (!current->task_works)
+                       break;
+               task_work_run();
+       } while (1);
 
        if (sig) {
 #ifdef CONFIG_COMPAT
@@ -5298,6 +6076,8 @@ static int io_cqring_wait(struct io_ring_ctx *ctx, int min_events,
        do {
                prepare_to_wait_exclusive(&ctx->wait, &iowq.wq,
                                                TASK_INTERRUPTIBLE);
+               if (current->task_works)
+                       task_work_run();
                if (io_should_wake(&iowq, false))
                        break;
                schedule();
@@ -5607,7 +6387,6 @@ static void io_ring_file_put(struct io_ring_ctx *ctx, struct file *file)
 struct io_file_put {
        struct llist_node llist;
        struct file *file;
-       struct completion *done;
 };
 
 static void io_ring_file_ref_flush(struct fixed_file_data *data)
@@ -5618,10 +6397,7 @@ static void io_ring_file_ref_flush(struct fixed_file_data *data)
        while ((node = llist_del_all(&data->put_llist)) != NULL) {
                llist_for_each_entry_safe(pfile, tmp, node, llist) {
                        io_ring_file_put(data->ctx, pfile->file);
-                       if (pfile->done)
-                               complete(pfile->done);
-                       else
-                               kfree(pfile);
+                       kfree(pfile);
                }
        }
 }
@@ -5816,33 +6592,18 @@ static void io_atomic_switch(struct percpu_ref *ref)
        percpu_ref_get(&data->refs);
 }
 
-static bool io_queue_file_removal(struct fixed_file_data *data,
+static int io_queue_file_removal(struct fixed_file_data *data,
                                  struct file *file)
 {
-       struct io_file_put *pfile, pfile_stack;
-       DECLARE_COMPLETION_ONSTACK(done);
+       struct io_file_put *pfile;
 
-       /*
-        * If we fail allocating the struct we need for doing async reomval
-        * of this file, just punt to sync and wait for it.
-        */
        pfile = kzalloc(sizeof(*pfile), GFP_KERNEL);
-       if (!pfile) {
-               pfile = &pfile_stack;
-               pfile->done = &done;
-       }
+       if (!pfile)
+               return -ENOMEM;
 
        pfile->file = file;
        llist_add(&pfile->llist, &data->put_llist);
-
-       if (pfile == &pfile_stack) {
-               percpu_ref_switch_to_atomic(&data->refs, io_atomic_switch);
-               wait_for_completion(&done);
-               flush_work(&data->ref_work);
-               return false;
-       }
-
-       return true;
+       return 0;
 }
 
 static int __io_sqe_files_update(struct io_ring_ctx *ctx,
@@ -5877,9 +6638,11 @@ static int __io_sqe_files_update(struct io_ring_ctx *ctx,
                index = i & IORING_FILE_TABLE_MASK;
                if (table->files[index]) {
                        file = io_file_from_index(ctx, index);
+                       err = io_queue_file_removal(data, file);
+                       if (err)
+                               break;
                        table->files[index] = NULL;
-                       if (io_queue_file_removal(data, file))
-                               ref_switch = true;
+                       ref_switch = true;
                }
                if (fd != -1) {
                        file = fget(fd);
@@ -5932,20 +6695,14 @@ static int io_sqe_files_update(struct io_ring_ctx *ctx, void __user *arg,
        return __io_sqe_files_update(ctx, &up, nr_args);
 }
 
-static void io_put_work(struct io_wq_work *work)
+static void io_free_work(struct io_wq_work *work)
 {
        struct io_kiocb *req = container_of(work, struct io_kiocb, work);
 
+       /* Consider that io_steal_work() relies on this ref */
        io_put_req(req);
 }
 
-static void io_get_work(struct io_wq_work *work)
-{
-       struct io_kiocb *req = container_of(work, struct io_kiocb, work);
-
-       refcount_inc(&req->refs);
-}
-
 static int io_init_wq_offload(struct io_ring_ctx *ctx,
                              struct io_uring_params *p)
 {
@@ -5956,8 +6713,7 @@ static int io_init_wq_offload(struct io_ring_ctx *ctx,
        int ret = 0;
 
        data.user = ctx->user;
-       data.get_work = io_get_work;
-       data.put_work = io_put_work;
+       data.free_work = io_free_work;
 
        if (!(p->flags & IORING_SETUP_ATTACH_WQ)) {
                /* Do QD, or 4 * CPUS, whatever is smallest */
@@ -6359,6 +7115,21 @@ static int io_eventfd_unregister(struct io_ring_ctx *ctx)
        return -ENXIO;
 }
 
+static int __io_destroy_buffers(int id, void *p, void *data)
+{
+       struct io_ring_ctx *ctx = data;
+       struct io_buffer *buf = p;
+
+       __io_remove_buffers(ctx, buf, id, -1U);
+       return 0;
+}
+
+static void io_destroy_buffers(struct io_ring_ctx *ctx)
+{
+       idr_for_each(&ctx->io_buffer_idr, __io_destroy_buffers, ctx);
+       idr_destroy(&ctx->io_buffer_idr);
+}
+
 static void io_ring_ctx_free(struct io_ring_ctx *ctx)
 {
        io_finish_async(ctx);
@@ -6369,6 +7140,7 @@ static void io_ring_ctx_free(struct io_ring_ctx *ctx)
        io_sqe_buffer_unregister(ctx);
        io_sqe_files_unregister(ctx);
        io_eventfd_unregister(ctx);
+       io_destroy_buffers(ctx);
        idr_destroy(&ctx->personality_idr);
 
 #if defined(CONFIG_UNIX)
@@ -6623,6 +7395,9 @@ SYSCALL_DEFINE6(io_uring_enter, unsigned int, fd, u32, to_submit,
        int submitted = 0;
        struct fd f;
 
+       if (current->task_works)
+               task_work_run();
+
        if (flags & ~(IORING_ENTER_GETEVENTS | IORING_ENTER_SQ_WAKEUP))
                return -EINVAL;
 
@@ -6669,7 +7444,14 @@ SYSCALL_DEFINE6(io_uring_enter, unsigned int, fd, u32, to_submit,
 
                min_complete = min(min_complete, ctx->cq_entries);
 
-               if (ctx->flags & IORING_SETUP_IOPOLL) {
+               /*
+                * When SETUP_IOPOLL and SETUP_SQPOLL are both enabled, user
+                * space applications don't need to do io completion events
+                * polling again, they can rely on io_sq_thread to do polling
+                * work, which can reduce cpu usage and uring_lock contention.
+                */
+               if (ctx->flags & IORING_SETUP_IOPOLL &&
+                   !(ctx->flags & IORING_SETUP_SQPOLL)) {
                        ret = io_iopoll_check(ctx, &nr_events, min_complete);
                } else {
                        ret = io_cqring_wait(ctx, min_complete, sig, sigsz);
@@ -6745,6 +7527,17 @@ static void __io_uring_show_fdinfo(struct io_ring_ctx *ctx, struct seq_file *m)
                seq_printf(m, "Personalities:\n");
                idr_for_each(&ctx->personality_idr, io_uring_show_cred, m);
        }
+       seq_printf(m, "PollList:\n");
+       spin_lock_irq(&ctx->completion_lock);
+       for (i = 0; i < (1U << ctx->cancel_hash_bits); i++) {
+               struct hlist_head *list = &ctx->cancel_hash[i];
+               struct io_kiocb *req;
+
+               hlist_for_each_entry(req, list, hash_node)
+                       seq_printf(m, "  op=%d, task_works=%d\n", req->opcode,
+                                       req->task->task_works != NULL);
+       }
+       spin_unlock_irq(&ctx->completion_lock);
        mutex_unlock(&ctx->uring_lock);
 }
 
@@ -6961,7 +7754,7 @@ static int io_uring_create(unsigned entries, struct io_uring_params *p)
 
        p->features = IORING_FEAT_SINGLE_MMAP | IORING_FEAT_NODROP |
                        IORING_FEAT_SUBMIT_STABLE | IORING_FEAT_RW_CUR_POS |
-                       IORING_FEAT_CUR_PERSONALITY;
+                       IORING_FEAT_CUR_PERSONALITY | IORING_FEAT_FAST_POLL;
        trace_io_uring_create(ret, ctx, p->sq_entries, p->cq_entries, p->flags);
        return ret;
 err:
@@ -7239,6 +8032,7 @@ static int __init io_uring_init(void)
        BUILD_BUG_SQE_ELEM(8,  __u64,  off);
        BUILD_BUG_SQE_ELEM(8,  __u64,  addr2);
        BUILD_BUG_SQE_ELEM(16, __u64,  addr);
+       BUILD_BUG_SQE_ELEM(16, __u64,  splice_off_in);
        BUILD_BUG_SQE_ELEM(24, __u32,  len);
        BUILD_BUG_SQE_ELEM(28,     __kernel_rwf_t, rw_flags);
        BUILD_BUG_SQE_ELEM(28, /* compat */   int, rw_flags);
@@ -7253,11 +8047,14 @@ static int __init io_uring_init(void)
        BUILD_BUG_SQE_ELEM(28, __u32,  open_flags);
        BUILD_BUG_SQE_ELEM(28, __u32,  statx_flags);
        BUILD_BUG_SQE_ELEM(28, __u32,  fadvise_advice);
+       BUILD_BUG_SQE_ELEM(28, __u32,  splice_flags);
        BUILD_BUG_SQE_ELEM(32, __u64,  user_data);
        BUILD_BUG_SQE_ELEM(40, __u16,  buf_index);
        BUILD_BUG_SQE_ELEM(42, __u16,  personality);
+       BUILD_BUG_SQE_ELEM(44, __s32,  splice_fd_in);
 
        BUILD_BUG_ON(ARRAY_SIZE(io_op_defs) != IORING_OP_LAST);
+       BUILD_BUG_ON(__REQ_F_LAST_BIT >= 8 * sizeof(int));
        req_cachep = KMEM_CACHE(io_kiocb, SLAB_HWCACHE_ALIGN | SLAB_PANIC);
        return 0;
 };
index 40b6c5a..88e1763 100644 (file)
@@ -164,7 +164,7 @@ config ROOT_NFS
          If you want your system to mount its root file system via NFS,
          choose Y here.  This is common practice for managing systems
          without local permanent storage.  For details, read
-         <file:Documentation/filesystems/nfs/nfsroot.txt>.
+         <file:Documentation/admin-guide/nfs/nfsroot.rst>.
 
          Most people say N here.
 
index 7fbe8f0..d99b5d3 100644 (file)
@@ -87,11 +87,11 @@ static void *pstore_ftrace_seq_next(struct seq_file *s, void *v, loff_t *pos)
        struct pstore_private *ps = s->private;
        struct pstore_ftrace_seq_data *data = v;
 
+       (*pos)++;
        data->off += REC_SIZE;
        if (data->off + REC_SIZE > ps->total_size)
                return NULL;
 
-       (*pos)++;
        return data;
 }
 
@@ -101,6 +101,9 @@ static int pstore_ftrace_seq_show(struct seq_file *s, void *v)
        struct pstore_ftrace_seq_data *data = v;
        struct pstore_ftrace_record *rec;
 
+       if (!data)
+               return 0;
+
        rec = (struct pstore_ftrace_record *)(ps->record->buf + data->off);
 
        seq_printf(s, "CPU:%d ts:%llu %08lx  %08lx  %ps <- %pS\n",
index d896457..408277e 100644 (file)
@@ -823,9 +823,9 @@ static int __init pstore_init(void)
 
        ret = pstore_init_fs();
        if (ret)
-               return ret;
+               free_buf_for_compression();
 
-       return 0;
+       return ret;
 }
 late_initcall(pstore_init);
 
index 013486b..7956221 100644 (file)
@@ -963,7 +963,6 @@ static void __init ramoops_register_dummy(void)
                pr_info("could not create platform device: %ld\n",
                        PTR_ERR(dummy));
                dummy = NULL;
-               ramoops_unregister_dummy();
        }
 }
 
index 1f4d8c0..c917c19 100644 (file)
@@ -34,7 +34,7 @@ struct persistent_ram_buffer {
        uint32_t    sig;
        atomic_t    start;
        atomic_t    size;
-       uint8_t     data[0];
+       uint8_t     data[];
 };
 
 #define PERSISTENT_RAM_SIG (0x43474244) /* DBGC */
index 072156c..5c76633 100644 (file)
@@ -2599,7 +2599,6 @@ static int journal_init_dev(struct super_block *super,
        int result;
        dev_t jdev;
        fmode_t blkdev_mode = FMODE_READ | FMODE_WRITE | FMODE_EXCL;
-       char b[BDEVNAME_SIZE];
 
        result = 0;
 
@@ -2621,8 +2620,8 @@ static int journal_init_dev(struct super_block *super,
                        result = PTR_ERR(journal->j_dev_bd);
                        journal->j_dev_bd = NULL;
                        reiserfs_warning(super, "sh-458",
-                                        "cannot init journal device '%s': %i",
-                                        __bdevname(jdev, b), result);
+                                        "cannot init journal device unknown-block(%u,%u): %i",
+                                        MAJOR(jdev), MINOR(jdev), result);
                        return result;
                } else if (jdev != super->s_dev)
                        set_blocksize(journal->j_dev_bd, super->s_blocksize);
index d671936..4735def 100644 (file)
@@ -1109,9 +1109,9 @@ static int splice_pipe_to_pipe(struct pipe_inode_info *ipipe,
 /*
  * Determine where to splice to/from.
  */
-static long do_splice(struct file *in, loff_t __user *off_in,
-                     struct file *out, loff_t __user *off_out,
-                     size_t len, unsigned int flags)
+long do_splice(struct file *in, loff_t __user *off_in,
+               struct file *out, loff_t __user *off_out,
+               size_t len, unsigned int flags)
 {
        struct pipe_inode_info *ipipe;
        struct pipe_inode_info *opipe;
index 853d92c..c1c0f9e 100644 (file)
@@ -441,14 +441,6 @@ void __bio_add_page(struct bio *bio, struct page *page,
                unsigned int len, unsigned int off);
 int bio_iov_iter_get_pages(struct bio *bio, struct iov_iter *iter);
 void bio_release_pages(struct bio *bio, bool mark_dirty);
-struct rq_map_data;
-extern struct bio *bio_map_user_iov(struct request_queue *,
-                                   struct iov_iter *, gfp_t);
-extern void bio_unmap_user(struct bio *);
-extern struct bio *bio_map_kern(struct request_queue *, void *, unsigned int,
-                               gfp_t);
-extern struct bio *bio_copy_kern(struct request_queue *, void *, unsigned int,
-                                gfp_t, int);
 extern void bio_set_pages_dirty(struct bio *bio);
 extern void bio_check_pages_dirty(struct bio *bio);
 
@@ -463,14 +455,9 @@ extern void bio_copy_data_iter(struct bio *dst, struct bvec_iter *dst_iter,
 extern void bio_copy_data(struct bio *dst, struct bio *src);
 extern void bio_list_copy_data(struct bio *dst, struct bio *src);
 extern void bio_free_pages(struct bio *bio);
-
-extern struct bio *bio_copy_user_iov(struct request_queue *,
-                                    struct rq_map_data *,
-                                    struct iov_iter *,
-                                    gfp_t);
-extern int bio_uncopy_user(struct bio *);
 void zero_fill_bio_iter(struct bio *bio, struct bvec_iter iter);
 void bio_truncate(struct bio *bio, unsigned new_size);
+void guard_bio_eod(struct bio *bio);
 
 static inline void zero_fill_bio(struct bio *bio)
 {
index 11cfd64..f389d7c 100644 (file)
@@ -162,7 +162,10 @@ struct blk_mq_hw_ctx {
        struct dentry           *sched_debugfs_dir;
 #endif
 
-       /** @hctx_list: List of all hardware queues. */
+       /**
+        * @hctx_list: if this hctx is not in use, this is an entry in
+        * q->unused_hctx_list.
+        */
        struct list_head        hctx_list;
 
        /**
@@ -409,6 +412,8 @@ enum {
                << BLK_MQ_F_ALLOC_POLICY_START_BIT)
 
 struct request_queue *blk_mq_init_queue(struct blk_mq_tag_set *);
+struct request_queue *blk_mq_init_queue_data(struct blk_mq_tag_set *set,
+               void *queuedata);
 struct request_queue *blk_mq_init_allocated_queue(struct blk_mq_tag_set *set,
                                                  struct request_queue *q,
                                                  bool elevator_init);
index f629d40..32868fb 100644 (file)
@@ -952,6 +952,10 @@ static inline unsigned int blk_rq_stats_sectors(const struct request *rq)
 }
 
 #ifdef CONFIG_BLK_DEV_ZONED
+
+/* Helper to convert BLK_ZONE_ZONE_XXX to its string format XXX */
+const char *blk_zone_cond_str(enum blk_zone_cond zone_cond);
+
 static inline unsigned int blk_rq_zone_no(struct request *rq)
 {
        return blk_queue_zone_no(rq->q, blk_rq_pos(rq));
@@ -1063,7 +1067,6 @@ extern void blk_abort_request(struct request *);
  * Access functions for manipulating queue properties
  */
 extern void blk_cleanup_queue(struct request_queue *);
-extern void blk_queue_make_request(struct request_queue *, make_request_fn *);
 extern void blk_queue_bounce_limit(struct request_queue *, u64);
 extern void blk_queue_max_hw_sectors(struct request_queue *, unsigned int);
 extern void blk_queue_chunk_sectors(struct request_queue *, unsigned int);
@@ -1140,8 +1143,7 @@ extern void blk_dump_rq_flags(struct request *, char *);
 extern long nr_blockdev_pages(void);
 
 bool __must_check blk_get_queue(struct request_queue *);
-struct request_queue *blk_alloc_queue(gfp_t);
-struct request_queue *blk_alloc_queue_node(gfp_t gfp_mask, int node_id);
+struct request_queue *blk_alloc_queue(make_request_fn make_request, int node_id);
 extern void blk_put_queue(struct request_queue *);
 extern void blk_set_queue_dying(struct request_queue *);
 
@@ -1484,15 +1486,6 @@ static inline unsigned int block_size(struct block_device *bdev)
        return bdev->bd_block_size;
 }
 
-typedef struct {struct page *v;} Sector;
-
-unsigned char *read_dev_sector(struct block_device *, sector_t, Sector *);
-
-static inline void put_dev_sector(Sector p)
-{
-       put_page(p.v);
-}
-
 int kblockd_schedule_work(struct work_struct *work);
 int kblockd_mod_delayed_work_on(int cpu, struct delayed_work *dwork, unsigned long delay);
 
@@ -1706,6 +1699,7 @@ struct block_device_operations {
        void (*swap_slot_free_notify) (struct block_device *, unsigned long);
        int (*report_zones)(struct gendisk *, sector_t sector,
                        unsigned int nr_zones, report_zones_cb cb, void *data);
+       char *(*devnode)(struct gendisk *disk, umode_t *mode);
        struct module *owner;
        const struct pr_ops *pr_ops;
 };
index abedbff..593e911 100644 (file)
@@ -2700,7 +2700,6 @@ static inline void unregister_chrdev(unsigned int major, const char *name)
 
 #ifdef CONFIG_BLOCK
 #define BLKDEV_MAJOR_MAX       512
-extern const char *__bdevname(dev_t, char *buffer);
 extern const char *bdevname(struct block_device *bdev, char *buffer);
 extern struct block_device *lookup_bdev(const char *);
 extern void blkdev_show(struct seq_file *,off_t);
index 07dc918..9b3fffd 100644 (file)
 #define part_to_dev(part)      (&((part)->__dev))
 
 extern struct device_type part_type;
-extern struct kobject *block_depr;
 extern struct class block_class;
 
-enum {
-/* These three have identical behaviour; use the second one if DOS FDISK gets
-   confused about extended/logical partitions starting past cylinder 1023. */
-       DOS_EXTENDED_PARTITION = 5,
-       LINUX_EXTENDED_PARTITION = 0x85,
-       WIN98_EXTENDED_PARTITION = 0x0f,
-
-       SUN_WHOLE_DISK = DOS_EXTENDED_PARTITION,
-
-       LINUX_SWAP_PARTITION = 0x82,
-       LINUX_DATA_PARTITION = 0x83,
-       LINUX_LVM_PARTITION = 0x8e,
-       LINUX_RAID_PARTITION = 0xfd,    /* autodetect RAID partition */
-
-       SOLARIS_X86_PARTITION = LINUX_SWAP_PARTITION,
-       NEW_SOLARIS_X86_PARTITION = 0xbf,
-
-       DM6_AUX1PARTITION = 0x51,       /* no DDO:  use xlated geom */
-       DM6_AUX3PARTITION = 0x53,       /* no DDO:  use xlated geom */
-       DM6_PARTITION = 0x54,           /* has DDO: use xlated geom & offset */
-       EZD_PARTITION = 0x55,           /* EZ-DRIVE */
-
-       FREEBSD_PARTITION = 0xa5,       /* FreeBSD Partition ID */
-       OPENBSD_PARTITION = 0xa6,       /* OpenBSD Partition ID */
-       NETBSD_PARTITION = 0xa9,        /* NetBSD Partition ID */
-       BSDI_PARTITION = 0xb7,          /* BSDI Partition ID */
-       MINIX_PARTITION = 0x81,         /* Minix Partition ID */
-       UNIXWARE_PARTITION = 0x63,      /* Same as GNU_HURD and SCO Unix */
-};
-
 #define DISK_MAX_PARTS                 256
 #define DISK_NAME_LEN                  32
 
@@ -70,26 +39,12 @@ enum {
 #include <linux/fs.h>
 #include <linux/workqueue.h>
 
-struct partition {
-       unsigned char boot_ind;         /* 0x80 - active */
-       unsigned char head;             /* starting head */
-       unsigned char sector;           /* starting sector */
-       unsigned char cyl;              /* starting cylinder */
-       unsigned char sys_ind;          /* What partition type */
-       unsigned char end_head;         /* end head */
-       unsigned char end_sector;       /* end sector */
-       unsigned char end_cyl;          /* end cylinder */
-       __le32 start_sect;      /* starting sector counting from 0 */
-       __le32 nr_sects;                /* nr of sectors in partition */
-} __attribute__((packed));
-
 struct disk_stats {
        u64 nsecs[NR_STAT_GROUPS];
        unsigned long sectors[NR_STAT_GROUPS];
        unsigned long ios[NR_STAT_GROUPS];
        unsigned long merges[NR_STAT_GROUPS];
        unsigned long io_ticks;
-       unsigned long time_in_queue;
        local_t in_flight[2];
 };
 
@@ -133,17 +88,64 @@ struct hd_struct {
        struct rcu_work rcu_work;
 };
 
-#define GENHD_FL_REMOVABLE                     1
-/* 2 is unused */
-#define GENHD_FL_MEDIA_CHANGE_NOTIFY           4
-#define GENHD_FL_CD                            8
-#define GENHD_FL_UP                            16
-#define GENHD_FL_SUPPRESS_PARTITION_INFO       32
-#define GENHD_FL_EXT_DEVT                      64 /* allow extended devt */
-#define GENHD_FL_NATIVE_CAPACITY               128
-#define GENHD_FL_BLOCK_EVENTS_ON_EXCL_WRITE    256
-#define GENHD_FL_NO_PART_SCAN                  512
-#define GENHD_FL_HIDDEN                                1024
+/**
+ * DOC: genhd capability flags
+ *
+ * ``GENHD_FL_REMOVABLE`` (0x0001): indicates that the block device
+ * gives access to removable media.
+ * When set, the device remains present even when media is not
+ * inserted.
+ * Must not be set for devices which are removed entirely when the
+ * media is removed.
+ *
+ * ``GENHD_FL_CD`` (0x0008): the block device is a CD-ROM-style
+ * device.
+ * Affects responses to the ``CDROM_GET_CAPABILITY`` ioctl.
+ *
+ * ``GENHD_FL_UP`` (0x0010): indicates that the block device is "up",
+ * with a similar meaning to network interfaces.
+ *
+ * ``GENHD_FL_SUPPRESS_PARTITION_INFO`` (0x0020): don't include
+ * partition information in ``/proc/partitions`` or in the output of
+ * printk_all_partitions().
+ * Used for the null block device and some MMC devices.
+ *
+ * ``GENHD_FL_EXT_DEVT`` (0x0040): the driver supports extended
+ * dynamic ``dev_t``, i.e. it wants extended device numbers
+ * (``BLOCK_EXT_MAJOR``).
+ * This affects the maximum number of partitions.
+ *
+ * ``GENHD_FL_NATIVE_CAPACITY`` (0x0080): based on information in the
+ * partition table, the device's capacity has been extended to its
+ * native capacity; i.e. the device has hidden capacity used by one
+ * of the partitions (this is a flag used so that native capacity is
+ * only ever unlocked once).
+ *
+ * ``GENHD_FL_BLOCK_EVENTS_ON_EXCL_WRITE`` (0x0100): event polling is
+ * blocked whenever a writer holds an exclusive lock.
+ *
+ * ``GENHD_FL_NO_PART_SCAN`` (0x0200): partition scanning is disabled.
+ * Used for loop devices in their default settings and some MMC
+ * devices.
+ *
+ * ``GENHD_FL_HIDDEN`` (0x0400): the block device is hidden; it
+ * doesn't produce events, doesn't appear in sysfs, and doesn't have
+ * an associated ``bdev``.
+ * Implies ``GENHD_FL_SUPPRESS_PARTITION_INFO`` and
+ * ``GENHD_FL_NO_PART_SCAN``.
+ * Used for multipath devices.
+ */
+#define GENHD_FL_REMOVABLE                     0x0001
+/* 2 is unused (used to be GENHD_FL_DRIVERFS) */
+/* 4 is unused (used to be GENHD_FL_MEDIA_CHANGE_NOTIFY) */
+#define GENHD_FL_CD                            0x0008
+#define GENHD_FL_UP                            0x0010
+#define GENHD_FL_SUPPRESS_PARTITION_INFO       0x0020
+#define GENHD_FL_EXT_DEVT                      0x0040
+#define GENHD_FL_NATIVE_CAPACITY               0x0080
+#define GENHD_FL_BLOCK_EVENTS_ON_EXCL_WRITE    0x0100
+#define GENHD_FL_NO_PART_SCAN                  0x0200
+#define GENHD_FL_HIDDEN                                0x0400
 
 enum {
        DISK_EVENT_MEDIA_CHANGE                 = 1 << 0, /* media changed */
@@ -189,7 +191,6 @@ struct gendisk {
                                          * disks that can't be partitioned. */
 
        char disk_name[DISK_NAME_LEN];  /* name of major driver */
-       char *(*devnode)(struct gendisk *gd, umode_t *mode);
 
        unsigned short events;          /* supported events */
        unsigned short event_flags;     /* flags related to event processing */
@@ -283,144 +284,7 @@ extern void disk_part_iter_init(struct disk_part_iter *piter,
                                 struct gendisk *disk, unsigned int flags);
 extern struct hd_struct *disk_part_iter_next(struct disk_part_iter *piter);
 extern void disk_part_iter_exit(struct disk_part_iter *piter);
-
-extern struct hd_struct *disk_map_sector_rcu(struct gendisk *disk,
-                                            sector_t sector);
-bool disk_has_partitions(struct gendisk *disk);
-
-/*
- * Macros to operate on percpu disk statistics:
- *
- * {disk|part|all}_stat_{add|sub|inc|dec}() modify the stat counters
- * and should be called between disk_stat_lock() and
- * disk_stat_unlock().
- *
- * part_stat_read() can be called at any time.
- *
- * part_stat_{add|set_all}() and {init|free}_part_stats are for
- * internal use only.
- */
-#ifdef CONFIG_SMP
-#define part_stat_lock()       ({ rcu_read_lock(); get_cpu(); })
-#define part_stat_unlock()     do { put_cpu(); rcu_read_unlock(); } while (0)
-
-#define part_stat_get_cpu(part, field, cpu)                                    \
-       (per_cpu_ptr((part)->dkstats, (cpu))->field)
-
-#define part_stat_get(part, field)                                     \
-       part_stat_get_cpu(part, field, smp_processor_id())
-
-#define part_stat_read(part, field)                                    \
-({                                                                     \
-       typeof((part)->dkstats->field) res = 0;                         \
-       unsigned int _cpu;                                              \
-       for_each_possible_cpu(_cpu)                                     \
-               res += per_cpu_ptr((part)->dkstats, _cpu)->field;       \
-       res;                                                            \
-})
-
-static inline void part_stat_set_all(struct hd_struct *part, int value)
-{
-       int i;
-
-       for_each_possible_cpu(i)
-               memset(per_cpu_ptr(part->dkstats, i), value,
-                               sizeof(struct disk_stats));
-}
-
-static inline int init_part_stats(struct hd_struct *part)
-{
-       part->dkstats = alloc_percpu(struct disk_stats);
-       if (!part->dkstats)
-               return 0;
-       return 1;
-}
-
-static inline void free_part_stats(struct hd_struct *part)
-{
-       free_percpu(part->dkstats);
-}
-
-#else /* !CONFIG_SMP */
-#define part_stat_lock()       ({ rcu_read_lock(); 0; })
-#define part_stat_unlock()     rcu_read_unlock()
-
-#define part_stat_get(part, field)             ((part)->dkstats.field)
-#define part_stat_get_cpu(part, field, cpu)    part_stat_get(part, field)
-#define part_stat_read(part, field)            part_stat_get(part, field)
-
-static inline void part_stat_set_all(struct hd_struct *part, int value)
-{
-       memset(&part->dkstats, value, sizeof(struct disk_stats));
-}
-
-static inline int init_part_stats(struct hd_struct *part)
-{
-       return 1;
-}
-
-static inline void free_part_stats(struct hd_struct *part)
-{
-}
-
-#endif /* CONFIG_SMP */
-
-#define part_stat_read_msecs(part, which)                              \
-       div_u64(part_stat_read(part, nsecs[which]), NSEC_PER_MSEC)
-
-#define part_stat_read_accum(part, field)                              \
-       (part_stat_read(part, field[STAT_READ]) +                       \
-        part_stat_read(part, field[STAT_WRITE]) +                      \
-        part_stat_read(part, field[STAT_DISCARD]))
-
-#define __part_stat_add(part, field, addnd)                            \
-       (part_stat_get(part, field) += (addnd))
-
-#define part_stat_add(part, field, addnd)      do {                    \
-       __part_stat_add((part), field, addnd);                          \
-       if ((part)->partno)                                             \
-               __part_stat_add(&part_to_disk((part))->part0,           \
-                               field, addnd);                          \
-} while (0)
-
-#define part_stat_dec(gendiskp, field)                                 \
-       part_stat_add(gendiskp, field, -1)
-#define part_stat_inc(gendiskp, field)                                 \
-       part_stat_add(gendiskp, field, 1)
-#define part_stat_sub(gendiskp, field, subnd)                          \
-       part_stat_add(gendiskp, field, -subnd)
-
-#define part_stat_local_dec(gendiskp, field)                           \
-       local_dec(&(part_stat_get(gendiskp, field)))
-#define part_stat_local_inc(gendiskp, field)                           \
-       local_inc(&(part_stat_get(gendiskp, field)))
-#define part_stat_local_read(gendiskp, field)                          \
-       local_read(&(part_stat_get(gendiskp, field)))
-#define part_stat_local_read_cpu(gendiskp, field, cpu)                 \
-       local_read(&(part_stat_get_cpu(gendiskp, field, cpu)))
-
-unsigned int part_in_flight(struct request_queue *q, struct hd_struct *part);
-void part_in_flight_rw(struct request_queue *q, struct hd_struct *part,
-                      unsigned int inflight[2]);
-void part_dec_in_flight(struct request_queue *q, struct hd_struct *part,
-                       int rw);
-void part_inc_in_flight(struct request_queue *q, struct hd_struct *part,
-                       int rw);
-
-static inline struct partition_meta_info *alloc_part_info(struct gendisk *disk)
-{
-       if (disk)
-               return kzalloc_node(sizeof(struct partition_meta_info),
-                                   GFP_KERNEL, disk->node_id);
-       return kzalloc(sizeof(struct partition_meta_info), GFP_KERNEL);
-}
-
-static inline void free_part_info(struct hd_struct *part)
-{
-       kfree(part->info);
-}
-
-void update_io_ticks(struct hd_struct *part, unsigned long now);
+extern bool disk_has_partitions(struct gendisk *disk);
 
 /* block/genhd.c */
 extern void device_add_disk(struct device *parent, struct gendisk *disk,
@@ -450,6 +314,8 @@ static inline int get_disk_ro(struct gendisk *disk)
 extern void disk_block_events(struct gendisk *disk);
 extern void disk_unblock_events(struct gendisk *disk);
 extern void disk_flush_events(struct gendisk *disk, unsigned int mask);
+extern void set_capacity_revalidate_and_notify(struct gendisk *disk,
+                       sector_t size, bool revalidate);
 extern unsigned int disk_clear_events(struct gendisk *disk, unsigned int mask);
 
 /* drivers/char/random.c */
@@ -469,170 +335,11 @@ static inline void set_capacity(struct gendisk *disk, sector_t size)
        disk->part0.nr_sects = size;
 }
 
-#ifdef CONFIG_SOLARIS_X86_PARTITION
-
-#define SOLARIS_X86_NUMSLICE   16
-#define SOLARIS_X86_VTOC_SANE  (0x600DDEEEUL)
-
-struct solaris_x86_slice {
-       __le16 s_tag;           /* ID tag of partition */
-       __le16 s_flag;          /* permission flags */
-       __le32 s_start;         /* start sector no of partition */
-       __le32 s_size;          /* # of blocks in partition */
-};
-
-struct solaris_x86_vtoc {
-       unsigned int v_bootinfo[3];     /* info needed by mboot (unsupported) */
-       __le32 v_sanity;                /* to verify vtoc sanity */
-       __le32 v_version;               /* layout version */
-       char    v_volume[8];            /* volume name */
-       __le16  v_sectorsz;             /* sector size in bytes */
-       __le16  v_nparts;               /* number of partitions */
-       unsigned int v_reserved[10];    /* free space */
-       struct solaris_x86_slice
-               v_slice[SOLARIS_X86_NUMSLICE]; /* slice headers */
-       unsigned int timestamp[SOLARIS_X86_NUMSLICE]; /* timestamp (unsupported) */
-       char    v_asciilabel[128];      /* for compatibility */
-};
-
-#endif /* CONFIG_SOLARIS_X86_PARTITION */
-
-#ifdef CONFIG_BSD_DISKLABEL
-/*
- * BSD disklabel support by Yossi Gottlieb <yogo@math.tau.ac.il>
- * updated by Marc Espie <Marc.Espie@openbsd.org>
- */
-
-/* check against BSD src/sys/sys/disklabel.h for consistency */
-
-#define BSD_DISKMAGIC  (0x82564557UL)  /* The disk magic number */
-#define BSD_MAXPARTITIONS      16
-#define OPENBSD_MAXPARTITIONS  16
-#define BSD_FS_UNUSED          0       /* disklabel unused partition entry ID */
-struct bsd_disklabel {
-       __le32  d_magic;                /* the magic number */
-       __s16   d_type;                 /* drive type */
-       __s16   d_subtype;              /* controller/d_type specific */
-       char    d_typename[16];         /* type name, e.g. "eagle" */
-       char    d_packname[16];                 /* pack identifier */ 
-       __u32   d_secsize;              /* # of bytes per sector */
-       __u32   d_nsectors;             /* # of data sectors per track */
-       __u32   d_ntracks;              /* # of tracks per cylinder */
-       __u32   d_ncylinders;           /* # of data cylinders per unit */
-       __u32   d_secpercyl;            /* # of data sectors per cylinder */
-       __u32   d_secperunit;           /* # of data sectors per unit */
-       __u16   d_sparespertrack;       /* # of spare sectors per track */
-       __u16   d_sparespercyl;         /* # of spare sectors per cylinder */
-       __u32   d_acylinders;           /* # of alt. cylinders per unit */
-       __u16   d_rpm;                  /* rotational speed */
-       __u16   d_interleave;           /* hardware sector interleave */
-       __u16   d_trackskew;            /* sector 0 skew, per track */
-       __u16   d_cylskew;              /* sector 0 skew, per cylinder */
-       __u32   d_headswitch;           /* head switch time, usec */
-       __u32   d_trkseek;              /* track-to-track seek, usec */
-       __u32   d_flags;                /* generic flags */
-#define NDDATA 5
-       __u32   d_drivedata[NDDATA];    /* drive-type specific information */
-#define NSPARE 5
-       __u32   d_spare[NSPARE];        /* reserved for future use */
-       __le32  d_magic2;               /* the magic number (again) */
-       __le16  d_checksum;             /* xor of data incl. partitions */
-
-                       /* filesystem and partition information: */
-       __le16  d_npartitions;          /* number of partitions in following */
-       __le32  d_bbsize;               /* size of boot area at sn0, bytes */
-       __le32  d_sbsize;               /* max size of fs superblock, bytes */
-       struct  bsd_partition {         /* the partition table */
-               __le32  p_size;         /* number of sectors in partition */
-               __le32  p_offset;       /* starting sector */
-               __le32  p_fsize;        /* filesystem basic fragment size */
-               __u8    p_fstype;       /* filesystem type, see below */
-               __u8    p_frag;         /* filesystem fragments per block */
-               __le16  p_cpg;          /* filesystem cylinders per group */
-       } d_partitions[BSD_MAXPARTITIONS];      /* actually may be more */
-};
-
-#endif /* CONFIG_BSD_DISKLABEL */
-
-#ifdef CONFIG_UNIXWARE_DISKLABEL
-/*
- * Unixware slices support by Andrzej Krzysztofowicz <ankry@mif.pg.gda.pl>
- * and Krzysztof G. Baranowski <kgb@knm.org.pl>
- */
-
-#define UNIXWARE_DISKMAGIC     (0xCA5E600DUL)  /* The disk magic number */
-#define UNIXWARE_DISKMAGIC2    (0x600DDEEEUL)  /* The slice table magic nr */
-#define UNIXWARE_NUMSLICE      16
-#define UNIXWARE_FS_UNUSED     0               /* Unused slice entry ID */
-
-struct unixware_slice {
-       __le16   s_label;       /* label */
-       __le16   s_flags;       /* permission flags */
-       __le32   start_sect;    /* starting sector */
-       __le32   nr_sects;      /* number of sectors in slice */
-};
-
-struct unixware_disklabel {
-       __le32   d_type;                /* drive type */
-       __le32   d_magic;                /* the magic number */
-       __le32   d_version;              /* version number */
-       char    d_serial[12];           /* serial number of the device */
-       __le32   d_ncylinders;           /* # of data cylinders per device */
-       __le32   d_ntracks;              /* # of tracks per cylinder */
-       __le32   d_nsectors;             /* # of data sectors per track */
-       __le32   d_secsize;              /* # of bytes per sector */
-       __le32   d_part_start;           /* # of first sector of this partition */
-       __le32   d_unknown1[12];         /* ? */
-       __le32  d_alt_tbl;              /* byte offset of alternate table */
-       __le32  d_alt_len;              /* byte length of alternate table */
-       __le32  d_phys_cyl;             /* # of physical cylinders per device */
-       __le32  d_phys_trk;             /* # of physical tracks per cylinder */
-       __le32  d_phys_sec;             /* # of physical sectors per track */
-       __le32  d_phys_bytes;           /* # of physical bytes per sector */
-       __le32  d_unknown2;             /* ? */
-       __le32   d_unknown3;             /* ? */
-       __le32  d_pad[8];               /* pad */
-
-       struct unixware_vtoc {
-               __le32  v_magic;                /* the magic number */
-               __le32  v_version;              /* version number */
-               char    v_name[8];              /* volume name */
-               __le16  v_nslices;              /* # of slices */
-               __le16  v_unknown1;             /* ? */
-               __le32  v_reserved[10];         /* reserved */
-               struct unixware_slice
-                       v_slice[UNIXWARE_NUMSLICE];     /* slice headers */
-       } vtoc;
-
-};  /* 408 */
-
-#endif /* CONFIG_UNIXWARE_DISKLABEL */
-
-#ifdef CONFIG_MINIX_SUBPARTITION
-#   define MINIX_NR_SUBPARTITIONS  4
-#endif /* CONFIG_MINIX_SUBPARTITION */
-
-#define ADDPART_FLAG_NONE      0
-#define ADDPART_FLAG_RAID      1
-#define ADDPART_FLAG_WHOLEDISK 2
-
-extern int blk_alloc_devt(struct hd_struct *part, dev_t *devt);
-extern void blk_free_devt(dev_t devt);
-extern void blk_invalidate_devt(dev_t devt);
 extern dev_t blk_lookup_devt(const char *name, int partno);
-extern char *disk_name (struct gendisk *hd, int partno, char *buf);
 
 int bdev_disk_changed(struct block_device *bdev, bool invalidate);
 int blk_add_partitions(struct gendisk *disk, struct block_device *bdev);
 int blk_drop_partitions(struct gendisk *disk, struct block_device *bdev);
-extern int disk_expand_part_tbl(struct gendisk *disk, int target);
-extern struct hd_struct * __must_check add_partition(struct gendisk *disk,
-                                                    int partno, sector_t start,
-                                                    sector_t len, int flags,
-                                                    struct partition_meta_info
-                                                      *info);
-extern void __delete_partition(struct percpu_ref *);
-extern void delete_partition(struct gendisk *, int);
 extern void printk_all_partitions(void);
 
 extern struct gendisk *__alloc_disk_node(int minors, int node_id);
@@ -646,20 +353,6 @@ extern void blk_register_region(dev_t devt, unsigned long range,
                        void *data);
 extern void blk_unregister_region(dev_t devt, unsigned long range);
 
-extern ssize_t part_size_show(struct device *dev,
-                             struct device_attribute *attr, char *buf);
-extern ssize_t part_stat_show(struct device *dev,
-                             struct device_attribute *attr, char *buf);
-extern ssize_t part_inflight_show(struct device *dev,
-                             struct device_attribute *attr, char *buf);
-#ifdef CONFIG_FAIL_MAKE_REQUEST
-extern ssize_t part_fail_show(struct device *dev,
-                             struct device_attribute *attr, char *buf);
-extern ssize_t part_fail_store(struct device *dev,
-                              struct device_attribute *attr,
-                              const char *buf, size_t count);
-#endif /* CONFIG_FAIL_MAKE_REQUEST */
-
 #define alloc_disk_node(minors, node_id)                               \
 ({                                                                     \
        static struct lock_class_key __key;                             \
@@ -678,100 +371,6 @@ extern ssize_t part_fail_store(struct device *dev,
 
 #define alloc_disk(minors) alloc_disk_node(minors, NUMA_NO_NODE)
 
-static inline int hd_ref_init(struct hd_struct *part)
-{
-       if (percpu_ref_init(&part->ref, __delete_partition, 0,
-                               GFP_KERNEL))
-               return -ENOMEM;
-       return 0;
-}
-
-static inline void hd_struct_get(struct hd_struct *part)
-{
-       percpu_ref_get(&part->ref);
-}
-
-static inline int hd_struct_try_get(struct hd_struct *part)
-{
-       return percpu_ref_tryget_live(&part->ref);
-}
-
-static inline void hd_struct_put(struct hd_struct *part)
-{
-       percpu_ref_put(&part->ref);
-}
-
-static inline void hd_struct_kill(struct hd_struct *part)
-{
-       percpu_ref_kill(&part->ref);
-}
-
-static inline void hd_free_part(struct hd_struct *part)
-{
-       free_part_stats(part);
-       free_part_info(part);
-       percpu_ref_exit(&part->ref);
-}
-
-/*
- * Any access of part->nr_sects which is not protected by partition
- * bd_mutex or gendisk bdev bd_mutex, should be done using this
- * accessor function.
- *
- * Code written along the lines of i_size_read() and i_size_write().
- * CONFIG_PREEMPTION case optimizes the case of UP kernel with preemption
- * on.
- */
-static inline sector_t part_nr_sects_read(struct hd_struct *part)
-{
-#if BITS_PER_LONG==32 && defined(CONFIG_SMP)
-       sector_t nr_sects;
-       unsigned seq;
-       do {
-               seq = read_seqcount_begin(&part->nr_sects_seq);
-               nr_sects = part->nr_sects;
-       } while (read_seqcount_retry(&part->nr_sects_seq, seq));
-       return nr_sects;
-#elif BITS_PER_LONG==32 && defined(CONFIG_PREEMPTION)
-       sector_t nr_sects;
-
-       preempt_disable();
-       nr_sects = part->nr_sects;
-       preempt_enable();
-       return nr_sects;
-#else
-       return part->nr_sects;
-#endif
-}
-
-/*
- * Should be called with mutex lock held (typically bd_mutex) of partition
- * to provide mutual exlusion among writers otherwise seqcount might be
- * left in wrong state leaving the readers spinning infinitely.
- */
-static inline void part_nr_sects_write(struct hd_struct *part, sector_t size)
-{
-#if BITS_PER_LONG==32 && defined(CONFIG_SMP)
-       write_seqcount_begin(&part->nr_sects_seq);
-       part->nr_sects = size;
-       write_seqcount_end(&part->nr_sects_seq);
-#elif BITS_PER_LONG==32 && defined(CONFIG_PREEMPTION)
-       preempt_disable();
-       part->nr_sects = size;
-       preempt_enable();
-#else
-       part->nr_sects = size;
-#endif
-}
-
-#if defined(CONFIG_BLK_DEV_INTEGRITY)
-extern void blk_integrity_add(struct gendisk *);
-extern void blk_integrity_del(struct gendisk *);
-#else  /* CONFIG_BLK_DEV_INTEGRITY */
-static inline void blk_integrity_add(struct gendisk *disk) { }
-static inline void blk_integrity_del(struct gendisk *disk) { }
-#endif /* CONFIG_BLK_DEV_INTEGRITY */
-
 #else /* CONFIG_BLOCK */
 
 static inline void printk_all_partitions(void) { }
index 837058b..b336622 100644 (file)
@@ -16,7 +16,7 @@
  * The io_mapping mechanism provides an abstraction for mapping
  * individual pages from an io device to the CPU in an efficient fashion.
  *
- * See Documentation/io-mapping.txt
+ * See Documentation/driver-api/io-mapping.rst
  */
 
 struct io_mapping {
index dba15ca..1dcd919 100644 (file)
@@ -8,6 +8,7 @@
 
 enum {
        ICQ_EXITED              = 1 << 2,
+       ICQ_DESTROYED           = 1 << 3,
 };
 
 /*
index 2ca9b70..cffa471 100644 (file)
@@ -57,8 +57,6 @@
 #define VPRINTK(fmt, args...)
 #endif /* ATA_DEBUG */
 
-#define BPRINTK(fmt, args...) if (ap->flags & ATA_FLAG_DEBUGMSG) printk(KERN_ERR "%s: " fmt, __func__, ## args)
-
 #define ata_print_version_once(dev, version)                   \
 ({                                                             \
        static bool __print_once;                               \
@@ -176,6 +174,7 @@ enum {
        ATA_DEV_NONE            = 11,   /* no device */
 
        /* struct ata_link flags */
+       /* NOTE: struct ata_force_param currently stores lflags in u16 */
        ATA_LFLAG_NO_HRST       = (1 << 1), /* avoid hardreset */
        ATA_LFLAG_NO_SRST       = (1 << 2), /* avoid softreset */
        ATA_LFLAG_ASSUME_ATA    = (1 << 3), /* assume ATA class */
@@ -531,12 +530,14 @@ typedef int (*ata_reset_fn_t)(struct ata_link *link, unsigned int *classes,
                              unsigned long deadline);
 typedef void (*ata_postreset_fn_t)(struct ata_link *link, unsigned int *classes);
 
-extern struct device_attribute dev_attr_link_power_management_policy;
 extern struct device_attribute dev_attr_unload_heads;
+#ifdef CONFIG_SATA_HOST
+extern struct device_attribute dev_attr_link_power_management_policy;
 extern struct device_attribute dev_attr_ncq_prio_enable;
 extern struct device_attribute dev_attr_em_message_type;
 extern struct device_attribute dev_attr_em_message;
 extern struct device_attribute dev_attr_sw_activity;
+#endif
 
 enum sw_activity {
        OFF,
@@ -1020,10 +1021,6 @@ struct ata_timing {
 /*
  * Core layer - drivers/ata/libata-core.c
  */
-extern const unsigned long sata_deb_timing_normal[];
-extern const unsigned long sata_deb_timing_hotplug[];
-extern const unsigned long sata_deb_timing_long[];
-
 extern struct ata_port_operations ata_dummy_port_ops;
 extern const struct ata_port_info ata_dummy_port_info;
 
@@ -1061,33 +1058,14 @@ static inline int is_multi_taskfile(struct ata_taskfile *tf)
               (tf->command == ATA_CMD_WRITE_MULTI_FUA_EXT);
 }
 
-static inline const unsigned long *
-sata_ehc_deb_timing(struct ata_eh_context *ehc)
-{
-       if (ehc->i.flags & ATA_EHI_HOTPLUGGED)
-               return sata_deb_timing_hotplug;
-       else
-               return sata_deb_timing_normal;
-}
-
 static inline int ata_port_is_dummy(struct ata_port *ap)
 {
        return ap->ops == &ata_dummy_port_ops;
 }
 
-extern int sata_set_spd(struct ata_link *link);
 extern int ata_std_prereset(struct ata_link *link, unsigned long deadline);
 extern int ata_wait_after_reset(struct ata_link *link, unsigned long deadline,
                                int (*check_ready)(struct ata_link *link));
-extern int sata_link_debounce(struct ata_link *link,
-                       const unsigned long *params, unsigned long deadline);
-extern int sata_link_resume(struct ata_link *link, const unsigned long *params,
-                           unsigned long deadline);
-extern int sata_link_scr_lpm(struct ata_link *link, enum ata_lpm_policy policy,
-                            bool spm_wakeup);
-extern int sata_link_hardreset(struct ata_link *link,
-                       const unsigned long *timing, unsigned long deadline,
-                       bool *online, int (*check_ready)(struct ata_link *));
 extern int sata_std_hardreset(struct ata_link *link, unsigned int *class,
                              unsigned long deadline);
 extern void ata_std_postreset(struct ata_link *link, unsigned int *classes);
@@ -1095,7 +1073,6 @@ extern void ata_std_postreset(struct ata_link *link, unsigned int *classes);
 extern struct ata_host *ata_host_alloc(struct device *dev, int max_ports);
 extern struct ata_host *ata_host_alloc_pinfo(struct device *dev,
                        const struct ata_port_info * const * ppi, int n_ports);
-extern int ata_slave_link_init(struct ata_port *ap);
 extern void ata_host_get(struct ata_host *host);
 extern void ata_host_put(struct ata_host *host);
 extern int ata_host_start(struct ata_host *host);
@@ -1117,22 +1094,6 @@ extern int ata_scsi_ioctl(struct scsi_device *dev, unsigned int cmd,
 extern int ata_scsi_queuecmd(struct Scsi_Host *h, struct scsi_cmnd *cmd);
 extern int ata_sas_scsi_ioctl(struct ata_port *ap, struct scsi_device *dev,
                            unsigned int cmd, void __user *arg);
-extern void ata_sas_port_destroy(struct ata_port *);
-extern struct ata_port *ata_sas_port_alloc(struct ata_host *,
-                                          struct ata_port_info *, struct Scsi_Host *);
-extern void ata_sas_async_probe(struct ata_port *ap);
-extern int ata_sas_sync_probe(struct ata_port *ap);
-extern int ata_sas_port_init(struct ata_port *);
-extern int ata_sas_port_start(struct ata_port *ap);
-extern int ata_sas_tport_add(struct device *parent, struct ata_port *ap);
-extern void ata_sas_tport_delete(struct ata_port *ap);
-extern void ata_sas_port_stop(struct ata_port *ap);
-extern int ata_sas_slave_configure(struct scsi_device *, struct ata_port *);
-extern int ata_sas_queuecmd(struct scsi_cmnd *cmd, struct ata_port *ap);
-extern int sata_scr_valid(struct ata_link *link);
-extern int sata_scr_read(struct ata_link *link, int reg, u32 *val);
-extern int sata_scr_write(struct ata_link *link, int reg, u32 val);
-extern int sata_scr_write_flush(struct ata_link *link, int reg, u32 val);
 extern bool ata_link_online(struct ata_link *link);
 extern bool ata_link_offline(struct ata_link *link);
 #ifdef CONFIG_PM
@@ -1153,9 +1114,6 @@ extern void ata_msleep(struct ata_port *ap, unsigned int msecs);
 extern u32 ata_wait_register(struct ata_port *ap, void __iomem *reg, u32 mask,
                        u32 val, unsigned long interval, unsigned long timeout);
 extern int atapi_cmd_type(u8 opcode);
-extern void ata_tf_to_fis(const struct ata_taskfile *tf,
-                         u8 pmp, int is_cmd, u8 *fis);
-extern void ata_tf_from_fis(const u8 *fis, struct ata_taskfile *tf);
 extern unsigned long ata_pack_xfermask(unsigned long pio_mask,
                        unsigned long mwdma_mask, unsigned long udma_mask);
 extern void ata_unpack_xfermask(unsigned long xfer_mask,
@@ -1179,7 +1137,6 @@ extern void ata_id_c_string(const u16 *id, unsigned char *s,
 extern unsigned int ata_do_dev_read_id(struct ata_device *dev,
                                        struct ata_taskfile *tf, u16 *id);
 extern void ata_qc_complete(struct ata_queued_cmd *qc);
-extern int ata_qc_complete_multiple(struct ata_port *ap, u64 qc_active);
 extern u64 ata_qc_get_active(struct ata_port *ap);
 extern void ata_scsi_simulate(struct ata_device *dev, struct scsi_cmnd *cmd);
 extern int ata_std_bios_param(struct scsi_device *sdev,
@@ -1196,7 +1153,96 @@ extern struct ata_device *ata_dev_pair(struct ata_device *adev);
 extern int ata_do_set_mode(struct ata_link *link, struct ata_device **r_failed_dev);
 extern void ata_scsi_port_error_handler(struct Scsi_Host *host, struct ata_port *ap);
 extern void ata_scsi_cmd_error_handler(struct Scsi_Host *host, struct ata_port *ap, struct list_head *eh_q);
+
+/*
+ * SATA specific code - drivers/ata/libata-sata.c
+ */
+#ifdef CONFIG_SATA_HOST
+extern const unsigned long sata_deb_timing_normal[];
+extern const unsigned long sata_deb_timing_hotplug[];
+extern const unsigned long sata_deb_timing_long[];
+
+static inline const unsigned long *
+sata_ehc_deb_timing(struct ata_eh_context *ehc)
+{
+       if (ehc->i.flags & ATA_EHI_HOTPLUGGED)
+               return sata_deb_timing_hotplug;
+       else
+               return sata_deb_timing_normal;
+}
+
+extern int sata_scr_valid(struct ata_link *link);
+extern int sata_scr_read(struct ata_link *link, int reg, u32 *val);
+extern int sata_scr_write(struct ata_link *link, int reg, u32 val);
+extern int sata_scr_write_flush(struct ata_link *link, int reg, u32 val);
+extern int sata_set_spd(struct ata_link *link);
+extern int sata_link_hardreset(struct ata_link *link,
+                       const unsigned long *timing, unsigned long deadline,
+                       bool *online, int (*check_ready)(struct ata_link *));
+extern int sata_link_resume(struct ata_link *link, const unsigned long *params,
+                           unsigned long deadline);
+extern void ata_eh_analyze_ncq_error(struct ata_link *link);
+#else
+static inline const unsigned long *
+sata_ehc_deb_timing(struct ata_eh_context *ehc)
+{
+       return NULL;
+}
+static inline int sata_scr_valid(struct ata_link *link) { return 0; }
+static inline int sata_scr_read(struct ata_link *link, int reg, u32 *val)
+{
+       return -EOPNOTSUPP;
+}
+static inline int sata_scr_write(struct ata_link *link, int reg, u32 val)
+{
+       return -EOPNOTSUPP;
+}
+static inline int sata_scr_write_flush(struct ata_link *link, int reg, u32 val)
+{
+       return -EOPNOTSUPP;
+}
+static inline int sata_set_spd(struct ata_link *link) { return -EOPNOTSUPP; }
+static inline int sata_link_hardreset(struct ata_link *link,
+                                     const unsigned long *timing,
+                                     unsigned long deadline,
+                                     bool *online,
+                                     int (*check_ready)(struct ata_link *))
+{
+       if (online)
+               *online = false;
+       return -EOPNOTSUPP;
+}
+static inline int sata_link_resume(struct ata_link *link,
+                                  const unsigned long *params,
+                                  unsigned long deadline)
+{
+       return -EOPNOTSUPP;
+}
+static inline void ata_eh_analyze_ncq_error(struct ata_link *link) { }
+#endif
+extern int sata_link_debounce(struct ata_link *link,
+                       const unsigned long *params, unsigned long deadline);
+extern int sata_link_scr_lpm(struct ata_link *link, enum ata_lpm_policy policy,
+                            bool spm_wakeup);
+extern int ata_slave_link_init(struct ata_port *ap);
+extern void ata_sas_port_destroy(struct ata_port *);
+extern struct ata_port *ata_sas_port_alloc(struct ata_host *,
+                                          struct ata_port_info *, struct Scsi_Host *);
+extern void ata_sas_async_probe(struct ata_port *ap);
+extern int ata_sas_sync_probe(struct ata_port *ap);
+extern int ata_sas_port_init(struct ata_port *);
+extern int ata_sas_port_start(struct ata_port *ap);
+extern int ata_sas_tport_add(struct device *parent, struct ata_port *ap);
+extern void ata_sas_tport_delete(struct ata_port *ap);
+extern void ata_sas_port_stop(struct ata_port *ap);
+extern int ata_sas_slave_configure(struct scsi_device *, struct ata_port *);
+extern int ata_sas_queuecmd(struct scsi_cmnd *cmd, struct ata_port *ap);
+extern void ata_tf_to_fis(const struct ata_taskfile *tf,
+                         u8 pmp, int is_cmd, u8 *fis);
+extern void ata_tf_from_fis(const u8 *fis, struct ata_taskfile *tf);
+extern int ata_qc_complete_multiple(struct ata_port *ap, u64 qc_active);
 extern bool sata_lpm_ignore_phy_events(struct ata_link *link);
+extern int sata_async_notification(struct ata_port *ap);
 
 extern int ata_cable_40wire(struct ata_port *ap);
 extern int ata_cable_80wire(struct ata_port *ap);
@@ -1206,12 +1252,6 @@ extern int ata_cable_unknown(struct ata_port *ap);
 
 /* Timing helpers */
 extern unsigned int ata_pio_need_iordy(const struct ata_device *);
-extern const struct ata_timing *ata_timing_find_mode(u8 xfer_mode);
-extern int ata_timing_compute(struct ata_device *, unsigned short,
-                             struct ata_timing *, int, int);
-extern void ata_timing_merge(const struct ata_timing *,
-                            const struct ata_timing *, struct ata_timing *,
-                            unsigned int);
 extern u8 ata_timing_cycle2mode(unsigned int xfer_shift, int cycle);
 
 /* PCI */
@@ -1295,14 +1335,12 @@ extern void ata_port_wait_eh(struct ata_port *ap);
 extern int ata_link_abort(struct ata_link *link);
 extern int ata_port_abort(struct ata_port *ap);
 extern int ata_port_freeze(struct ata_port *ap);
-extern int sata_async_notification(struct ata_port *ap);
 
 extern void ata_eh_freeze_port(struct ata_port *ap);
 extern void ata_eh_thaw_port(struct ata_port *ap);
 
 extern void ata_eh_qc_complete(struct ata_queued_cmd *qc);
 extern void ata_eh_qc_retry(struct ata_queued_cmd *qc);
-extern void ata_eh_analyze_ncq_error(struct ata_link *link);
 
 extern void ata_do_eh(struct ata_port *ap, ata_prereset_fn_t prereset,
                      ata_reset_fn_t softreset, ata_reset_fn_t hardreset,
@@ -1343,7 +1381,7 @@ extern struct device_attribute *ata_common_sdev_attrs[];
  * edge driver's module reference, otherwise the driver can be unloaded
  * even if the scsi_device is being accessed.
  */
-#define ATA_BASE_SHT(drv_name)                                 \
+#define __ATA_BASE_SHT(drv_name)                               \
        .module                 = THIS_MODULE,                  \
        .name                   = drv_name,                     \
        .ioctl                  = ata_scsi_ioctl,               \
@@ -1357,12 +1395,20 @@ extern struct device_attribute *ata_common_sdev_attrs[];
        .slave_configure        = ata_scsi_slave_config,        \
        .slave_destroy          = ata_scsi_slave_destroy,       \
        .bios_param             = ata_std_bios_param,           \
-       .unlock_native_capacity = ata_scsi_unlock_native_capacity, \
+       .unlock_native_capacity = ata_scsi_unlock_native_capacity
+
+#define ATA_BASE_SHT(drv_name)                                 \
+       __ATA_BASE_SHT(drv_name),                               \
        .sdev_attrs             = ata_common_sdev_attrs
 
+#ifdef CONFIG_SATA_HOST
+extern struct device_attribute *ata_ncq_sdev_attrs[];
+
 #define ATA_NCQ_SHT(drv_name)                                  \
-       ATA_BASE_SHT(drv_name),                                 \
+       __ATA_BASE_SHT(drv_name),                               \
+       .sdev_attrs             = ata_ncq_sdev_attrs,           \
        .change_queue_depth     = ata_scsi_change_queue_depth
+#endif
 
 /*
  * PMP helpers
@@ -1635,6 +1681,8 @@ extern struct ata_device *ata_dev_next(struct ata_device *dev,
  */
 static inline int ata_ncq_enabled(struct ata_device *dev)
 {
+       if (!IS_ENABLED(CONFIG_SATA_HOST))
+               return 0;
        return (dev->flags & (ATA_DFLAG_PIO | ATA_DFLAG_NCQ_OFF |
                              ATA_DFLAG_NCQ)) == ATA_DFLAG_NCQ;
 }
@@ -1804,6 +1852,16 @@ static inline int ata_dma_enabled(struct ata_device *adev)
 }
 
 /**************************************************************************
+ * PATA timings - drivers/ata/libata-pata-timings.c
+ */
+extern const struct ata_timing *ata_timing_find_mode(u8 xfer_mode);
+extern int ata_timing_compute(struct ata_device *, unsigned short,
+                             struct ata_timing *, int, int);
+extern void ata_timing_merge(const struct ata_timing *,
+                            const struct ata_timing *, struct ata_timing *,
+                            unsigned int);
+
+/**************************************************************************
  * PMP - drivers/ata/libata-pmp.c
  */
 #ifdef CONFIG_SATA_PMP
diff --git a/include/linux/msdos_partition.h b/include/linux/msdos_partition.h
new file mode 100644 (file)
index 0000000..2cb82db
--- /dev/null
@@ -0,0 +1,50 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _LINUX_MSDOS_PARTITION_H
+#define _LINUX_MSDOS_PARTITION_H
+
+#define MSDOS_LABEL_MAGIC              0xAA55
+
+struct msdos_partition {
+       u8 boot_ind;            /* 0x80 - active */
+       u8 head;                /* starting head */
+       u8 sector;              /* starting sector */
+       u8 cyl;                 /* starting cylinder */
+       u8 sys_ind;             /* What partition type */
+       u8 end_head;            /* end head */
+       u8 end_sector;          /* end sector */
+       u8 end_cyl;             /* end cylinder */
+       __le32 start_sect;      /* starting sector counting from 0 */
+       __le32 nr_sects;        /* nr of sectors in partition */
+} __packed;
+
+enum msdos_sys_ind {
+       /*
+        * These three have identical behaviour; use the second one if DOS FDISK
+        * gets confused about extended/logical partitions starting past
+        * cylinder 1023.
+        */
+       DOS_EXTENDED_PARTITION = 5,
+       LINUX_EXTENDED_PARTITION = 0x85,
+       WIN98_EXTENDED_PARTITION = 0x0f,
+
+       LINUX_DATA_PARTITION = 0x83,
+       LINUX_LVM_PARTITION = 0x8e,
+       LINUX_RAID_PARTITION = 0xfd,    /* autodetect RAID partition */
+
+       SOLARIS_X86_PARTITION = 0x82,   /* also Linux swap partitions */
+       NEW_SOLARIS_X86_PARTITION = 0xbf,
+
+       DM6_AUX1PARTITION = 0x51,       /* no DDO:  use xlated geom */
+       DM6_AUX3PARTITION = 0x53,       /* no DDO:  use xlated geom */
+       DM6_PARTITION = 0x54,           /* has DDO: use xlated geom & offset */
+       EZD_PARTITION = 0x55,           /* EZ-DRIVE */
+
+       FREEBSD_PARTITION = 0xa5,       /* FreeBSD Partition ID */
+       OPENBSD_PARTITION = 0xa6,       /* OpenBSD Partition ID */
+       NETBSD_PARTITION = 0xa9,        /* NetBSD Partition ID */
+       BSDI_PARTITION = 0xb7,          /* BSDI Partition ID */
+       MINIX_PARTITION = 0x81,         /* Minix Partition ID */
+       UNIXWARE_PARTITION = 0x63,      /* Same as GNU_HURD and SCO Unix */
+};
+
+#endif /* LINUX_MSDOS_PARTITION_H */
diff --git a/include/linux/part_stat.h b/include/linux/part_stat.h
new file mode 100644 (file)
index 0000000..ece6076
--- /dev/null
@@ -0,0 +1,115 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _LINUX_PART_STAT_H
+#define _LINUX_PART_STAT_H
+
+#include <linux/genhd.h>
+
+/*
+ * Macros to operate on percpu disk statistics:
+ *
+ * {disk|part|all}_stat_{add|sub|inc|dec}() modify the stat counters
+ * and should be called between disk_stat_lock() and
+ * disk_stat_unlock().
+ *
+ * part_stat_read() can be called at any time.
+ *
+ * part_stat_{add|set_all}() and {init|free}_part_stats are for
+ * internal use only.
+ */
+#ifdef CONFIG_SMP
+#define part_stat_lock()       ({ rcu_read_lock(); get_cpu(); })
+#define part_stat_unlock()     do { put_cpu(); rcu_read_unlock(); } while (0)
+
+#define part_stat_get_cpu(part, field, cpu)                            \
+       (per_cpu_ptr((part)->dkstats, (cpu))->field)
+
+#define part_stat_get(part, field)                                     \
+       part_stat_get_cpu(part, field, smp_processor_id())
+
+#define part_stat_read(part, field)                                    \
+({                                                                     \
+       typeof((part)->dkstats->field) res = 0;                         \
+       unsigned int _cpu;                                              \
+       for_each_possible_cpu(_cpu)                                     \
+               res += per_cpu_ptr((part)->dkstats, _cpu)->field;       \
+       res;                                                            \
+})
+
+static inline void part_stat_set_all(struct hd_struct *part, int value)
+{
+       int i;
+
+       for_each_possible_cpu(i)
+               memset(per_cpu_ptr(part->dkstats, i), value,
+                               sizeof(struct disk_stats));
+}
+
+static inline int init_part_stats(struct hd_struct *part)
+{
+       part->dkstats = alloc_percpu(struct disk_stats);
+       if (!part->dkstats)
+               return 0;
+       return 1;
+}
+
+static inline void free_part_stats(struct hd_struct *part)
+{
+       free_percpu(part->dkstats);
+}
+
+#else /* !CONFIG_SMP */
+#define part_stat_lock()       ({ rcu_read_lock(); 0; })
+#define part_stat_unlock()     rcu_read_unlock()
+
+#define part_stat_get(part, field)             ((part)->dkstats.field)
+#define part_stat_get_cpu(part, field, cpu)    part_stat_get(part, field)
+#define part_stat_read(part, field)            part_stat_get(part, field)
+
+static inline void part_stat_set_all(struct hd_struct *part, int value)
+{
+       memset(&part->dkstats, value, sizeof(struct disk_stats));
+}
+
+static inline int init_part_stats(struct hd_struct *part)
+{
+       return 1;
+}
+
+static inline void free_part_stats(struct hd_struct *part)
+{
+}
+
+#endif /* CONFIG_SMP */
+
+#define part_stat_read_accum(part, field)                              \
+       (part_stat_read(part, field[STAT_READ]) +                       \
+        part_stat_read(part, field[STAT_WRITE]) +                      \
+        part_stat_read(part, field[STAT_DISCARD]))
+
+#define __part_stat_add(part, field, addnd)                            \
+       (part_stat_get(part, field) += (addnd))
+
+#define part_stat_add(part, field, addnd)      do {                    \
+       __part_stat_add((part), field, addnd);                          \
+       if ((part)->partno)                                             \
+               __part_stat_add(&part_to_disk((part))->part0,           \
+                               field, addnd);                          \
+} while (0)
+
+#define part_stat_dec(gendiskp, field)                                 \
+       part_stat_add(gendiskp, field, -1)
+#define part_stat_inc(gendiskp, field)                                 \
+       part_stat_add(gendiskp, field, 1)
+#define part_stat_sub(gendiskp, field, subnd)                          \
+       part_stat_add(gendiskp, field, -subnd)
+
+#define part_stat_local_dec(gendiskp, field)                           \
+       local_dec(&(part_stat_get(gendiskp, field)))
+#define part_stat_local_inc(gendiskp, field)                           \
+       local_inc(&(part_stat_get(gendiskp, field)))
+#define part_stat_local_read(gendiskp, field)                          \
+       local_read(&(part_stat_get(gendiskp, field)))
+#define part_stat_local_read_cpu(gendiskp, field, cpu)                 \
+       local_read(&(part_stat_get_cpu(gendiskp, field, cpu)))
+
+#endif /* _LINUX_PART_STAT_H */
index 352c0d7..977e668 100644 (file)
 
 /* Vendors and devices.  Sort key: vendor first, device next. */
 
+#define PCI_VENDOR_ID_LOONGSON         0x0014
+
 #define PCI_VENDOR_ID_TTTECH           0x0357
 #define PCI_DEVICE_ID_TTTECH_MC322     0x000a
 
diff --git a/include/linux/raid/detect.h b/include/linux/raid/detect.h
new file mode 100644 (file)
index 0000000..37dd3f4
--- /dev/null
@@ -0,0 +1,3 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+
+void md_autodetect_dev(dev_t dev);
index 03583b6..4192369 100644 (file)
@@ -7,7 +7,8 @@
 #define SECCOMP_FILTER_FLAG_MASK       (SECCOMP_FILTER_FLAG_TSYNC | \
                                         SECCOMP_FILTER_FLAG_LOG | \
                                         SECCOMP_FILTER_FLAG_SPEC_ALLOW | \
-                                        SECCOMP_FILTER_FLAG_NEW_LISTENER)
+                                        SECCOMP_FILTER_FLAG_NEW_LISTENER | \
+                                        SECCOMP_FILTER_FLAG_TSYNC_ESRCH)
 
 #ifdef CONFIG_SECCOMP
 
index 15f3412..54338fa 100644 (file)
@@ -391,6 +391,10 @@ extern int recvmsg_copy_msghdr(struct msghdr *msg,
                               struct user_msghdr __user *umsg, unsigned flags,
                               struct sockaddr __user **uaddr,
                               struct iovec **iov);
+extern int __copy_msghdr_from_user(struct msghdr *kmsg,
+                                  struct user_msghdr __user *umsg,
+                                  struct sockaddr __user **save_addr,
+                                  struct iovec __user **uiov, size_t *nsegs);
 
 /* helpers which do the actual work for syscalls */
 extern int __sys_recvfrom(int fd, void __user *ubuf, size_t size,
index 74b4911..ebbbfea 100644 (file)
@@ -78,6 +78,9 @@ extern ssize_t add_to_pipe(struct pipe_inode_info *,
                              struct pipe_buffer *);
 extern ssize_t splice_direct_to_actor(struct file *, struct splice_desc *,
                                      splice_direct_actor *);
+extern long do_splice(struct file *in, loff_t __user *off_in,
+                     struct file *out, loff_t __user *off_out,
+                     size_t len, unsigned int flags);
 
 /*
  * for dynamic pipe sizing
index f277653..e341260 100644 (file)
@@ -38,6 +38,9 @@ struct compat_cmsghdr {
 #define compat_mmsghdr mmsghdr
 #endif /* defined(CONFIG_COMPAT) */
 
+int __get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg,
+                       struct sockaddr __user **save_addr, compat_uptr_t *ptr,
+                       compat_size_t *len);
 int get_compat_msghdr(struct msghdr *, struct compat_msghdr __user *,
                      struct sockaddr __user **, struct iovec **);
 struct sock_fprog __user *get_compat_bpf_fprog(char __user *optval);
index 57c7292..08edd60 100644 (file)
@@ -13,8 +13,7 @@
 
 #ifndef SCSICAM_H
 #define SCSICAM_H
-extern int scsicam_bios_param (struct block_device *bdev, sector_t capacity, int *ip);
-extern int scsi_partsize(unsigned char *buf, unsigned long capacity,
-           unsigned int  *cyls, unsigned int *hds, unsigned int *secs);
-extern unsigned char *scsi_bios_ptable(struct block_device *bdev);
+int scsicam_bios_param(struct block_device *bdev, sector_t capacity, int *ip);
+bool scsi_partsize(struct block_device *bdev, sector_t capacity, int geom[3]);
+unsigned char *scsi_bios_ptable(struct block_device *bdev);
 #endif /* def SCSICAM_H */
index 27bd9e4..9f0d3b7 100644 (file)
@@ -357,6 +357,109 @@ TRACE_EVENT(io_uring_submit_sqe,
                          __entry->force_nonblock, __entry->sq_thread)
 );
 
+TRACE_EVENT(io_uring_poll_arm,
+
+       TP_PROTO(void *ctx, u8 opcode, u64 user_data, int mask, int events),
+
+       TP_ARGS(ctx, opcode, user_data, mask, events),
+
+       TP_STRUCT__entry (
+               __field(  void *,       ctx             )
+               __field(  u8,           opcode          )
+               __field(  u64,          user_data       )
+               __field(  int,          mask            )
+               __field(  int,          events          )
+       ),
+
+       TP_fast_assign(
+               __entry->ctx            = ctx;
+               __entry->opcode         = opcode;
+               __entry->user_data      = user_data;
+               __entry->mask           = mask;
+               __entry->events         = events;
+       ),
+
+       TP_printk("ring %p, op %d, data 0x%llx, mask 0x%x, events 0x%x",
+                         __entry->ctx, __entry->opcode,
+                         (unsigned long long) __entry->user_data,
+                         __entry->mask, __entry->events)
+);
+
+TRACE_EVENT(io_uring_poll_wake,
+
+       TP_PROTO(void *ctx, u8 opcode, u64 user_data, int mask),
+
+       TP_ARGS(ctx, opcode, user_data, mask),
+
+       TP_STRUCT__entry (
+               __field(  void *,       ctx             )
+               __field(  u8,           opcode          )
+               __field(  u64,          user_data       )
+               __field(  int,          mask            )
+       ),
+
+       TP_fast_assign(
+               __entry->ctx            = ctx;
+               __entry->opcode         = opcode;
+               __entry->user_data      = user_data;
+               __entry->mask           = mask;
+       ),
+
+       TP_printk("ring %p, op %d, data 0x%llx, mask 0x%x",
+                         __entry->ctx, __entry->opcode,
+                         (unsigned long long) __entry->user_data,
+                         __entry->mask)
+);
+
+TRACE_EVENT(io_uring_task_add,
+
+       TP_PROTO(void *ctx, u8 opcode, u64 user_data, int mask),
+
+       TP_ARGS(ctx, opcode, user_data, mask),
+
+       TP_STRUCT__entry (
+               __field(  void *,       ctx             )
+               __field(  u8,           opcode          )
+               __field(  u64,          user_data       )
+               __field(  int,          mask            )
+       ),
+
+       TP_fast_assign(
+               __entry->ctx            = ctx;
+               __entry->opcode         = opcode;
+               __entry->user_data      = user_data;
+               __entry->mask           = mask;
+       ),
+
+       TP_printk("ring %p, op %d, data 0x%llx, mask %x",
+                         __entry->ctx, __entry->opcode,
+                         (unsigned long long) __entry->user_data,
+                         __entry->mask)
+);
+
+TRACE_EVENT(io_uring_task_run,
+
+       TP_PROTO(void *ctx, u8 opcode, u64 user_data),
+
+       TP_ARGS(ctx, opcode, user_data),
+
+       TP_STRUCT__entry (
+               __field(  void *,       ctx             )
+               __field(  u8,           opcode          )
+               __field(  u64,          user_data       )
+       ),
+
+       TP_fast_assign(
+               __entry->ctx            = ctx;
+               __entry->opcode         = opcode;
+               __entry->user_data      = user_data;
+       ),
+
+       TP_printk("ring %p, op %d, data 0x%llx",
+                         __entry->ctx, __entry->opcode,
+                         (unsigned long long) __entry->user_data)
+);
+
 #endif /* _TRACE_IO_URING_H */
 
 /* This part must be outside protection */
index 5e2981d..1318881 100644 (file)
@@ -7,26 +7,18 @@
  * Handbook", Sanches and Canton.
  */
 
-#ifdef FDPATCHES
-#define FD_IOPORT fdc_state[fdc].address
-#else
-/* It would be a lot saner just to force fdc_state[fdc].address to always
-   be set ! FIXME */
-#define FD_IOPORT 0x3f0
-#endif
-
 /* Fd controller regs. S&C, about page 340 */
-#define FD_STATUS      (4 + FD_IOPORT )
-#define FD_DATA                (5 + FD_IOPORT )
+#define FD_STATUS      4
+#define FD_DATA                5
 
 /* Digital Output Register */
-#define FD_DOR         (2 + FD_IOPORT )
+#define FD_DOR         2
 
 /* Digital Input Register (read) */
-#define FD_DIR         (7 + FD_IOPORT )
+#define FD_DIR         7
 
 /* Diskette Control Register (write)*/
-#define FD_DCR         (7 + FD_IOPORT )
+#define FD_DCR         7
 
 /* Bits of main status register */
 #define STATUS_BUSYMASK        0x0F            /* drive busy mask */
index 3f7961c..e48d746 100644 (file)
@@ -1,4 +1,4 @@
-/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
+/* SPDX-License-Identifier: (GPL-2.0 WITH Linux-syscall-note) OR MIT */
 /*
  * Header file for the io_uring interface.
  *
@@ -23,7 +23,10 @@ struct io_uring_sqe {
                __u64   off;    /* offset into file */
                __u64   addr2;
        };
-       __u64   addr;           /* pointer to buffer or iovecs */
+       union {
+               __u64   addr;   /* pointer to buffer or iovecs */
+               __u64   splice_off_in;
+       };
        __u32   len;            /* buffer size or number of iovecs */
        union {
                __kernel_rwf_t  rw_flags;
@@ -37,14 +40,21 @@ struct io_uring_sqe {
                __u32           open_flags;
                __u32           statx_flags;
                __u32           fadvise_advice;
+               __u32           splice_flags;
        };
        __u64   user_data;      /* data to be passed back at completion time */
        union {
                struct {
-                       /* index into fixed buffers, if used */
-                       __u16   buf_index;
+                       /* pack this to avoid bogus arm OABI complaints */
+                       union {
+                               /* index into fixed buffers, if used */
+                               __u16   buf_index;
+                               /* for grouped buffer selection */
+                               __u16   buf_group;
+                       } __attribute__((packed));
                        /* personality to use, if used */
                        __u16   personality;
+                       __s32   splice_fd_in;
                };
                __u64   __pad2[3];
        };
@@ -56,6 +66,7 @@ enum {
        IOSQE_IO_LINK_BIT,
        IOSQE_IO_HARDLINK_BIT,
        IOSQE_ASYNC_BIT,
+       IOSQE_BUFFER_SELECT_BIT,
 };
 
 /*
@@ -71,6 +82,8 @@ enum {
 #define IOSQE_IO_HARDLINK      (1U << IOSQE_IO_HARDLINK_BIT)
 /* always go async */
 #define IOSQE_ASYNC            (1U << IOSQE_ASYNC_BIT)
+/* select buffer from sqe->buf_group */
+#define IOSQE_BUFFER_SELECT    (1U << IOSQE_BUFFER_SELECT_BIT)
 
 /*
  * io_uring_setup() flags
@@ -113,6 +126,9 @@ enum {
        IORING_OP_RECV,
        IORING_OP_OPENAT2,
        IORING_OP_EPOLL_CTL,
+       IORING_OP_SPLICE,
+       IORING_OP_PROVIDE_BUFFERS,
+       IORING_OP_REMOVE_BUFFERS,
 
        /* this goes last, obviously */
        IORING_OP_LAST,
@@ -129,6 +145,12 @@ enum {
 #define IORING_TIMEOUT_ABS     (1U << 0)
 
 /*
+ * sqe->splice_flags
+ * extends splice(2) flags
+ */
+#define SPLICE_F_FD_IN_FIXED   (1U << 31) /* the last bit of __u32 */
+
+/*
  * IO completion data structure (Completion Queue Entry)
  */
 struct io_uring_cqe {
@@ -138,6 +160,17 @@ struct io_uring_cqe {
 };
 
 /*
+ * cqe->flags
+ *
+ * IORING_CQE_F_BUFFER If set, the upper 16 bits are the buffer ID
+ */
+#define IORING_CQE_F_BUFFER            (1U << 0)
+
+enum {
+       IORING_CQE_BUFFER_SHIFT         = 16,
+};
+
+/*
  * Magic offsets for the application to mmap the data it needs
  */
 #define IORING_OFF_SQ_RING             0ULL
@@ -204,6 +237,7 @@ struct io_uring_params {
 #define IORING_FEAT_SUBMIT_STABLE      (1U << 2)
 #define IORING_FEAT_RW_CUR_POS         (1U << 3)
 #define IORING_FEAT_CUR_PERSONALITY    (1U << 4)
+#define IORING_FEAT_FAST_POLL          (1U << 5)
 
 /*
  * io_uring_register(2) opcodes and arguments
index be84d87..c173545 100644 (file)
@@ -22,6 +22,7 @@
 #define SECCOMP_FILTER_FLAG_LOG                        (1UL << 1)
 #define SECCOMP_FILTER_FLAG_SPEC_ALLOW         (1UL << 2)
 #define SECCOMP_FILTER_FLAG_NEW_LISTENER       (1UL << 3)
+#define SECCOMP_FILTER_FLAG_TSYNC_ESRCH                (1UL << 4)
 
 /*
  * All BPF programs must return a 32-bit value.
index 0ae9cc2..29d326b 100644 (file)
@@ -429,12 +429,10 @@ void __init mount_block_root(char *name, int flags)
        struct page *page = alloc_page(GFP_KERNEL);
        char *fs_names = page_address(page);
        char *p;
-#ifdef CONFIG_BLOCK
        char b[BDEVNAME_SIZE];
-#else
-       const char *b = name;
-#endif
 
+       scnprintf(b, BDEVNAME_SIZE, "unknown-block(%u,%u)",
+                 MAJOR(ROOT_DEV), MINOR(ROOT_DEV));
        get_fs_names(fs_names);
 retry:
        for (p = fs_names; *p; p += strlen(p)+1) {
@@ -451,9 +449,6 @@ retry:
                 * and bad superblock on root device.
                 * and give them a list of the available devices
                 */
-#ifdef CONFIG_BLOCK
-               __bdevname(ROOT_DEV, b);
-#endif
                printk("VFS: Cannot open root device \"%s\" or %s: error %d\n",
                                root_device_name, b, err);
                printk("Please append a correct \"root=\" boot option; here are the available partitions:\n");
@@ -476,9 +471,6 @@ retry:
        for (p = fs_names; *p; p += strlen(p)+1)
                printk(" %s", p);
        printk("\n");
-#ifdef CONFIG_BLOCK
-       __bdevname(ROOT_DEV, b);
-#endif
        panic("VFS: Unable to mount root fs on %s", b);
 out:
        put_page(page);
index b6ea3dc..ec5c606 100644 (file)
@@ -528,8 +528,12 @@ static long seccomp_attach_filter(unsigned int flags,
                int ret;
 
                ret = seccomp_can_sync_threads();
-               if (ret)
-                       return ret;
+               if (ret) {
+                       if (flags & SECCOMP_FILTER_FLAG_TSYNC_ESRCH)
+                               return -ESRCH;
+                       else
+                               return ret;
+               }
        }
 
        /* Set log flag, if present. */
@@ -1221,6 +1225,7 @@ static const struct file_operations seccomp_notify_ops = {
        .poll = seccomp_notify_poll,
        .release = seccomp_notify_release,
        .unlocked_ioctl = seccomp_notify_ioctl,
+       .compat_ioctl = seccomp_notify_ioctl,
 };
 
 static struct file *init_listener(struct seccomp_filter *filter)
@@ -1288,10 +1293,12 @@ static long seccomp_set_mode_filter(unsigned int flags,
         * In the successful case, NEW_LISTENER returns the new listener fd.
         * But in the failure case, TSYNC returns the thread that died. If you
         * combine these two flags, there's no way to tell whether something
-        * succeeded or failed. So, let's disallow this combination.
+        * succeeded or failed. So, let's disallow this combination if the user
+        * has not explicitly requested no errors from TSYNC.
         */
        if ((flags & SECCOMP_FILTER_FLAG_TSYNC) &&
-           (flags & SECCOMP_FILTER_FLAG_NEW_LISTENER))
+           (flags & SECCOMP_FILTER_FLAG_NEW_LISTENER) &&
+           ((flags & SECCOMP_FILTER_FLAG_TSYNC_ESRCH) == 0))
                return -EINVAL;
 
        /* Prepare the new filter before holding any locks. */
index 0fef395..825f282 100644 (file)
@@ -97,16 +97,26 @@ void task_work_run(void)
                 * work->func() can do task_work_add(), do not set
                 * work_exited unless the list is empty.
                 */
-               raw_spin_lock_irq(&task->pi_lock);
                do {
+                       head = NULL;
                        work = READ_ONCE(task->task_works);
-                       head = !work && (task->flags & PF_EXITING) ?
-                               &work_exited : NULL;
+                       if (!work) {
+                               if (task->flags & PF_EXITING)
+                                       head = &work_exited;
+                               else
+                                       break;
+                       }
                } while (cmpxchg(&task->task_works, work, head) != work);
-               raw_spin_unlock_irq(&task->pi_lock);
 
                if (!work)
                        break;
+               /*
+                * Synchronize with task_work_cancel(). It can not remove
+                * the first entry == work, cmpxchg(task_works) must fail.
+                * But it can remove another entry from the ->next list.
+                */
+               raw_spin_lock_irq(&task->pi_lock);
+               raw_spin_unlock_irq(&task->pi_lock);
 
                do {
                        next = work->next;
index 47d99c7..4bed96e 100644 (file)
 #include <linux/uaccess.h>
 #include <net/compat.h>
 
-int get_compat_msghdr(struct msghdr *kmsg,
-                     struct compat_msghdr __user *umsg,
-                     struct sockaddr __user **save_addr,
-                     struct iovec **iov)
+int __get_compat_msghdr(struct msghdr *kmsg,
+                       struct compat_msghdr __user *umsg,
+                       struct sockaddr __user **save_addr,
+                       compat_uptr_t *ptr, compat_size_t *len)
 {
        struct compat_msghdr msg;
        ssize_t err;
@@ -79,10 +79,26 @@ int get_compat_msghdr(struct msghdr *kmsg,
                return -EMSGSIZE;
 
        kmsg->msg_iocb = NULL;
+       *ptr = msg.msg_iov;
+       *len = msg.msg_iovlen;
+       return 0;
+}
+
+int get_compat_msghdr(struct msghdr *kmsg,
+                     struct compat_msghdr __user *umsg,
+                     struct sockaddr __user **save_addr,
+                     struct iovec **iov)
+{
+       compat_uptr_t ptr;
+       compat_size_t len;
+       ssize_t err;
+
+       err = __get_compat_msghdr(kmsg, umsg, save_addr, &ptr, &len);
+       if (err)
+               return err;
 
-       err = compat_import_iovec(save_addr ? READ : WRITE,
-                                  compat_ptr(msg.msg_iov), msg.msg_iovlen,
-                                  UIO_FASTIOV, iov, &kmsg->msg_iter);
+       err = compat_import_iovec(save_addr ? READ : WRITE, compat_ptr(ptr),
+                                  len, UIO_FASTIOV, iov, &kmsg->msg_iter);
        return err < 0 ? err : 0;
 }
 
index 6490b84..25a8888 100644 (file)
@@ -129,7 +129,7 @@ config IP_PNP_DHCP
 
          If unsure, say Y. Note that if you want to use DHCP, a DHCP server
          must be operating on your network.  Read
-         <file:Documentation/filesystems/nfs/nfsroot.txt> for details.
+         <file:Documentation/admin-guide/nfs/nfsroot.rst> for details.
 
 config IP_PNP_BOOTP
        bool "IP: BOOTP support"
@@ -144,7 +144,7 @@ config IP_PNP_BOOTP
          does BOOTP itself, providing all necessary information on the kernel
          command line, you can say N here. If unsure, say Y. Note that if you
          want to use BOOTP, a BOOTP server must be operating on your network.
-         Read <file:Documentation/filesystems/nfs/nfsroot.txt> for details.
+         Read <file:Documentation/admin-guide/nfs/nfsroot.rst> for details.
 
 config IP_PNP_RARP
        bool "IP: RARP support"
@@ -157,7 +157,7 @@ config IP_PNP_RARP
          older protocol which is being obsoleted by BOOTP and DHCP), say Y
          here. Note that if you want to use RARP, a RARP server must be
          operating on your network. Read
-         <file:Documentation/filesystems/nfs/nfsroot.txt> for details.
+         <file:Documentation/admin-guide/nfs/nfsroot.rst> for details.
 
 config NET_IPIP
        tristate "IP: tunneling"
index 4438f6b..561f15b 100644 (file)
@@ -1621,7 +1621,7 @@ late_initcall(ip_auto_config);
 
 /*
  *  Decode any IP configuration options in the "ip=" or "nfsaddrs=" kernel
- *  command line parameter.  See Documentation/filesystems/nfs/nfsroot.txt.
+ *  command line parameter.  See Documentation/admin-guide/nfs/nfsroot.rst.
  */
 static int __init ic_proto_name(char *name)
 {
index 2eecf15..2dd739f 100644 (file)
@@ -2228,10 +2228,10 @@ struct used_address {
        unsigned int name_len;
 };
 
-static int copy_msghdr_from_user(struct msghdr *kmsg,
-                                struct user_msghdr __user *umsg,
-                                struct sockaddr __user **save_addr,
-                                struct iovec **iov)
+int __copy_msghdr_from_user(struct msghdr *kmsg,
+                           struct user_msghdr __user *umsg,
+                           struct sockaddr __user **save_addr,
+                           struct iovec __user **uiov, size_t *nsegs)
 {
        struct user_msghdr msg;
        ssize_t err;
@@ -2273,6 +2273,23 @@ static int copy_msghdr_from_user(struct msghdr *kmsg,
                return -EMSGSIZE;
 
        kmsg->msg_iocb = NULL;
+       *uiov = msg.msg_iov;
+       *nsegs = msg.msg_iovlen;
+       return 0;
+}
+
+static int copy_msghdr_from_user(struct msghdr *kmsg,
+                                struct user_msghdr __user *umsg,
+                                struct sockaddr __user **save_addr,
+                                struct iovec **iov)
+{
+       struct user_msghdr msg;
+       ssize_t err;
+
+       err = __copy_msghdr_from_user(kmsg, umsg, save_addr, &msg.msg_iov,
+                                       &msg.msg_iovlen);
+       if (err)
+               return err;
 
        err = import_iovec(save_addr ? READ : WRITE,
                            msg.msg_iov, msg.msg_iovlen,
diff --git a/scripts/check-sysctl-docs b/scripts/check-sysctl-docs
new file mode 100755 (executable)
index 0000000..8bcb9e2
--- /dev/null
@@ -0,0 +1,181 @@
+#!/usr/bin/gawk -f
+# SPDX-License-Identifier: GPL-2.0
+
+# Script to check sysctl documentation against source files
+#
+# Copyright (c) 2020 Stephen Kitt
+
+# Example invocation:
+#      scripts/check-sysctl-docs -vtable="kernel" \
+#              Documentation/admin-guide/sysctl/kernel.rst \
+#              $(git grep -l register_sysctl_)
+#
+# Specify -vdebug=1 to see debugging information
+
+BEGIN {
+    if (!table) {
+       print "Please specify the table to look for using the table variable" > "/dev/stderr"
+       exit 1
+    }
+}
+
+# The following globals are used:
+# children: maps ctl_table names and procnames to child ctl_table names
+# documented: maps documented entries (each key is an entry)
+# entries: maps ctl_table names and procnames to counts (so
+#          enumerating the subkeys for a given ctl_table lists its
+#          procnames)
+# files: maps procnames to source file names
+# paths: maps ctl_path names to paths
+# curpath: the name of the current ctl_path struct
+# curtable: the name of the current ctl_table struct
+# curentry: the name of the current proc entry (procname when parsing
+#           a ctl_table, constructed path when parsing a ctl_path)
+
+
+# Remove punctuation from the given value
+function trimpunct(value) {
+    while (value ~ /^["&]/) {
+       value = substr(value, 2)
+    }
+    while (value ~ /[]["&,}]$/) {
+       value = substr(value, 1, length(value) - 1)
+    }
+    return value
+}
+
+# Print the information for the given entry
+function printentry(entry) {
+    seen[entry]++
+    printf "* %s from %s", entry, file[entry]
+    if (documented[entry]) {
+       printf " (documented)"
+    }
+    print ""
+}
+
+
+# Stage 1: build the list of documented entries
+FNR == NR && /^=+$/ {
+    if (prevline ~ /Documentation for/) {
+       # This is the main title
+       next
+    }
+
+    # The previous line is a section title, parse it
+    $0 = prevline
+    if (debug) print "Parsing " $0
+    inbrackets = 0
+    for (i = 1; i <= NF; i++) {
+       if (length($i) == 0) {
+           continue
+       }
+       if (!inbrackets && substr($i, 1, 1) == "(") {
+           inbrackets = 1
+       }
+       if (!inbrackets) {
+           token = trimpunct($i)
+           if (length(token) > 0 && token != "and") {
+               if (debug) print trimpunct($i)
+               documented[trimpunct($i)]++
+           }
+       }
+       if (inbrackets && substr($i, length($i), 1) == ")") {
+           inbrackets = 0
+       }
+    }
+}
+
+FNR == NR {
+    prevline = $0
+    next
+}
+
+
+# Stage 2: process each file and find all sysctl tables
+BEGINFILE {
+    delete children
+    delete entries
+    delete paths
+    curpath = ""
+    curtable = ""
+    curentry = ""
+    if (debug) print "Processing file " FILENAME
+}
+
+/^static struct ctl_path/ {
+    match($0, /static struct ctl_path ([^][]+)/, tables)
+    curpath = tables[1]
+    if (debug) print "Processing path " curpath
+}
+
+/^static struct ctl_table/ {
+    match($0, /static struct ctl_table ([^][]+)/, tables)
+    curtable = tables[1]
+    if (debug) print "Processing table " curtable
+}
+
+/^};$/ {
+    curpath = ""
+    curtable = ""
+    curentry = ""
+}
+
+curpath && /\.procname[\t ]*=[\t ]*".+"/ {
+    match($0, /.procname[\t ]*=[\t ]*"([^"]+)"/, names)
+    if (curentry) {
+       curentry = curentry "/" names[1]
+    } else {
+       curentry = names[1]
+    }
+    if (debug) print "Setting path " curpath " to " curentry
+    paths[curpath] = curentry
+}
+
+curtable && /\.procname[\t ]*=[\t ]*".+"/ {
+    match($0, /.procname[\t ]*=[\t ]*"([^"]+)"/, names)
+    curentry = names[1]
+    if (debug) print "Adding entry " curentry " to table " curtable
+    entries[curtable][curentry]++
+    file[curentry] = FILENAME
+}
+
+/\.child[\t ]*=/ {
+    child = trimpunct($NF)
+    if (debug) print "Linking child " child " to table " curtable " entry " curentry
+    children[curtable][curentry] = child
+}
+
+/register_sysctl_table\(.*\)/ {
+    match($0, /register_sysctl_table\(([^)]+)\)/, tables)
+    if (debug) print "Registering table " tables[1]
+    if (children[tables[1]][table]) {
+       for (entry in entries[children[tables[1]][table]]) {
+           printentry(entry)
+       }
+    }
+}
+
+/register_sysctl_paths\(.*\)/ {
+    match($0, /register_sysctl_paths\(([^)]+), ([^)]+)\)/, tables)
+    if (debug) print "Attaching table " tables[2] " to path " tables[1]
+    if (paths[tables[1]] == table) {
+       for (entry in entries[tables[2]]) {
+           printentry(entry)
+       }
+    }
+    split(paths[tables[1]], components, "/")
+    if (length(components) > 1 && components[1] == table) {
+       # Count the first subdirectory as seen
+       seen[components[2]]++
+    }
+}
+
+
+END {
+    for (entry in documented) {
+       if (!seen[entry]) {
+           print "No implementation for " entry
+       }
+    }
+}
index 7784c54..997202a 100755 (executable)
@@ -51,7 +51,9 @@ open IN, "git grep ':doc:\`' Documentation/|"
      or die "Failed to run git grep";
 while (<IN>) {
        next if (!m,^([^:]+):.*\:doc\:\`([^\`]+)\`,);
+       next if (m,sphinx/,);
 
+       my $file = $1;
        my $d = $1;
        my $doc_ref = $2;
 
@@ -60,7 +62,12 @@ while (<IN>) {
        $d =~ s,(.*/).*,$1,;
        $f =~ s,.*\<([^\>]+)\>,$1,;
 
-       $f ="$d$f.rst";
+       if ($f =~ m,^/,) {
+               $f = "$f.rst";
+               $f =~ s,^/,Documentation/,;
+       } else {
+               $f = "$d$f.rst";
+       }
 
        next if (grep -e, glob("$f"));
 
@@ -69,7 +76,7 @@ while (<IN>) {
        }
        $doc_fix++;
 
-       print STDERR "$f: :doc:`$doc_ref`\n";
+       print STDERR "$file: :doc:`$doc_ref`\n";
 }
 close IN;
 
index e356954..f8ca236 100644 (file)
@@ -23,7 +23,7 @@ menuconfig GCC_PLUGINS
          GCC plugins are loadable modules that provide extra features to the
          compiler. They are useful for runtime instrumentation and static analysis.
 
-         See Documentation/core-api/gcc-plugins.rst for details.
+         See Documentation/kbuild/gcc-plugins.rst for details.
 
 if GCC_PLUGINS
 
index 054405b..d3c237b 100644 (file)
@@ -145,6 +145,13 @@ int main(void)
        DEVID(i2c_device_id);
        DEVID_FIELD(i2c_device_id, name);
 
+       DEVID(i3c_device_id);
+       DEVID_FIELD(i3c_device_id, match_flags);
+       DEVID_FIELD(i3c_device_id, dcr);
+       DEVID_FIELD(i3c_device_id, manuf_id);
+       DEVID_FIELD(i3c_device_id, part_id);
+       DEVID_FIELD(i3c_device_id, extra_info);
+
        DEVID(spi_device_id);
        DEVID_FIELD(spi_device_id, name);
 
index c91eba7..f81cbe0 100644 (file)
@@ -919,6 +919,24 @@ static int do_i2c_entry(const char *filename, void *symval,
        return 1;
 }
 
+static int do_i3c_entry(const char *filename, void *symval,
+                       char *alias)
+{
+       DEF_FIELD(symval, i3c_device_id, match_flags);
+       DEF_FIELD(symval, i3c_device_id, dcr);
+       DEF_FIELD(symval, i3c_device_id, manuf_id);
+       DEF_FIELD(symval, i3c_device_id, part_id);
+       DEF_FIELD(symval, i3c_device_id, extra_info);
+
+       strcpy(alias, "i3c:");
+       ADD(alias, "dcr", match_flags & I3C_MATCH_DCR, dcr);
+       ADD(alias, "manuf", match_flags & I3C_MATCH_MANUF, manuf_id);
+       ADD(alias, "part", match_flags & I3C_MATCH_PART, part_id);
+       ADD(alias, "ext", match_flags & I3C_MATCH_EXTRA_INFO, extra_info);
+
+       return 1;
+}
+
 /* Looks like: spi:S */
 static int do_spi_entry(const char *filename, void *symval,
                        char *alias)
@@ -1386,6 +1404,7 @@ static const struct devtable devtable[] = {
        {"vmbus", SIZE_hv_vmbus_device_id, do_vmbus_entry},
        {"rpmsg", SIZE_rpmsg_device_id, do_rpmsg_entry},
        {"i2c", SIZE_i2c_device_id, do_i2c_entry},
+       {"i3c", SIZE_i3c_device_id, do_i3c_entry},
        {"spi", SIZE_spi_device_id, do_spi_entry},
        {"dmi", SIZE_dmi_system_id, do_dmi_entry},
        {"platform", SIZE_platform_device_id, do_platform_entry},
index a8f0c00..fa3fb05 100755 (executable)
@@ -701,11 +701,26 @@ sub check_needs()
                } else {
                        my $rec_activate = "$virtenv_dir/bin/activate";
                        my $virtualenv = findprog("virtualenv-3");
+                       my $rec_python3 = "";
                        $virtualenv = findprog("virtualenv-3.5") if (!$virtualenv);
                        $virtualenv = findprog("virtualenv") if (!$virtualenv);
                        $virtualenv = "virtualenv" if (!$virtualenv);
 
-                       printf "\t$virtualenv $virtenv_dir\n";
+                       my $rel = "";
+                       if (index($system_release, "Ubuntu") != -1) {
+                               $rel = $1 if ($system_release =~ /Ubuntu\s+(\d+)[.]/);
+                               if ($rel && $rel >= 16) {
+                                       $rec_python3 = " -p python3";
+                               }
+                       }
+                       if (index($system_release, "Debian") != -1) {
+                               $rel = $1 if ($system_release =~ /Debian\s+(\d+)/);
+                               if ($rel && $rel >= 7) {
+                                       $rec_python3 = " -p python3";
+                               }
+                       }
+
+                       printf "\t$virtualenv$rec_python3 $virtenv_dir\n";
                        printf "\t. $rec_activate\n";
                        printf "\tpip install -r $requirement_file\n";
                        deactivate_help();
index 718bf72..e959b3c 100644 (file)
@@ -382,7 +382,7 @@ int key_payload_reserve(struct key *key, size_t datalen)
                spin_lock(&key->user->lock);
 
                if (delta > 0 &&
-                   (key->user->qnbytes + delta >= maxbytes ||
+                   (key->user->qnbytes + delta > maxbytes ||
                     key->user->qnbytes + delta < key->user->qnbytes)) {
                        ret = -EDQUOT;
                }
index 9b898c9..d1a3dea 100644 (file)
@@ -937,8 +937,8 @@ long keyctl_chown_key(key_serial_t id, uid_t user, gid_t group)
                                key_quota_root_maxbytes : key_quota_maxbytes;
 
                        spin_lock(&newowner->lock);
-                       if (newowner->qnkeys + 1 >= maxkeys ||
-                           newowner->qnbytes + key->quotalen >= maxbytes ||
+                       if (newowner->qnkeys + 1 > maxkeys ||
+                           newowner->qnbytes + key->quotalen > maxbytes ||
                            newowner->qnbytes + key->quotalen <
                            newowner->qnbytes)
                                goto quota_overrun;
similarity index 100%
rename from Documentation/EDID/edid.S
rename to tools/edid/edid.S
similarity index 100%
rename from Documentation/EDID/hex
rename to tools/edid/hex
index ee1b727..a9ad3bd 100644 (file)
@@ -212,6 +212,10 @@ struct seccomp_notif_sizes {
 #define SECCOMP_USER_NOTIF_FLAG_CONTINUE 0x00000001
 #endif
 
+#ifndef SECCOMP_FILTER_FLAG_TSYNC_ESRCH
+#define SECCOMP_FILTER_FLAG_TSYNC_ESRCH (1UL << 4)
+#endif
+
 #ifndef seccomp
 int seccomp(unsigned int op, unsigned int flags, void *args)
 {
@@ -2187,7 +2191,8 @@ TEST(detect_seccomp_filter_flags)
        unsigned int flags[] = { SECCOMP_FILTER_FLAG_TSYNC,
                                 SECCOMP_FILTER_FLAG_LOG,
                                 SECCOMP_FILTER_FLAG_SPEC_ALLOW,
-                                SECCOMP_FILTER_FLAG_NEW_LISTENER };
+                                SECCOMP_FILTER_FLAG_NEW_LISTENER,
+                                SECCOMP_FILTER_FLAG_TSYNC_ESRCH };
        unsigned int exclusive[] = {
                                SECCOMP_FILTER_FLAG_TSYNC,
                                SECCOMP_FILTER_FLAG_NEW_LISTENER };
@@ -2645,6 +2650,55 @@ TEST_F(TSYNC, two_siblings_with_one_divergence)
        EXPECT_EQ(SIBLING_EXIT_UNKILLED, (long)status);
 }
 
+TEST_F(TSYNC, two_siblings_with_one_divergence_no_tid_in_err)
+{
+       long ret, flags;
+       void *status;
+
+       ASSERT_EQ(0, prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0)) {
+               TH_LOG("Kernel does not support PR_SET_NO_NEW_PRIVS!");
+       }
+
+       ret = seccomp(SECCOMP_SET_MODE_FILTER, 0, &self->root_prog);
+       ASSERT_NE(ENOSYS, errno) {
+               TH_LOG("Kernel does not support seccomp syscall!");
+       }
+       ASSERT_EQ(0, ret) {
+               TH_LOG("Kernel does not support SECCOMP_SET_MODE_FILTER!");
+       }
+       self->sibling[0].diverge = 1;
+       tsync_start_sibling(&self->sibling[0]);
+       tsync_start_sibling(&self->sibling[1]);
+
+       while (self->sibling_count < TSYNC_SIBLINGS) {
+               sem_wait(&self->started);
+               self->sibling_count++;
+       }
+
+       flags = SECCOMP_FILTER_FLAG_TSYNC | \
+               SECCOMP_FILTER_FLAG_TSYNC_ESRCH;
+       ret = seccomp(SECCOMP_SET_MODE_FILTER, flags, &self->apply_prog);
+       ASSERT_EQ(ESRCH, errno) {
+               TH_LOG("Did not return ESRCH for diverged sibling.");
+       }
+       ASSERT_EQ(-1, ret) {
+               TH_LOG("Did not fail on diverged sibling.");
+       }
+
+       /* Wake the threads */
+       pthread_mutex_lock(&self->mutex);
+       ASSERT_EQ(0, pthread_cond_broadcast(&self->cond)) {
+               TH_LOG("cond broadcast non-zero");
+       }
+       pthread_mutex_unlock(&self->mutex);
+
+       /* Ensure they are both unkilled. */
+       PTHREAD_JOIN(self->sibling[0].tid, &status);
+       EXPECT_EQ(SIBLING_EXIT_UNKILLED, (long)status);
+       PTHREAD_JOIN(self->sibling[1].tid, &status);
+       EXPECT_EQ(SIBLING_EXIT_UNKILLED, (long)status);
+}
+
 TEST_F(TSYNC, two_siblings_not_under_filter)
 {
        long ret, sib;
@@ -3196,6 +3250,24 @@ TEST(user_notification_basic)
        EXPECT_EQ(0, WEXITSTATUS(status));
 }
 
+TEST(user_notification_with_tsync)
+{
+       int ret;
+       unsigned int flags;
+
+       /* these were exclusive */
+       flags = SECCOMP_FILTER_FLAG_NEW_LISTENER |
+               SECCOMP_FILTER_FLAG_TSYNC;
+       ASSERT_EQ(-1, user_trap_syscall(__NR_getppid, flags));
+       ASSERT_EQ(EINVAL, errno);
+
+       /* but now they're not */
+       flags |= SECCOMP_FILTER_FLAG_TSYNC_ESRCH;
+       ret = user_trap_syscall(__NR_getppid, flags);
+       close(ret);
+       ASSERT_LE(0, ret);
+}
+
 TEST(user_notification_kill_in_middle)
 {
        pid_t pid;