diff options
| author | Tejun Heo <tj@kernel.org> | 2013-11-28 14:54:14 -0500 |
|---|---|---|
| committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2013-11-29 20:19:16 -0500 |
| commit | 7c6e2d362c19f01e6d6c8be59d83a89722032884 (patch) | |
| tree | f47de0a95ae5de6016f19f949dacfe3a77326c31 | |
| parent | 45b4539309d82ae04e6ed7de494ae194ca0755aa (diff) | |
sysfs, kernfs: replace sysfs_dirent->s_dir.kobj and ->s_attr.[bin_]attr with ->priv
A directory sysfs_dirent points to the associated kobj. A regular or
bin file points to the associated [bin_]attribute. This patch
replaces sysfs_dirent->s_dir.kobj and ->s_attr.[bin_]attr with void *
->priv.
This is to prepare for kernfs interface so that sysfs can specify the
private data in the same way for directories and files. This lower
debuggability but not by much - the whole thing was overlaid in a
union anyway. If debuggability becomes an issue, we can later add
->priv accessors which explicitly check for the sysfs_dirent type and
performs casting.
This patch doesn't introduce any behavior difference.
Signed-off-by: Tejun Heo <tj@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
| -rw-r--r-- | fs/sysfs/dir.c | 2 | ||||
| -rw-r--r-- | fs/sysfs/file.c | 26 | ||||
| -rw-r--r-- | fs/sysfs/inode.c | 2 | ||||
| -rw-r--r-- | fs/sysfs/symlink.c | 2 | ||||
| -rw-r--r-- | fs/sysfs/sysfs.h | 13 |
5 files changed, 21 insertions, 24 deletions
diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c index 5ba896630d04..aeb08bd3f3dd 100644 --- a/fs/sysfs/dir.c +++ b/fs/sysfs/dir.c | |||
| @@ -681,7 +681,7 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd, | |||
| 681 | return -ENOMEM; | 681 | return -ENOMEM; |
| 682 | 682 | ||
| 683 | sd->s_ns = ns; | 683 | sd->s_ns = ns; |
| 684 | sd->s_dir.kobj = kobj; | 684 | sd->priv = kobj; |
| 685 | 685 | ||
| 686 | /* link in */ | 686 | /* link in */ |
| 687 | sysfs_addrm_start(&acxt); | 687 | sysfs_addrm_start(&acxt); |
diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c index 0f3f0a252a50..9b58d874c825 100644 --- a/fs/sysfs/file.c +++ b/fs/sysfs/file.c | |||
| @@ -74,7 +74,7 @@ static struct sysfs_open_file *sysfs_of(struct file *file) | |||
| 74 | */ | 74 | */ |
| 75 | static const struct sysfs_ops *sysfs_file_ops(struct sysfs_dirent *sd) | 75 | static const struct sysfs_ops *sysfs_file_ops(struct sysfs_dirent *sd) |
| 76 | { | 76 | { |
| 77 | struct kobject *kobj = sd->s_parent->s_dir.kobj; | 77 | struct kobject *kobj = sd->s_parent->priv; |
| 78 | 78 | ||
| 79 | if (!sysfs_ignore_lockdep(sd)) | 79 | if (!sysfs_ignore_lockdep(sd)) |
| 80 | lockdep_assert_held(sd); | 80 | lockdep_assert_held(sd); |
| @@ -89,7 +89,7 @@ static const struct sysfs_ops *sysfs_file_ops(struct sysfs_dirent *sd) | |||
| 89 | static int sysfs_seq_show(struct seq_file *sf, void *v) | 89 | static int sysfs_seq_show(struct seq_file *sf, void *v) |
| 90 | { | 90 | { |
| 91 | struct sysfs_open_file *of = sf->private; | 91 | struct sysfs_open_file *of = sf->private; |
| 92 | struct kobject *kobj = of->sd->s_parent->s_dir.kobj; | 92 | struct kobject *kobj = of->sd->s_parent->priv; |
| 93 | const struct sysfs_ops *ops; | 93 | const struct sysfs_ops *ops; |
| 94 | char *buf; | 94 | char *buf; |
| 95 | ssize_t count; | 95 | ssize_t count; |
| @@ -120,7 +120,7 @@ static int sysfs_seq_show(struct seq_file *sf, void *v) | |||
| 120 | */ | 120 | */ |
| 121 | ops = sysfs_file_ops(of->sd); | 121 | ops = sysfs_file_ops(of->sd); |
| 122 | if (ops->show) | 122 | if (ops->show) |
| 123 | count = ops->show(kobj, of->sd->s_attr.attr, buf); | 123 | count = ops->show(kobj, of->sd->priv, buf); |
| 124 | else | 124 | else |
| 125 | count = 0; | 125 | count = 0; |
| 126 | 126 | ||
| @@ -154,8 +154,8 @@ static ssize_t sysfs_bin_read(struct file *file, char __user *userbuf, | |||
| 154 | size_t bytes, loff_t *off) | 154 | size_t bytes, loff_t *off) |
| 155 | { | 155 | { |
| 156 | struct sysfs_open_file *of = sysfs_of(file); | 156 | struct sysfs_open_file *of = sysfs_of(file); |
| 157 | struct bin_attribute *battr = of->sd->s_attr.bin_attr; | 157 | struct bin_attribute *battr = of->sd->priv; |
| 158 | struct kobject *kobj = of->sd->s_parent->s_dir.kobj; | 158 | struct kobject *kobj = of->sd->s_parent->priv; |
| 159 | loff_t size = file_inode(file)->i_size; | 159 | loff_t size = file_inode(file)->i_size; |
| 160 | int count = min_t(size_t, bytes, PAGE_SIZE); | 160 | int count = min_t(size_t, bytes, PAGE_SIZE); |
| 161 | loff_t offs = *off; | 161 | loff_t offs = *off; |
| @@ -221,7 +221,7 @@ static ssize_t sysfs_bin_read(struct file *file, char __user *userbuf, | |||
| 221 | static int flush_write_buffer(struct sysfs_open_file *of, char *buf, loff_t off, | 221 | static int flush_write_buffer(struct sysfs_open_file *of, char *buf, loff_t off, |
| 222 | size_t count) | 222 | size_t count) |
| 223 | { | 223 | { |
| 224 | struct kobject *kobj = of->sd->s_parent->s_dir.kobj; | 224 | struct kobject *kobj = of->sd->s_parent->priv; |
| 225 | int rc = 0; | 225 | int rc = 0; |
| 226 | 226 | ||
| 227 | /* | 227 | /* |
| @@ -236,7 +236,7 @@ static int flush_write_buffer(struct sysfs_open_file *of, char *buf, loff_t off, | |||
| 236 | } | 236 | } |
| 237 | 237 | ||
| 238 | if (sysfs_is_bin(of->sd)) { | 238 | if (sysfs_is_bin(of->sd)) { |
| 239 | struct bin_attribute *battr = of->sd->s_attr.bin_attr; | 239 | struct bin_attribute *battr = of->sd->priv; |
| 240 | 240 | ||
| 241 | rc = -EIO; | 241 | rc = -EIO; |
| 242 | if (battr->write) | 242 | if (battr->write) |
| @@ -245,7 +245,7 @@ static int flush_write_buffer(struct sysfs_open_file *of, char *buf, loff_t off, | |||
| 245 | } else { | 245 | } else { |
| 246 | const struct sysfs_ops *ops = sysfs_file_ops(of->sd); | 246 | const struct sysfs_ops *ops = sysfs_file_ops(of->sd); |
| 247 | 247 | ||
| 248 | rc = ops->store(kobj, of->sd->s_attr.attr, buf, count); | 248 | rc = ops->store(kobj, of->sd->priv, buf, count); |
| 249 | } | 249 | } |
| 250 | 250 | ||
| 251 | sysfs_put_active(of->sd); | 251 | sysfs_put_active(of->sd); |
| @@ -466,8 +466,8 @@ static const struct vm_operations_struct sysfs_bin_vm_ops = { | |||
| 466 | static int sysfs_bin_mmap(struct file *file, struct vm_area_struct *vma) | 466 | static int sysfs_bin_mmap(struct file *file, struct vm_area_struct *vma) |
| 467 | { | 467 | { |
| 468 | struct sysfs_open_file *of = sysfs_of(file); | 468 | struct sysfs_open_file *of = sysfs_of(file); |
| 469 | struct bin_attribute *battr = of->sd->s_attr.bin_attr; | 469 | struct bin_attribute *battr = of->sd->priv; |
| 470 | struct kobject *kobj = of->sd->s_parent->s_dir.kobj; | 470 | struct kobject *kobj = of->sd->s_parent->priv; |
| 471 | int rc; | 471 | int rc; |
| 472 | 472 | ||
| 473 | mutex_lock(&of->mutex); | 473 | mutex_lock(&of->mutex); |
| @@ -607,7 +607,7 @@ static void sysfs_put_open_dirent(struct sysfs_dirent *sd, | |||
| 607 | static int sysfs_open_file(struct inode *inode, struct file *file) | 607 | static int sysfs_open_file(struct inode *inode, struct file *file) |
| 608 | { | 608 | { |
| 609 | struct sysfs_dirent *attr_sd = file->f_path.dentry->d_fsdata; | 609 | struct sysfs_dirent *attr_sd = file->f_path.dentry->d_fsdata; |
| 610 | struct kobject *kobj = attr_sd->s_parent->s_dir.kobj; | 610 | struct kobject *kobj = attr_sd->s_parent->priv; |
| 611 | struct sysfs_open_file *of; | 611 | struct sysfs_open_file *of; |
| 612 | bool has_read, has_write, has_mmap; | 612 | bool has_read, has_write, has_mmap; |
| 613 | int error = -EACCES; | 613 | int error = -EACCES; |
| @@ -617,7 +617,7 @@ static int sysfs_open_file(struct inode *inode, struct file *file) | |||
| 617 | return -ENODEV; | 617 | return -ENODEV; |
| 618 | 618 | ||
| 619 | if (sysfs_is_bin(attr_sd)) { | 619 | if (sysfs_is_bin(attr_sd)) { |
| 620 | struct bin_attribute *battr = attr_sd->s_attr.bin_attr; | 620 | struct bin_attribute *battr = attr_sd->priv; |
| 621 | 621 | ||
| 622 | has_read = battr->read || battr->mmap; | 622 | has_read = battr->read || battr->mmap; |
| 623 | has_write = battr->write || battr->mmap; | 623 | has_write = battr->write || battr->mmap; |
| @@ -848,7 +848,7 @@ int sysfs_add_file_mode_ns(struct sysfs_dirent *dir_sd, | |||
| 848 | return -ENOMEM; | 848 | return -ENOMEM; |
| 849 | 849 | ||
| 850 | sd->s_ns = ns; | 850 | sd->s_ns = ns; |
| 851 | sd->s_attr.attr = (void *)attr; | 851 | sd->priv = (void *)attr; |
| 852 | sysfs_dirent_init_lockdep(sd); | 852 | sysfs_dirent_init_lockdep(sd); |
| 853 | 853 | ||
| 854 | sysfs_addrm_start(&acxt); | 854 | sysfs_addrm_start(&acxt); |
diff --git a/fs/sysfs/inode.c b/fs/sysfs/inode.c index 5f7e2afb3457..81cc8585b32c 100644 --- a/fs/sysfs/inode.c +++ b/fs/sysfs/inode.c | |||
| @@ -275,7 +275,7 @@ static void sysfs_init_inode(struct sysfs_dirent *sd, struct inode *inode) | |||
| 275 | inode->i_fop = &sysfs_file_operations; | 275 | inode->i_fop = &sysfs_file_operations; |
| 276 | break; | 276 | break; |
| 277 | case SYSFS_KOBJ_BIN_ATTR: | 277 | case SYSFS_KOBJ_BIN_ATTR: |
| 278 | bin_attr = sd->s_attr.bin_attr; | 278 | bin_attr = sd->priv; |
| 279 | inode->i_size = bin_attr->size; | 279 | inode->i_size = bin_attr->size; |
| 280 | inode->i_fop = &sysfs_bin_operations; | 280 | inode->i_fop = &sysfs_bin_operations; |
| 281 | break; | 281 | break; |
diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c index 0922c53bd757..352fbbbc0551 100644 --- a/fs/sysfs/symlink.c +++ b/fs/sysfs/symlink.c | |||
| @@ -223,7 +223,7 @@ int sysfs_rename_link_ns(struct kobject *kobj, struct kobject *targ, | |||
| 223 | result = -EINVAL; | 223 | result = -EINVAL; |
| 224 | if (sysfs_type(sd) != SYSFS_KOBJ_LINK) | 224 | if (sysfs_type(sd) != SYSFS_KOBJ_LINK) |
| 225 | goto out; | 225 | goto out; |
| 226 | if (sd->s_symlink.target_sd->s_dir.kobj != targ) | 226 | if (sd->s_symlink.target_sd->priv != targ) |
| 227 | goto out; | 227 | goto out; |
| 228 | 228 | ||
| 229 | result = kernfs_rename_ns(sd, parent_sd, new, new_ns); | 229 | result = kernfs_rename_ns(sd, parent_sd, new, new_ns); |
diff --git a/fs/sysfs/sysfs.h b/fs/sysfs/sysfs.h index 2abccfdd932e..a6f3fa3f02fe 100644 --- a/fs/sysfs/sysfs.h +++ b/fs/sysfs/sysfs.h | |||
| @@ -17,8 +17,6 @@ struct sysfs_open_dirent; | |||
| 17 | 17 | ||
| 18 | /* type-specific structures for sysfs_dirent->s_* union members */ | 18 | /* type-specific structures for sysfs_dirent->s_* union members */ |
| 19 | struct sysfs_elem_dir { | 19 | struct sysfs_elem_dir { |
| 20 | struct kobject *kobj; | ||
| 21 | |||
| 22 | unsigned long subdirs; | 20 | unsigned long subdirs; |
| 23 | /* children rbtree starts here and goes through sd->s_rb */ | 21 | /* children rbtree starts here and goes through sd->s_rb */ |
| 24 | struct rb_root children; | 22 | struct rb_root children; |
| @@ -29,10 +27,6 @@ struct sysfs_elem_symlink { | |||
| 29 | }; | 27 | }; |
| 30 | 28 | ||
| 31 | struct sysfs_elem_attr { | 29 | struct sysfs_elem_attr { |
| 32 | union { | ||
| 33 | struct attribute *attr; | ||
| 34 | struct bin_attribute *bin_attr; | ||
| 35 | }; | ||
| 36 | struct sysfs_open_dirent *open; | 30 | struct sysfs_open_dirent *open; |
| 37 | }; | 31 | }; |
| 38 | 32 | ||
| @@ -74,6 +68,8 @@ struct sysfs_dirent { | |||
| 74 | struct sysfs_elem_attr s_attr; | 68 | struct sysfs_elem_attr s_attr; |
| 75 | }; | 69 | }; |
| 76 | 70 | ||
| 71 | void *priv; | ||
| 72 | |||
| 77 | unsigned short s_flags; | 73 | unsigned short s_flags; |
| 78 | umode_t s_mode; | 74 | umode_t s_mode; |
| 79 | unsigned int s_ino; | 75 | unsigned int s_ino; |
| @@ -103,7 +99,7 @@ static inline unsigned int sysfs_type(struct sysfs_dirent *sd) | |||
| 103 | 99 | ||
| 104 | #define sysfs_dirent_init_lockdep(sd) \ | 100 | #define sysfs_dirent_init_lockdep(sd) \ |
| 105 | do { \ | 101 | do { \ |
| 106 | struct attribute *attr = sd->s_attr.attr; \ | 102 | struct attribute *attr = sd->priv; \ |
| 107 | struct lock_class_key *key = attr->key; \ | 103 | struct lock_class_key *key = attr->key; \ |
| 108 | if (!key) \ | 104 | if (!key) \ |
| 109 | key = &attr->skey; \ | 105 | key = &attr->skey; \ |
| @@ -114,10 +110,11 @@ do { \ | |||
| 114 | /* Test for attributes that want to ignore lockdep for read-locking */ | 110 | /* Test for attributes that want to ignore lockdep for read-locking */ |
| 115 | static inline bool sysfs_ignore_lockdep(struct sysfs_dirent *sd) | 111 | static inline bool sysfs_ignore_lockdep(struct sysfs_dirent *sd) |
| 116 | { | 112 | { |
| 113 | struct attribute *attr = sd->priv; | ||
| 117 | int type = sysfs_type(sd); | 114 | int type = sysfs_type(sd); |
| 118 | 115 | ||
| 119 | return (type == SYSFS_KOBJ_ATTR || type == SYSFS_KOBJ_BIN_ATTR) && | 116 | return (type == SYSFS_KOBJ_ATTR || type == SYSFS_KOBJ_BIN_ATTR) && |
| 120 | sd->s_attr.attr->ignore_lockdep; | 117 | attr->ignore_lockdep; |
| 121 | } | 118 | } |
| 122 | 119 | ||
| 123 | #else | 120 | #else |
