Whamcloud - gitweb
LU-4749 mgs: Recognize colons in failover.node values
[fs/lustre-release.git] / lustre / mgs / mgs_llog.c
index aca72e3..1fbc87d 100644 (file)
@@ -1068,9 +1068,10 @@ static int mgs_replace_nids_log(const struct lu_env *env,
        if (!mrul)
                GOTO(out_close, rc = -ENOMEM);
        /* devname is only needed information to replace UUID records */
-       strncpy(mrul->target.mti_svname, devname, MTI_NAME_MAXLEN);
+       strlcpy(mrul->target.mti_svname, devname,
+               sizeof(mrul->target.mti_svname));
        /* parse nids later */
-       strncpy(mrul->target.mti_params, nids, MTI_PARAM_MAXLEN);
+       strlcpy(mrul->target.mti_params, nids, sizeof(mrul->target.mti_params));
        /* Copy records to this temporary llog */
        mrul->temp_llh = orig_llh;
 
@@ -1882,7 +1883,12 @@ static int mgs_write_log_failnids(const struct lu_env *env,
         #07 L add_conn 0:OSC_uml1_ost1_mdsA  1:uml2_UUID
         */
 
-        /* Pull failnid info out of params string */
+       /*
+        * Pull failnid info out of params string, which may contain something
+        * like "<nid1>,<nid2>:<nid3>,<nid4>".  class_parse_nid() does not
+        * complain about abnormal inputs like ",:<nid1>", "<nid1>:,<nid2>",
+        * etc.  However, convert_hostnames() should have caught those.
+        */
         while (class_find_param(ptr, PARAM_FAILNODE, &ptr) == 0) {
                 while (class_parse_nid(ptr, &nid, &ptr) == 0) {
                         if (failnodeuuid == NULL) {
@@ -1897,15 +1903,25 @@ static int mgs_write_log_failnids(const struct lu_env *env,
                                "client %s\n", libcfs_nid2str(nid),
                                failnodeuuid, cliname);
                        rc = record_add_uuid(env, llh, nid, failnodeuuid);
-                }
+                       /*
+                        * If *ptr is ':', we have added all NIDs for
+                        * failnodeuuid.
+                        */
+                       if (*ptr == ':') {
+                               rc = record_add_conn(env, llh, cliname,
+                                                    failnodeuuid);
+                               name_destroy(&failnodeuuid);
+                               failnodeuuid = NULL;
+                       }
+               }
                if (failnodeuuid) {
                        rc = record_add_conn(env, llh, cliname, failnodeuuid);
                        name_destroy(&failnodeuuid);
                        failnodeuuid = NULL;
                }
-        }
+       }
 
-        return rc;
+       return rc;
 }
 
 static int mgs_write_log_mdc_to_lmv(const struct lu_env *env,
@@ -3861,9 +3877,7 @@ int mgs_setparam(const struct lu_env *env, struct mgs_device *mgs,
                         RETURN(-EINVAL);
         } else {
                 /* assume devname is the fsname */
-               memset(fsname, 0, MTI_NAME_MAXLEN);
-                strncpy(fsname, devname, MTI_NAME_MAXLEN);
-               fsname[MTI_NAME_MAXLEN - 1] = 0;
+               strlcpy(fsname, devname, MTI_NAME_MAXLEN);
         }
         CDEBUG(D_MGS, "setparam fs='%s' device='%s'\n", fsname, devname);