Commit 375b611e authored by Tejun Heo's avatar Tejun Heo Committed by Greg Kroah-Hartman

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: default avatarTejun Heo <tj@kernel.org>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent aea585ef
...@@ -45,12 +45,23 @@ struct sysfs_open_dirent { ...@@ -45,12 +45,23 @@ struct sysfs_open_dirent {
struct sysfs_buffer { struct sysfs_buffer {
size_t count; size_t count;
char *page; char *page;
const struct sysfs_ops *ops;
struct mutex mutex; struct mutex mutex;
int event; int event;
struct list_head list; struct list_head list;
}; };
/*
* Determine ktype->sysfs_ops for the given sysfs_dirent. This function
* must be called while holding an active reference.
*/
static const struct sysfs_ops *sysfs_file_ops(struct sysfs_dirent *sd)
{
struct kobject *kobj = sd->s_parent->s_dir.kobj;
lockdep_assert_held(sd);
return kobj->ktype ? kobj->ktype->sysfs_ops : NULL;
}
/** /**
* fill_read_buffer - allocate and fill buffer from object. * fill_read_buffer - allocate and fill buffer from object.
* @dentry: dentry pointer. * @dentry: dentry pointer.
...@@ -66,7 +77,7 @@ static int fill_read_buffer(struct dentry *dentry, struct sysfs_buffer *buffer) ...@@ -66,7 +77,7 @@ static int fill_read_buffer(struct dentry *dentry, struct sysfs_buffer *buffer)
{ {
struct sysfs_dirent *attr_sd = dentry->d_fsdata; struct sysfs_dirent *attr_sd = dentry->d_fsdata;
struct kobject *kobj = attr_sd->s_parent->s_dir.kobj; struct kobject *kobj = attr_sd->s_parent->s_dir.kobj;
const struct sysfs_ops *ops = buffer->ops; const struct sysfs_ops *ops;
int ret = 0; int ret = 0;
ssize_t count; ssize_t count;
...@@ -80,6 +91,8 @@ static int fill_read_buffer(struct dentry *dentry, struct sysfs_buffer *buffer) ...@@ -80,6 +91,8 @@ static int fill_read_buffer(struct dentry *dentry, struct sysfs_buffer *buffer)
return -ENODEV; return -ENODEV;
buffer->event = atomic_read(&attr_sd->s_attr.open->event); buffer->event = atomic_read(&attr_sd->s_attr.open->event);
ops = sysfs_file_ops(attr_sd);
count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page); count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
sysfs_put_active(attr_sd); sysfs_put_active(attr_sd);
...@@ -191,13 +204,14 @@ static int flush_write_buffer(struct dentry *dentry, ...@@ -191,13 +204,14 @@ static int flush_write_buffer(struct dentry *dentry,
{ {
struct sysfs_dirent *attr_sd = dentry->d_fsdata; struct sysfs_dirent *attr_sd = dentry->d_fsdata;
struct kobject *kobj = attr_sd->s_parent->s_dir.kobj; struct kobject *kobj = attr_sd->s_parent->s_dir.kobj;
const struct sysfs_ops *ops = buffer->ops; const struct sysfs_ops *ops;
int rc; int rc;
/* need attr_sd for attr and ops, its parent for kobj */ /* need attr_sd for attr and ops, its parent for kobj */
if (!sysfs_get_active(attr_sd)) if (!sysfs_get_active(attr_sd))
return -ENODEV; return -ENODEV;
ops = sysfs_file_ops(attr_sd);
rc = ops->store(kobj, attr_sd->s_attr.attr, buffer->page, count); rc = ops->store(kobj, attr_sd->s_attr.attr, buffer->page, count);
sysfs_put_active(attr_sd); sysfs_put_active(attr_sd);
...@@ -205,7 +219,6 @@ static int flush_write_buffer(struct dentry *dentry, ...@@ -205,7 +219,6 @@ static int flush_write_buffer(struct dentry *dentry,
return rc; return rc;
} }
/** /**
* sysfs_write_file - write an attribute. * sysfs_write_file - write an attribute.
* @file: file pointer * @file: file pointer
...@@ -334,14 +347,11 @@ static int sysfs_open_file(struct inode *inode, struct file *file) ...@@ -334,14 +347,11 @@ static int sysfs_open_file(struct inode *inode, struct file *file)
return -ENODEV; return -ENODEV;
/* every kobject with an attribute needs a ktype assigned */ /* every kobject with an attribute needs a ktype assigned */
if (kobj->ktype && kobj->ktype->sysfs_ops) ops = sysfs_file_ops(attr_sd);
ops = kobj->ktype->sysfs_ops; if (WARN(!ops, KERN_ERR
else { "missing sysfs attribute operations for kobject: %s\n",
WARN(1, KERN_ERR kobject_name(kobj)))
"missing sysfs attribute operations for kobject: %s\n",
kobject_name(kobj));
goto err_out; goto err_out;
}
/* File needs write support. /* File needs write support.
* The inode's perms must say it's ok, * The inode's perms must say it's ok,
...@@ -370,7 +380,6 @@ static int sysfs_open_file(struct inode *inode, struct file *file) ...@@ -370,7 +380,6 @@ static int sysfs_open_file(struct inode *inode, struct file *file)
goto err_out; goto err_out;
mutex_init(&buffer->mutex); mutex_init(&buffer->mutex);
buffer->ops = ops;
file->private_data = buffer; file->private_data = buffer;
/* make sure we have open dirent struct */ /* make sure we have open dirent struct */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment