Skip to content

Commit 7c6e2d3

Browse files
htejungregkh
authored andcommitted
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>
1 parent 45b4539 commit 7c6e2d3

5 files changed

Lines changed: 21 additions & 24 deletions

File tree

‎fs/sysfs/dir.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,7 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
681681
return -ENOMEM;
682682

683683
sd->s_ns = ns;
684-
sd->s_dir.kobj = kobj;
684+
sd->priv = kobj;
685685

686686
/* link in */
687687
sysfs_addrm_start(&acxt);

‎fs/sysfs/file.c‎

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ static struct sysfs_open_file *sysfs_of(struct file *file)
7474
*/
7575
static const struct sysfs_ops *sysfs_file_ops(struct sysfs_dirent *sd)
7676
{
77-
struct kobject *kobj = sd->s_parent->s_dir.kobj;
77+
struct kobject *kobj = sd->s_parent->priv;
7878

7979
if (!sysfs_ignore_lockdep(sd))
8080
lockdep_assert_held(sd);
@@ -89,7 +89,7 @@ static const struct sysfs_ops *sysfs_file_ops(struct sysfs_dirent *sd)
8989
static int sysfs_seq_show(struct seq_file *sf, void *v)
9090
{
9191
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;
9393
const struct sysfs_ops *ops;
9494
char *buf;
9595
ssize_t count;
@@ -120,7 +120,7 @@ static int sysfs_seq_show(struct seq_file *sf, void *v)
120120
*/
121121
ops = sysfs_file_ops(of->sd);
122122
if (ops->show)
123-
count = ops->show(kobj, of->sd->s_attr.attr, buf);
123+
count = ops->show(kobj, of->sd->priv, buf);
124124
else
125125
count = 0;
126126

@@ -154,8 +154,8 @@ static ssize_t sysfs_bin_read(struct file *file, char __user *userbuf,
154154
size_t bytes, loff_t *off)
155155
{
156156
struct sysfs_open_file *of = sysfs_of(file);
157-
struct bin_attribute *battr = of->sd->s_attr.bin_attr;
158-
struct kobject *kobj = of->sd->s_parent->s_dir.kobj;
157+
struct bin_attribute *battr = of->sd->priv;
158+
struct kobject *kobj = of->sd->s_parent->priv;
159159
loff_t size = file_inode(file)->i_size;
160160
int count = min_t(size_t, bytes, PAGE_SIZE);
161161
loff_t offs = *off;
@@ -221,7 +221,7 @@ static ssize_t sysfs_bin_read(struct file *file, char __user *userbuf,
221221
static int flush_write_buffer(struct sysfs_open_file *of, char *buf, loff_t off,
222222
size_t count)
223223
{
224-
struct kobject *kobj = of->sd->s_parent->s_dir.kobj;
224+
struct kobject *kobj = of->sd->s_parent->priv;
225225
int rc = 0;
226226

227227
/*
@@ -236,7 +236,7 @@ static int flush_write_buffer(struct sysfs_open_file *of, char *buf, loff_t off,
236236
}
237237

238238
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;
240240

241241
rc = -EIO;
242242
if (battr->write)
@@ -245,7 +245,7 @@ static int flush_write_buffer(struct sysfs_open_file *of, char *buf, loff_t off,
245245
} else {
246246
const struct sysfs_ops *ops = sysfs_file_ops(of->sd);
247247

248-
rc = ops->store(kobj, of->sd->s_attr.attr, buf, count);
248+
rc = ops->store(kobj, of->sd->priv, buf, count);
249249
}
250250

251251
sysfs_put_active(of->sd);
@@ -466,8 +466,8 @@ static const struct vm_operations_struct sysfs_bin_vm_ops = {
466466
static int sysfs_bin_mmap(struct file *file, struct vm_area_struct *vma)
467467
{
468468
struct sysfs_open_file *of = sysfs_of(file);
469-
struct bin_attribute *battr = of->sd->s_attr.bin_attr;
470-
struct kobject *kobj = of->sd->s_parent->s_dir.kobj;
469+
struct bin_attribute *battr = of->sd->priv;
470+
struct kobject *kobj = of->sd->s_parent->priv;
471471
int rc;
472472

473473
mutex_lock(&of->mutex);
@@ -607,7 +607,7 @@ static void sysfs_put_open_dirent(struct sysfs_dirent *sd,
607607
static int sysfs_open_file(struct inode *inode, struct file *file)
608608
{
609609
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;
611611
struct sysfs_open_file *of;
612612
bool has_read, has_write, has_mmap;
613613
int error = -EACCES;
@@ -617,7 +617,7 @@ static int sysfs_open_file(struct inode *inode, struct file *file)
617617
return -ENODEV;
618618

619619
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;
621621

622622
has_read = battr->read || battr->mmap;
623623
has_write = battr->write || battr->mmap;
@@ -848,7 +848,7 @@ int sysfs_add_file_mode_ns(struct sysfs_dirent *dir_sd,
848848
return -ENOMEM;
849849

850850
sd->s_ns = ns;
851-
sd->s_attr.attr = (void *)attr;
851+
sd->priv = (void *)attr;
852852
sysfs_dirent_init_lockdep(sd);
853853

854854
sysfs_addrm_start(&acxt);

‎fs/sysfs/inode.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ static void sysfs_init_inode(struct sysfs_dirent *sd, struct inode *inode)
275275
inode->i_fop = &sysfs_file_operations;
276276
break;
277277
case SYSFS_KOBJ_BIN_ATTR:
278-
bin_attr = sd->s_attr.bin_attr;
278+
bin_attr = sd->priv;
279279
inode->i_size = bin_attr->size;
280280
inode->i_fop = &sysfs_bin_operations;
281281
break;

‎fs/sysfs/symlink.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ int sysfs_rename_link_ns(struct kobject *kobj, struct kobject *targ,
223223
result = -EINVAL;
224224
if (sysfs_type(sd) != SYSFS_KOBJ_LINK)
225225
goto out;
226-
if (sd->s_symlink.target_sd->s_dir.kobj != targ)
226+
if (sd->s_symlink.target_sd->priv != targ)
227227
goto out;
228228

229229
result = kernfs_rename_ns(sd, parent_sd, new, new_ns);

‎fs/sysfs/sysfs.h‎

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ struct sysfs_open_dirent;
1717

1818
/* type-specific structures for sysfs_dirent->s_* union members */
1919
struct sysfs_elem_dir {
20-
struct kobject *kobj;
21-
2220
unsigned long subdirs;
2321
/* children rbtree starts here and goes through sd->s_rb */
2422
struct rb_root children;
@@ -29,10 +27,6 @@ struct sysfs_elem_symlink {
2927
};
3028

3129
struct sysfs_elem_attr {
32-
union {
33-
struct attribute *attr;
34-
struct bin_attribute *bin_attr;
35-
};
3630
struct sysfs_open_dirent *open;
3731
};
3832

@@ -74,6 +68,8 @@ struct sysfs_dirent {
7468
struct sysfs_elem_attr s_attr;
7569
};
7670

71+
void *priv;
72+
7773
unsigned short s_flags;
7874
umode_t s_mode;
7975
unsigned int s_ino;
@@ -103,7 +99,7 @@ static inline unsigned int sysfs_type(struct sysfs_dirent *sd)
10399

104100
#define sysfs_dirent_init_lockdep(sd) \
105101
do { \
106-
struct attribute *attr = sd->s_attr.attr; \
102+
struct attribute *attr = sd->priv; \
107103
struct lock_class_key *key = attr->key; \
108104
if (!key) \
109105
key = &attr->skey; \
@@ -114,10 +110,11 @@ do { \
114110
/* Test for attributes that want to ignore lockdep for read-locking */
115111
static inline bool sysfs_ignore_lockdep(struct sysfs_dirent *sd)
116112
{
113+
struct attribute *attr = sd->priv;
117114
int type = sysfs_type(sd);
118115

119116
return (type == SYSFS_KOBJ_ATTR || type == SYSFS_KOBJ_BIN_ATTR) &&
120-
sd->s_attr.attr->ignore_lockdep;
117+
attr->ignore_lockdep;
121118
}
122119

123120
#else

0 commit comments

Comments
 (0)