27 Sep, 2013

4 commits

  • The pre-existing sysfs interfaces 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. For example,
    we end up forcing vast majority of sysfs_get_dirent() users to do
    sysfs_get_dirent(parent, NULL, name), which is silly and error-prone
    especially as @ns and @name may be interchanged without causing
    compilation warning.

    This renames sysfs_get_dirent() to sysfs_get_dirent_ns() and swap the
    positions of @name and @ns, and sysfs_get_dirent() is now a wrapper
    around sysfs_get_dirent_ns(). This makes confusions a lot less
    likely.

    There are other interfaces which take @ns before @name. They'll be
    updated by following patches.

    This patch doesn't introduce any functional changes.

    v2: EXPORT_SYMBOL_GPL() wasn't updated leading to undefined symbol
    error on module builds. Reported by build test robot. Fixed.

    Signed-off-by: Tejun Heo
    Cc: Eric W. Biederman
    Cc: Kay Sievers
    Cc: Fengguang Wu
    Signed-off-by: Greg Kroah-Hartman

    Tejun Heo
     
  • There's no reason for sysfs to be calling ktype->namespace(). It is
    backwards, obfuscates what's going on and unnecessarily tangles two
    separate layers.

    There are two places where symlink code calls ktype->namespace().

    * sysfs_do_create_link_sd() calls it to find out the namespace tag of
    the target directory. Unless symlinking races with cross-namespace
    renaming, this equals @target_sd->s_ns.

    * sysfs_rename_link() uses it to find out the new namespace to rename
    to and the new namespace can be different from the existing one.
    The function is renamed to sysfs_rename_link_ns() with an explicit
    @ns argument and the ktype->namespace() invocation is shifted to the
    device layer.

    While this patch replaces ktype->namespace() invocation with the
    recorded result in @target_sd, this shouldn't result in any behvior
    difference.

    Signed-off-by: Tejun Heo
    Cc: Eric W. Biederman
    Cc: Kay Sievers
    Signed-off-by: Greg Kroah-Hartman

    Tejun Heo
     
  • For some unrecognizable reason, namespace information is communicated
    to sysfs through ktype->namespace() callback when there's *nothing*
    which needs the use of a callback. The whole sequence of operations
    is completely synchronous and sysfs operations simply end up calling
    back into the layer which just invoked it in order to find out the
    namespace information, which is completely backwards, obfuscates
    what's going on and unnecessarily tangles two separate layers.

    This patch doesn't remove ktype->namespace() but shifts its handling
    to kobject layer. We probably want to get rid of the callback in the
    long term.

    This patch adds an explicit param to sysfs_{create|rename|move}_dir()
    and renames them to sysfs_{create|rename|move}_dir_ns(), respectively.
    ktype->namespace() invocations are moved to the calling sites of the
    above functions. A new helper kboject_namespace() is introduced which
    directly tests kobj_ns_type_operations->type which should give the
    same result as testing sysfs_fs_type(parent_sd) and returns @kobj's
    namespace tag as necessary. kobject_namespace() is extern as it will
    be used from another file in the following patches.

    This patch should be an equivalent conversion without any functional
    difference.

    Signed-off-by: Tejun Heo
    Cc: Eric W. Biederman
    Cc: Kay Sievers
    Signed-off-by: Greg Kroah-Hartman

    Tejun Heo
     
  • sysfs ns (namespace) implementation became more convoluted than
    necessary while trying to hide ns information from visible interface.
    The relatively recent attr ns support is a good example.

    * attr ns tag is determined by sysfs_ops->namespace() callback while
    dir tag is determined by kobj_type->namespace(). The placement is
    arbitrary.

    * Instead of performing operations with explicit ns tag, the namespace
    callback is routed through sysfs_attr_ns(), sysfs_ops->namespace(),
    class_attr_namespace(), class_attr->namespace(). It's not simpler
    in any sense. The only thing this convolution does is traversing
    the whole stack backwards.

    The namespace callbacks are unncessary because the operations involved
    are inherently synchronous. The information can be provided in in
    straight-forward top-down direction and reversing that direction is
    unnecessary and against basic design principles.

    This backward interface is unnecessarily convoluted and hinders
    properly separating out sysfs from driver model / kobject for proper
    layering. This patch updates attr ns support such that

    * sysfs_ops->namespace() and class_attr->namespace() are dropped.

    * sysfs_{create|remove}_file_ns(), which take explicit @ns param, are
    added and sysfs_{create|remove}_file() are now simple wrappers
    around the ns aware functions.

    * ns handling is dropped from sysfs_chmod_file(). Nobody uses it at
    this point. sysfs_chmod_file_ns() can be added later if necessary.

    * Explicit @ns is propagated through class_{create|remove}_file_ns()
    and netdev_class_{create|remove}_file_ns().

    * driver/net/bonding which is currently the only user of attr
    namespace is updated to use netdev_class_{create|remove}_file_ns()
    with @bh->net as the ns tag instead of using the namespace callback.

    This patch should be an equivalent conversion without any functional
    difference. It makes the code easier to follow, reduces lines of code
    a bit and helps proper separation and layering.

    Signed-off-by: Tejun Heo
    Cc: Eric W. Biederman
    Cc: Kay Sievers
    Acked-by: David S. Miller
    Signed-off-by: Greg Kroah-Hartman

    Tejun Heo
     

29 Aug, 2013

1 commit


28 Aug, 2013

1 commit


24 Aug, 2013

1 commit


23 Aug, 2013

1 commit

  • Gotta love a macro that doesn't reduce the typing you have to do.

    Also, only the driver core, and one network driver uses this. The
    driver core functions will be going away soon, and I'll convert the
    network driver soon to not need this as well, so delete it for now
    before anyone else gets some bright ideas and wants to use it.

    Signed-off-by: Greg Kroah-Hartman

    Greg Kroah-Hartman
     

22 Aug, 2013

2 commits


21 Aug, 2013

1 commit

  • __BIN_ATTR_RW() wasn't passing in the _size field. As it would break
    the build if this macro was ever used, it's obvious no one had ever
    tried to use it before.

    Fix it so that it can be used.

    Signed-off-by: Greg Kroah-Hartman

    Greg Kroah-Hartman
     

17 Jul, 2013

6 commits


26 Jan, 2013

1 commit

  • The most convenient way to expose ACPI power resources lists of a
    device is to put symbolic links to sysfs directories representing
    those resources into special attribute groups in the device's sysfs
    directory. For this purpose, it is necessary to be able to add
    symbolic links to attribute groups.

    For this reason, add sysfs helper functions for adding/removing
    symbolic links to/from attribute groups, sysfs_add_link_to_group()
    and sysfs_remove_link_from_group(), respectively.

    This change set includes a build fix from David Rientjes.

    Signed-off-by: Rafael J. Wysocki
    Acked-by: Greg Kroah-Hartman

    Rafael J. Wysocki
     

15 May, 2012

1 commit

  • This patch (as1554) fixes a lockdep false-positive report. The
    problem arises because lockdep is unable to deal with the
    tree-structured locks created by the device core and sysfs.

    This particular problem involves a sysfs attribute method that
    unregisters itself, not from the device it was called for, but from a
    descendant device. Lockdep doesn't understand the distinction and
    reports a possible deadlock, even though the operation is safe.

    This is the sort of thing that would normally be handled by using a
    nested lock annotation; unfortunately it's not feasible to do that
    here. There's no sensible way to tell sysfs when attribute removal
    occurs in the context of a parent attribute method.

    As a workaround, the patch adds a new flag to struct attribute
    telling sysfs not to inform lockdep when it acquires a readlock on a
    sysfs_dirent instance for the attribute. The readlock is still
    acquired, but lockdep doesn't know about it and hence does not
    complain about impossible deadlock scenarios.

    Also added are macros for static initialization of attribute
    structures with the ignore_lockdep flag set. The three offending
    attributes in the USB subsystem are converted to use the new macros.

    Signed-off-by: Alan Stern
    Acked-by: Tejun Heo
    CC: Eric W. Biederman
    CC: Peter Zijlstra
    Signed-off-by: Greg Kroah-Hartman

    Alan Stern
     

04 Jan, 2012

3 commits


20 Oct, 2011

1 commit

  • Looking up files in sysfs is hard to understand and analyize because we
    currently allow placing untagged files in tagged directories. In the
    implementation of that we have two subtly different meanings of NULL.
    NULL meaning there is no tag on a directory entry and NULL meaning
    we don't care which namespace the lookup is performed for. This
    multiple uses of NULL have resulted in subtle bugs (since fixed)
    in the code.

    Currently it is only the bonding driver that needs to have an untagged
    file in a tagged directory.

    To untagle this mess I am adding support for tagged files to sysfs.
    Modifying the bonding driver to implement bonding_masters as a tagged
    file. Registering bonding_masters once for each network namespace.
    Then I am removing support for untagged entries in tagged sysfs
    directories.

    Resulting in code that is much easier to reason about.

    Signed-off-by: Eric W. Biederman
    Acked-by: Greg Kroah-Hartman
    Signed-off-by: David S. Miller

    Eric W. Biederman
     

27 Jul, 2011

1 commit

  • This allows us to move duplicated code in
    (atomic_inc_not_zero() for now) to

    Signed-off-by: Arun Sharma
    Reviewed-by: Eric Dumazet
    Cc: Ingo Molnar
    Cc: David Miller
    Cc: Eric Dumazet
    Acked-by: Mike Frysinger
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Arun Sharma
     

13 Jun, 2011

1 commit

  • * new refcount in struct net, controlling actual freeing of the memory
    * new method in kobj_ns_type_operations (->drop_ns())
    * ->current_ns() semantics change - it's supposed to be followed by
    corresponding ->drop_ns(). For struct net in case of CONFIG_NET_NS it bumps
    the new refcount; net_drop_ns() decrements it and calls net_free() if the
    last reference has been dropped. Method renamed to ->grab_current_ns().
    * old net_free() callers call net_drop_ns() instead.
    * sysfs_exit_ns() is gone, along with a large part of callchain
    leading to it; now that the references stored in ->ns[...] stay valid we
    do not need to hunt them down and replace them with NULL. That fixes
    problems in sysfs_lookup() and sysfs_readdir(), along with getting rid
    of sb->s_instances abuse.

    Note that struct net *shutdown* logics has not changed - net_cleanup()
    is called exactly when it used to be called. The only thing postponed by
    having a sysfs instance refering to that struct net is actual freeing of
    memory occupied by struct net.

    Signed-off-by: Al Viro

    Al Viro
     

14 May, 2011

1 commit

  • On some arches (x86, sh, arm, unicore, powerpc) the oops message would
    print out the last sysfs file accessed.

    This was very useful in finding a number of sysfs and driver core bugs
    in the 2.5 and early 2.6 development days, but it has been a number of
    years since this file has actually helped in debugging anything that
    couldn't also be trivially determined from the stack traceback.

    So it's time to delete the line. This is good as we need all the space
    we can get for oops messages at times on consoles.

    Acked-by: Phil Carmody
    Acked-by: Ingo Molnar
    Cc: Andrew Morton
    Cc: Thomas Gleixner
    Signed-off-by: Greg Kroah-Hartman

    Greg Kroah-Hartman
     

17 Oct, 2010

1 commit


24 Aug, 2010

1 commit


06 Aug, 2010

2 commits


22 May, 2010

5 commits

  • This allows bin_attr->read,write,mmap callbacks to check file specific data
    (such as inode owner) as part of any privilege validation.

    Signed-off-by: Chris Wright
    Signed-off-by: Greg Kroah-Hartman

    Chris Wright
     
  • It appears gcc can't cope with using an enum that is only declared in
    an inline function declaration, that doesn't even use the variable
    that is so declared.

    Avoid the silliness and replace the enum with an int, and make gcc
    happy.

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

    Eric W. Biederman
     
  • Add some in-line comments to explain the new infrastructure, which
    was introduced to support sysfs directory tagging with namespaces.
    I think an overall description someplace might be good too, but it
    didn't really seem to fit into Documentation/filesystems/sysfs.txt,
    which appears more geared toward users, rather than maintainers, of
    sysfs.

    (Tejun, please let me know if I can make anything clearer or failed
    altogether to comment something that should be commented.)

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

    Serge E. Hallyn
     
  • 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
     

08 Mar, 2010

5 commits

  • After merging the final tree, today's linux-next build (powerpc
    allyesconfig) failed like this:

    drivers/pci/pci-sysfs.c: In function 'pci_create_legacy_files':
    drivers/pci/pci-sysfs.c:645: error: lvalue required as unary '&' operand
    drivers/pci/pci-sysfs.c:658: error: lvalue required as unary '&' operand

    Caused by commit "sysfs: Use sysfs_attr_init and sysfs_bin_attr_init on
    dynamic attributes" interacting with commit "sysfs: Use one lockdep
    class per sysfs attribute") both from the driver-core tree.

    Signed-off-by: Stephen Rothwell
    Cc: "Eric W. Biederman"
    Signed-off-by: Greg Kroah-Hartman

    Stephen Rothwell
     
  • 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
     
  • I have added a new requirement to the external sysfs interface
    that dynamically allocated sysfs attributes must call sysfs_attr_init
    if lockdep is enabled. For the time being callying sysfs_attr_init
    is only mandatory if lockdep is enabled, so we can live with a few
    unconverted instances until we find them all. As this is part of
    the public interface of sysfs it is a good idea to document these
    pseudo functions so someone inspeciting the code can find out
    what has happened.

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

    Eric W. Biederman
     
  • Acknowledge that the logical sysfs rwsem has one instance per
    sysfs attribute with different locking depencencies for different
    attributes.

    There is a sysfs idiom where writing to one sysfs file causes the
    addition or removal of other sysfs files. Lumping all of the
    sysfs attributes together in one lock class causes lockdep to
    generate lots of false positives.

    This introduces the requirement that non-static sysfs attributes
    need to be initialized with sysfs_attr_init or sysfs_bin_attr_init.
    Strictly speaking this requirement only exists when lockdep is
    enabled, and when lockdep is enabled we get a bit fat warning
    if this requirement is not met.

    Signed-off-by: Eric W. Biederman
    Acked-by: WANG Cong
    Cc: Tejun Heo
    Signed-off-by: Greg Kroah-Hartman

    Eric W. Biederman
     
  • Adding/Removing a whole array of attributes is very common. Add a standard
    utility function to do this with a simple function call, instead of
    requiring drivers to open code this.

    Signed-off-by: Andi Kleen
    Signed-off-by: Greg Kroah-Hartman

    Andi Kleen