1. 13 10月, 2007 6 次提交
  2. 19 7月, 2007 1 次提交
    • T
      sysfs: cosmetic clean up on node creation failure paths · 967e35dc
      Tejun Heo 提交于
      Node addition failure is detected by testing return value of
      sysfs_addfm_finish() which returns the number of added and removed
      nodes.  As the function is called as the last step of addition right
      on top of error handling block, the if blocks looked like the
      following.
      
      	if (sysfs_addrm_finish(&acxt))
      		success handling, usually return;
      	/* fall through to error handling */
      
      This is the opposite of usual convention in sysfs and makes the code
      difficult to understand.  This patch inverts the test and makes those
      blocks look more like others.
      Signed-off-by: NTejun Heo <htejun@gmail.com>
      Cc: Gabriel C <nix.or.die@googlemail.com>
      Cc: Miles Lane <miles.lane@gmail.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      967e35dc
  3. 12 7月, 2007 11 次提交
    • 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: 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: 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: kill unnecessary attribute->owner · 7b595756
      Tejun Heo 提交于
      sysfs is now completely out of driver/module lifetime game.  After
      deletion, a sysfs node doesn't access anything outside sysfs proper,
      so there's no reason to hold onto the attribute owners.  Note that
      often the wrong modules were accounted for as owners leading to
      accessing removed modules.
      
      This patch kills now unnecessary attribute->owner.  Note that with
      this change, userland holding a sysfs node does not prevent the
      backing module from being unloaded.
      
      For more info regarding lifetime rule cleanup, please read the
      following message.
      
        http://article.gmane.org/gmane.linux.kernel/510293
      
      (tweaked by Greg to not delete the field just yet, to make it easier to
      merge things properly.)
      Signed-off-by: NTejun Heo <htejun@gmail.com>
      Cc: Cornelia Huck <cornelia.huck@de.ibm.com>
      Cc: Andrew Morton <akpm@linux-foundation.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      7b595756
    • 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: make sysfs_dirent->s_element a union · 3e519038
      Tejun Heo 提交于
      Make sd->s_element a union of sysfs_elem_{dir|symlink|attr|bin_attr}
      and rename it to s_elem.  This is to achieve...
      
      * some level of type checking : changing symlink to point to
        sysfs_dirent instead of kobject is much safer and less painful now.
      * easier / standardized dereferencing
      * allow sysfs_elem_* to contain more than one entry
      
      Where possible, pointer is obtained by directly deferencing from sd
      instead of going through other entities.  This reduces dependencies to
      dentry, inode and kobject.  to_attr() and to_bin_attr() are unused now
      and removed.
      
      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>
      3e519038
    • T
      sysfs: add sysfs_dirent->s_name · 0c096b50
      Tejun Heo 提交于
      Add s_name to sysfs_dirent.  This is to further reduce dependency to
      the associated dentry.  Name is copied for directories and symlinks
      but not for attributes.
      
      Where possible, name dereferences are converted to use sd->s_name.
      sysfs_symlink->link_name and sysfs_get_name() are unused now and
      removed.
      
      This change allows symlink to be implemented using sysfs_dirent tree
      proper, which is the last remaining dentry-dependent sysfs walk.
      Signed-off-by: NTejun Heo <htejun@gmail.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      0c096b50
    • T
      sysfs: consolidate sysfs_dirent creation functions · a26cd722
      Tejun Heo 提交于
      Currently there are four functions to create sysfs_dirent -
      __sysfs_new_dirent(), sysfs_new_dirent(), __sysfs_make_dirent() and
      sysfs_make_dirent().  Other than sysfs_make_dirent(), no function has
      two users if calls to implement other functions are excluded.
      
      This patch consolidates sysfs_dirent creation functions into the
      following two.
      
      * sysfs_new_dirent() : allocate and initialize
      * sysfs_attach_dirent() : attach to sysfs_dirent hierarchy and/or
      			  associate with dentry
      
      This simplifies interface and gives callers more flexibility.  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>
      a26cd722
  4. 10 5月, 2007 1 次提交
  5. 03 5月, 2007 1 次提交
  6. 28 4月, 2007 1 次提交
  7. 16 3月, 2007 2 次提交
    • A
      [PATCH] sysfs: reinstate exclusion between method calls and attribute unregistration · e7b0d26a
      Alan Stern 提交于
      This patch (as869) reinstates the mutual exclusion between sysfs
      attribute method calls and attribute unregistration.  The
      previously-reported deadlocks have been fixed, and this exclusion is
      by far the simplest way to avoid races during driver unbinding.
      
      The check for orphaned read-buffers has been moved down slightly, so
      that the remainder of a partially-read buffer will still be available
      to userspace even after the attribute has been unregistered.
      Signed-off-by: NAlan Stern <stern@rowland.harvard.edu>
      Cc: Hugh Dickins <hugh@veritas.com>
      Cc: Cornelia Huck <cornelia.huck@de.ibm.com>
      Cc: Oliver Neukum <oneukum@suse.de>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      e7b0d26a
    • A
      [PATCH] sysfs and driver core: add callback helper, used by SCSI and S390 · d9a9cdfb
      Alan Stern 提交于
      This patch (as868) adds a helper routine for device drivers that need
      to set up a callback to perform some action in a different process's
      context.  This is intended for use by attribute methods that want to
      unregister themselves or their parent device.  Attribute method calls
      are mutually exclusive with unregistration, so such actions cannot be
      taken directly.
      
      Two attribute methods are converted to use the new helper routine: one
      for SCSI device deletion and one for System/390 ccwgroup devices.
      Signed-off-by: NAlan Stern <stern@rowland.harvard.edu>
      Cc: Hugh Dickins <hugh@veritas.com>
      Cc: Cornelia Huck <cornelia.huck@de.ibm.com>
      Cc: Oliver Neukum <oneukum@suse.de>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      d9a9cdfb
  8. 24 2月, 2007 1 次提交
  9. 17 2月, 2007 1 次提交
  10. 08 2月, 2007 3 次提交
  11. 09 12月, 2006 1 次提交
  12. 02 12月, 2006 1 次提交
  13. 19 10月, 2006 2 次提交
    • H
      sysfs: update obsolete comment in sysfs_update_file · 97a50184
      Hidetoshi Seto 提交于
      And the obsolete comment should be updated (or totally removed).
      Signed-off-by: NHidetoshi Seto <seto.hidetoshi@jp.fujitsu.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      97a50184
    • H
      sysfs: remove duplicated dput in sysfs_update_file · e4234451
      Hidetoshi Seto 提交于
      Following function can drops d_count twice against one reference
      by lookup_one_len.
      
      <SOURCE>
      /**
       * sysfs_update_file - update the modified timestamp on an object attribute.
       * @kobj: object we're acting for.
       * @attr: attribute descriptor.
       */
      int sysfs_update_file(struct kobject * kobj, const struct attribute * attr)
      {
              struct dentry * dir = kobj->dentry;
              struct dentry * victim;
              int res = -ENOENT;
      
              mutex_lock(&dir->d_inode->i_mutex);
              victim = lookup_one_len(attr->name, dir, strlen(attr->name));
              if (!IS_ERR(victim)) {
                      /* make sure dentry is really there */
                      if (victim->d_inode &&
                          (victim->d_parent->d_inode == dir->d_inode)) {
                              victim->d_inode->i_mtime = CURRENT_TIME;
                              fsnotify_modify(victim);
      
                              /**
                               * Drop reference from initial sysfs_get_dentry().
                               */
                              dput(victim);
                              res = 0;
                      } else
                              d_drop(victim);
      
                      /**
                       * Drop the reference acquired from sysfs_get_dentry() above.
                       */
                      dput(victim);
              }
              mutex_unlock(&dir->d_inode->i_mutex);
      
              return res;
      }
      </SOURCE>
      
      PCI-hotplug (drivers/pci/hotplug/pci_hotplug_core.c) is only user of
      this function. I confirmed that dentry of /sys/bus/pci/slots/XXX/*
      have negative d_count value.
      
      This patch removes unnecessary dput().
      Signed-off-by: NHidetoshi Seto <seto.hidetoshi@jp.fujitsu.com>
      Acked-by: NManeesh Soni <maneesh@in.ibm.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      e4234451
  14. 03 10月, 2006 1 次提交
  15. 15 4月, 2006 1 次提交
    • N
      [PATCH] sysfs: Allow sysfs attribute files to be pollable · 4508a7a7
      NeilBrown 提交于
      It works like this:
        Open the file
        Read all the contents.
        Call poll requesting POLLERR or POLLPRI (so select/exceptfds works)
        When poll returns,
           close the file and go to top of loop.
         or lseek to start of file and go back to the 'read'.
      
      Events are signaled by an object manager calling
         sysfs_notify(kobj, dir, attr);
      
      If the dir is non-NULL, it is used to find a subdirectory which
      contains the attribute (presumably created by sysfs_create_group).
      
      This has a cost of one int  per attribute, one wait_queuehead per kobject,
      one int per open file.
      
      The name "sysfs_notify" may be confused with the inotify
      functionality.  Maybe it would be nice to support inotify for sysfs
      attributes as well?
      
      This patch also uses sysfs_notify to allow /sys/block/md*/md/sync_action
      to be pollable
      Signed-off-by: NNeil Brown <neilb@suse.de>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      4508a7a7
  16. 03 4月, 2006 1 次提交
  17. 29 3月, 2006 1 次提交
  18. 21 3月, 2006 2 次提交
  19. 10 1月, 2006 1 次提交
  20. 30 7月, 2005 1 次提交