Whamcloud - gitweb
LU-1581 mount: kernel do not parse ldd
authorAlex Zhuravlev <bzzz@whamcloud.com>
Tue, 31 Jul 2012 11:42:29 +0000 (15:42 +0400)
committerOleg Drokin <green@whamcloud.com>
Thu, 6 Sep 2012 02:47:54 +0000 (22:47 -0400)
all ldd parsing is done by mount.lustre utility now.

Signed-off-by: Alex Zhuravlev <bzzz@whamcloud.com>
Change-Id: Ice15cf4fa8e411144713d0276d006f8cfe9c56f1
Reviewed-on: http://review.whamcloud.com/3613
Tested-by: Hudson
Tested-by: Maloo <whamcloud.maloo@gmail.com>
Reviewed-by: Jinshan Xiong <jinshan.xiong@whamcloud.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
lustre/include/lustre_disk.h
lustre/mgc/mgc_request.c
lustre/mgs/mgs_llog.c
lustre/obdclass/obd_mount.c
lustre/tests/conf-sanity.sh
lustre/utils/mkfs_lustre.c
lustre/utils/mount_lustre.c
lustre/utils/mount_utils.h
lustre/utils/mount_utils_ldiskfs.c

index 3cac2c7..7ccce88 100644 (file)
@@ -183,7 +183,8 @@ static inline int server_make_name(__u32 flags, __u16 index, char *fs,
         if (flags & (LDD_F_SV_TYPE_MDT | LDD_F_SV_TYPE_OST)) {
                 if (!(flags & LDD_F_SV_ALL))
                        sprintf(name, "%.8s%c%s%04x", fs,
-                               (flags & LDD_F_VIRGIN) ? ':' : '-',
+                               (flags & LDD_F_VIRGIN) ? ':' :
+                                       ((flags & LDD_F_WRITECONF) ? '=' : '-'),
                                (flags & LDD_F_SV_TYPE_MDT) ? "MDT" : "OST",
                                index);
         } else if (flags & LDD_F_SV_TYPE_MGS) {
@@ -219,6 +220,7 @@ struct lustre_mount_data {
         char      *lmd_mgssec;        /* sptlrpc flavor to mgs */
         char      *lmd_opts;          /* lustre mount options (as opposed to
                                          _device_ mount options) */
+       char      *lmd_params;        /* lustre params */
         __u32     *lmd_exclude;       /* array of OSTs to ignore */
        char    *lmd_mgs;           /* MGS nid */
        char    *lmd_osd_type;      /* OSD type */
@@ -234,6 +236,10 @@ struct lustre_mount_data {
 #define LMD_FLG_WRITECONF    0x0040  /* Rewrite config log */
 #define LMD_FLG_NOIR         0x0080  /* NO imperative recovery */
 #define LMD_FLG_NOSCRUB             0x0100  /* Do not trigger scrub automatically */
+#define LMD_FLG_MGS         0x0200  /* Also start MGS along with server */
+#define LMD_FLG_IAM         0x0400  /* IAM dir */
+#define LMD_FLG_NO_PRIMNODE  0x0800  /* all nodes are service nodes */
+#define LMD_FLG_VIRGIN      0x1000  /* the service registers first time */
 
 #define lmd_is_client(x) ((x)->lmd_flags & LMD_FLG_CLIENT)
 
index 6364022..67df5eb 100644 (file)
@@ -1723,7 +1723,7 @@ static int mgc_process_cfg_log(struct obd_device *mgc,
            running an MGS though (logs are already local). */
         if (lctxt && lsi && (lsi->lsi_flags & LSI_SERVER) &&
             (lsi->lsi_srv_mnt == cli->cl_mgc_vfsmnt) &&
-           !IS_MGS(lsi->lsi_ldd) && lsi->lsi_lmd->lmd_osd_type == NULL) {
+           !IS_MGS(lsi->lsi_ldd) && lsi->lsi_srv_mnt) {
                 push_ctxt(saved_ctxt, &mgc->obd_lvfs_ctxt, NULL);
                 must_pop++;
                 if (!local_only)
index 98a1108..10016d9 100644 (file)
@@ -600,8 +600,8 @@ static int mgs_set_index(struct obd_device *obd, struct mgs_target_info *mti)
 
         cfs_set_bit(mti->mti_stripe_index, imap);
         cfs_clear_bit(FSDB_LOG_EMPTY, &fsdb->fsdb_flags);
-       server_make_name(mti->mti_flags & ~LDD_F_VIRGIN, mti->mti_stripe_index,
-                         mti->mti_fsname, mti->mti_svname);
+       server_make_name(mti->mti_flags & ~(LDD_F_VIRGIN | LDD_F_WRITECONF),
+                        mti->mti_stripe_index, mti->mti_fsname, mti->mti_svname);
 
         CDEBUG(D_MGS, "Set index for %s to %d\n", mti->mti_svname,
                mti->mti_stripe_index);
index 1335646..bc08b46 100644 (file)
@@ -272,139 +272,6 @@ int server_put_mount_2(const char *name, struct vfsmount *mnt)
 }
 EXPORT_SYMBOL(server_put_mount_2);
 
-/******* mount helper utilities *********/
-
-#if 0
-static void ldd_print(struct lustre_disk_data *ldd)
-{
-        PRINT_CMD(PRINT_MASK, "  disk data:\n");
-        PRINT_CMD(PRINT_MASK, "server:  %s\n", ldd->ldd_svname);
-        PRINT_CMD(PRINT_MASK, "uuid:    %s\n", (char *)ldd->ldd_uuid);
-        PRINT_CMD(PRINT_MASK, "fs:      %s\n", ldd->ldd_fsname);
-        PRINT_CMD(PRINT_MASK, "index:   %04x\n", ldd->ldd_svindex);
-        PRINT_CMD(PRINT_MASK, "config:  %d\n", ldd->ldd_config_ver);
-        PRINT_CMD(PRINT_MASK, "flags:   %#x\n", ldd->ldd_flags);
-        PRINT_CMD(PRINT_MASK, "diskfs:  %s\n", MT_STR(ldd));
-        PRINT_CMD(PRINT_MASK, "options: %s\n", ldd->ldd_mount_opts);
-        PRINT_CMD(PRINT_MASK, "params:  %s\n", ldd->ldd_params);
-        PRINT_CMD(PRINT_MASK, "comment: %s\n", ldd->ldd_userdata);
-}
-#endif
-
-static int ldd_parse(struct lvfs_run_ctxt *mount_ctxt,
-                     struct lustre_disk_data *ldd)
-{
-        struct lvfs_run_ctxt saved;
-        struct file *file;
-        loff_t off = 0;
-        unsigned long len;
-        int rc;
-        ENTRY;
-
-        push_ctxt(&saved, mount_ctxt, NULL);
-
-        file = filp_open(MOUNT_DATA_FILE, O_RDONLY, 0644);
-        if (IS_ERR(file)) {
-                rc = PTR_ERR(file);
-                CERROR("cannot open %s: rc = %d\n", MOUNT_DATA_FILE, rc);
-                GOTO(out, rc);
-        }
-
-        len = i_size_read(file->f_dentry->d_inode);
-        CDEBUG(D_MOUNT, "Have %s, size %lu\n", MOUNT_DATA_FILE, len);
-        if (len != sizeof(*ldd)) {
-                CERROR("disk data size does not match: see %lu expect %u\n",
-                       len, (int)sizeof(*ldd));
-                GOTO(out_close, rc = -EINVAL);
-        }
-
-        rc = lustre_fread(file, ldd, len, &off);
-        if (rc != len) {
-                CERROR("error reading %s: read %d of %lu\n",
-                       MOUNT_DATA_FILE, rc, len);
-                GOTO(out_close, rc = -EINVAL);
-        }
-        rc = 0;
-
-        if (ldd->ldd_magic != LDD_MAGIC) {
-                /* FIXME add swabbing support */
-                CERROR("Bad magic in %s: %x!=%x\n", MOUNT_DATA_FILE,
-                       ldd->ldd_magic, LDD_MAGIC);
-                GOTO(out_close, rc = -EINVAL);
-        }
-
-        if (ldd->ldd_feature_incompat & ~LDD_INCOMPAT_SUPP) {
-                CERROR("%s: unsupported incompat filesystem feature(s) %x\n",
-                       ldd->ldd_svname,
-                       ldd->ldd_feature_incompat & ~LDD_INCOMPAT_SUPP);
-                GOTO(out_close, rc = -EINVAL);
-        }
-        if (ldd->ldd_feature_rocompat & ~LDD_ROCOMPAT_SUPP) {
-                CERROR("%s: unsupported read-only filesystem feature(s) %x\n",
-                       ldd->ldd_svname,
-                       ldd->ldd_feature_rocompat & ~LDD_ROCOMPAT_SUPP);
-                /* Do something like remount filesystem read-only */
-                GOTO(out_close, rc = -EINVAL);
-        }
-
-       /* svname of the form lustre:OST1234 means never registered */
-       rc = strlen(ldd->ldd_svname);
-       if (ldd->ldd_svname[rc - 8] == ':') {
-               ldd->ldd_svname[rc - 8] = '-';
-               ldd->ldd_flags |= LDD_F_VIRGIN;
-       }
-       rc = 0;
-
-out_close:
-        filp_close(file, 0);
-out:
-        pop_ctxt(&saved, mount_ctxt, NULL);
-        RETURN(rc);
-}
-
-static int ldd_write(struct lvfs_run_ctxt *mount_ctxt,
-                     struct lustre_disk_data *ldd)
-{
-        struct lvfs_run_ctxt saved;
-        struct file *file;
-        loff_t off = 0;
-        unsigned long len = sizeof(struct lustre_disk_data);
-        int rc = 0;
-        ENTRY;
-
-       if (ldd->ldd_magic == 0)
-               RETURN(0);
-
-        LASSERT(ldd->ldd_magic == LDD_MAGIC);
-
-        ldd->ldd_config_ver++;
-
-        push_ctxt(&saved, mount_ctxt, NULL);
-
-        file = filp_open(MOUNT_DATA_FILE, O_RDWR|O_SYNC, 0644);
-        if (IS_ERR(file)) {
-                rc = PTR_ERR(file);
-                CERROR("cannot open %s: rc = %d\n", MOUNT_DATA_FILE, rc);
-                GOTO(out, rc);
-        }
-
-        rc = lustre_fwrite(file, ldd, len, &off);
-        if (rc != len) {
-                CERROR("error writing %s: read %d of %lu\n",
-                       MOUNT_DATA_FILE, rc, len);
-                GOTO(out_close, rc = -EINVAL);
-        }
-
-        rc = 0;
-
-out_close:
-        filp_close(file, 0);
-out:
-        pop_ctxt(&saved, mount_ctxt, NULL);
-        RETURN(rc);
-}
-
-
 /**************** config llog ********************/
 
 /** Get a config log from the MGS and process it.
@@ -1063,13 +930,13 @@ static int server_sb2mti(struct super_block *sb, struct mgs_target_info *mti)
 
                 /* server use --servicenode param, only allow specified
                  * nids be registered */
-                if ((ldd->ldd_flags & LDD_F_NO_PRIMNODE) != 0 &&
-                    class_match_nid(ldd->ldd_params,
+               if ((lsi->lsi_lmd->lmd_flags & LMD_FLG_NO_PRIMNODE) != 0 &&
+                   class_match_nid(lsi->lsi_lmd->lmd_params,
                                     PARAM_FAILNODE, id.nid) < 1)
                         continue;
 
                 /* match specified network */
-                if (!class_match_net(ldd->ldd_params,
+               if (!class_match_net(lsi->lsi_lmd->lmd_params,
                                      PARAM_NETWORK, LNET_NIDNET(id.nid)))
                         continue;
 
@@ -1093,7 +960,8 @@ static int server_sb2mti(struct super_block *sb, struct mgs_target_info *mti)
                 CERROR("params too big for mti\n");
                 RETURN(-ENOMEM);
         }
-        memcpy(mti->mti_params, ldd->ldd_params, sizeof(mti->mti_params));
+       strncpy(mti->mti_params, lsi->lsi_lmd->lmd_params,
+                       sizeof(mti->mti_params));
         RETURN(0);
 }
 
@@ -1153,36 +1021,6 @@ int server_register_target(struct super_block *sb)
                 GOTO(out, rc);
         }
 
-        /* Always update our flags */
-        ldd->ldd_flags = mti->mti_flags & LDD_F_ONDISK_MASK;
-
-        /* If this flag is set, it means the MGS wants us to change our
-           on-disk data. (So far this means just the index.) */
-        if (mti->mti_flags & LDD_F_REWRITE_LDD) {
-                char *label;
-                int err;
-                CDEBUG(D_MOUNT, "Changing on-disk index from %#x to %#x "
-                       "for %s\n", ldd->ldd_svindex, mti->mti_stripe_index,
-                       mti->mti_svname);
-                ldd->ldd_svindex = mti->mti_stripe_index;
-                strncpy(ldd->ldd_svname, mti->mti_svname,
-                        sizeof(ldd->ldd_svname));
-                /* or ldd_make_sv_name(ldd); */
-                ldd_write(&mgc->obd_lvfs_ctxt, ldd);
-               if (lsi->lsi_lmd->lmd_osd_type)
-                       goto out;
-                err = fsfilt_set_label(mgc, lsi->lsi_srv_mnt->mnt_sb,
-                                       mti->mti_svname);
-                if (err)
-                        CERROR("Label set error %d\n", err);
-                label = fsfilt_get_label(mgc, lsi->lsi_srv_mnt->mnt_sb);
-                if (label)
-                        CDEBUG(D_MOUNT, "Disk label changed to %s\n", label);
-
-                /* Flush the new ldd to disk */
-                fsfilt_sync(mgc, lsi->lsi_srv_mnt->mnt_sb);
-        }
-
 out:
         if (mti)
                 OBD_FREE_PTR(mti);
@@ -1290,7 +1128,7 @@ static int server_start_targets(struct super_block *sb, struct vfsmount *mnt)
 
         /* Set the mgc fs to our server disk.  This allows the MGC to
          * read and write configs locally, in case it can't talk to the MGS. */
-       if (lsi->lsi_lmd->lmd_osd_type == NULL) {
+       if (lsi->lsi_srv_mnt) {
                rc = server_mgc_set_fs(lsi->lsi_mgc, sb);
                if (rc)
                        RETURN(rc);
@@ -1321,7 +1159,7 @@ static int server_start_targets(struct super_block *sb, struct vfsmount *mnt)
 
 out_mgc:
         /* Release the mgc fs for others to use */
-       if (lsi->lsi_lmd->lmd_osd_type == NULL)
+       if (lsi->lsi_srv_mnt)
                server_mgc_clear_fs(lsi->lsi_mgc);
 
         if (!rc) {
@@ -1416,6 +1254,8 @@ static int lustre_free_lsi(struct super_block *sb)
                if (lsi->lsi_lmd->lmd_osd_type != NULL)
                        OBD_FREE(lsi->lsi_lmd->lmd_osd_type,
                                 strlen(lsi->lsi_lmd->lmd_osd_type) + 1);
+               if (lsi->lsi_lmd->lmd_params != NULL)
+                       OBD_FREE(lsi->lsi_lmd->lmd_params, 4096);
 
                 OBD_FREE(lsi->lsi_lmd, sizeof(*lsi->lsi_lmd));
         }
@@ -1459,6 +1299,7 @@ static int lsi_prepare(struct lustre_sb_info *lsi)
                RETURN(-ENOMEM);
 
        strcpy(lsi->lsi_osd_type, LUSTRE_OSD_NAME);
+       ldd->ldd_mount_type = LDD_MT_LDISKFS;
 
        /* The server name is given as a mount line option */
        if (lsi->lsi_lmd->lmd_profile == NULL) {
@@ -1499,6 +1340,12 @@ static int lsi_prepare(struct lustre_sb_info *lsi)
        ldd->ldd_svindex = simple_strtoul(p + 4, NULL, 16);
        ldd->ldd_flags |= (lsi->lsi_lmd->lmd_flags & LMD_FLG_WRITECONF) ?
                                LDD_F_WRITECONF : 0;
+       ldd->ldd_flags |= (lsi->lsi_lmd->lmd_flags & LMD_FLG_VIRGIN) ?
+                               LDD_F_VIRGIN | LDD_F_UPDATE : 0;
+       ldd->ldd_flags |= (lsi->lsi_lmd->lmd_flags & LMD_FLG_MGS) ?
+                               LDD_F_SV_TYPE_MGS : 0;
+       ldd->ldd_flags |= (lsi->lsi_lmd->lmd_flags & LMD_FLG_NO_PRIMNODE) ?
+                               LDD_F_NO_PRIMNODE : 0;
 
        lsi->lsi_ldd = ldd;
 
@@ -1532,7 +1379,6 @@ err:
  */
 static struct vfsmount *server_kernel_mount(struct super_block *sb)
 {
-        struct lvfs_run_ctxt mount_ctxt;
         struct lustre_sb_info *lsi = s2lsi(sb);
         struct lustre_disk_data *ldd;
         struct lustre_mount_data *lmd = lsi->lsi_lmd;
@@ -1545,15 +1391,21 @@ static struct vfsmount *server_kernel_mount(struct super_block *sb)
         int rc;
         ENTRY;
 
-       if (lsi->lsi_lmd->lmd_osd_type) {
-               rc = lsi_prepare(lsi);
+       rc = lsi_prepare(lsi);
+       if (rc)
                RETURN(ERR_PTR(rc));
+
+       if (strcmp(lmd->lmd_osd_type, "osd-ldiskfs") == 0) {
+               /* with ldiskfs we're still mounting in the kernel space */
+               OBD_FREE(lmd->lmd_osd_type,
+                        strlen(lmd->lmd_osd_type) + 1);
+               lmd->lmd_osd_type = NULL;
+       } else {
+               /* non-ldiskfs backends (zfs) do mounting internally */
+               RETURN(NULL);
        }
 
-        OBD_ALLOC(ldd, sizeof(*ldd));
-        if (!ldd)
-                RETURN(ERR_PTR(-ENOMEM));
-       strcpy(lsi->lsi_osd_type, LUSTRE_OSD_NAME);
+       ldd = lsi->lsi_ldd;
 
         /* In the past, we have always used flags = 0.
            Note ext3/ldiskfs can't be mounted ro. */
@@ -1567,44 +1419,6 @@ static struct vfsmount *server_kernel_mount(struct super_block *sb)
         options = (char *)page;
         memset(options, 0, CFS_PAGE_SIZE);
 
-        /* mount-line options must be added for pre-mount because it may
-         * contain mount options such as journal_dev which are required
-         * to mount successfuly the underlying filesystem */
-        if (lmd->lmd_opts && (*(lmd->lmd_opts) != 0))
-                strncat(options, lmd->lmd_opts, CFS_PAGE_SIZE - 1);
-
-        /* Pre-mount ldiskfs to read the MOUNT_DATA_FILE */
-        CDEBUG(D_MOUNT, "Pre-mount ldiskfs %s\n", lmd->lmd_dev);
-        type = get_fs_type("ldiskfs");
-        if (!type) {
-                CERROR("premount failed: cannot find ldiskfs module\n");
-                GOTO(out_free, rc = -ENODEV);
-        }
-        mnt = vfs_kern_mount(type, s_flags, lmd->lmd_dev, (void *)options);
-        cfs_module_put(type->owner);
-        if (IS_ERR(mnt)) {
-                rc = PTR_ERR(mnt);
-                CERROR("premount %s:%#lx ldiskfs failed: %d "
-                        "Is the ldiskfs module available?\n",
-                        lmd->lmd_dev, s_flags, rc );
-                GOTO(out_free, rc);
-        }
-
-        OBD_SET_CTXT_MAGIC(&mount_ctxt);
-        mount_ctxt.pwdmnt = mnt;
-        mount_ctxt.pwd = mnt->mnt_root;
-        mount_ctxt.fs = get_ds();
-
-        rc = ldd_parse(&mount_ctxt, ldd);
-        unlock_mntput(mnt);
-
-        if (rc) {
-                CERROR("premount parse options failed: rc = %d\n", rc);
-                GOTO(out_free, rc);
-        }
-
-        /* Done with our pre-mount, now do the real mount. */
-
         /* Glom up mount options */
         memset(options, 0, CFS_PAGE_SIZE);
         strncpy(options, ldd->ldd_mount_opts, CFS_PAGE_SIZE - 2);
@@ -2332,6 +2146,11 @@ static int lmd_parse(char *options, struct lustre_mount_data *lmd)
         }
         lmd->lmd_magic = LMD_MAGIC;
 
+       OBD_ALLOC(lmd->lmd_params, 4096);
+       if (lmd->lmd_params == NULL)
+               RETURN(-ENOMEM);
+       lmd->lmd_params[0] = '\0';
+
         /* Set default flags here */
 
         s1 = options;
@@ -2383,6 +2202,12 @@ static int lmd_parse(char *options, struct lustre_mount_data *lmd)
                 } else if (strncmp(s1, "writeconf", 9) == 0) {
                         lmd->lmd_flags |= LMD_FLG_WRITECONF;
                         clear++;
+               } else if (strncmp(s1, "virgin", 6) == 0) {
+                       lmd->lmd_flags |= LMD_FLG_VIRGIN;
+                       clear++;
+               } else if (strncmp(s1, "noprimnode", 10) == 0) {
+                       lmd->lmd_flags |= LMD_FLG_NO_PRIMNODE;
+                       clear++;
                 } else if (strncmp(s1, "mgssec=", 7) == 0) {
                         rc = lmd_parse_mgssec(lmd, s1 + 7);
                         if (rc)
@@ -2394,22 +2219,30 @@ static int lmd_parse(char *options, struct lustre_mount_data *lmd)
                         if (rc)
                                 goto invalid;
                         clear++;
+               } else if (strncmp(s1, "mgs", 3) == 0) {
+                       /* We are an MGS */
+                       lmd->lmd_flags |= LMD_FLG_MGS;
+                       clear++;
                } else if (strncmp(s1, "svname=", 7) == 0) {
                        rc = lmd_parse_string(&lmd->lmd_profile, s1 + 7);
                        if (rc)
                                goto invalid;
                        clear++;
+               } else if (strncmp(s1, "param=", 6) == 0) {
+                       int length;
+                       char *tail = strchr(s1 + 6, ',');
+                       if (tail == NULL)
+                               length = strlen(s1);
+                       else
+                               length = tail - s1;
+                       length -= 6;
+                       strncat(lmd->lmd_params, s1 + 6, length);
+                       strcat(lmd->lmd_params, " ");
+                       clear++;
                } else if (strncmp(s1, "osd=", 4) == 0) {
                        rc = lmd_parse_string(&lmd->lmd_osd_type, s1 + 4);
                        if (rc)
                                goto invalid;
-                       /* with ldiskfs we're still doing ldd parsing
-                        * in the kernel space */
-                       if (!strcmp(lmd->lmd_osd_type, "osd-ldiskfs")) {
-                               OBD_FREE(lmd->lmd_osd_type,
-                                        strlen(lmd->lmd_osd_type) + 1);
-                               lmd->lmd_osd_type = NULL;
-                       }
                        clear++;
                 }
                 /* Linux 2.4 doesn't pass the device, so we stuck it at the
index e5dbb41..bc3a286 100644 (file)
@@ -11,7 +11,6 @@ ONLY=${ONLY:-"$*"}
 
 # bug number for skipped test:
 #               15977
-ALWAYS_EXCEPT="$CONF_SANITY_EXCEPT"
 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
 
 if [ "$FAILURE_MODE" = "HARD" ]; then
@@ -942,6 +941,9 @@ test_26() {
     lctl get_param -n devices
     DEVS=$(lctl get_param -n devices | egrep -v MG | wc -l)
     [ $DEVS -gt 0 ] && return 2
+    # start mds to drop writeconf setting
+    start_mds || return 3
+    stop_mds || return 4
     unload_modules_conf || return $?
 }
 run_test 26 "MDT startup failure cleans LOV (should return errs)"
index 483f512..bbf0854 100644 (file)
@@ -587,6 +587,8 @@ int main(int argc, char *const argv[])
                         "(%d)\n", mop.mo_device, ret);
                 goto out;
         }
+       mop.mo_ldd.ldd_flags &= ~(LDD_F_WRITECONF | LDD_F_VIRGIN);
+
         if (strstr(mop.mo_ldd.ldd_params, PARAM_MGSNODE))
             mop.mo_mgs_failnodes++;
 
@@ -747,6 +749,14 @@ int main(int argc, char *const argv[])
                 fprintf(stderr, "mkfs failed %d\n", ret);
                 goto out;
         }
+#else
+       /* update svname with '=' to refresh config */
+       if (mop.mo_ldd.ldd_flags & LDD_F_WRITECONF) {
+               struct mount_opts opts;
+               opts.mo_ldd = mop.mo_ldd;
+               opts.mo_source = mop.mo_device;
+               (void) osd_label_lustre(&opts);
+       }
 #endif
 
         /* Write our config files */
index 4364ea4..9be94a6 100644 (file)
@@ -241,6 +241,9 @@ int parse_options(struct mount_opts *mop, char *orig_options, int *flagp)
                                mop->mo_retry = 0;
                 } else if (val && strncmp(arg, "mgssec", 6) == 0) {
                         append_option(options, opt);
+               } else if (strncmp(arg, "nosvc", 5) == 0) {
+                       mop->mo_nosvc = 1;
+                       append_option(options, opt);
                 } else if (strcmp(opt, "force") == 0) {
                         //XXX special check for 'force' option
                        ++mop->mo_force;
@@ -290,6 +293,7 @@ static int add_mgsnids(struct mount_opts *mop, char *options,
 static int parse_ldd(char *source, struct mount_opts *mop, char *options)
 {
        struct lustre_disk_data *ldd = &mop->mo_ldd;
+       char *cur, *start;
        int rc;
 
        rc = osd_is_lustre(source, &ldd->ldd_mount_type);
@@ -300,15 +304,6 @@ static int parse_ldd(char *source, struct mount_opts *mop, char *options)
                return ENODEV;
        }
 
-       /* for new backends (i.e. ZFS) we will be parsing mount data
-        * in the userspace and pass it in the form of mount options.
-        * to adopt this schema smoothly we're still doing old way
-        * (parsing mount data within the kernel) for ldiskfs */
-       if (ldd->ldd_mount_type == LDD_MT_EXT3 ||
-           ldd->ldd_mount_type == LDD_MT_LDISKFS ||
-           ldd->ldd_mount_type == LDD_MT_LDISKFS2)
-               return 0;
-
        rc = osd_read_ldd(source, ldd);
        if (rc) {
                fprintf(stderr, "%s: %s failed to read permanent mount"
@@ -330,13 +325,16 @@ static int parse_ldd(char *source, struct mount_opts *mop, char *options)
        }
 
        /* Since we never rewrite ldd, ignore temp flags */
-       ldd->ldd_flags &= ~(LDD_F_VIRGIN | LDD_F_UPDATE);
+       ldd->ldd_flags &= ~(LDD_F_VIRGIN | LDD_F_UPDATE | LDD_F_WRITECONF);
 
        /* svname of the form lustre:OST1234 means never registered */
        rc = strlen(ldd->ldd_svname);
        if (ldd->ldd_svname[rc - 8] == ':') {
                ldd->ldd_svname[rc - 8] = '-';
                ldd->ldd_flags |= LDD_F_VIRGIN;
+       } else if (ldd->ldd_svname[rc - 8] == '=') {
+               ldd->ldd_svname[rc - 8] = '-';
+               ldd->ldd_flags |= LDD_F_WRITECONF;
        }
 
        /* backend osd type */
@@ -362,13 +360,32 @@ static int parse_ldd(char *source, struct mount_opts *mop, char *options)
                return EINVAL;
        }
 
-       if (ldd->ldd_flags & (LDD_F_VIRGIN | LDD_F_WRITECONF))
+       if (ldd->ldd_flags & LDD_F_VIRGIN)
+               append_option(options, "virgin");
+       if (ldd->ldd_flags & LDD_F_WRITECONF)
                append_option(options, "writeconf");
        if (ldd->ldd_flags & LDD_F_IAM_DIR)
                append_option(options, "iam");
        if (ldd->ldd_flags & LDD_F_NO_PRIMNODE)
                append_option(options, "noprimnode");
 
+       /* prefix every lustre parameter with param= so that in-kernel
+        * mount can recognize them properly and send to MGS at registration */
+       start = ldd->ldd_params;
+       while (start && *start != '\0') {
+               while (*start == ' ') start++;
+               if (*start == '\0')
+                       break;
+               cur = start;
+               start = strchr(cur, ' ');
+               if (start) {
+                       *start = '\0';
+                       start++;
+               }
+               append_option(options, "param=");
+               strcat(options, cur);
+       }
+
        /* svname must be last option */
        append_option(options, "svname=");
        strcat(options, ldd->ldd_svname);
@@ -388,6 +405,7 @@ static void set_defaults(struct mount_opts *mop)
        mop->mo_have_mgsnid = 0;
        mop->mo_md_stripe_cache_size = 16384;
        mop->mo_orig_options = "";
+       mop->mo_nosvc = 0;
 }
 
 static int parse_opts(int argc, char *const argv[], struct mount_opts *mop)
@@ -672,9 +690,13 @@ int main(int argc, char *const argv[])
                                       mop.mo_orig_options, 0,0,0);
 
                /* change label from <fsname>:<index> to <fsname>-<index>
-                * to indicate the device has been registered. */
-               if (mop.mo_ldd.ldd_flags & LDD_F_VIRGIN)
-                       (void) osd_label_lustre(&mop);
+                * 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);
+               }
         }
 
        free(options);
index a698cb5..d0eca33 100644 (file)
@@ -82,6 +82,7 @@ struct mount_opts {
        int      mo_retry;
        int      mo_have_mgsnid;
        int      mo_md_stripe_cache_size;
+       int      mo_nosvc;
 };
 
 int get_mountdata(char *, struct lustre_disk_data *);
index f863ac9..5554e84 100644 (file)
@@ -161,6 +161,25 @@ out_rmdir:
        return ret;
 }
 
+static int readcmd(char *cmd, char *buf, int len)
+{
+       FILE *fp;
+       int red;
+
+       fp = popen(cmd, "r");
+       if (!fp)
+               return errno;
+
+       red = fread(buf, 1, len, fp);
+       pclose(fp);
+
+       /* strip trailing newline */
+       if (buf[red - 1] == '\n')
+               buf[red - 1] = '\0';
+
+       return (red == 0) ? -ENOENT : 0;
+}
+
 int ldiskfs_read_ldd(char *dev, struct lustre_disk_data *mo_ldd)
 {
        char tmpdir[] = "/tmp/dirXXXXXX";
@@ -209,6 +228,11 @@ out_close:
        run_command(cmd, cmdsz);
        if (ret)
                verrprint("Failed to read old data (%d)\n", ret);
+
+       /* As long as we at least have the label, we're good to go */
+       snprintf(cmd, sizeof(cmd), E2LABEL" %s", dev);
+       ret = readcmd(cmd, mo_ldd->ldd_svname, sizeof(mo_ldd->ldd_svname) - 1);
+
        return ret;
 }