Whamcloud - gitweb
LU-6662 utils: allow overriding default mountopts 70/15870/6
authorHongchao Zhang <hongchao.zhang@intel.com>
Sun, 14 Jun 2015 08:33:56 +0000 (16:33 +0800)
committerOleg Drokin <oleg.drokin@intel.com>
Fri, 18 Dec 2015 05:28:01 +0000 (05:28 +0000)
during formatting the device for Lustre, there are two kinds of
mount options to be used by "mkfs.lustre", which is default and
wanted options. the wanted options is mandatory but the default
should only be used if user doesn't specify it.

Signed-off-by: Hongchao Zhang <hongchao.zhang@intel.com>
Change-Id: I7d8093082455e0a08eb40df63dbc938d6dd8a2a6
Reviewed-on: http://review.whamcloud.com/15870
Tested-by: Jenkins
Reviewed-by: Nathaniel Clark <nathaniel.l.clark@intel.com>
Tested-by: Maloo <hpdd-maloo@intel.com>
Reviewed-by: Andreas Dilger <andreas.dilger@intel.com>
lustre/tests/conf-sanity.sh
lustre/utils/mkfs_lustre.c
lustre/utils/mount_lustre.c
lustre/utils/mount_utils.c
lustre/utils/mount_utils.h
lustre/utils/mount_utils_ldiskfs.c
lustre/utils/mount_utils_zfs.c

index c3a4881..1c38538 100644 (file)
@@ -5775,6 +5775,29 @@ test_87() { #LU-6544
 }
 run_test 87 "check if MDT inode can hold EAs with N stripes properly"
 
+test_88() {
+       [ "$(facet_fstype mds1)" == "zfs" ] &&
+               skip "LU-6662: no implementation for ZFS" && return
+
+       load_modules
+
+       add mds1 $(mkfs_opts mds1 $(mdsdevname 1)) \
+               --reformat $(mdsdevname 1) || error "add mds1 failed"
+
+       do_facet mds1 "$TUNEFS $(mdsdevname 1) |
+               grep -e \".*opts:.*errors=remount-ro.*\"" ||
+               error "default mount options is missing"
+
+       add mds1 $(mkfs_opts mds1 $(mdsdevname 1)) \
+               --mountfsoptions="user_xattr,errors=panic" \
+               --reformat $(mdsdevname 1) || error "add mds1 failed"
+
+       do_facet mds1 "$TUNEFS $(mdsdevname 1) |
+               grep -e \".*opts:.*errors=panic.*\"" ||
+               error "user can't override default mount options"
+}
+run_test 88 "check the default mount options can be overridden"
+
 # $1 test directory
 # $2 (optional) value of max_mod_rpcs_in_flight to set
 check_max_mod_rpcs_in_flight() {
index c8fd1c5..8bf063a 100644 (file)
@@ -588,8 +588,7 @@ int main(int argc, char *const argv[])
        struct mkfs_opts mop;
        struct lustre_disk_data *ldd;
        char *mountopts = NULL;
-       char always_mountopts[512] = "";
-       char default_mountopts[512] = "";
+       char wanted_mountopts[512] = "";
        unsigned mount_type;
        int ret = 0;
        int ret2 = 0;
@@ -724,33 +723,41 @@ int main(int argc, char *const argv[])
 
         /* These are the permanent mount options (always included) */
        ret = osd_prepare_lustre(&mop,
-                                default_mountopts, sizeof(default_mountopts),
-                                always_mountopts, sizeof(always_mountopts));
+                                wanted_mountopts, sizeof(wanted_mountopts));
        if (ret) {
                fatal();
                fprintf(stderr, "unable to prepare backend (%d)\n", ret);
                goto out;
        }
 
-        if (mountopts) {
-                trim_mountfsoptions(mountopts);
-                (void)check_mountfsoptions(mountopts, default_mountopts, 1);
-                if (check_mountfsoptions(mountopts, always_mountopts, 0)) {
-                        ret = EINVAL;
-                        goto out;
-                }
-                sprintf(ldd->ldd_mount_opts, "%s", mountopts);
-        } else {
+       if (mountopts) {
+               trim_mountfsoptions(mountopts);
+               if (check_mountfsoptions(mountopts, wanted_mountopts)) {
+                       ret = EINVAL;
+                       goto out;
+               }
+               snprintf(ldd->ldd_mount_opts, sizeof(ldd->ldd_mount_opts),
+                        "%s", mountopts);
+       } else {
 #ifdef TUNEFS
-                if (ldd->ldd_mount_opts[0] == 0)
-                        /* use the defaults unless old opts exist */
+               if (ldd->ldd_mount_opts[0] == 0)
+               /* use the defaults unless old opts exist */
 #endif
-                {
-                        sprintf(ldd->ldd_mount_opts, "%s%s",
-                                always_mountopts, default_mountopts);
-                        trim_mountfsoptions(ldd->ldd_mount_opts);
-                }
-        }
+               {
+                       snprintf(ldd->ldd_mount_opts,
+                                sizeof(ldd->ldd_mount_opts),
+                                "%s", wanted_mountopts);
+                       trim_mountfsoptions(ldd->ldd_mount_opts);
+               }
+       }
+
+       ret = osd_fix_mountopts(&mop, ldd->ldd_mount_opts,
+                               sizeof(ldd->ldd_mount_opts));
+       if (ret) {
+               fatal();
+               fprintf(stderr, "unable to fix mountfsoptions (%d)\n", ret);
+               goto out;
+       }
 
         server_make_name(ldd->ldd_flags, ldd->ldd_svindex,
                          ldd->ldd_fsname, ldd->ldd_svname);
index 9261b75..88fcaa7 100644 (file)
@@ -322,8 +322,7 @@ static int add_mgsnids(struct mount_opts *mop, char *options,
 
 static int clear_update_ondisk(char *source, struct lustre_disk_data *ldd)
 {
-       char always_mountopts[512] = "";
-       char default_mountopts[512] = "";
+       char wanted_mountopts[512] = "";
        struct mkfs_opts mkop;
        int ret;
        int ret2;
@@ -339,8 +338,7 @@ static int clear_update_ondisk(char *source, struct lustre_disk_data *ldd)
        strncpy(mkop.mo_device, source, sizeof(mkop.mo_device));
 
        ret = osd_prepare_lustre(&mkop,
-                       default_mountopts, sizeof(default_mountopts),
-                       always_mountopts, sizeof(always_mountopts));
+                                wanted_mountopts, sizeof(wanted_mountopts));
        if (ret) {
                fatal();
                fprintf(stderr, "Can't prepare device %s: %s\n",
index b19aeef..9d8e232 100644 (file)
@@ -298,8 +298,7 @@ static int in_mntlist(char *opt, char *mntlist)
  * present in mountopts.  The justwarn boolean toggles between error and
  * warning message.  Return an error count.
  */
-int check_mountfsoptions(char *mountopts, char *wanted_mountopts,
-                        int justwarn)
+int check_mountfsoptions(char *mountopts, char *wanted_mountopts)
 {
        char *ml, *mlp, *item, *ctx = NULL;
        int errors = 0;
@@ -311,9 +310,8 @@ int check_mountfsoptions(char *mountopts, char *wanted_mountopts,
        mlp = ml;
        while ((item = strtok_r(mlp, ",", &ctx))) {
                if (!in_mntlist(item, mountopts)) {
-                       fprintf(stderr, "%s: %s mount option `%s' is missing\n",
-                               progname, justwarn ? "Warning: default"
-                               : "Error: mandatory", item);
+                       fprintf(stderr, "%s: Error: mandatory mount option"
+                               " '%s' is missing\n", progname, item);
                        errors++;
                }
                mlp = NULL;
@@ -547,6 +545,10 @@ struct module_backfs_ops *load_backfs_module(enum ldd_mount_type mount_type)
                free(ops);
                return NULL;
        }
+
+       /* optional methods */
+       DLSYM(name, ops, fix_mountopts);
+
        return ops;
 }
 
@@ -644,16 +646,14 @@ int osd_make_lustre(struct mkfs_opts *mop)
 }
 
 int osd_prepare_lustre(struct mkfs_opts *mop,
-               char *default_mountopts, int default_len,
-               char *always_mountopts, int always_len)
+                      char *wanted_mountopts, size_t len)
 {
        struct lustre_disk_data *ldd = &mop->mo_ldd;
        int ret;
 
        if (backfs_mount_type_okay(ldd->ldd_mount_type))
                ret = backfs_ops[ldd->ldd_mount_type]->prepare_lustre(mop,
-                       default_mountopts, default_len,
-                       always_mountopts, always_len);
+                                                       wanted_mountopts, len);
 
        else
                ret = EINVAL;
@@ -661,6 +661,20 @@ int osd_prepare_lustre(struct mkfs_opts *mop,
        return ret;
 }
 
+int osd_fix_mountopts(struct mkfs_opts *mop, char *mountopts, size_t len)
+{
+       struct lustre_disk_data *ldd = &mop->mo_ldd;
+
+       if (!backfs_mount_type_okay(ldd->ldd_mount_type))
+               return EINVAL;
+
+       if (backfs_ops[ldd->ldd_mount_type]->fix_mountopts == NULL)
+               return 0;
+
+       return backfs_ops[ldd->ldd_mount_type]->fix_mountopts(mop, mountopts,
+                                                             len);
+}
+
 int osd_tune_lustre(char *dev, struct mount_opts *mop)
 {
        struct lustre_disk_data *ldd = &mop->mo_ldd;
index 13180ed..013bb46 100644 (file)
@@ -121,7 +121,7 @@ char *strscpy(char *dst, char *src, int buflen);
 int check_mtab_entry(char *spec1, char *spec2, char *mntpt, char *type);
 int update_mtab_entry(char *spec, char *mtpt, char *type, char *opts,
                      int flags, int freq, int pass);
-int check_mountfsoptions(char *mountopts, char *wanted_mountopts, int justwarn);
+int check_mountfsoptions(char *mountopts, char *wanted_mountopts);
 void trim_mountfsoptions(char *s);
 __u64 get_device_size(char* device);
 
@@ -137,8 +137,8 @@ int osd_read_ldd(char *dev, struct lustre_disk_data *ldd);
 int osd_is_lustre(char *dev, unsigned *mount_type);
 int osd_make_lustre(struct mkfs_opts *mop);
 int osd_prepare_lustre(struct mkfs_opts *mop,
-                      char *default_mountopts, int default_len,
-                      char *always_mountopts, int always_len);
+                      char *wanted_mountopts, size_t len);
+int osd_fix_mountopts(struct mkfs_opts *mop, char *mountopts, size_t len);
 int osd_tune_lustre(char *dev, struct mount_opts *mop);
 int osd_label_lustre(struct mount_opts *mop);
 int osd_enable_quota(struct mkfs_opts *mop);
@@ -153,8 +153,9 @@ struct module_backfs_ops {
        int     (*is_lustre)(char *dev, enum ldd_mount_type *mount_type);
        int     (*make_lustre)(struct mkfs_opts *mop);
        int     (*prepare_lustre)(struct mkfs_opts *mop,
-                                 char *default_mountopts, int default_len,
-                                 char *always_mountopts, int always_len);
+                                 char *wanted_mountopts, size_t len);
+       int     (*fix_mountopts)(struct mkfs_opts *mop,
+                                char *mountopts, size_t len);
        int     (*tune_lustre)(char *dev, struct mount_opts *mop);
        int     (*label_lustre)(struct mount_opts *mop);
        int     (*enable_quota)(struct mkfs_opts *mop);
index 4f6b84c..f3e9c2b 100644 (file)
@@ -944,8 +944,7 @@ int ldiskfs_make_lustre(struct mkfs_opts *mop)
 }
 
 int ldiskfs_prepare_lustre(struct mkfs_opts *mop,
-                          char *default_mountopts, int default_len,
-                          char *always_mountopts, int always_len)
+                          char *wanted_mountopts, size_t len)
 {
        struct lustre_disk_data *ldd = &mop->mo_ldd;
        int ret;
@@ -958,9 +957,16 @@ int ldiskfs_prepare_lustre(struct mkfs_opts *mop,
                mop->mo_flags |= MO_IS_LOOP;
        }
 
-       strscat(default_mountopts, ",errors=remount-ro", default_len);
        if (IS_MDT(ldd) || IS_MGS(ldd))
-               strscat(always_mountopts, ",user_xattr", always_len);
+               strscat(wanted_mountopts, ",user_xattr", len);
+
+       return 0;
+}
+
+int ldiskfs_fix_mountopts(struct mkfs_opts *mop, char *mountopts, size_t len)
+{
+       if (strstr(mountopts, "errors=") == NULL)
+               strscat(mountopts, ",errors=remount-ro", len);
 
        return 0;
 }
index 854f174..1ca12ce 100644 (file)
@@ -563,8 +563,7 @@ int zfs_enable_quota(struct mkfs_opts *mop)
 }
 
 int zfs_prepare_lustre(struct mkfs_opts *mop,
-               char *default_mountopts, int default_len,
-               char *always_mountopts, int always_len)
+                      char *wanted_mountopts, size_t len)
 {
        if (osd_check_zfs_setup() == 0)
                return EINVAL;