From 0c6a82a2c45a00af99819c1407222095765a8e1c Mon Sep 17 00:00:00 2001 From: nathan Date: Tue, 27 Sep 2005 00:12:52 +0000 Subject: [PATCH] Branch b1_4_mountconf b=8013 move options parsing from mount.lustre into kernel --- lustre/Makefile.in | 3 +- lustre/autoMakefile.am | 5 +- lustre/include/linux/lustre_disk.h | 13 +-- lustre/llite/llite_lib.c | 4 +- lustre/obdclass/obd_mount.c | 89 +++++++++++++++-- lustre/utils/mkfs_lustre.c | 18 ++-- lustre/utils/mount_lustre.c | 190 +++++-------------------------------- 7 files changed, 129 insertions(+), 193 deletions(-) diff --git a/lustre/Makefile.in b/lustre/Makefile.in index 78f976c..dbf1863 100644 --- a/lustre/Makefile.in +++ b/lustre/Makefile.in @@ -8,7 +8,8 @@ subdir-m += osc subdir-m += obdecho subdir-m += mgc -@SERVER_TRUE@subdir-m += mds obdfilter ost mgs +@SERVER_TRUE@subdir-m += mds obdfilter ost +# mgs @CLIENT_TRUE@subdir-m += mdc llite @INCLUDE_RULES@ diff --git a/lustre/autoMakefile.am b/lustre/autoMakefile.am index 75132e2..cbee40b 100644 --- a/lustre/autoMakefile.am +++ b/lustre/autoMakefile.am @@ -6,9 +6,10 @@ AUTOMAKE_OPTIONS = foreign ALWAYS_SUBDIRS := include lvfs obdclass ldlm ptlrpc osc lov obdecho \ - mgc mgs doc utils tests conf scripts autoconf + mgc doc utils tests conf scripts autoconf -SERVER_SUBDIRS := ldiskfs obdfilter ost mds mgs +SERVER_SUBDIRS := ldiskfs obdfilter ost mds +# mgs CLIENT_SUBDIRS := mdc llite diff --git a/lustre/include/linux/lustre_disk.h b/lustre/include/linux/lustre_disk.h index bbc3979..ae4ce14 100644 --- a/lustre/include/linux/lustre_disk.h +++ b/lustre/include/linux/lustre_disk.h @@ -88,16 +88,17 @@ struct lustre_disk_data { #define MT_STR(data) mt_str((data)->ldd_mount_type) /****************** mount command *********************/ +#define MAX_FAILOVER_LIST 10 /* Passed by mount - no persistent info here */ struct lustre_mount_data { - __u32 lmd_magic; - __u32 lmd_flags; /* lustre mount flags */ - struct host_desc lmd_mgsnid; /* who to contact at startup */ + __u32 lmd_magic; + __u32 lmd_flags; /* lustre mount flags */ + __u16 lmd_mgsnid_count; /* how many failover nids we have for the MGS */ + lnet_nid_t lmd_mgsnid[MAX_FAILOVER_LIST]; /* who to contact at startup */ //struct lustre_disk_data *lmd_ldd; /* in-mem copy of ldd */ - char lmd_dev[128]; /* device or file system name */ - char lmd_mtpt[128]; /* mount point (for client overmount) */ - char lmd_opts[256]; /* lustre mount options (as opposed to + char lmd_dev[128]; /* device or file system name */ + char lmd_opts[256]; /* lustre mount options (as opposed to _device_ mount options) */ }; diff --git a/lustre/llite/llite_lib.c b/lustre/llite/llite_lib.c index c0616c1..f655c75 100644 --- a/lustre/llite/llite_lib.c +++ b/lustre/llite/llite_lib.c @@ -449,7 +449,7 @@ void ll_options(char *options, char **ost, char **mdc, int *flags) } EXIT; } - + void ll_lli_init(struct ll_inode_info *lli) { sema_init(&lli->lli_open_sem, 1); @@ -483,6 +483,8 @@ int ll_fill_super(struct super_block *sb) RETURN(-ENOMEM); } + ll_options(lsi->lsi_lmd->lmd_opts, &osc, &mdc, &sbi->ll_flags); + /* generate a string unique to this super, let's try the address of the super itself.*/ sprintf(ll_instance, "%p", sb); diff --git a/lustre/obdclass/obd_mount.c b/lustre/obdclass/obd_mount.c index 7f6641f..2e741e1 100644 --- a/lustre/obdclass/obd_mount.c +++ b/lustre/obdclass/obd_mount.c @@ -28,7 +28,7 @@ #include #include #include -#include +//#include #include #include #include @@ -494,7 +494,7 @@ static int lustre_update_llog(struct obd_device *obd) } -static int do_lcfg(char *cfgname, ptl_nid_t nid, int cmd, +static int do_lcfg(char *cfgname, lnet_nid_t nid, int cmd, char *s1, char *s2, char *s3, char *s4) { struct lustre_cfg_bufs bufs; @@ -538,7 +538,8 @@ static int lustre_start_mgs(struct super_block *sb, struct vfsmount *mnt) cfg.cfg_instance = mgsname; snprintf(cfg.cfg_uuid.uuid, sizeof(cfg.cfg_uuid.uuid), mgsname); - err = do_lcfg(mgsname, 0, LCFG_ATTACH, LUSTRE_MGS_NAME, cfg.cfg_uuid.uuid, 0, 0); + err = do_lcfg(mgsname, 0, LCFG_ATTACH, /*LUSTRE_MGS_NAME*/ "mgs", + cfg.cfg_uuid.uuid, 0, 0); if (err) GOTO(out_dereg, err); @@ -727,10 +728,11 @@ static struct vfsmount *lustre_kern_mount(struct super_block *sb) options = (char *)page; memset(options, 0, PAGE_SIZE); strcpy(options, ldd->ldd_mount_opts); + /* Add in any mount-line options */ if (strlen(lmd->lmd_opts)) { if (strlen(options)) strcat(options, ","); - strcat(options, ldd->ldd_mount_opts); + strcat(options, lmd->lmd_opts); } CERROR("kern_mount: %s %s %s\n", MT_STR(ldd), lmd->lmd_dev, options); @@ -968,6 +970,68 @@ void lustre_common_put_super(struct super_block *sb) lustre_free_sbi(sb); } +static void print_lmd(struct lustre_mount_data *lmd) +{ + int i; + + for (i = 0; i < lmd->lmd_mgsnid_count; i++) + CERROR("nid %d: %s\n", i, libcfs_nid2str(lmd->lmd_mgsnid[i])); + CERROR("fsname: %s\n", lmd->lmd_dev); + CERROR("options: %s\n", lmd->lmd_opts); + +} + +static int parse_lmd(char *devname, char *options, + struct lustre_mount_data *lmd) +{ + char *s1, *s2; + if (strchr(devname, ',')) { + LCONSOLE_ERROR("No commas are allowed in the device name\n"); + goto invalid; + } + s1 = devname; + while ((s2 = strchr(s1, ':'))) { + lnet_nid_t nid; + *s2 = 0; + lmd->lmd_flags = LMD_FLG_CLIENT; + nid = libcfs_str2nid(s1); + if (nid == LNET_NID_ANY) { + LCONSOLE_ERROR("Can't parse NID '%s'\n", s1); + goto invalid; + } + if (lmd->lmd_mgsnid_count >= MAX_FAILOVER_LIST) { + LCONSOLE_ERROR("Too many NIDs: '%s'\n", s1); + goto invalid; + } + lmd->lmd_mgsnid[lmd->lmd_mgsnid_count++] = libcfs_str2nid(s1); + s1 = s2 + 1; + } + + while (*++s1 == '/') + ; + + if (strlen(s1) > sizeof(lmd->lmd_dev)) { + LCONSOLE_ERROR("Filesystem name too long: '%s'\n", s1); + goto invalid; + } + strcpy(lmd->lmd_dev, s1); + + if (strlen(options) > sizeof(lmd->lmd_opts)) { + LCONSOLE_ERROR("Options string too long: '%s'\n", options); + goto invalid; + } + strcpy(lmd->lmd_opts, options); + + lmd->lmd_magic = LMD_MAGIC; + + print_lmd(lmd); + return 0; + +invalid: + return -EINVAL; +} + + /* Common mount */ int lustre_fill_super(struct super_block *sb, void *data, int silent) { @@ -1001,7 +1065,7 @@ int lustre_fill_super(struct super_block *sb, void *data, int silent) char mgcname[64]; snprintf(mgcname, sizeof(mgcname), "mgc-client-%s", lmd->lmd_dev); - CERROR("Mounting client\n"); + CERROR("Mounting client for fs %s\n", lmd->lmd_dev); err = lustre_start_mgc(sb, NULL); if (err) { lustre_free_sbi(sb); @@ -1039,8 +1103,20 @@ void lustre_register_client_fill_super(int (*cfs)(struct super_block *sb)) struct super_block * lustre_get_sb(struct file_system_type *fs_type, int flags, const char *devname, void * data) { + struct lustre_mount_data lmd; + + if (((struct lustre_mount_data *)data)->lmd_magic == LMD_MAGIC ) { + /* mount.lustre is sending lmd */ + CERROR("Using mount.lustre's lmd\n"); + return get_sb_nodev(fs_type, flags, data, lustre_fill_super); + } + + /* Figure out the lmd from the mount line */ + if (parse_lmd((char *)devname, (char *)data, &lmd)) + return ERR_PTR(-EINVAL); + /* calls back in fill super */ - return get_sb_nodev(fs_type, flags, data, lustre_fill_super); + return get_sb_nodev(fs_type, flags, (void *)&lmd, lustre_fill_super); } struct file_system_type lustre_fs_type = { @@ -1056,6 +1132,7 @@ struct file_system_type lustre_fs_type = { static struct super_block *lustre_read_super(struct super_block *sb, void *data, int silent) { + //FIXME need the device for the lmd!! int err; ENTRY; err = lustre_fill_super(sb, data, silent); diff --git a/lustre/utils/mkfs_lustre.c b/lustre/utils/mkfs_lustre.c index c27e4ca..d38b155 100644 --- a/lustre/utils/mkfs_lustre.c +++ b/lustre/utils/mkfs_lustre.c @@ -37,7 +37,7 @@ #include #include -#include +#include #include "obdctl.h" /* So obd.o will link */ @@ -590,9 +590,9 @@ static int jt_setup() { int ret; /* FIXME uneeded? */ - ret = access(PORTALS_DEV_PATH, F_OK); + ret = access(LNET_DEV_PATH, F_OK); if (ret) - system("mknod "PORTALS_DEV_PATH" c 10 240"); + system("mknod "LNET_DEV_PATH" c 10 240"); ret = access(OBD_DEV_PATH, F_OK); if (ret) system("mknod "OBD_DEV_PATH" c 10 241"); @@ -603,7 +603,7 @@ static int jt_setup() } /* see jt_ptl_network */ -int jt_getnids(ptl_nid_t *nidarray, int maxnids) +int jt_getnids(lnet_nid_t *nidarray, int maxnids) { struct portal_ioctl_data data; int count; @@ -612,7 +612,7 @@ int jt_getnids(ptl_nid_t *nidarray, int maxnids) for (count = 0; count < maxnids; count++) { PORTAL_IOC_INIT (data); data.ioc_count = count; - rc = l_ioctl(PORTALS_DEV_ID, IOC_PORTAL_GET_NI, &data); + rc = l_ioctl(LNET_DEV_ID, IOC_PORTAL_GET_NI, &data); if (rc >= 0) { vprint("%s\n", libcfs_nid2str(data.ioc_nid)); @@ -752,11 +752,11 @@ int write_llog_files(struct mkfs_opts *mop) } if (IS_MDT(&mop->mo_ldd)) { - ptl_nid_t nidarray[128]; + lnet_nid_t nidarray[128]; char scnt[20], ssz[20], soff[20], spat[20]; char cliname[sizeof(mop->mo_ldd.ldd_fsname)]; char mdcname[sizeof(mop->mo_ldd.ldd_fsname)]; - ptl_nid_t nid; + lnet_nid_t nid; int numnids; /* Write mds-conf log */ @@ -1088,13 +1088,13 @@ int main(int argc , char *const argv[]) } if (IS_MDT(&mop.mo_ldd) && !IS_MGMT(&mop.mo_ldd) && - mop.mo_ldd.ldd_mgmtnid.primary == PTL_NID_ANY) { + mop.mo_ldd.ldd_mgmtnid.primary == LNET_NID_ANY) { vprint("No MGMT specified, adding to this MDT\n"); mop.mo_ldd.ldd_flags |= LDD_F_SV_TYPE_MGMT; //FIXME mop.mo_ldd.ldd_mgmt.primary == libcfs_str2nid(localhost); } - if (mop.mo_ldd.ldd_mgmtnid.primary == PTL_NID_ANY) { + if (mop.mo_ldd.ldd_mgmtnid.primary == LNET_NID_ANY) { fatal(); fprintf(stderr, "Must specify either --mgmt or --mgmtnode\n"); usage(stderr); diff --git a/lustre/utils/mount_lustre.c b/lustre/utils/mount_lustre.c index 8e9f9c6..66bf85a 100644 --- a/lustre/utils/mount_lustre.c +++ b/lustre/utils/mount_lustre.c @@ -36,7 +36,7 @@ #include #include -#include +//#include #include "obdctl.h" int verbose; @@ -61,30 +61,6 @@ void usage(FILE *out) exit(out != stdout); } -int get_os_version() -{ - static int version = 0; - - if (!version) { - int fd; - char release[4] = ""; - - fd = open("/proc/sys/kernel/osrelease", O_RDONLY); - if (fd < 0) - fprintf(stderr, "Warning: Can't resolve kernel version," - " assuming 2.6\n"); - else { - read(fd, release, 4); - close(fd); - } - if (strncmp(release, "2.4.", 4) == 0) - version = 24; - else - version = 26; - } - return version; -} - static int load_module(char *module_name) { char buf[256]; @@ -102,19 +78,13 @@ static int load_module(char *module_name) return rc; } -static int load_modules(struct lustre_mount_data *lmd) +static int load_modules() { int rc = 0; - rc = load_module("_lustre"); - - if (lmd_is_client(lmd)) { - rc = load_module("llite"); - } else { - rc = load_module("mds"); - if (rc) return rc; - rc = load_module("ost"); - } + rc = load_module("lustre"); + rc = load_module("mds"); + rc = load_module("ost"); return rc; } @@ -177,41 +147,6 @@ update_mtab_entry(char *spec, char *mtpt, char *type, char *opts, return rc; } -int -init_options(struct lustre_mount_data *lmd) -{ - memset(lmd, 0, sizeof(*lmd)); - //gethostname(lmd->lmd_hostname, sizeof lmd->lmd_hostname); - //lmd->lmd_server_nid = PTL_NID_ANY; - //ptl_parse_nid(&lmd->lmd_nid, lmd->lmd_hostname); - //lmd->lmd_port = 988; /* XXX define LUSTRE_DEFAULT_PORT */ - //lmd->lmd_nal = SOCKNAL; - //ptl_parse_ipaddr(&lmd->lmd_ipaddr, lmd->lmd_hostname); - lmd->lmd_magic = LMD_MAGIC; - lmd->lmd_flags = LMD_FLG_MNTCNF; - lmd->lmd_mgsnid.primary = PTL_NID_ANY; - lmd->lmd_mgsnid.backup = PTL_NID_ANY; - return 0; -} - -int -print_options(struct lustre_mount_data *lmd) -{ - printf("mgmt primary nid: %s\n", - libcfs_nid2str(lmd->lmd_mgsnid.primary)); - printf("mgmt backup nid: %s\n", - libcfs_nid2str(lmd->lmd_mgsnid.backup)); - printf("device: %s\n", lmd->lmd_dev); - printf("mount point: %s\n", lmd->lmd_mtpt); - printf("options: %s\n", lmd->lmd_opts); - printf("flags: %x\n", lmd->lmd_flags); - if (lmd_is_client(lmd)) - printf("CLIENT\n"); - else - printf("SERVER\n"); - - return 0; -} /***************************************************************************** * @@ -253,7 +188,7 @@ static int parse_one_option(const char *check, int *flagp) const struct opt_map *opt; for (opt = &opt_map[0]; opt->opt != NULL; opt++) { - if (strcmp(check, opt->opt) == 0) { + if (strncmp(check, opt->opt, strlen(opt->opt)) == 0) { if (opt->inv) *flagp &= ~(opt->mask); else @@ -264,10 +199,13 @@ static int parse_one_option(const char *check, int *flagp) return 0; } -int parse_options(char *options, struct lustre_mount_data *lmd, int *flagp) +int parse_options(char *orig_options, int *flagp) { int val; - char *opt, *opteq; + char *options, *opt, *opteq; + + options = malloc(strlen(orig_options) + 1); + strcpy(options, orig_options); *flagp = 0; /* parsing ideas here taken from util-linux/mount/nfsmount.c */ @@ -275,109 +213,21 @@ int parse_options(char *options, struct lustre_mount_data *lmd, int *flagp) if ((opteq = strchr(opt, '='))) { val = atoi(opteq + 1); *opteq = '\0'; - if (0) { - /* NO special lustre options, just standard - mount options */ - } else { - fprintf(stderr, "%s: unknown option '%s'\n", - progname, opt); - usage(stderr); - } + /* All the network options have gone :)) */ + fprintf(stderr, "%s: unknown option '%s'. " + "Ignoring.\n", progname, opt); } else { if (parse_one_option(opt, flagp)) continue; fprintf(stderr, "%s: unknown option '%s'\n", progname, opt); - usage(stderr); } } + free(options); return 0; } -int -build_data(char *source, char *target, char *options, - struct lustre_mount_data *lmd, int *flagp) -{ - char buf[1024]; - char *nid = NULL; - char *devname = NULL; - char *s; - int rc; - - init_options(lmd); - - if (lmd_bad_magic(lmd)) - return 4; - - if (strlen(source) >= sizeof(buf)) { - fprintf(stderr, "%s: device name too long\n", - progname); - return 1; - } - strcpy(buf, source); - - if ((s = strchr(buf, ':'))) { - /* Client */ - if (verbose) - printf("CLIENT\n"); - lmd->lmd_flags |= LMD_FLG_CLIENT; - - /* [,]:/fsname[/fsetname[/subdir/]] - nid=mgsnid, devname=fsname */ - nid = buf; - *s = '\0'; - while (*++s == '/') /*spin*/; - devname = s; /* for clients, devname=fsname */ - - rc = parse_options(options, lmd, flagp); - if (rc) - return rc; - - if (lmd->lmd_mgsnid.primary != PTL_NID_ANY) - /* In case it was defined as -o mgmtnode= */ - //FIXME set_nid_pair(&lmd->lmd_mgsnid, nid); - if (lmd->lmd_mgsnid.primary == PTL_NID_ANY) { - fprintf(stderr, "%s: can't parse nid '%s'\n", - progname, nid); - return 1; - } - } else { - /* Server */ - if (verbose) - printf("SERVER\n"); - - devname = source; - - /* We have to keep the loop= option in the mtab file - in order for umount to free the loop device. The strtok - in parse_options terminates the options list at the first - comma, so we're saving a local copy here. */ - strcpy(buf, options); - rc = parse_options(options, lmd, flagp); - if (rc) - return rc; - strcpy(options, buf); - - // move into lustre: rc = read_mount_options(source, target, lmd); - } - - if (strlen(devname) + 1 > sizeof(lmd->lmd_dev)) { - fprintf(stderr, "%s: device name too long\n", progname); - return(1); - } - strcpy(lmd->lmd_dev, devname); - - if (strlen(target) + 1 > sizeof(lmd->lmd_mtpt)) { - fprintf(stderr, "%s: mount point too long\n", progname); - return(1); - } - strcpy(lmd->lmd_mtpt, target); - - if (verbose) - print_options(lmd); - return 0; -} int main(int argc, char *const argv[]) { @@ -397,6 +247,8 @@ int main(int argc, char *const argv[]) progname = strrchr(argv[0], '/'); progname = progname ? progname + 1 : argv[0]; + printf("starting %s\n", progname); + while ((opt = getopt_long(argc, argv, "fhno:v", long_opt, NULL)) != EOF){ switch (opt) { @@ -452,8 +304,10 @@ int main(int argc, char *const argv[]) if (!force && check_mtab_entry(source, target, "lustre")) exit(32); - rc = build_data(source, target, options, &lmd, &flags); + rc = parse_options(options, &flags); if (rc) { + fprintf(stderr, "%s: can't parse options: %s\n", + progname, options); exit(1); } @@ -466,7 +320,7 @@ int main(int argc, char *const argv[]) } /* FIXME remove */ - if ((rc = load_modules(&lmd))) { + if ((rc = load_modules())) { return rc; } @@ -474,7 +328,7 @@ int main(int argc, char *const argv[]) /* flags and target get to lustre_get_sb, but not lustre_fill_super. Lustre ignores the flags, but mount does not. */ - rc = mount(source, target, "lustre", flags, (void *)&lmd); + rc = mount(source, target, "lustre", flags, (void *)options); if (rc) { fprintf(stderr, "%s: mount(%s, %s) failed: %s\n", progname, source, target, strerror(errno)); -- 1.8.3.1