1. 13 10月, 2007 3 次提交
  2. 19 7月, 2007 1 次提交
  3. 12 7月, 2007 18 次提交
    • 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_FLAG_REMOVED flag · 380e6fbb
      Tejun Heo 提交于
      Implement SYSFS_FLAG_REMOVED flag which currently is used only to
      improve sanity check in sysfs_deactivate().  The flag 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>
      380e6fbb
    • 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: make sysfs_drop_dentry() access inodes using ilookup() · d0bcb568
      Tejun Heo 提交于
      sysfs_drop_dentry() used to go through sd->s_dentry and
      sd->s_parent->s_dentry to access the inodes.  This is incorrect
      because inode can be cached without dentry.
      
      This patch makes sysfs_drop_dentry() access inodes using ilookup() on
      sd->s_ino.  This is both correct and simpler.
      Signed-off-by: NTejun Heo <htejun@gmail.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      d0bcb568
    • R
      sysfs: Fix oops in sysfs_drop_dentry on x86_64 · 9d9307da
      Rafael J. Wysocki 提交于
      Fix oops on x86_64 caused by the dereference of dir in
      sysfs_drop_dentry() made before checking if dir is not NULL
      (cf. http://marc.info/?l=linux-kernel&m=118151626704924&w=2).
      Signed-off-by: NRafael J. Wysocki <rjw@sisk.pl>
      Signed-off-by: NTejun Heo <htejun@gmail.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      9d9307da
    • 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: 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: 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
  4. 13 6月, 2007 3 次提交
  5. 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
  6. 16 3月, 2007 1 次提交
  7. 07 3月, 2007 1 次提交
    • 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
  8. 13 2月, 2007 1 次提交
  9. 08 2月, 2007 3 次提交
    • E
      sysfs: Shadow directory support · b592fcfe
      Eric W. Biederman 提交于
      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/*. 
      
      What I want is a separate /sys/class/net directory in sysfs for each
      network namespace, and I want to name each of them /sys/class/net.
      
      I looked and the VFS actually allows that.  All that is needed is
      for /sys/class/net to implement a follow link method to redirect
      lookups to the real directory you want. 
      
      Implementing a follow link method that is sensitive to the current
      network namespace turns out to be 3 lines of code so it looks like a
      clean approach.  Modifying sysfs so it doesn't get in my was is a bit
      trickier. 
      
      I am calling the concept of multiple directories all at the same path
      in the filesystem shadow directories.  With the directory entry really
      at that location the shadow master. 
      
      The following patch modifies sysfs so it can handle a directory
      structure slightly different from the kobject tree so I can implement
      the shadow directories for handling /sys/class/net/.
      Signed-off-by: NEric W. Biederman <ebiederm@xmission.com>
      Cc: Maneesh Soni <maneesh@in.ibm.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      b592fcfe
    • F
      sysfs: suppress lockdep warnings · d3fc373a
      Frederik Deweerdt 提交于
      Lockdep issues the following warning:
      [    9.064000] =============================================
      [    9.064000] [ INFO: possible recursive locking detected ]
      [    9.064000] 2.6.20-rc3-mm1 #3
      [    9.064000] ---------------------------------------------
      [    9.064000] init/1 is trying to acquire lock:
      [    9.064000]  (&sysfs_inode_imutex_key){--..}, at: [<c03e6afc>] mutex_lock+0x1c/0x1f
      [    9.064000]
      [    9.064000] but task is already holding lock:
      [    9.064000]  (&sysfs_inode_imutex_key){--..}, at: [<c03e6afc>] mutex_lock+0x1c/0x1f
      [    9.065000]
      [    9.065000] other info that might help us debug this:
      [    9.065000] 2 locks held by init/1:
      [    9.065000]  #0:  (tty_mutex){--..}, at: [<c03e6afc>] mutex_lock+0x1c/0x1f
      [    9.065000]  #1:  (&sysfs_inode_imutex_key){--..}, at: [<c03e6afc>] mutex_lock+0x1c/0x1f
      [    9.065000]
      [    9.065000] stack backtrace:
      [    9.065000]  [<c010390d>] show_trace_log_lvl+0x1a/0x30
      [    9.066000]  [<c0103935>] show_trace+0x12/0x14
      [    9.066000]  [<c0103a2f>] dump_stack+0x16/0x18
      [    9.066000]  [<c0138cb8>] print_deadlock_bug+0xb9/0xc3
      [    9.066000]  [<c0138d17>] check_deadlock+0x55/0x5a
      [    9.066000]  [<c013a953>] __lock_acquire+0x371/0xbf0
      [    9.066000]  [<c013b7a9>] lock_acquire+0x69/0x83
      [    9.066000]  [<c03e6b7e>] __mutex_lock_slowpath+0x75/0x2d1
      [    9.066000]  [<c03e6afc>] mutex_lock+0x1c/0x1f
      [    9.066000]  [<c01b249c>] sysfs_drop_dentry+0xb1/0x133
      [    9.066000]  [<c01b25d1>] sysfs_hash_and_remove+0xb3/0x142
      [    9.066000]  [<c01b30ed>] sysfs_remove_file+0xd/0x10
      [    9.067000]  [<c02849e0>] device_remove_file+0x23/0x2e
      [    9.067000]  [<c02850b2>] device_del+0x188/0x1e6
      [    9.067000]  [<c028511b>] device_unregister+0xb/0x15
      [    9.067000]  [<c0285318>] device_destroy+0x9c/0xa9
      [    9.067000]  [<c0261431>] vcs_remove_sysfs+0x1c/0x3b
      [    9.067000]  [<c0267a08>] con_close+0x5e/0x6b
      [    9.067000]  [<c02598f2>] release_dev+0x4c4/0x6e5
      [    9.067000]  [<c0259faa>] tty_release+0x12/0x1c
      [    9.067000]  [<c0174872>] __fput+0x177/0x1a0
      [    9.067000]  [<c01746f5>] fput+0x3b/0x41
      [    9.068000]  [<c0172ee1>] filp_close+0x36/0x65
      [    9.068000]  [<c0172f73>] sys_close+0x63/0xa4
      [    9.068000]  [<c0102a96>] sysenter_past_esp+0x5f/0x99
      [    9.068000]  =======================
      
      This is due to sysfs_hash_and_remove() holding dir->d_inode->i_mutex
      before calling sysfs_drop_dentry() which calls orphan_all_buffers()
      which in turn takes node->i_mutex.
      Signed-off-by: NFrederik Deweerdt <frederik.deweerdt@gmail.com>
      Cc: Oliver Neukum <oliver@neukum.org>
      Signed-off-by: NAndrew Morton <akpm@osdl.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      d3fc373a
    • O
      Driver core: fix race in sysfs between sysfs_remove_file() and read()/write() · 94bebf4d
      Oliver Neukum 提交于
      This patch prevents a race between IO and removing a file from sysfs.
      It introduces a list of sysfs_buffers associated with a file at the inode.
      Upon removal of a file the list is walked and the buffers marked orphaned.
      IO to orphaned buffers fails with -ENODEV. The driver can safely free
      associated data structures or be unloaded.
      Signed-off-by: NOliver Neukum <oliver@neukum.name>
      Acked-by: NManeesh Soni <maneesh@in.ibm.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      
      94bebf4d
  10. 27 9月, 2006 1 次提交
  11. 26 9月, 2006 1 次提交
  12. 13 7月, 2006 1 次提交
  13. 29 6月, 2006 1 次提交
  14. 01 4月, 2006 1 次提交
  15. 21 3月, 2006 2 次提交
  16. 12 1月, 2006 1 次提交