1. 30 11月, 2013 2 次提交
    • T
      sysfs, kernfs: prepare open, release, poll paths for kernfs · c6fb4495
      Tejun Heo 提交于
      We're in the process of separating out core sysfs functionality into
      kernfs which will deal with sysfs_dirents directly.  This patch
      prepares the rest - open, release and poll.  There isn't much to do.
      Just renaming is enough.  As sysfs_file_operations and
      sysfs_bin_operations are identical now, use the same file_operations
      for both - kernfs_file_operations.
      
      This patch doesn't introduce any behavior changes.
      Signed-off-by: NTejun Heo <tj@kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      c6fb4495
    • T
      sysfs, kernfs: replace sysfs_dirent->s_dir.kobj and ->s_attr.[bin_]attr with ->priv · 7c6e2d36
      Tejun Heo 提交于
      A directory sysfs_dirent points to the associated kobj.  A regular or
      bin file points to the associated [bin_]attribute.  This patch
      replaces sysfs_dirent->s_dir.kobj and ->s_attr.[bin_]attr with void *
      ->priv.
      
      This is to prepare for kernfs interface so that sysfs can specify the
      private data in the same way for directories and files.  This lower
      debuggability but not by much - the whole thing was overlaid in a
      union anyway.  If debuggability becomes an issue, we can later add
      ->priv accessors which explicitly check for the sysfs_dirent type and
      performs casting.
      
      This patch doesn't introduce any behavior difference.
      Signed-off-by: NTejun Heo <tj@kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      7c6e2d36
  2. 28 11月, 2013 1 次提交
    • T
      sysfs, kernfs: introduce kernfs_setattr() · 5d60418e
      Tejun Heo 提交于
      Introduce kernfs setattr interface - kernfs_setattr().
      
      sysfs_sd_setattr() is renamed to __kernfs_setattr() and
      kernfs_setattr() is a simple wrapper around it with sysfs_mutex
      locking.  sysfs_chmod_file() is updated to get an explicit ref on
      kobj->sd and then invoke kernfs_setattr() so that it doesn't have to
      use internal interface.
      
      This patch doesn't introduce any behavior differences.
      
      v2: Dummy implementation for !CONFIG_SYSFS updated to return -ENOSYS.
      Signed-off-by: NTejun Heo <tj@kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      5d60418e
  3. 30 10月, 2013 2 次提交
    • T
      sysfs: move sysfs_hash_and_remove() to fs/sysfs/dir.c · 7eed6ecb
      Tejun Heo 提交于
      Most removal related logic is implemented in fs/sysfs/dir.c.  Move
      sysfs_hash_and_remove() to fs/sysfs/dir.c so that __sysfs_remove()
      doesn't have to be public.
      
      This is pure relocation.
      Signed-off-by: NTejun Heo <tj@kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      7eed6ecb
    • T
      sysfs: merge sysfs_elem_bin_attr into sysfs_elem_attr · 56b3f3b8
      Tejun Heo 提交于
      3124eb16 ("sysfs: merge regular and bin file handling") folded bin
      file handling into regular file handling.  Among other things, bin
      file now shares the same open path including sysfs_open_dirent
      association using sysfs_dirent->s_attr.open.  This is buggy because
      ->s_bin_attr lives in the same union and doesn't have the field.  This
      bug doesn't trigger because sysfs_elem_bin_attr doesn't have an active
      field at the conflicting position.  It does have a field "buffers" but
      it isn't used anymore.
      
      This patch collapses sysfs_elem_bin_attr into sysfs_elem_attr so that
      the bin_attr is accessed through ->s_attr.bin_attr which lives with
      ->s_attr.attr in an anonymous union.  The code paths already assume
      bin_attr contains attr as the first element, so this doesn't add any
      more assumptions while making it explicit that the two types are
      handled together.
      Signed-off-by: NTejun Heo <tj@kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      56b3f3b8
  4. 06 10月, 2013 1 次提交
    • T
      sysfs: merge regular and bin file handling · 3124eb16
      Tejun Heo 提交于
      With the previous changes, sysfs regular file code is ready to handle
      bin files too.  This patch makes bin files share the regular file
      path.
      
      * sysfs_create/remove_bin_file() are moved to fs/sysfs/file.c.
      
      * sysfs_init_inode() is updated to use the new sysfs_bin_operations
        instead of bin_fops for bin files.
      
      * fs/sysfs/bin.c and the related pieces are removed.
      
      This patch shouldn't introduce any behavior difference to bin file
      accesses.
      
      Overall, this unification reduces the amount of duplicate logic, makes
      behaviors more consistent and paves the road for building simpler and
      more versatile interface which will allow other subsystems to make use
      of sysfs for their pseudo filesystems.
      
      v2: Stale fs/sysfs/bin.c reference dropped from
          Documentation/DocBook/filesystems.tmpl.  Reported by kbuild test
          robot.
      Signed-off-by: NTejun Heo <tj@kernel.org>
      Cc: Kay Sievers <kay@vrfy.org>
      Cc: kbuild test robot <fengguang.wu@intel.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      3124eb16
  5. 04 10月, 2013 2 次提交
    • T
      sysfs: introduce [__]sysfs_remove() · 250f7c3f
      Tejun Heo 提交于
      Given a sysfs_dirent, there is no reason to have multiple versions of
      removal functions.  A function which removes the specified
      sysfs_dirent and its descendants is enough.
      
      This patch intorduces [__}sysfs_remove() which replaces all internal
      variations of removal functions.  This will be the only removal
      function in the planned new sysfs_dirent based interface.
      Signed-off-by: NTejun Heo <tj@kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      250f7c3f
    • T
      sysfs: remove sysfs_addrm_cxt->parent_sd · d69ac5a0
      Tejun Heo 提交于
      sysfs_addrm_start/finish() enclose sysfs_dirent additions and
      deletions and sysfs_addrm_cxt is used to record information necessary
      to finish the operations.  Currently, sysfs_addrm_start() takes
      @parent_sd, records it in sysfs_addrm_cxt, and assumes that all
      operations in the block are performed under that @parent_sd.
      
      This assumption has been fine until now but we want to make some
      operations behave recursively and, while having @parent_sd recorded in
      sysfs_addrm_cxt doesn't necessarily prevents that, it becomes
      confusing.
      
      This patch removes sysfs_addrm_cxt->parent_sd and makes
      sysfs_add_one() take an explicit @parent_sd parameter.  Note that
      sysfs_remove_one() doesn't need the extra argument as its parent is
      always known from the target @sd.
      
      While at it, add __acquires/releases() notations to
      sysfs_addrm_start/finish() respectively.
      
      This patch doesn't make any functional difference.
      Signed-off-by: NTejun Heo <tj@kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      d69ac5a0
  6. 27 9月, 2013 1 次提交
    • T
      sysfs: @name comes before @ns · cfec0bc8
      Tejun Heo 提交于
      Some internal sysfs functions which take explicit namespace argument
      are weird in that they place the optional @ns in front of @name which
      is contrary to the established convention.  This is confusing and
      error-prone especially as @ns and @name may be interchanged without
      causing compilation warning.
      
      Swap the positions of @name and @ns in the following internal
      functions.
      
       sysfs_find_dirent()
       sysfs_rename()
       sysfs_hash_and_remove()
       sysfs_name_hash()
       sysfs_name_compare()
       create_dir()
      
      This patch doesn't introduce any functional changes.
      Signed-off-by: NTejun Heo <tj@kernel.org>
      Cc: Eric W. Biederman <ebiederm@xmission.com>
      Cc: Kay Sievers <kay@vrfy.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      cfec0bc8
  7. 22 8月, 2013 3 次提交
  8. 18 5月, 2013 1 次提交
  9. 16 5月, 2012 1 次提交
  10. 06 5月, 2012 1 次提交
  11. 09 3月, 2012 1 次提交
  12. 25 2月, 2012 1 次提交
    • M
      sysfs: Fix memory leak in sysfs_sd_setsecdata(). · 93518dd2
      Masami Ichikawa 提交于
      This patch fixies follwing two memory leak patterns that reported by kmemleak.
      sysfs_sd_setsecdata() is called during sys_lsetxattr() operation.
      It checks sd->s_iattr is NULL or not. Then if it is NULL, it calls
      sysfs_init_inode_attrs() to allocate memory.
      That code is this.
      
      iattrs = sd->s_iattr;
      if (!iattrs)
                      iattrs = sysfs_init_inode_attrs(sd);
      
      The iattrs recieves sysfs_init_inode_attrs()'s result,  but sd->s_iattr
      doesn't know the address. so it needs to set correct address to
      sd->s_iattr to free memory in other function.
      
      unreferenced object 0xffff880250b73e60 (size 32):
        comm "systemd", pid 1, jiffies 4294683888 (age 94.553s)
        hex dump (first 32 bytes):
          73 79 73 74 65 6d 5f 75 3a 6f 62 6a 65 63 74 5f  system_u:object_
          72 3a 73 79 73 66 73 5f 74 3a 73 30 00 00 00 00  r:sysfs_t:s0....
        backtrace:
          [<ffffffff814cb1d0>] kmemleak_alloc+0x73/0x98
          [<ffffffff811270ab>] __kmalloc+0x100/0x12c
          [<ffffffff8120775a>] context_struct_to_string+0x106/0x210
          [<ffffffff81207cc1>] security_sid_to_context_core+0x10b/0x129
          [<ffffffff812090ef>] security_sid_to_context+0x10/0x12
          [<ffffffff811fb0da>] selinux_inode_getsecurity+0x7d/0xa8
          [<ffffffff811fb127>] selinux_inode_getsecctx+0x22/0x2e
          [<ffffffff811f4d62>] security_inode_getsecctx+0x16/0x18
          [<ffffffff81191dad>] sysfs_setxattr+0x96/0x117
          [<ffffffff811542f0>] __vfs_setxattr_noperm+0x73/0xd9
          [<ffffffff811543d9>] vfs_setxattr+0x83/0xa1
          [<ffffffff811544c6>] setxattr+0xcf/0x101
          [<ffffffff81154745>] sys_lsetxattr+0x6a/0x8f
          [<ffffffff814efda9>] system_call_fastpath+0x16/0x1b
          [<ffffffffffffffff>] 0xffffffffffffffff
      unreferenced object 0xffff88024163c5a0 (size 96):
        comm "systemd", pid 1, jiffies 4294683888 (age 94.553s)
        hex dump (first 32 bytes):
          00 00 00 00 ed 41 00 00 00 00 00 00 00 00 00 00  .....A..........
          00 00 00 00 00 00 00 00 0c 64 42 4f 00 00 00 00  .........dBO....
        backtrace:
          [<ffffffff814cb1d0>] kmemleak_alloc+0x73/0x98
          [<ffffffff81127402>] kmem_cache_alloc_trace+0xc4/0xee
          [<ffffffff81191cbe>] sysfs_init_inode_attrs+0x2a/0x83
          [<ffffffff81191dd6>] sysfs_setxattr+0xbf/0x117
          [<ffffffff811542f0>] __vfs_setxattr_noperm+0x73/0xd9
          [<ffffffff811543d9>] vfs_setxattr+0x83/0xa1
          [<ffffffff811544c6>] setxattr+0xcf/0x101
          [<ffffffff81154745>] sys_lsetxattr+0x6a/0x8f
          [<ffffffff814efda9>] system_call_fastpath+0x16/0x1b
          [<ffffffffffffffff>] 0xffffffffffffffff
      `
      Signed-off-by: NMasami Ichikawa <masami256@gmail.com>
      Cc: stable <stable@vger.kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      93518dd2
  13. 25 1月, 2012 2 次提交
    • E
      sysfs: Kill nlink counting. · 524b6c5b
      Eric W. Biederman 提交于
      Tracking the number of subdirectories requires an extra field that increases
      the size of sysfs_dirent.  nlinks are not particularly interesting for sysfs
      and the nlink counts are wrong when network namespaces are involved so stop
      counting them, and always return nlink == 1.  Userspace already knows that
      directories with nlink == 1 have an nlink count they can't use to count
      subdirectories.
      
      This reduces the size of sysfs_dirent by 8 bytes on 64bit platforms.
      Signed-off-by: NEric W. Biederman <ebiederm@xmission.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      524b6c5b
    • E
      sysfs: Complain bitterly about attempts to remove files from nonexistent directories. · ce597919
      Eric W. Biederman 提交于
      Recently an OOPS was observed from the usb serial io_ti driver when it tried to remove
      sysfs directories.  Upon investigation it turns out this driver was always buggy
      and that a recent sysfs change had stopped guarding itself against removing attributes
      from sysfs directories that had already been removed. :(
      
      Historically we have been silent about attempting to files from nonexistent sysfs
      directories and have politely returned error codes.  That has resulted in people writing
      broken code that ignores the error codes.
      
      Issue a kernel WARNING and a stack backtrace to make it clear in no uncertain
      terms that abusing sysfs is not ok, and the callers need to fix their code.
      
      This change transforms the io_ti OOPS into a more comprehensible error message
      and stack backtrace.
      Signed-off-by: NEric W. Biederman <ebiederm@xmission.com>
      Reported-by: NWolfgang Frisch <wfpub@roembden.net>
      Cc: stable <stable@vger.kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      ce597919
  14. 04 1月, 2012 1 次提交
  15. 02 11月, 2011 1 次提交
  16. 20 10月, 2011 1 次提交
  17. 23 8月, 2011 1 次提交
  18. 20 7月, 2011 3 次提交
  19. 11 1月, 2011 1 次提交
  20. 07 1月, 2011 1 次提交
  21. 10 8月, 2010 2 次提交
  22. 05 6月, 2010 2 次提交
  23. 28 5月, 2010 1 次提交
  24. 22 5月, 2010 2 次提交
    • E
      sysfs: Implement sysfs tagged directory support. · 3ff195b0
      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/*, /sys/devices/virtual/net/*, and
      potentially a few other directories of the form /sys/ ... /net/*.
      
      What this patch does is to add an additional tag field to the
      sysfs dirent structure.  For directories that should show different
      contents depending on the context such as /sys/class/net/, and
      /sys/devices/virtual/net/ this tag field is used to specify the
      context in which those directories should be visible.  Effectively
      this is the same as creating multiple distinct directories with
      the same name but internally to sysfs the result is nicer.
      
      I am calling the concept of a single directory that looks like multiple
      directories all at the same path in the filesystem tagged directories.
      
      For the networking namespace the set of directories whose contents I need
      to filter with tags can depend on the presence or absence of hotplug
      hardware or which modules are currently loaded.  Which means I need
      a simple race free way to setup those directories as tagged.
      
      To achieve a reace free design all tagged directories are created
      and managed by sysfs itself.
      
      Users of this interface:
      - define a type in the sysfs_tag_type enumeration.
      - call sysfs_register_ns_types with the type and it's operations
      - sysfs_exit_ns when an individual tag is no longer valid
      
      - Implement mount_ns() which returns the ns of the calling process
        so we can attach it to a sysfs superblock.
      - Implement ktype.namespace() which returns the ns of a syfs kobject.
      
      Everything else is left up to sysfs and the driver layer.
      
      For the network namespace mount_ns and namespace() are essentially
      one line functions, and look to remain that.
      
      Tags are currently represented a const void * pointers as that is
      both generic, prevides enough information for equality comparisons,
      and is trivial to create for current users, as it is just the
      existing namespace pointer.
      
      The work needed in sysfs is more extensive.  At each directory
      or symlink creating I need to check if the directory it is being
      created in is a tagged directory and if so generate the appropriate
      tag to place on the sysfs_dirent.  Likewise at each symlink or
      directory removal I need to check if the sysfs directory it is
      being removed from is a tagged directory and if so figure out
      which tag goes along with the name I am deleting.
      
      Currently only directories which hold kobjects, and
      symlinks are supported.  There is not enough information
      in the current file attribute interfaces to give us anything
      to discriminate on which makes it useless, and there are
      no potential users which makes it an uninteresting problem
      to solve.
      Signed-off-by: NEric W. Biederman <ebiederm@xmission.com>
      Signed-off-by: NBenjamin Thery <benjamin.thery@bull.net>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      3ff195b0
    • E
      sysfs: Add support for tagged directories with untagged members. · af10ec77
      Eric W. Biederman 提交于
      I had hopped to avoid this but the bonding driver adds a file
      to /sys/class/net/  and the easiest way to handle that file is
      to make it untagged and to register it only once.
      
      So relax the rules on tagged directories, and make bonding work.
      Signed-off-by: NEric W. Biederman <ebiederm@aristanetworks.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      af10ec77
  25. 30 3月, 2010 1 次提交
    • T
      include cleanup: Update gfp.h and slab.h includes to prepare for breaking... · 5a0e3ad6
      Tejun Heo 提交于
      include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
      
      percpu.h is included by sched.h and module.h and thus ends up being
      included when building most .c files.  percpu.h includes slab.h which
      in turn includes gfp.h making everything defined by the two files
      universally available and complicating inclusion dependencies.
      
      percpu.h -> slab.h dependency is about to be removed.  Prepare for
      this change by updating users of gfp and slab facilities include those
      headers directly instead of assuming availability.  As this conversion
      needs to touch large number of source files, the following script is
      used as the basis of conversion.
      
        http://userweb.kernel.org/~tj/misc/slabh-sweep.py
      
      The script does the followings.
      
      * Scan files for gfp and slab usages and update includes such that
        only the necessary includes are there.  ie. if only gfp is used,
        gfp.h, if slab is used, slab.h.
      
      * When the script inserts a new include, it looks at the include
        blocks and try to put the new include such that its order conforms
        to its surrounding.  It's put in the include block which contains
        core kernel includes, in the same order that the rest are ordered -
        alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
        doesn't seem to be any matching order.
      
      * If the script can't find a place to put a new include (mostly
        because the file doesn't have fitting include block), it prints out
        an error message indicating which .h file needs to be added to the
        file.
      
      The conversion was done in the following steps.
      
      1. The initial automatic conversion of all .c files updated slightly
         over 4000 files, deleting around 700 includes and adding ~480 gfp.h
         and ~3000 slab.h inclusions.  The script emitted errors for ~400
         files.
      
      2. Each error was manually checked.  Some didn't need the inclusion,
         some needed manual addition while adding it to implementation .h or
         embedding .c file was more appropriate for others.  This step added
         inclusions to around 150 files.
      
      3. The script was run again and the output was compared to the edits
         from #2 to make sure no file was left behind.
      
      4. Several build tests were done and a couple of problems were fixed.
         e.g. lib/decompress_*.c used malloc/free() wrappers around slab
         APIs requiring slab.h to be added manually.
      
      5. The script was run on all .h files but without automatically
         editing them as sprinkling gfp.h and slab.h inclusions around .h
         files could easily lead to inclusion dependency hell.  Most gfp.h
         inclusion directives were ignored as stuff from gfp.h was usually
         wildly available and often used in preprocessor macros.  Each
         slab.h inclusion directive was examined and added manually as
         necessary.
      
      6. percpu.h was updated not to include slab.h.
      
      7. Build test were done on the following configurations and failures
         were fixed.  CONFIG_GCOV_KERNEL was turned off for all tests (as my
         distributed build env didn't work with gcov compiles) and a few
         more options had to be turned off depending on archs to make things
         build (like ipr on powerpc/64 which failed due to missing writeq).
      
         * x86 and x86_64 UP and SMP allmodconfig and a custom test config.
         * powerpc and powerpc64 SMP allmodconfig
         * sparc and sparc64 SMP allmodconfig
         * ia64 SMP allmodconfig
         * s390 SMP allmodconfig
         * alpha SMP allmodconfig
         * um on x86_64 SMP allmodconfig
      
      8. percpu.h modifications were reverted so that it could be applied as
         a separate patch and serve as bisection point.
      
      Given the fact that I had only a couple of failures from tests on step
      6, I'm fairly confident about the coverage of this conversion patch.
      If there is a breakage, it's likely to be something in one of the arch
      headers which should be easily discoverable easily on most builds of
      the specific arch.
      Signed-off-by: NTejun Heo <tj@kernel.org>
      Guess-its-ok-by: NChristoph Lameter <cl@linux-foundation.org>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
      5a0e3ad6
  26. 08 3月, 2010 2 次提交
  27. 17 2月, 2010 1 次提交
  28. 12 12月, 2009 1 次提交