Whamcloud - gitweb
LU-1581 utils: osd_prepare_lustre 19/3219/4
authorAlex Zhuravlev <bzzz@whamcloud.com>
Tue, 5 Jun 2012 07:26:38 +0000 (11:26 +0400)
committerAlex Zhuravlev <bzzz@whamcloud.com>
Mon, 2 Jul 2012 16:47:14 +0000 (20:47 +0400)
wrapper to prepare backed, load modules, etc

Signed-off-by: Alex Zhuravlev <bzzz@whamcloud.com>
Change-Id: I9f841889cdb950aa9a6650369d73fdc1f0a57f55

lustre/utils/Makefile.am
lustre/utils/mkfs_lustre.c
lustre/utils/mount_utils.c
lustre/utils/mount_utils.h
lustre/utils/mount_utils_ldiskfs.c

index f549c15..350acd1 100644 (file)
@@ -95,6 +95,7 @@ llog_reader_DEPENDENCIES := $(LIBPTLCTL)
 lr_reader_SOURCES = lr_reader.c
 
 mount_lustre_SOURCES = mount_lustre.c mount_utils.c mount_utils.h
+mount_lustre_SOURCES += mount_utils_ldiskfs.c
 mount_lustre_LDADD := $(LIBPTLCTL)
 mount_lustre_DEPENDENCIES := $(LIBPTLCTL)
 
index 2c20ac9..27fdad3 100644 (file)
@@ -518,15 +518,6 @@ int main(int argc, char *const argv[])
         /* device is last arg */
         strscpy(mop.mo_device, argv[argc - 1], sizeof(mop.mo_device));
 
-        /* Are we using a loop device? */
-        ret = is_block(mop.mo_device);
-        if (ret < 0) {
-                ret = errno;
-                goto out;
-        }
-        if (ret == 0)
-                mop.mo_flags |= MO_IS_LOOP;
-
 #ifdef TUNEFS
         /* For tunefs, we must read in the old values before parsing any
            new ones. */
@@ -605,32 +596,14 @@ int main(int argc, char *const argv[])
 #endif
 
         /* These are the permanent mount options (always included) */
-        switch (ldd->ldd_mount_type) {
-        case LDD_MT_EXT3:
-        case LDD_MT_LDISKFS:
-        case LDD_MT_LDISKFS2:
-                strscat(default_mountopts, ",errors=remount-ro",
-                        sizeof(default_mountopts));
-                if (IS_MDT(ldd) || IS_MGS(ldd))
-                        strscat(always_mountopts, ",user_xattr",
-                                sizeof(always_mountopts));
-                /* NB: Files created while extents are enabled can only be read
-                 * if mounted using the ext4 or ldiskfs filesystem type. */
-                if (IS_OST(ldd) &&
-                    (ldd->ldd_mount_type == LDD_MT_LDISKFS ||
-                     ldd->ldd_mount_type == LDD_MT_LDISKFS2)) {
-                        strscat(default_mountopts, ",extents,mballoc",
-                                sizeof(default_mountopts));
-                }
-                break;
-        default:
-                fatal();
-                fprintf(stderr, "unknown fs type %d '%s'\n",
-                        ldd->ldd_mount_type,
-                        MT_STR(ldd));
-                ret = EINVAL;
-                goto out;
-        }
+       ret = osd_prepare_lustre(&mop,
+                                default_mountopts, sizeof(default_mountopts),
+                                always_mountopts, sizeof(always_mountopts));
+       if (ret) {
+               fatal();
+               fprintf(stderr, "unable to prepare backend (%d)\n", ret);
+               goto out;
+       }
 
         if (mountopts) {
                 trim_mountfsoptions(mountopts);
index e6769ea..4d9c93c 100644 (file)
@@ -376,6 +376,31 @@ int loop_format(struct mkfs_opts *mop)
        return 0;
 }
 
+int osd_prepare_lustre(struct mkfs_opts *mop,
+               char *default_mountopts, int default_len,
+               char *always_mountopts, int always_len)
+{
+       struct lustre_disk_data *ldd = &mop->mo_ldd;
+       int ret;
+
+       switch (ldd->ldd_mount_type) {
+       case LDD_MT_LDISKFS:
+       case LDD_MT_LDISKFS2:
+               ret = ldiskfs_prepare_lustre(mop,
+                                            default_mountopts, default_len,
+                                            always_mountopts, always_len);
+               break;
+       default:
+               fatal();
+               fprintf(stderr, "unknown fs type %d '%s'\n",
+                       ldd->ldd_mount_type, MT_STR(ldd));
+               ret = EINVAL;
+               break;
+       }
+
+       return ret;
+}
+
 __u64 get_device_size(char* device)
 {
        int ret, fd;
index 01a7795..9d732c3 100644 (file)
@@ -97,4 +97,13 @@ int loop_format(struct mkfs_opts *mop);
 int loop_setup(struct mkfs_opts *mop);
 int loop_cleanup(struct mkfs_opts *mop);
 
+/* generic target support */
+int osd_prepare_lustre(struct mkfs_opts *mop,
+                      char *default_mountopts, int default_len,
+                      char *always_mountopts, int always_len);
+
+int ldiskfs_prepare_lustre(struct mkfs_opts *mop,
+                          char *default_mountopts, int default_len,
+                          char *always_mountopts, int always_len);
+
 #endif
index 637c92c..86f9ef5 100644 (file)
@@ -731,6 +731,28 @@ int make_lustre_backfs(struct mkfs_opts *mop)
        return ret;
 }
 
+int ldiskfs_prepare_lustre(struct mkfs_opts *mop,
+                          char *default_mountopts, int default_len,
+                          char *always_mountopts, int always_len)
+{
+       struct lustre_disk_data *ldd = &mop->mo_ldd;
+       int ret;
+
+       /* Set MO_IS_LOOP to indicate a loopback device is needed */
+       ret = is_block(mop->mo_device);
+       if (ret < 0) {
+               return errno;
+       } else if (ret == 0) {
+               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);
+
+       return 0;
+}
+
 /* return canonicalized absolute pathname, even if the target file does not
  * exist, unlike realpath */
 static char *absolute_path(char *devname)