Whamcloud - gitweb
LU-744 obdclass: revise stats for cl_object cache
[fs/lustre-release.git] / lustre / obdclass / acl.c
index 07364bc..7adbd59 100644 (file)
@@ -1,6 +1,4 @@
-/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
- * vim:expandtab:shiftwidth=8:tabstop=8:
- *
+/*
  * GPL HEADER START
  *
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
@@ -26,7 +24,7 @@
  * GPL HEADER END
  */
 /*
- * Copyright  2008 Sun Microsystems, Inc. All rights reserved
+ * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
  */
 /*
  * Author: Fan Yong <fanyong@clusterfs.com>
  */
 
-#ifndef EXPORT_SYMTAB
-# define EXPORT_SYMTAB
-#endif
-
 #define DEBUG_SUBSYSTEM S_SEC
 
-#include <linux/lustre_acl.h>
+#include <lustre_acl.h>
 #include <lustre_eacl.h>
 #include <obd_support.h>
 
@@ -211,6 +205,49 @@ int lustre_posix_acl_chmod_masq(posix_acl_xattr_entry *entry, __u32 mode,
 EXPORT_SYMBOL(lustre_posix_acl_chmod_masq);
 
 /*
+ * Returns 0 if the acl can be exactly represented in the traditional
+ * file mode permission bits, or else 1. Returns -E... on error.
+ */
+       int
+lustre_posix_acl_equiv_mode(posix_acl_xattr_entry *entry, mode_t *mode_p,
+               int count)
+{
+       posix_acl_xattr_entry *pa, *pe;
+       mode_t                 mode = 0;
+       int                    not_equiv = 0;
+
+       for (pa = &entry[0], pe = &entry[count - 1]; pa <= pe; pa++) {
+               __u16 perm = le16_to_cpu(pa->e_perm);
+               switch (le16_to_cpu(pa->e_tag)) {
+                       case ACL_USER_OBJ:
+                               mode |= (perm & S_IRWXO) << 6;
+                               break;
+                       case ACL_GROUP_OBJ:
+                               mode |= (perm & S_IRWXO) << 3;
+                               break;
+                       case ACL_OTHER:
+                               mode |= perm & S_IRWXO;
+                               break;
+                       case ACL_MASK:
+                               mode = (mode & ~S_IRWXG) |
+                                       ((perm & S_IRWXO) << 3);
+                               not_equiv = 1;
+                               break;
+                       case ACL_USER:
+                       case ACL_GROUP:
+                               not_equiv = 1;
+                               break;
+                       default:
+                               return -EINVAL;
+               }
+       }
+       if (mode_p)
+               *mode_p = (*mode_p & ~S_IRWXUGO) | mode;
+       return not_equiv;
+}
+EXPORT_SYMBOL(lustre_posix_acl_equiv_mode);
+
+/*
  * Modify acl when creating a new object.
  */
 int lustre_posix_acl_create_masq(posix_acl_xattr_entry *entry, __u32 *pmode,
@@ -766,12 +803,12 @@ lustre_acl_xattr_merge2ext(posix_acl_xattr_header *posix_header, int size,
                                 if (posix_header->a_entries[i].e_perm !=
                                                                 ee->e_perm)
                                         /* entry modified. */
-                                        ee->e_perm =
+                                        ee->e_stat =
                                         new->a_entries[j++].e_stat =
                                                         cpu_to_le32(ES_MOD);
                                 else
                                         /* entry unchanged. */
-                                        ee->e_perm =
+                                        ee->e_stat =
                                         new->a_entries[j++].e_stat =
                                                         cpu_to_le32(ES_UNC);
                         } else {
@@ -796,12 +833,12 @@ lustre_acl_xattr_merge2ext(posix_acl_xattr_header *posix_header, int size,
                                 if (posix_header->a_entries[i].e_perm !=
                                                                 ee->e_perm)
                                         /* entry modified. */
-                                        ee->e_perm =
+                                        ee->e_stat =
                                         new->a_entries[j++].e_stat =
                                                         cpu_to_le32(ES_MOD);
                                 else
                                         /* entry unchanged. */
-                                        ee->e_perm =
+                                        ee->e_stat =
                                         new->a_entries[j++].e_stat =
                                                         cpu_to_le32(ES_UNC);
                         } else {