Whamcloud - gitweb
LU-7481 utils: label lustre device correctly 45/24845/3
authorHongchao Zhang <hongchao.zhang@intel.com>
Sat, 8 Oct 2016 19:49:33 +0000 (03:49 +0800)
committerOleg Drokin <oleg.drokin@intel.com>
Tue, 24 Jan 2017 05:24:06 +0000 (05:24 +0000)
Currently, the device label will be read before mounting Lustre,
the flags LDD_F_VIRGIN and LDD_F_WRITECONF will be set according
to the label (the corresponding original flags containing in the
lustre_disk_data will be ignored). But the device label could be
changed during mount by the journal recovery, and the device should
be also labeled to indicate the target device is supposed to start.

Test-Parameters: testlist=conf-sanity,conf-sanity,conf-sanity

Change-Id: I2df1d81f764a7d1ffa26afb0197d137c057a25e9
Signed-off-by: Hongchao Zhang <hongchao.zhang@intel.com>
Reviewed-on: https://review.whamcloud.com/24845
Reviewed-by: Andreas Dilger <andreas.dilger@intel.com>
Tested-by: Jenkins
Tested-by: Maloo <hpdd-maloo@intel.com>
Reviewed-by: Jian Yu <jian.yu@intel.com>
Reviewed-by: Fan Yong <fan.yong@intel.com>
Reviewed-by: Oleg Drokin <oleg.drokin@intel.com>
lustre/utils/mount_lustre.c

index 75d17b2..1126748 100644 (file)
@@ -684,6 +684,34 @@ static int parse_opts(int argc, char *const argv[], struct mount_opts *mop)
        return 0;
 }
 
+/* change label from <fsname>:<index> to
+ * <fsname>-<index> to indicate the device has
+ * been registered. only if the label is
+ * supposed to be changed and target service
+ * is supposed to start */
+static void label_lustre(struct mount_opts *mop)
+{
+       if (mop->mo_nosvc)
+               return;
+
+       if (mop->mo_ldd.ldd_flags & (LDD_F_VIRGIN | LDD_F_WRITECONF)) {
+               (void)osd_label_lustre(mop);
+       } else {
+               struct lustre_disk_data ldd;
+               int rc;
+
+               /* device label could be changed after journal recovery,
+                * it should also be relabeled for mount has succeeded. */
+               memset(&ldd, 0, sizeof(ldd));
+               rc = osd_read_ldd(mop->mo_source, &ldd);
+               if (rc == 0) {
+                       rc = strlen(ldd.ldd_svname);
+                       if (rc >= 8 && ldd.ldd_svname[rc - 8] != '-')
+                               (void)osd_label_lustre(mop);
+               }
+       }
+}
+
 int main(int argc, char *const argv[])
 {
        struct mount_opts mop;
@@ -819,16 +847,7 @@ int main(int argc, char *const argv[])
                        rc = mount(mop.mo_source, mop.mo_target, "lustre",
                                   flags, (void *)options);
                        if (rc == 0) {
-                               /* change label from <fsname>:<index> to
-                                * <fsname>-<index> to indicate the device has
-                                *  been registered. only if the label is
-                                *  supposed to be changed and target service
-                                *  is supposed to start */
-                               if (mop.mo_ldd.ldd_flags &
-                                  (LDD_F_VIRGIN | LDD_F_WRITECONF)) {
-                                       if (mop.mo_nosvc == 0)
-                                               (void)osd_label_lustre(&mop);
-                               }
+                               label_lustre(&mop);
                        } else {
                                 if (verbose) {
                                         fprintf(stderr, "%s: mount %s at %s "