aboutsummaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
authorChristoph Hellwig <hch@lst.de>2015-10-03 09:32:37 -0400
committerNicholas Bellinger <nab@linux-iscsi.org>2015-10-14 01:08:43 -0400
commit870823e629ea194e6cf8e82a9694ac62cad49512 (patch)
treeb48ab62284a125096e42d6628850c7a8e4629aa7 /fs
parent6ff33f3902c3b1c5d0db6b1e2c70b6d76fba357f (diff)
configfs: add show and store methods to struct configfs_attribute
Add methods to struct configfs_attribute to directly show and store attributes without adding boilerplate code to every user. In addition to the methods this also adds 3 helper macros to define read/write, read-only and write-only attributes with a single line of code. Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Nicholas Bellinger <nab@linux-iscsi.org> Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>
Diffstat (limited to 'fs')
-rw-r--r--fs/configfs/file.c17
1 files changed, 12 insertions, 5 deletions
diff --git a/fs/configfs/file.c b/fs/configfs/file.c
index 403269ffcdf3..106ca589e90a 100644
--- a/fs/configfs/file.c
+++ b/fs/configfs/file.c
@@ -74,7 +74,11 @@ static int fill_read_buffer(struct dentry * dentry, struct configfs_buffer * buf
74 if (!buffer->page) 74 if (!buffer->page)
75 return -ENOMEM; 75 return -ENOMEM;
76 76
77 count = ops->show_attribute(item,attr,buffer->page); 77 if (ops->show_attribute)
78 count = ops->show_attribute(item, attr, buffer->page);
79 else
80 count = attr->show(item, buffer->page);
81
78 buffer->needs_read_fill = 0; 82 buffer->needs_read_fill = 0;
79 BUG_ON(count > (ssize_t)SIMPLE_ATTR_SIZE); 83 BUG_ON(count > (ssize_t)SIMPLE_ATTR_SIZE);
80 if (count >= 0) 84 if (count >= 0)
@@ -173,7 +177,9 @@ flush_write_buffer(struct dentry * dentry, struct configfs_buffer * buffer, size
173 struct config_item * item = to_item(dentry->d_parent); 177 struct config_item * item = to_item(dentry->d_parent);
174 struct configfs_item_operations * ops = buffer->ops; 178 struct configfs_item_operations * ops = buffer->ops;
175 179
176 return ops->store_attribute(item,attr,buffer->page,count); 180 if (ops->store_attribute)
181 return ops->store_attribute(item, attr, buffer->page, count);
182 return attr->store(item, buffer->page, count);
177} 183}
178 184
179 185
@@ -237,8 +243,8 @@ static int check_perm(struct inode * inode, struct file * file)
237 * and we must have a store method. 243 * and we must have a store method.
238 */ 244 */
239 if (file->f_mode & FMODE_WRITE) { 245 if (file->f_mode & FMODE_WRITE) {
240 246 if (!(inode->i_mode & S_IWUGO) ||
241 if (!(inode->i_mode & S_IWUGO) || !ops->store_attribute) 247 (!ops->store_attribute && !attr->store))
242 goto Eaccess; 248 goto Eaccess;
243 249
244 } 250 }
@@ -248,7 +254,8 @@ static int check_perm(struct inode * inode, struct file * file)
248 * must be a show method for it. 254 * must be a show method for it.
249 */ 255 */
250 if (file->f_mode & FMODE_READ) { 256 if (file->f_mode & FMODE_READ) {
251 if (!(inode->i_mode & S_IRUGO) || !ops->show_attribute) 257 if (!(inode->i_mode & S_IRUGO) ||
258 (!ops->show_attribute && !attr->show))
252 goto Eaccess; 259 goto Eaccess;
253 } 260 }
254 261