chiark / gitweb /
[PATCH] more extras/multipath updates
[elogind.git] / extras / multipath / main.c
index b5ab664433165d8b661f34e45757ccbb143f170a..9bceb265ba1fe4a2e1cf48b1f67868fde79e0d96 100644 (file)
@@ -26,7 +26,7 @@
 #include <string.h>
 #include <sys/ioctl.h>
 #include <libsysfs.h>
-#include <libdevmapper.h>
+#include "libdevmapper/libdevmapper.h"
 #include "main.h"
 
 static int
@@ -458,9 +458,7 @@ static int
 make_dm_node(char * str)
 {
        int r = 0;
-       dev_t dev;
        char buff[FILE_NAME_SIZE];
-       int major, minor;
        struct dm_names * names;
         unsigned next = 0;
        struct dm_task *dmt;
@@ -486,14 +484,9 @@ make_dm_node(char * str)
                 names = (void *) names + next;
         } while (next);
 
-       major = (int) MAJOR(names->dev);
-       minor = (int) MINOR(names->dev);
-
-       dev = major << sizeof(dev_t);
-       dev = dev | minor;
        sprintf(buff, "/dev/mapper/%s", str);
        unlink(buff);
-       mknod(buff, 0600 | S_IFBLK, dev);
+       mknod(buff, 0600 | S_IFBLK, names->dev);
 
        out:
        dm_task_destroy(dmt);
@@ -667,9 +660,19 @@ usage(char * progname)
        exit(1);
 }
 
+static int
+running(char * run) {
+       struct stat buf;
+
+       if(!stat(run, &buf))
+               return 1;
+       return 0;
+}
+
 int
 main(int argc, char *argv[])
 {
+       char * run = "/var/run/multipath.run";
        struct multipath * mp;
        struct path * all_paths;
        struct scsi_dev * all_scsi_ids;
@@ -712,12 +715,26 @@ main(int argc, char *argv[])
 
        }
 
+       if (running(run)) {
+               if (conf.verbose) {
+                       fprintf(stderr, "Already running.\n");
+                       fprintf(stderr, "If you know what you do, please ");
+                       fprintf(stderr, "remove %s\n", run);
+               }
+               return 1;
+       }
+
+       if(!open(run, O_CREAT))
+               exit(1);
+
        /* dynamic allocations */
        mp = malloc(conf.max_devs * sizeof(struct multipath));
        all_paths = malloc(conf.max_devs * sizeof(struct path));
        all_scsi_ids = malloc(conf.max_devs * sizeof(struct scsi_dev));
-       if (mp == NULL || all_paths == NULL || all_scsi_ids == NULL)
+       if (mp == NULL || all_paths == NULL || all_scsi_ids == NULL) {
+               unlink(run);
                exit(1);
+       }
 
        if (!conf.with_sysfs) {
                get_all_scsi_ids(&conf, all_scsi_ids);
@@ -729,13 +746,15 @@ main(int argc, char *argv[])
 
        if (conf.verbose) {
                print_all_path(&conf, all_paths);
-               printf("\n");
+               fprintf(stdout, "\n");
                print_all_mp(all_paths, mp, nmp);
-               printf("\n");
+               fprintf(stdout, "\n");
        }
 
-       if (conf.dry_run)
+       if (conf.dry_run) {
+               unlink(run);
                exit(0);
+       }
 
        for (k=0; k<=nmp; k++) {
                if (map_present(mp[k].wwid)) {
@@ -744,5 +763,6 @@ main(int argc, char *argv[])
                        add_map(&conf, all_paths, mp, k, DM_DEVICE_CREATE);
                }
        }
+       unlink(run);
        exit(0);
 }