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
     

24 Dec, 2009

1 commit


20 Oct, 2008

1 commit

  • Tejun's commit 7b595756ec1f49e0049a9e01a1298d53a7faaa15 made sysfs
    attribute->owner unnecessary. But the field was left in the structure to
    ease the merge. It's been over a year since that change and it is now
    time to start killing attribute->owner along with its users - one arch at
    a time!

    This patch is attempt #1 to get rid of attribute->owner only for
    CONFIG_X86_64 or CONFIG_X86_32 . We will deal with other arches later on
    as and when possible - avr32 will be the next since that is something I
    can test. Compile (make allyesconfig / make allmodconfig / custom config)
    and boot tested.

    akpm: the idea is that we put the declaration of sttribute.owner inside
    `#ifndef CONFIG_X86'. But that proved to be too ambitious for now because
    new usages kept on turning up in subsystem trees.

    [akpm: remove the ifdef for now]
    Signed-off-by: Parag Warudkar
    Cc: Greg KH
    Cc: Ingo Molnar
    Cc: Tejun Heo
    Cc: Len Brown
    Cc: Jens Axboe
    Cc: Jean Delvare
    Cc: Roland Dreier
    Cc: David Brownell
    Cc: Alessandro Zummo
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Parag Warudkar
     

17 Oct, 2008

5 commits

  • It finally dawned on me what the clean fix to sysfs_rename_dir
    calling kobject_set_name is. Move the work into kobject_rename
    where it belongs. The callers serialize us anyway so this is
    safe.

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

    Eric W. Biederman
     
  • When looking at kobject_rename I found two bugs with
    that exist when sysfs support is disabled in the kernel.

    kobject_rename does not change the name on the kobject when
    sysfs support is not compiled in.

    kobject_rename without locking attempts to check the
    validity of a rename operation, which the kobject layer
    simply does not have the infrastructure to do.

    This patch documents the previously unstated requirement of
    kobject_rename that is the responsibility of the caller to
    provide mutual exclusion and to be certain that the new_name
    for the kobject is valid.

    This patch modifies sysfs_rename_dir in !CONFIG_SYSFS case
    to call kobject_set_name to actually change the kobject_name.

    This patch removes the bogus and misleading check in kobject_rename
    that attempts to see if a rename is valid. The check is bogus
    because we do not have the proper locking. The check is misleading
    because it looks like we can and do perform checking at the kobject
    level that we don't.

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

    Eric W. Biederman
     
  • Because they can be, and because code like this produces a warning if
    they're not:

    struct device_attribute dev_attr;

    sysfs_notify(&kobj, NULL, dev_attr.attr.name);

    Signed-off-by: Trent Piepho
    CC: Neil Brown
    Signed-off-by: Greg Kroah-Hartman

    Trent Piepho
     
  • Support sysfs_notify from atomic context with new sysfs_notify_dirent

    sysfs_notify currently takes sysfs_mutex.
    This means that it cannot be called in atomic context.
    sysfs_mutex is sometimes held over a malloc (sysfs_rename_dir)
    so it can block on low memory.

    In md I want to be able to notify on a sysfs attribute from
    atomic context, and I don't want to block on low memory because I
    could be in the writeout path for freeing memory.

    So:
    - export the "sysfs_dirent" structure along with sysfs_get, sysfs_put
    and sysfs_get_dirent so I can get the sysfs_dirent that I want to
    notify on and hold it in an md structure.
    - split sysfs_notify_dirent out of sysfs_notify so the sysfs_dirent
    can be notified on with no blocking (just a spinlock).

    Signed-off-by: Neil Brown
    Acked-by: Tejun Heo
    Signed-off-by: Greg Kroah-Hartman

    Neil Brown
     
  • Print the name of the last-accessed sysfs file when we oops, to help track
    down oopses which occur in sysfs store/read handlers. Because these oopses
    tend to not leave any trace of the offending code in the stack traces.

    Cc: Kay Sievers
    Cc: Mathieu Desnoyers
    Signed-off-by: Andrew Morton
    Signed-off-by: Greg Kroah-Hartman

    Andrew Morton
     

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
     

05 May, 2008

1 commit

  • x86.git testing found the following build failure on v2.6.26-rc1:

    In file included from include/linux/kobject.h:22,
    from include/linux/module.h:17,
    from include/linux/crypto.h:22,
    from arch/x86/kernel/asm-offsets_32.c:8,
    from arch/x86/kernel/asm-offsets.c:3:
    include/linux/sysfs.h:201: error: redefinition of 'sysfs_update_group'
    include/linux/sysfs.h:195: error: previous definition of 'sysfs_update_group' was here
    make[1]: *** [arch/x86/kernel/asm-offsets.s] Error 1
    make: *** [prepare0] Error 2

    with the following config:

    http://redhat.com/~mingo/misc/config-Sun_May__4_07_09_30_CEST_2008.bad

    the reason for the build failure is the duplicate definition of the
    sysfs_update_group() inline function in include/linux/sysfs.h.

    The duplication was a merge error: it was added via -mm by commit
    v2.6.25-7262-g2850699, "sysfs: sysfs_update_group stub for
    CONFIG_SYSFS=n" a day before v2.6.26-rc1, but a day before that the same
    commit was already merged upstream via the sysfs tree, with commit
    v2.6.25-7211-g1cbfb7a.

    Signed-off-by: Ingo Molnar
    Signed-off-by: Linus Torvalds

    Ingo Molnar
     

01 May, 2008

2 commits

  • scsi_transport_spi uses sysfs_update_group() when CONFIG_SYSFS=n, so provide a
    stub for it.

    next-20080423/drivers/scsi/scsi_transport_spi.c:1467: error: implicit declaration of function 'sysfs_update_group'
    make[3]: *** [drivers/scsi/scsi_transport_spi.o] Error 1

    Signed-off-by: Randy Dunlap
    Cc: Greg KH
    Cc: James Bottomley
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Randy Dunlap
     
  • scsi_transport_spi uses sysfs_update_group() when CONFIG_SYSFS=n,
    so provide a stub for it.

    next-20080423/drivers/scsi/scsi_transport_spi.c:1467: error: implicit declaration of function 'sysfs_update_group'
    make[3]: *** [drivers/scsi/scsi_transport_spi.o] Error 1

    Signed-off-by: Randy Dunlap
    Cc: James Bottomley
    Signed-off-by: Greg Kroah-Hartman

    Randy Dunlap
     

23 Apr, 2008

1 commit

  • We have a problem in scsi_transport_spi in that we need to customise
    not only the visibility of the attributes, but also their mode. Fix
    this by making the is_visible() callback return a mode, with 0
    indicating is not visible.

    Also add a sysfs_update_group() API to allow us to change either the
    visibility or mode of the files at any time on the fly.

    Acked-by: Kay Sievers
    Signed-off-by: James Bottomley

    James Bottomley
     

20 Apr, 2008

1 commit


24 Jan, 2008

1 commit

  • This patch allows the various users of attribute_groups to selectively
    allow the appearance of group attributes. The primary consumer of
    this will be the transport classes in which we currently have
    elaborate attribute selection algorithms to do this same thing.

    Acked-by: Greg KH
    Signed-off-by: James Bottomley

    James Bottomley
     

13 Oct, 2007

4 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
     
  • sysfs_update_file() depends on inode->i_mtime but sysfs iondes are now
    reclaimable making the reported modification time unreliable. There's
    only one user (pci hotplug) of this notification mechanism and it
    reportedly isn't utilized from userland.

    Kill sysfs_update_file().

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

    Tejun Heo
     
  • sysfs is about to go through major overhaul making this a pretty good
    opportunity to clean up (out-of-tree changes and pending patches will
    need regeneration anyway). Clean up headers.

    * Kill space between * and symbolname.

    * Move SYSFS_* type constants and flags into fs/sysfs/sysfs.h.
    They're internal to sysfs.

    * Reformat function prototypes and add argument symbol names.

    * Make dummy function definition order match that of function
    prototypes.

    * Add some comments.

    * Reorganize fs/sysfs/sysfs.h according to which file the declared
    variable or feature lives in.

    This patch does not introduce any behavior change.

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

    Tejun Heo
     
  • While shadow directories appear to be a good idea, the current scheme
    of controlling their creation and destruction outside of sysfs appears
    to be a locking and maintenance nightmare in the face of sysfs
    directories dynamically coming and going. Which can now occur for
    directories containing network devices when CONFIG_SYSFS_DEPRECATED is
    not set.

    This patch removes everything from the initial shadow directory support
    that allowed the shadow directory creation to be controlled at a higher
    level. So except for a few bits of sysfs_rename_dir everything from
    commit b592fcfe7f06c15ec11774b5be7ce0de3aa86e73 is now gone.

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

    Eric W. Biederman
     

12 Jul, 2007

1 commit

  • Well, first of all, I don't want to change so many files either.

    What I do:
    Adding a new parameter "struct bin_attribute *" in the
    .read/.write methods for the sysfs binary attributes.

    In fact, only the four lines change in fs/sysfs/bin.c and
    include/linux/sysfs.h do the real work.
    But I have to update all the files that use binary attributes
    to make them compatible with the new .read and .write methods.
    I'm not sure if I missed any. :(

    Why I do this:
    For a sysfs attribute, we can get a pointer pointing to the
    struct attribute in the .show/.store method,
    while we can't do this for the binary attributes.
    I don't know why this is different, but this does make it not
    so handy to use the binary attributes as the regular ones.
    So I think this patch is reasonable. :)

    Who benefits from it:
    The patch that exposes ACPI tables in sysfs
    requires such an improvement.
    All the table binary attributes share the same .read method.
    Parameter "struct bin_attribute *" is used to get
    the table signature and instance number which are used to
    distinguish different ACPI table binary attributes.

    Without this parameter, we need to offer different .read methods
    for different ACPI table binary attributes.
    This is impossible as there are various ACPI tables on different
    platforms, and we don't know what they are until they are loaded.

    Signed-off-by: Zhang Rui
    Signed-off-by: Greg Kroah-Hartman

    Zhang Rui