From: Alex Zhuravlev Date: Tue, 5 Jun 2012 07:26:38 +0000 (+0400) Subject: LU-1581 utils: osd_prepare_lustre X-Git-Url: https://git.whamcloud.com/?a=commitdiff_plain;h=89d3c13400dee909cf712cee7cffc5ae1ab4e089;p=fs%2Flustre-release.git LU-1581 utils: osd_prepare_lustre wrapper to prepare backed, load modules, etc Signed-off-by: Alex Zhuravlev Change-Id: I9f841889cdb950aa9a6650369d73fdc1f0a57f55 --- diff --git a/lustre/utils/Makefile.am b/lustre/utils/Makefile.am index f549c15..350acd1 100644 --- a/lustre/utils/Makefile.am +++ b/lustre/utils/Makefile.am @@ -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) diff --git a/lustre/utils/mkfs_lustre.c b/lustre/utils/mkfs_lustre.c index 2c20ac9..27fdad3 100644 --- a/lustre/utils/mkfs_lustre.c +++ b/lustre/utils/mkfs_lustre.c @@ -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); diff --git a/lustre/utils/mount_utils.c b/lustre/utils/mount_utils.c index e6769ea..4d9c93c 100644 --- a/lustre/utils/mount_utils.c +++ b/lustre/utils/mount_utils.c @@ -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; diff --git a/lustre/utils/mount_utils.h b/lustre/utils/mount_utils.h index 01a7795..9d732c3 100644 --- a/lustre/utils/mount_utils.h +++ b/lustre/utils/mount_utils.h @@ -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 diff --git a/lustre/utils/mount_utils_ldiskfs.c b/lustre/utils/mount_utils_ldiskfs.c index 637c92c..86f9ef5 100644 --- a/lustre/utils/mount_utils_ldiskfs.c +++ b/lustre/utils/mount_utils_ldiskfs.c @@ -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)