1. 09 Oct, 2008 40 commits
    • Tejun Heo's avatar
      init: DEBUG_BLOCK_EXT_DEVT requires explicit root= param · 55dc7db7
      Tejun Heo authored
      DEBUG_BLOCK_EXT_DEVT shuffles SCSI and IDE device numbers and root
      device number set using rdev become meaningless.  Root devices should
      be explicitly specified using textual names.  Warn about it if root
      can't be found and DEBUG_BLOCK_EXT_DEVT is enabled.  Also, add warning
      to the help text.
      Signed-off-by: default avatarTejun Heo <tj@kernel.org>
      Cc: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
      Signed-off-by: default avatarJens Axboe <jens.axboe@oracle.com>
      55dc7db7
    • Tejun Heo's avatar
      block: don't test for partition size in bdget_disk() and blk_lookup_devt() · 2bbedcb4
      Tejun Heo authored
      bdget_disk() and blk_lookup_devt() never cared whether the specified
      partition (or disk) is zero sized or not.  I got confused while
      converting those not to depend on consecutive minor numbers in commit
      5a6411b1178baf534aa9138052864dfa89d3eada and later when dev0 was added
      it broke callers which expected to get valid return for zero sized
      disk devices.
      
      So, they never needed nr_sects checks in the first place.  Kill them.
      
      This problem was spotted and debugged by Bartlmoiej Zolnierkiewicz.
      Signed-off-by: default avatarTejun Heo <tj@kernel.org>
      Cc: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
      Signed-off-by: default avatarJens Axboe <jens.axboe@oracle.com>
      2bbedcb4
    • Jens Axboe's avatar
      Change default value of CONFIG_DEBUG_BLOCK_EXT_DEVT to 'n' · 759f8ca3
      Jens Axboe authored
      It's a debug option that you would explicitly enable to test this
      feature, we should default it to 'n' to prevent accidental surprises
      for now.
      Signed-off-by: default avatarJens Axboe <jens.axboe@oracle.com>
      759f8ca3
    • Harvey Harrison's avatar
      block: kmalloc args reversed, small function definition fixes · aeb3d3a8
      Harvey Harrison authored
      Noticed by sparse:
      block/blk-softirq.c:156:12: warning: symbol 'blk_softirq_init' was not declared. Should it be static?
      block/genhd.c:583:28: warning: function 'bdget_disk' with external linkage has definition
      block/genhd.c:659:17: warning: incorrect type in argument 1 (different base types)
      block/genhd.c:659:17:    expected unsigned int [unsigned] [usertype] size
      block/genhd.c:659:17:    got restricted gfp_t
      block/genhd.c:659:29: warning: incorrect type in argument 2 (different base types)
      block/genhd.c:659:29:    expected restricted gfp_t [usertype] flags
      block/genhd.c:659:29:    got unsigned int
      block: kmalloc args reversed
      Signed-off-by: default avatarHarvey Harrison <harvey.harrison@gmail.com>
      Signed-off-by: default avatarJens Axboe <jens.axboe@oracle.com>
      aeb3d3a8
    • FUJITA Tomonori's avatar
      sg: use blk_rq_aligned helper function · 01cfcddd
      FUJITA Tomonori authored
      Signed-off-by: default avatarFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
      Cc: Douglas Gilbert <dougg@torque.net>
      Cc: Jens Axboe <jens.axboe@oracle.com>
      Signed-off-by: default avatarJens Axboe <jens.axboe@oracle.com>
      01cfcddd
    • FUJITA Tomonori's avatar
      block: add blk_rq_aligned helper function · 87904074
      FUJITA Tomonori authored
      This adds blk_rq_aligned helper function to see if alignment and
      padding requirement is satisfied for DMA transfer. This also converts
      blk_rq_map_kern and __blk_rq_map_user to use the helper function.
      Signed-off-by: default avatarFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
      Cc: Jens Axboe <jens.axboe@oracle.com>
      Signed-off-by: default avatarJens Axboe <jens.axboe@oracle.com>
      87904074
    • FUJITA Tomonori's avatar
      bio: convert bio_copy_kern to use bio_copy_user · 4d8ab62e
      FUJITA Tomonori authored
      bio_copy_kern and bio_copy_user are very similar. This converts
      bio_copy_kern to use bio_copy_user.
      Signed-off-by: default avatarFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
      Cc: Jens Axboe <jens.axboe@oracle.com>
      Signed-off-by: default avatarJens Axboe <jens.axboe@oracle.com>
      4d8ab62e
    • FUJITA Tomonori's avatar
      sg: convert the indirect IO path to use the block layer · 10db10d1
      FUJITA Tomonori authored
      This patch converts the indirect IO path (including mmap IO and old
      struct sg_header) to use the block layer functions (blk_get_request,
      blk_execute_rq_nowait, blk_rq_map_user, etc) instead of
      scsi_execute_async().
      
      [Jens: fixed compile error with SCSI logging enabled]
      Signed-off-by: default avatarFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
      Signed-off-by: default avatarDouglas Gilbert <dougg@torque.net>
      Cc: Mike Christie <michaelc@cs.wisc.edu>
      Cc: James Bottomley <James.Bottomley@HansenPartnership.com>
      Signed-off-by: default avatarJens Axboe <jens.axboe@oracle.com>
      10db10d1
    • FUJITA Tomonori's avatar
      sg: convert the direct IO path to use the block layer · 6e5a30cb
      FUJITA Tomonori authored
      This patch converts the direct IO path (SG_FLAG_DIRECT_IO) to use the
      block layer functions (blk_get_request, blk_execute_rq_nowait,
      blk_rq_map_user, etc) instead of scsi_execute_async().
      Signed-off-by: default avatarFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
      Signed-off-by: default avatarDouglas Gilbert <dougg@torque.net>
      Cc: Mike Christie <michaelc@cs.wisc.edu>
      Cc: James Bottomley <James.Bottomley@HansenPartnership.com>
      Signed-off-by: default avatarJens Axboe <jens.axboe@oracle.com>
      6e5a30cb
    • FUJITA Tomonori's avatar
      sg: convert the non-data path to use the block layer · 10865dfa
      FUJITA Tomonori authored
      This patch converts the non data path to use the block layer functions
      (blk_get_request, blk_execute_rq_nowait, etc) instead of uses
      scsi_execute_async().
      Signed-off-by: default avatarFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
      Signed-off-by: default avatarDouglas Gilbert <dougg@torque.net>
      Cc: Mike Christie <michaelc@cs.wisc.edu>
      Cc: James Bottomley <James.Bottomley@HansenPartnership.com>
      Signed-off-by: default avatarJens Axboe <jens.axboe@oracle.com>
      10865dfa
    • FUJITA Tomonori's avatar
      block: introduce struct rq_map_data to use reserved pages · 152e283f
      FUJITA Tomonori authored
      This patch introduces struct rq_map_data to enable bio_copy_use_iov()
      use reserved pages.
      
      Currently, bio_copy_user_iov allocates bounce pages but
      drivers/scsi/sg.c wants to allocate pages by itself and use
      them. struct rq_map_data can be used to pass allocated pages to
      bio_copy_user_iov.
      
      The current users of bio_copy_user_iov simply passes NULL (they don't
      want to use pre-allocated pages).
      Signed-off-by: default avatarFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
      Cc: Jens Axboe <jens.axboe@oracle.com>
      Cc: Douglas Gilbert <dougg@torque.net>
      Cc: Mike Christie <michaelc@cs.wisc.edu>
      Cc: James Bottomley <James.Bottomley@HansenPartnership.com>
      Signed-off-by: default avatarJens Axboe <jens.axboe@oracle.com>
      152e283f
    • FUJITA Tomonori's avatar
      block: add gfp_mask argument to blk_rq_map_user and blk_rq_map_user_iov · a3bce90e
      FUJITA Tomonori authored
      Currently, blk_rq_map_user and blk_rq_map_user_iov always do
      GFP_KERNEL allocation.
      
      This adds gfp_mask argument to blk_rq_map_user and blk_rq_map_user_iov
      so sg can use it (sg always does GFP_ATOMIC allocation).
      Signed-off-by: default avatarFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
      Signed-off-by: default avatarDouglas Gilbert <dougg@torque.net>
      Cc: Mike Christie <michaelc@cs.wisc.edu>
      Cc: James Bottomley <James.Bottomley@HansenPartnership.com>
      Signed-off-by: default avatarJens Axboe <jens.axboe@oracle.com>
      a3bce90e
    • Aaron Carroll's avatar
      cfq-iosched: fix queue depth detection · 45333d5a
      Aaron Carroll authored
      CFQ's detection of queueing devices assumes a non-queuing device and detects
      if the queue depth reaches a certain threshold.  Under some workloads (e.g.
      synchronous reads), CFQ effectively forces a unit queue depth, thus defeating
      the detection logic.  This leads to poor performance on queuing hardware,
      since the idle window remains enabled.
      
      This patch inverts the sense of the logic: assume a queuing-capable device,
      and detect if the depth does not exceed the threshold.
      Signed-off-by: default avatarAaron Carroll <aaronc@gelato.unsw.edu.au>
      Signed-off-by: default avatarJens Axboe <jens.axboe@oracle.com>
      45333d5a
    • Jens Axboe's avatar
      block: don't use bio_has_data() in the completion path · 60540161
      Jens Axboe authored
      We should just check for rq->bio, as that is really the information
      we are looking for. Even if the bio attached doesn't carry data,
      we still need to do IO post processing on it.
      Signed-off-by: default avatarJens Axboe <jens.axboe@oracle.com>
      60540161
    • Jens Axboe's avatar
      block: inherit CPU completion on bio->rq and rq->rq merges · ab780f1e
      Jens Axboe authored
      Somewhat incomplete, as we do allow merges of requests and bios
      that have different completion CPUs given. This is done on the
      assumption that a larger IO is still more beneficial than CPU
      locality.
      Signed-off-by: default avatarJens Axboe <jens.axboe@oracle.com>
      ab780f1e
    • Jens Axboe's avatar
      block: add support for IO CPU affinity · c7c22e4d
      Jens Axboe authored
      This patch adds support for controlling the IO completion CPU of
      either all requests on a queue, or on a per-request basis. We export
      a sysfs variable (rq_affinity) which, if set, migrates completions
      of requests to the CPU that originally submitted it. A bio helper
      (bio_set_completion_cpu()) is also added, so that queuers can ask
      for completion on that specific CPU.
      
      In testing, this has been show to cut the system time by as much
      as 20-40% on synthetic workloads where CPU affinity is desired.
      
      This requires a little help from the architecture, so it'll only
      work as designed for archs that are using the new generic smp
      helper infrastructure.
      Signed-off-by: default avatarJens Axboe <jens.axboe@oracle.com>
      c7c22e4d
    • Jens Axboe's avatar
      block: make kblockd_schedule_work() take the queue as parameter · 18887ad9
      Jens Axboe authored
      Preparatory patch for checking queuing affinity.
      Signed-off-by: default avatarJens Axboe <jens.axboe@oracle.com>
      18887ad9
    • Jens Axboe's avatar
      b646fc59
    • Jens Axboe's avatar
    • Tejun Heo's avatar
      block: allow disk to have extended device number · 3e1a7ff8
      Tejun Heo authored
      Now that disk and partition handlings are mostly unified, it's easy to
      allow disk to have extended device number.  This patch makes
      add_disk() use extended device number if disk->minors is zero.  Both
      sd and ide-disk are updated to use this.
      
      * sd_format_disk_name() is implemented which can generically determine
        the drive name.  This removes disk number restriction stemming from
        limited device names.
      
      * If sd index goes over SD_MAX_DISKS (which can be increased now BTW),
        sd simply doesn't initialize minors letting block layer choose
        extended device number.
      
      * If CONFIG_DEBUG_EXT_DEVT is set, both sd and ide-disk always set
        minors to 0 and use extended device numbers.
      Signed-off-by: default avatarTejun Heo <tj@kernel.org>
      Signed-off-by: default avatarJens Axboe <jens.axboe@oracle.com>
      3e1a7ff8
    • Tejun Heo's avatar
      block: replace @ext_minors with GENHD_FL_EXT_DEVT · 689d6fac
      Tejun Heo authored
      With previous changes, it's meaningless to limit the number of
      partitions.  Replace @ext_minors with GENHD_FL_EXT_DEVT such that
      setting the flag allows the disk to have maximum number of allowed
      partitions (only limited by the number of entries in parsed_partitions
      as determined by MAX_PART constant).
      
      This kills not-too-pretty alloc_disk_ext[_node]() functions and makes
      @minors parameter to alloc_disk[_node]() unnecessary.  The parameter
      is left alone to avoid disturbing the users.
      Signed-off-by: default avatarTejun Heo <tj@kernel.org>
      Signed-off-by: default avatarJens Axboe <jens.axboe@oracle.com>
      689d6fac
    • Tejun Heo's avatar
      block: make partition array dynamic · 540eed56
      Tejun Heo authored
      disk->__part used to be statically allocated to the maximum possible
      number of partitions.  This patch makes partition array allocation
      dynamic.  The added overhead is minimal as only real change is one
      memory dereference changed to RCU one.  This saves both a bit of
      memory and cpu cycles iterating through unoccupied slots and makes
      increasing partition limit easier.
      Signed-off-by: default avatarTejun Heo <tj@kernel.org>
      Signed-off-by: default avatarJens Axboe <jens.axboe@oracle.com>
      540eed56
    • Tejun Heo's avatar
      block: move stats from disk to part0 · 074a7aca
      Tejun Heo authored
      Move stats related fields - stamp, in_flight, dkstats - from disk to
      part0 and unify stat handling such that...
      
      * part_stat_*() now updates part0 together if the specified partition
        is not part0.  ie. part_stat_*() are now essentially all_stat_*().
      
      * {disk|all}_stat_*() are gone.
      
      * part_round_stats() is updated similary.  It handles part0 stats
        automatically and disk_round_stats() is killed.
      
      * part_{inc|dec}_in_fligh() is implemented which automatically updates
        part0 stats for parts other than part0.
      
      * disk_map_sector_rcu() is updated to return part0 if no part matches.
        Combined with the above changes, this makes NULL special case
        handling in callers unnecessary.
      
      * Separate stats show code paths for disk are collapsed into part
        stats show code paths.
      
      * Rename disk_stat_lock/unlock() to part_stat_lock/unlock()
      
      While at it, reposition stat handling macros a bit and add missing
      parentheses around macro parameters.
      Signed-off-by: default avatarTejun Heo <tj@kernel.org>
      Signed-off-by: default avatarJens Axboe <jens.axboe@oracle.com>
      074a7aca
    • Tejun Heo's avatar
      block: kill GENHD_FL_FAIL and use part0->make_it_fail · eddb2e26
      Tejun Heo authored
      GENHD_FL_FAIL for disk is what make_it_fail is for parts.  Kill it and
      use part0->make_it_fail.  Sysfs node handling is unified too.
      Signed-off-by: default avatarTejun Heo <tj@kernel.org>
      Signed-off-by: default avatarJens Axboe <jens.axboe@oracle.com>
      eddb2e26
    • Tejun Heo's avatar
      block: always set bdev->bd_part · 0762b8bd
      Tejun Heo authored
      Till now, bdev->bd_part is set only if the bdev was for parts other
      than part0.  This patch makes bdev->bd_part always set so that code
      paths don't have to differenciate common handling.
      Signed-off-by: default avatarTejun Heo <tj@kernel.org>
      Signed-off-by: default avatarJens Axboe <jens.axboe@oracle.com>
      0762b8bd
    • Tejun Heo's avatar
      block: move holder_dir from disk to part0 · 4c46501d
      Tejun Heo authored
      Move disk->holder_dir to part0->holder_dir.  Kill now mostly
      superflous bdev_get_holder().
      
      While at it, kill superflous kobject_get/put() around holder_dir,
      slave_dir and cmd_filter creation and collapse
      disk_sysfs_add_subdirs() into register_disk().  These serve no purpose
      but obfuscating the code.
      Signed-off-by: default avatarTejun Heo <tj@kernel.org>
      Signed-off-by: default avatarJens Axboe <jens.axboe@oracle.com>
      4c46501d
    • Tejun Heo's avatar
      block: move policy from disk to part0 · b7db9956
      Tejun Heo authored
      Move disk->policy to part0->policy.  Implement and use get_disk_ro().
      Signed-off-by: default avatarTejun Heo <tj@kernel.org>
      Signed-off-by: default avatarJens Axboe <jens.axboe@oracle.com>
      b7db9956
    • Tejun Heo's avatar
      block: unify sysfs size node handling · e5610521
      Tejun Heo authored
      Now that capacity and __dev are moved to part0, part0 and others can
      share the same method.
      Signed-off-by: default avatarTejun Heo <tj@kernel.org>
      Signed-off-by: default avatarJens Axboe <jens.axboe@oracle.com>
      e5610521
    • Tejun Heo's avatar
      block: move __dev from disk to part0 · 548b10eb
      Tejun Heo authored
      Move disk->__dev to part0->__dev.  This simplifies bdget_disk() and
      lookup_devt() and allows common sysfs attributes to be unified.
      part_to_disk() is updated to handle part0 -> disk.
      
      Updated to include a fix from Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>,
      he writes:
      
      "part0 is a "special" partition and doesn't need to have capacity set - this
      fixes regression caused by "block: move __dev from disk to part0" commit."
      Signed-off-by: default avatarTejun Heo <tj@kernel.org>
      Signed-off-by: default avatarJens Axboe <jens.axboe@oracle.com>
      548b10eb
    • Tejun Heo's avatar
      block: move capacity from disk to part0 · 80795aef
      Tejun Heo authored
      Move disk->capacity to part0->nr_sects and convert all users who
      directly accessed the field to use {get|set}_capacity().  This is done
      early to allow the __dev field to be moved.
      Signed-off-by: default avatarTejun Heo <tj@kernel.org>
      Signed-off-by: default avatarJens Axboe <jens.axboe@oracle.com>
      80795aef
    • Tejun Heo's avatar
      block: introduce partition 0 · b5d0b9df
      Tejun Heo authored
      genhd and partition code handled disk and partitions separately.  All
      information about the whole disk was in struct genhd and partitions in
      struct hd_struct.  However, the whole disk (part0) and other
      partitions have a lot in common and the data structures end up having
      good number of common fields and thus separate code paths doing the
      same thing.  Also, the partition array was indexed by partno - 1 which
      gets pretty confusing at times.
      
      This patch introduces partition 0 and makes the partition array
      indexed by partno.  Following patches will unify the handling of disk
      and parts piece-by-piece.
      
      This patch also implements disk_partitionable() which tests whether a
      disk is partitionable.  With coming dynamic partition array change,
      the most common usage of disk_max_parts() will be testing whether a
      disk is partitionable and the number of max partitions will become
      much less important.
      Signed-off-by: default avatarTejun Heo <tj@kernel.org>
      Signed-off-by: default avatarJens Axboe <jens.axboe@oracle.com>
      b5d0b9df
    • Tejun Heo's avatar
      block: implement and use {disk|part}_to_dev() · ed9e1982
      Tejun Heo authored
      Implement {disk|part}_to_dev() and use them to access generic device
      instead of directly dereferencing {disk|part}->dev.  To make sure no
      user is left behind, rename generic devices fields to __dev.
      
      This is in preparation of unifying partition 0 handling with other
      partitions.
      Signed-off-by: default avatarTejun Heo <tj@kernel.org>
      Signed-off-by: default avatarJens Axboe <jens.axboe@oracle.com>
      ed9e1982
    • Tejun Heo's avatar
      block: implement CONFIG_DEBUG_BLOCK_EXT_DEVT · 870d6656
      Tejun Heo authored
      Extended devt introduces non-contiguos device numbers.  This patch
      implements a debug option which forces most devt allocations to be
      from the extended area and spreads them out.  This is enabled by
      default if DEBUG_KERNEL is set and achieves...
      
      1. Detects code paths in kernel or userland which expect predetermined
         consecutive device numbers.
      
      2. When something goes wrong, avoid corruption as adding to the minor
         of earlier partition won't lead to the wrong but valid device.
      Signed-off-by: default avatarTejun Heo <tj@kernel.org>
      Signed-off-by: default avatarJens Axboe <jens.axboe@oracle.com>
      870d6656
    • Tejun Heo's avatar
      sd/ide-disk: apply extended minors to sd and ide · f615b48c
      Tejun Heo authored
      Update sd and ide-disk such that they can take advantage of extended
      minors.
      
      ide-disk already has 64 minors per device and currently doesn't use
      extended minors although after this patch it can be turned on by
      simply tweaking constants.
      
      sd only had 16 minors per device causing problems on certain peculiar
      configurations.  This patch lifts the restriction and enables it to
      use upto 64 minors.
      Signed-off-by: default avatarTejun Heo <tj@kernel.org>
      Signed-off-by: default avatarJens Axboe <jens.axboe@oracle.com>
      f615b48c
    • Tejun Heo's avatar
      block: adjust formatting for large minors and add ext_range sysfs attr · 1f014290
      Tejun Heo authored
      With extended minors and the soon-to-follow debug feature, large minor
      numbers for block devices will be common.  This patch does the
      followings to make printouts pretty.
      
      * Adapt print formats such that large minors don't break the
        formatting.
      
      * For extended MAJ:MIN, %02x%02x for MAJ:MIN used in
        printk_all_partitions() doesn't cut it anymore.  Update it such that
        %03x:%05x is used if either MAJ or MIN doesn't fit in %02x.
      
      * Implement ext_range sysfs attribute which shows total minors the
        device can use including both conventional minor space and the
        extended one.
      Signed-off-by: default avatarTejun Heo <tj@kernel.org>
      Signed-off-by: default avatarJens Axboe <jens.axboe@oracle.com>
      1f014290
    • Tejun Heo's avatar
      block: implement extended dev numbers · bcce3de1
      Tejun Heo authored
      Implement extended device numbers.  A block driver can tell block
      layer that it wants to use extended device numbers.  After the usual
      minor space is used up, block layer automatically allocates devt's
      from EXT_BLOCK_MAJOR.
      
      Currently only one major number is allocated for this but as the
      allocation is strictly on-demand, ~1mil minor space under it should
      suffice unless the system actually has more than ~1mil partitions and
      if that ever happens adding more majors to the extended devt area is
      easy.
      
      Due to internal implementation issues, the first partition can't be
      allocated on the extended area.  In other words, genhd->minors should
      at least be 1.  This limitation will be lifted by later changes.
      Signed-off-by: default avatarTejun Heo <tj@kernel.org>
      Signed-off-by: default avatarJens Axboe <jens.axboe@oracle.com>
      bcce3de1
    • Tejun Heo's avatar
      block: fix diskstats access · c9959059
      Tejun Heo authored
      There are two variants of stat functions - ones prefixed with double
      underbars which don't care about preemption and ones without which
      disable preemption before manipulating per-cpu counters.  It's unclear
      whether the underbarred ones assume that preemtion is disabled on
      entry as some callers don't do that.
      
      This patch unifies diskstats access by implementing disk_stat_lock()
      and disk_stat_unlock() which take care of both RCU (for partition
      access) and preemption (for per-cpu counter access).  diskstats access
      should always be enclosed between the two functions.  As such, there's
      no need for the versions which disables preemption.  They're removed
      and double underbars ones are renamed to drop the underbars.  As an
      extra argument is added, there's no danger of using the old version
      unconverted.
      
      disk_stat_lock() uses get_cpu() and returns the cpu index and all
      diskstat functions which access per-cpu counters now has @cpu
      argument to help RT.
      
      This change adds RCU or preemption operations at some places but also
      collapses several preemption ops into one at others.  Overall, the
      performance difference should be negligible as all involved ops are
      very lightweight per-cpu ones.
      Signed-off-by: default avatarTejun Heo <tj@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Signed-off-by: default avatarJens Axboe <jens.axboe@oracle.com>
      c9959059
    • Tejun Heo's avatar
      block: fix disk->part[] dereferencing race · e71bf0d0
      Tejun Heo authored
      disk->part[] is protected by its matching bdev's lock.  However,
      non-critical accesses like collecting stats and printing out sysfs and
      proc information used to be performed without any locking.  As
      partitions can come and go dynamically, partitions can go away
      underneath those non-critical accesses.  As some of those accesses are
      writes, this theoretically can lead to silent corruption.
      
      This patch fixes the race by using RCU for the partition array and dev
      reference counter to hold partitions.
      
      * Rename disk->part[] to disk->__part[] to make sure no one outside
        genhd layer proper accesses it directly.
      
      * Use RCU for disk->__part[] dereferencing.
      
      * Implement disk_{get|put}_part() which can be used to get and put
        partitions from gendisk respectively.
      
      * Iterators are implemented to help iterate through all partitions
        safely.
      
      * Functions which require RCU readlock are marked with _rcu suffix.
      
      * Use disk_put_part() in __blkdev_put() instead of directly putting
        the contained kobject.
      Signed-off-by: default avatarTejun Heo <tj@kernel.org>
      Signed-off-by: default avatarJens Axboe <jens.axboe@oracle.com>
      e71bf0d0
    • Tejun Heo's avatar
      block: don't depend on consecutive minor space · f331c029
      Tejun Heo authored
      * Implement disk_devt() and part_devt() and use them to directly
        access devt instead of computing it from ->major and ->first_minor.
      
        Note that all references to ->major and ->first_minor outside of
        block layer is used to determine devt of the disk (the part0) and as
        ->major and ->first_minor will continue to represent devt for the
        disk, converting these users aren't strictly necessary.  However,
        convert them for consistency.
      
      * Implement disk_max_parts() to avoid directly deferencing
        genhd->minors.
      
      * Update bdget_disk() such that it doesn't assume consecutive minor
        space.
      
      * Move devt computation from register_disk() to add_disk() and make it
        the only one (all other usages use the initially determined value).
      
      These changes clean up the code and will help disk->part dereference
      fix and extended block device numbers.
      Signed-off-by: default avatarTejun Heo <tj@kernel.org>
      Signed-off-by: default avatarJens Axboe <jens.axboe@oracle.com>
      f331c029
    • Tejun Heo's avatar
      block: make variable and argument names more consistent · cf771cb5
      Tejun Heo authored
      In hd_struct, @partno is used to denote partition number and a number
      of other places use @part to denote hd_struct.  Functions use @part
      and @index instead.  This causes confusion and makes it difficult to
      use consistent variable names for hd_struct.  Always use @partno if a
      variable represents partition number.
      
      Also, print out functions use @f or @part for seq_file argument.  Use
      @seqf uniformly instead.
      Signed-off-by: default avatarTejun Heo <tj@kernel.org>
      Signed-off-by: default avatarJens Axboe <jens.axboe@oracle.com>
      cf771cb5