All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Serge E. Hallyn" <serue@us.ibm.com>
To: "Eric W. Biederman" <ebiederm@xmission.com>
Cc: Greg Kroah-Hartman <gregkh@suse.de>,
	Kay Sievers <kay.sievers@vrfy.org>, Greg KH <greg@kroah.com>,
	linux-kernel@vger.kernel.org, Tejun Heo <tj@kernel.org>,
	Cornelia Huck <cornelia.huck@de.ibm.com>,
	linux-fsdevel@vger.kernel.org,
	Eric Dumazet <eric.dumazet@gmail.com>,
	Benjamin LaHaise <bcrl@lhnet.ca>,
	"Eric W. Biederman" <ebiederm@aristanetworks.com>
Subject: Re: [PATCH 09/13] sysfs: Implement sysfs_getattr & sysfs_permission
Date: Tue, 3 Nov 2009 22:20:38 -0600	[thread overview]
Message-ID: <20091104042038.GE27639@us.ibm.com> (raw)
In-Reply-To: <1257249429-12384-9-git-send-email-ebiederm@xmission.com>

Quoting Eric W. Biederman (ebiederm@xmission.com):
> From: Eric W. Biederman <ebiederm@xmission.com>
> 
> With the implementation of sysfs_getattr and sysfs_permission
> sysfs becomes able to lazily propogate inode attribute changes
> from the sysfs_dirents to the vfs inodes.   This paves the way
> for deleting significant chunks of now unnecessary code.
>
> Acked-by: Tejun Heo <tj@kernel.org>
> Signed-off-by: Eric W. Biederman <ebiederm@aristanetworks.com>
> ---
>  fs/sysfs/dir.c     |    2 +
>  fs/sysfs/inode.c   |   64 ++++++++++++++++++++++++++++++++++++++-------------
>  fs/sysfs/symlink.c |    3 ++
>  fs/sysfs/sysfs.h   |    2 +
>  4 files changed, 54 insertions(+), 17 deletions(-)
> 
> diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
> index fa37126..25d052a 100644
> --- a/fs/sysfs/dir.c
> +++ b/fs/sysfs/dir.c
> @@ -800,7 +800,9 @@ static struct dentry * sysfs_lookup(struct inode *dir, struct dentry *dentry,
> 
>  const struct inode_operations sysfs_dir_inode_operations = {
>  	.lookup		= sysfs_lookup,
> +	.permission	= sysfs_permission,
>  	.setattr	= sysfs_setattr,
> +	.getattr	= sysfs_getattr,
>  	.setxattr	= sysfs_setxattr,
>  };
> 
> diff --git a/fs/sysfs/inode.c b/fs/sysfs/inode.c
> index fccfb55..2dcafe8 100644
> --- a/fs/sysfs/inode.c
> +++ b/fs/sysfs/inode.c
> @@ -37,7 +37,9 @@ static struct backing_dev_info sysfs_backing_dev_info = {
>  };
> 
>  static const struct inode_operations sysfs_inode_operations ={
> +	.permission	= sysfs_permission,
>  	.setattr	= sysfs_setattr,
> +	.getattr	= sysfs_getattr,
>  	.setxattr	= sysfs_setxattr,
>  };
> 
> @@ -196,7 +198,6 @@ static inline void set_default_inode_attr(struct inode * inode, mode_t mode)
> 
>  static inline void set_inode_attr(struct inode * inode, struct iattr * iattr)
>  {
> -	inode->i_mode = iattr->ia_mode;
>  	inode->i_uid = iattr->ia_uid;
>  	inode->i_gid = iattr->ia_gid;
>  	inode->i_atime = iattr->ia_atime;
> @@ -227,38 +228,56 @@ static int sysfs_count_nlink(struct sysfs_dirent *sd)
>  	return nr + 2;
>  }
> 
> +static void sysfs_refresh_inode(struct sysfs_dirent *sd, struct inode *inode)
> +{
> +	struct sysfs_inode_attrs *iattrs = sd->s_iattr;
> +
> +	inode->i_mode = sd->s_mode;
> +	if (iattrs) {
> +		/* sysfs_dirent has non-default attributes
> +		 * get them from persistent copy in sysfs_dirent
> +		 */
> +		set_inode_attr(inode, &iattrs->ia_iattr);
> +		security_inode_notifysecctx(inode,
> +					    iattrs->ia_secdata,
> +					    iattrs->ia_secdata_len);
> +	}
> +
> +	if (sysfs_type(sd) == SYSFS_DIR)
> +		inode->i_nlink = sysfs_count_nlink(sd);
> +}
> +
> +int sysfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
> +{
> +	struct sysfs_dirent *sd = dentry->d_fsdata;
> +	struct inode *inode = dentry->d_inode;
> +
> +	mutex_lock(&sysfs_mutex);
> +	sysfs_refresh_inode(sd, inode);
> +	mutex_unlock(&sysfs_mutex);

So the inode->i_mutex is not needed?

> +
> +	generic_fillattr(inode, stat);
> +	return 0;
> +}
> +
>  static void sysfs_init_inode(struct sysfs_dirent *sd, struct inode *inode)
>  {
>  	struct bin_attribute *bin_attr;
> -	struct sysfs_inode_attrs *iattrs;
> 
>  	inode->i_private = sysfs_get(sd);
>  	inode->i_mapping->a_ops = &sysfs_aops;
>  	inode->i_mapping->backing_dev_info = &sysfs_backing_dev_info;
>  	inode->i_op = &sysfs_inode_operations;
> -	inode->i_ino = sd->s_ino;
>  	lockdep_set_class(&inode->i_mutex, &sysfs_inode_imutex_key);
> 
> -	iattrs = sd->s_iattr;
> -	if (iattrs) {
> -		/* sysfs_dirent has non-default attributes
> -		 * get them for the new inode from persistent copy
> -		 * in sysfs_dirent
> -		 */
> -		set_inode_attr(inode, &iattrs->ia_iattr);
> -		if (iattrs->ia_secdata)
> -			security_inode_notifysecctx(inode,
> -						iattrs->ia_secdata,
> -						iattrs->ia_secdata_len);
> -	} else
> -		set_default_inode_attr(inode, sd->s_mode);
> +	set_default_inode_attr(inode, sd->s_mode);
> +	sysfs_refresh_inode(sd, inode);
> 
>  	/* initialize inode according to type */
>  	switch (sysfs_type(sd)) {
>  	case SYSFS_DIR:
>  		inode->i_op = &sysfs_dir_inode_operations;
>  		inode->i_fop = &sysfs_dir_operations;
> -		inode->i_nlink = sysfs_count_nlink(sd);
>  		break;
>  	case SYSFS_KOBJ_ATTR:
>  		inode->i_size = PAGE_SIZE;
> @@ -341,3 +360,14 @@ int sysfs_hash_and_remove(struct sysfs_dirent *dir_sd, const char *name)
>  	else
>  		return -ENOENT;
>  }
> +
> +int sysfs_permission(struct inode *inode, int mask)
> +{
> +	struct sysfs_dirent *sd = inode->i_private;
> +
> +	mutex_lock(&sysfs_mutex);
> +	sysfs_refresh_inode(sd, inode);
> +	mutex_unlock(&sysfs_mutex);
> +
> +	return generic_permission(inode, mask, NULL);
> +}
> diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
> index 1137418..c5eff49 100644
> --- a/fs/sysfs/symlink.c
> +++ b/fs/sysfs/symlink.c
> @@ -214,6 +214,9 @@ const struct inode_operations sysfs_symlink_inode_operations = {
>  	.readlink	= generic_readlink,
>  	.follow_link	= sysfs_follow_link,
>  	.put_link	= sysfs_put_link,
> +	.setattr	= sysfs_setattr,
> +	.getattr	= sysfs_getattr,
> +	.permission	= sysfs_permission,
>  };
> 
> 
> diff --git a/fs/sysfs/sysfs.h b/fs/sysfs/sysfs.h
> index a96d967..12ccc07 100644
> --- a/fs/sysfs/sysfs.h
> +++ b/fs/sysfs/sysfs.h
> @@ -156,7 +156,9 @@ static inline void __sysfs_put(struct sysfs_dirent *sd)
>  struct inode *sysfs_get_inode(struct sysfs_dirent *sd);
>  void sysfs_delete_inode(struct inode *inode);
>  int sysfs_sd_setattr(struct sysfs_dirent *sd, struct iattr *iattr);
> +int sysfs_permission(struct inode *inode, int mask);
>  int sysfs_setattr(struct dentry *dentry, struct iattr *iattr);
> +int sysfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
>  int sysfs_setxattr(struct dentry *dentry, const char *name, const void *value,
>  		size_t size, int flags);
>  int sysfs_hash_and_remove(struct sysfs_dirent *dir_sd, const char *name);
> -- 
> 1.6.5.2.143.g8cc62
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

  reply	other threads:[~2009-11-04  4:20 UTC|newest]

Thread overview: 92+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-11-03 11:53 [PATCH 0/13] sysfs lazification Eric W. Biederman
2009-11-03 11:56 ` [PATCH 01/13] sysfs: Update sysfs_setxattr so it updates secdata under the sysfs_mutex Eric W. Biederman
2009-11-03 13:48   ` Serge E. Hallyn
2009-11-03 21:09     ` Eric W. Biederman
2009-11-03 21:31       ` Serge E. Hallyn
2009-11-03 22:13         ` Eric W. Biederman
2009-11-07  2:27   ` Tejun Heo
2009-11-03 11:56 ` [PATCH 02/13] sysfs: Rename sysfs_d_iput to sysfs_dentry_iput Eric W. Biederman
2009-11-04  4:33   ` Serge E. Hallyn
2009-11-03 11:56 ` [PATCH 03/13] sysfs: Use dentry_ops instead of directly playing with the dcache Eric W. Biederman
2009-11-03 22:27   ` Serge E. Hallyn
2009-11-03 11:57 ` [PATCH 04/13] sysfs: Simplify sysfs_chmod_file semantics Eric W. Biederman
2009-11-04  2:43   ` Serge E. Hallyn
2009-11-04  3:42     ` Eric W. Biederman
2009-11-04  4:55       ` Serge E. Hallyn
2009-11-03 11:57 ` [PATCH 05/13] sysfs: Simplify iattr time assignments Eric W. Biederman
2009-11-04  2:57   ` Serge E. Hallyn
2009-11-03 11:57 ` [PATCH 06/13] sysfs: Fix locking and factor out sysfs_sd_setattr Eric W. Biederman
2009-11-04  3:16   ` Serge E. Hallyn
2009-11-04  3:49     ` Eric W. Biederman
2009-11-04 12:56       ` Eric W. Biederman
2009-11-03 11:57 ` [PATCH 07/13] sysfs: Update s_iattr on link and unlink Eric W. Biederman
2009-11-04  3:54   ` Serge E. Hallyn
2009-11-04  4:11     ` Eric W. Biederman
2009-11-04  4:58       ` Serge E. Hallyn
2009-11-03 11:57 ` [PATCH 08/13] sysfs: Nicely indent sysfs_symlink_inode_operations Eric W. Biederman
2009-11-04  4:33   ` Serge E. Hallyn
2009-11-03 11:57 ` [PATCH 09/13] sysfs: Implement sysfs_getattr & sysfs_permission Eric W. Biederman
2009-11-04  4:20   ` Serge E. Hallyn [this message]
2009-11-04  5:50     ` Eric W. Biederman
2009-11-04 14:24       ` Serge E. Hallyn
2009-11-07  2:06   ` Tejun Heo
2009-11-08  6:04     ` Eric W. Biederman
2009-11-03 11:57 ` [PATCH 10/13] sysfs: In sysfs_chmod_file lazily propagate the mode change Eric W. Biederman
2009-11-04  4:23   ` Serge E. Hallyn
2009-11-03 11:57 ` [PATCH 11/13] sysfs: Gut sysfs_addrm_start and sysfs_addrm_finish Eric W. Biederman
2009-11-04  4:32   ` Serge E. Hallyn
2009-11-07  2:08   ` Tejun Heo
2009-11-03 11:57 ` [PATCH 12/13] sysfs: Propagate renames to the vfs on demand Eric W. Biederman
2009-11-04 21:49   ` Serge E. Hallyn
2009-11-04 21:59     ` Eric W. Biederman
2009-11-07  2:11       ` Tejun Heo
2009-11-07  2:16         ` Eric W. Biederman
2009-11-07  2:20           ` Tejun Heo
2009-11-07  2:34             ` Eric W. Biederman
2009-11-07 11:12           ` Miklos Szeredi
2009-11-07 11:57             ` Eric W. Biederman
2009-11-09 14:14         ` Serge E. Hallyn
2009-11-09 22:34           ` Eric Biederman
2009-11-03 11:57 ` [PATCH 13/13] sysfs: Factor out sysfs_rename from sysfs_rename_dir and sysfs_move_dir Eric W. Biederman
2009-11-04 22:19   ` Serge E. Hallyn
2009-11-04 22:23     ` Eric W. Biederman
2009-11-04 22:37       ` Serge E. Hallyn
2009-11-05  4:51         ` Eric W. Biederman
2009-11-04 12:04 ` [PATCH 14/13] sysfs: sysfs_setattr remove unnecessary permission check Eric W. Biederman
2009-11-04 14:25   ` Serge E. Hallyn
2009-11-07  2:18   ` Tejun Heo
2009-11-04 12:05 ` [PATCH 15/13] sysfs: Protect sysfs_refresh_inode with inode mutex Eric W. Biederman
2009-11-04 14:27   ` Serge E. Hallyn
2009-11-04 20:51     ` Eric W. Biederman
2009-11-07  2:26   ` Tejun Heo
2009-11-08  7:04     ` Eric W. Biederman
2009-11-06 22:48 ` [PATCH 0/13] sysfs lazification Greg KH
2009-11-08  7:06   ` Eric W. Biederman
2009-11-17  9:11   ` Eric W. Biederman
2009-11-17 15:41     ` Greg KH
2009-11-17 15:56       ` Eric W. Biederman
2009-11-08  7:25 ` [PATCH 0/15] sysfs lazification final Eric W. Biederman
2009-11-08  7:26   ` [PATCH 01/15] sysfs: Update sysfs_setxattr so it updates secdata under the sysfs_mutex Eric W. Biederman
2009-11-08  7:27   ` [PATCH 02/15] sysfs: Rename sysfs_d_iput to sysfs_dentry_iput Eric W. Biederman
2009-11-08  7:27   ` [PATCH 03/15] sysfs: Use dentry_ops instead of directly playing with the dcache Eric W. Biederman
2009-11-08  7:27   ` [PATCH 04/15] sysfs: Simplify sysfs_chmod_file semantics Eric W. Biederman
2009-11-08  7:27   ` [PATCH 05/15] sysfs: Simplify iattr time assignments Eric W. Biederman
2009-11-08  7:27   ` [PATCH 06/15] sysfs: Fix locking and factor out sysfs_sd_setattr Eric W. Biederman
2009-11-09 14:26     ` Serge E. Hallyn
2009-11-20 20:13     ` Greg KH
2009-11-20 21:39       ` Eric W. Biederman
2009-11-21  0:07       ` Eric W. Biederman
2009-11-21  5:12         ` Greg KH
2009-11-08  7:27   ` [PATCH 07/15] sysfs: Update s_iattr on link and unlink Eric W. Biederman
2009-11-08  7:27   ` [PATCH 08/15] sysfs: Nicely indent sysfs_symlink_inode_operations Eric W. Biederman
2009-11-08  7:27   ` [PATCH 09/15] sysfs: Implement sysfs_getattr & sysfs_permission Eric W. Biederman
2009-11-08  7:27   ` [PATCH 10/15] sysfs: In sysfs_chmod_file lazily propagate the mode change Eric W. Biederman
2009-11-08  7:27   ` [PATCH 11/15] sysfs: Gut sysfs_addrm_start and sysfs_addrm_finish Eric W. Biederman
2009-11-08  7:27   ` [PATCH 12/15] sysfs: Propagate renames to the vfs on demand Eric W. Biederman
2009-11-08  7:27   ` [PATCH 13/15] sysfs: Factor out sysfs_rename from sysfs_rename_dir and sysfs_move_dir Eric W. Biederman
2009-11-08  7:27   ` [PATCH 14/15] sysfs: sysfs_setattr remove unnecessary permission check Eric W. Biederman
2009-11-08  7:27   ` [PATCH 15/15] sysfs: Protect sysfs_refresh_inode with inode mutex Eric W. Biederman
2009-11-09  3:57   ` [PATCH 0/15] sysfs lazification final Tejun Heo
2009-11-30 21:33   ` Greg KH
2009-11-30 21:53     ` Greg KH
2009-12-01  0:12       ` Eric W. Biederman

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=20091104042038.GE27639@us.ibm.com \
    --to=serue@us.ibm.com \
    --cc=bcrl@lhnet.ca \
    --cc=cornelia.huck@de.ibm.com \
    --cc=ebiederm@aristanetworks.com \
    --cc=ebiederm@xmission.com \
    --cc=eric.dumazet@gmail.com \
    --cc=greg@kroah.com \
    --cc=gregkh@suse.de \
    --cc=kay.sievers@vrfy.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tj@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.