1. 23 8月, 2008 1 次提交
  2. 01 8月, 2008 7 次提交
    • J
      [PATCH] configfs: Pin configfs subsystems separately from new config_items. · 70526b67
      Joel Becker 提交于
      configfs_mkdir() creates a new item by calling its parent's
      ->make_item/group() functions.  Once that object is created,
      configfs_mkdir() calls try_module_get() on the new item's module.  If it
      succeeds, the module owning the new item cannot be unloaded, and
      configfs is safe to reference the item.
      
      If the item and the subsystem it belongs to are part of the same module,
      the subsystem is also pinned.  This is the common case.
      
      However, if the subsystem is made up of multiple modules, this may not
      pin the subsystem.  Thus, it would be possible to unload the toplevel
      subsystem module while there is still a child item.  Thus, we now
      try_module_get() the subsystem's module.  This only really affects
      children of the toplevel subsystem group.  Deeper children already have
      their parents pinned.
      Signed-off-by: NJoel Becker <joel.becker@oracle.com>
      Signed-off-by: NMark Fasheh <mfasheh@suse.com>
      70526b67
    • L
      [PATCH] configfs: Fix open directory making rmdir() fail · 99cefda4
      Louis Rilling 提交于
      When checking for user-created elements under an item to be removed by rmdir(),
      configfs_detach_prep() counts fake configfs_dirents created by dir_open() as
      user-created and fails when finding one. It is however perfectly valid to remove
      a directory that is open.
      
      Simply make configfs_detach_prep() skip fake configfs_dirent, like it already
      does for attributes, and like detach_groups() does.
      Signed-off-by: NLouis Rilling <louis.rilling@kerlabs.com>
      Signed-off-by: NJoel Becker <joel.becker@oracle.com>
      Signed-off-by: NMark Fasheh <mfasheh@suse.com>
      99cefda4
    • L
      [PATCH] configfs: Lock new directory inodes before removing on cleanup after failure · 2e2ce171
      Louis Rilling 提交于
      Once a new configfs directory is created by configfs_attach_item() or
      configfs_attach_group(), a failure in the remaining initialization steps leads
      to removing a directory which inode the VFS may have already accessed.
      
      This commit adds the necessary inode locking to safely remove configfs
      directories while cleaning up after a failure. As an advantage, the locking
      rules of populate_groups() and detach_groups() become the same: the caller must
      have the group's inode mutex locked.
      Signed-off-by: NLouis Rilling <louis.rilling@kerlabs.com>
      Signed-off-by: NJoel Becker <joel.becker@oracle.com>
      Signed-off-by: NMark Fasheh <mfasheh@suse.com>
      2e2ce171
    • L
      [PATCH] configfs: Prevent userspace from creating new entries under attaching directories · 2a109f2a
      Louis Rilling 提交于
      process 1: 					process 2:
      configfs_mkdir("A")
        attach_group("A")
          attach_item("A")
            d_instantiate("A")
          populate_groups("A")
            mutex_lock("A")
            attach_group("A/B")
              attach_item("A")
                d_instantiate("A/B")
      						mkdir("A/B/C")
      						  do_path_lookup("A/B/C", LOOKUP_PARENT)
      						    ok
      						  lookup_create("A/B/C")
      						    mutex_lock("A/B")
      						    ok
      						  configfs_mkdir("A/B/C")
      						    ok
            attach_group("A/C")
              attach_item("A/C")
                d_instantiate("A/C")
              populate_groups("A/C")
                mutex_lock("A/C")
                attach_group("A/C/D")
                  attach_item("A/C/D")
                    failure
                mutex_unlock("A/C")
                detach_groups("A/C")
                  nothing to do
      						mkdir("A/C/E")
      						  do_path_lookup("A/C/E", LOOKUP_PARENT)
      						    ok
      						  lookup_create("A/C/E")
      						    mutex_lock("A/C")
      						    ok
      						  configfs_mkdir("A/C/E")
      						    ok
              detach_item("A/C")
              d_delete("A/C")
            mutex_unlock("A")
            detach_groups("A")
              mutex_lock("A/B")
              detach_group("A/B")
      	  detach_groups("A/B")
      	    nothing since no _default_ group
                detach_item("A/B")
              mutex_unlock("A/B")
              d_delete("A/B")
          detach_item("A")
          d_delete("A")
      
      Two bugs:
      
      1/ "A/B/C" and "A/C/E" are created, but never removed while their parent are
      removed in the end. The same could happen with symlink() instead of mkdir().
      
      2/ "A" and "A/C" inodes are not locked while detach_item() is called on them,
         which may probably confuse VFS.
      
      This commit fixes 1/, tagging new directories with CONFIGFS_USET_CREATING before
      building the inode and instantiating the dentry, and validating the whole
      group+default groups hierarchy in a second pass by clearing
      CONFIGFS_USET_CREATING.
      	mkdir(), symlink(), lookup(), and dir_open() simply return -ENOENT if
      called in (or linking to) a directory tagged with CONFIGFS_USET_CREATING. This
      does not prevent userspace from calling stat() successfuly on such directories,
      but this prevents userspace from adding (children to | symlinking from/to |
      read/write attributes of | listing the contents of) not validated items. In
      other words, userspace will not interact with the subsystem on a new item until
      the new item creation completes correctly.
      	It was first proposed to re-use CONFIGFS_USET_IN_MKDIR instead of a new
      flag CONFIGFS_USET_CREATING, but this generated conflicts when checking the
      target of a new symlink: a valid target directory in the middle of attaching
      a new user-created child item could be wrongly detected as being attached.
      
      2/ is fixed by next commit.
      Signed-off-by: NLouis Rilling <louis.rilling@kerlabs.com>
      Signed-off-by: NJoel Becker <joel.becker@oracle.com>
      Signed-off-by: NMark Fasheh <mfasheh@suse.com>
      2a109f2a
    • L
      [PATCH] configfs: Fix failing symlink() making rmdir() fail · 9a73d78c
      Louis Rilling 提交于
      On a similar pattern as mkdir() vs rmdir(), a failing symlink() may make rmdir()
      fail for the symlink's parent and the symlink's target as well.
      
      failing symlink() making target's rmdir() fail:
      
      	process 1:				process 2:
      	symlink("A/S" -> "B")
      	  allow_link()
      	  create_link()
      	    attach to "B" links list
      						rmdir("B")
      						  detach_prep("B")
      						    error because of new link
      	    configfs_create_link("A", "S")
      	      error (eg -ENOMEM)
      
      failing symlink() making parent's rmdir() fail:
      
      	process 1:				process 2:
      	symlink("A/D/S" -> "B")
      	  allow_link()
      	  create_link()
      	    attach to "B" links list
      	    configfs_create_link("A/D", "S")
      	      make_dirent("A/D", "S")
      						rmdir("A")
      						  detach_prep("A")
      						    detach_prep("A/D")
      						      error because of "S"
      	      create("S")
      	        error (eg -ENOMEM)
      
      We cannot use the same solution as for mkdir() vs rmdir(), since rmdir() on the
      target cannot wait on the i_mutex of the new symlink's parent without risking a
      deadlock (with other symlink() or sys_rename()). Instead we define a global
      mutex protecting all configfs symlinks attachment, so that rmdir() can avoid the
      races above.
      Signed-off-by: NLouis Rilling <louis.rilling@kerlabs.com>
      Signed-off-by: NJoel Becker <joel.becker@oracle.com>
      Signed-off-by: NMark Fasheh <mfasheh@suse.com>
      9a73d78c
    • L
      [PATCH] configfs: Fix symlink() to a removing item · 4768e9b1
      Louis Rilling 提交于
      The rule for configfs symlinks is that symlinks always point to valid
      config_items, and prevent the target from being removed. However,
      configfs_symlink() only checks that it can grab a reference on the target item,
      without ensuring that it remains alive until the symlink is correctly attached.
      
      This patch makes configfs_symlink() fail whenever the target is being removed,
      using the CONFIGFS_USET_DROPPING flag set by configfs_detach_prep() and
      protected by configfs_dirent_lock.
      
      This patch introduces a similar (weird?) behavior as with mkdir failures making
      rmdir fail: if symlink() races with rmdir() of the parent directory (or its
      youngest user-created ancestor if parent is a default group) or rmdir() of the
      target directory, and then fails in configfs_create(), this can make the racing
      rmdir() fail despite the concerned directory having no user-created entry (resp.
      no symlink pointing to it or one of its default groups) in the end.
      This behavior is fixed in later patches.
      Signed-off-by: NLouis Rilling <louis.rilling@kerlabs.com>
      Signed-off-by: NJoel Becker <joel.becker@oracle.com>
      Signed-off-by: NMark Fasheh <mfasheh@suse.com>
      4768e9b1
    • J
      [PATCH] configfs: Include linux/err.h in linux/configfs.h · dacdd0e0
      Joel Becker 提交于
      We now use PTR_ERR() in the ->make_item() and ->make_group() operations.
      Folks including configfs.h need err.h.
      Signed-off-by: NJoel Becker <joel.becker@oracle.com>
      Signed-off-by: NMark Fasheh <mfasheh@suse.com>
      dacdd0e0
  3. 18 7月, 2008 2 次提交
  4. 15 7月, 2008 6 次提交
    • J
      configfs: Allow ->make_item() and ->make_group() to return detailed errors. · 11c3b792
      Joel Becker 提交于
      The configfs operations ->make_item() and ->make_group() currently
      return a new item/group.  A return of NULL signifies an error.  Because
      of this, -ENOMEM is the only return code bubbled up the stack.
      
      Multiple folks have requested the ability to return specific error codes
      when these operations fail.  This patch adds that ability by changing the
      ->make_item/group() ops to return an int.
      
      Also updated are the in-kernel users of configfs.
      Signed-off-by: NJoel Becker <joel.becker@oracle.com>
      11c3b792
    • L
      configfs: Fix failing mkdir() making racing rmdir() fail · 6d8344ba
      Louis Rilling 提交于
      When fixing the rename() vs rmdir() deadlock, we stopped locking default groups'
      inodes in configfs_detach_prep(), letting racing mkdir() in default groups
      proceed concurrently. This enables races like below happen, which leads to a
      failing mkdir() making rmdir() fail, despite the group to remove having no
      user-created directory under it in the end.
      
      	process A: 			process B:
      	/* PWD=A/B */
      	mkdir("C")
      	  make_item("C")
      	  attach_group("C")
      					rmdir("A")
      					  detach_prep("A")
      					    detach_prep("B")
      					      error because of "C"
      					  return -ENOTEMPTY
      	    attach_group("C/D")
      	      error (eg -ENOMEM)
      	  return -ENOMEM
      
      This patch prevents such scenarii by making rmdir() wait as long as
      detach_prep() fails because a racing mkdir() is in the middle of attach_group().
      To achieve this, mkdir() sets a flag CONFIGFS_USET_IN_MKDIR in parent's
      configfs_dirent before calling attach_group(), and clears the flag once
      attach_group() is done. detach_prep() fails with -EAGAIN whenever the flag is
      hit and returns the guilty inode's mutex so that rmdir() can wait on it.
      Signed-off-by: NLouis Rilling <Louis.Rilling@kerlabs.com>
      Signed-off-by: NJoel Becker <joel.becker@oracle.com>
      6d8344ba
    • L
      configfs: Fix deadlock with racing rmdir() and rename() · b3e76af8
      Louis Rilling 提交于
      This patch fixes the deadlock between racing sys_rename() and configfs_rmdir().
      
      The idea is to avoid locking i_mutexes of default groups in
      configfs_detach_prep(), and rely instead on the new configfs_dirent_lock to
      protect against configfs_dirent's linkage mutations. To ensure that an mkdir()
      racing with rmdir() will not create new items in a to-be-removed default group,
      we make configfs_new_dirent() check for the CONFIGFS_USET_DROPPING flag right
      before linking the new dirent, and return error if the flag is set. This makes
      racing mkdir()/symlink()/dir_open() fail in places where errors could already
      happen, resp. in (attach_item()|attach_group())/create_link()/new_dirent().
      
      configfs_depend() remains safe since it locks all the path from configfs root,
      and is thus mutually exclusive with rmdir().
      
      An advantage of this is that now detach_groups() unconditionnaly takes the
      default groups i_mutex, which makes it more consistent with populate_groups().
      Signed-off-by: NLouis Rilling <Louis.Rilling@kerlabs.com>
      Signed-off-by: NJoel Becker <joel.becker@oracle.com>
      b3e76af8
    • L
      configfs: Make configfs_new_dirent() return error code instead of NULL · 107ed40b
      Louis Rilling 提交于
      This patch makes configfs_new_dirent return negative error code instead of NULL,
      which will be useful in the next patch to differentiate ENOMEM from ENOENT.
      Signed-off-by: NLouis Rilling <Louis.Rilling@kerlabs.com>
      Signed-off-by: NJoel Becker <joel.becker@oracle.com>
      107ed40b
    • L
      configfs: Protect configfs_dirent s_links list mutations · 5301a77d
      Louis Rilling 提交于
      Symlinks to a config_item are listed under its configfs_dirent s_links, but the
      list mutations are not protected by any common lock.
      
      This patch uses the configfs_dirent_lock spinlock to add the necessary
      protection.
      
      Note: we should also protect the list_empty() test in configfs_detach_prep() but
      1/ the lock should not be released immediately because nothing would prevent the
      list from being filled after a successful list_empty() test, making the problem
      tricky,
      2/ this will be solved by the rmdir() vs rename() deadlock bugfix.
      Signed-off-by: NLouis Rilling <Louis.Rilling@kerlabs.com>
      Signed-off-by: NJoel Becker <joel.becker@oracle.com>
      5301a77d
    • L
      configfs: Introduce configfs_dirent_lock · 6f610764
      Louis Rilling 提交于
      This patch introduces configfs_dirent_lock spinlock to protect configfs_dirent
      traversals against linkage mutations (add/del/move). This will allow
      configfs_detach_prep() to avoid locking i_mutexes.
      
      Locking rules for configfs_dirent linkage mutations are the same plus the
      requirement of taking configfs_dirent_lock. For configfs_dirent walking, one can
      either take appropriate i_mutex as before, or take configfs_dirent_lock.
      
      The spinlock could actually be a mutex, but the critical sections are either
      O(1) or should not be too long (default groups walking in last patch).
      
      ChangeLog:
        - Clarify the comment on configfs_dirent_lock usage
        - Move sd->s_element init before linking the new dirent
        - In lseek(), do not release configfs_dirent_lock before the dirent is
          relinked.
      Signed-off-by: NLouis Rilling <Louis.Rilling@kerlabs.com>
      Signed-off-by: NJoel Becker <joel.becker@oracle.com>
      6f610764
  5. 26 1月, 2008 1 次提交
    • J
      configfs: dir.c fix possible recursive locking · ba611edf
      Joonwoo Park 提交于
      configfs_register_subsystem() with default_groups triggers recursive locking.
      it seems that mutex_lock_nested is needed.
      
      =============================================
      [ INFO: possible recursive locking detected ]
      2.6.24-rc6 #141
      ---------------------------------------------
      swapper/1 is trying to acquire lock:
       (&sb->s_type->i_mutex_key#3){--..}, at: [<c40ca76f>] configfs_attach_group+0x4f/0x190
      
      but task is already holding lock:
       (&sb->s_type->i_mutex_key#3){--..}, at: [<c40ca9d5>] configfs_register_subsystem+0x55/0x130
      
      other info that might help us debug this:
      1 lock held by swapper/1:
       #0:  (&sb->s_type->i_mutex_key#3){--..}, at: [<c40ca9d5>] configfs_register_subsystem+0x55/0x130
      
      stack backtrace:
      Pid: 1, comm: swapper Not tainted 2.6.24-rc6 #141
       [<c40053ba>] show_trace_log_lvl+0x1a/0x30
       [<c4005e82>] show_trace+0x12/0x20
       [<c400687e>] dump_stack+0x6e/0x80
       [<c404ec72>] __lock_acquire+0xe62/0x1120
       [<c404efb2>] lock_acquire+0x82/0xa0
       [<c43fdad8>] mutex_lock_nested+0x98/0x2e0
       [<c40ca76f>] configfs_attach_group+0x4f/0x190
       [<c40caa46>] configfs_register_subsystem+0xc6/0x130
       [<c45c8186>] init_netconsole+0x2b6/0x300
       [<c45a75f2>] kernel_init+0x142/0x320
       [<c4004fb3>] kernel_thread_helper+0x7/0x14
       =======================
      Signed-off-by: NJoonwoo Park <joonwpark81@gmail.com>
      Signed-off-by: NJoel Becker <joel.becker@oracle.com>
      Signed-off-by: NMark Fasheh <mark.fasheh@oracle.com>
      ba611edf
  6. 17 10月, 2007 1 次提交
    • D
      r/o bind mounts: filesystem helpers for custom 'struct file's · ce8d2cdf
      Dave Hansen 提交于
      Why do we need r/o bind mounts?
      
      This feature allows a read-only view into a read-write filesystem.  In the
      process of doing that, it also provides infrastructure for keeping track of
      the number of writers to any given mount.
      
      This has a number of uses.  It allows chroots to have parts of filesystems
      writable.  It will be useful for containers in the future because users may
      have root inside a container, but should not be allowed to write to
      somefilesystems.  This also replaces patches that vserver has had out of the
      tree for several years.
      
      It allows security enhancement by making sure that parts of your filesystem
      read-only (such as when you don't trust your FTP server), when you don't want
      to have entire new filesystems mounted, or when you want atime selectively
      updated.  I've been using the following script to test that the feature is
      working as desired.  It takes a directory and makes a regular bind and a r/o
      bind mount of it.  It then performs some normal filesystem operations on the
      three directories, including ones that are expected to fail, like creating a
      file on the r/o mount.
      
      This patch:
      
      Some filesystems forego the vfs and may_open() and create their own 'struct
      file's.
      
      This patch creates a couple of helper functions which can be used by these
      filesystems, and will provide a unified place which the r/o bind mount code
      may patch.
      
      Also, rename an existing, static-scope init_file() to a less generic name.
      Signed-off-by: NDave Hansen <haveblue@us.ibm.com>
      Cc: Christoph Hellwig <hch@lst.de>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      ce8d2cdf
  7. 11 7月, 2007 3 次提交
    • J
      configfs: config item dependancies. · 631d1feb
      Joel Becker 提交于
      Sometimes other drivers depend on particular configfs items.  For
      example, ocfs2 mounts depend on a heartbeat region item.  If that
      region item is removed with rmdir(2), the ocfs2 mount must BUG or go
      readonly.  Not happy.
      
      This provides two additional API calls: configfs_depend_item() and
      configfs_undepend_item().  A client driver can call
      configfs_depend_item() on an existing item to tell configfs that it is
      depended on.  configfs will then return -EBUSY from rmdir(2) for that
      item.  When the item is no longer depended on, the client driver calls
      configfs_undepend_item() on it.
      
      These API cannot be called underneath any configfs callbacks, as
      they will conflict.  They can block and allocate.  A client driver
      probably shouldn't calling them of its own gumption.  Rather it should
      be providing an API that external subsystems call.
      
      How does this work?  Imagine the ocfs2 mount process.  When it mounts,
      it asks for a heart region item.  This is done via a call into the
      heartbeat code.  Inside the heartbeat code, the region item is looked
      up.  Here, the heartbeat code calls configfs_depend_item().  If it
      succeeds, then heartbeat knows the region is safe to give to ocfs2.
      If it fails, it was being torn down anyway, and heartbeat can gracefully
      pass up an error.
      
      [ Fixed some bad whitespace in configfs.txt. --Mark ]
      Signed-off-by: NJoel Becker <joel.becker@oracle.com>
      Signed-off-by: NMark Fasheh <mark.fasheh@oracle.com>
      631d1feb
    • J
      configfs: accessing item hierarchy during rmdir(2) · 299894cc
      Joel Becker 提交于
      Add a notification callback, ops->disconnect_notify(). It has the same
      prototype as ->drop_item(), but it will be called just before the item
      linkage is broken. This way, configfs users who want to do work while
      the object is still in the heirarchy have a chance.
      
      Client drivers will still need to config_item_put() in their
      ->drop_item(), if they implement it.  They need do nothing in
      ->disconnect_notify().  They don't have to provide it if they don't
      care.  But someone who wants to be notified before ci_parent is set to
      NULL can now be notified.
      Signed-off-by: NJoel Becker <joel.becker@oracle.com>
      Signed-off-by: NMark Fasheh <mark.fasheh@oracle.com>
      299894cc
    • J
      configfs: Convert subsystem semaphore to mutex · e6bd07ae
      Joel Becker 提交于
      Convert the su_sem member of struct configfs_subsystem to a struct
      mutex, as that's what it is. Also convert all the users and update
      Documentation/configfs.txt and Documentation/configfs_example.c
      accordingly.
      
      [ Conflict in fs/dlm/config.c with commit
        3168b078 manually resolved. --Mark ]
      Inspired-by: NSatyam Sharma <ssatyam@cse.iitk.ac.in>
      Signed-off-by: NJoel Becker <joel.becker@oracle.com>
      Signed-off-by: NMark Fasheh <mark.fasheh@oracle.com>
      e6bd07ae
  8. 15 3月, 2007 1 次提交
  9. 13 2月, 2007 1 次提交
  10. 12 2月, 2007 1 次提交
  11. 09 12月, 2006 1 次提交
  12. 02 12月, 2006 2 次提交
  13. 01 10月, 2006 1 次提交
  14. 21 9月, 2006 1 次提交
  15. 30 6月, 2006 1 次提交
  16. 27 6月, 2006 1 次提交
  17. 18 5月, 2006 2 次提交
  18. 11 4月, 2006 1 次提交
  19. 29 3月, 2006 1 次提交
  20. 04 2月, 2006 1 次提交
  21. 10 1月, 2006 1 次提交
  22. 04 1月, 2006 1 次提交