linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andreas Gruenbacher <andreas.gruenbacher@gmail.com>
To: Alexander Viro <viro@zeniv.linux.org.uk>,
	Christoph Hellwig <hch@infradead.org>,
	Eric Paris <eparis@redhat.com>,
	"Aneesh Kumar K.V" <aneesh.kumar@linux.vnet.ibm.com>,
	linux-fsdevel@vger.kernel.org,
	David Quigley <dpquigl@davequigley.com>,
	"J. Bruce Fields" <bfields@fieldses.org>
Cc: linux-security-module@vger.kernel.org, cluster-devel@redhat.com
Subject: [RFC 07/11] 9p: Stop using the generic xattr_handler infrastructure
Date: Thu, 20 Aug 2015 20:19:54 +0200	[thread overview]
Message-ID: <1440094798-1411-8-git-send-email-agruenba@redhat.com> (raw)
In-Reply-To: <1440094798-1411-1-git-send-email-agruenba@redhat.com>

Of all the file systems that use the generic xattr handler infrastructure, 9p
is the only one that needs dentries inside the xattr file system code.  Open
code the xattr handling code in 9p so that we can then convert the generic code
to pass down inodes instead of dentries; this actually takes only little
additional code.

Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com>
---
 fs/9p/acl.c       | 12 ++++++------
 fs/9p/vfs_super.c |  5 ++---
 fs/9p/xattr.c     | 46 ++++++++++++++++++++++++++++++++++++++--------
 fs/9p/xattr.h     | 15 ++++++++++++---
 4 files changed, 58 insertions(+), 20 deletions(-)

diff --git a/fs/9p/acl.c b/fs/9p/acl.c
index 5325304..d6a02e0 100644
--- a/fs/9p/acl.c
+++ b/fs/9p/acl.c
@@ -212,9 +212,9 @@ int v9fs_acl_mode(struct inode *dir, umode_t *modep,
 	return 0;
 }
 
-static int v9fs_xattr_get_acl(struct dentry *dentry, const char *name,
-			      void *buffer, size_t size,
-			      const struct xattr_handler *handler)
+static ssize_t v9fs_xattr_get_acl(struct dentry *dentry, const char *name,
+				  void *buffer, size_t size,
+				  const struct v9fs_xattr_handler *handler)
 {
 	struct v9fs_session_info *v9ses;
 	struct posix_acl *acl;
@@ -243,7 +243,7 @@ static int v9fs_xattr_get_acl(struct dentry *dentry, const char *name,
 
 static int v9fs_xattr_set_acl(struct dentry *dentry, const char *name,
 			      const void *value, size_t size,
-			      int flags, const struct xattr_handler *handler)
+			      int flags, const struct v9fs_xattr_handler *handler)
 {
 	int retval;
 	struct posix_acl *acl;
@@ -327,14 +327,14 @@ err_out:
 	return retval;
 }
 
-const struct xattr_handler v9fs_xattr_acl_access_handler = {
+const struct v9fs_xattr_handler v9fs_xattr_acl_access_handler = {
 	.prefix	= POSIX_ACL_XATTR_ACCESS,
 	.flags	= ACL_TYPE_ACCESS,
 	.get	= v9fs_xattr_get_acl,
 	.set	= v9fs_xattr_set_acl,
 };
 
-const struct xattr_handler v9fs_xattr_acl_default_handler = {
+const struct v9fs_xattr_handler v9fs_xattr_acl_default_handler = {
 	.prefix	= POSIX_ACL_XATTR_DEFAULT,
 	.flags	= ACL_TYPE_DEFAULT,
 	.get	= v9fs_xattr_get_acl,
diff --git a/fs/9p/vfs_super.c b/fs/9p/vfs_super.c
index bf495ce..7914544 100644
--- a/fs/9p/vfs_super.c
+++ b/fs/9p/vfs_super.c
@@ -80,10 +80,9 @@ v9fs_fill_super(struct super_block *sb, struct v9fs_session_info *v9ses,
 	sb->s_blocksize_bits = fls(v9ses->maxdata - 1);
 	sb->s_blocksize = 1 << sb->s_blocksize_bits;
 	sb->s_magic = V9FS_MAGIC;
-	if (v9fs_proto_dotl(v9ses)) {
+	if (v9fs_proto_dotl(v9ses))
 		sb->s_op = &v9fs_super_ops_dotl;
-		sb->s_xattr = v9fs_xattr_handlers;
-	} else
+	else
 		sb->s_op = &v9fs_super_ops;
 	sb->s_bdi = &v9ses->bdi;
 	if (v9ses->cache)
diff --git a/fs/9p/xattr.c b/fs/9p/xattr.c
index 00b28f4..64ffd00 100644
--- a/fs/9p/xattr.c
+++ b/fs/9p/xattr.c
@@ -132,14 +132,44 @@ int v9fs_fid_xattr_set(struct p9_fid *fid, const char *name,
 	return retval;
 }
 
+ssize_t v9fs_getxattr(struct dentry *dentry, const char *name, void *buffer, size_t size)
+{
+	const struct v9fs_xattr_handler **handlers = v9fs_xattr_handlers;
+
+	for (; *handlers != NULL; handlers++) {
+		const struct v9fs_xattr_handler *handler = *handlers;
+		const char *suffix = strcmp_prefix(name, handler->prefix);
+
+		if (suffix)
+			return handler->get(dentry, suffix, buffer, size, handler);
+	}
+	return -EOPNOTSUPP;
+}
+
+int v9fs_setxattr(struct dentry *dentry, const char *name, const void *value,
+		  size_t size, int flags)
+{
+	const struct v9fs_xattr_handler **handlers = v9fs_xattr_handlers;
+
+	for (; *handlers != NULL; handlers++) {
+		const struct v9fs_xattr_handler *handler = *handlers;
+		const char *suffix = strcmp_prefix(name, handler->prefix);
+
+		if (suffix)
+			return handler->set(dentry, name, value, size, flags,
+					    handler);
+	}
+	return -EOPNOTSUPP;
+}
+
 ssize_t v9fs_listxattr(struct dentry *dentry, char *buffer, size_t buffer_size)
 {
 	return v9fs_xattr_get(dentry, NULL, buffer, buffer_size);
 }
 
-static int v9fs_xattr_handler_get(struct dentry *dentry, const char *name,
-				  void *buffer, size_t size,
-				  const struct xattr_handler *handler)
+static ssize_t v9fs_xattr_handler_get(struct dentry *dentry, const char *name,
+				      void *buffer, size_t size,
+				      const struct v9fs_xattr_handler *handler)
 {
 	int prefix_len = strlen(handler->prefix);
 
@@ -150,7 +180,7 @@ static int v9fs_xattr_handler_get(struct dentry *dentry, const char *name,
 
 static int v9fs_xattr_handler_set(struct dentry *dentry, const char *name,
 				  const void *value, size_t size, int flags,
-				  const struct xattr_handler *handler)
+				  const struct v9fs_xattr_handler *handler)
 {
 	int prefix_len = strlen(handler->prefix);
 
@@ -159,27 +189,27 @@ static int v9fs_xattr_handler_set(struct dentry *dentry, const char *name,
 	return v9fs_xattr_set(dentry, name - prefix_len, value, size, flags);
 }
 
-static struct xattr_handler v9fs_xattr_user_handler = {
+static struct v9fs_xattr_handler v9fs_xattr_user_handler = {
 	.prefix	= XATTR_USER_PREFIX,
 	.get	= v9fs_xattr_handler_get,
 	.set	= v9fs_xattr_handler_set,
 };
 
-static struct xattr_handler v9fs_xattr_trusted_handler = {
+static struct v9fs_xattr_handler v9fs_xattr_trusted_handler = {
 	.prefix	= XATTR_TRUSTED_PREFIX,
 	.get	= v9fs_xattr_handler_get,
 	.set	= v9fs_xattr_handler_set,
 };
 
 #ifdef CONFIG_9P_FS_SECURITY
-static struct xattr_handler v9fs_xattr_security_handler = {
+static struct v9fs_xattr_handler v9fs_xattr_security_handler = {
 	.prefix	= XATTR_SECURITY_PREFIX,
 	.get	= v9fs_xattr_handler_get,
 	.set	= v9fs_xattr_handler_set,
 };
 #endif
 
-const struct xattr_handler *v9fs_xattr_handlers[] = {
+const struct v9fs_xattr_handler *v9fs_xattr_handlers[] = {
 	&v9fs_xattr_user_handler,
 	&v9fs_xattr_trusted_handler,
 #ifdef CONFIG_9P_FS_POSIX_ACL
diff --git a/fs/9p/xattr.h b/fs/9p/xattr.h
index c63c3be..488ad6d 100644
--- a/fs/9p/xattr.h
+++ b/fs/9p/xattr.h
@@ -18,9 +18,18 @@
 #include <net/9p/9p.h>
 #include <net/9p/client.h>
 
-extern const struct xattr_handler *v9fs_xattr_handlers[];
-extern const struct xattr_handler v9fs_xattr_acl_access_handler;
-extern const struct xattr_handler v9fs_xattr_acl_default_handler;
+struct v9fs_xattr_handler {
+	const char *prefix;
+	int flags;
+	ssize_t (*get)(struct dentry *, const char *, void *, size_t,
+		       const struct v9fs_xattr_handler *);
+	int (*set)(struct dentry *, const char *, const void *, size_t, int,
+		   const struct v9fs_xattr_handler *);
+};
+
+extern const struct v9fs_xattr_handler *v9fs_xattr_handlers[];
+extern const struct v9fs_xattr_handler v9fs_xattr_acl_access_handler;
+extern const struct v9fs_xattr_handler v9fs_xattr_acl_default_handler;
 
 extern ssize_t v9fs_fid_xattr_get(struct p9_fid *, const char *,
 				  void *, size_t);
-- 
2.4.3


  parent reply	other threads:[~2015-08-20 18:23 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-20 18:19 [RFC 00/11] Inode security label invalidation Andreas Gruenbacher
2015-08-20 18:19 ` [RFC 01/11] ubifs: Remove unused "security.*" xattr handler Andreas Gruenbacher
2015-08-20 18:19 ` [RFC 02/11] hfsplus: Remove unused xattr handler list operations Andreas Gruenbacher
2015-08-20 18:19 ` [RFC 03/11] 9p: Simplify the xattr handlers Andreas Gruenbacher
2015-08-20 18:19 ` [RFC 04/11] xattr handlers: Pass handler to operations instead of flags Andreas Gruenbacher
2015-08-20 18:19 ` [RFC 05/11] xattr handlers: Some simplifications Andreas Gruenbacher
2015-08-20 18:19 ` [RFC 06/11] lib: Move strcmp_prefix into string.c Andreas Gruenbacher
2015-08-20 18:19 ` Andreas Gruenbacher [this message]
2015-08-21  6:46   ` [RFC 07/11] 9p: Stop using the generic xattr_handler infrastructure Christoph Hellwig
2015-08-21  8:35     ` [Cluster-devel] " Steven Whitehouse
2015-08-20 18:19 ` [RFC 08/11] xattr: Pass inodes to xattr handlers instead of dentries Andreas Gruenbacher
2015-08-20 18:19 ` [RFC 09/11] vfs: Add igetxattr inode operation Andreas Gruenbacher
2015-08-21  6:48   ` Christoph Hellwig
2015-08-20 18:19 ` [RFC 10/11] selinux: Allow to invalidate an inode's security label Andreas Gruenbacher
2015-08-20 18:19 ` [RFC 11/11] gfs2: Invalide security labels of inodes that go invalid Andreas Gruenbacher
2015-08-21  6:49   ` Christoph Hellwig
2015-08-21  9:25     ` [Cluster-devel] " Andreas Gruenbacher
2015-08-24 17:42 ` [RFC 00/11] Inode security label invalidation Stephen Smalley
2015-08-24 19:13   ` Andreas Grünbacher
2015-08-24 20:47   ` Eric Paris

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=1440094798-1411-8-git-send-email-agruenba@redhat.com \
    --to=andreas.gruenbacher@gmail.com \
    --cc=aneesh.kumar@linux.vnet.ibm.com \
    --cc=bfields@fieldses.org \
    --cc=cluster-devel@redhat.com \
    --cc=dpquigl@davequigley.com \
    --cc=eparis@redhat.com \
    --cc=hch@infradead.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-security-module@vger.kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    /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;
as well as URLs for NNTP newsgroup(s).