1. 08 Aug, 2010 2 commits
    • NeilBrown's avatar
      md: fix another deadlock with removing sysfs attributes. · bb4f1e9d
      NeilBrown authored
      
      Move the deletion of sysfs attributes from reconfig_mutex to
      open_mutex didn't really help as a process can try to take
      open_mutex while holding reconfig_mutex, so the same deadlock can
      happen, just requiring one more process to be involved in the chain.
      
      I looks like I cannot easily use locking to wait for the sysfs
      deletion to complete, so don't.
      
      The only things that we cannot do while the deletions are still
      pending is other things which can change the sysfs namespace: run,
      takeover, stop.  Each of these can fail with -EBUSY.
      So set a flag while doing a sysfs deletion, and fail run, takeover,
      stop if that flag is set.
      
      This is suitable for 2.6.35.x
      
      Cc: stable@kernel.org
      Signed-off-by: default avatarNeilBrown <neilb@suse.de>
      bb4f1e9d
    • Dan Williams's avatar
      md: move revalidate_disk() back outside open_mutex · 147e0b6a
      Dan Williams authored
      Commit b821eaa5
      
       "md: remove ->changed and related code" moved
      revalidate_disk() under open_mutex, and lockdep noticed.
      
      [ INFO: possible circular locking dependency detected ]
      2.6.32-mdadm-locking #1
      -------------------------------------------------------
      mdadm/3640 is trying to acquire lock:
       (&bdev->bd_mutex){+.+.+.}, at: [<ffffffff811acecb>] revalidate_disk+0x5b/0x90
      
      but task is already holding lock:
       (&mddev->open_mutex){+.+...}, at: [<ffffffffa055e07a>] do_md_stop+0x4a/0x4d0 [md_mod]
      
      which lock already depends on the new lock.
      
      It is suitable for 2.6.35.x
      
      Cc: <stable@kernel.org>
      Reported-by: default avatarPrzemyslaw Czarnowski <przemyslaw.hawrylewicz.czarnowski@intel.com>
      Signed-off-by: default avatarDan Williams <dan.j.williams@intel.com>
      Signed-off-by: default avatarNeilBrown <neilb@suse.de>
      147e0b6a
  2. 25 Jul, 2010 8 commits
    • NeilBrown's avatar
      md/bitmap: separate out loading a bitmap from initialising the structures. · 69e51b44
      NeilBrown authored
      
      dm makes this distinction between ->ctr and ->resume, so we need to
      too.
      
      Also get the new bitmap_load to clear out the bitmap first, as this is
      most consistent with the dm suspend/resume approach
      Signed-off-by: default avatarNeilBrown <neilb@suse.de>
      69e51b44
    • NeilBrown's avatar
      md/bitmap: clean up plugging calls. · b63d7c2e
      NeilBrown authored
      
      1/ use md_unplug in bitmap.c as we will soon be using bitmaps under
        arrays with no queue attached.
      
      2/ Don't bother plugging the queue when we set a bit in the bitmap.
         The reason for this was to encourage as many bits as possible to
         get set before we unplug and write stuff out.
         However every personality already plugs the queue after
         bitmap_startwrite either directly (raid1/raid10) or be setting
         STRIPE_BIT_DELAY which causes the queue to be plugged later
         (raid5).
      Signed-off-by: default avatarNeilBrown <neilb@suse.de>
      b63d7c2e
    • NeilBrown's avatar
      md/plug: optionally use plugger to unplug an array during resync/recovery. · 252ac522
      NeilBrown authored
      
      If an array doesn't have a 'queue' then md_do_sync cannot
      unplug it.
      In that case it will have a 'plugger', so make that available
      to the mddev, and use it to unplug the array if needed.
      Signed-off-by: default avatarNeilBrown <neilb@suse.de>
      252ac522
    • NeilBrown's avatar
      md/raid5: add simple plugging infrastructure. · 2ac87401
      NeilBrown authored
      
      md/raid5 uses the plugging infrastructure provided by the block layer
      and 'struct request_queue'.  However when we plug raid5 under dm there
      is no request queue so we cannot use that.
      
      So create a similar infrastructure that is much lighter weight and use
      it for raid5.
      Signed-off-by: default avatarNeilBrown <neilb@suse.de>
      2ac87401
    • NeilBrown's avatar
      md: add support for raising dm events. · 768a418d
      NeilBrown authored
      
      dm uses scheduled work to raise events to user-space.
      So allow md device to have work_structs and schedule them on an error.
      Signed-off-by: default avatarNeilBrown <neilb@suse.de>
      768a418d
    • NeilBrown's avatar
      md: export various start/stop interfaces · 390ee602
      NeilBrown authored
      
      export entry points for starting and stopping md arrays.
      This will be used by a module to make md/raid5 work under
      dm.
      Also stop calling md_stop_writes from md_stop, as that won't
      work well with dm - it will want to call the two separately.
      Signed-off-by: default avatarNeilBrown <neilb@suse.de>
      390ee602
    • NeilBrown's avatar
      md: split out md_rdev_init · e8bb9a83
      NeilBrown authored
      
      This functionality will be needed separately in a subsequent patch, so
      split it into it's own exported function.
      Signed-off-by: default avatarNeilBrown <neilb@suse.de>
      e8bb9a83
    • NeilBrown's avatar
      md: be more careful setting MD_CHANGE_CLEAN · 676e42d8
      NeilBrown authored
      
      When MD_CHANGE_CLEAN is set we might block in md_write_start.
      So we should only set it when fairly sure that something will clear
      it.
      
      There are two places where it is set so as to encourage a metadata
      update to record the progress of resync/recovery.  This should only
      be done if the internal metadata update mechanisms are in use, which
      can be tested by by inspecting '->persistent'.
      Signed-off-by: default avatarNeilBrown <neilb@suse.de>
      676e42d8
  3. 20 Jul, 2010 1 commit
  4. 23 Jun, 2010 3 commits
    • NeilBrown's avatar
      md: Don't update ->recovery_offset when reshaping an array to fewer devices. · 70fffd0b
      NeilBrown authored
      
      When an array is reshaped to have fewer devices, the reshape proceeds
      from the end of the devices to the beginning.
      
      If a device happens to be non-In_sync (which is possible but rare)
      we would normally update the ->recovery_offset as the reshape
      progresses. However that would be wrong as the recover_offset records
      that the early part of the device is in_sync, while in fact it would
      only be the later part that is in_sync, and in any case the offset
      number would be measured from the wrong end of the device.
      
      Relatedly, if after a reshape a spare is discovered to not be
      recoverred all the way to the end, not allow spare_active
      to incorporate it in the array.
      
      This becomes relevant in the following sample scenario:
      
      A 4 drive RAID5 is converted to a 6 drive RAID6 in a combined
      operation.
      The RAID5->RAID6 conversion will cause a 5 drive to be included as a
      spare, then the 5drive -> 6drive reshape will effectively rebuild that
      spare as it progresses.  The 6th drive is treated as in_sync the whole
      time as there is never any case that we might consider reading from
      it, but must not because there is no valid data.
      
      If we interrupt this reshape part-way through and reverse it to return
      to a 5-drive RAID6 (or event a 4-drive RAID5), we don't want to update
      the recovery_offset - as that would be wrong - and we don't want to
      include that spare as active in the 5-drive RAID6 when the reversed
      reshape completed and it will be mostly out-of-sync still.
      Signed-off-by: default avatarNeilBrown <neilb@suse.de>
      70fffd0b
    • NeilBrown's avatar
      md: fix handling of array level takeover that re-arranges devices. · e93f68a1
      NeilBrown authored
      
      Most array level changes leave the list of devices largely unchanged,
      possibly causing one at the end to become redundant.
      However conversions between RAID0 and RAID10 need to renumber
      all devices (except 0).
      
      This renumbering is currently being done in the ->run method when the
      new personality takes over.  However this is too late as the common
      code in md.c might already have invalidated some of the devices if
      they had a ->raid_disk number that appeared to high.
      
      Moving it into the ->takeover method is too early as the array is
      still active at that time and wrong ->raid_disk numbers could cause
      confusion.
      
      So add a ->new_raid_disk field to mdk_rdev_s and use it to communicate
      the new raid_disk number.
      Now the common code knows exactly which devices need to be renumbered,
      and which can be invalidated, and can do it all at a convenient time
      when the array is suspend.
      It can also update some symlinks in sysfs which previously were not be
      updated correctly.
      Reported-by: default avatarMaciej Trela <maciej.trela@intel.com>
      Signed-off-by: default avatarNeilBrown <neilb@suse.de>
      e93f68a1
    • NeilBrown's avatar
      Restore partition detection of newly created md arrays. · f3b99be1
      NeilBrown authored
      Commit  b821eaa5
      
       broke partition
      detection for md arrays.
      
      The logic was almost right.  However if revalidate_disk is called
      when the device is not yet open, bdev->bd_disk won't be set, so the
      flush_disk() Call will not set bd_invalidated.
      
      So when md_open is called we still need to ensure that
      ->bd_invalidated gets set.  This is easily done with a call to
      check_disk_size_change in the place where the offending commit removed
      check_disk_change.  At the important times, the size will have changed
      from 0 to non-zero, so check_disk_size_change will set bd_invalidated.
      Tested-by: default avatarDuncan <1i5t5.duncan@cox.net>
      Reported-by: default avatarDuncan <1i5t5.duncan@cox.net>
      Signed-off-by: default avatarNeilBrown <neilb@suse.de>
      f3b99be1
  5. 21 May, 2010 1 commit
    • Eric W. Biederman's avatar
      sysfs: Implement sysfs tagged directory support. · 3ff195b0
      Eric W. Biederman authored
      
      The problem.  When implementing a network namespace I need to be able
      to have multiple network devices with the same name.  Currently this
      is a problem for /sys/class/net/*, /sys/devices/virtual/net/*, and
      potentially a few other directories of the form /sys/ ... /net/*.
      
      What this patch does is to add an additional tag field to the
      sysfs dirent structure.  For directories that should show different
      contents depending on the context such as /sys/class/net/, and
      /sys/devices/virtual/net/ this tag field is used to specify the
      context in which those directories should be visible.  Effectively
      this is the same as creating multiple distinct directories with
      the same name but internally to sysfs the result is nicer.
      
      I am calling the concept of a single directory that looks like multiple
      directories all at the same path in the filesystem tagged directories.
      
      For the networking namespace the set of directories whose contents I need
      to filter with tags can depend on the presence or absence of hotplug
      hardware or which modules are currently loaded.  Which means I need
      a simple race free way to setup those directories as tagged.
      
      To achieve a reace free design all tagged directories are created
      and managed by sysfs itself.
      
      Users of this interface:
      - define a type in the sysfs_tag_type enumeration.
      - call sysfs_register_ns_types with the type and it's operations
      - sysfs_exit_ns when an individual tag is no longer valid
      
      - Implement mount_ns() which returns the ns of the calling process
        so we can attach it to a sysfs superblock.
      - Implement ktype.namespace() which returns the ns of a syfs kobject.
      
      Everything else is left up to sysfs and the driver layer.
      
      For the network namespace mount_ns and namespace() are essentially
      one line functions, and look to remain that.
      
      Tags are currently represented a const void * pointers as that is
      both generic, prevides enough information for equality comparisons,
      and is trivial to create for current users, as it is just the
      existing namespace pointer.
      
      The work needed in sysfs is more extensive.  At each directory
      or symlink creating I need to check if the directory it is being
      created in is a tagged directory and if so generate the appropriate
      tag to place on the sysfs_dirent.  Likewise at each symlink or
      directory removal I need to check if the sysfs directory it is
      being removed from is a tagged directory and if so figure out
      which tag goes along with the name I am deleting.
      
      Currently only directories which hold kobjects, and
      symlinks are supported.  There is not enough information
      in the current file attribute interfaces to give us anything
      to discriminate on which makes it useless, and there are
      no potential users which makes it an uninteresting problem
      to solve.
      Signed-off-by: default avatarEric W. Biederman <ebiederm@xmission.com>
      Signed-off-by: default avatarBenjamin Thery <benjamin.thery@bull.net>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
      3ff195b0
  6. 18 May, 2010 22 commits
  7. 17 May, 2010 2 commits
    • NeilBrown's avatar
      md: manage redundancy group in sysfs when changing level. · a64c876f
      NeilBrown authored
      
      Some levels expect the 'redundancy group' to be present,
      others don't.
      So when we change level of an array we might need to
      add or remove this group.
      
      This requires fixing up the current practice of overloading ->private
      to indicate (when ->pers == NULL) that something needs to be removed.
      So create a new ->to_remove to fill that role.
      
      When changing levels, we may need to add or remove attributes.  When
      changing RAID5 -> RAID6, we both add and remove the same thing.  It is
      important to catch this and optimise it out as the removal is delayed
      until a lock is released, so trying to add immediately would cause
      problems.
      
      
      Cc: stable@kernel.org
      Signed-off-by: default avatarNeilBrown <neilb@suse.de>
      a64c876f
    • NeilBrown's avatar
      md: remove unneeded sysfs files more promptly · b6eb127d
      NeilBrown authored
      
      When an array is stopped we need to remove some
      sysfs files which are dependent on the type of array.
      
      We need to delay that deletion as deleting them while holding
      reconfig_mutex can lead to deadlocks.
      
      We currently delay them until the array is completely destroyed.
      However it is possible to deactivate and then reactivate the array.
      It is also possible to need to remove sysfs files when changing level,
      which can potentially happen several times before an array is
      destroyed.
      
      So we need to delete these files more promptly: as soon as
      reconfig_mutex is dropped.
      
      We need to ensure this happens before do_md_run can restart the array,
      so we use open_mutex for some extra locking.  This is not deadlock
      prone.
      
      Cc: stable@kernel.org
      Signed-off-by: default avatarNeilBrown <neilb@suse.de>
      b6eb127d
  8. 11 May, 2010 1 commit
    • Dan Williams's avatar
      md: set mddev readonly flag on blkdev BLKROSET ioctl · e2218350
      Dan Williams authored
      
      When the user sets the block device to readwrite then the mddev should
      follow suit.  Otherwise, the BUG_ON in md_write_start() will be set to
      trigger.
      
      The reverse direction, setting mddev->ro to match a set readonly
      request, can be ignored because the blkdev level readonly flag precludes
      the need to have mddev->ro set correctly.  Nevermind the fact that
      setting mddev->ro to 1 may fail if the array is in use.
      
      Cc: <stable@kernel.org>
      Signed-off-by: default avatarDan Williams <dan.j.williams@intel.com>
      Signed-off-by: default avatarNeilBrown <neilb@suse.de>
      e2218350