From: Tejun Heo <tj@kernel.org>
To: gregkh@linuxfoundation.org
Cc: kay@vrfy.org, linux-kernel@vger.kernel.org,
ebiederm@xmission.com, bhelgaas@google.com,
Tejun Heo <tj@kernel.org>
Subject: [PATCH 08/41] sysfs, kernfs: replace sysfs_dirent->s_dir.kobj and ->s_attr.[bin_]attr with ->priv
Date: Sat, 23 Nov 2013 17:21:53 -0500 [thread overview]
Message-ID: <1385245346-856-9-git-send-email-tj@kernel.org> (raw)
In-Reply-To: <1385245346-856-1-git-send-email-tj@kernel.org>
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>
---
fs/sysfs/dir.c | 2 +-
fs/sysfs/file.c | 26 +++++++++++++-------------
fs/sysfs/inode.c | 2 +-
fs/sysfs/symlink.c | 2 +-
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 5ba8966..aeb08bd 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,
return -ENOMEM;
sd->s_ns = ns;
- sd->s_dir.kobj = kobj;
+ sd->priv = kobj;
/* link in */
sysfs_addrm_start(&acxt);
diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
index 0f3f0a2..9b58d87 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)
*/
static const struct sysfs_ops *sysfs_file_ops(struct sysfs_dirent *sd)
{
- struct kobject *kobj = sd->s_parent->s_dir.kobj;
+ struct kobject *kobj = sd->s_parent->priv;
if (!sysfs_ignore_lockdep(sd))
lockdep_assert_held(sd);
@@ -89,7 +89,7 @@ static const struct sysfs_ops *sysfs_file_ops(struct sysfs_dirent *sd)
static int sysfs_seq_show(struct seq_file *sf, void *v)
{
struct sysfs_open_file *of = sf->private;
- struct kobject *kobj = of->sd->s_parent->s_dir.kobj;
+ struct kobject *kobj = of->sd->s_parent->priv;
const struct sysfs_ops *ops;
char *buf;
ssize_t count;
@@ -120,7 +120,7 @@ static int sysfs_seq_show(struct seq_file *sf, void *v)
*/
ops = sysfs_file_ops(of->sd);
if (ops->show)
- count = ops->show(kobj, of->sd->s_attr.attr, buf);
+ count = ops->show(kobj, of->sd->priv, buf);
else
count = 0;
@@ -154,8 +154,8 @@ static ssize_t sysfs_bin_read(struct file *file, char __user *userbuf,
size_t bytes, loff_t *off)
{
struct sysfs_open_file *of = sysfs_of(file);
- struct bin_attribute *battr = of->sd->s_attr.bin_attr;
- struct kobject *kobj = of->sd->s_parent->s_dir.kobj;
+ struct bin_attribute *battr = of->sd->priv;
+ struct kobject *kobj = of->sd->s_parent->priv;
loff_t size = file_inode(file)->i_size;
int count = min_t(size_t, bytes, PAGE_SIZE);
loff_t offs = *off;
@@ -221,7 +221,7 @@ static ssize_t sysfs_bin_read(struct file *file, char __user *userbuf,
static int flush_write_buffer(struct sysfs_open_file *of, char *buf, loff_t off,
size_t count)
{
- struct kobject *kobj = of->sd->s_parent->s_dir.kobj;
+ struct kobject *kobj = of->sd->s_parent->priv;
int rc = 0;
/*
@@ -236,7 +236,7 @@ static int flush_write_buffer(struct sysfs_open_file *of, char *buf, loff_t off,
}
if (sysfs_is_bin(of->sd)) {
- struct bin_attribute *battr = of->sd->s_attr.bin_attr;
+ struct bin_attribute *battr = of->sd->priv;
rc = -EIO;
if (battr->write)
@@ -245,7 +245,7 @@ static int flush_write_buffer(struct sysfs_open_file *of, char *buf, loff_t off,
} else {
const struct sysfs_ops *ops = sysfs_file_ops(of->sd);
- rc = ops->store(kobj, of->sd->s_attr.attr, buf, count);
+ rc = ops->store(kobj, of->sd->priv, buf, count);
}
sysfs_put_active(of->sd);
@@ -466,8 +466,8 @@ static const struct vm_operations_struct sysfs_bin_vm_ops = {
static int sysfs_bin_mmap(struct file *file, struct vm_area_struct *vma)
{
struct sysfs_open_file *of = sysfs_of(file);
- struct bin_attribute *battr = of->sd->s_attr.bin_attr;
- struct kobject *kobj = of->sd->s_parent->s_dir.kobj;
+ struct bin_attribute *battr = of->sd->priv;
+ struct kobject *kobj = of->sd->s_parent->priv;
int rc;
mutex_lock(&of->mutex);
@@ -607,7 +607,7 @@ static void sysfs_put_open_dirent(struct sysfs_dirent *sd,
static int sysfs_open_file(struct inode *inode, struct file *file)
{
struct sysfs_dirent *attr_sd = file->f_path.dentry->d_fsdata;
- struct kobject *kobj = attr_sd->s_parent->s_dir.kobj;
+ struct kobject *kobj = attr_sd->s_parent->priv;
struct sysfs_open_file *of;
bool has_read, has_write, has_mmap;
int error = -EACCES;
@@ -617,7 +617,7 @@ static int sysfs_open_file(struct inode *inode, struct file *file)
return -ENODEV;
if (sysfs_is_bin(attr_sd)) {
- struct bin_attribute *battr = attr_sd->s_attr.bin_attr;
+ struct bin_attribute *battr = attr_sd->priv;
has_read = battr->read || battr->mmap;
has_write = battr->write || battr->mmap;
@@ -848,7 +848,7 @@ int sysfs_add_file_mode_ns(struct sysfs_dirent *dir_sd,
return -ENOMEM;
sd->s_ns = ns;
- sd->s_attr.attr = (void *)attr;
+ sd->priv = (void *)attr;
sysfs_dirent_init_lockdep(sd);
sysfs_addrm_start(&acxt);
diff --git a/fs/sysfs/inode.c b/fs/sysfs/inode.c
index 5f7e2af..81cc858 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)
inode->i_fop = &sysfs_file_operations;
break;
case SYSFS_KOBJ_BIN_ATTR:
- bin_attr = sd->s_attr.bin_attr;
+ bin_attr = sd->priv;
inode->i_size = bin_attr->size;
inode->i_fop = &sysfs_bin_operations;
break;
diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
index 0922c53..352fbbb 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,
result = -EINVAL;
if (sysfs_type(sd) != SYSFS_KOBJ_LINK)
goto out;
- if (sd->s_symlink.target_sd->s_dir.kobj != targ)
+ if (sd->s_symlink.target_sd->priv != targ)
goto out;
result = kernfs_rename_ns(sd, parent_sd, new, new_ns);
diff --git a/fs/sysfs/sysfs.h b/fs/sysfs/sysfs.h
index 2abccfd..a6f3fa3 100644
--- a/fs/sysfs/sysfs.h
+++ b/fs/sysfs/sysfs.h
@@ -17,8 +17,6 @@ struct sysfs_open_dirent;
/* type-specific structures for sysfs_dirent->s_* union members */
struct sysfs_elem_dir {
- struct kobject *kobj;
-
unsigned long subdirs;
/* children rbtree starts here and goes through sd->s_rb */
struct rb_root children;
@@ -29,10 +27,6 @@ struct sysfs_elem_symlink {
};
struct sysfs_elem_attr {
- union {
- struct attribute *attr;
- struct bin_attribute *bin_attr;
- };
struct sysfs_open_dirent *open;
};
@@ -74,6 +68,8 @@ struct sysfs_dirent {
struct sysfs_elem_attr s_attr;
};
+ void *priv;
+
unsigned short s_flags;
umode_t s_mode;
unsigned int s_ino;
@@ -103,7 +99,7 @@ static inline unsigned int sysfs_type(struct sysfs_dirent *sd)
#define sysfs_dirent_init_lockdep(sd) \
do { \
- struct attribute *attr = sd->s_attr.attr; \
+ struct attribute *attr = sd->priv; \
struct lock_class_key *key = attr->key; \
if (!key) \
key = &attr->skey; \
@@ -114,10 +110,11 @@ do { \
/* Test for attributes that want to ignore lockdep for read-locking */
static inline bool sysfs_ignore_lockdep(struct sysfs_dirent *sd)
{
+ struct attribute *attr = sd->priv;
int type = sysfs_type(sd);
return (type == SYSFS_KOBJ_ATTR || type == SYSFS_KOBJ_BIN_ATTR) &&
- sd->s_attr.attr->ignore_lockdep;
+ attr->ignore_lockdep;
}
#else
--
1.8.4.2
next prev parent reply other threads:[~2013-11-23 22:32 UTC|newest]
Thread overview: 92+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-11-23 22:21 [PATCHSET driver-core-next] sysfs: separate out kernfs, take #3 Tejun Heo
2013-11-23 22:21 ` [PATCH 01/41] sysfs: drop kobj_ns_type handling, take #2 Tejun Heo
2013-11-23 23:05 ` [PATCH v2 " Tejun Heo
2013-11-23 22:21 ` [PATCH 02/41] sysfs: make __sysfs_add_one() fail if the parent isn't a directory Tejun Heo
2013-11-23 22:21 ` [PATCH 03/41] sysfs, kernfs: add skeletons for kernfs Tejun Heo
2013-11-24 14:54 ` [PATCH REPOST " Tejun Heo
2013-11-23 22:21 ` [PATCH 04/41] sysfs, kernfs: introduce kernfs_remove[_by_name[_ns]]() Tejun Heo
2013-11-23 22:21 ` [PATCH 05/41] sysfs, kernfs: introduce kernfs_create_link() Tejun Heo
2013-11-23 22:21 ` [PATCH 06/41] sysfs, kernfs: introduce kernfs_rename[_ns]() Tejun Heo
2013-11-23 22:21 ` [PATCH 07/41] sysfs, kernfs: introduce kernfs_setattr() Tejun Heo
2013-11-23 22:21 ` Tejun Heo [this message]
2013-11-23 22:21 ` [PATCH 09/41] sysfs, kernfs: introduce kernfs_create_dir[_ns]() Tejun Heo
2013-11-23 23:07 ` [PATCH v4 " Tejun Heo
2013-11-28 6:05 ` Greg KH
2013-11-28 19:54 ` [PATCHSET PARTIAL REPOST driver-core-next] sysfs: separate out kernfs, take #3 Tejun Heo
2013-11-28 19:54 ` [PATCH 01/34] sysfs, kernfs: replace sysfs_dirent->s_dir.kobj and ->s_attr.[bin_]attr with ->priv Tejun Heo
2013-11-28 19:54 ` [PATCH 02/34] sysfs, kernfs: introduce kernfs_create_dir[_ns]() Tejun Heo
2013-11-28 19:54 ` [PATCH 03/34] sysfs, kernfs: prepare read path for kernfs Tejun Heo
2013-11-28 19:54 ` [PATCH 04/34] sysfs, kernfs: prepare write " Tejun Heo
2013-11-28 19:54 ` [PATCH 05/34] sysfs, kernfs: prepare mmap " Tejun Heo
2013-11-28 19:54 ` [PATCH 06/34] sysfs, kernfs: prepare open, release, poll paths " Tejun Heo
2013-11-28 19:54 ` [PATCH 07/34] sysfs, kernfs: move sysfs_open_file to include/linux/kernfs.h Tejun Heo
2013-11-28 19:54 ` [PATCH 08/34] sysfs, kernfs: introduce kernfs_ops Tejun Heo
2013-11-28 19:54 ` [PATCH 09/34] sysfs, kernfs: add sysfs_dirent->s_attr.size Tejun Heo
2013-11-28 19:54 ` [PATCH 10/34] sysfs, kernfs: remove SYSFS_KOBJ_BIN_ATTR Tejun Heo
2013-11-28 19:54 ` [PATCH 11/34] sysfs, kernfs: introduce kernfs_create_file[_ns]() Tejun Heo
2013-11-28 19:54 ` [PATCH 12/34] sysfs, kernfs: remove sysfs_add_one() Tejun Heo
2013-11-28 19:54 ` [PATCH 13/34] sysfs, kernfs: add kernfs_ops->seq_{start|next|stop}() Tejun Heo
2013-11-28 19:54 ` [PATCH 14/34] sysfs, kernfs: introduce kernfs_notify() Tejun Heo
2013-11-28 19:54 ` [PATCH 15/34] sysfs, kernfs: reorganize SYSFS_* constants Tejun Heo
2013-11-28 19:54 ` [PATCH 16/34] sysfs, kernfs: revamp sysfs_dirent active_ref lockdep annotation Tejun Heo
2013-11-28 19:54 ` [PATCH 17/34] sysfs, kernfs: introduce kernfs[_find_and]_get() and kernfs_put() Tejun Heo
2013-11-28 19:54 ` [PATCH 18/34] sysfs, kernfs: move internal decls to fs/kernfs/kernfs-internal.h Tejun Heo
2013-11-28 19:54 ` [PATCH 19/34] sysfs, kernfs: move inode code to fs/kernfs/inode.c Tejun Heo
2013-11-28 19:54 ` [PATCH 20/34] sysfs, kernfs: move dir core code to fs/kernfs/dir.c Tejun Heo
2013-11-28 19:54 ` [PATCH 21/34] sysfs, kernfs: move file core code to fs/kernfs/file.c Tejun Heo
2013-11-28 19:54 ` [PATCH 22/34] sysfs, kernfs: move symlink core code to fs/kernfs/symlink.c Tejun Heo
2013-11-28 19:54 ` [PATCH 23/34] sysfs, kernfs: drop unused params from sysfs_fill_super() Tejun Heo
2013-11-28 19:54 ` [PATCH 24/34] sysfs, kernfs: make sysfs_super_info->ns const Tejun Heo
2013-11-28 19:54 ` [PATCH 25/34] sysfs, kernfs: no need to kern_mount() sysfs from sysfs_init() Tejun Heo
2013-11-28 19:54 ` [PATCH 26/34] sysfs, kernfs: introduce sysfs_root_sd Tejun Heo
2013-11-28 19:54 ` [PATCH 27/34] sysfs, kernfs: implement kernfs_create/destroy_root() Tejun Heo
2013-11-28 19:54 ` [PATCH 28/34] sysfs, kernfs: make inode number ida per kernfs_root Tejun Heo
2013-11-28 19:54 ` [PATCH 29/34] sysfs, kernfs: make super_blocks bind to different kernfs_roots Tejun Heo
2013-11-28 19:54 ` [PATCH 30/34] sysfs, kernfs: prepare mount path for kernfs Tejun Heo
2013-11-28 19:54 ` [PATCH 31/34] sysfs, kernfs: move mount core code to fs/kernfs/mount.c Tejun Heo
2013-11-28 19:54 ` [PATCH 32/34] sysfs, kernfs: make sysfs_dirent definition public Tejun Heo
2013-11-29 22:18 ` Tejun Heo
2013-11-29 22:19 ` Tejun Heo
2013-11-28 19:54 ` [PATCH 33/34] sysfs, kernfs: implement kernfs_ns_enabled() Tejun Heo
2013-11-29 22:19 ` [PATCH v2 " Tejun Heo
2013-11-28 19:54 ` [PATCH 34/34] sysfs, kernfs: remove cross inclusions of internal headers Tejun Heo
2013-11-29 22:21 ` [PATCHSET PARTIAL REPOST driver-core-next] sysfs: separate out kernfs, take #3 Tejun Heo
2013-11-30 2:55 ` Greg KH
2013-11-30 13:05 ` Tejun Heo
2013-11-23 22:21 ` [PATCH 10/41] sysfs, kernfs: prepare read path for kernfs Tejun Heo
2013-11-23 22:21 ` [PATCH 11/41] sysfs, kernfs: prepare write " Tejun Heo
2013-11-23 22:21 ` [PATCH 12/41] sysfs, kernfs: prepare mmap " Tejun Heo
2013-11-23 22:21 ` [PATCH 13/41] sysfs, kernfs: prepare open, release, poll paths " Tejun Heo
2013-11-23 22:21 ` [PATCH 14/41] sysfs, kernfs: move sysfs_open_file to include/linux/kernfs.h Tejun Heo
2013-11-23 22:22 ` [PATCH 15/41] sysfs, kernfs: introduce kernfs_ops Tejun Heo
2013-11-23 22:22 ` [PATCH 16/41] sysfs, kernfs: add sysfs_dirent->s_attr.size Tejun Heo
2013-11-23 22:22 ` [PATCH 17/41] sysfs, kernfs: remove SYSFS_KOBJ_BIN_ATTR Tejun Heo
2013-11-23 22:22 ` [PATCH 18/41] sysfs, kernfs: introduce kernfs_create_file[_ns]() Tejun Heo
2013-11-23 22:22 ` [PATCH 19/41] sysfs, kernfs: remove sysfs_add_one() Tejun Heo
2013-11-23 22:22 ` [PATCH 20/41] sysfs, kernfs: add kernfs_ops->seq_{start|next|stop}() Tejun Heo
2013-11-23 22:22 ` [PATCH 21/41] sysfs, kernfs: introduce kernfs_notify() Tejun Heo
2013-11-23 22:22 ` [PATCH 22/41] sysfs, kernfs: reorganize SYSFS_* constants Tejun Heo
2013-11-23 22:22 ` [PATCH 23/41] sysfs, kernfs: revamp sysfs_dirent active_ref lockdep annotation Tejun Heo
2013-11-23 22:22 ` [PATCH 24/41] sysfs, kernfs: introduce kernfs[_find_and]_get() and kernfs_put() Tejun Heo
2013-11-23 22:22 ` [PATCH 25/41] sysfs, kernfs: move internal decls to fs/kernfs/kernfs-internal.h Tejun Heo
2013-11-23 22:22 ` [PATCH 26/41] sysfs, kernfs: move inode code to fs/kernfs/inode.c Tejun Heo
2013-11-23 22:22 ` [PATCH 27/41] sysfs, kernfs: move dir core code to fs/kernfs/dir.c Tejun Heo
2013-11-23 22:22 ` [PATCH 28/41] sysfs, kernfs: move file core code to fs/kernfs/file.c Tejun Heo
2013-11-23 22:22 ` [PATCH 29/41] sysfs, kernfs: move symlink core code to fs/kernfs/symlink.c Tejun Heo
2013-11-23 22:22 ` [PATCH 30/41] sysfs, kernfs: drop unused params from sysfs_fill_super() Tejun Heo
2013-11-23 22:22 ` [PATCH 31/41] sysfs, kernfs: make sysfs_super_info->ns const Tejun Heo
2013-11-23 22:22 ` [PATCH 32/41] sysfs, kernfs: no need to kern_mount() sysfs from sysfs_init() Tejun Heo
2013-11-23 22:22 ` [PATCH 33/41] sysfs, kernfs: introduce sysfs_root_sd Tejun Heo
2013-11-23 22:22 ` [PATCH 34/41] sysfs, kernfs: implement kernfs_create/destroy_root() Tejun Heo
2013-11-23 22:22 ` [PATCH 35/41] sysfs, kernfs: make inode number ida per kernfs_root Tejun Heo
2013-11-23 22:22 ` [PATCH 36/41] sysfs, kernfs: make super_blocks bind to different kernfs_roots Tejun Heo
2013-11-23 22:22 ` [PATCH 37/41] sysfs, kernfs: prepare mount path for kernfs Tejun Heo
2013-11-24 14:57 ` [PATCH REPOST " Tejun Heo
2013-11-23 22:22 ` [PATCH 38/41] sysfs, kernfs: move mount core code to fs/kernfs/mount.c Tejun Heo
2013-11-23 22:22 ` [PATCH 39/41] sysfs, kernfs: make sysfs_dirent definition public Tejun Heo
2013-11-23 22:22 ` [PATCH 40/41] sysfs, kernfs: implement kernfs_ns_enabled() Tejun Heo
2013-11-23 22:22 ` [PATCH 41/41] sysfs, kernfs: remove cross inclusions of internal headers Tejun Heo
2013-11-23 22:48 ` [PATCHSET driver-core-next] sysfs: separate out kernfs, take #3 Tejun Heo
2013-11-23 23:09 ` Tejun Heo
2013-11-24 9:16 ` Christoph Hellwig
2013-11-24 14:28 ` Tejun Heo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1385245346-856-9-git-send-email-tj@kernel.org \
--to=tj@kernel.org \
--cc=bhelgaas@google.com \
--cc=ebiederm@xmission.com \
--cc=gregkh@linuxfoundation.org \
--cc=kay@vrfy.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox