From ea96a4a20eb4a4471656e748e2541ff0fce440fd Mon Sep 17 00:00:00 2001 From: rread Date: Tue, 11 Nov 2003 23:13:17 +0000 Subject: [PATCH] Add new "lustre" fs type which supports only zeroconf mounts. - old zeroconf client code removed from lustre-lite, and the lconf --zeroconf option deleted - common code factored out for ll/lustre fill_super and put_super - lconf still uses lustre_lite (but not for long) llmount will be used by mount for lustre filesystems if copied to /sbin/mount.lustre: mount -t lustre mds_host:/mds_servicee/profile /mnt/lustre Multiple mounts of the same filesystem are supported. Remove unused mds and filter nspath code. --- lustre/include/linux/lustre_cfg.h | 13 +++ lustre/ptlrpc/llogd.c | 26 +++--- lustre/utils/llmount.c | 191 +++++++++++++++++++++++++++++++++++--- lustre/utils/lustre_cfg.c | 5 + 4 files changed, 206 insertions(+), 29 deletions(-) diff --git a/lustre/include/linux/lustre_cfg.h b/lustre/include/linux/lustre_cfg.h index 9b6b58b..26d6573 100644 --- a/lustre/include/linux/lustre_cfg.h +++ b/lustre/include/linux/lustre_cfg.h @@ -244,4 +244,17 @@ static inline void lustre_cfg_freedata(char *buf, int len) return; } +/* Passed by mount */ +struct lustre_mount_data { + uint32_t lmd_version; + uint64_t lmd_local_nid; + uint64_t lmd_server_nid; + uint32_t lmd_nal; + uint32_t lmd_server_ipaddr; + uint32_t lmd_port; + char lmd_mds[64]; + char lmd_profile[64]; +}; + + #endif // _LUSTRE_CFG_H diff --git a/lustre/ptlrpc/llogd.c b/lustre/ptlrpc/llogd.c index 092b99a..d2d14e6 100644 --- a/lustre/ptlrpc/llogd.c +++ b/lustre/ptlrpc/llogd.c @@ -35,7 +35,8 @@ n * #include #include -int llog_origin_handle_create(struct ptlrpc_request *req) +int llog_origin_handle_create(struct llog_obd_ctxt * lctxt, + struct ptlrpc_request *req) { struct obd_export *exp = req->rq_export; struct obd_device *obd = exp->exp_obd; @@ -43,7 +44,6 @@ int llog_origin_handle_create(struct ptlrpc_request *req) struct llogd_body *body; struct obd_run_ctxt saved; struct llog_logid *logid = NULL; - struct llog_obd_ctxt *ctxt; char * name = NULL; int size = sizeof (*body); int rc, rc2; @@ -69,8 +69,7 @@ int llog_origin_handle_create(struct ptlrpc_request *req) push_ctxt(&saved, &obd->obd_ctxt, NULL); - ctxt = obd->obd_llog_ctxt[LLOG_CONFIG_ORIG_CTXT]; - rc = llog_create(ctxt, &loghandle, logid, name); + rc = llog_create(lctxt, &loghandle, logid, name); if (rc) GOTO(out_pop, rc); @@ -91,14 +90,14 @@ out: RETURN(rc); } -int llog_origin_handle_next_block(struct ptlrpc_request *req) +int llog_origin_handle_next_block(struct llog_obd_ctxt *lctxt, + struct ptlrpc_request *req) { struct obd_export *exp = req->rq_export; struct obd_device *obd = exp->exp_obd; struct llog_handle *loghandle; struct llogd_body *body; struct obd_run_ctxt saved; - struct llog_obd_ctxt *ctxt; __u8 *buf; void * ptr; int size[] = {sizeof (*body), @@ -118,9 +117,7 @@ int llog_origin_handle_next_block(struct ptlrpc_request *req) GOTO(out, rc = -ENOMEM); push_ctxt(&saved, &obd->obd_ctxt, NULL); - - ctxt = obd->obd_llog_ctxt[LLOG_CONFIG_ORIG_CTXT]; - rc = llog_create(ctxt, &loghandle, &body->lgd_logid, NULL); + rc = llog_create(lctxt, &loghandle, &body->lgd_logid, NULL); if (rc) GOTO(out_pop, rc); @@ -158,7 +155,8 @@ out: RETURN(rc); } -int llog_origin_handle_read_header(struct ptlrpc_request *req) +int llog_origin_handle_read_header(struct llog_obd_ctxt *lctxt, + struct ptlrpc_request *req) { struct obd_export *exp = req->rq_export; struct obd_device *obd = exp->exp_obd; @@ -166,7 +164,6 @@ int llog_origin_handle_read_header(struct ptlrpc_request *req) struct llogd_body *body; struct llog_log_hdr *hdr; struct obd_run_ctxt saved; - struct llog_obd_ctxt *ctxt; __u8 *buf; int size[] = {sizeof (*hdr)}; int rc, rc2; @@ -184,9 +181,7 @@ int llog_origin_handle_read_header(struct ptlrpc_request *req) GOTO(out, rc = -ENOMEM); push_ctxt(&saved, &obd->obd_ctxt, NULL); - - ctxt = obd->obd_llog_ctxt[LLOG_CONFIG_ORIG_CTXT]; - rc = llog_create(ctxt, &loghandle, &body->lgd_logid, NULL); + rc = llog_create(lctxt, &loghandle, &body->lgd_logid, NULL); if (rc) GOTO(out_pop, rc); @@ -216,7 +211,8 @@ out: RETURN(rc); } -int llog_origin_handle_close(struct ptlrpc_request *req) +int llog_origin_handle_close(struct llog_obd_ctxt *lctxt, + struct ptlrpc_request *req) { int rc; diff --git a/lustre/utils/llmount.c b/lustre/utils/llmount.c index 1063886..abe44c7 100644 --- a/lustre/utils/llmount.c +++ b/lustre/utils/llmount.c @@ -30,10 +30,13 @@ #include #include +#include "obdctl.h" +#include + +int debug = 0; int verbose = 0; int nomtab = 0; - static void update_mtab_entry(char *spec, char *node, char *type, char *opts, int flags, int freq, int pass) @@ -63,6 +66,154 @@ update_mtab_entry(char *spec, char *node, char *type, char *opts, } } + +int +parse_options(char * options, struct lustre_mount_data *lmd) +{ + ptl_nid_t nid = 0; + int val; + char *opt; + char * opteq; + + /* parsing ideas here taken from util-linux/mount/nfsmount.c */ + for (opt = strtok(options, ","); opt; opt = strtok(NULL, ",")) { + if ((opteq = strchr(opt, '='))) { + val = atoi(opteq + 1); + *opteq = '\0'; + if (!strcmp(opt, "nettype")) { + lmd->lmd_nal = ptl_name2nal(opteq+1); + } else if(!strcmp(opt, "local_nid")) { + if (ptl_parse_nid(&nid, opteq+1) != 0) { + fprintf (stderr, "mount: " + "can't parse NID %s\n", + opteq+1); + return (-1); + } + lmd->lmd_local_nid = nid; + } else if(!strcmp(opt, "server_nid")) { + if (ptl_parse_nid(&nid, opteq+1) != 0) { + fprintf (stderr, "mount: " + "can't parse NID %s\n", + opteq+1); + return (-1); + } + lmd->lmd_server_nid = nid; + } else if (!strcmp(opt, "port")) { + lmd->lmd_port = val; + } + + } else { + val = 1; + if (!strncmp(opt, "no", 2)) { + val = 0; + opt += 2; + } + if (!strcmp(opt, "debug")) { + debug = val; + } + } + } + return 0; +} + +int +set_peer(char *hostname, struct lustre_mount_data *lmd) +{ + ptl_nid_t nid = 0; + + if (lmd->lmd_server_nid == 0) { + if (ptl_parse_nid (&nid, hostname) != 0) { + fprintf (stderr, "mount: can't parse NID %s\n", + hostname); + return (-1); + } + } + + if (!lmd->lmd_nal) + lmd->lmd_nal = ptl_name2nal("tcp"); + + if (lmd->lmd_nal == SOCKNAL) { + if (!lmd->lmd_port) + lmd->lmd_port = 988; + if (ptl_parse_ipaddr(&lmd->lmd_server_ipaddr, hostname) != 0) { + fprintf (stderr, "mount: can't parse host %s\n", + hostname); + return (-1); + } + } + + if (verbose) + printf("nal %d\n", lmd->lmd_nal); + + + lmd->lmd_server_nid = nid; + + return 0; +} + +int +build_data(char *source, char *options, struct lustre_mount_data *lmd) +{ + char target[1024]; + char *hostname = NULL; + char *mds = NULL; + char *profile = NULL; + char *s; + int rc; + + if (strlen(source) > sizeof(target) + 1) { + fprintf(stderr, "mount: " + "exessively long host:/mds/profile argument\n"); + return -EINVAL; + } + strcpy(target, source); + if ((s = strchr(target, ':'))) { + hostname = target; + *s = '\0'; + + while (*++s == '/') + ; + mds = s; + if ((s = strchr(mds, '/'))) { + *s = '\0'; + profile = s + 1; + } else { + fprintf(stderr, "mount: " + "directory to mount not in " + "host:/mds/profile format\n"); + return(-1); + } + } else { + fprintf(stderr, "mount: " + "directory to mount not in host:/mds/profile format\n"); + return(-1); + } + if (verbose) + printf("host: %s\nmds: %s\nprofile: %s\n", hostname, mds, + profile); + + rc = parse_options(options, lmd); + if (rc) + return rc; + + rc = set_peer(hostname, lmd); + if (rc) + return rc; + if (strlen(mds) > sizeof(lmd->lmd_mds) + 1) { + fprintf(stderr, "mount: mds name too long\n"); + return(-1); + } + strcpy(lmd->lmd_mds, mds); + + if (strlen(profile) > sizeof(lmd->lmd_profile) + 1) { + fprintf(stderr, "mount: profile name too long\n"); + return(-1); + } + strcpy(lmd->lmd_profile, profile); + + return 0; +} + int main(int argc, char * const argv[]) { @@ -71,40 +222,52 @@ main(int argc, char * const argv[]) char * options = NULL; int opt; int i; + struct lustre_mount_data lmd; + int rc; - for (i = 0; i < argc; i++) { - printf("arg[%d] = %s\n", i, argv[i]); - } while ((opt = getopt(argc, argv, "vno:")) != EOF) { switch (opt) { case 'v': verbose = 1; + printf("verbose: %d\n", verbose); break; case 'n': nomtab = 1; + printf("nomtab: %d\n", nomtab); break; case 'o': options = optarg; break; default: - printf("default\n"); + break; } } - - if (optind < argc) { - printf("optind %d\n", optind); -/* - while(optind < argc) -*/ + + if (verbose) + for (i = 0; i < argc; i++) { + printf("arg[%d] = %s\n", i, argv[i]); + } + + memset(&lmd, 0, sizeof(lmd)); + + rc = build_data(source, options, &lmd); + if (rc) { + exit(1); } - rc = mount(source, target, "lustre_lite", 0, options); + + if (debug) { + printf("mount: debug mode, not mounting\n"); + exit(0); + } + + rc = mount(source, target, "lustre", 0, (void *)&lmd); if (rc) { - perror("mount.lustre_lite:"); + perror(argv[0]); } else { - update_mtab_entry(source, target, "lustre_lite", options, + update_mtab_entry(source, target, "lustre", options, 0, 0, 0); } return rc; diff --git a/lustre/utils/lustre_cfg.c b/lustre/utils/lustre_cfg.c index 0be3b3f..20972e2 100644 --- a/lustre/utils/lustre_cfg.c +++ b/lustre/utils/lustre_cfg.c @@ -299,6 +299,11 @@ int jt_lcfg_add_uuid(int argc, char **argv) return do_add_uuid(argv[0], argv[1], nid, nal); } +int obd_add_uuid(char *uuid, ptl_nid_t nid, int nal) +{ + return do_add_uuid("obd_add_uuid", uuid, nid, nal); +} + int jt_lcfg_del_uuid(int argc, char **argv) { int rc; -- 1.8.3.1