Commit 471bd7b7 authored by Tejun Heo's avatar Tejun Heo Committed by Greg Kroah-Hartman

sysfs, kernfs: add sysfs_dirent->s_attr.size

sysfs sets the size of regular files unconditionally at PAGE_SIZE and
takes the size of bin files from bin_attribute.  The latter is a
pretty bad interface which forces bin_attribute users to create a
separate copy of bin_attribute for each instance of the file -
e.g. pci resource files.

Add sysfs_dirent->s_attr.size so that the size can be specified
separately.  This unifies inode init paths of ATTR and BIN_ATTR
identical and allows for generic size handling for kernfs.

Unfortunately, this grows the size of sysfs_dirent by sizeof(loff_t).
Signed-off-by: default avatarTejun Heo <tj@kernel.org>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent f6acf8bb
...@@ -923,6 +923,7 @@ int sysfs_add_file_mode_ns(struct sysfs_dirent *dir_sd, ...@@ -923,6 +923,7 @@ int sysfs_add_file_mode_ns(struct sysfs_dirent *dir_sd,
const struct kernfs_ops *ops; const struct kernfs_ops *ops;
struct sysfs_addrm_cxt acxt; struct sysfs_addrm_cxt acxt;
struct sysfs_dirent *sd; struct sysfs_dirent *sd;
loff_t size;
int rc; int rc;
if (type == SYSFS_KOBJ_ATTR) { if (type == SYSFS_KOBJ_ATTR) {
...@@ -943,6 +944,8 @@ int sysfs_add_file_mode_ns(struct sysfs_dirent *dir_sd, ...@@ -943,6 +944,8 @@ int sysfs_add_file_mode_ns(struct sysfs_dirent *dir_sd,
ops = &sysfs_file_kfops_wo; ops = &sysfs_file_kfops_wo;
else else
ops = &sysfs_file_kfops_empty; ops = &sysfs_file_kfops_empty;
size = PAGE_SIZE;
} else { } else {
struct bin_attribute *battr = (void *)attr; struct bin_attribute *battr = (void *)attr;
...@@ -954,6 +957,8 @@ int sysfs_add_file_mode_ns(struct sysfs_dirent *dir_sd, ...@@ -954,6 +957,8 @@ int sysfs_add_file_mode_ns(struct sysfs_dirent *dir_sd,
ops = &sysfs_bin_kfops_wo; ops = &sysfs_bin_kfops_wo;
else else
ops = &sysfs_file_kfops_empty; ops = &sysfs_file_kfops_empty;
size = battr->size;
} }
sd = sysfs_new_dirent(attr->name, mode, type); sd = sysfs_new_dirent(attr->name, mode, type);
...@@ -961,6 +966,7 @@ int sysfs_add_file_mode_ns(struct sysfs_dirent *dir_sd, ...@@ -961,6 +966,7 @@ int sysfs_add_file_mode_ns(struct sysfs_dirent *dir_sd,
return -ENOMEM; return -ENOMEM;
sd->s_attr.ops = ops; sd->s_attr.ops = ops;
sd->s_attr.size = size;
sd->s_ns = ns; sd->s_ns = ns;
sd->priv = (void *)attr; sd->priv = (void *)attr;
sysfs_dirent_init_lockdep(sd); sysfs_dirent_init_lockdep(sd);
......
...@@ -254,8 +254,6 @@ int sysfs_getattr(struct vfsmount *mnt, struct dentry *dentry, ...@@ -254,8 +254,6 @@ int sysfs_getattr(struct vfsmount *mnt, struct dentry *dentry,
static void sysfs_init_inode(struct sysfs_dirent *sd, struct inode *inode) static void sysfs_init_inode(struct sysfs_dirent *sd, struct inode *inode)
{ {
struct bin_attribute *bin_attr;
inode->i_private = sysfs_get(sd); inode->i_private = sysfs_get(sd);
inode->i_mapping->a_ops = &sysfs_aops; inode->i_mapping->a_ops = &sysfs_aops;
inode->i_mapping->backing_dev_info = &sysfs_backing_dev_info; inode->i_mapping->backing_dev_info = &sysfs_backing_dev_info;
...@@ -271,12 +269,8 @@ static void sysfs_init_inode(struct sysfs_dirent *sd, struct inode *inode) ...@@ -271,12 +269,8 @@ static void sysfs_init_inode(struct sysfs_dirent *sd, struct inode *inode)
inode->i_fop = &sysfs_dir_operations; inode->i_fop = &sysfs_dir_operations;
break; break;
case SYSFS_KOBJ_ATTR: case SYSFS_KOBJ_ATTR:
inode->i_size = PAGE_SIZE;
inode->i_fop = &kernfs_file_operations;
break;
case SYSFS_KOBJ_BIN_ATTR: case SYSFS_KOBJ_BIN_ATTR:
bin_attr = sd->priv; inode->i_size = sd->s_attr.size;
inode->i_size = bin_attr->size;
inode->i_fop = &kernfs_file_operations; inode->i_fop = &kernfs_file_operations;
break; break;
case SYSFS_KOBJ_LINK: case SYSFS_KOBJ_LINK:
......
...@@ -29,6 +29,7 @@ struct sysfs_elem_symlink { ...@@ -29,6 +29,7 @@ struct sysfs_elem_symlink {
struct sysfs_elem_attr { struct sysfs_elem_attr {
const struct kernfs_ops *ops; const struct kernfs_ops *ops;
struct sysfs_open_dirent *open; struct sysfs_open_dirent *open;
loff_t size;
}; };
struct sysfs_inode_attrs { struct sysfs_inode_attrs {
......
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