1. 30 11月, 2013 11 次提交
    • 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
    • T
      sysfs, kernfs: prepare read path for kernfs · c2b19daf
      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 read path so that the kernfs and sysfs parts are separate.
      
      * Regular file read path is refactored such that
        kernfs_seq_start/next/stop/show() handle all the boilerplate work
        including locking and updating event count for poll, while
        sysfs_kf_seq_show() deals with interaction with kobj show method.
      
      * Bin file read path is refactored such that kernfs_file_direct_read()
        handles all the boilerplate work including buffer management and
        locking, while sysfs_kf_bin_read() deals with interaction with
        bin_attribute read method.
      
      kernfs_file_read() is added.  It invokes either the seq_file or direct
      read path depending on the file type.  This will eventually allow
      using the same file_operations for both file types, which is necessary
      to separate out kernfs.
      
      While this patch changes the order of some operations, it shouldn't
      change any visible behavior.
      
      v2: Dropped unnecessary zeroing of @count from sysfs_kf_seq_show().
          Add comments explaining single_open() behavior.  Both suggested by
          Pavel.
      
      v3: seq_stop() is called even after seq_start() failed.
          kernfs_seq_start() updated so that it doesn't unlock
          sysfs_open_file->mutex on failure so that kernfs_seq_stop()
          doesn't try to unlock an already unlocked mutex.  Reported by
          Fengguang.
      Signed-off-by: NTejun Heo <tj@kernel.org>
      Cc: Pavel Machek <pavel@ucw.cz>
      Cc: Fengguang Wu <fengguang.wu@intel.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      c2b19daf
    • T
      sysfs, kernfs: replace sysfs_dirent->s_dir.kobj and ->s_attr.[bin_]attr with ->priv · 7c6e2d36
      Tejun Heo 提交于
      A directory sysfs_dirent points to the associated kobj.  A regular or
      bin file points to the associated [bin_]attribute.  This patch
      replaces sysfs_dirent->s_dir.kobj and ->s_attr.[bin_]attr with void *
      ->priv.
      
      This is to prepare for kernfs interface so that sysfs can specify the
      private data in the same way for directories and files.  This lower
      debuggability but not by much - the whole thing was overlaid in a
      union anyway.  If debuggability becomes an issue, we can later add
      ->priv accessors which explicitly check for the sysfs_dirent type and
      performs casting.
      
      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>
      7c6e2d36
  2. 28 11月, 2013 2 次提交
  3. 24 11月, 2013 1 次提交
    • T
      sysfs: use a separate locking class for open files depending on mmap · 027a485d
      Tejun Heo 提交于
      The following two commits implemented mmap support in the regular file
      path and merged bin file support into the regular path.
      
       73d97146 ("sysfs: copy bin mmap support from fs/sysfs/bin.c to fs/sysfs/file.c")
       3124eb16 ("sysfs: merge regular and bin file handling")
      
      After the merge, the following commands trigger a spurious lockdep
      warning.  "test-mmap-read" simply mmaps the file and dumps the
      content.
      
        $ cat /sys/block/sda/trace/act_mask
        $ test-mmap-read /sys/devices/pci0000\:00/0000\:00\:03.0/resource0 4096
      
        ======================================================
        [ INFO: possible circular locking dependency detected ]
        3.12.0-work+ #378 Not tainted
        -------------------------------------------------------
        test-mmap-read/567 is trying to acquire lock:
         (&of->mutex){+.+.+.}, at: [<ffffffff8120a8df>] sysfs_bin_mmap+0x4f/0x120
      
        but task is already holding lock:
         (&mm->mmap_sem){++++++}, at: [<ffffffff8114b399>] vm_mmap_pgoff+0x49/0xa0
      
        which lock already depends on the new lock.
      
        the existing dependency chain (in reverse order) is:
      
        -> #3 (&mm->mmap_sem){++++++}:
        ...
        -> #2 (sr_mutex){+.+.+.}:
        ...
        -> #1 (&bdev->bd_mutex){+.+.+.}:
        ...
        -> #0 (&of->mutex){+.+.+.}:
        ...
      
        other info that might help us debug this:
      
        Chain exists of:
         &of->mutex --> sr_mutex --> &mm->mmap_sem
      
         Possible unsafe locking scenario:
      
      	 CPU0                    CPU1
      	 ----                    ----
          lock(&mm->mmap_sem);
      				 lock(sr_mutex);
      				 lock(&mm->mmap_sem);
          lock(&of->mutex);
      
         *** DEADLOCK ***
      
        1 lock held by test-mmap-read/567:
         #0:  (&mm->mmap_sem){++++++}, at: [<ffffffff8114b399>] vm_mmap_pgoff+0x49/0xa0
      
        stack backtrace:
        CPU: 3 PID: 567 Comm: test-mmap-read Not tainted 3.12.0-work+ #378
        Hardware name: Bochs Bochs, BIOS Bochs 01/01/2011
         ffffffff81ed41a0 ffff880009441bc8 ffffffff81611ad2 ffffffff81eccb80
         ffff880009441c08 ffffffff8160f215 ffff880009441c60 ffff880009c75208
         0000000000000000 ffff880009c751e0 ffff880009c75208 ffff880009c74ac0
        Call Trace:
         [<ffffffff81611ad2>] dump_stack+0x4e/0x7a
         [<ffffffff8160f215>] print_circular_bug+0x2b0/0x2bf
         [<ffffffff8109ca0a>] __lock_acquire+0x1a3a/0x1e60
         [<ffffffff8109d6ba>] lock_acquire+0x9a/0x1d0
         [<ffffffff81615547>] mutex_lock_nested+0x67/0x3f0
         [<ffffffff8120a8df>] sysfs_bin_mmap+0x4f/0x120
         [<ffffffff8115d363>] mmap_region+0x3b3/0x5b0
         [<ffffffff8115d8ae>] do_mmap_pgoff+0x34e/0x3d0
         [<ffffffff8114b3ba>] vm_mmap_pgoff+0x6a/0xa0
         [<ffffffff8115be3e>] SyS_mmap_pgoff+0xbe/0x250
         [<ffffffff81008282>] SyS_mmap+0x22/0x30
         [<ffffffff8161a4d2>] system_call_fastpath+0x16/0x1b
      
      This happens because one file nests sr_mutex, which nests mm->mmap_sem
      under it, under of->mutex while mmap implementation naturally nests
      of->mutex under mm->mmap_sem.  The warning is false positive as
      of->mutex is per open-file and the two paths belong to two different
      files.  This warning didn't trigger before regular and bin file
      supports were merged because only bin file supported mmap and the
      other side of locking happened only on regular files which used
      equivalent but separate locking.
      
      It'd be best if we give separate locking classes per file but we can't
      easily do that.  Let's differentiate on ->mmap() for now.  Later we'll
      add explicit file operations struct and can add per-ops lockdep key
      there.
      Signed-off-by: NTejun Heo <tj@kernel.org>
      Reported-by: NDave Jones <davej@redhat.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      027a485d
  4. 02 11月, 2013 1 次提交
    • T
      sysfs: use generic_file_llseek() for sysfs_file_operations · 044e3bc3
      Tejun Heo 提交于
      13c589d5 ("sysfs: use seq_file when reading regular files")
      converted regular sysfs files to use seq_file.  The commit substituted
      generic_file_llseek() with seq_lseek() for llseek implementation.
      
      Before the change, all regular sysfs files were allowed to seek to any
      position in [0, PAGE_SIZE] as the file size is always PAGE_SIZE and
      generic_file_llseek() allows any seeking inside the range under file
      size; however, seq_lseek()'s behavior is different.  It traverses the
      output by repeatedly invoking ->show() until it reaches the target
      offset or traversal indicates EOF.  As seq_files are fully dynamic and
      may not end at all, it doesn't support seeking from the end
      (SEEK_END).
      
      Apparently, there are userland tools which uses SEEK_END to discover
      the buffer size to use and the switch to seq_lseek() disturbs them as
      SEEK_END fails with -EINVAL.
      
      The only benefits of using seq_lseek() instead of
      generic_file_llseek() are
      
      * Early failure.  If traversing to certain file position should fail,
        seq_lseek() will report such failures on lseek(2) instead of the
        following read/write operations.
      
      * EOF detection.  While SEEK_END is not supported, SEEK_SET/CUR +
        large offset can be used to detect eof - eof at the time of the seek
        anyway as the file size may change dynamically.
      
      Both aren't necessary for sysfs or prospect kernfs users.  Revert to
      genefic_file_llseek() and preserve the original behavior.
      Signed-off-by: NTejun Heo <tj@kernel.org>
      Reported-by: NHeiko Carstens <heiko.carstens@de.ibm.com>
      Link: https://lkml.kernel.org/r/20131031114358.GA5551@osirisTested-by: NHeiko Carstens <heiko.carstens@de.ibm.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      044e3bc3
  5. 31 10月, 2013 1 次提交
  6. 30 10月, 2013 1 次提交
    • T
      sysfs: merge sysfs_elem_bin_attr into sysfs_elem_attr · 56b3f3b8
      Tejun Heo 提交于
      3124eb16 ("sysfs: merge regular and bin file handling") folded bin
      file handling into regular file handling.  Among other things, bin
      file now shares the same open path including sysfs_open_dirent
      association using sysfs_dirent->s_attr.open.  This is buggy because
      ->s_bin_attr lives in the same union and doesn't have the field.  This
      bug doesn't trigger because sysfs_elem_bin_attr doesn't have an active
      field at the conflicting position.  It does have a field "buffers" but
      it isn't used anymore.
      
      This patch collapses sysfs_elem_bin_attr into sysfs_elem_attr so that
      the bin_attr is accessed through ->s_attr.bin_attr which lives with
      ->s_attr.attr in an anonymous union.  The code paths already assume
      bin_attr contains attr as the first element, so this doesn't add any
      more assumptions while making it explicit that the two types are
      handled together.
      Signed-off-by: NTejun Heo <tj@kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      56b3f3b8
  7. 25 10月, 2013 1 次提交
  8. 15 10月, 2013 1 次提交
  9. 14 10月, 2013 1 次提交
    • T
      sysfs: make sysfs_file_ops() follow ignore_lockdep flag · 785a162d
      Tejun Heo 提交于
      375b611e ("sysfs: remove sysfs_buffer->ops") introduced
      sysfs_file_ops() which determines the associated file operation of a
      given sysfs_dirent.  As file ops access should be protected by an
      active reference, the new function includes a lockdep assertion on the
      sysfs_dirent; unfortunately, I forgot to take attr->ignore_lockdep
      flag into account and the lockdep assertion trips spuriously for files
      which opt out from active reference lockdep checking.
      
      # cat /sys/devices/pci0000:00/0000:00:01.2/usb1/authorized
      
       ------------[ cut here ]------------
       WARNING: CPU: 1 PID: 540 at /work/os/work/fs/sysfs/file.c:79 sysfs_file_ops+0x4e/0x60()
       Modules linked in:
       CPU: 1 PID: 540 Comm: cat Not tainted 3.11.0-work+ #3
       Hardware name: Bochs Bochs, BIOS Bochs 01/01/2011
        0000000000000009 ffff880016205c08 ffffffff81ca0131 0000000000000000
        ffff880016205c40 ffffffff81096d0d ffff8800166cb898 ffff8800166f6f60
        ffffffff8125a220 ffff880011ab1ec0 ffff88000aff0c78 ffff880016205c50
       Call Trace:
        [<ffffffff81ca0131>] dump_stack+0x4e/0x82
        [<ffffffff81096d0d>] warn_slowpath_common+0x7d/0xa0
        [<ffffffff81096dea>] warn_slowpath_null+0x1a/0x20
        [<ffffffff8125994e>] sysfs_file_ops+0x4e/0x60
        [<ffffffff8125a274>] sysfs_open_file+0x54/0x300
        [<ffffffff811df612>] do_dentry_open.isra.17+0x182/0x280
        [<ffffffff811df820>] finish_open+0x30/0x40
        [<ffffffff811f0623>] do_last+0x503/0xd90
        [<ffffffff811f0f6b>] path_openat+0xbb/0x6d0
        [<ffffffff811f23ba>] do_filp_open+0x3a/0x90
        [<ffffffff811e09a9>] do_sys_open+0x129/0x220
        [<ffffffff811e0abe>] SyS_open+0x1e/0x20
        [<ffffffff81caf3c2>] system_call_fastpath+0x16/0x1b
       ---[ end trace aa48096b111dafdb ]---
      
      Rename fs/sysfs/dir.c::ignore_lockdep() to sysfs_ignore_lockdep() and
      move it to fs/sysfs/sysfs.h and make sysfs_file_ops() skip lockdep
      assertion if sysfs_ignore_lockdep() is true.
      Signed-off-by: NTejun Heo <tj@kernel.org>
      Reported-by: NYinghai Lu <yinghai@kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      785a162d
  10. 06 10月, 2013 13 次提交
    • T
      sysfs: merge regular and bin file handling · 3124eb16
      Tejun Heo 提交于
      With the previous changes, sysfs regular file code is ready to handle
      bin files too.  This patch makes bin files share the regular file
      path.
      
      * sysfs_create/remove_bin_file() are moved to fs/sysfs/file.c.
      
      * sysfs_init_inode() is updated to use the new sysfs_bin_operations
        instead of bin_fops for bin files.
      
      * fs/sysfs/bin.c and the related pieces are removed.
      
      This patch shouldn't introduce any behavior difference to bin file
      accesses.
      
      Overall, this unification reduces the amount of duplicate logic, makes
      behaviors more consistent and paves the road for building simpler and
      more versatile interface which will allow other subsystems to make use
      of sysfs for their pseudo filesystems.
      
      v2: Stale fs/sysfs/bin.c reference dropped from
          Documentation/DocBook/filesystems.tmpl.  Reported by kbuild test
          robot.
      Signed-off-by: NTejun Heo <tj@kernel.org>
      Cc: Kay Sievers <kay@vrfy.org>
      Cc: kbuild test robot <fengguang.wu@intel.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      3124eb16
    • T
      sysfs: prepare open path for unified regular / bin file handling · 49fe6047
      Tejun Heo 提交于
      sysfs bin file handling will be merged into the regular file support.
      This patch prepares the open path.
      
      This patch updates sysfs_open_file() such that it can handle both
      regular and bin files.
      
      This is a preparation and the new bin file path isn't used yet.
      Signed-off-by: NTejun Heo <tj@kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      49fe6047
    • T
      sysfs: copy bin mmap support from fs/sysfs/bin.c to fs/sysfs/file.c · 73d97146
      Tejun Heo 提交于
      sysfs bin file handling will be merged into the regular file support.
      This patch copies mmap support from bin so that fs/sysfs/file.c can
      handle mmapping bin files.
      
      The code is copied mostly verbatim with the following updates.
      
      * ->mmapped and ->vm_ops are added to sysfs_open_file and bin_buffer
        references are replaced with sysfs_open_file ones.
      
      * Symbols are prefixed with sysfs_.
      
      * sysfs_unmap_bin_file() grabs sysfs_open_dirent and traverses
        ->files.  Invocation of this function is added to
        sysfs_addrm_finish().
      
      * sysfs_bin_mmap() is added to sysfs_bin_operations.
      
      This is a preparation and the new mmap path isn't used yet.
      Signed-off-by: NTejun Heo <tj@kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      73d97146
    • T
      sysfs: add sysfs_bin_read() · 2f0c6b75
      Tejun Heo 提交于
      sysfs bin file handling will be merged into the regular file support.
      This patch prepares the read path.
      
      Copy fs/sysfs/bin.c::read() to fs/sysfs/file.c and make it use
      sysfs_open_file instead of bin_buffer.  The function is identical copy
      except for the use of sysfs_open_file.
      
      The new function is added to sysfs_bin_operations.  This isn't used
      yet but will eventually replace fs/sysfs/bin.c.
      Signed-off-by: NTejun Heo <tj@kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      2f0c6b75
    • T
      sysfs: prepare path write for unified regular / bin file handling · f9b9a621
      Tejun Heo 提交于
      sysfs bin file handling will be merged into the regular file support.
      This patch prepares the write path.
      
      bin file write is almost identical to regular file write except that
      the write length is capped by the inode size and @off is passed to the
      write method.  This patch adds bin file handling to sysfs_write_file()
      so that it can handle both regular and bin files.
      
      A new file_operations struct sysfs_bin_operations is added, which
      currently only hosts sysfs_write_file() and generic_file_llseek().
      This isn't used yet but will eventually replace fs/sysfs/bin.c.
      Signed-off-by: NTejun Heo <tj@kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      f9b9a621
    • T
      sysfs: use seq_file when reading regular files · 13c589d5
      Tejun Heo 提交于
      sysfs read path implements its own buffering scheme between userland
      and kernel callbacks, which essentially is a degenerate duplicate of
      seq_file.  This patch replaces the custom read buffering
      implementation in sysfs with seq_file.
      
      While the amount of code reduction is small, this reduces low level
      hairiness and enables future development of a new versatile API based
      on seq_file so that sysfs features can be shared with other
      subsystems.
      
      As write path was already converted to not use sysfs_open_file->page,
      this patch makes ->page and ->count unused and removes them.
      
      Userland behavior remains the same except for some extreme corner
      cases - e.g. sysfs will now regenerate the content each time a file is
      read after a non-contiguous seek whereas the original code would keep
      using the same content.  While this is a userland visible behavior
      change, it is extremely unlikely to be noticeable and brings sysfs
      behavior closer to that of procfs.
      Signed-off-by: NTejun Heo <tj@kernel.org>
      Cc: Kay Sievers <kay@vrfy.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      13c589d5
    • T
      sysfs: use transient write buffer · 8ef445f0
      Tejun Heo 提交于
      There isn't much to be gained by keeping around kernel buffer while a
      file is open especially as the read path planned to be converted to
      use seq_file and won't use the buffer.  This patch makes
      sysfs_write_file() use per-write transient buffer instead of
      sysfs_open_file->page.
      
      This simplifies the write path, enables removing sysfs_open_file->page
      once read path is updated and will help merging bin file write path
      which already requires the use of a transient buffer due to a locking
      order issue.
      
      As the function comments of flush_write_buffer() and
      sysfs_write_buffer() are being updated anyway, reformat them so that
      they're more conventional.
      
      v2: Use min_t() instead of min() in sysfs_write_file() to avoid build
          warning on arm.  Reported by build test robot.
      Signed-off-by: NTejun Heo <tj@kernel.org>
      Cc: kbuild test robot <fengguang.wu@intel.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      8ef445f0
    • T
      sysfs: add sysfs_open_file->sd and ->file · bcafe4ee
      Tejun Heo 提交于
      sysfs will be converted to use seq_file for read path, which will make
      it difficult to pass around multiple pointers directly.  This patch
      adds sysfs_open_file->sd and ->file so that we can reach all the
      necessary data structures from sysfs_open_file.
      
      flush_write_buffer() is updated to drop @dentry which was used to
      discover the sysfs_dirent as it's now available through
      sysfs_open_file->sd.
      
      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>
      bcafe4ee
    • T
      sysfs: rename sysfs_buffer to sysfs_open_file · 58282d8d
      Tejun Heo 提交于
      sysfs read path will be converted to use seq_file which will handle
      buffering making sysfs_buffer a misnomer.  Rename sysfs_buffer to
      sysfs_open_file, and sysfs_open_dirent->buffers to ->files.
      
      This path is pure rename.
      Signed-off-by: NTejun Heo <tj@kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      58282d8d
    • T
      sysfs: add sysfs_open_file_mutex · c75ec764
      Tejun Heo 提交于
      Add a separate mutex to protect sysfs_open_dirent->buffers list.  This
      will allow performing sleepable operations while traversing
      sysfs_buffers, which will be renamed to sysfs_open_file.
      
      Note that currently sysfs_open_dirent->buffers list isn't being used
      for anything and this patch doesn't make any functional difference.
      It will be used to merge regular and bin file supports.
      Signed-off-by: NTejun Heo <tj@kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      c75ec764
    • T
      sysfs: remove sysfs_buffer->ops · 375b611e
      Tejun Heo 提交于
      Currently, sysfs_ops is fetched during sysfs_open_file() and cached in
      sysfs_buffer->ops to be used while the file is open.  This patch
      removes the caching and makes each operation directly fetch sysfs_ops.
      
      This patch doesn't introduce any behavior difference and is to prepare
      for merging regular and bin file supports.
      Signed-off-by: NTejun Heo <tj@kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      375b611e
    • T
      sysfs: remove sysfs_buffer->needs_read_fill · aea585ef
      Tejun Heo 提交于
      ->needs_read_fill is used to implement the following behaviors.
      
      1. Ensure buffer filling on the first read.
      2. Force buffer filling after a write.
      3. Force buffer filling after a successful poll.
      
      However, #2 and #3 don't really work as sysfs doesn't reset file
      position.  While the read buffer would be refilled, the next read
      would continue from the position after the last read or write,
      requiring an explicit seek to the start for it to be useful, which
      makes ->needs_read_fill superflous as read buffer is always refilled
      if f_pos == 0.
      
      Update sysfs_read_file() to test buffer->page for #1 instead and
      remove ->needs_read_fill.  While this changes behavior in extreme
      corner cases - e.g. re-reading a sysfs file after seeking to non-zero
      position after a write or poll, it's highly unlikely to lead to actual
      breakage.  This change is to prepare for using seq_file in the read
      path.
      
      While at it, reformat a comment in fill_write_buffer().
      Signed-off-by: NTejun Heo <tj@kernel.org>
      Cc: Kay Sievers <kay@vrfy.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      aea585ef
    • T
      sysfs: remove unused sysfs_buffer->pos · 89e51dab
      Tejun Heo 提交于
      Signed-off-by: NTejun Heo <tj@kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      89e51dab
  11. 04 10月, 2013 1 次提交
    • T
      sysfs: remove sysfs_addrm_cxt->parent_sd · d69ac5a0
      Tejun Heo 提交于
      sysfs_addrm_start/finish() enclose sysfs_dirent additions and
      deletions and sysfs_addrm_cxt is used to record information necessary
      to finish the operations.  Currently, sysfs_addrm_start() takes
      @parent_sd, records it in sysfs_addrm_cxt, and assumes that all
      operations in the block are performed under that @parent_sd.
      
      This assumption has been fine until now but we want to make some
      operations behave recursively and, while having @parent_sd recorded in
      sysfs_addrm_cxt doesn't necessarily prevents that, it becomes
      confusing.
      
      This patch removes sysfs_addrm_cxt->parent_sd and makes
      sysfs_add_one() take an explicit @parent_sd parameter.  Note that
      sysfs_remove_one() doesn't need the extra argument as its parent is
      always known from the target @sd.
      
      While at it, add __acquires/releases() notations to
      sysfs_addrm_start/finish() respectively.
      
      This patch doesn't make any functional difference.
      Signed-off-by: NTejun Heo <tj@kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      d69ac5a0
  12. 27 9月, 2013 3 次提交
    • T
      sysfs: @name comes before @ns · cfec0bc8
      Tejun Heo 提交于
      Some internal sysfs functions which take explicit namespace argument
      are weird in that they place the optional @ns in front of @name which
      is contrary to the established convention.  This is confusing and
      error-prone especially as @ns and @name may be interchanged without
      causing compilation warning.
      
      Swap the positions of @name and @ns in the following internal
      functions.
      
       sysfs_find_dirent()
       sysfs_rename()
       sysfs_hash_and_remove()
       sysfs_name_hash()
       sysfs_name_compare()
       create_dir()
      
      This patch doesn't introduce any functional changes.
      Signed-off-by: NTejun Heo <tj@kernel.org>
      Cc: Eric W. Biederman <ebiederm@xmission.com>
      Cc: Kay Sievers <kay@vrfy.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      cfec0bc8
    • T
      sysfs: clean up sysfs_get_dirent() · 388975cc
      Tejun Heo 提交于
      The pre-existing sysfs interfaces which take explicit namespace
      argument are weird in that they place the optional @ns in front of
      @name which is contrary to the established convention.  For example,
      we end up forcing vast majority of sysfs_get_dirent() users to do
      sysfs_get_dirent(parent, NULL, name), which is silly and error-prone
      especially as @ns and @name may be interchanged without causing
      compilation warning.
      
      This renames sysfs_get_dirent() to sysfs_get_dirent_ns() and swap the
      positions of @name and @ns, and sysfs_get_dirent() is now a wrapper
      around sysfs_get_dirent_ns().  This makes confusions a lot less
      likely.
      
      There are other interfaces which take @ns before @name.  They'll be
      updated by following patches.
      
      This patch doesn't introduce any functional changes.
      
      v2: EXPORT_SYMBOL_GPL() wasn't updated leading to undefined symbol
          error on module builds.  Reported by build test robot.  Fixed.
      Signed-off-by: NTejun Heo <tj@kernel.org>
      Cc: Eric W. Biederman <ebiederm@xmission.com>
      Cc: Kay Sievers <kay@vrfy.org>
      Cc: Fengguang Wu <fengguang.wu@intel.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      388975cc
    • T
      sysfs: make attr namespace interface less convoluted · 58292cbe
      Tejun Heo 提交于
      sysfs ns (namespace) implementation became more convoluted than
      necessary while trying to hide ns information from visible interface.
      The relatively recent attr ns support is a good example.
      
      * attr ns tag is determined by sysfs_ops->namespace() callback while
        dir tag is determined by kobj_type->namespace().  The placement is
        arbitrary.
      
      * Instead of performing operations with explicit ns tag, the namespace
        callback is routed through sysfs_attr_ns(), sysfs_ops->namespace(),
        class_attr_namespace(), class_attr->namespace().  It's not simpler
        in any sense.  The only thing this convolution does is traversing
        the whole stack backwards.
      
      The namespace callbacks are unncessary because the operations involved
      are inherently synchronous.  The information can be provided in in
      straight-forward top-down direction and reversing that direction is
      unnecessary and against basic design principles.
      
      This backward interface is unnecessarily convoluted and hinders
      properly separating out sysfs from driver model / kobject for proper
      layering.  This patch updates attr ns support such that
      
      * sysfs_ops->namespace() and class_attr->namespace() are dropped.
      
      * sysfs_{create|remove}_file_ns(), which take explicit @ns param, are
        added and sysfs_{create|remove}_file() are now simple wrappers
        around the ns aware functions.
      
      * ns handling is dropped from sysfs_chmod_file().  Nobody uses it at
        this point.  sysfs_chmod_file_ns() can be added later if necessary.
      
      * Explicit @ns is propagated through class_{create|remove}_file_ns()
        and netdev_class_{create|remove}_file_ns().
      
      * driver/net/bonding which is currently the only user of attr
        namespace is updated to use netdev_class_{create|remove}_file_ns()
        with @bh->net as the ns tag instead of using the namespace callback.
      
      This patch should be an equivalent conversion without any functional
      difference.  It makes the code easier to follow, reduces lines of code
      a bit and helps proper separation and layering.
      Signed-off-by: NTejun Heo <tj@kernel.org>
      Cc: Eric W. Biederman <ebiederm@xmission.com>
      Cc: Kay Sievers <kay@vrfy.org>
      Acked-by: NDavid S. Miller <davem@davemloft.net>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      58292cbe
  13. 22 8月, 2013 3 次提交