Whamcloud - gitweb
LU-2800 autoconf: remove bio_endio args test
[fs/lustre-release.git] / lustre / utils / mount_lustre.c
index 3fa1311..20abe44 100644 (file)
@@ -324,7 +324,12 @@ static int clear_update_ondisk(char *source, struct lustre_disk_data *ldd)
        memset(&mkop, 0, sizeof(mkop));
        mkop.mo_ldd = *ldd;
        mkop.mo_ldd.ldd_flags &= ~LDD_F_UPDATE;
-       mkop.mo_device = strdup(source);
+       if (strlen(source) > sizeof(mkop.mo_device)-1) {
+               fatal();
+               fprintf(stderr, "Device name too long: %s\n", source);
+               return -E2BIG;
+       }
+       strncpy(mkop.mo_device, source, sizeof(mkop.mo_device));
 
        ret = osd_prepare_lustre(&mkop,
                        default_mountopts, sizeof(default_mountopts),
@@ -500,6 +505,10 @@ static int parse_opts(int argc, char *const argv[], struct mount_opts *mop)
                {"verbose", 0, 0, 'v'},
                {0, 0, 0, 0}
        };
+       char real_path[PATH_MAX] = {'\0'};
+       FILE *f;
+       char path[256], name[256];
+       size_t sz;
        char *ptr;
        int opt, rc;
 
@@ -540,13 +549,30 @@ static int parse_opts(int argc, char *const argv[], struct mount_opts *mop)
                usage(stderr);
        }
 
-       if (argv[optind] == NULL)
+       mop->mo_usource = argv[optind];
+       if (!mop->mo_usource) {
                usage(stderr);
+       }
 
-       /* Try to get the real path to the device */
-       rc = get_realpath(argv[optind], &mop->mo_usource);
-       if (rc != 0)
-               mop->mo_usource = argv[optind];
+       /**
+        * Try to get the real path to the device, in case it is a
+        * symbolic link for instance
+        */
+       if (realpath(mop->mo_usource, real_path) != NULL) {
+               ptr = strrchr(real_path, '/');
+               if (ptr && strncmp(ptr, "/dm-", 4) == 0 && isdigit(*(ptr + 4))) {
+                       snprintf(path, sizeof(path), "/sys/block/%s/dm/name", ptr+1);
+                       if ((f = fopen(path, "r"))) {
+                               /* read "<name>\n" from sysfs */
+                               if (fgets(name, sizeof(name), f) && (sz = strlen(name)) > 1) {
+                                       name[sz - 1] = '\0';
+                                       snprintf(real_path, sizeof(real_path), "/dev/mapper/%s", name);
+                               }
+                               fclose(f);
+                       }
+               }
+               mop->mo_usource = strdup(real_path);
+       }
 
        ptr = strstr(mop->mo_usource, ":/");
        if (ptr != NULL) {
@@ -664,7 +690,18 @@ int main(int argc, char *const argv[])
                 for (i = 0, rc = -EAGAIN; i <= mop.mo_retry && rc != 0; i++) {
                        rc = mount(mop.mo_source, mop.mo_target, "lustre",
                                   flags, (void *)options);
-                        if (rc) {
+                       if (rc == 0) {
+                               /* change label from <fsname>:<index> to
+                                * <fsname>-<index> to indicate the device has
+                                *  been registered. only if the label is
+                                *  supposed to be changed and target service
+                                *  is supposed to start */
+                               if (mop.mo_ldd.ldd_flags &
+                                  (LDD_F_VIRGIN | LDD_F_WRITECONF)) {
+                                       if (mop.mo_nosvc == 0)
+                                               (void)osd_label_lustre(&mop);
+                               }
+                       } else {
                                 if (verbose) {
                                         fprintf(stderr, "%s: mount %s at %s "
                                                 "failed: %s retries left: "
@@ -750,16 +787,7 @@ int main(int argc, char *const argv[])
        } else if (!mop.mo_nomtab) {
                rc = update_mtab_entry(mop.mo_usource, mop.mo_target, "lustre",
                                       mop.mo_orig_options, 0,0,0);
-
-               /* change label from <fsname>:<index> to <fsname>-<index>
-                * to indicate the device has been registered.
-                * only if the label is supposed to be changed and
-                * target service is supposed to start */
-               if (mop.mo_ldd.ldd_flags & (LDD_F_VIRGIN | LDD_F_WRITECONF)) {
-                       if (mop.mo_nosvc == 0 )
-                               (void) osd_label_lustre(&mop);
-               }
-        }
+       }
 
        free(options);
        /* mo_usource should be freed, but we can rely on the kernel */