Whamcloud - gitweb
LU-10937 sptlrpc: split sptlrpc_process_config() 60/33760/4
authorJames Simmons <uja.ornl@yahoo.com>
Fri, 4 Jan 2019 12:37:52 +0000 (07:37 -0500)
committerOleg Drokin <green@whamcloud.com>
Wed, 16 Jan 2019 07:06:45 +0000 (07:06 +0000)
Make sptlrpc_process_config() more than a single line wapper
exporting function. Instead migrate the lcfg parsing out of
__sptlrpc_process_config() so that we can use this function
for both LCFG_PARAM and LCFG_SET_PARAM handling.

The first field parsed from struct lustre_cfg *lcfg is the
target. This can be "_mgs", file system name, or an obd target
i.e fsname-MDT0000. We can move to extracting the file system
name out of the target string using server_name2fsname().

Test-Parameters: testlist=sanity-sec envdefinitions=SHARED_KEY=true

Change-Id: If94ee8164ab2b49fe10d098b32faea9e331f04ac
Signed-off-by: James Simmons <uja.ornl@yahoo.com>
Reviewed-on: https://review.whamcloud.com/33760
Tested-by: Jenkins
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: Sebastien Buisson <sbuisson@ddn.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lustre/include/lustre_disk.h
lustre/mgc/mgc_request.c
lustre/mgs/mgs_llog.c
lustre/ptlrpc/sec_config.c

index 82a8afc..47ad428 100644 (file)
@@ -323,15 +323,18 @@ struct lustre_mount_info {
 
 /****************** prototypes *********************/
 
 
 /****************** prototypes *********************/
 
-/* obd_mount.c */
-int server_name2fsname(const char *svname, char *fsname, const char **endptr);
-#endif /* HAVE_SERVER_SUPPORT */
+/* obd_mount_server.c */
+int server_fill_super(struct super_block *sb);
+struct lustre_mount_info *server_get_mount(const char *name);
+int server_put_mount(const char *name, bool dereg_mnt);
+struct mgs_target_info;
+int server_mti_print(const char *title, struct mgs_target_info *mti);
+void server_calc_timeout(struct lustre_sb_info *lsi, struct obd_device *obd);
 
 
+/* obd_mount.c */
 int server_name2svname(const char *label, char *svname, const char **endptr,
                       size_t svsize);
 int server_name2svname(const char *label, char *svname, const char **endptr,
                       size_t svsize);
-void obdname2fsname(const char *tgt, char *fsname, size_t buflen);
 
 
-#ifdef HAVE_SERVER_SUPPORT
 int server_name_is_ost(const char *svname);
 int target_name2index(const char *svname, u32 *idx, const char **endptr);
 
 int server_name_is_ost(const char *svname);
 int target_name2index(const char *svname, u32 *idx, const char **endptr);
 
@@ -340,21 +343,14 @@ int lustre_start_simple(char *obdname, char *type, char *uuid,
                        char *s1, char *s2, char *s3, char *s4);
 int lustre_start_mgc(struct super_block *sb);
 #endif /* HAVE_SERVER_SUPPORT */
                        char *s1, char *s2, char *s3, char *s4);
 int lustre_start_mgc(struct super_block *sb);
 #endif /* HAVE_SERVER_SUPPORT */
+int server_name2fsname(const char *svname, char *fsname, const char **endptr);
+void obdname2fsname(const char *tgt, char *fsname, size_t fslen);
+
 void lustre_register_client_fill_super(int (*cfs)(struct super_block *sb,
                                                  struct vfsmount *mnt));
 void lustre_register_kill_super_cb(void (*cfs)(struct super_block *sb));
 int lustre_common_put_super(struct super_block *sb);
 
 void lustre_register_client_fill_super(int (*cfs)(struct super_block *sb,
                                                  struct vfsmount *mnt));
 void lustre_register_kill_super_cb(void (*cfs)(struct super_block *sb));
 int lustre_common_put_super(struct super_block *sb);
 
-# ifdef HAVE_SERVER_SUPPORT
-/* obd_mount_server.c */
-int server_fill_super(struct super_block *sb);
-struct lustre_mount_info *server_get_mount(const char *name);
-int server_put_mount(const char *name, bool dereg_mnt);
-struct mgs_target_info;
-int server_mti_print(const char *title, struct mgs_target_info *mti);
-void server_calc_timeout(struct lustre_sb_info *lsi, struct obd_device *obd);
-# endif
-
 int mgc_fsname2resid(char *fsname, struct ldlm_res_id *res_id, int type);
 int mgc_logname2resid(char *fsname, struct ldlm_res_id *res_id, int type);
 
 int mgc_fsname2resid(char *fsname, struct ldlm_res_id *res_id, int type);
 int mgc_logname2resid(char *fsname, struct ldlm_res_id *res_id, int type);
 
index 896a2e2..91910a9 100644 (file)
@@ -1414,7 +1414,7 @@ static int mgc_apply_recover_logs(struct obd_device *mgc,
        char *inst;
        char *buf;
        int bufsz;
        char *inst;
        char *buf;
        int bufsz;
-       int pos;
+       int pos = 0;
        int rc  = 0;
        int off = 0;
 
        int rc  = 0;
        int off = 0;
 
@@ -1432,6 +1432,7 @@ static int mgc_apply_recover_logs(struct obd_device *mgc,
                        OBD_FREE(inst, PAGE_SIZE);
                        return -E2BIG;
                }
                        OBD_FREE(inst, PAGE_SIZE);
                        return -E2BIG;
                }
+#ifdef HAVE_SERVER_SUPPORT
        } else {
                LASSERT(IS_MDT(lsi));
                rc = server_name2svname(lsi->lsi_svname, inst, NULL,
        } else {
                LASSERT(IS_MDT(lsi));
                rc = server_name2svname(lsi->lsi_svname, inst, NULL,
@@ -1441,7 +1442,8 @@ static int mgc_apply_recover_logs(struct obd_device *mgc,
                        RETURN(-EINVAL);
                }
                pos = strlen(inst);
                        RETURN(-EINVAL);
                }
                pos = strlen(inst);
-        }
+#endif /* HAVE_SERVER_SUPPORT */
+       }
 
         ++pos;
         buf   = inst + pos;
 
         ++pos;
         buf   = inst + pos;
index 5fa816d..174378b 100644 (file)
@@ -5233,7 +5233,6 @@ static int mgs_set_param2(const struct lu_env *env, struct mgs_device *mgs,
            sizeof(mti->mti_params))
                GOTO(out, rc = -E2BIG);
 
            sizeof(mti->mti_params))
                GOTO(out, rc = -E2BIG);
 
-       /* obdname2fsname reports devname as an obd device */
        len = strcspn(param, ".=");
        if (len && param[len] != '=') {
                struct list_head *tmp;
        len = strcspn(param, ".=");
        if (len && param[len] != '=') {
                struct list_head *tmp;
index b661ff8..7df845e 100644 (file)
@@ -618,68 +618,86 @@ static int sptlrpc_conf_merge_rule(struct sptlrpc_conf *conf,
  * find one through the target name in the record inside conf_lock;
  * otherwise means caller already hold conf_lock.
  */
  * find one through the target name in the record inside conf_lock;
  * otherwise means caller already hold conf_lock.
  */
-static int __sptlrpc_process_config(struct lustre_cfg *lcfg,
-                                    struct sptlrpc_conf *conf)
+static int __sptlrpc_process_config(char *target, const char *fsname,
+                                   struct sptlrpc_rule *rule,
+                                   struct sptlrpc_conf *conf)
 {
 {
-        char                   *target, *param;
-        char                    fsname[MTI_NAME_MAXLEN];
-        struct sptlrpc_rule     rule;
-        int                     rc;
+       int rc;
 
        ENTRY;
 
        ENTRY;
-       print_lustre_cfg(lcfg);
-
-        target = lustre_cfg_string(lcfg, 1);
-        if (target == NULL) {
-                CERROR("missing target name\n");
-                RETURN(-EINVAL);
-        }
-
-        param = lustre_cfg_string(lcfg, 2);
-        if (param == NULL) {
-                CERROR("missing parameter\n");
-                RETURN(-EINVAL);
-        }
-
-        CDEBUG(D_SEC, "processing rule: %s.%s\n", target, param);
-
-        /* parse rule to make sure the format is correct */
-        if (strncmp(param, PARAM_SRPC_FLVR, sizeof(PARAM_SRPC_FLVR) - 1) != 0) {
-                CERROR("Invalid sptlrpc parameter: %s\n", param);
-                RETURN(-EINVAL);
-        }
-        param += sizeof(PARAM_SRPC_FLVR) - 1;
-
-        rc = sptlrpc_parse_rule(param, &rule);
-        if (rc)
-                RETURN(-EINVAL);
-
-        if (conf == NULL) {
-               obdname2fsname(target, fsname, sizeof(fsname));
+       if (!conf) {
+               if (!fsname)
+                       return -ENODEV;
 
                mutex_lock(&sptlrpc_conf_lock);
 
                mutex_lock(&sptlrpc_conf_lock);
-                conf = sptlrpc_conf_get(fsname, 0);
-                if (conf == NULL) {
-                        CERROR("can't find conf\n");
-                        rc = -ENOMEM;
-                } else {
-                        rc = sptlrpc_conf_merge_rule(conf, target, &rule);
-                }
+               conf = sptlrpc_conf_get(fsname, 0);
+               if (!conf) {
+                       CERROR("can't find conf\n");
+                       rc = -ENOMEM;
+               } else {
+                       rc = sptlrpc_conf_merge_rule(conf, target, rule);
+               }
                mutex_unlock(&sptlrpc_conf_lock);
                mutex_unlock(&sptlrpc_conf_lock);
-        } else {
+       } else {
                LASSERT(mutex_is_locked(&sptlrpc_conf_lock));
                LASSERT(mutex_is_locked(&sptlrpc_conf_lock));
-                rc = sptlrpc_conf_merge_rule(conf, target, &rule);
-        }
+               rc = sptlrpc_conf_merge_rule(conf, target, rule);
+       }
 
 
-        if (rc == 0)
-                conf->sc_modified++;
+       if (!rc)
+               conf->sc_modified++;
 
 
-        RETURN(rc);
+       RETURN(rc);
 }
 
 int sptlrpc_process_config(struct lustre_cfg *lcfg)
 {
 }
 
 int sptlrpc_process_config(struct lustre_cfg *lcfg)
 {
-        return __sptlrpc_process_config(lcfg, NULL);
+       char fsname[MTI_NAME_MAXLEN];
+       struct sptlrpc_rule rule;
+       char *target, *param;
+       int rc;
+
+       print_lustre_cfg(lcfg);
+
+       target = lustre_cfg_string(lcfg, 1);
+       if (!target) {
+               CERROR("missing target name\n");
+               return -EINVAL;
+       }
+
+       param = lustre_cfg_string(lcfg, 2);
+       if (!param) {
+               CERROR("missing parameter\n");
+               return -EINVAL;
+       }
+
+       /* parse rule to make sure the format is correct */
+       if (strncmp(param, PARAM_SRPC_FLVR,
+                   sizeof(PARAM_SRPC_FLVR) - 1) != 0) {
+               CERROR("Invalid sptlrpc parameter: %s\n", param);
+               return -EINVAL;
+       }
+       param += sizeof(PARAM_SRPC_FLVR) - 1;
+
+       CDEBUG(D_SEC, "processing rule: %s.%s\n", target, param);
+
+       /*
+        * Three types of targets exist for sptlrpc using conf_param
+        * 1.   '_mgs' which targets mgc srpc settings. Treat it as
+        *      as a special file system name.
+        * 2.   target is a device which can be fsname-MDTXXXX or
+        *      fsname-OSTXXXX. This can be verified by the function
+        *      server_name2fsname.
+        * 3.   If both above conditions are not meet then the target
+        *      is a actual filesystem.
+        */
+       if (server_name2fsname(target, fsname, NULL))
+               strlcpy(fsname, target, sizeof(target));
+
+       rc = sptlrpc_parse_rule(param, &rule);
+       if (rc)
+               return rc;
+
+       return __sptlrpc_process_config(target, fsname, &rule, NULL);
 }
 EXPORT_SYMBOL(sptlrpc_process_config);
 
 }
 EXPORT_SYMBOL(sptlrpc_process_config);