Whamcloud - gitweb
LU-1287 mountconf: write failover nid config correctly
authorLai Siyao <laisiyao@whamcloud.com>
Thu, 14 Jun 2012 10:21:00 +0000 (18:21 +0800)
committerOleg Drokin <green@whamcloud.com>
Mon, 17 Dec 2012 06:32:51 +0000 (01:32 -0500)
Once OST starts before MDT, MDT needs steal OSC config from client
config, but both target nids and failover nids are stored as the
same type of config LCFG_ADD_UUID. To handle this correctly, all
LCFG_ADD_UUID before LCFG_SETUP is treated as target nids, while
after as failover nids. NB this implies that records should be
written into config file in fixed order.

Signed-off-by: Lai Siyao <laisiyao@whamcloud.com>
Change-Id: I42d014911edad1bc53bb1a66def160ee0da3e670
Reviewed-on: http://review.whamcloud.com/3107
Reviewed-by: Sebastien Buisson <sebastien.buisson@bull.net>
Reviewed-by: Mike Pershin <mike.pershin@intel.com>
Tested-by: Hudson
Tested-by: Maloo <whamcloud.maloo@gmail.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lustre/mgs/mgs_llog.c

index d20b59e..911edb2 100644 (file)
@@ -1106,6 +1106,24 @@ static int mgs_write_log_osc_to_lov(const struct lu_env *env,
 static int name_create_mdt_and_lov(char **logname, char **lovname,
                                   struct fs_db *fsdb, int i);
 
+static int add_param(char *params, char *key, char *val)
+{
+       char *start = params + strlen(params);
+       char *end = params + sizeof(((struct mgs_target_info *)0)->mti_params);
+       int keylen = 0;
+
+       if (key != NULL)
+               keylen = strlen(key);
+       if (start + 1 + keylen + strlen(val) >= end) {
+               CERROR("params are too long: %s %s%s\n",
+                      params, key != NULL ? key : "", val);
+               return -EINVAL;
+       }
+
+       sprintf(start, " %s%s", key != NULL ? key : "", val);
+       return 0;
+}
+
 static int mgs_steal_llog_handler(const struct lu_env *env,
                                  struct llog_handle *llh,
                                  struct llog_rec_hdr *rec, void *data)
@@ -1201,15 +1219,23 @@ static int mgs_steal_llog_handler(const struct lu_env *env,
         if (got_an_osc_or_mdc == 0 || last_step < 0)
                 RETURN(rc);
 
-        if (lcfg->lcfg_command == LCFG_ADD_UUID) {
-                uint64_t nodenid;
-                nodenid = lcfg->lcfg_nid;
+       if (lcfg->lcfg_command == LCFG_ADD_UUID) {
+               uint64_t nodenid = lcfg->lcfg_nid;
 
-                tmti->mti_nids[tmti->mti_nid_count] = nodenid;
-                tmti->mti_nid_count++;
+               if (strlen(tmti->mti_uuid) == 0) {
+                       /* target uuid not set, this config record is before
+                        * LCFG_SETUP, this nid is one of target node nid.
+                        */
+                       tmti->mti_nids[tmti->mti_nid_count] = nodenid;
+                       tmti->mti_nid_count++;
+               } else {
+                       /* failover node nid */
+                       rc = add_param(tmti->mti_params, PARAM_FAILNODE,
+                                      libcfs_nid2str(nodenid));
+               }
 
-                RETURN(rc);
-        }
+               RETURN(rc);
+       }
 
         if (lcfg->lcfg_command == LCFG_SETUP) {
                 char *target;
@@ -1892,11 +1918,18 @@ static int mgs_write_log_osc_to_lov(const struct lu_env *env,
        rc = record_start_log(env, mgs, &llh, logname);
         if (rc)
                GOTO(out_free, rc);
+
         /* FIXME these should be a single journal transaction */
        rc = record_marker(env, llh, fsdb, CM_START | flags, mti->mti_svname,
                            "add osc");
        if (rc)
                GOTO(out_end, rc);
+
+       /* NB: don't change record order, because upon MDT steal OSC config
+        * from client, it treats all nids before LCFG_SETUP as target nids
+        * (multiple interfaces), while nids after as failover node nids.
+        * See mgs_steal_llog_handler() LCFG_ADD_UUID.
+        */
         for (i = 0; i < mti->mti_nid_count; i++) {
                 CDEBUG(D_MGS, "add nid %s\n", libcfs_nid2str(mti->mti_nids[i]));
                rc = record_add_uuid(env, llh, mti->mti_nids[i], nodeuuid);