From: Alex Zhuravlev Date: Tue, 5 Jun 2012 08:40:22 +0000 (+0400) Subject: LU-1581 utils: osd_read_ldd() wrapper X-Git-Tag: 2.2.60~23 X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=commitdiff_plain;h=56e0d0bd401ba7dadb19e21dac624f6eb9cee3f7 LU-1581 utils: osd_read_ldd() wrapper used to fetch mountdata from backend Signed-off-by: Alex Zhuravlev Change-Id: I785c43ff95ae3e8faecf9231495529e0d2da8246 Reviewed-on: http://review.whamcloud.com/3221 Tested-by: Hudson Tested-by: Maloo Reviewed-by: Li Wei Reviewed-by: Andreas Dilger --- diff --git a/lustre/utils/mkfs_lustre.c b/lustre/utils/mkfs_lustre.c index a333ac6..070cb20 100644 --- a/lustre/utils/mkfs_lustre.c +++ b/lustre/utils/mkfs_lustre.c @@ -533,7 +533,7 @@ int main(int argc, char *const argv[]) goto out; } - ret = read_local_files(&mop); + ret = osd_read_ldd(mop.mo_device, &mop.mo_ldd); if (ret) { fatal(); fprintf(stderr, "Failed to read previous Lustre data from %s " diff --git a/lustre/utils/mount_utils.c b/lustre/utils/mount_utils.c index 84e0da3..4fb5ee0 100644 --- a/lustre/utils/mount_utils.c +++ b/lustre/utils/mount_utils.c @@ -376,6 +376,27 @@ int loop_format(struct mkfs_opts *mop) return 0; } +/* Read the server config files */ +int osd_read_ldd(char *dev, struct lustre_disk_data *ldd) +{ + int ret; + + switch (ldd->ldd_mount_type) { + case LDD_MT_LDISKFS: + case LDD_MT_LDISKFS2: + ret = ldiskfs_read_ldd(dev, ldd); + break; + default: + fatal(); + fprintf(stderr, "unknown fs type %d '%s'\n", + ldd->ldd_mount_type, MT_STR(ldd)); + ret = EINVAL; + break; + } + + return ret; +} + /* Was this device formatted for Lustre */ int osd_is_lustre(char *dev, unsigned *mount_type) { diff --git a/lustre/utils/mount_utils.h b/lustre/utils/mount_utils.h index cd74d89..498d3ee 100644 --- a/lustre/utils/mount_utils.h +++ b/lustre/utils/mount_utils.h @@ -98,11 +98,13 @@ int loop_setup(struct mkfs_opts *mop); int loop_cleanup(struct mkfs_opts *mop); /* generic target support */ +int osd_read_ldd(char *dev, struct lustre_disk_data *ldd); 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_read_ldd(char *dev, struct lustre_disk_data *ldd); int ldiskfs_is_lustre(char *dev, unsigned *mount_type); int ldiskfs_prepare_lustre(struct mkfs_opts *mop, char *default_mountopts, int default_len, diff --git a/lustre/utils/mount_utils_ldiskfs.c b/lustre/utils/mount_utils_ldiskfs.c index 097e08e..4321bcb 100644 --- a/lustre/utils/mount_utils_ldiskfs.c +++ b/lustre/utils/mount_utils_ldiskfs.c @@ -156,12 +156,11 @@ out_rmdir: return ret; } -int read_local_files(struct mkfs_opts *mop) +int ldiskfs_read_ldd(char *dev, struct lustre_disk_data *mo_ldd) { char tmpdir[] = "/tmp/dirXXXXXX"; char cmd[PATH_MAX]; char filepnm[128]; - char *dev; FILE *filep; int ret = 0; int cmdsz = sizeof(cmd); @@ -173,8 +172,6 @@ int read_local_files(struct mkfs_opts *mop) return errno; } - dev = mop->mo_device; - /* TODO: it's worth observing the get_mountdata() function that is in mount_utils.c for getting the mountdata out of the filesystem */ @@ -193,7 +190,7 @@ int read_local_files(struct mkfs_opts *mop) if (filep) { size_t num_read; vprint("Reading %s\n", MOUNT_DATA_FILE); - num_read = fread(&mop->mo_ldd, sizeof(mop->mo_ldd), 1, filep); + num_read = fread(mo_ldd, sizeof(*mo_ldd), 1, filep); if (num_read < 1 && ferror(filep)) { fprintf(stderr, "%s: Unable to read from file %s: %s\n", progname, filepnm, strerror(errno));