1. 23 4月, 2008 1 次提交
  2. 31 10月, 2007 1 次提交
  3. 17 10月, 2007 1 次提交
  4. 13 10月, 2007 16 次提交
  5. 19 7月, 2007 1 次提交
  6. 12 7月, 2007 20 次提交
    • T
      sysfs: make directory dentries and inodes reclaimable · 51225039
      Tejun Heo 提交于
      This patch makes dentries and inodes for sysfs directories
      reclaimable.
      
      * sysfs_notify() is modified to walk sysfs_dirent tree instead of
        dentry tree.
      
      * sysfs_update_file() and sysfs_chmod_file() use sysfs_get_dentry() to
        grab the victim dentry.
      
      * sysfs_rename_dir() and sysfs_move_dir() grab all dentries using
        sysfs_get_dentry() on startup.
      
      * Dentries for all shadowed directories are pinned in memory to serve
        as lookup start point.
      Signed-off-by: NTejun Heo <htejun@gmail.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      51225039
    • T
      sysfs: implement sysfs_get_dentry() · 53e0ae92
      Tejun Heo 提交于
      Some sysfs operations require dentry and inode.  sysfs_get_dentry()
      looks up and gets dentry for the specified sysfs_dirent.  It finds the
      first ancestor with dentry attached and starts looking up dentries
      from there.
      
      Looking up from the nearest ancestor is necessary to support shadowed
      directories because we can't reliably lookup dentry for one of the
      shadows.  Dentries for each shadow will be pinned in memory such that
      they can serve as the starting point for dentry lookup.
      Signed-off-by: NTejun Heo <htejun@gmail.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      53e0ae92
    • T
      sysfs: move sysfs_drop_dentry() to dir.c and make it static · a0edd7c8
      Tejun Heo 提交于
      After add/remove path restructuring, the only user of
      sysfs_drop_dentry() is sysfs_addrm_finish().  Move sysfs_drop_dentry()
      to dir.c and make it static.
      Signed-off-by: NTejun Heo <htejun@gmail.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      a0edd7c8
    • T
      sysfs: restructure add/remove paths and fix inode update · fb6896da
      Tejun Heo 提交于
      The original add/remove code had the following problems.
      
      * parent's timestamps are updated on dentry instantiation.  this is
        incorrect with reclaimable files.
      
      * updating parent's timestamps isn't synchronized.
      
      * parent nlink update assumes the inode is accessible which won't be
        true once directory dentries are made reclaimable.
      
      This patch restructures add/remove paths to resolve the above
      problems.  Add/removal are done in the following steps.
      
      1. sysfs_addrm_start() : acquire locks including sysfs_mutex and other
         resources.
      
      2-a. sysfs_add_one() : add new sd.  linking the new sd into the
           children list is caller's responsibility.
      
      2-b. sysfs_remove_one() : remove a sd.  unlinking the sd from the
           children list is caller's responsibility.
      
      3. sysfs_addrm_finish() : release all resources and clean up.
      
      Steps 2-a and/or 2-b can be repeated multiple times.
      
      Parent's inode is looked up during sysfs_addrm_start().  If available
      (always at the moment), it's pinned and nlink is updated as sd's are
      added and removed.  Timestamps are updated during finish if any sd has
      been added or removed.  If parent's inode is not available during
      start, sysfs_mutex ensures that parent inode is not created till
      add/remove is complete.
      
      All the complexity is contained inside the helper functions.
      Especially, dentry/inode handling is properly hidden from the rest of
      sysfs which now mostly operate on sysfs_dirents.  As an added bonus,
      codes which use these helpers to add and remove sysfs_dirents are now
      more structured and simpler.
      Signed-off-by: NTejun Heo <htejun@gmail.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      fb6896da
    • T
      sysfs: use sysfs_mutex to protect the sysfs_dirent tree · 3007e997
      Tejun Heo 提交于
      As kobj sysfs dentries and inodes are gonna be made reclaimable,
      i_mutex can't be used to protect sysfs_dirent tree.  Use sysfs_mutex
      globally instead.  As the whole tree is protected with sysfs_mutex,
      there is no reason to keep sysfs_rename_sem.  Drop it.
      
      While at it, add docbook comments to functions which require
      sysfs_mutex locking.
      Signed-off-by: NTejun Heo <htejun@gmail.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      3007e997
    • T
      sysfs: consolidate sysfs spinlocks · 5f995323
      Tejun Heo 提交于
      Replace sysfs_lock and kobj_sysfs_assoc_lock with sysfs_assoc_lock.
      sysfs_lock was originally to be used to protect sysfs_dirent tree but
      mutex seems better choice, so there is no reason to keep sysfs_lock
      separate.  Merge the two spinlocks into one.
      Signed-off-by: NTejun Heo <htejun@gmail.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      5f995323
    • T
      sysfs: make kobj point to sysfs_dirent instead of dentry · 608e266a
      Tejun Heo 提交于
      As kobj sysfs dentries and inodes are gonna be made reclaimable,
      dentry can't be used as naming token for sysfs file/directory, replace
      kobj->dentry with kobj->sd.  The only external interface change is
      shadow directory handling.  All other changes are contained in kobj
      and sysfs.
      Signed-off-by: NTejun Heo <htejun@gmail.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      608e266a
    • T
      sysfs: implement sysfs_find_dirent() and sysfs_get_dirent() · f0b0af47
      Tejun Heo 提交于
      Implement sysfs_find_dirent() and sysfs_get_dirent().
      sysfs_dirent_exist() is replaced by sysfs_find_dirent().  These will
      be used to make directory entries reclamiable.
      Signed-off-by: NTejun Heo <htejun@gmail.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      f0b0af47
    • T
      sysfs: rename sysfs_dirent->s_type to s_flags and make room for flags · b402d72c
      Tejun Heo 提交于
      Rename sysfs_dirent->s_type to s_flags, pack type into lower eight
      bits and reserve the rest for flags.  sysfs_type() can used to access
      the type.  All existing sd->s_type accesses are converted to use
      sysfs_type().  While at it, type test is changed to equality test
      instead of bit-and test where appropriate.
      Signed-off-by: NTejun Heo <htejun@gmail.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      b402d72c
    • T
      sysfs: use singly-linked list for sysfs_dirent tree · 0c73f18b
      Tejun Heo 提交于
      Make sysfs_dirent use singly linked list for its tree structure.
      sysfs_link_sibling() and sysfs_unlink_sibling() functions are added to
      handle simpler cases.  It adds some complexity and cpu cycle overhead
      but reduced memory footprint is worthwhile on big machines.
      
      This change reduces the sizeof sysfs_dirent from 104 to 88 on 64bit
      and from 60 to 52 on 32bit.
      Signed-off-by: NTejun Heo <htejun@gmail.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      0c73f18b
    • T
      sysfs: slim down sysfs_dirent->s_active · 8619f979
      Tejun Heo 提交于
      Make sysfs_dirent->s_active an atomic_t instead of rwsem.  This
      reduces the size of sysfs_dirent from 136 to 104 on 64bit and from 76
      to 60 on 32bit with lock debugging turned off.  With lock debugging
      turned on the reduction is much larger.
      
      s_active starts at zero and each active reference increments s_active.
      Putting a reference decrements s_active.  Deactivation subtracts
      SD_DEACTIVATED_BIAS which is currently INT_MIN and assumed to be small
      enough to make s_active negative.  If s_active is negative,
      sysfs_get() no longer grants new references.  Deactivation succeeds
      immediately if there is no active user; otherwise, it waits using a
      completion for the last put.
      
      Due to the removal of lockdep tricks, this change makes things less
      trickier in release_sysfs_dirent().  As all the complexity is
      contained in three s_active functions, I think it's more readable this
      way.
      Signed-off-by: NTejun Heo <htejun@gmail.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      8619f979
    • T
      sysfs: move s_active functions to fs/sysfs/dir.c · b6b4a439
      Tejun Heo 提交于
      These functions are about to receive more complexity and doesn't
      really need to be inlined in the first place.  Move them from
      fs/sysfs/sysfs.h to fs/sysfs/dir.c.
      Signed-off-by: NTejun Heo <htejun@gmail.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      b6b4a439
    • T
      sysfs: use iget_locked() instead of new_inode() · 8312a8d7
      Tejun Heo 提交于
      After dentry is reclaimed, sysfs always used to allocate new dentry
      and inode if the file is accessed again.  This causes problem with
      operations which only pin the inode.  For example, if inotify watch is
      added to a sysfs file and the dentry for the file is reclaimed, the
      next update event creates new dentry and new inode making the inotify
      watch miss all the events from there on.
      
      This patch fixes it by using iget_locked() instead of new_inode().
      sysfs_new_inode() is renamed to sysfs_get_inode() and inode is
      initialized iff the inode is newly allocated.  sysfs_instantiate() is
      responsible for unlocking new inodes.
      Signed-off-by: NTejun Heo <htejun@gmail.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      8312a8d7
    • T
      sysfs: reorganize sysfs_new_indoe() and sysfs_create() · fc9f54b9
      Tejun Heo 提交于
      Reorganize/clean up sysfs_new_inode() and sysfs_create().
      
      * sysfs_init_inode() is separated out from sysfs_new_inode() and is
        responsible for basic initialization.
      * sysfs_instantiate() replaces the last step of sysfs_create() and is
        responsible for dentry instantitaion.
      * type-specific initialization is moved out to the callers.
      * mode is specified only once when creating a sysfs_dirent.
      * spurious list_del_init(&sd->s_sibling) dropped from create_dir()
      
      This change is to
      
      * prepare for inode allocation fix.
      * separate alloc and init code for synchronization update.
      * make dentry/inode initialization more flexible for later changes.
      
      This patch doesn't introduce visible behavior change.
      Signed-off-by: NTejun Heo <htejun@gmail.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      fc9f54b9
    • T
      sysfs: reimplement sysfs_drop_dentry() · dbde0fcf
      Tejun Heo 提交于
      This patch reimplements sysfs_drop_dentry() such that remove_dir() can
      use it to drop dentry instead of using a separate mechanism.  With
      this change, making directories reclaimable is much easier.
      
      This patch used to contain fixes for two race conditions around
      sd->s_dentry but that part has been separated out and included into
      mainline early as commit 6aa054aa and
      dd14cbc9.
      Signed-off-by: NTejun Heo <htejun@gmail.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      dbde0fcf
    • T
      sysfs: separate out sysfs_attach_dentry() · 198a2a84
      Tejun Heo 提交于
      Consolidate sd <-> dentry association into sysfs_attach_dentry() and
      call it after dentry and inode are properly set up.  This is in
      preparation of sysfs_drop_dentry() updates.
      Signed-off-by: NTejun Heo <htejun@gmail.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      198a2a84
    • T
      sysfs: kill attribute file orphaning · 73107cb3
      Tejun Heo 提交于
      Now that sysfs_dirent can be disconnected from kobject on deletion,
      there is no need to orphan each attribute files.  All [bin_]attribute
      nodes are automatically orphaned when the parent node is deleted.
      Kill attribute file orphaning.
      Signed-off-by: NTejun Heo <htejun@gmail.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      73107cb3
    • T
      sysfs: implement sysfs_dirent active reference and immediate disconnect · 0ab66088
      Tejun Heo 提交于
      sysfs: implement sysfs_dirent active reference and immediate disconnect
      
      Opening a sysfs node references its associated kobject, so userland
      can arbitrarily prolong lifetime of a kobject which complicates
      lifetime rules in drivers.  This patch implements active reference and
      makes the association between kobject and sysfs immediately breakable.
      
      Now each sysfs_dirent has two reference counts - s_count and s_active.
      s_count is a regular reference count which guarantees that the
      containing sysfs_dirent is accessible.  As long as s_count reference
      is held, all sysfs internal fields in sysfs_dirent are accessible
      including s_parent and s_name.
      
      The newly added s_active is active reference count.  This is acquired
      by invoking sysfs_get_active() and it's the caller's responsibility to
      ensure sysfs_dirent itself is accessible (should be holding s_count
      one way or the other).  Dereferencing sysfs_dirent to access objects
      out of sysfs proper requires active reference.  This includes access
      to the associated kobjects, attributes and ops.
      
      The active references can be drained and denied by calling
      sysfs_deactivate().  All active sysfs_dirents must be deactivated
      after deletion but before the default reference is dropped.  This
      enables immediate disconnect of sysfs nodes.  Once a sysfs_dirent is
      deleted, it won't access any entity external to sysfs proper.
      
      Because attr/bin_attr ops access both the node itself and its parent
      for kobject, they need to hold active references to both.
      sysfs_get/put_active_two() helpers are provided to help grabbing both
      references.  Parent's is acquired first and released last.
      
      Unlike other operations, mmapped area lingers on after mmap() is
      finished and the module implement implementing it and kobj need to
      stay referenced till all the mapped pages are gone.  This is
      accomplished by holding one set of active references to the bin_attr
      and its parent if there have been any mmap during lifetime of an
      openfile.  The references are dropped when the openfile is released.
      
      This change makes sysfs lifetime rules independent from both kobject's
      and module's.  It not only fixes several race conditions caused by
      sysfs not holding onto the proper module when referencing kobject, but
      also helps fixing and simplifying lifetime management in driver model
      and drivers by taking sysfs out of the equation.
      
      Please read the following message for more info.
      
        http://article.gmane.org/gmane.linux.kernel/510293Signed-off-by: NTejun Heo <htejun@gmail.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      0ab66088
    • T
      sysfs: reimplement symlink using sysfs_dirent tree · 2b29ac25
      Tejun Heo 提交于
      sysfs symlink is implemented by referencing dentry and kobject from
      sysfs_dirent - symlink entry references kobject, dentry is used to
      walk the tree.  This complicates object lifetimes rules and is
      dangerous - for example, there is no way to tell to which module the
      target of a symlink belongs and referencing that kobject can make it
      linger after the module is gone.
      
      This patch reimplements symlink using only sysfs_dirent tree.  sd for
      a symlink points and holds reference to the target sysfs_dirent and
      all walking is done using sysfs_dirent tree.  Simpler and safer.
      
      Please read the following message for more info.
      
        http://article.gmane.org/gmane.linux.kernel/510293Signed-off-by: NTejun Heo <htejun@gmail.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      2b29ac25
    • T
      sysfs: implement kobj_sysfs_assoc_lock · aecdceda
      Tejun Heo 提交于
      kobj->dentry can go away anytime unless the user controls when the
      associated sysfs node is deleted.  This patch implements
      kobj_sysfs_assoc_lock which protects kobj->dentry.  This will be used
      to maintain kobj based API when converting sysfs to use sysfs_dirent
      tree instead of dentry/kobject.
      
      Note that this lock belongs to kobject/driver-model not sysfs.  Once
      sysfs is converted to not use kobject in its interface, this can be
      removed from sysfs.
      
      This is in preparation of object reference simplification.
      Signed-off-by: NTejun Heo <htejun@gmail.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      aecdceda