nfsd4: remove unused deleg dprintk's.
[linux-2.6.git] / fs / nfsd / nfs4acl.c
index 11ebf6c..ad88f1c 100644 (file)
@@ -1,6 +1,4 @@
 /*
- *  fs/nfs4acl/acl.c
- *
  *  Common NFSv4 ACL handling code.
  *
  *  Copyright (c) 2002, 2003 The Regents of the University of Michigan.
  *  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#include <linux/string.h>
 #include <linux/slab.h>
-#include <linux/list.h>
-#include <linux/types.h>
-#include <linux/fs.h>
-#include <linux/module.h>
 #include <linux/nfs_fs.h>
-#include <linux/posix_acl.h>
-#include <linux/nfs4.h>
-#include <linux/nfs4_acl.h>
+#include "acl.h"
 
 
 /* mode bit translations: */
 
 /* flags used to simulate posix default ACLs */
 #define NFS4_INHERITANCE_FLAGS (NFS4_ACE_FILE_INHERIT_ACE \
-               | NFS4_ACE_DIRECTORY_INHERIT_ACE | NFS4_ACE_INHERIT_ONLY_ACE)
+               | NFS4_ACE_DIRECTORY_INHERIT_ACE)
+
+#define NFS4_SUPPORTED_FLAGS (NFS4_INHERITANCE_FLAGS \
+               | NFS4_ACE_INHERIT_ONLY_ACE \
+               | NFS4_ACE_IDENTIFIER_GROUP)
 
 #define MASK_EQUAL(mask1, mask2) \
        ( ((mask1) & NFS4_ACE_MASK_ALL) == ((mask2) & NFS4_ACE_MASK_ALL) )
@@ -85,35 +80,44 @@ mask_from_posix(unsigned short perm, unsigned int flags)
 }
 
 static u32
-deny_mask(u32 allow_mask, unsigned int flags)
+deny_mask_from_posix(unsigned short perm, u32 flags)
 {
-       u32 ret = ~allow_mask & ~NFS4_MASK_UNSUPP;
-       if (!(flags & NFS4_ACL_DIR))
-               ret &= ~NFS4_ACE_DELETE_CHILD;
-       return ret;
+       u32 mask = 0;
+
+       if (perm & ACL_READ)
+               mask |= NFS4_READ_MODE;
+       if (perm & ACL_WRITE)
+               mask |= NFS4_WRITE_MODE;
+       if ((perm & ACL_WRITE) && (flags & NFS4_ACL_DIR))
+               mask |= NFS4_ACE_DELETE_CHILD;
+       if (perm & ACL_EXECUTE)
+               mask |= NFS4_EXECUTE_MODE;
+       return mask;
 }
 
 /* XXX: modify functions to return NFS errors; they're only ever
  * used by nfs code, after all.... */
 
-static int
-mode_from_nfs4(u32 perm, unsigned short *mode, unsigned int flags)
+/* We only map from NFSv4 to POSIX ACLs when setting ACLs, when we err on the
+ * side of being more restrictive, so the mode bit mapping below is
+ * pessimistic.  An optimistic version would be needed to handle DENY's,
+ * but we espect to coalesce all ALLOWs and DENYs before mapping to mode
+ * bits. */
+
+static void
+low_mode_from_nfs4(u32 perm, unsigned short *mode, unsigned int flags)
 {
-       u32 ignore = 0;
+       u32 write_mode = NFS4_WRITE_MODE;
 
-       if (!(flags & NFS4_ACL_DIR))
-               ignore |= NFS4_ACE_DELETE_CHILD; /* ignore it */
-       perm |= ignore;
+       if (flags & NFS4_ACL_DIR)
+               write_mode |= NFS4_ACE_DELETE_CHILD;
        *mode = 0;
        if ((perm & NFS4_READ_MODE) == NFS4_READ_MODE)
                *mode |= ACL_READ;
-       if ((perm & NFS4_WRITE_MODE) == NFS4_WRITE_MODE)
+       if ((perm & write_mode) == write_mode)
                *mode |= ACL_WRITE;
        if ((perm & NFS4_EXECUTE_MODE) == NFS4_EXECUTE_MODE)
                *mode |= ACL_EXECUTE;
-       if (!MASK_EQUAL(perm, ignore|mask_from_posix(*mode, flags)))
-               return -EINVAL;
-       return 0;
 }
 
 struct ace_container {
@@ -122,108 +126,155 @@ struct ace_container {
 };
 
 static short ace2type(struct nfs4_ace *);
-static int _posix_to_nfsv4_one(struct posix_acl *, struct nfs4_acl *, unsigned int);
-static struct posix_acl *_nfsv4_to_posix_one(struct nfs4_acl *, unsigned int);
-int nfs4_acl_add_ace(struct nfs4_acl *, u32, u32, u32, int, uid_t);
-int nfs4_acl_split(struct nfs4_acl *, struct nfs4_acl *);
+static void _posix_to_nfsv4_one(struct posix_acl *, struct nfs4_acl *,
+                               unsigned int);
 
 struct nfs4_acl *
 nfs4_acl_posix_to_nfsv4(struct posix_acl *pacl, struct posix_acl *dpacl,
                        unsigned int flags)
 {
        struct nfs4_acl *acl;
-       int error = -EINVAL;
-
-       if ((pacl != NULL &&
-               (posix_acl_valid(pacl) < 0 || pacl->a_count == 0)) ||
-           (dpacl != NULL &&
-               (posix_acl_valid(dpacl) < 0 || dpacl->a_count == 0)))
-               goto out_err;
+       int size = 0;
 
-       acl = nfs4_acl_new();
-       if (acl == NULL) {
-               error = -ENOMEM;
-               goto out_err;
+       if (pacl) {
+               if (posix_acl_valid(pacl) < 0)
+                       return ERR_PTR(-EINVAL);
+               size += 2*pacl->a_count;
        }
-
-       if (pacl != NULL) {
-               error = _posix_to_nfsv4_one(pacl, acl,
-                                               flags & ~NFS4_ACL_TYPE_DEFAULT);
-               if (error < 0)
-                       goto out_acl;
+       if (dpacl) {
+               if (posix_acl_valid(dpacl) < 0)
+                       return ERR_PTR(-EINVAL);
+               size += 2*dpacl->a_count;
        }
 
-       if (dpacl != NULL) {
-               error = _posix_to_nfsv4_one(dpacl, acl,
-                                               flags | NFS4_ACL_TYPE_DEFAULT);
-               if (error < 0)
-                       goto out_acl;
-       }
+       /* Allocate for worst case: one (deny, allow) pair each: */
+       acl = nfs4_acl_new(size);
+       if (acl == NULL)
+               return ERR_PTR(-ENOMEM);
 
-       return acl;
+       if (pacl)
+               _posix_to_nfsv4_one(pacl, acl, flags & ~NFS4_ACL_TYPE_DEFAULT);
 
-out_acl:
-       nfs4_acl_free(acl);
-out_err:
-       acl = ERR_PTR(error);
+       if (dpacl)
+               _posix_to_nfsv4_one(dpacl, acl, flags | NFS4_ACL_TYPE_DEFAULT);
 
        return acl;
 }
 
-static int
-nfs4_acl_add_pair(struct nfs4_acl *acl, int eflag, u32 mask, int whotype,
-               uid_t owner, unsigned int flags)
+struct posix_acl_summary {
+       unsigned short owner;
+       unsigned short users;
+       unsigned short group;
+       unsigned short groups;
+       unsigned short other;
+       unsigned short mask;
+};
+
+static void
+summarize_posix_acl(struct posix_acl *acl, struct posix_acl_summary *pas)
 {
-       int error;
-
-       error = nfs4_acl_add_ace(acl, NFS4_ACE_ACCESS_ALLOWED_ACE_TYPE,
-                                eflag, mask, whotype, owner);
-       if (error < 0)
-               return error;
-       error = nfs4_acl_add_ace(acl, NFS4_ACE_ACCESS_DENIED_ACE_TYPE,
-                               eflag, deny_mask(mask, flags), whotype, owner);
-       return error;
+       struct posix_acl_entry *pa, *pe;
+
+       /*
+        * Only pas.users and pas.groups need initialization; previous
+        * posix_acl_valid() calls ensure that the other fields will be
+        * initialized in the following loop.  But, just to placate gcc:
+        */
+       memset(pas, 0, sizeof(*pas));
+       pas->mask = 07;
+
+       pe = acl->a_entries + acl->a_count;
+
+       FOREACH_ACL_ENTRY(pa, acl, pe) {
+               switch (pa->e_tag) {
+                       case ACL_USER_OBJ:
+                               pas->owner = pa->e_perm;
+                               break;
+                       case ACL_GROUP_OBJ:
+                               pas->group = pa->e_perm;
+                               break;
+                       case ACL_USER:
+                               pas->users |= pa->e_perm;
+                               break;
+                       case ACL_GROUP:
+                               pas->groups |= pa->e_perm;
+                               break;
+                       case ACL_OTHER:
+                               pas->other = pa->e_perm;
+                               break;
+                       case ACL_MASK:
+                               pas->mask = pa->e_perm;
+                               break;
+               }
+       }
+       /* We'll only care about effective permissions: */
+       pas->users &= pas->mask;
+       pas->group &= pas->mask;
+       pas->groups &= pas->mask;
 }
 
 /* We assume the acl has been verified with posix_acl_valid. */
-static int
+static void
 _posix_to_nfsv4_one(struct posix_acl *pacl, struct nfs4_acl *acl,
                                                unsigned int flags)
 {
-       struct posix_acl_entry *pa, *pe, *group_owner_entry;
-       int error = -EINVAL;
-       u32 mask, mask_mask;
+       struct posix_acl_entry *pa, *group_owner_entry;
+       struct nfs4_ace *ace;
+       struct posix_acl_summary pas;
+       unsigned short deny;
        int eflag = ((flags & NFS4_ACL_TYPE_DEFAULT) ?
-                                       NFS4_INHERITANCE_FLAGS : 0);
+               NFS4_INHERITANCE_FLAGS | NFS4_ACE_INHERIT_ONLY_ACE : 0);
 
        BUG_ON(pacl->a_count < 3);
-       pe = pacl->a_entries + pacl->a_count;
-       pa = pe - 2; /* if mask entry exists, it's second from the last. */
-       if (pa->e_tag == ACL_MASK)
-               mask_mask = deny_mask(mask_from_posix(pa->e_perm, flags), flags);
-       else
-               mask_mask = 0;
+       summarize_posix_acl(pacl, &pas);
 
        pa = pacl->a_entries;
-       BUG_ON(pa->e_tag != ACL_USER_OBJ);
-       mask = mask_from_posix(pa->e_perm, flags | NFS4_ACL_OWNER);
-       error = nfs4_acl_add_pair(acl, eflag, mask, NFS4_ACL_WHO_OWNER, 0, flags);
-       if (error < 0)
-               goto out;
+       ace = acl->aces + acl->naces;
+
+       /* We could deny everything not granted by the owner: */
+       deny = ~pas.owner;
+       /*
+        * but it is equivalent (and simpler) to deny only what is not
+        * granted by later entries:
+        */
+       deny &= pas.users | pas.group | pas.groups | pas.other;
+       if (deny) {
+               ace->type = NFS4_ACE_ACCESS_DENIED_ACE_TYPE;
+               ace->flag = eflag;
+               ace->access_mask = deny_mask_from_posix(deny, flags);
+               ace->whotype = NFS4_ACL_WHO_OWNER;
+               ace++;
+               acl->naces++;
+       }
+
+       ace->type = NFS4_ACE_ACCESS_ALLOWED_ACE_TYPE;
+       ace->flag = eflag;
+       ace->access_mask = mask_from_posix(pa->e_perm, flags | NFS4_ACL_OWNER);
+       ace->whotype = NFS4_ACL_WHO_OWNER;
+       ace++;
+       acl->naces++;
        pa++;
 
        while (pa->e_tag == ACL_USER) {
-               mask = mask_from_posix(pa->e_perm, flags);
-               error = nfs4_acl_add_ace(acl, NFS4_ACE_ACCESS_DENIED_ACE_TYPE,
-                               eflag,  mask_mask, NFS4_ACL_WHO_NAMED, pa->e_id);
-               if (error < 0)
-                       goto out;
-
-
-               error = nfs4_acl_add_pair(acl, eflag, mask,
-                               NFS4_ACL_WHO_NAMED, pa->e_id, flags);
-               if (error < 0)
-                       goto out;
+               deny = ~(pa->e_perm & pas.mask);
+               deny &= pas.groups | pas.group | pas.other;
+               if (deny) {
+                       ace->type = NFS4_ACE_ACCESS_DENIED_ACE_TYPE;
+                       ace->flag = eflag;
+                       ace->access_mask = deny_mask_from_posix(deny, flags);
+                       ace->whotype = NFS4_ACL_WHO_NAMED;
+                       ace->who = pa->e_id;
+                       ace++;
+                       acl->naces++;
+               }
+               ace->type = NFS4_ACE_ACCESS_ALLOWED_ACE_TYPE;
+               ace->flag = eflag;
+               ace->access_mask = mask_from_posix(pa->e_perm & pas.mask,
+                                                  flags);
+               ace->whotype = NFS4_ACL_WHO_NAMED;
+               ace->who = pa->e_id;
+               ace++;
+               acl->naces++;
                pa++;
        }
 
@@ -232,67 +283,65 @@ _posix_to_nfsv4_one(struct posix_acl *pacl, struct nfs4_acl *acl,
 
        /* allow ACEs */
 
-       if (pacl->a_count > 3) {
-               BUG_ON(pa->e_tag != ACL_GROUP_OBJ);
-               error = nfs4_acl_add_ace(acl, NFS4_ACE_ACCESS_DENIED_ACE_TYPE,
-                               NFS4_ACE_IDENTIFIER_GROUP | eflag, mask_mask,
-                               NFS4_ACL_WHO_GROUP, 0);
-               if (error < 0)
-                       goto out;
-       }
        group_owner_entry = pa;
-       mask = mask_from_posix(pa->e_perm, flags);
-       error = nfs4_acl_add_ace(acl, NFS4_ACE_ACCESS_ALLOWED_ACE_TYPE,
-                       NFS4_ACE_IDENTIFIER_GROUP | eflag, mask,
-                       NFS4_ACL_WHO_GROUP, 0);
-       if (error < 0)
-               goto out;
+
+       ace->type = NFS4_ACE_ACCESS_ALLOWED_ACE_TYPE;
+       ace->flag = eflag;
+       ace->access_mask = mask_from_posix(pas.group, flags);
+       ace->whotype = NFS4_ACL_WHO_GROUP;
+       ace++;
+       acl->naces++;
        pa++;
 
        while (pa->e_tag == ACL_GROUP) {
-               mask = mask_from_posix(pa->e_perm, flags);
-               error = nfs4_acl_add_ace(acl, NFS4_ACE_ACCESS_DENIED_ACE_TYPE,
-                               NFS4_ACE_IDENTIFIER_GROUP | eflag, mask_mask,
-                               NFS4_ACL_WHO_NAMED, pa->e_id);
-               if (error < 0)
-                       goto out;
-
-               error = nfs4_acl_add_ace(acl, NFS4_ACE_ACCESS_ALLOWED_ACE_TYPE,
-                               NFS4_ACE_IDENTIFIER_GROUP | eflag, mask,
-                               NFS4_ACL_WHO_NAMED, pa->e_id);
-               if (error < 0)
-                       goto out;
+               ace->type = NFS4_ACE_ACCESS_ALLOWED_ACE_TYPE;
+               ace->flag = eflag | NFS4_ACE_IDENTIFIER_GROUP;
+               ace->access_mask = mask_from_posix(pa->e_perm & pas.mask,
+                                                  flags);
+               ace->whotype = NFS4_ACL_WHO_NAMED;
+               ace->who = pa->e_id;
+               ace++;
+               acl->naces++;
                pa++;
        }
 
        /* deny ACEs */
 
        pa = group_owner_entry;
-       mask = mask_from_posix(pa->e_perm, flags);
-       error = nfs4_acl_add_ace(acl, NFS4_ACE_ACCESS_DENIED_ACE_TYPE,
-                       NFS4_ACE_IDENTIFIER_GROUP | eflag,
-                       deny_mask(mask, flags), NFS4_ACL_WHO_GROUP, 0);
-       if (error < 0)
-               goto out;
+
+       deny = ~pas.group & pas.other;
+       if (deny) {
+               ace->type = NFS4_ACE_ACCESS_DENIED_ACE_TYPE;
+               ace->flag = eflag;
+               ace->access_mask = deny_mask_from_posix(deny, flags);
+               ace->whotype = NFS4_ACL_WHO_GROUP;
+               ace++;
+               acl->naces++;
+       }
        pa++;
+
        while (pa->e_tag == ACL_GROUP) {
-               mask = mask_from_posix(pa->e_perm, flags);
-               error = nfs4_acl_add_ace(acl, NFS4_ACE_ACCESS_DENIED_ACE_TYPE,
-                               NFS4_ACE_IDENTIFIER_GROUP | eflag,
-                               deny_mask(mask, flags), NFS4_ACL_WHO_NAMED, pa->e_id);
-               if (error < 0)
-                       goto out;
+               deny = ~(pa->e_perm & pas.mask);
+               deny &= pas.other;
+               if (deny) {
+                       ace->type = NFS4_ACE_ACCESS_DENIED_ACE_TYPE;
+                       ace->flag = eflag | NFS4_ACE_IDENTIFIER_GROUP;
+                       ace->access_mask = deny_mask_from_posix(deny, flags);
+                       ace->whotype = NFS4_ACL_WHO_NAMED;
+                       ace->who = pa->e_id;
+                       ace++;
+                       acl->naces++;
+               }
                pa++;
        }
 
        if (pa->e_tag == ACL_MASK)
                pa++;
-       BUG_ON(pa->e_tag != ACL_OTHER);
-       mask = mask_from_posix(pa->e_perm, flags);
-       error = nfs4_acl_add_pair(acl, eflag, mask, NFS4_ACL_WHO_EVERYONE, 0, flags);
-
-out:
-       return error;
+       ace->type = NFS4_ACE_ACCESS_ALLOWED_ACE_TYPE;
+       ace->flag = eflag;
+       ace->access_mask = mask_from_posix(pa->e_perm, flags);
+       ace->whotype = NFS4_ACL_WHO_EVERYONE;
+       acl->naces++;
 }
 
 static void
@@ -331,476 +380,374 @@ sort_pacl(struct posix_acl *pacl)
        sort_pacl_range(pacl, 1, i-1);
 
        BUG_ON(pacl->a_entries[i].e_tag != ACL_GROUP_OBJ);
-       j = i++;
+       j = ++i;
        while (pacl->a_entries[j].e_tag == ACL_GROUP)
                j++;
        sort_pacl_range(pacl, i, j-1);
        return;
 }
 
-static int
-write_pace(struct nfs4_ace *ace, struct posix_acl *pacl,
-               struct posix_acl_entry **pace, short tag, unsigned int flags)
-{
-       struct posix_acl_entry *this = *pace;
-
-       if (*pace == pacl->a_entries + pacl->a_count)
-               return -EINVAL; /* fell off the end */
-       (*pace)++;
-       this->e_tag = tag;
-       if (tag == ACL_USER_OBJ)
-               flags |= NFS4_ACL_OWNER;
-       if (mode_from_nfs4(ace->access_mask, &this->e_perm, flags))
-               return -EINVAL;
-       this->e_id = (tag == ACL_USER || tag == ACL_GROUP ?
-                       ace->who : ACL_UNDEFINED_ID);
-       return 0;
-}
+/*
+ * While processing the NFSv4 ACE, this maintains bitmasks representing
+ * which permission bits have been allowed and which denied to a given
+ * entity: */
+struct posix_ace_state {
+       u32 allow;
+       u32 deny;
+};
 
-static struct nfs4_ace *
-get_next_v4_ace(struct list_head **p, struct list_head *head)
-{
-       struct nfs4_ace *ace;
+struct posix_user_ace_state {
+       uid_t uid;
+       struct posix_ace_state perms;
+};
 
-       *p = (*p)->next;
-       if (*p == head)
-               return NULL;
-       ace = list_entry(*p, struct nfs4_ace, l_ace);
+struct posix_ace_state_array {
+       int n;
+       struct posix_user_ace_state aces[];
+};
 
-       return ace;
-}
+/*
+ * While processing the NFSv4 ACE, this maintains the partial permissions
+ * calculated so far: */
+
+struct posix_acl_state {
+       int empty;
+       struct posix_ace_state owner;
+       struct posix_ace_state group;
+       struct posix_ace_state other;
+       struct posix_ace_state everyone;
+       struct posix_ace_state mask; /* Deny unused in this case */
+       struct posix_ace_state_array *users;
+       struct posix_ace_state_array *groups;
+};
 
-int
-nfs4_acl_nfsv4_to_posix(struct nfs4_acl *acl, struct posix_acl **pacl,
-               struct posix_acl **dpacl, unsigned int flags)
+static int
+init_state(struct posix_acl_state *state, int cnt)
 {
-       struct nfs4_acl *dacl;
-       int error = -ENOMEM;
-
-       *pacl = NULL;
-       *dpacl = NULL;
-
-       dacl = nfs4_acl_new();
-       if (dacl == NULL)
-               goto out;
-
-       error = nfs4_acl_split(acl, dacl);
-       if (error < 0)
-               goto out_acl;
-
-       if (pacl != NULL) {
-               if (acl->naces == 0) {
-                       error = -ENODATA;
-                       goto try_dpacl;
-               }
-
-               *pacl = _nfsv4_to_posix_one(acl, flags);
-               if (IS_ERR(*pacl)) {
-                       error = PTR_ERR(*pacl);
-                       *pacl = NULL;
-                       goto out_acl;
-               }
+       int alloc;
+
+       memset(state, 0, sizeof(struct posix_acl_state));
+       state->empty = 1;
+       /*
+        * In the worst case, each individual acl could be for a distinct
+        * named user or group, but we don't no which, so we allocate
+        * enough space for either:
+        */
+       alloc = sizeof(struct posix_ace_state_array)
+               + cnt*sizeof(struct posix_user_ace_state);
+       state->users = kzalloc(alloc, GFP_KERNEL);
+       if (!state->users)
+               return -ENOMEM;
+       state->groups = kzalloc(alloc, GFP_KERNEL);
+       if (!state->groups) {
+               kfree(state->users);
+               return -ENOMEM;
        }
-
-try_dpacl:
-       if (dpacl != NULL) {
-               if (dacl->naces == 0) {
-                       if (pacl == NULL || *pacl == NULL)
-                               error = -ENODATA;
-                       goto out_acl;
-               }
-
-               error = 0;
-               *dpacl = _nfsv4_to_posix_one(dacl, flags);
-               if (IS_ERR(*dpacl)) {
-                       error = PTR_ERR(*dpacl);
-                       *dpacl = NULL;
-                       goto out_acl;
-               }
-       }
-
-out_acl:
-       if (error && pacl) {
-               posix_acl_release(*pacl);
-               *pacl = NULL;
-       }
-       nfs4_acl_free(dacl);
-out:
-       return error;
+       return 0;
 }
 
-static int
-same_who(struct nfs4_ace *a, struct nfs4_ace *b)
-{
-       return a->whotype == b->whotype &&
-               (a->whotype != NFS4_ACL_WHO_NAMED || a->who == b->who);
+static void
+free_state(struct posix_acl_state *state) {
+       kfree(state->users);
+       kfree(state->groups);
 }
 
-static int
-complementary_ace_pair(struct nfs4_ace *allow, struct nfs4_ace *deny,
-               unsigned int flags)
+static inline void add_to_mask(struct posix_acl_state *state, struct posix_ace_state *astate)
 {
-       int ignore = 0;
-       if (!(flags & NFS4_ACL_DIR))
-               ignore |= NFS4_ACE_DELETE_CHILD;
-       return MASK_EQUAL(ignore|deny_mask(allow->access_mask, flags),
-                         ignore|deny->access_mask) &&
-               allow->type == NFS4_ACE_ACCESS_ALLOWED_ACE_TYPE &&
-               deny->type == NFS4_ACE_ACCESS_DENIED_ACE_TYPE &&
-               allow->flag == deny->flag &&
-               same_who(allow, deny);
+       state->mask.allow |= astate->allow;
 }
 
-static inline int
-user_obj_from_v4(struct nfs4_acl *n4acl, struct list_head **p,
-               struct posix_acl *pacl, struct posix_acl_entry **pace,
-               unsigned int flags)
-{
-       int error = -EINVAL;
-       struct nfs4_ace *ace, *ace2;
-
-       ace = get_next_v4_ace(p, &n4acl->ace_head);
-       if (ace == NULL)
-               goto out;
-       if (ace2type(ace) != ACL_USER_OBJ)
-               goto out;
-       error = write_pace(ace, pacl, pace, ACL_USER_OBJ, flags);
-       if (error < 0)
-               goto out;
-       error = -EINVAL;
-       ace2 = get_next_v4_ace(p, &n4acl->ace_head);
-       if (ace2 == NULL)
-               goto out;
-       if (!complementary_ace_pair(ace, ace2, flags))
-               goto out;
-       error = 0;
-out:
-       return error;
-}
+/*
+ * Certain bits (SYNCHRONIZE, DELETE, WRITE_OWNER, READ/WRITE_NAMED_ATTRS,
+ * READ_ATTRIBUTES, READ_ACL) are currently unenforceable and don't translate
+ * to traditional read/write/execute permissions.
+ *
+ * It's problematic to reject acls that use certain mode bits, because it
+ * places the burden on users to learn the rules about which bits one
+ * particular server sets, without giving the user a lot of help--we return an
+ * error that could mean any number of different things.  To make matters
+ * worse, the problematic bits might be introduced by some application that's
+ * automatically mapping from some other acl model.
+ *
+ * So wherever possible we accept anything, possibly erring on the side of
+ * denying more permissions than necessary.
+ *
+ * However we do reject *explicit* DENY's of a few bits representing
+ * permissions we could never deny:
+ */
 
-static inline int
-users_from_v4(struct nfs4_acl *n4acl, struct list_head **p,
-               struct nfs4_ace **mask_ace,
-               struct posix_acl *pacl, struct posix_acl_entry **pace,
-               unsigned int flags)
+static inline int check_deny(u32 mask, int isowner)
 {
-       int error = -EINVAL;
-       struct nfs4_ace *ace, *ace2;
-
-       ace = get_next_v4_ace(p, &n4acl->ace_head);
-       if (ace == NULL)
-               goto out;
-       while (ace2type(ace) == ACL_USER) {
-               if (ace->type != NFS4_ACE_ACCESS_DENIED_ACE_TYPE)
-                       goto out;
-               if (*mask_ace &&
-                       !MASK_EQUAL(ace->access_mask, (*mask_ace)->access_mask))
-                       goto out;
-               *mask_ace = ace;
-               ace = get_next_v4_ace(p, &n4acl->ace_head);
-               if (ace == NULL)
-                       goto out;
-               if (ace->type != NFS4_ACE_ACCESS_ALLOWED_ACE_TYPE)
-                       goto out;
-               error = write_pace(ace, pacl, pace, ACL_USER, flags);
-               if (error < 0)
-                       goto out;
-               error = -EINVAL;
-               ace2 = get_next_v4_ace(p, &n4acl->ace_head);
-               if (ace2 == NULL)
-                       goto out;
-               if (!complementary_ace_pair(ace, ace2, flags))
-                       goto out;
-               if ((*mask_ace)->flag != ace2->flag ||
-                               !same_who(*mask_ace, ace2))
-                       goto out;
-               ace = get_next_v4_ace(p, &n4acl->ace_head);
-               if (ace == NULL)
-                       goto out;
-       }
-       error = 0;
-out:
-       return error;
+       if (mask & (NFS4_ACE_READ_ATTRIBUTES | NFS4_ACE_READ_ACL))
+               return -EINVAL;
+       if (!isowner)
+               return 0;
+       if (mask & (NFS4_ACE_WRITE_ATTRIBUTES | NFS4_ACE_WRITE_ACL))
+               return -EINVAL;
+       return 0;
 }
 
-static inline int
-group_obj_and_groups_from_v4(struct nfs4_acl *n4acl, struct list_head **p,
-               struct nfs4_ace **mask_ace,
-               struct posix_acl *pacl, struct posix_acl_entry **pace,
-               unsigned int flags)
+static struct posix_acl *
+posix_state_to_acl(struct posix_acl_state *state, unsigned int flags)
 {
-       int error = -EINVAL;
-       struct nfs4_ace *ace, *ace2;
-       struct ace_container *ac;
-       struct list_head group_l;
-
-       INIT_LIST_HEAD(&group_l);
-       ace = list_entry(*p, struct nfs4_ace, l_ace);
-
-       /* group owner (mask and allow aces) */
-
-       if (pacl->a_count != 3) {
-               /* then the group owner should be preceded by mask */
-               if (ace->type != NFS4_ACE_ACCESS_DENIED_ACE_TYPE)
-                       goto out;
-               if (*mask_ace &&
-                       !MASK_EQUAL(ace->access_mask, (*mask_ace)->access_mask))
-                       goto out;
-               *mask_ace = ace;
-               ace = get_next_v4_ace(p, &n4acl->ace_head);
-               if (ace == NULL)
-                       goto out;
-
-               if ((*mask_ace)->flag != ace->flag || !same_who(*mask_ace, ace))
-                       goto out;
+       struct posix_acl_entry *pace;
+       struct posix_acl *pacl;
+       int nace;
+       int i, error = 0;
+
+       /*
+        * ACLs with no ACEs are treated differently in the inheritable
+        * and effective cases: when there are no inheritable ACEs, we
+        * set a zero-length default posix acl:
+        */
+       if (state->empty && (flags & NFS4_ACL_TYPE_DEFAULT)) {
+               pacl = posix_acl_alloc(0, GFP_KERNEL);
+               return pacl ? pacl : ERR_PTR(-ENOMEM);
        }
+       /*
+        * When there are no effective ACEs, the following will end
+        * up setting a 3-element effective posix ACL with all
+        * permissions zero.
+        */
+       nace = 4 + state->users->n + state->groups->n;
+       pacl = posix_acl_alloc(nace, GFP_KERNEL);
+       if (!pacl)
+               return ERR_PTR(-ENOMEM);
 
-       if (ace2type(ace) != ACL_GROUP_OBJ)
-               goto out;
-
-       ac = kmalloc(sizeof(*ac), GFP_KERNEL);
-       error = -ENOMEM;
-       if (ac == NULL)
-               goto out;
-       ac->ace = ace;
-       list_add_tail(&ac->ace_l, &group_l);
-
-       error = -EINVAL;
-       if (ace->type != NFS4_ACE_ACCESS_ALLOWED_ACE_TYPE)
-               goto out;
-
-       error = write_pace(ace, pacl, pace, ACL_GROUP_OBJ, flags);
-       if (error < 0)
-               goto out;
-
-       error = -EINVAL;
-       ace = get_next_v4_ace(p, &n4acl->ace_head);
-       if (ace == NULL)
-               goto out;
-
-       /* groups (mask and allow aces) */
-
-       while (ace2type(ace) == ACL_GROUP) {
-               if (*mask_ace == NULL)
-                       goto out;
-
-               if (ace->type != NFS4_ACE_ACCESS_DENIED_ACE_TYPE ||
-                       !MASK_EQUAL(ace->access_mask, (*mask_ace)->access_mask))
-                       goto out;
-               *mask_ace = ace;
-
-               ace = get_next_v4_ace(p, &n4acl->ace_head);
-               if (ace == NULL)
-                       goto out;
-               ac = kmalloc(sizeof(*ac), GFP_KERNEL);
-               error = -ENOMEM;
-               if (ac == NULL)
-                       goto out;
-               error = -EINVAL;
-               if (ace->type != NFS4_ACE_ACCESS_ALLOWED_ACE_TYPE ||
-                               !same_who(ace, *mask_ace))
-                       goto out;
-
-               ac->ace = ace;
-               list_add_tail(&ac->ace_l, &group_l);
-
-               error = write_pace(ace, pacl, pace, ACL_GROUP, flags);
-               if (error < 0)
-                       goto out;
-               error = -EINVAL;
-               ace = get_next_v4_ace(p, &n4acl->ace_head);
-               if (ace == NULL)
-                       goto out;
+       pace = pacl->a_entries;
+       pace->e_tag = ACL_USER_OBJ;
+       error = check_deny(state->owner.deny, 1);
+       if (error)
+               goto out_err;
+       low_mode_from_nfs4(state->owner.allow, &pace->e_perm, flags);
+       pace->e_id = ACL_UNDEFINED_ID;
+
+       for (i=0; i < state->users->n; i++) {
+               pace++;
+               pace->e_tag = ACL_USER;
+               error = check_deny(state->users->aces[i].perms.deny, 0);
+               if (error)
+                       goto out_err;
+               low_mode_from_nfs4(state->users->aces[i].perms.allow,
+                                       &pace->e_perm, flags);
+               pace->e_id = state->users->aces[i].uid;
+               add_to_mask(state, &state->users->aces[i].perms);
        }
 
-       /* group owner (deny ace) */
-
-       if (ace2type(ace) != ACL_GROUP_OBJ)
-               goto out;
-       ac = list_entry(group_l.next, struct ace_container, ace_l);
-       ace2 = ac->ace;
-       if (!complementary_ace_pair(ace2, ace, flags))
-               goto out;
-       list_del(group_l.next);
-       kfree(ac);
-
-       /* groups (deny aces) */
-
-       while (!list_empty(&group_l)) {
-               ace = get_next_v4_ace(p, &n4acl->ace_head);
-               if (ace == NULL)
-                       goto out;
-               if (ace2type(ace) != ACL_GROUP)
-                       goto out;
-               ac = list_entry(group_l.next, struct ace_container, ace_l);
-               ace2 = ac->ace;
-               if (!complementary_ace_pair(ace2, ace, flags))
-                       goto out;
-               list_del(group_l.next);
-               kfree(ac);
+       pace++;
+       pace->e_tag = ACL_GROUP_OBJ;
+       error = check_deny(state->group.deny, 0);
+       if (error)
+               goto out_err;
+       low_mode_from_nfs4(state->group.allow, &pace->e_perm, flags);
+       pace->e_id = ACL_UNDEFINED_ID;
+       add_to_mask(state, &state->group);
+
+       for (i=0; i < state->groups->n; i++) {
+               pace++;
+               pace->e_tag = ACL_GROUP;
+               error = check_deny(state->groups->aces[i].perms.deny, 0);
+               if (error)
+                       goto out_err;
+               low_mode_from_nfs4(state->groups->aces[i].perms.allow,
+                                       &pace->e_perm, flags);
+               pace->e_id = state->groups->aces[i].uid;
+               add_to_mask(state, &state->groups->aces[i].perms);
        }
 
-       ace = get_next_v4_ace(p, &n4acl->ace_head);
-       if (ace == NULL)
-               goto out;
-       if (ace2type(ace) != ACL_OTHER)
-               goto out;
-       error = 0;
-out:
-       while (!list_empty(&group_l)) {
-               ac = list_entry(group_l.next, struct ace_container, ace_l);
-               list_del(group_l.next);
-               kfree(ac);
-       }
-       return error;
-}
+       pace++;
+       pace->e_tag = ACL_MASK;
+       low_mode_from_nfs4(state->mask.allow, &pace->e_perm, flags);
+       pace->e_id = ACL_UNDEFINED_ID;
 
-static inline int
-mask_from_v4(struct nfs4_acl *n4acl, struct list_head **p,
-               struct nfs4_ace **mask_ace,
-               struct posix_acl *pacl, struct posix_acl_entry **pace,
-               unsigned int flags)
-{
-       int error = -EINVAL;
-       struct nfs4_ace *ace;
+       pace++;
+       pace->e_tag = ACL_OTHER;
+       error = check_deny(state->other.deny, 0);
+       if (error)
+               goto out_err;
+       low_mode_from_nfs4(state->other.allow, &pace->e_perm, flags);
+       pace->e_id = ACL_UNDEFINED_ID;
 
-       ace = list_entry(*p, struct nfs4_ace, l_ace);
-       if (pacl->a_count != 3) {
-               if (*mask_ace == NULL)
-                       goto out;
-               (*mask_ace)->access_mask = deny_mask((*mask_ace)->access_mask, flags);
-               write_pace(*mask_ace, pacl, pace, ACL_MASK, flags);
-       }
-       error = 0;
-out:
-       return error;
+       return pacl;
+out_err:
+       posix_acl_release(pacl);
+       return ERR_PTR(error);
 }
 
-static inline int
-other_from_v4(struct nfs4_acl *n4acl, struct list_head **p,
-               struct posix_acl *pacl, struct posix_acl_entry **pace,
-               unsigned int flags)
+static inline void allow_bits(struct posix_ace_state *astate, u32 mask)
 {
-       int error = -EINVAL;
-       struct nfs4_ace *ace, *ace2;
-
-       ace = list_entry(*p, struct nfs4_ace, l_ace);
-       if (ace->type != NFS4_ACE_ACCESS_ALLOWED_ACE_TYPE)
-               goto out;
-       error = write_pace(ace, pacl, pace, ACL_OTHER, flags);
-       if (error < 0)
-               goto out;
-       error = -EINVAL;
-       ace2 = get_next_v4_ace(p, &n4acl->ace_head);
-       if (ace2 == NULL)
-               goto out;
-       if (!complementary_ace_pair(ace, ace2, flags))
-               goto out;
-       error = 0;
-out:
-       return error;
+       /* Allow all bits in the mask not already denied: */
+       astate->allow |= mask & ~astate->deny;
 }
 
-static int
-calculate_posix_ace_count(struct nfs4_acl *n4acl)
+static inline void deny_bits(struct posix_ace_state *astate, u32 mask)
 {
-       if (n4acl->naces == 6) /* owner, owner group, and other only */
-               return 3;
-       else { /* Otherwise there must be a mask entry. */
-               /* Also, the remaining entries are for named users and
-                * groups, and come in threes (mask, allow, deny): */
-               if (n4acl->naces < 7)
-                       return -1;
-               if ((n4acl->naces - 7) % 3)
-                       return -1;
-               return 4 + (n4acl->naces - 7)/3;
-       }
+       /* Deny all bits in the mask not already allowed: */
+       astate->deny |= mask & ~astate->allow;
 }
 
-
-static struct posix_acl *
-_nfsv4_to_posix_one(struct nfs4_acl *n4acl, unsigned int flags)
+static int find_uid(struct posix_acl_state *state, struct posix_ace_state_array *a, uid_t uid)
 {
-       struct posix_acl *pacl;
-       int error = -EINVAL, nace = 0;
-       struct list_head *p;
-       struct nfs4_ace *mask_ace = NULL;
-       struct posix_acl_entry *pace;
-
-       nace = calculate_posix_ace_count(n4acl);
-       if (nace < 0)
-               goto out_err;
+       int i;
 
-       pacl = posix_acl_alloc(nace, GFP_KERNEL);
-       error = -ENOMEM;
-       if (pacl == NULL)
-               goto out_err;
+       for (i = 0; i < a->n; i++)
+               if (a->aces[i].uid == uid)
+                       return i;
+       /* Not found: */
+       a->n++;
+       a->aces[i].uid = uid;
+       a->aces[i].perms.allow = state->everyone.allow;
+       a->aces[i].perms.deny  = state->everyone.deny;
 
-       pace = &pacl->a_entries[0];
-       p = &n4acl->ace_head;
+       return i;
+}
 
-       error = user_obj_from_v4(n4acl, &p, pacl, &pace, flags);
-       if (error)
-               goto out_acl;
+static void deny_bits_array(struct posix_ace_state_array *a, u32 mask)
+{
+       int i;
 
-       error = users_from_v4(n4acl, &p, &mask_ace, pacl, &pace, flags);
-       if (error)
-               goto out_acl;
+       for (i=0; i < a->n; i++)
+               deny_bits(&a->aces[i].perms, mask);
+}
 
-       error = group_obj_and_groups_from_v4(n4acl, &p, &mask_ace, pacl, &pace,
-                                               flags);
-       if (error)
-               goto out_acl;
+static void allow_bits_array(struct posix_ace_state_array *a, u32 mask)
+{
+       int i;
 
-       error = mask_from_v4(n4acl, &p, &mask_ace, pacl, &pace, flags);
-       if (error)
-               goto out_acl;
-       error = other_from_v4(n4acl, &p, pacl, &pace, flags);
-       if (error)
-               goto out_acl;
+       for (i=0; i < a->n; i++)
+               allow_bits(&a->aces[i].perms, mask);
+}
 
-       error = -EINVAL;
-       if (p->next != &n4acl->ace_head)
-               goto out_acl;
-       if (pace != pacl->a_entries + pacl->a_count)
-               goto out_acl;
+static void process_one_v4_ace(struct posix_acl_state *state,
+                               struct nfs4_ace *ace)
+{
+       u32 mask = ace->access_mask;
+       int i;
 
-       sort_pacl(pacl);
+       state->empty = 0;
 
-       return pacl;
-out_acl:
-       posix_acl_release(pacl);
-out_err:
-       pacl = ERR_PTR(error);
-       return pacl;
+       switch (ace2type(ace)) {
+       case ACL_USER_OBJ:
+               if (ace->type == NFS4_ACE_ACCESS_ALLOWED_ACE_TYPE) {
+                       allow_bits(&state->owner, mask);
+               } else {
+                       deny_bits(&state->owner, mask);
+               }
+               break;
+       case ACL_USER:
+               i = find_uid(state, state->users, ace->who);
+               if (ace->type == NFS4_ACE_ACCESS_ALLOWED_ACE_TYPE) {
+                       allow_bits(&state->users->aces[i].perms, mask);
+               } else {
+                       deny_bits(&state->users->aces[i].perms, mask);
+                       mask = state->users->aces[i].perms.deny;
+                       deny_bits(&state->owner, mask);
+               }
+               break;
+       case ACL_GROUP_OBJ:
+               if (ace->type == NFS4_ACE_ACCESS_ALLOWED_ACE_TYPE) {
+                       allow_bits(&state->group, mask);
+               } else {
+                       deny_bits(&state->group, mask);
+                       mask = state->group.deny;
+                       deny_bits(&state->owner, mask);
+                       deny_bits(&state->everyone, mask);
+                       deny_bits_array(state->users, mask);
+                       deny_bits_array(state->groups, mask);
+               }
+               break;
+       case ACL_GROUP:
+               i = find_uid(state, state->groups, ace->who);
+               if (ace->type == NFS4_ACE_ACCESS_ALLOWED_ACE_TYPE) {
+                       allow_bits(&state->groups->aces[i].perms, mask);
+               } else {
+                       deny_bits(&state->groups->aces[i].perms, mask);
+                       mask = state->groups->aces[i].perms.deny;
+                       deny_bits(&state->owner, mask);
+                       deny_bits(&state->group, mask);
+                       deny_bits(&state->everyone, mask);
+                       deny_bits_array(state->users, mask);
+                       deny_bits_array(state->groups, mask);
+               }
+               break;
+       case ACL_OTHER:
+               if (ace->type == NFS4_ACE_ACCESS_ALLOWED_ACE_TYPE) {
+                       allow_bits(&state->owner, mask);
+                       allow_bits(&state->group, mask);
+                       allow_bits(&state->other, mask);
+                       allow_bits(&state->everyone, mask);
+                       allow_bits_array(state->users, mask);
+                       allow_bits_array(state->groups, mask);
+               } else {
+                       deny_bits(&state->owner, mask);
+                       deny_bits(&state->group, mask);
+                       deny_bits(&state->other, mask);
+                       deny_bits(&state->everyone, mask);
+                       deny_bits_array(state->users, mask);
+                       deny_bits_array(state->groups, mask);
+               }
+       }
 }
 
-int
-nfs4_acl_split(struct nfs4_acl *acl, struct nfs4_acl *dacl)
+int nfs4_acl_nfsv4_to_posix(struct nfs4_acl *acl, struct posix_acl **pacl,
+                           struct posix_acl **dpacl, unsigned int flags)
 {
-       struct list_head *h, *n;
+       struct posix_acl_state effective_acl_state, default_acl_state;
        struct nfs4_ace *ace;
-       int error = 0;
-
-       list_for_each_safe(h, n, &acl->ace_head) {
-               ace = list_entry(h, struct nfs4_ace, l_ace);
-
-               if ((ace->flag & NFS4_INHERITANCE_FLAGS)
-                               != NFS4_INHERITANCE_FLAGS)
+       int ret;
+
+       ret = init_state(&effective_acl_state, acl->naces);
+       if (ret)
+               return ret;
+       ret = init_state(&default_acl_state, acl->naces);
+       if (ret)
+               goto out_estate;
+       ret = -EINVAL;
+       for (ace = acl->aces; ace < acl->aces + acl->naces; ace++) {
+               if (ace->type != NFS4_ACE_ACCESS_ALLOWED_ACE_TYPE &&
+                   ace->type != NFS4_ACE_ACCESS_DENIED_ACE_TYPE)
+                       goto out_dstate;
+               if (ace->flag & ~NFS4_SUPPORTED_FLAGS)
+                       goto out_dstate;
+               if ((ace->flag & NFS4_INHERITANCE_FLAGS) == 0) {
+                       process_one_v4_ace(&effective_acl_state, ace);
                        continue;
-
-               error = nfs4_acl_add_ace(dacl, ace->type, ace->flag,
-                               ace->access_mask, ace->whotype, ace->who) == -1;
-               if (error < 0)
-                       goto out;
-
-               list_del(h);
-               kfree(ace);
-               acl->naces--;
+               }
+               if (!(flags & NFS4_ACL_DIR))
+                       goto out_dstate;
+               /*
+                * Note that when only one of FILE_INHERIT or DIRECTORY_INHERIT
+                * is set, we're effectively turning on the other.  That's OK,
+                * according to rfc 3530.
+                */
+               process_one_v4_ace(&default_acl_state, ace);
+
+               if (!(ace->flag & NFS4_ACE_INHERIT_ONLY_ACE))
+                       process_one_v4_ace(&effective_acl_state, ace);
        }
-
-out:
-       return error;
+       *pacl = posix_state_to_acl(&effective_acl_state, flags);
+       if (IS_ERR(*pacl)) {
+               ret = PTR_ERR(*pacl);
+               *pacl = NULL;
+               goto out_dstate;
+       }
+       *dpacl = posix_state_to_acl(&default_acl_state,
+                                               flags | NFS4_ACL_TYPE_DEFAULT);
+       if (IS_ERR(*dpacl)) {
+               ret = PTR_ERR(*dpacl);
+               *dpacl = NULL;
+               posix_acl_release(*pacl);
+               *pacl = NULL;
+               goto out_dstate;
+       }
+       sort_pacl(*pacl);
+       sort_pacl(*dpacl);
+       ret = 0;
+out_dstate:
+       free_state(&default_acl_state);
+out_estate:
+       free_state(&effective_acl_state);
+       return ret;
 }
 
 static short
@@ -825,61 +772,17 @@ EXPORT_SYMBOL(nfs4_acl_posix_to_nfsv4);
 EXPORT_SYMBOL(nfs4_acl_nfsv4_to_posix);
 
 struct nfs4_acl *
-nfs4_acl_new(void)
+nfs4_acl_new(int n)
 {
        struct nfs4_acl *acl;
 
-       if ((acl = kmalloc(sizeof(*acl), GFP_KERNEL)) == NULL)
+       acl = kmalloc(sizeof(*acl) + n*sizeof(struct nfs4_ace), GFP_KERNEL);
+       if (acl == NULL)
                return NULL;
-
        acl->naces = 0;
-       INIT_LIST_HEAD(&acl->ace_head);
-
        return acl;
 }
 
-void
-nfs4_acl_free(struct nfs4_acl *acl)
-{
-       struct list_head *h;
-       struct nfs4_ace *ace;
-
-       if (!acl)
-               return;
-
-       while (!list_empty(&acl->ace_head)) {
-               h = acl->ace_head.next;
-               list_del(h);
-               ace = list_entry(h, struct nfs4_ace, l_ace);
-               kfree(ace);
-       }
-
-       kfree(acl);
-
-       return;
-}
-
-int
-nfs4_acl_add_ace(struct nfs4_acl *acl, u32 type, u32 flag, u32 access_mask,
-               int whotype, uid_t who)
-{
-       struct nfs4_ace *ace;
-
-       if ((ace = kmalloc(sizeof(*ace), GFP_KERNEL)) == NULL)
-               return -1;
-
-       ace->type = type;
-       ace->flag = flag;
-       ace->access_mask = access_mask;
-       ace->whotype = whotype;
-       ace->who = who;
-
-       list_add_tail(&ace->l_ace, &acl->ace_head);
-       acl->naces++;
-
-       return 0;
-}
-
 static struct {
        char *string;
        int   stringlen;
@@ -907,7 +810,7 @@ nfs4_acl_get_whotype(char *p, u32 len)
 {
        int i;
 
-       for (i=0; i < sizeof(s2t_map) / sizeof(*s2t_map); i++) {
+       for (i = 0; i < ARRAY_SIZE(s2t_map); i++) {
                if (s2t_map[i].stringlen == len &&
                                0 == memcmp(s2t_map[i].string, p, len))
                        return s2t_map[i].type;
@@ -920,7 +823,7 @@ nfs4_acl_write_who(int who, char *p)
 {
        int i;
 
-       for (i=0; i < sizeof(s2t_map) / sizeof(*s2t_map); i++) {
+       for (i = 0; i < ARRAY_SIZE(s2t_map); i++) {
                if (s2t_map[i].type == who) {
                        memcpy(p, s2t_map[i].string, s2t_map[i].stringlen);
                        return s2t_map[i].stringlen;
@@ -930,25 +833,6 @@ nfs4_acl_write_who(int who, char *p)
        return -1;
 }
 
-static inline int
-match_who(struct nfs4_ace *ace, uid_t owner, gid_t group, uid_t who)
-{
-       switch (ace->whotype) {
-               case NFS4_ACL_WHO_NAMED:
-                       return who == ace->who;
-               case NFS4_ACL_WHO_OWNER:
-                       return who == owner;
-               case NFS4_ACL_WHO_GROUP:
-                       return who == group;
-               case NFS4_ACL_WHO_EVERYONE:
-                       return 1;
-               default:
-                       return 0;
-       }
-}
-
 EXPORT_SYMBOL(nfs4_acl_new);
-EXPORT_SYMBOL(nfs4_acl_free);
-EXPORT_SYMBOL(nfs4_acl_add_ace);
 EXPORT_SYMBOL(nfs4_acl_get_whotype);
 EXPORT_SYMBOL(nfs4_acl_write_who);