sysfs, kernfs: introduce kernfs_ops
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: Tejun Heo <tj@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:

committed by
Greg Kroah-Hartman

parent
dd8a5b036b
commit
f6acf8bb6a
@@ -33,6 +33,32 @@ struct sysfs_open_file {
|
||||
const struct vm_operations_struct *vm_ops;
|
||||
};
|
||||
|
||||
struct kernfs_ops {
|
||||
/*
|
||||
* Read is handled by either seq_file or raw_read().
|
||||
*
|
||||
* If seq_show() is present, seq_file path is active. The behavior
|
||||
* is equivalent to single_open(). @sf->private points to the
|
||||
* associated sysfs_open_file.
|
||||
*
|
||||
* read() is bounced through kernel buffer and a read larger than
|
||||
* PAGE_SIZE results in partial operation of PAGE_SIZE.
|
||||
*/
|
||||
int (*seq_show)(struct seq_file *sf, void *v);
|
||||
|
||||
ssize_t (*read)(struct sysfs_open_file *of, char *buf, size_t bytes,
|
||||
loff_t off);
|
||||
|
||||
/*
|
||||
* write() is bounced through kernel buffer and a write larger than
|
||||
* PAGE_SIZE results in partial operation of PAGE_SIZE.
|
||||
*/
|
||||
ssize_t (*write)(struct sysfs_open_file *of, char *buf, size_t bytes,
|
||||
loff_t off);
|
||||
|
||||
int (*mmap)(struct sysfs_open_file *of, struct vm_area_struct *vma);
|
||||
};
|
||||
|
||||
#ifdef CONFIG_SYSFS
|
||||
|
||||
struct sysfs_dirent *kernfs_create_dir_ns(struct sysfs_dirent *parent,
|
||||
|
Reference in New Issue
Block a user