Whamcloud - gitweb
Branch b1_4_mountconf
[fs/lustre-release.git] / lustre / utils / mount_lustre.c
index 291d29f..66bf85a 100644 (file)
@@ -35,9 +35,9 @@
 #include <getopt.h>
 #include <sys/utsname.h>
 
-#include "obdctl.h"
-#include <portals/ptlctl.h>
 #include <linux/lustre_disk.h>
+//#include <portals/ptlctl.h>
+#include "obdctl.h"
 
 int          verbose;
 int          nomtab;
@@ -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;
 
-        if (lmd_is_client(lmd)) {
-                rc = load_module("lustre");
-        } else {
-                if (lmd->u.srv.disk_type & MDS_DISK_TYPE)
-                        rc = load_module("mds");
-                if (rc) return rc;
-                if (lmd->u.srv.disk_type & OST_DISK_TYPE) 
-                        rc = load_module("oss");
-        }
+        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->u.cli.lmd_async = 0;
-        lmd->lmd_magic = LMD_MAGIC;
-        lmd->lmd_nid = PTL_NID_ANY;
-        return 0;
-}
-
-int
-print_options(struct lustre_mount_data *lmd)
-{
-        printf("nid:             %s\n", libcfs_nid2str(lmd->lmd_nid));
-        
-        if (lmd_is_client(lmd)) {
-                printf("CLIENT\n");
-                printf("mds:             %s\n", lmd->u.cli.lmd_mds);
-                printf("profile:         %s\n", lmd->u.cli.lmd_profile);
-        } else {
-                printf("SERVER\n");
-                printf("service type:    %x\n", lmd->u.srv.disk_type);
-                printf("device:          %s\n", lmd->u.srv.lmd_source);
-                printf("fs type:         %s\n", lmd->u.srv.lmd_fstype);
-                printf("fs opts:         %s\n", lmd->u.srv.lmd_fsopts);
-        }
-
-        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,162 +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) {
-                                /* All the network options have gone :)) */
-                        } 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 read_mount_options(char *source, char *target, 
-                       struct lustre_mount_data *lmd)
-{
-        char cmd[512];
-        char opfilenm[255];
-        FILE *opfile;
-        __u32 lddmagic;
-        int ret;
-        
-        if ( strlen(lmd->u.srv.lmd_source) == 0) {
-                strcpy(lmd->u.srv.lmd_source, source);
-                sprintf(cmd, "mount -t ext3  %s %s", lmd->u.srv.lmd_source, target);
-        }
-        else
-                sprintf(cmd, "mount -o loop  %s %s", lmd->u.srv.lmd_source, target);
-           
-        ret = system(cmd);
-        if (ret) {
-                fprintf(stderr, "Unable to mount %s\n", lmd->u.srv.lmd_source);
-                return errno;
-        }
-
-        /* mounted, now read the options file */
-        sprintf(opfilenm, "%s/%s", target, MOUNTOPTS_FILE_NAME);
-        opfile = fopen(opfilenm, "r");
-        if (!opfile) {
-                fprintf(stderr,"Unable to open options file %s: %s\n", 
-                        opfilenm, strerror(errno));
-                ret = errno;
-                goto out_umnt;
-        }
-
-        ret = fscanf(opfile, "%x\n", &lddmagic);
-        if (ret < 1) {
-                fprintf(stderr, "Can't read options file %s\n", opfilenm);
-                goto out_close;
-        }
-        if (lddmagic != LDD_MAGIC) {
-                fprintf(stderr, "Bad magic in options file %s\n", opfilenm);
-                goto out_close;
-        }
-
-        fscanf(opfile, "%s\n", lmd->u.srv.lmd_fstype);
-        fscanf(opfile, "%s\n", lmd->u.srv.lmd_fsopts);
-        fscanf(opfile, "%x\n", &lmd->u.srv.disk_type);
-        //fread(&data->mgt.host, sizeof(data->mgt.host), 1, opfile);
-        ret = 0;
-
-out_close:
-        fclose(opfile);
-out_umnt:
-        sprintf(cmd, "umount %s", target);
-        system(cmd);
-        return ret;
-}
-
-int
-build_data(char *source, char *target, char *options, 
-           struct lustre_mount_data *lmd, int *flagp)
-{
-        char  buf[1024];
-        char *nid = NULL;
-        char *mgmt = NULL;
-        char *s;
-        int   rc;
-
-        if (lmd_bad_magic(lmd))
-                return 4;
-
-        if (strlen(source) >= sizeof(buf)) {
-                fprintf(stderr, "%s: nid:/fsname argument too long\n",
-                        progname);
-                return 1;
-        }
-        strcpy(buf, source);
-
-        if ((s = strchr(buf, ':'))) {
-                /* Client */
-                if (verbose)
-                        printf("CLIENT\n");
-                lmd->lmd_type = 
-
-                nid = buf;
-                *s = '\0';
-
-                while (*++s == '/')
-                        ;
-                mgmt = s;
-
-                rc = parse_options(options, lmd, flagp);
-                if (rc)
-                        return rc;
-
-                lmd->lmd_nid = libcfs_str2nid(nid);
-                if (lmd->lmd_nid == PTL_NID_ANY) {
-                        fprintf(stderr, "%s: can't parse nid '%s'\n",
-                                progname, libcfs_nid2str(lmd->lmd_nid));
-                        return 1;
-                }
-
-                if (strlen(mgmt) + 4 > sizeof(lmd->lmd_mgmt)) {
-                        fprintf(stderr, "%s: mgmt name too long\n", progname);
-                        return(1);
-                }
-                strcpy(lmd->lmd_mds, mgmt);
-        } else {
-                /* Server */
-                if (verbose)
-                        printf("SERVER\n");
-                lmd->lmd_magic = LMD_SERVER_MAGIC;
-
-                if (strlen(source) + 1 > sizeof(lmd->u.srv.lmd_source)) {
-                        fprintf(stderr, "%s: source name too long\n", progname);
-                        return(1);
-                }
-
-                /* 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); 
-                fprintf(stderr, "source = %s \n",lmd->u.srv.lmd_source);
-                print_options(lmd);
-                if (rc)
-                        return rc;
-                strcpy(options, buf);
-
-                rc = read_mount_options(source, target, lmd);
-                if (rc)
-                        return rc;
-        }
-
-        if (verbose)
-                print_options(lmd);
-        return 0;
-}
 
 int main(int argc, char *const argv[])
 {
@@ -450,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) {
@@ -505,9 +304,10 @@ int main(int argc, char *const argv[])
         if (!force && check_mtab_entry(source, target, "lustre"))
                 exit(32);
 
-        init_options(&lmd);
-        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);
         }
 
@@ -519,15 +319,19 @@ int main(int argc, char *const argv[])
                 return 1;
         }
 
-        if ((rc = load_modules(&lmd))) {
+        /* FIXME remove */
+        if ((rc = load_modules())) {
                 return rc;
         }
 
         if (!fake)
-                rc = mount(source, target, "lustre", flags, (void *)&lmd);
+                /* 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 *)options);
         if (rc) {
-                fprintf(stderr, "%s: mount(%s, %s) failed: %s\n", source,
-                        target, progname, strerror(errno));
+                fprintf(stderr, "%s: mount(%s, %s) failed: %s\n", progname, 
+                        source, target, strerror(errno));
                 if (errno == ENODEV)
                         fprintf(stderr, "Are the lustre modules loaded?\n"
                              "Check /etc/modules.conf and /proc/filesystems\n");