1. 20 Dec, 2013 1 commit
  2. 19 Dec, 2013 2 commits
  3. 18 Dec, 2013 1 commit
  4. 17 Dec, 2013 6 commits
    • Tejun Heo's avatar
      kernfs: add kernfs_dir_ops · 80b9bbef
      Tejun Heo authored
      Add support for mkdir(2), rmdir(2) and rename(2) syscalls.  This is
      implemented through optional kernfs_dir_ops callback table which can
      be specified on kernfs_create_root().  An implemented callback is
      invoked when the matching syscall is invoked.
      
      As kernfs keep dcache syncs with internal representation and
      revalidates dentries on each access, the implementation of these
      methods is extremely simple.  Each just discovers the relevant
      kernfs_node(s) and invokes the requested callback which is allowed to
      do any kernfs operations and the end result doesn't necessarily have
      to match the expected semantics of the syscall.
      
      This will be used to convert cgroup to use kernfs instead of its own
      filesystem implementation.
      Signed-off-by: default avatarTejun Heo <tj@kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      80b9bbef
    • Tejun Heo's avatar
      kernfs: allow negative dentries · 19bbb926
      Tejun Heo authored
      kernfs doesn't allow negative dentries - kernfs_iop_lookup() returns
      ERR_PTR(-ENOENT) instead of NULL which short-circuits negative dentry
      creation and kernfs's d_delete() callback, kernfs_dop_delete(),
      returns 1 for all removed nodes.  This in turn allows
      kernfs_dop_revalidate() to assume that there's no negative dentry for
      kernfs.
      
      This worked fine for sysfs but kernfs is scheduled to grow mkdir(2)
      support which depend on negative dentries.  This patch updates so that
      kernfs allows negative dentries.  The required changes are almost
      trivial - kernfs_iop_lookup() now returns NULL instead of
      ERR_PTR(-ENOENT) when the target kernfs_node doesn't exist,
      kernfs_dop_delete() is removed and kernfs_dop_revalidate() is updated
      to check whether the target dentry is negative and request fresh
      lookup if so.
      Signed-off-by: default avatarTejun Heo <tj@kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      19bbb926
    • Tejun Heo's avatar
      kernfs: update kernfs_rename_ns() to consider KERNFS_STATIC_NAME · 47a52e91
      Tejun Heo authored
      kernfs_rename_ns() currently assumes that the target sysfs_dirent has
      a copied name.  This has been okay because sysfs supports rename only
      for directories which always have copied names; however, there's
      nothing in kernfs interface which calls for such restriction and
      currently invoking kernfs_rename_ns() on a regular file leads to oops
      because it ends up trying to kfree() a static name.
      
      This patch updates kernfs_rename_ns() so that it skips kfree() of the
      old name if it's static.  This allows it to be used for all node
      types.
      Signed-off-by: default avatarTejun Heo <tj@kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      47a52e91
    • Tejun Heo's avatar
      kernfs: mark static names with KERNFS_STATIC_NAME · 2063d608
      Tejun Heo authored
      Because sysfs used struct attribute which are supposed to stay
      constant, sysfs didn't copy names when creating regular files.  The
      specified string for name was supposed to stay constant.  Such
      distinction isn't inherent for kernfs.  kernfs_create_file[_ns]()
      should be able to take the same @name as kernfs_create_dir[_ns]()
      
      As there can be huge number of sysfs attributes, we still want to be
      able to use static names for sysfs attributes.  This patch renames
      kernfs_create_file_ns_key() to __kernfs_create_file() and adds
      @name_is_static parameter so that the caller can explicitly indicate
      that @name can be used without copying.  kernfs is updated to use
      KERNFS_STATIC_NAME to distinguish static and copied names.
      
      This patch doesn't introduce any behavior changes.
      Signed-off-by: default avatarTejun Heo <tj@kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      2063d608
    • Tejun Heo's avatar
      kernfs: add REMOVED check to create and rename paths · d0ae3d43
      Tejun Heo authored
      kernfs currently assumes that the caller doesn't try to create a new
      node under a removed parent, rename a removed node, or move a node
      under a removed node.  While this works fine for sysfs, it'd be nice
      to have protection against such cases especially given that kernfs is
      planned to add support for mkdir, rmdir and rename requsts from
      userland which may make race conditions more likely.
      
      This patch updates create and rename paths to check REMOVED and fail
      the operation with -ENOENT if performed on or towards removed nodes.
      Note that remove path already has such check.
      Signed-off-by: default avatarTejun Heo <tj@kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      d0ae3d43
    • Tejun Heo's avatar
      kernfs: add @mode to kernfs_create_dir[_ns]() · bb8b9d09
      Tejun Heo authored
      sysfs assumed 0755 for all newly created directories and kernfs
      inherited it.  This assumption is unnecessarily restrictive and
      inconsistent with kernfs_create_file[_ns]().  This patch adds @mode
      parameter to kernfs_create_dir[_ns]() and update uses in sysfs
      accordingly.  Among others, this will be useful for implementations of
      the planned ->mkdir() method.
      
      This patch doesn't introduce any behavior differences.
      Signed-off-by: default avatarTejun Heo <tj@kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      bb8b9d09
  5. 12 Dec, 2013 4 commits
    • Tejun Heo's avatar
      kernfs: s/sysfs/kernfs/ in internal functions and whatever is left · c637b8ac
      Tejun Heo authored
      kernfs has just been separated out from sysfs and we're already in
      full conflict mode.  Nothing can make the situation any worse.  Let's
      take the chance to name things properly.
      
      This patch performs the following renames.
      
      * s/sysfs_*()/kernfs_*()/ in all internal functions
      * s/sysfs/kernfs/ in internal strings, comments and whatever is remaining
      * Uniformly rename various vfs operations so that they're consistently
        named and distinguishable.
      
      This patch is strictly rename only and doesn't introduce any
      functional difference.
      Signed-off-by: default avatarTejun Heo <tj@kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      c637b8ac
    • Tejun Heo's avatar
      kernfs: s/sysfs/kernfs/ in global variables · a797bfc3
      Tejun Heo authored
      kernfs has just been separated out from sysfs and we're already in
      full conflict mode.  Nothing can make the situation any worse.  Let's
      take the chance to name things properly.
      
      This patch performs the following renames.
      
      * s/sysfs_mutex/kernfs_mutex/
      * s/sysfs_dentry_ops/kernfs_dops/
      * s/sysfs_dir_operations/kernfs_dir_fops/
      * s/sysfs_dir_inode_operations/kernfs_dir_iops/
      * s/kernfs_file_operations/kernfs_file_fops/ - renamed for consistency
      * s/sysfs_symlink_inode_operations/kernfs_symlink_iops/
      * s/sysfs_aops/kernfs_aops/
      * s/sysfs_backing_dev_info/kernfs_bdi/
      * s/sysfs_inode_operations/kernfs_iops/
      * s/sysfs_dir_cachep/kernfs_node_cache/
      * s/sysfs_ops/kernfs_sops/
      
      This patch is strictly rename only and doesn't introduce any
      functional difference.
      Signed-off-by: default avatarTejun Heo <tj@kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      a797bfc3
    • Tejun Heo's avatar
      kernfs: s/sysfs/kernfs/ in constants · df23fc39
      Tejun Heo authored
      kernfs has just been separated out from sysfs and we're already in
      full conflict mode.  Nothing can make the situation any worse.  Let's
      take the chance to name things properly.
      
      This patch performs the following renames.
      
      * s/SYSFS_DIR/KERNFS_DIR/
      * s/SYSFS_KOBJ_ATTR/KERNFS_FILE/
      * s/SYSFS_KOBJ_LINK/KERNFS_LINK/
      * s/SYSFS_{TYPE_FLAGS}/KERNFS_{TYPE_FLAGS}/
      * s/SYSFS_FLAG_{FLAG}/KERNFS_{FLAG}/
      * s/sysfs_type()/kernfs_type()/
      * s/SD_DEACTIVATED_BIAS/KN_DEACTIVATED_BIAS/
      
      This patch is strictly rename only and doesn't introduce any
      functional difference.
      Signed-off-by: default avatarTejun Heo <tj@kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      df23fc39
    • Tejun Heo's avatar
      kernfs: s/sysfs/kernfs/ in various data structures · c525aadd
      Tejun Heo authored
      kernfs has just been separated out from sysfs and we're already in
      full conflict mode.  Nothing can make the situation any worse.  Let's
      take the chance to name things properly.
      
      This patch performs the following renames.
      
      * s/sysfs_open_dirent/kernfs_open_node/
      * s/sysfs_open_file/kernfs_open_file/
      * s/sysfs_inode_attrs/kernfs_iattrs/
      * s/sysfs_addrm_cxt/kernfs_addrm_cxt/
      * s/sysfs_super_info/kernfs_super_info/
      * s/sysfs_info()/kernfs_info()/
      * s/sysfs_open_dirent_lock/kernfs_open_node_lock/
      * s/sysfs_open_file_mutex/kernfs_open_file_mutex/
      * s/sysfs_of()/kernfs_of()/
      
      This patch is strictly rename only and doesn't introduce any
      functional difference.
      Signed-off-by: default avatarTejun Heo <tj@kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      c525aadd
  6. 11 Dec, 2013 5 commits
    • Tejun Heo's avatar
      kernfs: drop s_ prefix from kernfs_node members · adc5e8b5
      Tejun Heo authored
      kernfs has just been separated out from sysfs and we're already in
      full conflict mode.  Nothing can make the situation any worse.  Let's
      take the chance to name things properly.
      
      s_ prefix for kernfs members is used inconsistently and a misnomer
      now.  It's not like kernfs_node is used widely across the kernel
      making the ability to grep for the members particularly useful.  Let's
      just drop the prefix.
      
      This patch is strictly rename only and doesn't introduce any
      functional difference.
      Signed-off-by: default avatarTejun Heo <tj@kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      adc5e8b5
    • Tejun Heo's avatar
      kernfs: s/sysfs_dirent/kernfs_node/ and rename its friends accordingly · 324a56e1
      Tejun Heo authored
      kernfs has just been separated out from sysfs and we're already in
      full conflict mode.  Nothing can make the situation any worse.  Let's
      take the chance to name things properly.
      
      This patch performs the following renames.
      
      * s/sysfs_elem_dir/kernfs_elem_dir/
      * s/sysfs_elem_symlink/kernfs_elem_symlink/
      * s/sysfs_elem_attr/kernfs_elem_file/
      * s/sysfs_dirent/kernfs_node/
      * s/sd/kn/ in kernfs proper
      * s/parent_sd/parent/
      * s/target_sd/target/
      * s/dir_sd/parent/
      * s/to_sysfs_dirent()/rb_to_kn()/
      * misc renames of local vars when they conflict with the above
      
      Because md, mic and gpio dig into sysfs details, this patch ends up
      modifying them.  All are sysfs_dirent renames and trivial.  While we
      can avoid these by introducing a dummy wrapping struct sysfs_dirent
      around kernfs_node, given the limited usage outside kernfs and sysfs
      proper, I don't think such workaround is called for.
      
      This patch is strictly rename only and doesn't introduce any
      functional difference.
      
      - mic / gpio renames were missing.  Spotted by kbuild test robot.
      Signed-off-by: default avatarTejun Heo <tj@kernel.org>
      Cc: Neil Brown <neilb@suse.de>
      Cc: Linus Walleij <linus.walleij@linaro.org>
      Cc: Ashutosh Dixit <ashutosh.dixit@intel.com>
      Cc: kbuild test robot <fengguang.wu@intel.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      324a56e1
    • Linus Walleij's avatar
      Documentation: start documenting driver design patterns · a8b1c019
      Linus Walleij authored
      After realizing that we tend to tell developers the same thing over
      and over, let's attempt to document some commin design patterns
      used in the device drivers. The idea is that this can be extended
      so I just start out with two well-known design patterns.
      
      Cc: Rob Landley <rob@landley.net>
      Cc: Mark Brown <broonie@kernel.org>
      Cc: Arnd Bergmann <arnd@arndb.de>
      Cc: Grant Likely <grant.likely@linaro.org>
      Signed-off-by: default avatarLinus Walleij <linus.walleij@linaro.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      a8b1c019
    • Tejun Heo's avatar
      sysfs: fix use-after-free in sysfs_kill_sb() · a7560a01
      Tejun Heo authored
      While restructuring the [u]mount path, 4b93dc9b ("sysfs, kernfs:
      prepare mount path for kernfs") incorrectly updated sysfs_kill_sb() so
      that it first kills super_block and then tries to dereference its
      namespace tag to drop it.  Fix it by caching namespace tag before
      killing the superblock and then drop the cached namespace tag.
      Signed-off-by: default avatarTejun Heo <tj@kernel.org>
      Reported-by: default avatarYuanhan Liu <yuanhan.liu@linux.intel.com>
      Tested-by: default avatarYuanhan Liu <yuanhan.liu@linux.intel.com>
      Tested-by: default avatarVlastimil Babka <vbabka@suse.cz>
      Link: http://lkml.kernel.org/g/20131205031051.GC5135@yliu-dev.sh.intel.comSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      a7560a01
    • Tejun Heo's avatar
      sysfs: bail early from kernfs_file_mmap() to avoid spurious lockdep warning · 9b2db6e1
      Tejun Heo authored
      This is v3.14 fix for the same issue that a8b14744 ("sysfs: give
      different locking key to regular and bin files") addresses for v3.13.
      Due to the extensive kernfs reorganization in v3.14 branch, the same
      fix couldn't be ported as-is.  The v3.13 fix was ignored while merging
      it into v3.14 branch.
      
      027a485d ("sysfs: use a separate locking class for open files
      depending on mmap") assigned different lockdep key to
      sysfs_open_file->mutex depending on whether the file implements mmap
      or not in an attempt to avoid spurious lockdep warning caused by
      merging of regular and bin file paths.
      
      While this restored some of the original behavior of using different
      locks (at least lockdep is concerned) for the different clases of
      files.  The restoration wasn't full because now the lockdep key
      assignment depends on whether the file has mmap or not instead of
      whether it's a regular file or not.
      
      This means that bin files which don't implement mmap will get assigned
      the same lockdep class as regular files.  This is problematic because
      file_operations for bin files still implements the mmap file operation
      and checking whether the sysfs file actually implements mmap happens
      in the file operation after grabbing @sysfs_open_file->mutex.  We
      still end up adding locking dependency from mmap locking to
      sysfs_open_file->mutex to the regular file mutex which triggers
      spurious circular locking warning.
      
      For v3.13, a8b14744 ("sysfs: give different locking key to regular
      and bin files") fixed it by giving sysfs_open_file->mutex different
      lockdep keys depending on whether the file is regular or bin instead
      of whether mmap exists or not; however, due to the way sysfs is now
      layered behind kernfs, this approach is no longer viable.  kernfs can
      tell whether a sysfs node has mmap implemented or not but can't tell
      whether a bin file from a regular one.
      
      This patch updates kernfs such that kernfs_file_mmap() checks
      SYSFS_FLAG_HAS_MMAP and bail before grabbing sysfs_open_file->mutex so
      that it doesn't add spurious locking dependency from mmap to
      sysfs_open_file->mutex and changes sysfs so that it specifies
      kernfs_ops->mmap iff the sysfs file implements mmap.  Combined, this
      ensures that sysfs_open_file->mutex is grabbed under mmap path iff the
      sysfs file actually implements mmap.  As sysfs_open_file->mutex is
      already given a different lockdep key if mmap is implemented, this
      removes the spurious locking dependency.
      Signed-off-by: default avatarTejun Heo <tj@kernel.org>
      Reported-by: default avatarDave Jones <davej@redhat.com>
      Link: http://lkml.kernel.org/g/20131203184324.GA11320@redhat.comSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      9b2db6e1
  7. 10 Dec, 2013 1 commit
    • Tejun Heo's avatar
      Merge branch 'driver-core-linus' into driver-core-next · 13ccb93f
      Tejun Heo authored
      a8b14744 ("sysfs: give different locking key to regular and bin
      files") in driver-core-linus modifies sysfs_open_file() so that it
      gives out different locking classes to sysfs_open_files depending on
      whether the file is bin or not.  Due to the massive kernfs
      reorganization in driver-core-next, this naturally causes merge
      conflict in fs/sysfs/file.c.
      
      Due to the way things are split between kernfs and sysfs in
      driver-core-next, the same fix can't easily be applied to
      driver-core-next.  This merge simply ignores the offending commit.  A
      following patch will implement a separate fix for the issue.
      Signed-off-by: default avatarTejun Heo <tj@kernel.org>
      13ccb93f
  8. 09 Dec, 2013 9 commits
  9. 08 Dec, 2013 3 commits
    • Tejun Heo's avatar
      sysfs: give different locking key to regular and bin files · a8b14744
      Tejun Heo authored
      027a485d ("sysfs: use a separate locking class for open files
      depending on mmap") assigned different lockdep key to
      sysfs_open_file->mutex depending on whether the file implements mmap
      or not in an attempt to avoid spurious lockdep warning caused by
      merging of regular and bin file paths.
      
      While this restored some of the original behavior of using different
      locks (at least lockdep is concerned) for the different clases of
      files.  The restoration wasn't full because now the lockdep key
      assignment depends on whether the file has mmap or not instead of
      whether it's a regular file or not.
      
      This means that bin files which don't implement mmap will get assigned
      the same lockdep class as regular files.  This is problematic because
      file_operations for bin files still implements the mmap file operation
      and checking whether the sysfs file actually implements mmap happens
      in the file operation after grabbing @sysfs_open_file->mutex.  We
      still end up adding locking dependency from mmap locking to
      sysfs_open_file->mutex to the regular file mutex which triggers
      spurious circular locking warning.
      
      Fix it by restoring the original behavior fully by differentiating
      lockdep key by whether the file is regular or bin, instead of the
      existence of mmap.
      Signed-off-by: default avatarTejun Heo <tj@kernel.org>
      Reported-by: default avatarDave Jones <davej@redhat.com>
      Link: http://lkml.kernel.org/g/20131203184324.GA11320@redhat.comSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      a8b14744
    • Bjorn Helgaas's avatar
      kobject: remove kset from sysfs immediately in kset_unregister() · 35a5fe69
      Bjorn Helgaas authored
      There's no "unlink from sysfs" interface for ksets, so I think callers of
      kset_unregister() expect the kset to be removed from sysfs immediately,
      without waiting for the last reference to be released.
      
      This patch makes the sysfs removal happen immediately, so the caller may
      create a new kset with the same name as soon as kset_unregister() returns.
      Without this, every caller has to call "kobject_del(&kset->kobj)" first
      unless it knows it will never create a new kset with the same name.
      
      This sometimes shows up on module unload and reload, where the reload fails
      because it tries to create a kobject with the same name as one from the
      original load that still exists.  CONFIG_DEBUG_KOBJECT_RELEASE=y makes this
      problem easier to hit.
      Signed-off-by: default avatarBjorn Helgaas <bhelgaas@google.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      35a5fe69
    • Bjorn Helgaas's avatar
      kobject: delay kobject release for random time · 89c86a64
      Bjorn Helgaas authored
      When CONFIG_DEBUG_KOBJECT_RELEASE=y, delay kobject release functions for a
      random time between 1 and 8 seconds, which effectively changes the order in
      which they're called.
      Signed-off-by: default avatarBjorn Helgaas <bhelgaas@google.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      89c86a64
  10. 06 Dec, 2013 8 commits