1. 09 12月, 2013 4 次提交
  2. 08 12月, 2013 2 次提交
  3. 04 12月, 2013 3 次提交
    • 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
    • T
      kernfs: update sysfs_init_inode_attrs() · 9a8049af
      Tejun Heo 提交于
      sysfs_init_inode_attrs() is a bit clumsy to use requiring the caller
      to check whether @sd->s_iattr is already set or not.  Rename it to
      sysfs_inode_attrs(), update it to check whether @sd->s_iattr is
      already initialized before trying to initialize it and return
      @sd->s_iattr.  This simplifies the callers.
      
      While at it,
      
      * Rename struct sysfs_inode_attrs pointer variables to "attrs".  As
        kernfs no longer deals with "struct attribute", this isn't confusing
        and makes it easier to distinguish from struct iattr pointers.
      
      * A new field will be added to sysfs_inode_attrs.  Reindent in
        preparation.
      
      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>
      9a8049af
    • B
      kobject: fix kset sample error path · e756bc56
      Bjorn Helgaas 提交于
      Previously, example_init() leaked a kset if any of the object creations
      failed.  This fixes the leak by calling kset_unregister() in the error
      path.
      Signed-off-by: NBjorn Helgaas <bhelgaas@google.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      e756bc56
  4. 30 11月, 2013 31 次提交
    • T
      sysfs, kernfs: remove cross inclusions of internal headers · bfc5c173
      Tejun Heo 提交于
      fs/kernfs/kernfs-internal.h needed to include fs/sysfs/sysfs.h because
      part of kernfs core implementation was living in sysfs.
      
      fs/sysfs/sysfs.h needed to include fs/kernfs/kernfs-internal.h because
      include/linux/kernfs.h didn't expose enough interface.
      
      The separation is complete and neither is true anymore.  Remove the
      cross inclusion and make sysfs a proper user of kernfs.
      Signed-off-by: NTejun Heo <tj@kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      bfc5c173
    • 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: move mount core code to fs/kernfs/mount.c · fa736a95
      Tejun Heo 提交于
      Move core mount code to fs/kernfs/mount.c.  The respective
      declarations in fs/sysfs/sysfs.h are moved to
      fs/kernfs/kernfs-internal.h.
      
      This is pure relocation.
      Signed-off-by: NTejun Heo <tj@kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      fa736a95
    • T
      sysfs, kernfs: prepare mount path for kernfs · 4b93dc9b
      Tejun Heo 提交于
      We're in the process of separating out core sysfs functionality into
      kernfs which will deal with sysfs_dirents directly.  This patch
      rearranges mount path so that the kernfs and sysfs parts are separate.
      
      * As sysfs_super_info won't be visible outside kernfs proper,
        kernfs_super_ns() is added to allow kernfs users to access a
        super_block's namespace tag.
      
      * Generic mount operation is separated out into kernfs_mount_ns().
        sysfs_mount() now just performs sysfs-specific permission check,
        acquires namespace tag, and invokes kernfs_mount_ns().
      
      * Generic superblock release is separated out into kernfs_kill_sb()
        which can be used directly as file_system_type->kill_sb().  As sysfs
        needs to put the namespace tag, sysfs_kill_sb() wraps
        kernfs_kill_sb() with ns tag put.
      
      * sysfs_dir_cachep init and sysfs_inode_init() are separated out into
        kernfs_init().  kernfs_init() uses only small amount of memory and
        trying to handle and propagate kernfs_init() failure doesn't make
        much sense.  Use SLAB_PANIC for sysfs_dir_cachep and make
        sysfs_inode_init() panic on failure.
      
        After this change, kernfs_init() should be called before
        sysfs_init(), fs/namespace.c::mnt_init() modified accordingly.
      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>
      4b93dc9b
    • T
      sysfs, kernfs: make super_blocks bind to different kernfs_roots · df394fb5
      Tejun Heo 提交于
      kernfs is being updated to allow multiple sysfs_dirent hierarchies so
      that it can also be used by other users.  Currently, sysfs
      super_blocks are always attached to one kernfs_root - sysfs_root - and
      distinguished only by their namespace tags.
      
      This patch adds sysfs_super_info->root and update
      sysfs_fill/test_super() so that super_blocks are identified by the
      combination of both the associated kernfs_root and namespace tag.
      This allows mounting different kernfs hierarchies.
      Signed-off-by: NTejun Heo <tj@kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      df394fb5
    • 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: introduce sysfs_root_sd · 061447a4
      Tejun Heo 提交于
      Currently, it's assumed that there's a single kernfs hierarchy in the
      system anchored at sysfs_root which is defined as a global struct.  To
      allow other users of kernfs, this will be made dynamic.  Introduce a
      new global variable sysfs_root_sd which points to &sysfs_root and
      convert all &sysfs_root users.
      
      This patch doesn't introduce any behavior difference.
      Signed-off-by: NTejun Heo <tj@kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      061447a4
    • T
      sysfs, kernfs: no need to kern_mount() sysfs from sysfs_init() · 9e30cc95
      Tejun Heo 提交于
      It has been very long since sysfs depended on vfs to keep track of
      internal states and whether sysfs is mounted or not doesn't make any
      difference to sysfs's internal operation.
      
      In addition to init and filesystem type registration, sysfs_init()
      invokes kern_mount() to create in-kernel mount of sysfs.  This
      internal mounting doesn't server any purpose anymore.  Remove it.
      Signed-off-by: NTejun Heo <tj@kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      9e30cc95
    • T
      sysfs, kernfs: make sysfs_super_info->ns const · 51a35e9f
      Tejun Heo 提交于
      Add const qualifier to sysfs_super_info->ns so that it's consistent
      with other namespace tag usages in sysfs.  Because kobject doesn't use
      const qualifier for namespace tags, this ends up requiring an explicit
      cast to drop const qualifier in free_sysfs_super_info().
      Signed-off-by: NTejun Heo <tj@kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      51a35e9f
    • T
      sysfs, kernfs: drop unused params from sysfs_fill_super() · ccc532dc
      Tejun Heo 提交于
      sysfs_fill_super() takes three params - @sb, @data and @silent - but
      uses only @sb.  Drop the latter two.
      Signed-off-by: NTejun Heo <tj@kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      ccc532dc
    • T
      sysfs, kernfs: move symlink core code to fs/kernfs/symlink.c · 2072f1af
      Tejun Heo 提交于
      Move core symlink code to fs/kernfs/symlink.c.  fs/sysfs/symlink.c now
      only contains 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.
      Signed-off-by: NTejun Heo <tj@kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      2072f1af
    • T
      sysfs, kernfs: move file core code to fs/kernfs/file.c · 414985ae
      Tejun Heo 提交于
      Move core file code to fs/kernfs/file.c.  fs/sysfs/file.c now contains
      sysfs kernfs_ops callbacks, sysfs wrappers around kernfs interfaces,
      and sysfs_schedule_callback().  The respective declarations in
      fs/sysfs/sysfs.h are moved to fs/kernfs/kernfs-internal.h.
      
      This is pure relocation.
      
      v2: Refreshed on top of the v2 of "sysfs, kernfs: prepare read path
          for kernfs".
      
      v3: Refreshed on top of the v3 of "sysfs, kernfs: prepare read path
          for kernfs".
      Signed-off-by: NTejun Heo <tj@kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      414985ae
    • 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
    • T
      sysfs, kernfs: move inode code to fs/kernfs/inode.c · ffed24e2
      Tejun Heo 提交于
      There's nothing sysfs-specific in fs/sysfs/inode.c.  Move everything
      in it to fs/kernfs/inode.c.  The respective declarations in
      fs/sysfs/sysfs.h are moved to fs/kernfs/kernfs-internal.h.
      
      This is pure relocation.
      Signed-off-by: NTejun Heo <tj@kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      ffed24e2
    • T
      sysfs, kernfs: move internal decls to fs/kernfs/kernfs-internal.h · ae6621b0
      Tejun Heo 提交于
      Move data structure, constant and basic accessor declarations from
      fs/sysfs/sysfs.h to fs/kernfs/kernfs-internal.h.  The two files
      currently include each other.  Once kernfs / sysfs separation is
      complete, the cross inclusions will be removed.  Inclusion protectors
      are added to fs/sysfs/sysfs.h to allow cross-inclusion.
      
      This patch doesn't introduce any functional changes.
      Signed-off-by: NTejun Heo <tj@kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      ae6621b0
    • T
      sysfs, kernfs: introduce kernfs[_find_and]_get() and kernfs_put() · ccf73cf3
      Tejun Heo 提交于
      Introduce kernfs interface for finding, getting and putting
      sysfs_dirents.
      
      * sysfs_find_dirent() is renamed to kernfs_find_ns() and lockdep
        assertion for sysfs_mutex is added.
      
      * sysfs_get_dirent_ns() is renamed to kernfs_find_and_get().
      
      * Macro inline dancing around __sysfs_get/put() are removed and
        kernfs_get/put() are made proper functions implemented in
        fs/sysfs/dir.c.
      
      While the conversions are mostly equivalent, there's one difference -
      kernfs_get() doesn't return the input param as its return value.  This
      change is intentional.  While passing through the input increases
      writability in some areas, it is unnecessary and has been shown to
      cause confusion regarding how the last ref is handled.
      Signed-off-by: NTejun Heo <tj@kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      ccf73cf3
    • T
      sysfs, kernfs: revamp sysfs_dirent active_ref lockdep annotation · 517e64f5
      Tejun Heo 提交于
      Currently, sysfs_dirent active_ref lockdep annotation uses
      attribute->[s]key as the lockdep key, which forces
      kernfs_create_file_ns() to assume that sysfs_dirent->priv is pointing
      to a struct attribute which may not be true for non-sysfs users.  This
      patch restructures the lockdep annotation such that
      
      * kernfs_ops contains lockdep_key which is used by default for files
        created kernfs_create_file_ns().
      
      * kernfs_create_file_ns_key() is introduced which takes an extra @key
        argument.  The created file will use the specified key for
        active_ref lockdep annotation.  If NULL is specified, lockdep for
        the file is disabled.
      
      * sysfs_add_file_mode_ns() is updated to use
        kernfs_create_file_ns_key() with the appropriate key from the
        attribute or NULL if ignore_lockdep is set.
      
      This makes the lockdep annotation properly contained in kernfs while
      allowing sysfs to cleanly keep its current behavior.  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>
      517e64f5
    • T
      sysfs, kernfs: reorganize SYSFS_* constants · 2b25a629
      Tejun Heo 提交于
      We want to add one more SYSFS_FLAG_* but we can't use the next higher
      bit, 0x10000, as the flag field is 16bits wide.  The flags are
      currently arranged weirdly - 8 bits are set aside for the type flags
      when there are only three three used, the first flag starts at 0x1000
      instead of 0x0100 and flag literals have 5 digits (20 bits) when only
      4 digits can be used.
      
      Rearrange them so that type bits are only the lowest four, flags start
      at 0x0010 and similar flags are grouped.
      
      This patch doesn't cause any behavior difference.
      Signed-off-by: NTejun Heo <tj@kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      2b25a629
    • T
      sysfs, kernfs: introduce kernfs_notify() · 024f6471
      Tejun Heo 提交于
      Introduce kernfs interface to wake up poll(2) which takes and returns
      sysfs_dirents.
      
      sysfs_notify_dirent() is renamed to kernfs_notify() and sysfs_notify()
      is updated so that it doesn't directly grab sysfs_mutex but acquires
      the target sysfs_dirents using sysfs_get_dirent().
      sysfs_notify_dirent() is reimplemented as a dumb inline wrapper around
      kernfs_notify().
      
      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>
      024f6471
    • T
      sysfs, kernfs: add kernfs_ops->seq_{start|next|stop}() · d19b9846
      Tejun Heo 提交于
      kernfs_ops currently only supports single_open() behavior which is
      pretty restrictive.  Add optional callbacks ->seq_{start|next|stop}()
      which, when implemented, are invoked for seq_file traversal.  This
      allows full seq_file functionality for kernfs users.  This currently
      doesn't have any user and doesn't change any behavior.
      
      v2: Refreshed on top of the updated "sysfs, kernfs: prepare read path
          for kernfs".
      Signed-off-by: NTejun Heo <tj@kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      d19b9846
    • T
      sysfs, kernfs: remove sysfs_add_one() · 2d0cfbec
      Tejun Heo 提交于
      sysfs_add_one() is a wrapper around __sysfs_add_one() which prints out
      duplicate name warning if __sysfs_add_one() fails with -EEXIST.  The
      previous kernfs conversions moved all dup warnings to sysfs interface
      functions and sysfs_add_one() doesn't have any user left.
      
      Remove sysfs_add_one() and update __sysfs_add_one() to take its name.
      
      This patch doesn't make any functional changes.
      Signed-off-by: NTejun Heo <tj@kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      2d0cfbec
    • T
      sysfs, kernfs: introduce kernfs_create_file[_ns]() · 496f7394
      Tejun Heo 提交于
      Introduce kernfs interface to create a file which takes and returns
      sysfs_dirents.
      
      The actual file creation part is separated out from
      sysfs_add_file_mode_ns() into kernfs_create_file_ns().  The former now
      only decides the kernfs_ops to use and the file's size and invokes the
      latter.
      
      This patch doesn't introduce behavior changes.
      
      v2: Dummy implementation for !CONFIG_SYSFS updated to return -ENOSYS.
      Signed-off-by: NTejun Heo <tj@kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      496f7394
    • T
      sysfs, kernfs: remove SYSFS_KOBJ_BIN_ATTR · a7dc66df
      Tejun Heo 提交于
      After kernfs_ops and sysfs_dirent->s_attr.size addition, the
      distinction between SYSFS_KOBJ_BIN_ATTR and SYSFS_KOBJ_ATTR is only
      necessary while creating files to decide which kernfs_ops to use.
      Afterwards, they behave exactly the same.
      
      This patch removes SYSFS_KOBJ_BIN_ATTR along with sysfs_is_bin().
      sysfs_add_file[_mode_ns]() are updated to take bool @is_bin instead of
      @type.
      
      This patch doesn't introduce any behavior changes.  This completely
      isolates the distinction between the two sysfs file types in the sysfs
      layer proper.
      Signed-off-by: NTejun Heo <tj@kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      a7dc66df
    • T
      sysfs, kernfs: add sysfs_dirent->s_attr.size · 471bd7b7
      Tejun Heo 提交于
      sysfs sets the size of regular files unconditionally at PAGE_SIZE and
      takes the size of bin files from bin_attribute.  The latter is a
      pretty bad interface which forces bin_attribute users to create a
      separate copy of bin_attribute for each instance of the file -
      e.g. pci resource files.
      
      Add sysfs_dirent->s_attr.size so that the size can be specified
      separately.  This unifies inode init paths of ATTR and BIN_ATTR
      identical and allows for generic size handling for kernfs.
      
      Unfortunately, this grows the size of sysfs_dirent by sizeof(loff_t).
      Signed-off-by: NTejun Heo <tj@kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      471bd7b7
    • T
      sysfs, kernfs: introduce kernfs_ops · f6acf8bb
      Tejun Heo 提交于
      We're in the process of separating out core sysfs functionality into
      kernfs which will deal with sysfs_dirents directly.  This patch
      introduces kernfs_ops which hosts methods kernfs users implement and
      updates fs/sysfs/file.c such that sysfs_kf_*() functions populate
      kernfs_ops and kernfs_file_*() functions call the matching entries
      from kernfs_ops.
      
      kernfs_ops contains the following groups of methods.
      
      * seq_show() - for kernfs files which use seq_file for reads.
      
      * read() - for direct read implementations.  Used iff seq_show() is
        not implemented.
      
      * write() - for writes.
      
      * mmap() - for mmaps.
      
      Notes:
      
      * sysfs_elem_attr->ops is added so that kernfs_ops can be accessed
        from sysfs_dirent.  kernfs_ops() helper is added to verify locking
        and access the field.
      
      * SYSFS_FLAG_HAS_(SEQ_SHOW|MMAP) added.  sd->s_attr->ops is accessible
        only while holding active_ref and there are cases where we want to
        take different actions depending on which ops are implemented.
        These two flags cache whether the two ops are implemented for those.
      
      * kernfs_file_*() no longer test sysfs type but chooses different
        behaviors depending on which methods in kernfs_ops are implemented.
        The conversions are trivial except for the open path.  As
        kernfs_file_open() now decides whether to allow read/write accesses
        depending on the kernfs_ops implemented, the presence of methods in
        kobjs and attribute_bin should be propagated to kernfs_ops.
        sysfs_add_file_mode_ns() is updated so that it propagates presence /
        absence of the callbacks through _empty, _ro, _wo, _rw kernfs_ops.
      Signed-off-by: NTejun Heo <tj@kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      f6acf8bb
    • T
      sysfs, kernfs: move sysfs_open_file to include/linux/kernfs.h · dd8a5b03
      Tejun Heo 提交于
      sysfs_open_file will be used as the primary handle for kernfs methods.
      Move its definition from fs/sysfs/file.c to include/linux/kernfs.h and
      mark the public and private fields.
      
      This is pure relocation.
      Signed-off-by: NTejun Heo <tj@kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      dd8a5b03
    • T
      sysfs, kernfs: prepare open, release, poll paths for kernfs · c6fb4495
      Tejun Heo 提交于
      We're in the process of separating out core sysfs functionality into
      kernfs which will deal with sysfs_dirents directly.  This patch
      prepares the rest - open, release and poll.  There isn't much to do.
      Just renaming is enough.  As sysfs_file_operations and
      sysfs_bin_operations are identical now, use the same file_operations
      for both - kernfs_file_operations.
      
      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>
      c6fb4495
    • T
      sysfs, kernfs: prepare mmap path for kernfs · fdbffaa4
      Tejun Heo 提交于
      We're in the process of separating out core sysfs functionality into
      kernfs which will deal with sysfs_dirents directly.  This patch
      rearranges mmap path so that the kernfs and sysfs parts are separate.
      
      sysfs_kf_bin_mmap() which handles the interaction with bin_attribute
      mmap method is factored out of sysfs_bin_mmap(), which is renamed to
      kernfs_file_mmap().  All vma ops are renamed accordingly.
      
      sysfs_bin_mmap() is updated such that it can be used for both file
      types.  This will eventually allow using the same file_operations for
      both file types, which is necessary to separate out kernfs.
      
      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>
      fdbffaa4
    • T
      sysfs, kernfs: prepare write path for kernfs · 50b38ca0
      Tejun Heo 提交于
      We're in the process of separating out core sysfs functionality into
      kernfs which will deal with sysfs_dirents directly.  This patch
      rearranges write path so that the kernfs and sysfs parts are separate.
      
      kernfs_file_write() handles all boilerplate work including buffer
      management and locking and invokes sysfs_kf_write() or
      sysfs_kf_bin_write() depending on the file type which deals with the
      interaction with kobj store or bin_attribute write method.
      
      While this patch changes the order of some operations, it shouldn't
      change any visible behavior.
      Signed-off-by: NTejun Heo <tj@kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      50b38ca0