From b00b85189ea20ac906eec46092b5330e382dc616 Mon Sep 17 00:00:00 2001 From: Alex Zhuravlev Date: Tue, 5 Jun 2012 11:55:36 +0400 Subject: [PATCH] LU-1581 utils: introduce osd_is_lustre() wrapper the purpose of that is to verify whether underlying device can be used for lustre and identify backend filesystem Signed-off-by: Alex Zhuravlev Change-Id: Ie95cf8b88811be12feb4af67e15ff26ecae9a447 --- lustre/utils/mkfs_lustre.c | 5 +++-- lustre/utils/mount_utils.c | 14 ++++++++++++++ lustre/utils/mount_utils.h | 2 ++ lustre/utils/mount_utils_ldiskfs.c | 29 ++++++++++++----------------- 4 files changed, 31 insertions(+), 19 deletions(-) diff --git a/lustre/utils/mkfs_lustre.c b/lustre/utils/mkfs_lustre.c index 27fdad3..a333ac6 100644 --- a/lustre/utils/mkfs_lustre.c +++ b/lustre/utils/mkfs_lustre.c @@ -500,6 +500,7 @@ int main(int argc, char *const argv[]) char *mountopts = NULL; char always_mountopts[512] = ""; char default_mountopts[512] = ""; + unsigned mount_type; int ret = 0; if ((progname = strrchr(argv[0], '/')) != NULL) @@ -523,7 +524,7 @@ int main(int argc, char *const argv[]) new ones. */ /* Check whether the disk has already been formatted by mkfs.lustre */ - ret = is_lustre_target(&mop); + ret = osd_is_lustre(mop.mo_device, &mount_type); if (ret == 0) { fatal(); fprintf(stderr, "Device %s has not been formatted with " @@ -665,7 +666,7 @@ int main(int argc, char *const argv[]) #ifndef TUNEFS /* mkfs.lustre */ /* Check whether the disk has already been formatted by mkfs.lustre */ if (!(mop.mo_flags & MO_FORCEFORMAT)) { - ret = is_lustre_target(&mop); + ret = osd_is_lustre(mop.mo_device, &mount_type); if (ret) { fatal(); fprintf(stderr, "Device %s was previously formatted " diff --git a/lustre/utils/mount_utils.c b/lustre/utils/mount_utils.c index 4d9c93c..84e0da3 100644 --- a/lustre/utils/mount_utils.c +++ b/lustre/utils/mount_utils.c @@ -376,6 +376,20 @@ int loop_format(struct mkfs_opts *mop) return 0; } +/* Was this device formatted for Lustre */ +int osd_is_lustre(char *dev, unsigned *mount_type) +{ + vprint("checking for existing Lustre data: "); + + if (ldiskfs_is_lustre(dev, mount_type)) { + vprint("found\n"); + return 1; + } + + vprint("not found\n"); + return 0; +} + int osd_prepare_lustre(struct mkfs_opts *mop, char *default_mountopts, int default_len, char *always_mountopts, int always_len) diff --git a/lustre/utils/mount_utils.h b/lustre/utils/mount_utils.h index 9d732c3..cd74d89 100644 --- a/lustre/utils/mount_utils.h +++ b/lustre/utils/mount_utils.h @@ -98,10 +98,12 @@ int loop_setup(struct mkfs_opts *mop); int loop_cleanup(struct mkfs_opts *mop); /* generic target support */ +int osd_is_lustre(char *dev, unsigned *mount_type); int osd_prepare_lustre(struct mkfs_opts *mop, char *default_mountopts, int default_len, char *always_mountopts, int always_len); +int ldiskfs_is_lustre(char *dev, unsigned *mount_type); int ldiskfs_prepare_lustre(struct mkfs_opts *mop, char *default_mountopts, int default_len, char *always_mountopts, int always_len); diff --git a/lustre/utils/mount_utils_ldiskfs.c b/lustre/utils/mount_utils_ldiskfs.c index 86f9ef5..097e08e 100644 --- a/lustre/utils/mount_utils_ldiskfs.c +++ b/lustre/utils/mount_utils_ldiskfs.c @@ -277,31 +277,26 @@ static int file_in_dev(char *file_name, char *dev_name) } /* Check whether the device has already been used with lustre */ -int is_lustre_target(struct mkfs_opts *mop) +int ldiskfs_is_lustre(char *dev, unsigned *mount_type) { - int rc; - - vprint("checking for existing Lustre data: "); + int ret; - if ((rc = file_in_dev(MOUNT_DATA_FILE, mop->mo_device))) { - vprint("found %s\n", - (rc == 1) ? MOUNT_DATA_FILE : "extents"); - /* in the -1 case, 'extents' means this really IS a lustre - target */ - return rc; + ret = file_in_dev(MOUNT_DATA_FILE, dev); + if (ret) { + /* in the -1 case, 'extents' means IS a lustre target */ + *mount_type = LDD_MT_LDISKFS; + return 1; } - if ((rc = file_in_dev(LAST_RCVD, mop->mo_device))) { - vprint("found %s\n", LAST_RCVD); - return rc; + ret = file_in_dev(LAST_RCVD, dev); + if (ret) { + *mount_type = LDD_MT_LDISKFS; + return 1; } - vprint("not found\n"); - return 0; /* The device is not a lustre target. */ + return 0; } - - /* Check if a certain feature is supported by e2fsprogs. * Firstly we try to use "debugfs supported_features" command to check if * the feature is supported. If this fails we try to set this feature with -- 1.8.3.1