From cc6bcab341007660796de9beda6f994971d43239 Mon Sep 17 00:00:00 2001
From: bwzhou <bwzhou>
Date: Mon, 5 Nov 2007 16:01:07 +0000
Subject: [PATCH] Branch b1_6 b=13317 r=shadow, johann

enable liblustre to connect to mds with acl
---
 lustre/autoconf/lustre-core.m4 | 13 +++++++++++
 lustre/include/liblustre.h     |  9 ++++++++
 lustre/include/lustre_mds.h    |  6 -----
 lustre/liblustre/llite_lib.c   |  3 +++
 lustre/liblustre/super.c       |  6 ++++-
 lustre/utils/wirecheck.c       | 42 ++++++++++++++++++++++++++++++++++
 lustre/utils/wiretest.c        | 29 +++++++++++++++++++++++
 7 files changed, 101 insertions(+), 7 deletions(-)

diff --git a/lustre/autoconf/lustre-core.m4 b/lustre/autoconf/lustre-core.m4
index e65ad06f82..c0651fa393 100644
--- a/lustre/autoconf/lustre-core.m4
+++ b/lustre/autoconf/lustre-core.m4
@@ -1269,6 +1269,19 @@ if test x$enable_liblustre != xyes ; then
 fi
 AC_MSG_RESULT([$enable_liblustre_tests])
 
+AC_MSG_CHECKING([whether to enable liblustre acl])
+AC_ARG_ENABLE([liblustre-acl],
+	AC_HELP_STRING([--disable-liblustre-acl],
+			[disable ACL support for liblustre]),
+	[],[enable_liblustre_acl=yes])
+if test x$enable_liblustre != xyes ; then
+   enable_liblustre_acl='no'
+fi
+AC_MSG_RESULT([$enable_liblustre_acl])
+if test x$enable_liblustre_acl != xno ; then
+  AC_DEFINE(LIBLUSTRE_POSIX_ACL, 1, Liblustre Support ACL-enabled MDS)
+fi
+
 AC_MSG_CHECKING([whether to build mpitests])
 AC_ARG_ENABLE([mpitests],
 	AC_HELP_STRING([--enable-mpitests],
diff --git a/lustre/include/liblustre.h b/lustre/include/liblustre.h
index abf8d3a1ca..82436dd94d 100644
--- a/lustre/include/liblustre.h
+++ b/lustre/include/liblustre.h
@@ -903,6 +903,15 @@ void posix_acl_release(struct posix_acl *acl)
 {
 }
 
+#ifdef LIBLUSTRE_POSIX_ACL
+ #define posix_acl_xattr_entry xattr_acl_entry
+ #define posix_acl_xattr_header xattr_acl_header
+ #define posix_acl_xattr_size(entry) xattr_acl_size(entry)
+ #ifndef CONFIG_FS_POSIX_ACL
+  #define CONFIG_FS_POSIX_ACL 1
+ #endif
+#endif
+
 #ifndef ENOTSUPP
 #define ENOTSUPP ENOTSUP
 #endif
diff --git a/lustre/include/lustre_mds.h b/lustre/include/lustre_mds.h
index 4a79122a44..c2ace3e639 100644
--- a/lustre/include/lustre_mds.h
+++ b/lustre/include/lustre_mds.h
@@ -101,14 +101,8 @@ struct mds_file_data {
 # endif /* HAVE_XATTR_ACL */
 
 # define LUSTRE_POSIX_ACL_MAX_ENTRIES   (32)
-
-# ifdef __KERNEL__
 #  define LUSTRE_POSIX_ACL_MAX_SIZE      \
                 (mds_xattr_acl_size(LUSTRE_POSIX_ACL_MAX_ENTRIES))
-# else /* __KERNEL__ */
-#  define LUSTRE_POSIX_ACL_MAX_SIZE	0
-# endif /* __KERNEL__ */
-
 #else /* CONFIG_FS_POSIX_ACL */
 # define LUSTRE_POSIX_ACL_MAX_SIZE      0
 #endif /* CONFIG_FS_POSIX_ACL */
diff --git a/lustre/liblustre/llite_lib.c b/lustre/liblustre/llite_lib.c
index a4b3e421aa..09d17c342c 100644
--- a/lustre/liblustre/llite_lib.c
+++ b/lustre/liblustre/llite_lib.c
@@ -157,6 +157,9 @@ int liblustre_process_log(struct config_llog_instance *cfg,
                 GOTO(out_cleanup, rc = -ENOMEM);
 
         ocd->ocd_connect_flags = OBD_CONNECT_VERSION | OBD_CONNECT_AT;
+#ifdef LIBLUSTRE_POSIX_ACL
+        ocd->ocd_connect_flags |= OBD_CONNECT_ACL;
+#endif
         ocd->ocd_version = LUSTRE_VERSION_CODE;
 
         rc = obd_connect(&mgc_conn, obd, &mgc_uuid, ocd, NULL);
diff --git a/lustre/liblustre/super.c b/lustre/liblustre/super.c
index 6abda5ef87..784101a964 100644
--- a/lustre/liblustre/super.c
+++ b/lustre/liblustre/super.c
@@ -1937,6 +1937,9 @@ llu_fsswop_mount(const char *source,
 
         ocd.ocd_connect_flags = OBD_CONNECT_IBITS | OBD_CONNECT_VERSION |
                 OBD_CONNECT_AT;
+#ifdef LIBLUSTRE_POSIX_ACL
+        ocd.ocd_connect_flags |= OBD_CONNECT_ACL;
+#endif
         ocd.ocd_ibits_known = MDS_INODELOCK_FULL;
         ocd.ocd_version = LUSTRE_VERSION_CODE;
 
@@ -1991,7 +1994,8 @@ llu_fsswop_mount(const char *source,
 
         /* fetch attr of root inode */
         err = mdc_getattr(sbi->ll_mdc_exp, &rootfid,
-                          OBD_MD_FLGETATTR | OBD_MD_FLBLOCKS, 0, &request);
+                          OBD_MD_FLGETATTR | OBD_MD_FLBLOCKS, 0, 
+                          &request);
         if (err) {
                 CERROR("mdc_getattr failed for root: rc = %d\n", err);
                 GOTO(out_osc, err);
diff --git a/lustre/utils/wirecheck.c b/lustre/utils/wirecheck.c
index 560ec8110b..e3e677f40b 100644
--- a/lustre/utils/wirecheck.c
+++ b/lustre/utils/wirecheck.c
@@ -54,23 +54,44 @@ do {                                                            \
         CHECK_VALUE((int)offsetof(struct s, m));                \
 } while(0)
 
+#define CHECK_MEMBER_OFFSET_TYPEDEF(s,m)                        \
+do {                                                            \
+        CHECK_VALUE((int)offsetof(s, m));                       \
+} while(0)
+
 #define CHECK_MEMBER_SIZEOF(s,m)                                \
 do {                                                            \
         CHECK_VALUE((int)sizeof(((struct s *)0)->m));           \
 } while(0)
 
+#define CHECK_MEMBER_SIZEOF_TYPEDEF(s,m)                        \
+do {                                                            \
+        CHECK_VALUE((int)sizeof(((s *)0)->m));                  \
+} while(0)
+
 #define CHECK_MEMBER(s,m)                                       \
 do {                                                            \
         CHECK_MEMBER_OFFSET(s, m);                              \
         CHECK_MEMBER_SIZEOF(s, m);                              \
 } while(0)
 
+#define CHECK_MEMBER_TYPEDEF(s,m)                               \
+do {                                                            \
+        CHECK_MEMBER_OFFSET_TYPEDEF(s, m);                      \
+        CHECK_MEMBER_SIZEOF_TYPEDEF(s, m);                      \
+} while(0)
+
 #define CHECK_STRUCT(s)                                         \
 do {                                                            \
         COMMENT("Checks for struct "#s);                        \
                 CHECK_VALUE((int)sizeof(struct s));             \
 } while(0)
 
+#define CHECK_STRUCT_TYPEDEF(s)                                 \
+do {                                                            \
+        COMMENT("Checks for type "#s);                          \
+                CHECK_VALUE((int)sizeof(s));                    \
+} while(0)
 
 static void
 check_lustre_handle(void)
@@ -1004,6 +1025,25 @@ check_lustre_disk_data(void)
         CHECK_MEMBER(lustre_disk_data, ldd_params);
 }
 
+static void
+check_posix_acl_xattr_entry(void)
+{
+        BLANK_LINE();
+        CHECK_STRUCT_TYPEDEF(posix_acl_xattr_entry);
+        CHECK_MEMBER_TYPEDEF(posix_acl_xattr_entry, e_tag);
+        CHECK_MEMBER_TYPEDEF(posix_acl_xattr_entry, e_perm);
+        CHECK_MEMBER_TYPEDEF(posix_acl_xattr_entry, e_id);
+}
+
+static void
+check_posix_acl_xattr_header(void)
+{
+        BLANK_LINE();
+        CHECK_STRUCT_TYPEDEF(posix_acl_xattr_header);
+        CHECK_MEMBER_TYPEDEF(posix_acl_xattr_header, a_version);
+        CHECK_MEMBER_TYPEDEF(posix_acl_xattr_header, a_entries);
+}
+
 static void
 system_string (char *cmdline, char *str, int len)
 {
@@ -1253,6 +1293,8 @@ main(int argc, char **argv)
         check_qunit_data_old();
         check_mgs_target_info();
         check_lustre_disk_data();
+        check_posix_acl_xattr_entry();
+        check_posix_acl_xattr_header();
 
 
         printf("}\n\n");
diff --git a/lustre/utils/wiretest.c b/lustre/utils/wiretest.c
index 4590602223..c0824d15d5 100644
--- a/lustre/utils/wiretest.c
+++ b/lustre/utils/wiretest.c
@@ -2140,4 +2140,33 @@ void lustre_assert_wire_constants(void)
                  (long long)(int)offsetof(struct lustre_disk_data, ldd_params));
         LASSERTF((int)sizeof(((struct lustre_disk_data *)0)->ldd_params) == 4096, " found %lld\n",
                  (long long)(int)sizeof(((struct lustre_disk_data *)0)->ldd_params));
+
+        /* Checks for type posix_acl_xattr_entry */
+        LASSERTF((int)sizeof(xattr_acl_entry) == 8, " found %lld\n",
+                 (long long)(int)sizeof(xattr_acl_entry));
+        LASSERTF((int)offsetof(xattr_acl_entry, e_tag) == 0, " found %lld\n",
+                 (long long)(int)offsetof(xattr_acl_entry, e_tag));
+        LASSERTF((int)sizeof(((xattr_acl_entry *)0)->e_tag) == 2, " found %lld\n",
+                 (long long)(int)sizeof(((xattr_acl_entry *)0)->e_tag));
+        LASSERTF((int)offsetof(xattr_acl_entry, e_perm) == 2, " found %lld\n",
+                 (long long)(int)offsetof(xattr_acl_entry, e_perm));
+        LASSERTF((int)sizeof(((xattr_acl_entry *)0)->e_perm) == 2, " found %lld\n",
+                 (long long)(int)sizeof(((xattr_acl_entry *)0)->e_perm));
+        LASSERTF((int)offsetof(xattr_acl_entry, e_id) == 4, " found %lld\n",
+                 (long long)(int)offsetof(xattr_acl_entry, e_id));
+        LASSERTF((int)sizeof(((xattr_acl_entry *)0)->e_id) == 4, " found %lld\n",
+                 (long long)(int)sizeof(((xattr_acl_entry *)0)->e_id));
+
+        /* Checks for type posix_acl_xattr_header */
+        LASSERTF((int)sizeof(xattr_acl_header) == 4, " found %lld\n",
+                 (long long)(int)sizeof(xattr_acl_header));
+        LASSERTF((int)offsetof(xattr_acl_header, a_version) == 0, " found %lld\n",
+                 (long long)(int)offsetof(xattr_acl_header, a_version));
+        LASSERTF((int)sizeof(((xattr_acl_header *)0)->a_version) == 4, " found %lld\n",
+                 (long long)(int)sizeof(((xattr_acl_header *)0)->a_version));
+        LASSERTF((int)offsetof(xattr_acl_header, a_entries) == 4, " found %lld\n",
+                 (long long)(int)offsetof(xattr_acl_header, a_entries));
+        LASSERTF((int)sizeof(((xattr_acl_header *)0)->a_entries) == 0, " found %lld\n",
+                 (long long)(int)sizeof(((xattr_acl_header *)0)->a_entries));
+
 }
-- 
GitLab