Whamcloud - gitweb
LU-9679 mdc: create mdc_acl.c 92/39292/4
authorMr NeilBrown <neilb@suse.de>
Mon, 6 Jul 2020 12:34:47 +0000 (08:34 -0400)
committerOleg Drokin <green@whamcloud.com>
Fri, 17 Jul 2020 19:29:31 +0000 (19:29 +0000)
This new C file contains acl related code so it can be
conditionally compiled.

Also remove conditional code around the call to mdc_unpack_acl(), as
those tests are already performed inside mdc_unpack_acl().

In the Makefile, use CONFIG_FS_POSIX_ACL to control conditional
compilation as CONFIG_LUSTRE_FS_POSIX_ACL is not available, but the
two are semantically equivalent in this context.

This removes all #ifdef of CONFIG_LUSTRE_FS_POSIX_ACL from C files in
'mdc'.

Signed-off-by: Mr NeilBrown <neilb@suse.de>
Change-Id: Ic9060bee4a2ad55580d8879fe32fee01b1cb8884
Reviewed-on: https://review.whamcloud.com/39292
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: James Simmons <jsimmons@infradead.org>
Reviewed-by: Lai Siyao <lai.siyao@whamcloud.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lustre/mdc/Makefile.in
lustre/mdc/mdc_acl.c [new file with mode: 0644]
lustre/mdc/mdc_internal.h
lustre/mdc/mdc_request.c

index ba426af..454d910 100644 (file)
@@ -1,5 +1,6 @@
 MODULES := mdc
-mdc-objs :=    mdc_request.o \
+
+mdc-objs-y :=  mdc_request.o \
                mdc_reint.o \
                lproc_mdc.o \
                mdc_lib.o \
@@ -7,6 +8,10 @@ mdc-objs :=    mdc_request.o \
                mdc_changelog.o \
                mdc_dev.o
 
-EXTRA_DIST = $(mdc-objs:.o=.c) mdc_internal.h
+mdc-objs-$(CONFIG_FS_POSIX_ACL) += mdc_acl.o
+
+mdc-objs := $(mdc-objs-y)
+
+EXTRA_DIST = $(mdc-objs:.o=.c) mdc_acl.c mdc_internal.h
 
 @INCLUDE_RULES@
diff --git a/lustre/mdc/mdc_acl.c b/lustre/mdc/mdc_acl.c
new file mode 100644 (file)
index 0000000..6814045
--- /dev/null
@@ -0,0 +1,64 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * GPL HEADER START
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 only,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License version 2 for more details (a copy is included
+ * in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License
+ * version 2 along with this program; If not, see
+ * http://www.gnu.org/licenses/gpl-2.0.html
+ *
+ * GPL HEADER END
+ */
+#include <lustre_acl.h>
+
+#include "mdc_internal.h"
+
+int mdc_unpack_acl(struct ptlrpc_request *req, struct lustre_md *md)
+{
+       struct req_capsule *pill = &req->rq_pill;
+       struct mdt_body *body = md->body;
+       struct posix_acl *acl;
+       void *buf;
+       int rc;
+
+       /* for ACL, it's possible that FLACL is set but aclsize is zero.
+        * only when aclsize != 0 there's an actual segment for ACL
+        * in reply buffer.
+        */
+       if (!body->mbo_aclsize) {
+               md->posix_acl = NULL;
+               return 0;
+       }
+
+       buf = req_capsule_server_sized_get(pill, &RMF_ACL, body->mbo_aclsize);
+       if (!buf)
+               return -EPROTO;
+
+       acl = posix_acl_from_xattr(&init_user_ns, buf, body->mbo_aclsize);
+       if (IS_ERR_OR_NULL(acl)) {
+               rc = acl ? PTR_ERR(acl) : 0;
+               CERROR("convert xattr to acl: %d\n", rc);
+               return rc;
+       }
+
+       rc = posix_acl_valid(&init_user_ns, acl);
+       if (rc) {
+               CERROR("validate acl: %d\n", rc);
+               posix_acl_release(acl);
+               return rc;
+       }
+
+       md->posix_acl = acl;
+       return 0;
+}
index c7e4793..c037014 100644 (file)
@@ -167,6 +167,16 @@ static inline int mdc_prep_elc_req(struct obd_export *exp,
                                 count);
 }
 
+#ifdef CONFIG_LUSTRE_FS_POSIX_ACL
+int mdc_unpack_acl(struct ptlrpc_request *req, struct lustre_md *md);
+#else
+static inline
+int mdc_unpack_acl(struct ptlrpc_request *req, struct lustre_md *md)
+{
+       return 0;
+}
+#endif
+
 static inline unsigned long hash_x_index(__u64 hash, int hash64)
 {
        if (BITS_PER_LONG == 32 && hash64)
index 6f319cb..0b435d7 100644 (file)
@@ -505,47 +505,6 @@ out:
        return rc;
 }
 
-#ifdef CONFIG_LUSTRE_FS_POSIX_ACL
-static int mdc_unpack_acl(struct ptlrpc_request *req, struct lustre_md *md)
-{
-        struct req_capsule     *pill = &req->rq_pill;
-        struct mdt_body        *body = md->body;
-        struct posix_acl       *acl;
-        void                   *buf;
-        int                     rc;
-        ENTRY;
-
-       if (!body->mbo_aclsize)
-               RETURN(0);
-
-       buf = req_capsule_server_sized_get(pill, &RMF_ACL, body->mbo_aclsize);
-
-       if (!buf)
-               RETURN(-EPROTO);
-
-       acl = posix_acl_from_xattr(&init_user_ns, buf, body->mbo_aclsize);
-       if (acl == NULL)
-               RETURN(0);
-        if (IS_ERR(acl)) {
-                rc = PTR_ERR(acl);
-                CERROR("convert xattr to acl: %d\n", rc);
-                RETURN(rc);
-        }
-
-        rc = posix_acl_valid(&init_user_ns, acl);
-        if (rc) {
-                CERROR("validate acl: %d\n", rc);
-                posix_acl_release(acl);
-                RETURN(rc);
-        }
-
-        md->posix_acl = acl;
-        RETURN(0);
-}
-#else
-#define mdc_unpack_acl(req, md) 0
-#endif
-
 int mdc_get_lustre_md(struct obd_export *exp, struct ptlrpc_request *req,
                       struct obd_export *dt_exp, struct obd_export *md_exp,
                       struct lustre_md *md)
@@ -643,30 +602,24 @@ int mdc_get_lustre_md(struct obd_export *exp, struct ptlrpc_request *req,
                        }
                }
        }
-        rc = 0;
+       rc = 0;
 
        if (md->body->mbo_valid & OBD_MD_FLACL) {
                /* for ACL, it's possible that FLACL is set but aclsize is zero.
                 * only when aclsize != 0 there's an actual segment for ACL
                 * in reply buffer.
                 */
-               if (md->body->mbo_aclsize) {
-                        rc = mdc_unpack_acl(req, md);
-                        if (rc)
-                                GOTO(out, rc);
-#ifdef CONFIG_LUSTRE_FS_POSIX_ACL
-                } else {
-                        md->posix_acl = NULL;
-#endif
-                }
-        }
+               rc = mdc_unpack_acl(req, md);
+               if (rc)
+                       GOTO(out, rc);
+       }
 
-        EXIT;
+       EXIT;
 out:
-        if (rc)
+       if (rc)
                lmd_clear_acl(md);
 
-        return rc;
+       return rc;
 }
 
 int mdc_free_lustre_md(struct obd_export *exp, struct lustre_md *md)