summaryrefslogtreecommitdiff
path: root/fs
diff options
context:
space:
mode:
authorTejun Heo <tj@kernel.org>2013-11-28 14:54:26 -0500
committerPawel Osmialowski <p.osmialowsk@mcdsrvbld02.digital.local>2015-03-27 14:37:30 +0100
commitea72c71344e75459493113b7d264f5973ebdcfb8 (patch)
treece2d5c2029d602dc913563b55b98d5d35f91277b /fs
parenta09bb738478e1360b12f310c6b1af92cc51c5158 (diff)
downloadlinux-3.10-ea72c71344e75459493113b7d264f5973ebdcfb8.tar.gz
linux-3.10-ea72c71344e75459493113b7d264f5973ebdcfb8.tar.bz2
linux-3.10-ea72c71344e75459493113b7d264f5973ebdcfb8.zip
sysfs, kernfs: add kernfs_ops->seq_{start|next|stop}()
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: Tejun Heo <tj@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'fs')
-rw-r--r--fs/sysfs/file.c39
1 files changed, 28 insertions, 11 deletions
diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
index 41a1e0accc0..ef89b3cfc41 100644
--- a/fs/sysfs/file.c
+++ b/fs/sysfs/file.c
@@ -147,6 +147,7 @@ static ssize_t sysfs_kf_bin_read(struct sysfs_open_file *of, char *buf,
static void *kernfs_seq_start(struct seq_file *sf, loff_t *ppos)
{
struct sysfs_open_file *of = sf->private;
+ const struct kernfs_ops *ops;
/*
* @of->mutex nests outside active ref and is just to ensure that
@@ -156,26 +157,42 @@ static void *kernfs_seq_start(struct seq_file *sf, loff_t *ppos)
if (!sysfs_get_active(of->sd))
return ERR_PTR(-ENODEV);
- /*
- * The same behavior and code as single_open(). Returns !NULL if
- * pos is at the beginning; otherwise, NULL.
- */
- return NULL + !*ppos;
+ ops = kernfs_ops(of->sd);
+ if (ops->seq_start) {
+ return ops->seq_start(sf, ppos);
+ } else {
+ /*
+ * The same behavior and code as single_open(). Returns
+ * !NULL if pos is at the beginning; otherwise, NULL.
+ */
+ return NULL + !*ppos;
+ }
}
static void *kernfs_seq_next(struct seq_file *sf, void *v, loff_t *ppos)
{
- /*
- * The same behavior and code as single_open(), always terminate
- * after the initial read.
- */
- ++*ppos;
- return NULL;
+ struct sysfs_open_file *of = sf->private;
+ const struct kernfs_ops *ops = kernfs_ops(of->sd);
+
+ if (ops->seq_next) {
+ return ops->seq_next(sf, v, ppos);
+ } else {
+ /*
+ * The same behavior and code as single_open(), always
+ * terminate after the initial read.
+ */
+ ++*ppos;
+ return NULL;
+ }
}
static void kernfs_seq_stop(struct seq_file *sf, void *v)
{
struct sysfs_open_file *of = sf->private;
+ const struct kernfs_ops *ops = kernfs_ops(of->sd);
+
+ if (ops->seq_stop)
+ ops->seq_stop(sf, v);
sysfs_put_active(of->sd);
mutex_unlock(&of->mutex);