05 Sep, 2012

1 commit


27 Jul, 2010

3 commits

  • Supporting symlinks from untagged to tagged directories is reasonable,
    and needed to support CONFIG_SYSFS_DEPRECATED. So don't fail a prior
    allowing that case to work.

    Signed-off-by: Eric W. Biederman
    Signed-off-by: Greg Kroah-Hartman

    Eric W. Biederman
     
  • This happens for network devices when SYSFS_DEPRECATED is enabled.

    Signed-off-by: Eric W. Biederman
    Signed-off-by: Greg Kroah-Hartman

    Eric W. Biederman
     
  • Recently my tagged sysfs support revealed a flaw in the device core
    that a few rare drivers are running into such that we don't always put
    network devices in a class subdirectory named net/.

    Since we are not creating the class directory the network devices wind
    up in a non-tagged directory, but the symlinks to the network devices
    from /sys/class/net are in a tagged directory. All of which works
    until we go to remove or rename the symlink. When we remove or rename
    a symlink we look in the namespace of the target of the symlink.
    Since the target of the symlink is in a non-tagged sysfs directory we
    don't have a namespace to look in, and we fail to remove the symlink.

    Detect this problem up front and simply don't create symlinks we won't
    be able to remove later. This prevents symlink leakage and fails in
    a much clearer and more understandable way.

    Signed-off-by: Eric W. Biederman
    Cc: Andrew Morton
    Cc: Rafael J. Wysocki
    Cc: Maciej W. Rozycki
    Cc: Kay Sievers
    Cc: Johannes Berg
    Signed-off-by: Greg Kroah-Hartman

    Eric W. Biederman
     

22 May, 2010

2 commits

  • When removing a symlink sysfs_remove_link does not provide
    enough information to figure out which tagged directory the symlink
    falls in. So I need sysfs_delete_link which is passed the target
    of the symlink to delete.

    sysfs_rename_link is updated to call sysfs_delete_link instead
    of sysfs_remove_link as we have all of the information necessary
    and the callers are interesting.

    Both of these functions now have enough information to find a symlink
    in a tagged directory. The only restriction is that they must be called
    before the target kobject is renamed or deleted. If they are called
    later I loose track of which tag the target kobject was marked with
    and can no longer find the old symlink to remove it.

    This patch was split from an earlier patch.

    Signed-off-by: Eric W. Biederman
    Signed-off-by: Benjamin Thery
    Signed-off-by: Daniel Lezcano
    Acked-by: Tejun Heo
    Signed-off-by: Greg Kroah-Hartman

    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: Eric W. Biederman
    Signed-off-by: Benjamin Thery
    Signed-off-by: Greg Kroah-Hartman

    Eric W. Biederman
     

16 May, 2010

1 commit

  • Links for each port are created in sysfs using the device
    name, but this could be changed after being added to the
    bridge.

    As well as being unable to remove interfaces after this
    occurs (because userspace tools don't recognise the new
    name, and the kernel won't recognise the old name), adding
    another interface with the old name to the bridge will
    cause an error trying to create the sysfs link.

    This fixes the problem by listening for NETDEV_CHANGENAME
    notifications and renaming the link.

    https://bugzilla.kernel.org/show_bug.cgi?id=12743

    Signed-off-by: Simon Arlott
    Acked-by: Stephen Hemminger
    Signed-off-by: David S. Miller

    Simon Arlott
     

30 Mar, 2010

1 commit

  • …it 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: Tejun Heo <tj@kernel.org>
    Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
    Cc: Ingo Molnar <mingo@redhat.com>
    Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>

    Tejun Heo
     

08 Mar, 2010

1 commit

  • Because of rename ordering problems we occassionally give false
    warnings about invalid sysfs operations. So using sysfs_rename
    create a sysfs_rename_link function that doesn't need strange
    workarounds.

    Cc: Benjamin Thery
    Cc: Daniel Lezcano
    Acked-by: Serge Hallyn
    Acked-by: Tejun Heo
    Signed-off-by: Eric W. Biederman
    Signed-off-by: Greg Kroah-Hartman

    Eric W. Biederman
     

12 Dec, 2009

2 commits

  • With the implementation of sysfs_getattr and sysfs_permission
    sysfs becomes able to lazily propogate inode attribute changes
    from the sysfs_dirents to the vfs inodes. This paves the way
    for deleting significant chunks of now unnecessary code.

    While doing this we did not reference sysfs_setattr from
    sysfs_symlink_inode_operations so I added along with
    sysfs_getattr and sysfs_permission.

    Acked-by: Tejun Heo
    Acked-by: Serge Hallyn
    Signed-off-by: Eric W. Biederman
    Signed-off-by: Greg Kroah-Hartman

    Eric W. Biederman
     
  • Lining up the functions in sysfs_symlink_inode_operations
    follows the pattern in the rest of sysfs and makes things
    slightly more readable.

    Acked-by: Tejun Heo
    Acked-by: Serge Hallyn
    Signed-off-by: Eric W. Biederman
    Signed-off-by: Greg Kroah-Hartman

    Eric W. Biederman
     

10 Sep, 2009

1 commit

  • This patch adds a setxattr handler to the file, directory, and symlink
    inode_operations structures for sysfs. The patch uses hooks introduced in the
    previous patch to handle the getting and setting of security information for
    the sysfs inodes. As was suggested by Eric Biederman the struct iattr in the
    sysfs_dirent structure has been replaced by a structure which contains the
    iattr, secdata and secdata length to allow the changes to persist in the event
    that the inode representing the sysfs_dirent is evicted. Because sysfs only
    stores this information when a change is made all the optional data is moved
    into one dynamically allocated field.

    This patch addresses an issue where SELinux was denying virtd access to the PCI
    configuration entries in sysfs. The lack of setxattr handlers for sysfs
    required that a single label be assigned to all entries in sysfs. Granting virtd
    access to every entry in sysfs is not an acceptable solution so fine grained
    labeling of sysfs is required such that individual entries can be labeled
    appropriately.

    [sds: Fixed compile-time warnings, coding style, and setting of inode security init flags.]

    Signed-off-by: David P. Quigley
    Signed-off-by: Stephen D. Smalley
    Signed-off-by: James Morris

    David P. Quigley
     

16 Jun, 2009

1 commit


22 Jul, 2008

1 commit

  • driver core: Suppress sysfs warnings for device_rename().

    Renaming network devices to an already existing name is not
    something we want sysfs to print a scary warning for, since the
    callers can deal with this correctly. So let's introduce
    sysfs_create_link_nowarn() which gets rid of the common warning.

    Signed-off-by: Cornelia Huck
    Signed-off-by: Greg Kroah-Hartman

    Cornelia Huck
     

18 Apr, 2008

1 commit

  • Allow callers of sysfs_remove_link() to pass a NULL kobj, in which case
    sysfs_root will be used as the parent directory. This allows us to tear down
    top level symlinks created via sysfs_create_link(), which already has
    similar handling of a NULL parent object.

    Signed-off-by: Mark Fasheh
    Acked-by: Greg Kroah-Hartman

    Mark Fasheh
     

25 Jan, 2008

1 commit

  • Instead of walking from the source down to the root of sysfs, and back
    to the target, we stop at the first directory the source and the target
    share.

    This link:
    /devices/pci0000:00/0000:00:1d.7/usb1/1-0:1.0/ep_81

    pointed to:
    ../../../../../devices/pci0000:00/0000:00:1d.0/usb2/2-0:1.0/usb_endpoint/usbdev2.1_ep81

    now it just points to:
    usb_endpoint/usbdev1.1_ep81

    Thanks to Denis Cheng for bringing this up, and sending the initial patch.

    CC: Denis Cheng
    Signed-off-by: Kay Sievers
    Signed-off-by: Greg Kroah-Hartman

    Kay Sievers
     

13 Oct, 2007

6 commits

  • Sysfs has gone through considerable amount of reimplementation. Add
    copyrights. Any objections? :-)

    Signed-off-by: Tejun Heo
    Signed-off-by: Greg Kroah-Hartman

    Tejun Heo
     
  • Make s_elem an anonymous union. Prefixing with s_elem makes things
    needlessly longer without any advantage.

    Signed-off-by: Tejun Heo
    Acked-by: Cornelia Huck
    Signed-off-by: Greg Kroah-Hartman

    Tejun Heo
     
  • This patch modifies the users of sysfs_mount to use sysfs_root
    instead (which is what they are looking for). It then
    makes sysfs_mount static to keep people from using it
    by accident.

    The net result is slightly faster and cleaner code.

    Signed-off-by: Eric W. Biederman
    Signed-off-by: Tejun Heo
    Cc: Cornelia Huck
    Signed-off-by: Greg Kroah-Hartman

    Eric W. Biederman
     
  • Make sysfs_add_one() check for duplicate entry and return -EEXIST if
    such entry exists. This simplifies node addition code a bit.

    This patch doesn't introduce any noticeable behavior change.

    Signed-off-by: Tejun Heo
    Acked-by: Cornelia Huck
    Signed-off-by: Greg Kroah-Hartman

    Tejun Heo
     
  • When adding or removing a sysfs_dirent, the user used to be required
    to call link/unlink separately. It was for two reasons - code looked
    like that before sysfs_addrm_cxt conversion and to avoid looping
    through parent_sd->children list twice during removal.

    Performance optimization during removal just isn't worth it. Make
    sysfs_add/remove_one() call sysfs_link/unlink_sibing() implicitly.
    This makes code simpler albeit slightly less efficient. This change
    doesn't introduce any noticeable behavior change.

    Signed-off-by: Tejun Heo
    Acked-by: Cornelia Huck
    Signed-off-by: Greg Kroah-Hartman

    Tejun Heo
     
  • Cleanup semaphore.h

    Signed-off-by: Dave Young
    Signed-off-by: Greg Kroah-Hartman

    Dave Young
     

19 Jul, 2007

2 commits

  • 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: Tejun Heo
    Cc: Gabriel C
    Cc: Miles Lane
    Signed-off-by: Greg Kroah-Hartman

    Tejun Heo
     
  • There is a subtle bug in sysfs_create_link() failure path. When
    symlink creation fails because there's already a node with the same
    name, the target sysfs_dirent is put twice - once by failure path of
    sysfs_create_link() and once more when the symlink is released.

    Fix it by making only the symlink node responsible for putting
    target_sd.

    Signed-off-by: Tejun Heo
    Cc: Gabriel C
    Cc: Miles Lane
    Signed-off-by: Greg Kroah-Hartman

    Tejun Heo
     

12 Jul, 2007

10 commits

  • 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: Tejun Heo
    Signed-off-by: Greg Kroah-Hartman

    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: Tejun Heo
    Signed-off-by: Greg Kroah-Hartman

    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: Tejun Heo
    Signed-off-by: Greg Kroah-Hartman

    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: Tejun Heo
    Signed-off-by: Greg Kroah-Hartman

    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: Tejun Heo
    Signed-off-by: Greg Kroah-Hartman

    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/510293

    Signed-off-by: Tejun Heo
    Signed-off-by: Greg Kroah-Hartman

    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: Tejun Heo
    Signed-off-by: Greg Kroah-Hartman

    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: Tejun Heo
    Signed-off-by: Greg Kroah-Hartman

    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: Tejun Heo
    Signed-off-by: Greg Kroah-Hartman

    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: Tejun Heo
    Signed-off-by: Greg Kroah-Hartman

    Tejun Heo
     

13 Feb, 2007

1 commit

  • Many struct inode_operations in the kernel can be "const". Marking them const
    moves these to the .rodata section, which avoids false sharing with potential
    dirty data. In addition it'll catch accidental writes at compile time to
    these shared resources.

    Signed-off-by: Arjan van de Ven
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Arjan van de Ven
     

08 Feb, 2007

1 commit

  • 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: Oliver Neukum
    Acked-by: Maneesh Soni
    Signed-off-by: Greg Kroah-Hartman

    Oliver Neukum
     

26 Sep, 2006

1 commit


21 Mar, 2006

2 commits


10 Jan, 2006

1 commit