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 6/8] nfsv4: Implement posix listxattr
Date: Wed, 2 Sep 2009 17:54:26 +0530 [thread overview]
Message-ID: <1251894268-1555-7-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 | 141 +++++++++++++++++++++++++++++++++++++++++++++++++++-
fs/nfs/nfs4proc.c | 4 ++
2 files changed, 142 insertions(+), 3 deletions(-)
diff --git a/fs/nfs/nfs4pacl.c b/fs/nfs/nfs4pacl.c
index c1c2b04..162f4c5 100644
--- a/fs/nfs/nfs4pacl.c
+++ b/fs/nfs/nfs4pacl.c
@@ -7,12 +7,132 @@
#include <linux/xattr.h>
#include "internal.h"
+#define NFSDBG_FACILITY NFSDBG_PROC
+
+struct posix_acl *nfs4_proc_getacl(struct inode *inode, int type)
+{
+ struct nfs_server *server = NFS_SERVER(inode);
+ struct nfs4_getpaclres res;
+ struct page *pages[NFSACL_MAXPAGES] = { };
+ struct nfs4_getpaclargs args = {
+ .fh = NFS_FH(inode),
+ /* The xdr layer may allocate pages here. */
+ .pages = pages,
+ };
+ struct rpc_message msg = {
+ .rpc_argp = &args,
+ .rpc_resp = &res,
+ };
+ struct posix_acl *acl;
+ int status, count;
+
+ memset(&res, 0, sizeof(struct nfs4_getpaclres));
+ if (!nfs_server_capable(inode, NFS_CAP_PACLS))
+ return ERR_PTR(-EOPNOTSUPP);
+
+ status = nfs_revalidate_inode(server, inode);
+ if (status < 0)
+ return ERR_PTR(status);
+ acl = get_cached_acl(inode, type);
+ if (acl != ACL_NOT_CACHED)
+ return acl;
+ acl = NULL;
+
+ /*
+ * Only get the access acl when explicitly requested: We don't
+ * need it for access decisions, and only some applications use
+ * it. Applications which request the access acl first are not
+ * penalized from this optimization.
+ */
+ if (type == ACL_TYPE_ACCESS)
+ args.mask |= NFS_ACLCNT|NFS_ACL;
+ if (S_ISDIR(inode->i_mode))
+ args.mask |= NFS_DFACLCNT|NFS_DFACL;
+ if (args.mask == 0)
+ return NULL;
+
+ dprintk("NFS4 call getacl\n");
+ msg.rpc_proc = &server->client_acl->cl_procinfo[NFSPROC4_CLNT_GETPACL];
+ status = rpc_call_sync(server->client_acl, &msg, 0);
+ dprintk("NFS4 reply getacl: %d\n", status);
+
+ /* pages may have been allocated at the xdr layer. */
+ for (count = 0; count < NFSACL_MAXPAGES && args.pages[count]; count++)
+ __free_page(args.pages[count]);
+
+ switch (status) {
+ case 0:
+ break;
+ case -EPFNOSUPPORT:
+ case -EPROTONOSUPPORT:
+ dprintk("NFS_V4_PACL extension not supported; disabling\n");
+ server->caps &= ~NFS_CAP_PACLS;
+ case -ENOTSUPP:
+ status = -EOPNOTSUPP;
+ default:
+ goto getout;
+ }
+ if ((args.mask & res.mask) != args.mask) {
+ status = -EIO;
+ goto getout;
+ }
+
+ if (res.acl_access != NULL) {
+ if (posix_acl_equiv_mode(res.acl_access, NULL) == 0) {
+ posix_acl_release(res.acl_access);
+ res.acl_access = NULL;
+ }
+ }
+ if (res.mask & NFS_ACL)
+ set_cached_acl(inode, type, res.acl_access);
+ if (res.mask & NFS_DFACL)
+ set_cached_acl(inode, type, res.acl_default);
+
+ switch (type) {
+ case ACL_TYPE_ACCESS:
+ acl = res.acl_access;
+ res.acl_access = NULL;
+ break;
+
+ case ACL_TYPE_DEFAULT:
+ acl = res.acl_default;
+ res.acl_default = NULL;
+ }
+
+getout:
+ posix_acl_release(res.acl_access);
+ posix_acl_release(res.acl_default);
+
+ if (status != 0) {
+ posix_acl_release(acl);
+ acl = ERR_PTR(status);
+ }
+ return acl;
+}
static size_t nfs4_xattr_list_pacl_default(struct inode *inode, char *list,
size_t list_len, const char *name,
size_t name_len)
{
- return 0;
+ int ret = 0;
+ struct posix_acl *acl;
+ size_t len = strlen(POSIX_ACL_XATTR_DEFAULT) + 1;
+
+ if (S_ISDIR(inode->i_mode)) {
+ acl = nfs4_proc_getacl(inode, ACL_TYPE_DEFAULT);
+ if (IS_ERR(acl))
+ return PTR_ERR(acl);
+ if (acl) {
+ if (list && len <= list_len) {
+ memcpy(list, POSIX_ACL_XATTR_DEFAULT, len);
+ ret = len;
+ } else
+ ret = -ERANGE;
+ posix_acl_release(acl);
+ }
+ return ret;
+ }
+ return ret;
}
static int nfs4_xattr_get_pacl_default(struct inode *inode, const char *key,
@@ -35,10 +155,25 @@ struct xattr_handler nfs4_xattr_pacl_default_handler = {
};
static size_t nfs4_xattr_list_pacl_access(struct inode *inode, char *list,
- size_t list_len, const char *name,
+ size_t list_len, const char *name,
size_t name_len)
{
- return 0;
+ int ret = 0;
+ struct posix_acl *acl;
+ size_t len = strlen(POSIX_ACL_XATTR_ACCESS) + 1;
+
+ acl = nfs4_proc_getacl(inode, ACL_TYPE_ACCESS);
+ if (IS_ERR(acl))
+ return PTR_ERR(acl);
+ if (acl) {
+ if (list && len <= list_len) {
+ memcpy(list, POSIX_ACL_XATTR_ACCESS, len);
+ ret = len;
+ } else
+ ret = -ERANGE;
+ posix_acl_release(acl);
+ }
+ return ret;
}
static int nfs4_xattr_get_pacl_access(struct inode *inode, const char *key,
diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c
index 2c71885..b2e8fe4 100644
--- a/fs/nfs/nfs4proc.c
+++ b/fs/nfs/nfs4proc.c
@@ -3120,6 +3120,10 @@ static void nfs4_set_cached_acl(struct inode *inode, struct nfs4_cached_acl *acl
static void nfs4_zap_acl_attr(struct inode *inode)
{
nfs4_set_cached_acl(inode, NULL);
+#ifdef CONFIG_NFS4_FS_POSIX_ACL
+ forget_cached_acl(inode, ACL_TYPE_DEFAULT);
+ forget_cached_acl(inode, ACL_TYPE_ACCESS);
+#endif
}
static inline ssize_t nfs4_read_cached_acl(struct inode *inode, char *buf, size_t buflen)
--
1.6.4.2.253.g0b1fac
next prev 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 ` Aneesh Kumar K.V [this message]
2009-09-02 12:24 ` [RFC PATCH 7/8] nfsv4: Implement getfacl Aneesh Kumar K.V
2009-09-02 12:24 ` [RFC PATCH 8/8] nfsv4: Implement setfacl Aneesh Kumar K.V
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-7-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