1. 12 7月, 2007 25 次提交
    • 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: fix root sysfs_dirent -> root dentry association · 0b8ead82
      Tejun Heo 提交于
      The root sysfs_dirent didn't point to the root dentry fix it.
      Signed-off-by: NTejun Heo <htejun@gmail.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      0b8ead82
    • 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: fix parent refcounting during rename and move · 7f7cfffe
      Tejun Heo 提交于
      Parent reference wasn't properly transferred during rename and move.
      Fix it.
      Signed-off-by: NTejun Heo <htejun@gmail.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      7f7cfffe
    • T
      sysfs: make sysfs_alloc_ino() static · 42b37df6
      Tejun Heo 提交于
      sysfs_alloc_ino() isn't used out side of fs/sysfs/dir.c.  Make it
      static.
      Signed-off-by: NTejun Heo <htejun@gmail.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      42b37df6
    • 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: 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: implement bin_buffer · eb361653
      Tejun Heo 提交于
      Implement bin_buffer which contains a mutex and pointer to PAGE_SIZE
      buffer to properly synchronize accesses to per-openfile buffer and
      prepare for immediate-kobj-disconnect.
      Signed-off-by: NTejun Heo <htejun@gmail.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      eb361653
    • 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
    • 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: add sysfs_dirent->s_parent · 13b3086d
      Tejun Heo 提交于
      Add sysfs_dirent->s_parent.  With this patch, each sd points to and
      holds a reference to its parent.  This allows walking sysfs tree
      without referencing sd->s_dentry which can go away anytime if the user
      doesn't control when it's deleted.
      
      sd->s_parent is initialized and parent is referenced in
      sysfs_attach_dirent().  Reference to parent is released when the sd is
      released, so as long as reference to a sd is held, s_parent can be
      followed.
      
      dentry walk in sysfs_readdir() is convereted to s_parent walk.
      
      This will be used to reimplement symlink such that it uses only
      sysfs_dirent tree.
      Signed-off-by: NTejun Heo <htejun@gmail.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      13b3086d
    • 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
    • T
      sysfs: flatten and fix sysfs_rename_dir() error handling · 996b7376
      Tejun Heo 提交于
      Error handling in sysfs_rename_dir() was broken.
      
      * When lookup_one_len() fails, 0 is returned.
      
      * If parent inode check fails, returns with inode mutex and rename
        rwsem held.
      
      This patch fixes the above bugs and flattens error handling such that
      it's more readable and easier to modify.
      Signed-off-by: NTejun Heo <htejun@gmail.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      996b7376
    • T
      sysfs: flatten cleanup paths in sysfs_add_link() and create_dir() · dfeb9fb0
      Tejun Heo 提交于
      Flatten cleanup paths in sysfs_add_link() and create_dir() to improve
      readability and ease further changes to these functions.  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>
      dfeb9fb0
    • T
      sysfs: fix error handling in binattr write() · 93e3cd82
      Tejun Heo 提交于
      Error handling in fs/sysfs/bin.c:write() was wrong because size_t
      count is used to receive return value from flush_write() which is
      negative on failure.
      
      This patch updates write() such that int variable is used instead.
      read() is updated the same way for consistency.
      Signed-off-by: NTejun Heo <htejun@gmail.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      93e3cd82
    • T
      sysfs: make sysfs_put() ignore NULL sd · 7a23ad44
      Tejun Heo 提交于
      Make sysfs_put() ignore NULL sd instead of oopsing.
      Signed-off-by: NTejun Heo <htejun@gmail.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      7a23ad44
    • T
      sysfs: allocate inode number using ida · 2b611bb7
      Tejun Heo 提交于
      sysfs used simple incrementing allocator which is not guaranteed to be
      unique.  This patch makes sysfs use ida to give each sd a unique and
      packed inode number.
      Signed-off-by: NTejun Heo <htejun@gmail.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      2b611bb7
    • T
      sysfs: move release_sysfs_dirent() to dir.c · fa7f912a
      Tejun Heo 提交于
      There is no reason this function should be inlined and soon to follow
      sysfs object reference simplification will make it heavier.  Move it
      to dir.c.
      Signed-off-by: NTejun Heo <htejun@gmail.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      fa7f912a
  2. 13 6月, 2007 3 次提交
  3. 22 5月, 2007 1 次提交
    • A
      Detach sched.h from mm.h · e8edc6e0
      Alexey Dobriyan 提交于
      First thing mm.h does is including sched.h solely for can_do_mlock() inline
      function which has "current" dereference inside. By dealing with can_do_mlock()
      mm.h can be detached from sched.h which is good. See below, why.
      
      This patch
      a) removes unconditional inclusion of sched.h from mm.h
      b) makes can_do_mlock() normal function in mm/mlock.c
      c) exports can_do_mlock() to not break compilation
      d) adds sched.h inclusions back to files that were getting it indirectly.
      e) adds less bloated headers to some files (asm/signal.h, jiffies.h) that were
         getting them indirectly
      
      Net result is:
      a) mm.h users would get less code to open, read, preprocess, parse, ... if
         they don't need sched.h
      b) sched.h stops being dependency for significant number of files:
         on x86_64 allmodconfig touching sched.h results in recompile of 4083 files,
         after patch it's only 3744 (-8.3%).
      
      Cross-compile tested on
      
      	all arm defconfigs, all mips defconfigs, all powerpc defconfigs,
      	alpha alpha-up
      	arm
      	i386 i386-up i386-defconfig i386-allnoconfig
      	ia64 ia64-up
      	m68k
      	mips
      	parisc parisc-up
      	powerpc powerpc-up
      	s390 s390-up
      	sparc sparc-up
      	sparc64 sparc64-up
      	um-x86_64
      	x86_64 x86_64-up x86_64-defconfig x86_64-allnoconfig
      
      as well as my two usual configs.
      Signed-off-by: NAlexey Dobriyan <adobriyan@gmail.com>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      e8edc6e0
  4. 10 5月, 2007 1 次提交
  5. 03 5月, 2007 2 次提交
  6. 28 4月, 2007 3 次提交
  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. 07 3月, 2007 2 次提交
    • H
      [PATCH] suspend regression: sysfs deadlock · 266d4f40
      Hugh Dickins 提交于
      Suspend deadlocks when trying to unregister /sys/block/sr0.
      
      This comes from Oliver's commit 94bebf4d
      "Driver core: fix race in sysfs between sysfs_remove_file() and
      read()/write()".
      
      sysfs_write_file downs buffer->sem while calling flush_write_buffer, and
      flushing that particular write buffer entails downing buffer->sem in
      orphan_all_buffers, resulting in the obvious self-deadlock.
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      266d4f40
    • M
      [PATCH] Fix 2.6.21 rfcomm lockups · 0de1517e
      Mark Lord 提交于
      Any attempt to open/use a bluetooth rfcomm device locks up
      scheduling completely on my machine.
      
      Interrupts (ping, alt-sysrq) seem to be alive, but nothing else.
      
      This was working fine in 2.6.20, broken now in 2.6.21-rc2-git*
      
      Reverting this change (below) fixes it:
      
      | author    Marcel Holtmann <marcel@holtmann.org>
      |      Sat, 17 Feb 2007 22:58:57 +0000 (23:58 +0100)
      | committer    David S. Miller <davem@sunset.davemloft.net>
      |      Mon, 26 Feb 2007 19:42:41 +0000 (11:42 -0800)
      | commit    c1a33136
      | tree    337a876f727061362b6a169f8759849c105b8f7a    tree | snapshot
      | parent    f5ffd462    commit | diff
      | | [Bluetooth] Make use of device_move() for RFCOMM TTY devices
      | | In the case of bound RFCOMM TTY devices the parent is not available
      | before its usage. So when opening a RFCOMM TTY device, move it to
      | the corresponding ACL device as a child. When closing the device,
      | move it back to the virtual device tree.
      | Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
      
      The simplest fix for this bug is to prevent sysfs_move_dir()
      from self-deadlocking when (old_parent == new_parent).
      
      This patch prevents total system lockup when using rfcomm devices.
      Signed-off-by: NMark Lord <mlord@pobox.com>
      Acked-by: NCornelia Huck <cornelia.huck@de.ibm.com>
      Cc: Greg KH <greg@kroah.com>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      0de1517e
  9. 24 2月, 2007 1 次提交