1. 11 1月, 2014 3 次提交
    • T
      kernfs: remove KERNFS_REMOVED · ae34372e
      Tejun Heo 提交于
      KERNFS_REMOVED is used to mark half-initialized and dying nodes so
      that they don't show up in lookups and deny adding new nodes under or
      renaming it; however, its role overlaps those of deactivation and
      removal from rbtree.
      
      It's necessary to deny addition of new children while removal is in
      progress; however, this role considerably intersects with deactivation
      - KERNFS_REMOVED prevents new children while deactivation prevents new
      file operations.  There's no reason to have them separate making
      things more complex than necessary.
      
      KERNFS_REMOVED is also used to decide whether a node is still visible
      to vfs layer, which is rather redundant as equivalent determination
      can be made by testing whether the node is on its parent's children
      rbtree or not.
      
      This patch removes KERNFS_REMOVED.
      
      * Instead of KERNFS_REMOVED, each node now starts its life
        deactivated.  This means that we now use both atomic_add() and
        atomic_sub() on KN_DEACTIVATED_BIAS, which is INT_MIN.  The compiler
        generates an overflow warnings when negating INT_MIN as the negation
        can't be represented as a positive number.  Nothing is actually
        broken but let's bump BIAS by one to avoid the warnings for archs
        which negates the subtrahend..
      
      * KERNFS_REMOVED tests in add and rename paths are replaced with
        kernfs_get/put_active() of the target nodes.  Due to the way the add
        path is structured now, active ref handling is done in the callers
        of kernfs_add_one().  This will be consolidated up later.
      
      * kernfs_remove_one() is updated to deactivate instead of setting
        KERNFS_REMOVED.  This removes deactivation from kernfs_deactivate(),
        which is now renamed to kernfs_drain().
      
      * kernfs_dop_revalidate() now tests RB_EMPTY_NODE(&kn->rb) instead of
        KERNFS_REMOVED and KERNFS_REMOVED test in kernfs_dir_pos() is
        dropped.  A node which is removed from the children rbtree is not
        included in the iteration in the first place.  This means that a
        node may be visible through vfs a bit longer - it's now also visible
        after deactivation until the actual removal.  This slightly enlarged
        window difference doesn't make any difference to the userland.
      
      * Sanity check on KERNFS_REMOVED in kernfs_put() is replaced with
        checks on the active ref.
      
      * Some comment style updates in the affected area.
      
      v2: Reordered before removal path restructuring.  kernfs_active()
          dropped and kernfs_get/put_active() used instead.  RB_EMPTY_NODE()
          used in the lookup paths.
      Signed-off-by: NTejun Heo <tj@kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      ae34372e
    • T
      kernfs: remove KERNFS_ACTIVE_REF and add kernfs_lockdep() · a69d001c
      Tejun Heo 提交于
      There currently are two mechanisms gating active ref lockdep
      annotations - KERNFS_LOCKDEP flag and KERNFS_ACTIVE_REF type mask.
      The former disables lockdep annotations in kernfs_get/put_active()
      while the latter disables all of kernfs_deactivate().
      
      While KERNFS_ACTIVE_REF also behaves as an optimization to skip the
      deactivation step for non-file nodes, the benefit is marginal and it
      needlessly diverges code paths.  Let's drop KERNFS_ACTIVE_REF and use
      KERNFS_LOCKDEP in kernfs_deactivate() too.
      
      While at it, add a test helper kernfs_lockdep() to test KERNFS_LOCKDEP
      flag so that it's more convenient and the related code can be compiled
      out when not enabled.
      Signed-off-by: NTejun Heo <tj@kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      a69d001c
    • T
      kernfs: replace kernfs_node->u.completion with kernfs_root->deactivate_waitq · ea1c472d
      Tejun Heo 提交于
      kernfs_node->u.completion is used to notify deactivation completion
      from kernfs_put_active() to kernfs_deactivate().  We now allow
      multiple racing removals of the same node and the current removal
      scheme is no longer correct - kernfs_remove() invocation may return
      before the node is properly deactivated if it races against another
      removal.  The removal path will be restructured to address the issue.
      
      To help such restructure which requires supporting multiple waiters,
      this patch replaces kernfs_node->u.completion with
      kernfs_root->deactivate_waitq.  This makes deactivation event
      notifications share a per-root waitqueue_head; however, the wait path
      is quite cold and this will also allow shaving one pointer off
      kernfs_node.
      Signed-off-by: NTejun Heo <tj@kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      ea1c472d
  2. 18 12月, 2013 6 次提交
    • T
      kernfs: add kernfs_dir_ops · 80b9bbef
      Tejun Heo 提交于
      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: NTejun Heo <tj@kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      80b9bbef
    • T
      kernfs: allow negative dentries · 19bbb926
      Tejun Heo 提交于
      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: NTejun Heo <tj@kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      19bbb926
    • T
      kernfs: update kernfs_rename_ns() to consider KERNFS_STATIC_NAME · 47a52e91
      Tejun Heo 提交于
      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: NTejun Heo <tj@kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      47a52e91
    • T
      kernfs: mark static names with KERNFS_STATIC_NAME · 2063d608
      Tejun Heo 提交于
      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: NTejun Heo <tj@kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      2063d608
    • T
      kernfs: add REMOVED check to create and rename paths · d0ae3d43
      Tejun Heo 提交于
      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: NTejun Heo <tj@kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      d0ae3d43
    • T
      kernfs: add @mode to kernfs_create_dir[_ns]() · bb8b9d09
      Tejun Heo 提交于
      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: NTejun Heo <tj@kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      bb8b9d09
  3. 12 12月, 2013 6 次提交
    • T
      kernfs: s/sysfs/kernfs/ in internal functions and whatever is left · c637b8ac
      Tejun Heo 提交于
      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: NTejun Heo <tj@kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      c637b8ac
    • T
      kernfs: s/sysfs/kernfs/ in global variables · a797bfc3
      Tejun Heo 提交于
      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: NTejun Heo <tj@kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      a797bfc3
    • T
      kernfs: s/sysfs/kernfs/ in constants · df23fc39
      Tejun Heo 提交于
      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: NTejun Heo <tj@kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      df23fc39
    • T
      kernfs: s/sysfs/kernfs/ in various data structures · c525aadd
      Tejun Heo 提交于
      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: NTejun Heo <tj@kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      c525aadd
    • T
      kernfs: drop s_ prefix from kernfs_node members · adc5e8b5
      Tejun Heo 提交于
      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: NTejun Heo <tj@kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      adc5e8b5
    • T
      kernfs: s/sysfs_dirent/kernfs_node/ and rename its friends accordingly · 324a56e1
      Tejun Heo 提交于
      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: NTejun 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: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      324a56e1
  4. 04 12月, 2013 1 次提交
    • T
      kernfs: implement "trusted.*" xattr support · 2322392b
      Tejun Heo 提交于
      kernfs inherited "security.*" xattr support from sysfs.  This patch
      extends xattr support to "trusted.*" using simple_xattr_*().  As
      trusted xattrs are restricted to CAP_SYS_ADMIN, simple_xattr_*() which
      uses kernel memory for storage shouldn't be problematic.
      
      Note that the existing "security.*" support doesn't implement
      get/remove/list and the this patch only implements those ops for
      "trusted.*".  We probably want to extend those ops to include support
      for "security.*".
      
      This patch will allow using kernfs from cgroup which requires
      "trusted.*" xattr support.
      Signed-off-by: NTejun Heo <tj@kernel.org>
      Cc: David P. Quigley <dpquigl@tycho.nsa.gov>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      2322392b
  5. 30 11月, 2013 5 次提交
    • T
      sysfs, kernfs: implement kernfs_ns_enabled() · ac9bba03
      Tejun Heo 提交于
      fs/sysfs/symlink.c::sysfs_delete_link() tests @sd->s_flags for
      SYSFS_FLAG_NS.  Let's add kernfs_ns_enabled() so that sysfs doesn't
      have to test sysfs_dirent flag directly.  This makes things tidier for
      kernfs proper too.
      
      This is purely cosmetic.
      
      v2: To avoid possible NULL deref, use noop dummy implementation which
          always returns false when !CONFIG_SYSFS.
      Signed-off-by: NTejun Heo <tj@kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      ac9bba03
    • T
      sysfs, kernfs: make sysfs_dirent definition public · cf9e5a73
      Tejun Heo 提交于
      sysfs_dirent includes some information which should be available to
      kernfs users - the type, flags, name and parent pointer.  This patch
      moves sysfs_dirent definition from kernfs/kernfs-internal.h to
      include/linux/kernfs.h so that kernfs users can access them.
      
      The type part of flags is exported as enum kernfs_node_type, the flags
      kernfs_node_flag, sysfs_type() and kernfs_enable_ns() are moved to
      include/linux/kernfs.h and the former is updated to return the enum
      type.  sysfs_dirent->s_parent and ->s_name are marked explicitly as
      public.
      
      This patch doesn't introduce any functional changes.
      
      v2: Flags exported too and kernfs_enable_ns() definition moved.
      
      v3: While moving kernfs_enable_ns() to include/linux/kernfs.h, v1 and
          v2 put the definition outside CONFIG_SYSFS replacing the dummy
          implementation with the actual implementation too.  Unfortunately,
          this can lead to oops when !CONFIG_SYSFS because
          kernfs_enable_ns() may be called on a NULL @sd and now tries to
          dereference @sd instead of not doing anything.  This issue was
          reported by Yuanhan Liu.
      Signed-off-by: NTejun Heo <tj@kernel.org>
      Reported-by: NYuanhan Liu <yuanhan.liu@linux.intel.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      cf9e5a73
    • T
      sysfs, kernfs: make inode number ida per kernfs_root · bc755553
      Tejun Heo 提交于
      kernfs is being updated to allow multiple sysfs_dirent hierarchies so
      that it can also be used by other users.  Currently, inode number is
      allocated using a global ida, sysfs_ino_ida; however, inos for
      different hierarchies should be handled separately.
      
      This patch makes ino allocation per kernfs_root.  sysfs_ino_ida is
      replaced by kernfs_root->ino_ida and sysfs_new_dirent() is updated to
      take @root and allocate ino from it.  ida_simple_get/remove() are used
      instead of sysfs_ino_lock and sysfs_alloc/free_ino().
      Signed-off-by: NTejun Heo <tj@kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      bc755553
    • T
      sysfs, kernfs: implement kernfs_create/destroy_root() · ba7443bc
      Tejun Heo 提交于
      There currently is single kernfs hierarchy in the whole system which
      is used for sysfs.  kernfs needs to support multiple hierarchies to
      allow other users.  This patch introduces struct kernfs_root which
      serves as the root of each kernfs hierarchy and implements
      kernfs_create/destroy_root().
      
      * Each kernfs_root is associated with a root sd (sysfs_dentry).  The
        root is freed when the root sd is released and kernfs_destory_root()
        simply invokes kernfs_remove() on the root sd.  sysfs_remove_one()
        is updated to handle release of the root sd.  Note that ps_iattr
        update in sysfs_remove_one() is trivially updated for readability.
      
      * Root sd's are now dynamically allocated using sysfs_new_dirent().
        Update sysfs_alloc_ino() so that it gives out ino from 1 so that the
        root sd still gets ino 1.
      
      * While kernfs currently only points to the root sd, it'll soon grow
        fields which are specific to each hierarchy.  As determining a given
        sd's root will be necessary, sd->s_dir.root is added.  This backlink
        fits better as a separate field in sd; however, sd->s_dir is inside
        union with space to spare, so use it to save space and provide
        kernfs_root() accessor to determine the root sd.
      
      * As hierarchies may be destroyed now, each mount needs to hold onto
        the hierarchy it's attached to.  Update sysfs_fill_super() and
        sysfs_kill_sb() so that they get and put the kernfs_root
        respectively.
      
      * sysfs_root is replaced with kernfs_root which is dynamically created
        by invoking kernfs_create_root() from sysfs_init().
      
      This patch doesn't introduce any visible behavior changes.
      
      v2: kernfs_create_root() forgot to set @sd->priv.  Fixed.
      Signed-off-by: NTejun Heo <tj@kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      ba7443bc
    • T
      sysfs, kernfs: move dir core code to fs/kernfs/dir.c · fd7b9f7b
      Tejun Heo 提交于
      Move core dir code to fs/kernfs/dir.c.  fs/sysfs/dir.c now only
      contains sysfs_warn_dup() and sysfs wrappers around kernfs interfaces.
      The respective declarations in fs/sysfs/sysfs.h are moved to
      fs/kernfs/kernfs-internal.h.
      
      This is pure relocation.
      
      v2: sysfs_symlink_target_lock was mistakenly relocated to kernfs.  It
          should remain with sysfs.  Fixed.
      Signed-off-by: NTejun Heo <tj@kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      fd7b9f7b
  6. 28 11月, 2013 1 次提交
    • T
      sysfs, kernfs: add skeletons for kernfs · b8441ed2
      Tejun Heo 提交于
      Core sysfs implementation will be separated into kernfs so that it can
      be used by other non-kobject users.
      
      This patch creates fs/kernfs/ directory and makes boilerplate changes.
      kernfs interface will be directly based on sysfs_dirent and its
      forward declaration is moved to include/linux/kernfs.h which is
      included from include/linux/sysfs.h.  sysfs core implementation will
      be gradually separated out and moved to kernfs.
      
      This patch doesn't introduce any functional changes.
      
      v2: mount.c added.
      Signed-off-by: NTejun Heo <tj@kernel.org>
      Cc: linux-fsdevel@vger.kernel.org
      Cc: Christoph Hellwig <hch@infradead.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      b8441ed2