public inbox for linux-nfs@vger.kernel.org
 help / color / mirror / Atom feed
From: "Aneesh Kumar K.V" <aneesh.kumar@linux.vnet.ibm.com>
To: trond.myklebust@netapp.com, bfields@fieldses.org,
	nfsv4@linux-nfs.org, ffilzlnx@us.ibm.com, agruen@suse.de,
	aneesh.kumar@linux.vnet.ibm.com, sfrench@us.ibm.com
Cc: linux-nfs@vger.kernel.org
Subject: [RFC PATCH 8/8] nfsv4: Implement setfacl
Date: Wed,  2 Sep 2009 17:54:28 +0530	[thread overview]
Message-ID: <1251894268-1555-9-git-send-email-aneesh.kumar@linux.vnet.ibm.com> (raw)
In-Reply-To: <1251894268-1555-1-git-send-email-aneesh.kumar@linux.vnet.ibm.com>

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
---
 fs/nfs/nfs4pacl.c |  140 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 138 insertions(+), 2 deletions(-)

diff --git a/fs/nfs/nfs4pacl.c b/fs/nfs/nfs4pacl.c
index a13a833..1978739 100644
--- a/fs/nfs/nfs4pacl.c
+++ b/fs/nfs/nfs4pacl.c
@@ -110,6 +110,124 @@ getout:
 	return acl;
 }
 
+static int nfs4_proc_setacls(struct inode *inode, struct posix_acl *acl,
+		  struct posix_acl *dfacl)
+{
+	struct nfs_server *server = NFS_SERVER(inode);
+	struct page *pages[NFSACL_MAXPAGES];
+	struct nfs4_setpaclargs args = {
+		.inode = inode,
+		.mask = NFS_ACL,
+		.acl_access = acl,
+		.pages = pages,
+	};
+	struct rpc_message msg = {
+		.rpc_argp	= &args,
+	};
+	int status;
+
+	status = -EOPNOTSUPP;
+	if (!nfs_server_capable(inode, NFS_CAP_PACLS))
+		goto out;
+
+	/* We are doing this here, because XDR marshalling can only
+	   return -ENOMEM. */
+	status = -ENOSPC;
+	if (acl != NULL && acl->a_count > NFS_ACL_MAX_ENTRIES)
+		goto out;
+	if (dfacl != NULL && dfacl->a_count > NFS_ACL_MAX_ENTRIES)
+		goto out;
+	if (S_ISDIR(inode->i_mode)) {
+		args.mask |= NFS_DFACL;
+		args.acl_default = dfacl;
+		args.len = nfsacl_size(acl, dfacl);
+	} else
+		args.len = nfsacl_size(acl, NULL);
+
+	if (args.len > NFS_ACL_INLINE_BUFSIZE) {
+		unsigned int npages = 1 + ((args.len - 1) >> PAGE_SHIFT);
+
+		status = -ENOMEM;
+		do {
+			args.pages[args.npages] = alloc_page(GFP_KERNEL);
+			if (args.pages[args.npages] == NULL)
+				goto out_freepages;
+			args.npages++;
+		} while (args.npages < npages);
+	}
+
+	dprintk("NFSV4 call setacl\n");
+	msg.rpc_proc = &server->client_acl->cl_procinfo[NFSPROC4_CLNT_SETPACL];
+	status = rpc_call_sync(server->client_acl, &msg, 0);
+	nfs_access_zap_cache(inode);
+	nfs_zap_acl_cache(inode);
+	dprintk("NFSv4 reply setacl: %d\n", status);
+
+	switch (status) {
+	case 0:
+		if (!IS_ERR(dfacl))
+			set_cached_acl(inode, ACL_TYPE_DEFAULT, dfacl);
+		if (!IS_ERR(acl))
+			set_cached_acl(inode, ACL_TYPE_ACCESS, acl);
+		break;
+	case -EPFNOSUPPORT:
+	case -EPROTONOSUPPORT:
+		dprintk("NFS_V4_PACL SETACL RPC not supported"
+				"(will not retry)\n");
+		server->caps &= ~NFS_CAP_PACLS;
+	case -ENOTSUPP:
+		status = -EOPNOTSUPP;
+	}
+out_freepages:
+	while (args.npages != 0) {
+		args.npages--;
+		__free_page(args.pages[args.npages]);
+	}
+out:
+	return status;
+}
+
+int nfs4_proc_setacl(struct inode *inode, int type, struct posix_acl *acl)
+{
+	int status;
+	struct posix_acl *alloc = NULL, *dfacl = NULL;
+
+	if (S_ISDIR(inode->i_mode)) {
+		switch (type) {
+		case ACL_TYPE_ACCESS:
+			alloc = dfacl = nfs4_proc_getacl(inode,
+						ACL_TYPE_DEFAULT);
+			if (IS_ERR(alloc))
+				goto fail;
+			break;
+
+		case ACL_TYPE_DEFAULT:
+			dfacl = acl;
+			alloc = acl = nfs4_proc_getacl(inode,
+						ACL_TYPE_ACCESS);
+			if (IS_ERR(alloc))
+				goto fail;
+			break;
+
+		default:
+			return -EINVAL;
+		}
+	} else if (type != ACL_TYPE_ACCESS)
+			return -EINVAL;
+
+	if (acl == NULL) {
+		alloc = acl = posix_acl_from_mode(inode->i_mode, GFP_KERNEL);
+		if (IS_ERR(alloc))
+			goto fail;
+	}
+	status = nfs4_proc_setacls(inode, acl, dfacl);
+	posix_acl_release(alloc);
+	return status;
+
+fail:
+	return PTR_ERR(alloc);
+}
+
 static size_t nfs4_xattr_list_pacl_default(struct inode *inode, char *list,
 				size_t list_len, const char *name,
 				size_t name_len)
@@ -159,7 +277,16 @@ static int nfs4_xattr_get_pacl_default(struct inode *inode, const char *key,
 static int nfs4_xattr_set_pacl_default(struct inode *inode, const char *key,
 			const void *buf, size_t buflen, int flags)
 {
-	return -EOPNOTSUPP;
+	int error;
+	struct posix_acl *acl;
+
+	acl = posix_acl_from_xattr(buf, buflen);
+	if (IS_ERR(acl))
+		return PTR_ERR(acl);
+	error = nfs4_proc_setacl(inode, ACL_TYPE_DEFAULT, acl);
+	posix_acl_release(acl);
+
+	return error;
 }
 
 struct xattr_handler nfs4_xattr_pacl_default_handler = {
@@ -212,7 +339,16 @@ static int nfs4_xattr_get_pacl_access(struct inode *inode, const char *key,
 static int nfs4_xattr_set_pacl_access(struct inode *inode, const char *key,
 			const void *buf, size_t buflen, int flags)
 {
-	return -EOPNOTSUPP;
+	int error;
+	struct posix_acl *acl;
+
+	acl = posix_acl_from_xattr(buf, buflen);
+	if (IS_ERR(acl))
+		return PTR_ERR(acl);
+	error = nfs4_proc_setacl(inode, ACL_TYPE_ACCESS, acl);
+	posix_acl_release(acl);
+
+	return error;
 }
 
 
-- 
1.6.4.2.253.g0b1fac


  parent reply	other threads:[~2009-09-02 12:25 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-09-02 12:24 POSIX ACL support for NFSV4 (using sideband protocol) Aneesh Kumar K.V
2009-09-02 12:24 ` [RFC PATCH 1/8] nfs4: Posix acl server side side-band protocol support Aneesh Kumar K.V
2009-09-02 12:24 ` [RFC PATCH 2/8] nfsv4: Switch to generic xattr handling code Aneesh Kumar K.V
2009-09-02 12:24 ` [RFC PATCH 3/8] nfsv4: Add support for posix ACL Aneesh Kumar K.V
2009-09-02 12:24 ` [RFC PATCH 4/8] nfs: use different capability flag for v4 and posix acl Aneesh Kumar K.V
2009-09-02 12:24 ` [RFC PATCH 5/8] nfsv4: Add nfsv4 rpc client side support Aneesh Kumar K.V
2009-09-02 12:24 ` [RFC PATCH 6/8] nfsv4: Implement posix listxattr Aneesh Kumar K.V
2009-09-02 12:24 ` [RFC PATCH 7/8] nfsv4: Implement getfacl Aneesh Kumar K.V
2009-09-02 12:24 ` Aneesh Kumar K.V [this message]
2009-09-02 16:42 ` POSIX ACL support for NFSV4 (using sideband protocol) J. Bruce Fields
2009-09-02 17:49   ` Aneesh Kumar K.V
2009-09-02 18:27     ` J. Bruce Fields
2009-09-03 19:09   ` Andreas Gruenbacher

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=1251894268-1555-9-git-send-email-aneesh.kumar@linux.vnet.ibm.com \
    --to=aneesh.kumar@linux.vnet.ibm.com \
    --cc=agruen@suse.de \
    --cc=bfields@fieldses.org \
    --cc=ffilzlnx@us.ibm.com \
    --cc=linux-nfs@vger.kernel.org \
    --cc=nfsv4@linux-nfs.org \
    --cc=sfrench@us.ibm.com \
    --cc=trond.myklebust@netapp.com \
    /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