1. 11 10月, 2008 4 次提交
    • H
      ext4: add an option to control error handling on file data · 5bf5683a
      Hidehiro Kawai 提交于
      If the journal doesn't abort when it gets an IO error in file data
      blocks, the file data corruption will spread silently.  Because
      most of applications and commands do buffered writes without fsync(),
      they don't notice the IO error.  It's scary for mission critical
      systems.  On the other hand, if the journal aborts whenever it gets
      an IO error in file data blocks, the system will easily become
      inoperable.  So this patch introduces a filesystem option to
      determine whether it aborts the journal or just call printk() when
      it gets an IO error in file data.
      
      If you mount an ext4 fs with data_err=abort option, it aborts on file
      data write error.  If you mount it with data_err=ignore, it doesn't
      abort, just call printk().  data_err=ignore is the default.
      
      Here is the corresponding patch of the ext3 version:
      http://kerneltrap.org/mailarchive/linux-kernel/2008/9/9/3239374Signed-off-by: NHidehiro Kawai <hidehiro.kawai.ez@hitachi.com>
      Signed-off-by: NTheodore Ts'o <tytso@mit.edu>
      5bf5683a
    • H
      jbd2: don't dirty original metadata buffer on abort · 7ad7445f
      Hidehiro Kawai 提交于
      Currently, original metadata buffers are dirtied when they are
      unfiled whether the journal has aborted or not.  Eventually these
      buffers will be written-back to the filesystem by pdflush.  This
      means some metadata buffers are written to the filesystem without
      journaling if the journal aborts.  So if both journal abort and
      system crash happen at the same time, the filesystem would become
      inconsistent state.  Additionally, replaying journaled metadata
      can overwrite the latest metadata on the filesystem partly.
      Because, if the journal gets aborted, journaled metadata are
      preserved and replayed during the next mount not to lose
      uncheckpointed metadata.  This would also break the consistency
      of the filesystem.
      
      This patch prevents original metadata buffers from being dirtied
      on abort by clearing BH_JBDDirty flag from those buffers.  Thus,
      no metadata buffers are written to the filesystem without journaling.
      Signed-off-by: NHidehiro Kawai <hidehiro.kawai.ez@hitachi.com>
      Signed-off-by: NTheodore Ts'o <tytso@mit.edu>
      7ad7445f
    • H
      ext4: add checks for errors from jbd2 · 7ffe1ea8
      Hidehiro Kawai 提交于
      If the journal has aborted due to a checkpointing failure, we
      have to keep the contents of the journal space.  Otherwise, the
      filesystem will lose uncheckpointed metadata completely and
      become inconsistent.  To avoid this, we need to keep needs_recovery
      flag if checkpoint has failed.
      
      With this patch, ext4_put_super() detects a checkpointing failure
      from the return value of journal_destroy(), then it invokes
      ext4_abort() to make the filesystem read only and keep
      needs_recovery flag.  Errors from jbd2_journal_flush() are also
      handled by this patch in some places.
      Signed-off-by: NHidehiro Kawai <hidehiro.kawai.ez@hitachi.com>
      Signed-off-by: NTheodore Ts'o <tytso@mit.edu>
      7ffe1ea8
    • H
      jbd2: fix error handling for checkpoint io · 44519faf
      Hidehiro Kawai 提交于
      When a checkpointing IO fails, current JBD2 code doesn't check the
      error and continue journaling.  This means latest metadata can be
      lost from both the journal and filesystem.
      
      This patch leaves the failed metadata blocks in the journal space
      and aborts journaling in the case of jbd2_log_do_checkpoint().
      To achieve this, we need to do:
      
      1. don't remove the failed buffer from the checkpoint list where in
         the case of __try_to_free_cp_buf() because it may be released or
         overwritten by a later transaction
      2. jbd2_log_do_checkpoint() is the last chance, remove the failed
         buffer from the checkpoint list and abort the journal
      3. when checkpointing fails, don't update the journal super block to
         prevent the journaled contents from being cleaned.  For safety,
         don't update j_tail and j_tail_sequence either
      4. when checkpointing fails, notify this error to the ext4 layer so
         that ext4 don't clear the needs_recovery flag, otherwise the
         journaled contents are ignored and cleaned in the recovery phase
      5. if the recovery fails, keep the needs_recovery flag
      6. prevent jbd2_cleanup_journal_tail() from being called between
         __jbd2_journal_drop_transaction() and jbd2_journal_abort()
         (a possible race issue between jbd2_log_do_checkpoint()s called by
         jbd2_journal_flush() and __jbd2_log_wait_for_space())
      Signed-off-by: NHidehiro Kawai <hidehiro.kawai.ez@hitachi.com>
      Signed-off-by: NTheodore Ts'o <tytso@mit.edu>
      44519faf
  2. 13 10月, 2008 1 次提交
    • H
      jbd2: abort when failed to log metadata buffers · 77e841de
      Hidehiro Kawai 提交于
      If we failed to write metadata buffers to the journal space and
      succeeded to write the commit record, stale data can be written
      back to the filesystem as metadata in the recovery phase.
      
      To avoid this, when we failed to write out metadata buffers,
      abort the journal before writing the commit record.
      
      We can also avoid this kind of corruption by using the journal
      checksum feature because it can detect invalid metadata blocks in the
      journal and avoid them from being replayed.  So we don't need to care
      about asynchronous commit record writeout with a checksum.
      Signed-off-by: NHidehiro Kawai <hidehiro.kawai.ez@hitachi.com>
      Signed-off-by: NTheodore Ts'o <tytso@mit.edu>
      77e841de
  3. 11 10月, 2008 2 次提交
  4. 10 10月, 2008 1 次提交
    • L
      Don't allow splice() to files opened with O_APPEND · efc968d4
      Linus Torvalds 提交于
      This is debatable, but while we're debating it, let's disallow the
      combination of splice and an O_APPEND destination.
      
      It's not entirely clear what the semantics of O_APPEND should be, and
      POSIX apparently expects pwrite() to ignore O_APPEND, for example.  So
      we could make up any semantics we want, including the old ones.
      
      But Miklos convinced me that we should at least give it some thought,
      and that accepting writes at arbitrary offsets is wrong at least for
      IS_APPEND() files (which always have O_APPEND set, even if the reverse
      isn't true: you can obviously have O_APPEND set on a regular file).
      
      So disallow O_APPEND entirely for now.  I doubt anybody cares, and this
      way we have one less gray area to worry about.
      Reported-and-argued-for-by: NMiklos Szeredi <miklos@szeredi.hu>
      Acked-by: NJens Axboe <ens.axboe@oracle.com>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      efc968d4
  5. 09 10月, 2008 32 次提交
    • R
      block_dev: fix kernel-doc in new functions · 57d1b536
      Randy Dunlap 提交于
      Fix kernel-doc in new functions:
      
      Error(mmotm-2008-1002-1617//fs/block_dev.c:895): duplicate section name 'Description'
      Error(mmotm-2008-1002-1617//fs/block_dev.c:924): duplicate section name 'Description'
      Warning(mmotm-2008-1002-1617//fs/block_dev.c:1282): No description found for parameter 'pathname'
      Signed-off-by: NRandy Dunlap <randy.dunlap@oracle.com>
      cc: Andrew Patterson <andrew.patterson@hp.com>
      Signed-off-by: NJens Axboe <jens.axboe@oracle.com>
      57d1b536
    • D
      block: mark bio_split_pool static · 6feef531
      Denis ChengRq 提交于
      Since all bio_split calls refer the same single bio_split_pool, the bio_split
      function can use bio_split_pool directly instead of the mempool_t parameter;
      
      then the mempool_t parameter can be removed from bio_split param list, and
      bio_split_pool is only referred in fs/bio.c file, can be marked static.
      Signed-off-by: NDenis ChengRq <crquan@gmail.com>
      Signed-off-by: NJens Axboe <jens.axboe@oracle.com>
      6feef531
    • M
      block: Find bio sector offset given idx and offset · ad3316bf
      Martin K. Petersen 提交于
      Helper function to find the sector offset in a bio given bvec index
      and page offset.
      Signed-off-by: NMartin K. Petersen <martin.petersen@oracle.com>
      Signed-off-by: NJens Axboe <jens.axboe@oracle.com>
      ad3316bf
    • M
      block: Introduce integrity data ownership flag · 74aa8c2c
      Martin K. Petersen 提交于
      A filesystem might supply its own integrity metadata.  Introduce a
      flag that indicates whether the filesystem or the block layer owns the
      integrity buffer.
      Signed-off-by: NMartin K. Petersen <martin.petersen@oracle.com>
      Signed-off-by: NJens Axboe <jens.axboe@oracle.com>
      74aa8c2c
    • J
      block: revert part of d7533ad0e132f92e75c1b2eb7c26387b25a583c1 · b04accc4
      Jens Axboe 提交于
      We need bdev_get_integrity() to support the pending md/dm patches.
      Signed-off-by: NJens Axboe <jens.axboe@oracle.com>
      b04accc4
    • J
      block: cleanup some of the integrity stuff in blkdev.h · 9c02f2b0
      Jens Axboe 提交于
      Don't put functions that are only used in fs/bio-integrity.c in
      blkdev.h, it's much cleaner to just keep it in there. Also kill
      completely unused bdev_get_tag_size()
      Signed-off-by: NJens Axboe <jens.axboe@oracle.com>
      9c02f2b0
    • J
      block: add bio_kmalloc() · 0a0d96b0
      Jens Axboe 提交于
      Not all callers need (or want!) the mempool backing guarentee, it
      essentially means that you can only use bio_alloc() for short allocations
      and not for preallocating some bio's at setup or init time.
      
      So add bio_kmalloc() which does the same thing as bio_alloc(), except
      it just uses kmalloc() as the backing instead of the bio mempools.
      Signed-off-by: NJens Axboe <jens.axboe@oracle.com>
      0a0d96b0
    • A
      Call flush_disk() after detecting an online resize. · 608aeef1
      Andrew Patterson 提交于
      We call flush_disk() to make sure the buffer cache for the disk is
      flushed after a disk resize. There are two resize cases, growing and
      shrinking. Given that users can shrink/then grow a disk before
      revalidate_disk() is called, we treat the grow case identically to
      shrinking. We need to flush the buffer cache after an online shrink
      because, as James Bottomley puts it,
      
           The two use cases for shrinking I can see are
      
           1. planned: the fs is already shrunk to within the new boundaries
              and all data is relocated, so invalidate is fine (any dirty
              buffers that might exist in the shrunk region are there only
              because they were relocated but not yet written to their
              original location).
           2. unplanned:  In this case, the fs is probably toast, so whether
              we invalidate or not isn't going to make a whole lot of
              difference; it's still going to try to read or write from
              sectors beyond the new size and get I/O errors.
      
      Immediately invalidating shrunk disks will cause errors for outstanding
      I/Os for reads/write beyond the new end of the disk to be generated
      earlier then if we waited for the normal buffer cache operation. It also
      removes a potential security hole where we might keep old data around
      from beyond the end of the shrunk disk if the disk was not invalidated.
      Signed-off-by: NAndrew Patterson <andrew.patterson@hp.com>
      Signed-off-by: NJens Axboe <jens.axboe@oracle.com>
      608aeef1
    • A
      Added flush_disk to factor out common buffer cache flushing code. · 56ade44b
      Andrew Patterson 提交于
      We need to be able to flush the buffer cache for for more than
      just when a disk is changed, so we factor out common cache flush code
      in check_disk_change() to an internal flush_disk() routine.  This
      routine will then be used for both disk changes and disk resizes (in a
      later patch).
      
      Include the disk name in the text indicating that there are busy
      inodes on the device and increase the KERN severity of the message.
      Signed-off-by: NAndrew Patterson <andrew.patterson@hp.com>
      Signed-off-by: NJens Axboe <jens.axboe@oracle.com>
      56ade44b
    • A
      Check for device resize when rescanning partitions · 9bc3ffbf
      Andrew Patterson 提交于
      Check for device resize in the rescan_partitions() routine. If the device
      has been resized, the bdev size is set to match. The rescan_partitions()
      routine is called when opening the device and when calling the
      BLKRRPART ioctl.
      Signed-off-by: NAndrew Patterson <andrew.patterson@hp.com>
      Signed-off-by: NJens Axboe <jens.axboe@oracle.com>
      9bc3ffbf
    • A
      Adjust block device size after an online resize of a disk. · c3279d14
      Andrew Patterson 提交于
      The revalidate_disk routine now checks if a disk has been resized by
      comparing the gendisk capacity to the bdev inode size.  If they are
      different (usually because the disk has been resized underneath the kernel)
      the bdev inode size is adjusted to match the capacity.
      Signed-off-by: NAndrew Patterson <andrew.patterson@hp.com>
      Signed-off-by: NJens Axboe <jens.axboe@oracle.com>
      c3279d14
    • A
      Wrapper for lower-level revalidate_disk routines. · 0c002c2f
      Andrew Patterson 提交于
      This is a wrapper for the lower-level revalidate_disk call-backs such
      as sd_revalidate_disk(). It allows us to perform pre and post
      operations when calling them.
      
      We will use this wrapper in a later patch to adjust block device sizes
      after an online resize (a _post_ operation).
      Signed-off-by: NAndrew Patterson <andrew.patterson@hp.com>
      Signed-off-by: NJens Axboe <jens.axboe@oracle.com>
      0c002c2f
    • F
      block: make blk_rq_map_user take a NULL user-space buffer · 81882766
      FUJITA Tomonori 提交于
      This patch changes blk_rq_map_user to accept a NULL user-space buffer
      with a READ command if rq_map_data is not NULL. Thus a caller can pass
      page frames to lk_rq_map_user to just set up a request and bios with
      page frames propely. bio_uncopy_user (called via blk_rq_unmap_user)
      doesn't copy data to user space with such request.
      Signed-off-by: NFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
      Signed-off-by: NJens Axboe <jens.axboe@oracle.com>
      81882766
    • F
      bio: convert bio_copy_kern to use bio_copy_user · 4d8ab62e
      FUJITA Tomonori 提交于
      bio_copy_kern and bio_copy_user are very similar. This converts
      bio_copy_kern to use bio_copy_user.
      Signed-off-by: NFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
      Cc: Jens Axboe <jens.axboe@oracle.com>
      Signed-off-by: NJens Axboe <jens.axboe@oracle.com>
      4d8ab62e
    • F
      block: introduce struct rq_map_data to use reserved pages · 152e283f
      FUJITA Tomonori 提交于
      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: NFUJITA 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: NJens Axboe <jens.axboe@oracle.com>
      152e283f
    • F
      block: add gfp_mask argument to blk_rq_map_user and blk_rq_map_user_iov · a3bce90e
      FUJITA Tomonori 提交于
      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: NFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
      Signed-off-by: NDouglas Gilbert <dougg@torque.net>
      Cc: Mike Christie <michaelc@cs.wisc.edu>
      Cc: James Bottomley <James.Bottomley@HansenPartnership.com>
      Signed-off-by: NJens Axboe <jens.axboe@oracle.com>
      a3bce90e
    • J
      block: add support for IO CPU affinity · c7c22e4d
      Jens Axboe 提交于
      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: NJens Axboe <jens.axboe@oracle.com>
      c7c22e4d
    • T
      block: allow disk to have extended device number · 3e1a7ff8
      Tejun Heo 提交于
      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: NTejun Heo <tj@kernel.org>
      Signed-off-by: NJens Axboe <jens.axboe@oracle.com>
      3e1a7ff8
    • T
      block: replace @ext_minors with GENHD_FL_EXT_DEVT · 689d6fac
      Tejun Heo 提交于
      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: NTejun Heo <tj@kernel.org>
      Signed-off-by: NJens Axboe <jens.axboe@oracle.com>
      689d6fac
    • T
      block: make partition array dynamic · 540eed56
      Tejun Heo 提交于
      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: NTejun Heo <tj@kernel.org>
      Signed-off-by: NJens Axboe <jens.axboe@oracle.com>
      540eed56
    • T
      block: move stats from disk to part0 · 074a7aca
      Tejun Heo 提交于
      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: NTejun Heo <tj@kernel.org>
      Signed-off-by: NJens Axboe <jens.axboe@oracle.com>
      074a7aca
    • T
      block: kill GENHD_FL_FAIL and use part0->make_it_fail · eddb2e26
      Tejun Heo 提交于
      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: NTejun Heo <tj@kernel.org>
      Signed-off-by: NJens Axboe <jens.axboe@oracle.com>
      eddb2e26
    • T
      block: always set bdev->bd_part · 0762b8bd
      Tejun Heo 提交于
      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: NTejun Heo <tj@kernel.org>
      Signed-off-by: NJens Axboe <jens.axboe@oracle.com>
      0762b8bd
    • T
      block: move holder_dir from disk to part0 · 4c46501d
      Tejun Heo 提交于
      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: NTejun Heo <tj@kernel.org>
      Signed-off-by: NJens Axboe <jens.axboe@oracle.com>
      4c46501d
    • T
      block: move policy from disk to part0 · b7db9956
      Tejun Heo 提交于
      Move disk->policy to part0->policy.  Implement and use get_disk_ro().
      Signed-off-by: NTejun Heo <tj@kernel.org>
      Signed-off-by: NJens Axboe <jens.axboe@oracle.com>
      b7db9956
    • T
      block: unify sysfs size node handling · e5610521
      Tejun Heo 提交于
      Now that capacity and __dev are moved to part0, part0 and others can
      share the same method.
      Signed-off-by: NTejun Heo <tj@kernel.org>
      Signed-off-by: NJens Axboe <jens.axboe@oracle.com>
      e5610521
    • T
      block: move capacity from disk to part0 · 80795aef
      Tejun Heo 提交于
      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: NTejun Heo <tj@kernel.org>
      Signed-off-by: NJens Axboe <jens.axboe@oracle.com>
      80795aef
    • T
      block: introduce partition 0 · b5d0b9df
      Tejun Heo 提交于
      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: NTejun Heo <tj@kernel.org>
      Signed-off-by: NJens Axboe <jens.axboe@oracle.com>
      b5d0b9df
    • T
      block: implement and use {disk|part}_to_dev() · ed9e1982
      Tejun Heo 提交于
      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: NTejun Heo <tj@kernel.org>
      Signed-off-by: NJens Axboe <jens.axboe@oracle.com>
      ed9e1982
    • T
      block: implement extended dev numbers · bcce3de1
      Tejun Heo 提交于
      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: NTejun Heo <tj@kernel.org>
      Signed-off-by: NJens Axboe <jens.axboe@oracle.com>
      bcce3de1
    • T
      block: fix diskstats access · c9959059
      Tejun Heo 提交于
      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: NTejun Heo <tj@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Signed-off-by: NJens Axboe <jens.axboe@oracle.com>
      c9959059
    • T
      block: fix disk->part[] dereferencing race · e71bf0d0
      Tejun Heo 提交于
      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: NTejun Heo <tj@kernel.org>
      Signed-off-by: NJens Axboe <jens.axboe@oracle.com>
      e71bf0d0