Whamcloud - gitweb
LU-1203 mdt: map old params to new ones by using an array
authorYu Jian <yujian@whamcloud.com>
Fri, 31 Aug 2012 11:02:30 +0000 (19:02 +0800)
committerOleg Drokin <green@whamcloud.com>
Thu, 6 Sep 2012 18:21:10 +0000 (14:21 -0400)
This patch improves mdt_process_config() to use an array for
mapping old params to new ones.

The patch also adds a common function class_find_old_param()
to check whether a proc param is an old one or not, and return
new one if it's an old one.

Signed-off-by: Yu Jian <yujian@whamcloud.com>
Change-Id: I122e4e83a3f4e84a3fdbd3fe6a69b7c1b5e08d3f
Reviewed-on: http://review.whamcloud.com/3836
Tested-by: Hudson
Reviewed-by: Niu Yawei <niu@whamcloud.com>
Reviewed-by: Liang Zhen <liang@whamcloud.com>
Tested-by: Maloo <whamcloud.maloo@gmail.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lustre/include/lustre_param.h
lustre/mdt/mdt_handler.c
lustre/obdclass/obd_config.c

index 2623610..b9d6052 100644 (file)
  * @{
  */
 
+/* For interoperability between 1.8 and 2.0. */
+struct cfg_interop_param {
+       char *old_param;
+       char *new_param;
+};
+
 /* obd_config.c */
 int class_find_param(char *buf, char *key, char **valp);
+struct cfg_interop_param *class_find_old_param(const char *param,
+                                              struct cfg_interop_param *ptr);
 int class_get_next_param(char **params, char *copy);
 int class_match_param(char *buf, char *key, char **valp);
 int class_parse_nid(char *buf, lnet_nid_t *nid, char **endh);
index 67645f6..4ed6d5e 100644 (file)
@@ -4906,13 +4906,13 @@ err_lmi:
 }
 
 /* For interoperability between 1.8 and 2.0. */
-#define CFG_GROUP_UPCALL       "mdt.group_upcall"
-#define CFG_QUOTA_TYPE_OLD     "mdt.quota_type"
-#define CFG_QUOTA_TYPE_NEW     "mdd.quota_type"
-#define CFG_ROOT_SQUASH_OLD    "mdt.rootsquash"
-#define CFG_ROOT_SQUASH_NEW    "mdt.root_squash"
-#define CFG_NOSQUASH_NID_OLD   "mdt.nosquash_nid"
-#define CFG_NOSQUASH_NID_NEW   "mdt.nosquash_nids"
+static struct cfg_interop_param mdt_interop_param[] = {
+       { "mdt.group_upcall",   NULL },
+       { "mdt.quota_type",     "mdd.quota_type" },
+       { "mdt.rootsquash",     "mdt.root_squash" },
+       { "mdt.nosquash_nid",   "mdt.nosquash_nids" },
+       { NULL }
+};
 
 /* used by MGS to process specific configurations */
 static int mdt_process_config(const struct lu_env *env,
@@ -4930,9 +4930,9 @@ static int mdt_process_config(const struct lu_env *env,
                struct obd_device          *obd = d->ld_obd;
 
                /* For interoperability between 1.8 and 2.0. */
+               struct cfg_interop_param   *ptr = NULL;
                struct lustre_cfg          *old_cfg = NULL;
                char                       *param = NULL;
-               char                       *new_name = NULL;
 
                param = lustre_cfg_string(cfg, 1);
                if (param == NULL) {
@@ -4941,43 +4941,19 @@ static int mdt_process_config(const struct lu_env *env,
                        break;
                }
 
-               /* Skip old "mdt.group_upcall" param. */
-               if (strncmp(param, CFG_GROUP_UPCALL,
-                           strlen(CFG_GROUP_UPCALL)) == 0) {
-                       CWARN("For 1.8 interoperability, skip this %s."
-                             " It is obsolete.\n", CFG_GROUP_UPCALL);
-                       break;
-               }
-
-               /* Rename old "mdt.quota_type" to "mdd.quota_type". */
-               if (strncmp(param, CFG_QUOTA_TYPE_OLD,
-                           strlen(CFG_QUOTA_TYPE_OLD)) == 0) {
-                       CWARN("Found old param %s, changed it to %s.\n",
-                             CFG_QUOTA_TYPE_OLD, CFG_QUOTA_TYPE_NEW);
-                       new_name = CFG_QUOTA_TYPE_NEW;
+               ptr = class_find_old_param(param, mdt_interop_param);
+               if (ptr != NULL) {
+                       if (ptr->new_param == NULL) {
+                               CWARN("For 1.8 interoperability, skip this %s."
+                                     " It is obsolete.\n", ptr->old_param);
+                                       break;
+                       }
 
-               } else if (strncmp(param, CFG_ROOT_SQUASH_OLD,
-                                  strlen(CFG_ROOT_SQUASH_OLD)) == 0) {
-                       /* Rename old "mdt.rootsquash" to "mdt.root_squash". */
                        CWARN("Found old param %s, changed it to %s.\n",
-                             CFG_ROOT_SQUASH_OLD, CFG_ROOT_SQUASH_NEW);
-                       new_name = CFG_ROOT_SQUASH_NEW;
-
-               } else if (strncmp(param, CFG_NOSQUASH_NID_OLD,
-                                  strlen(CFG_NOSQUASH_NID_OLD)) == 0 &&
-                          param[strlen(CFG_NOSQUASH_NID_OLD)] != 's') {
-                       /*
-                        * Rename old "mdt.nosquash_nid" to
-                        * "mdt.nosquash_nids".
-                        */
-                       CWARN("Found old param %s, changed it to %s.\n",
-                             CFG_NOSQUASH_NID_OLD, CFG_NOSQUASH_NID_NEW);
-                       new_name = CFG_NOSQUASH_NID_NEW;
-               }
+                             ptr->old_param, ptr->new_param);
 
-               if (new_name != NULL) {
                        old_cfg = cfg;
-                       cfg = lustre_cfg_rename(old_cfg, new_name);
+                       cfg = lustre_cfg_rename(old_cfg, ptr->new_param);
                        if (IS_ERR(cfg)) {
                                rc = PTR_ERR(cfg);
                                break;
index 7d82c5b..1ac5b87 100644 (file)
@@ -77,6 +77,47 @@ int class_find_param(char *buf, char *key, char **valp)
 EXPORT_SYMBOL(class_find_param);
 
 /**
+ * Check whether the proc parameter \a param is an old parameter or not from
+ * the array \a ptr which contains the mapping from old parameters to new ones.
+ * If it's an old one, then return the pointer to the cfg_interop_param struc-
+ * ture which contains both the old and new parameters.
+ *
+ * \param param                        proc parameter
+ * \param ptr                  an array which contains the mapping from
+ *                             old parameters to new ones
+ *
+ * \retval valid-pointer       pointer to the cfg_interop_param structure
+ *                             which contains the old and new parameters
+ * \retval NULL                        \a param or \a ptr is NULL,
+ *                             or \a param is not an old parameter
+ */
+struct cfg_interop_param *class_find_old_param(const char *param,
+                                              struct cfg_interop_param *ptr)
+{
+       char *value = NULL;
+       int   name_len = 0;
+
+       if (param == NULL || ptr == NULL)
+               RETURN(NULL);
+
+       value = strchr(param, '=');
+       if (value == NULL)
+               name_len = strlen(param);
+       else
+               name_len = value - param;
+
+       while (ptr->old_param != NULL) {
+               if (strncmp(param, ptr->old_param, name_len) == 0 &&
+                   name_len == strlen(ptr->old_param))
+                       RETURN(ptr);
+               ptr++;
+       }
+
+       RETURN(NULL);
+}
+EXPORT_SYMBOL(class_find_old_param);
+
+/**
  * Finds a parameter in \a params and copies it to \a copy.
  *
  * Leading spaces are skipped. Next space or end of string is the