From f251f3201d59c0fe0d5b2c6f96dfc7594583e0d8 Mon Sep 17 00:00:00 2001 From: Alex Zhuravlev Date: Wed, 27 Jun 2012 13:07:01 +0400 Subject: [PATCH] LU-1581 utils: mount to parse mountdata only for non-ldiskfs backends for a while Signed-off-by: Alex Zhuravlev Change-Id: I051489ff2e853f2fd07fc0b355c1e18278939a1d Reviewed-on: http://review.whamcloud.com/3235 Reviewed-by: Andreas Dilger Tested-by: Hudson Reviewed-by: Li Wei Tested-by: Maloo --- lustre/utils/mount_lustre.c | 108 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 105 insertions(+), 3 deletions(-) diff --git a/lustre/utils/mount_lustre.c b/lustre/utils/mount_lustre.c index 09e1bdd..263f5d2 100644 --- a/lustre/utils/mount_lustre.c +++ b/lustre/utils/mount_lustre.c @@ -261,6 +261,31 @@ int parse_options(struct mount_opts *mop, char *orig_options, int *flagp) return 0; } +/* Add mgsnids from ldd params */ +static int add_mgsnids(struct mount_opts *mop, char *options, + const char *params) +{ + char *ptr = (char *)params; + char tmp, *sep; + + while ((ptr = strstr(ptr, PARAM_MGSNODE)) != NULL) { + sep = strchr(ptr, ' '); + if (sep != NULL) { + tmp = *sep; + *sep = '\0'; + } + append_option(options, ptr); + mop->mo_have_mgsnid++; + if (sep) { + *sep = tmp; + ptr = sep; + } else { + break; + } + } + + return 0; +} static int parse_ldd(char *source, struct mount_opts *mop, char *options) { @@ -275,6 +300,79 @@ static int parse_ldd(char *source, struct mount_opts *mop, char *options) return ENODEV; } + /* for new backends (i.e. ZFS) we will be parsing mount data + * in the userspace and pass it in the form of mount options. + * to adopt this schema smoothly we're still doing old way + * (parsing mount data within the kernel) for ldiskfs */ + if (ldd->ldd_mount_type == LDD_MT_EXT3 || + ldd->ldd_mount_type == LDD_MT_LDISKFS || + ldd->ldd_mount_type == LDD_MT_LDISKFS2) + return 0; + + rc = osd_read_ldd(source, ldd); + if (rc) { + fprintf(stderr, "%s: %s failed to read permanent mount" + " data: %s\n", progname, source, strerror(rc)); + return rc; + } + + if (ldd->ldd_flags & LDD_F_NEED_INDEX) { + fprintf(stderr, "%s: %s has no index assigned " + "(probably formatted with old mkfs)\n", + progname, source); + return EINVAL; + } + + if (ldd->ldd_flags & LDD_F_UPGRADE14) { + fprintf(stderr, "%s: we cannot upgrade %s from this (very old) " + "Lustre version\n", progname, source); + return EINVAL; + } + + /* Since we never rewrite ldd, ignore temp flags */ + ldd->ldd_flags &= ~(LDD_F_VIRGIN | LDD_F_UPDATE); + + /* svname of the form lustre:OST1234 means never registered */ + rc = strlen(ldd->ldd_svname); + if (ldd->ldd_svname[rc - 8] == ':') { + ldd->ldd_svname[rc - 8] = '-'; + ldd->ldd_flags |= LDD_F_VIRGIN; + } + + /* backend osd type */ + append_option(options, "osd="); + strcat(options, mt_type(ldd->ldd_mount_type)); + + append_option(options, ldd->ldd_mount_opts); + + if (!mop->mo_have_mgsnid) { + /* Only use disk data if mount -o mgsnode=nid wasn't + * specified */ + if (ldd->ldd_flags & LDD_F_SV_TYPE_MGS) { + append_option(options, "mgs"); + mop->mo_have_mgsnid++; + } else { + add_mgsnids(mop, options, ldd->ldd_params); + } + } + /* Better have an mgsnid by now */ + if (!mop->mo_have_mgsnid) { + fprintf(stderr, "%s: missing option mgsnode=\n", + progname); + return EINVAL; + } + + if (ldd->ldd_flags & (LDD_F_VIRGIN | LDD_F_WRITECONF)) + append_option(options, "writeconf"); + if (ldd->ldd_flags & LDD_F_IAM_DIR) + append_option(options, "iam"); + if (ldd->ldd_flags & LDD_F_NO_PRIMNODE) + append_option(options, "noprimnode"); + + /* svname must be last option */ + append_option(options, "svname="); + strcat(options, ldd->ldd_svname); + return 0; } @@ -373,9 +471,13 @@ static int parse_opts(int argc, char *const argv[], struct mount_opts *mop) } } - mop->mo_source = convert_hostnames(mop->mo_usource); - if (!mop->mo_source) { - usage(stderr); + ptr = strstr(mop->mo_usource, ":/"); + if (ptr != NULL) { + mop->mo_source = convert_hostnames(mop->mo_usource); + if (!mop->mo_source) + usage(stderr); + } else { + mop->mo_source = strdup(mop->mo_usource); } if (realpath(argv[optind + 1], mop->mo_target) == NULL) { -- 1.8.3.1