summaryrefslogtreecommitdiffstats
path: root/fs/sysfs
diff options
context:
space:
mode:
authorTejun Heo <tj@kernel.org>2013-10-01 17:42:00 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2013-10-05 20:21:03 -0400
commitbcafe4eea3e58a60e9c2c63781700a9ab1d70f93 (patch)
tree88026a22d2892e755551343f7245c804935d7f3f /fs/sysfs
parent58282d8dc2e7cf2b87c8fee94d7138ed08e0a2e5 (diff)
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>
Diffstat (limited to 'fs/sysfs')
-rw-r--r--fs/sysfs/file.c23
1 files changed, 12 insertions, 11 deletions
diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
index 4b55bcf4422e..af6e9092a679 100644
--- a/fs/sysfs/file.c
+++ b/fs/sysfs/file.c
@@ -45,6 +45,8 @@ struct sysfs_open_dirent {
45}; 45};
46 46
47struct sysfs_open_file { 47struct sysfs_open_file {
48 struct sysfs_dirent *sd;
49 struct file *file;
48 size_t count; 50 size_t count;
49 char *page; 51 char *page;
50 struct mutex mutex; 52 struct mutex mutex;
@@ -192,7 +194,6 @@ static int fill_write_buffer(struct sysfs_open_file *of,
192 194
193/** 195/**
194 * flush_write_buffer - push buffer to kobject. 196 * flush_write_buffer - push buffer to kobject.
195 * @dentry: dentry to the attribute
196 * @of: open file 197 * @of: open file
197 * @count: number of bytes 198 * @count: number of bytes
198 * 199 *
@@ -200,22 +201,20 @@ static int fill_write_buffer(struct sysfs_open_file *of,
200 * dealing with, then call the store() method for the attribute, 201 * dealing with, then call the store() method for the attribute,
201 * passing the buffer that we acquired in fill_write_buffer(). 202 * passing the buffer that we acquired in fill_write_buffer().
202 */ 203 */
203static int flush_write_buffer(struct dentry *dentry, 204static int flush_write_buffer(struct sysfs_open_file *of, size_t count)
204 struct sysfs_open_file *of, size_t count)
205{ 205{
206 struct sysfs_dirent *attr_sd = dentry->d_fsdata; 206 struct kobject *kobj = of->sd->s_parent->s_dir.kobj;
207 struct kobject *kobj = attr_sd->s_parent->s_dir.kobj;
208 const struct sysfs_ops *ops; 207 const struct sysfs_ops *ops;
209 int rc; 208 int rc;
210 209
211 /* need attr_sd for attr and ops, its parent for kobj */ 210 /* need @of->sd for attr and ops, its parent for kobj */
212 if (!sysfs_get_active(attr_sd)) 211 if (!sysfs_get_active(of->sd))
213 return -ENODEV; 212 return -ENODEV;
214 213
215 ops = sysfs_file_ops(attr_sd); 214 ops = sysfs_file_ops(of->sd);
216 rc = ops->store(kobj, attr_sd->s_attr.attr, of->page, count); 215 rc = ops->store(kobj, of->sd->s_attr.attr, of->page, count);
217 216
218 sysfs_put_active(attr_sd); 217 sysfs_put_active(of->sd);
219 218
220 return rc; 219 return rc;
221} 220}
@@ -245,7 +244,7 @@ static ssize_t sysfs_write_file(struct file *file, const char __user *buf,
245 mutex_lock(&of->mutex); 244 mutex_lock(&of->mutex);
246 len = fill_write_buffer(of, buf, count); 245 len = fill_write_buffer(of, buf, count);
247 if (len > 0) 246 if (len > 0)
248 len = flush_write_buffer(file->f_path.dentry, of, len); 247 len = flush_write_buffer(of, len);
249 if (len > 0) 248 if (len > 0)
250 *ppos += len; 249 *ppos += len;
251 mutex_unlock(&of->mutex); 250 mutex_unlock(&of->mutex);
@@ -385,6 +384,8 @@ static int sysfs_open_file(struct inode *inode, struct file *file)
385 goto err_out; 384 goto err_out;
386 385
387 mutex_init(&of->mutex); 386 mutex_init(&of->mutex);
387 of->sd = attr_sd;
388 of->file = file;
388 file->private_data = of; 389 file->private_data = of;
389 390
390 /* make sure we have open dirent struct */ 391 /* make sure we have open dirent struct */