platform/kernel/linux-3.10.git
9 years agosysfs: copy bin mmap support from fs/sysfs/bin.c to fs/sysfs/file.c
Tejun Heo [Tue, 1 Oct 2013 21:42:07 +0000 (17:42 -0400)]
sysfs: copy bin mmap support from fs/sysfs/bin.c to fs/sysfs/file.c

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: Tejun Heo <tj@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
9 years agosysfs: add sysfs_bin_read()
Tejun Heo [Tue, 1 Oct 2013 21:42:06 +0000 (17:42 -0400)]
sysfs: add sysfs_bin_read()

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: Tejun Heo <tj@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
9 years agosysfs: prepare path write for unified regular / bin file handling
Tejun Heo [Tue, 1 Oct 2013 21:42:05 +0000 (17:42 -0400)]
sysfs: prepare path write for unified regular / bin file handling

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: Tejun Heo <tj@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
9 years agosysfs: collapse fs/sysfs/bin.c::fill_read() into read()
Tejun Heo [Tue, 1 Oct 2013 21:42:04 +0000 (17:42 -0400)]
sysfs: collapse fs/sysfs/bin.c::fill_read() into read()

read() is simple enough and fill_read() being in a separate function
doesn't add anything.  Let's collapse it into read().  This will make
merging bin file handling with regular file.

Signed-off-by: Tejun Heo <tj@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
9 years agosysfs: skip bin_buffer->buffer while reading
Tejun Heo [Tue, 1 Oct 2013 21:42:03 +0000 (17:42 -0400)]
sysfs: skip bin_buffer->buffer while reading

After b31ca3f5dfc ("sysfs: fix deadlock"), bin read() first writes
data to bb->buffer and bounces it to a transient kernel buffer which
is then copied out to userland.  The double bouncing doesn't add
anything.  Let's just use the transient buffer directly.

While at it, rename @temp to @buf for clarity.

Signed-off-by: Tejun Heo <tj@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
9 years agosysfs: use seq_file when reading regular files
Tejun Heo [Tue, 1 Oct 2013 21:42:02 +0000 (17:42 -0400)]
sysfs: use seq_file when reading regular files

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: Tejun Heo <tj@kernel.org>
Cc: Kay Sievers <kay@vrfy.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
9 years agosysfs: use transient write buffer
Tejun Heo [Tue, 1 Oct 2013 21:42:01 +0000 (17:42 -0400)]
sysfs: use transient write buffer

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: Tejun Heo <tj@kernel.org>
Cc: kbuild test robot <fengguang.wu@intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
9 years agosysfs: add sysfs_open_file->sd and ->file
Tejun Heo [Tue, 1 Oct 2013 21:42:00 +0000 (17:42 -0400)]
sysfs: add sysfs_open_file->sd and ->file

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: Tejun Heo <tj@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
9 years agosysfs: rename sysfs_buffer to sysfs_open_file
Tejun Heo [Tue, 1 Oct 2013 21:41:59 +0000 (17:41 -0400)]
sysfs: rename sysfs_buffer to sysfs_open_file

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: Tejun Heo <tj@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
9 years agosysfs: add sysfs_open_file_mutex
Tejun Heo [Tue, 1 Oct 2013 21:41:58 +0000 (17:41 -0400)]
sysfs: add sysfs_open_file_mutex

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: Tejun Heo <tj@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
9 years agosysfs: remove sysfs_buffer->ops
Tejun Heo [Tue, 1 Oct 2013 21:41:57 +0000 (17:41 -0400)]
sysfs: remove sysfs_buffer->ops

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: Tejun Heo <tj@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
9 years agosysfs: remove sysfs_buffer->needs_read_fill
Tejun Heo [Tue, 1 Oct 2013 21:41:56 +0000 (17:41 -0400)]
sysfs: remove sysfs_buffer->needs_read_fill

->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: Tejun Heo <tj@kernel.org>
Cc: Kay Sievers <kay@vrfy.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
9 years agosysfs: remove unused sysfs_buffer->pos
Tejun Heo [Tue, 1 Oct 2013 21:41:55 +0000 (17:41 -0400)]
sysfs: remove unused sysfs_buffer->pos

Signed-off-by: Tejun Heo <tj@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
9 years agosysfs: introduce [__]sysfs_remove()
Tejun Heo [Wed, 18 Sep 2013 21:15:38 +0000 (17:15 -0400)]
sysfs: introduce [__]sysfs_remove()

Given a sysfs_dirent, there is no reason to have multiple versions of
removal functions.  A function which removes the specified
sysfs_dirent and its descendants is enough.

This patch intorduces [__}sysfs_remove() which replaces all internal
variations of removal functions.  This will be the only removal
function in the planned new sysfs_dirent based interface.

Signed-off-by: Tejun Heo <tj@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
9 years agosysfs: make __sysfs_remove_dir() recursive
Tejun Heo [Wed, 18 Sep 2013 21:15:37 +0000 (17:15 -0400)]
sysfs: make __sysfs_remove_dir() recursive

Currently, sysfs directory removal is inconsistent in that it would
remove any files directly under it but wouldn't recurse into
directories.  Thanks to group subdirectories, this doesn't even match
with kobject boundaries.  sysfs is in the process of being separated
out so that it can be used by multiple subsystems and we want to have
a consistent behavior - either removal of a sysfs_dirent should remove
every descendant entries or none instead of something inbetween.

This patch implements proper recursive removal in
__sysfs_remove_dir().  The function now walks its subtree in a
post-order walk to remove all descendants.

This is a behavior change but kobject / driver layer, which currently
is the only consumer, has already been updated to handle duplicate
removal attempts, so nothing should be broken after this change.

Signed-off-by: Tejun Heo <tj@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
9 years agokobject: grab an extra reference on kobject->sd to allow duplicate deletes
Tejun Heo [Wed, 18 Sep 2013 21:15:36 +0000 (17:15 -0400)]
kobject: grab an extra reference on kobject->sd to allow duplicate deletes

sysfs currently has a rather weird behavior regarding removals.  A
directory removal would delete all files directly under it but
wouldn't recurse into subdirectories, which, while a bit inconsistent,
seems to make sense at the first glance as each directory is
supposedly associated with a kobject and each kobject can take care of
the directory deletion; however, this doesn't really hold as we have
groups which can be directories without a kobject associated with it
and require explicit deletions.

We're in the process of separating out sysfs from kboject / driver
core and want a consistent behavior.  A removal should delete either
only the specified node or everything under it.  I think it is helpful
to support recursive atomic removal and later patches will implement
it.

Such change means that a sysfs_dirent associated with kobject may be
deleted before the kobject itself is removed if one of its ancestor
gets removed before it.  As sysfs_remove_dir() puts the base ref, we
may end up with dangling pointer on descendants.  This can be solved
by holding an extra reference on the sd from kobject.

Acquire an extra reference on the associated sysfs_dirent on directory
creation and put it after removal.

Signed-off-by: Tejun Heo <tj@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
9 years agosysfs: remove sysfs_addrm_cxt->parent_sd
Tejun Heo [Wed, 18 Sep 2013 21:15:35 +0000 (17:15 -0400)]
sysfs: remove sysfs_addrm_cxt->parent_sd

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: Tejun Heo <tj@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
9 years agoconstify ->actor
Al Viro [Thu, 23 May 2013 02:22:04 +0000 (22:22 -0400)]
constify ->actor

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
9 years ago->readdir() is gone
Al Viro [Thu, 23 May 2013 01:44:23 +0000 (21:44 -0400)]
->readdir() is gone

everything's converted to ->iterate()

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
9 years agoconvert ecryptfs
Al Viro [Thu, 23 May 2013 01:23:40 +0000 (21:23 -0400)]
convert ecryptfs

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
9 years agoconvert coda
Al Viro [Thu, 23 May 2013 01:15:30 +0000 (21:15 -0400)]
convert coda

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
9 years agoconvert ocfs2
Al Viro [Thu, 23 May 2013 01:06:00 +0000 (21:06 -0400)]
convert ocfs2

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
9 years agoconvert fatfs
Al Viro [Wed, 22 May 2013 22:37:16 +0000 (18:37 -0400)]
convert fatfs

... pox upon the idiotic ioctls; life would be much easier without
those.

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
9 years agoconvert xfs
Al Viro [Wed, 22 May 2013 21:07:56 +0000 (17:07 -0400)]
convert xfs

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
9 years agoconvert btrfs
Al Viro [Wed, 22 May 2013 20:48:09 +0000 (16:48 -0400)]
convert btrfs

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
9 years agoconvert hostfs
Al Viro [Wed, 22 May 2013 20:34:19 +0000 (16:34 -0400)]
convert hostfs

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
9 years agoconvert afs
Al Viro [Wed, 22 May 2013 20:31:14 +0000 (16:31 -0400)]
convert afs

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
9 years agoconvert ncpfs
Al Viro [Wed, 22 May 2013 19:11:27 +0000 (15:11 -0400)]
convert ncpfs

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
9 years agoconvert hfsplus
Al Viro [Wed, 22 May 2013 18:59:39 +0000 (14:59 -0400)]
convert hfsplus

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
9 years agoconvert hfs
Al Viro [Wed, 22 May 2013 18:29:35 +0000 (14:29 -0400)]
convert hfs

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
9 years agoconvert befs
Al Viro [Wed, 22 May 2013 17:44:05 +0000 (13:44 -0400)]
convert befs

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
9 years agoconvert cifs
Al Viro [Wed, 22 May 2013 20:17:25 +0000 (16:17 -0400)]
convert cifs

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
9 years agoconvert freevxfs
Al Viro [Sat, 18 May 2013 07:15:00 +0000 (03:15 -0400)]
convert freevxfs

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
9 years agoconvert fuse
Al Viro [Sat, 18 May 2013 07:03:58 +0000 (03:03 -0400)]
convert fuse

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
9 years agoconvert hpfs
Al Viro [Sat, 18 May 2013 06:58:57 +0000 (02:58 -0400)]
convert hpfs

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
9 years agoreiserfs: switch reiserfs_readdir_dentry to inode
Al Viro [Sat, 18 May 2013 02:58:58 +0000 (22:58 -0400)]
reiserfs: switch reiserfs_readdir_dentry to inode

... and clean the callers up a bit

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
9 years agoreiserfs: is_privroot_deh() needs only directory inode, actually
Al Viro [Sat, 18 May 2013 02:45:29 +0000 (22:45 -0400)]
reiserfs: is_privroot_deh() needs only directory inode, actually

... and that - only to get the superblock.  Privroot is a directory
and we don't allow hardlinks to those...

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
9 years agoconvert reiserfs
Al Viro [Sat, 18 May 2013 02:42:17 +0000 (22:42 -0400)]
convert reiserfs

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
9 years agoconvert ntfs
Al Viro [Sat, 18 May 2013 01:22:31 +0000 (21:22 -0400)]
convert ntfs

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
9 years agoconvert isofs
Al Viro [Sat, 18 May 2013 01:11:59 +0000 (21:11 -0400)]
convert isofs

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
9 years agoconvert jffs2
Al Viro [Fri, 17 May 2013 22:08:49 +0000 (18:08 -0400)]
convert jffs2

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
9 years agoconvert f2fs
Al Viro [Fri, 17 May 2013 22:02:17 +0000 (18:02 -0400)]
convert f2fs

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
9 years agoconvert 9p
Al Viro [Fri, 17 May 2013 21:51:41 +0000 (17:51 -0400)]
convert 9p

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
9 years agoconvert affs
Al Viro [Fri, 17 May 2013 21:44:42 +0000 (17:44 -0400)]
convert affs

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
9 years agoconvert adfs
Al Viro [Fri, 17 May 2013 21:30:10 +0000 (17:30 -0400)]
convert adfs

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
9 years agoconvert logfs
Al Viro [Fri, 17 May 2013 21:06:34 +0000 (17:06 -0400)]
convert logfs

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
9 years agoconvert jfs
Al Viro [Fri, 17 May 2013 21:00:34 +0000 (17:00 -0400)]
convert jfs

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
9 years agoconvert ceph
Al Viro [Fri, 17 May 2013 20:52:26 +0000 (16:52 -0400)]
convert ceph

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
9 years agoconvert nfs
Al Viro [Fri, 17 May 2013 20:34:50 +0000 (16:34 -0400)]
convert nfs

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
9 years agoconvert ext4
Al Viro [Fri, 17 May 2013 20:08:53 +0000 (16:08 -0400)]
convert ext4

and trim the living hell out bogosities in inline dir case

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
9 years agoconvert qnx6
Al Viro [Fri, 17 May 2013 19:32:10 +0000 (15:32 -0400)]
convert qnx6

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
9 years agoconvert qnx4
Al Viro [Fri, 17 May 2013 19:17:59 +0000 (15:17 -0400)]
convert qnx4

... and use strnlen() instead of strlen() - it's done on untrusted data,
after all.

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
9 years agoconvert omfs
Al Viro [Fri, 17 May 2013 19:05:25 +0000 (15:05 -0400)]
convert omfs

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
9 years agoconvert nilfs2
Al Viro [Thu, 16 May 2013 18:36:14 +0000 (14:36 -0400)]
convert nilfs2

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
9 years agoconvert sysfs
Al Viro [Thu, 16 May 2013 18:31:02 +0000 (14:31 -0400)]
convert sysfs

get rid of the kludges in sysfs_readdir()

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
9 years agoconvert gfs2
Al Viro [Thu, 16 May 2013 18:14:48 +0000 (14:14 -0400)]
convert gfs2

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
9 years agoconvert exofs
Al Viro [Thu, 16 May 2013 17:48:17 +0000 (13:48 -0400)]
convert exofs

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
9 years agoconvert bfs
Al Viro [Thu, 16 May 2013 17:41:48 +0000 (13:41 -0400)]
convert bfs

... and get rid of that ridiculous mutex in bfs_readdir()

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
9 years agoconvert procfs
Al Viro [Thu, 16 May 2013 16:07:31 +0000 (12:07 -0400)]
convert procfs

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
9 years agoconvert openpromfs
Al Viro [Thu, 16 May 2013 05:52:12 +0000 (01:52 -0400)]
convert openpromfs

what the hell is op_mutex for, BTW?

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
9 years agoconvert efs
Al Viro [Thu, 16 May 2013 05:41:10 +0000 (01:41 -0400)]
convert efs

* sanity checks belong before risky operation, not after it
* don't quit as soon as we'd found an entry

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
9 years agoconvert configfs
Al Viro [Thu, 16 May 2013 05:28:34 +0000 (01:28 -0400)]
convert configfs

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
9 years agoconvert romfs
Al Viro [Thu, 16 May 2013 05:22:00 +0000 (01:22 -0400)]
convert romfs

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
9 years agoconvert squashfs
Al Viro [Thu, 16 May 2013 05:17:58 +0000 (01:17 -0400)]
convert squashfs

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
9 years agoconvert ubifs
Al Viro [Thu, 16 May 2013 05:14:46 +0000 (01:14 -0400)]
convert ubifs

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
9 years agoconvert udf
Al Viro [Thu, 16 May 2013 05:09:37 +0000 (01:09 -0400)]
convert udf

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
9 years agoconvert ext3
Al Viro [Thu, 16 May 2013 01:02:48 +0000 (21:02 -0400)]
convert ext3

new helper: dir_relax(inode).  Call when you are in location that will
_not_ be invalidated by directory modifications (block boundary, in case
of ext*).  Returns whether the directory has survived (dropping i_mutex
allows rmdir to kill the sucker; if it returns false to us, ->iterate()
is obviously done)

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
9 years agoswitch dcache_readdir() users to ->iterate()
Al Viro [Thu, 16 May 2013 00:23:06 +0000 (20:23 -0400)]
switch dcache_readdir() users to ->iterate()

new helpers - dir_emit_dot(file, ctx, dentry), dir_emit_dotdot(file, ctx),
dir_emit_dots(file, ctx).

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
9 years agosimple local unixlike: switch to ->iterate()
Al Viro [Wed, 15 May 2013 22:51:49 +0000 (18:51 -0400)]
simple local unixlike: switch to ->iterate()

ext2, ufs, minix, sysv

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
9 years agointroduce ->iterate(), ctx->pos, dir_emit()
Al Viro [Wed, 15 May 2013 22:49:12 +0000 (18:49 -0400)]
introduce ->iterate(), ctx->pos, dir_emit()

New method - ->iterate(file, ctx).  That's the replacement for ->readdir();
it takes callback from ctx->actor, uses ctx->pos instead of file->f_pos and
calls dir_emit(ctx, ...) instead of filldir(data, ...).  It does *not*
update file->f_pos (or look at it, for that matter); iterate_dir() does the
update.

Note that dir_emit() takes the offset from ctx->pos (and eventually
filldir_t will lose that argument).

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
9 years agointroduce iterate_dir() and dir_context
Al Viro [Wed, 15 May 2013 17:52:59 +0000 (13:52 -0400)]
introduce iterate_dir() and dir_context

iterate_dir(): new helper, replacing vfs_readdir().

struct dir_context: contains the readdir callback (and will get more stuff
in it), embedded into whatever data that callback wants to deal with;
eventually, we'll be passing it to ->readdir() replacement instead of
(data,filldir) pair.

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
9 years agosysfs: clean up sysfs_get_dirent()
Tejun Heo [Thu, 12 Sep 2013 03:19:13 +0000 (23:19 -0400)]
sysfs: clean up sysfs_get_dirent()

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: Tejun 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: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
9 years agosysfs: @name comes before @ns
Tejun Heo [Thu, 12 Sep 2013 02:29:09 +0000 (22:29 -0400)]
sysfs: @name comes before @ns

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: Tejun Heo <tj@kernel.org>
Cc: Eric W. Biederman <ebiederm@xmission.com>
Cc: Kay Sievers <kay@vrfy.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
9 years agosysfs: remove ktype->namespace() invocations in symlink code
Tejun Heo [Thu, 12 Sep 2013 02:29:06 +0000 (22:29 -0400)]
sysfs: remove ktype->namespace() invocations in symlink code

There's no reason for sysfs to be calling ktype->namespace().  It is
backwards, obfuscates what's going on and unnecessarily tangles two
separate layers.

There are two places where symlink code calls ktype->namespace().

* sysfs_do_create_link_sd() calls it to find out the namespace tag of
  the target directory.  Unless symlinking races with cross-namespace
  renaming, this equals @target_sd->s_ns.

* sysfs_rename_link() uses it to find out the new namespace to rename
  to and the new namespace can be different from the existing one.
  The function is renamed to sysfs_rename_link_ns() with an explicit
  @ns argument and the ktype->namespace() invocation is shifted to the
  device layer.

While this patch replaces ktype->namespace() invocation with the
recorded result in @target_sd, this shouldn't result in any behvior
difference.

Signed-off-by: Tejun Heo <tj@kernel.org>
Cc: Eric W. Biederman <ebiederm@xmission.com>
Cc: Kay Sievers <kay@vrfy.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
9 years agosysfs: remove ktype->namespace() invocations in directory code
Tejun Heo [Thu, 12 Sep 2013 02:29:05 +0000 (22:29 -0400)]
sysfs: remove ktype->namespace() invocations in directory code

For some unrecognizable reason, namespace information is communicated
to sysfs through ktype->namespace() callback when there's *nothing*
which needs the use of a callback.  The whole sequence of operations
is completely synchronous and sysfs operations simply end up calling
back into the layer which just invoked it in order to find out the
namespace information, which is completely backwards, obfuscates
what's going on and unnecessarily tangles two separate layers.

This patch doesn't remove ktype->namespace() but shifts its handling
to kobject layer.  We probably want to get rid of the callback in the
long term.

This patch adds an explicit param to sysfs_{create|rename|move}_dir()
and renames them to sysfs_{create|rename|move}_dir_ns(), respectively.
ktype->namespace() invocations are moved to the calling sites of the
above functions.  A new helper kboject_namespace() is introduced which
directly tests kobj_ns_type_operations->type which should give the
same result as testing sysfs_fs_type(parent_sd) and returns @kobj's
namespace tag as necessary.  kobject_namespace() is extern as it will
be used from another file in the following patches.

This patch should be an equivalent conversion without any functional
difference.

Signed-off-by: Tejun Heo <tj@kernel.org>
Cc: Eric W. Biederman <ebiederm@xmission.com>
Cc: Kay Sievers <kay@vrfy.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
9 years agosysfs: make attr namespace interface less convoluted
Tejun Heo [Thu, 12 Sep 2013 02:29:04 +0000 (22:29 -0400)]
sysfs: make attr namespace interface less convoluted

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: Tejun Heo <tj@kernel.org>
Cc: Eric W. Biederman <ebiederm@xmission.com>
Cc: Kay Sievers <kay@vrfy.org>
Acked-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
9 years agosysfs: drop semicolon from to_sysfs_dirent() definition
Tejun Heo [Thu, 12 Sep 2013 02:29:03 +0000 (22:29 -0400)]
sysfs: drop semicolon from to_sysfs_dirent() definition

The expansion of to_sysfs_dirent() contains an unncessary trailing
semicolon making it impossible to use in the middle of statements.
Drop it.

Signed-off-by: Tejun Heo <tj@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
9 years agosysfs: Restrict mounting sysfs
Eric W. Biederman [Tue, 26 Mar 2013 03:07:01 +0000 (20:07 -0700)]
sysfs: Restrict mounting sysfs

Don't allow mounting sysfs unless the caller has CAP_SYS_ADMIN rights
over the net namespace.  The principle here is if you create or have
capabilities over it you can mount it, otherwise you get to live with
what other people have mounted.

Instead of testing this with a straight forward ns_capable call,
perform this check the long and torturous way with kobject helpers,
this keeps direct knowledge of namespaces out of sysfs, and preserves
the existing sysfs abstractions.

Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
9 years agouserns: Better restrictions on when proc and sysfs can be mounted
Eric W. Biederman [Sun, 31 Mar 2013 02:57:41 +0000 (19:57 -0700)]
userns: Better restrictions on when proc and sysfs can be mounted

Rely on the fact that another flavor of the filesystem is already
mounted and do not rely on state in the user namespace.

Verify that the mounted filesystem is not covered in any significant
way.  I would love to verify that the previously mounted filesystem
has no mounts on top but there are at least the directories
/proc/sys/fs/binfmt_misc and /sys/fs/cgroup/ that exist explicitly
for other filesystems to mount on top of.

Refactor the test into a function named fs_fully_visible and call that
function from the mount routines of proc and sysfs.  This makes this
test local to the filesystems involved and the results current of when
the mounts take place, removing a weird threading of the user
namespace, the mount namespace and the filesystems themselves.

Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
9 years agosysfs: file.c: fix up broken string warnings
Greg Kroah-Hartman [Wed, 21 Aug 2013 23:37:42 +0000 (16:37 -0700)]
sysfs: file.c: fix up broken string warnings

This fixes the coding style warnings in fs/sysfs/file.c for broken
strings across lines.

Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
9 years agosysfs: fix up uaccess.h coding style warnings
Greg Kroah-Hartman [Wed, 21 Aug 2013 23:34:59 +0000 (16:34 -0700)]
sysfs: fix up uaccess.h coding style warnings

This fixes the uaccess.h warnings in the sysfs.c files.

Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
9 years agosysfs: fix up 80 column coding style issues
Greg Kroah-Hartman [Wed, 21 Aug 2013 23:33:34 +0000 (16:33 -0700)]
sysfs: fix up 80 column coding style issues

This fixes up the 80 column coding style issues in the sysfs .c files.

Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
9 years agosysfs: fix up space coding style issues
Greg Kroah-Hartman [Wed, 21 Aug 2013 23:28:26 +0000 (16:28 -0700)]
sysfs: fix up space coding style issues

This fixes up all of the space-related coding style issues for the sysfs
code.

Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
9 years agosysfs: remove trailing whitespace
Greg Kroah-Hartman [Wed, 21 Aug 2013 23:21:17 +0000 (16:21 -0700)]
sysfs: remove trailing whitespace

This removes all trailing whitespace errors in the sysfs code.

Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
9 years agosysfs: fix placement of EXPORT_SYMBOL()
Greg Kroah-Hartman [Wed, 21 Aug 2013 23:17:47 +0000 (16:17 -0700)]
sysfs: fix placement of EXPORT_SYMBOL()

The export should happen after the function, not at the bottom of the
file, so fix that up.

Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
9 years agosysfs: group: update copyright to add myself and the LF
Greg Kroah-Hartman [Wed, 21 Aug 2013 23:14:11 +0000 (16:14 -0700)]
sysfs: group: update copyright to add myself and the LF

Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
9 years agosysfs: group.c: add kerneldoc for sysfs_remove_group
Greg Kroah-Hartman [Wed, 21 Aug 2013 23:12:34 +0000 (16:12 -0700)]
sysfs: group.c: add kerneldoc for sysfs_remove_group

sysfs_remove_group() never had kerneldoc, so add it, and fix up the
kerneldoc for sysfs_remove_groups() which didn't specify the parameters
properly.

Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
9 years agosysfs: group.c: fix up broken string coding style
Greg Kroah-Hartman [Wed, 21 Aug 2013 23:10:02 +0000 (16:10 -0700)]
sysfs: group.c: fix up broken string coding style

checkpatch complains about the broken string in the file, and it's
correct, so fix it up.

Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
9 years agosysfs: group.c: fix up some * coding style issues
Greg Kroah-Hartman [Wed, 21 Aug 2013 23:07:29 +0000 (16:07 -0700)]
sysfs: group.c: fix up some * coding style issues

This fixes up the * coding style warnings for the group.c sysfs file.

Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
9 years agosysfs: group.c: fix trailing whitespace
Greg Kroah-Hartman [Wed, 21 Aug 2013 23:06:14 +0000 (16:06 -0700)]
sysfs: group.c: fix trailing whitespace

There was some trailing spaces in the file, fix that up.

Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
9 years agosysfs: group.c: move EXPORT_SYMBOL_GPL() to the proper location
Greg Kroah-Hartman [Wed, 21 Aug 2013 23:04:12 +0000 (16:04 -0700)]
sysfs: group.c: move EXPORT_SYMBOL_GPL() to the proper location

This fixes up the coding style issue of incorrectly placing the
EXPORT_SYMBOL_GPL() macro, it should be right after the function itself,
not at the end of the file.

Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
9 years agosysfs: add sysfs_create/remove_groups()
Greg Kroah-Hartman [Wed, 21 Aug 2013 20:47:50 +0000 (13:47 -0700)]
sysfs: add sysfs_create/remove_groups()

These functions are being open-coded in 3 different places in the driver
core, and other driver subsystems will want to start doing this as well,
so move it to the sysfs core to keep it all in one place, where we know
it is written properly.

Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
9 years agosysfs: prevent warning when only using binary attributes
Oliver Schinagl [Sun, 14 Jul 2013 23:05:56 +0000 (16:05 -0700)]
sysfs: prevent warning when only using binary attributes

When only using bin_attrs instead of attrs the kernel prints a warning
and refuses to create the sysfs entry. This fixes that.

Signed-off-by: Oliver Schinagl <oliver@schinagl.nl>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
9 years agosysfs: add support for binary attributes in groups
Greg Kroah-Hartman [Sun, 14 Jul 2013 23:05:55 +0000 (16:05 -0700)]
sysfs: add support for binary attributes in groups

groups should be able to support binary attributes, just like it
supports "normal" attributes.  This lets us only handle one type of
structure, groups, throughout the driver core and subsystems, making
binary attributes a "full fledged" part of the driver model, and not
something just "tacked on".

Reported-by: Oliver Schinagl <oliver@schinagl.nl>
Reviewed-by: Guenter Roeck <linux@roeck-us.net>
Tested-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
9 years agosysfs_notify is only possible on file attributes
Nick Dyer [Fri, 7 Jun 2013 14:45:13 +0000 (15:45 +0100)]
sysfs_notify is only possible on file attributes

If sysfs_notify is called on a binary attribute, bad things can
happen, so prevent it.

Note, no in-kernel usage of this is currently present, but in the
future, it's good to be safe.

Changes in V2:
- Also ignore sysfs_notify on dirs, links
- Use WARN_ON rather than silently failing
- Compiled and tested (huge apologies about first submission)

Signed-off-by: Nick Dyer <nick.dyer@itdev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
9 years agosysfs: kill sysfs_sb declaration in fs/sysfs/inode.c.
Rami Rosen [Mon, 29 Apr 2013 13:05:32 +0000 (16:05 +0300)]
sysfs: kill sysfs_sb declaration in fs/sysfs/inode.c.

This patch removes sysfs_sb declaration from fs/sysfs/inode.c
(due to 0f4288ec6fcc1a47d1fa0241ec1c6dacd5a09e96,
 "Kill unused sysfs_sb variable").

Signed-off-by: Rami Rosen <ramirose@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
9 years agosysfs: sysfs_link_sibling(): fix typo in comment
Warner Wang [Mon, 13 May 2013 03:11:05 +0000 (11:11 +0800)]
sysfs: sysfs_link_sibling(): fix typo in comment

Fix a typo subling->sibling in the comment of sysfs_link_sibling().

Signed-off-by: Warner Wang <warner.wang@hp.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
9 years agofuse: drop dentry on failed revalidate
Anand Avati [Thu, 5 Sep 2013 09:44:44 +0000 (11:44 +0200)]
fuse: drop dentry on failed revalidate

Drop a subtree when we find that it has moved or been delated.  This can be
done as long as there are no submounts under this location.

If the directory was moved and we come across the same directory in a
future lookup it will be reconnected by d_materialise_unique().

Signed-off-by: Anand Avati <avati@redhat.com>
Signed-off-by: Miklos Szeredi <mszeredi@suse.cz>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
9 years agofuse: clean up return in fuse_dentry_revalidate()
Miklos Szeredi [Thu, 5 Sep 2013 09:44:43 +0000 (11:44 +0200)]
fuse: clean up return in fuse_dentry_revalidate()

On errors unrelated to the filesystem's state (ENOMEM, ENOTCONN) return the
error itself from ->d_revalidate() insted of returning zero (invalid).

Also make a common label for invalidating the dentry.  This will be used by
the next patch.

Signed-off-by: Miklos Szeredi <mszeredi@suse.cz>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
9 years agofuse: use d_materialise_unique()
Miklos Szeredi [Thu, 5 Sep 2013 09:44:42 +0000 (11:44 +0200)]
fuse: use d_materialise_unique()

Use d_materialise_unique() instead of d_splice_alias().  This allows dentry
subtrees to be moved to a new place if there moved, even if something is
referencing a dentry in the subtree (open fd, cwd, etc..).

This will also allow us to drop a subtree if it is found to be replaced by
something else.  In this case the disconnected subtree can later be
reconnected to its new location.

d_materialise_unique() ensures that a directory entry only ever has one
alias.  We keep fc->inst_mutex around the calls for d_materialise_unique()
on directories to prevent a race with mkdir "stealing" the inode.

Signed-off-by: Miklos Szeredi <mszeredi@suse.cz>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>