chiark / gitweb /
[PATCH] yet more extras/multipath
[elogind.git] / extras / multipath / main.c
index f3f92e7eba6dbdd617a860bfca132680696e49b2..bc65899ce14376706cf3d8b86b5d15a8e9563024 100644 (file)
@@ -195,6 +195,31 @@ basename(char * str1, char * str2)
        strcpy(str2, ++p);
 }
 
+static int
+blacklist (char * dev) {
+       int i;
+       static struct {
+               char * headstr;
+               int lengh;
+       } blist[] = {
+               {"cciss", 5},
+               {"hd", 2},
+               {"md", 2},
+               {"dm", 2},
+               {"sr", 2},
+               {"scd", 3},
+               {"ram", 3},
+               {"raw", 3},
+               {NULL, 0},
+       };
+
+       for (i = 0; blist[i].lengh; i++) {
+               if (strncmp(dev, blist[i].headstr, blist[i].lengh))
+                       return 1;
+       }
+       return 0;
+}
+
 static int
 get_all_paths_sysfs(struct env * conf, struct path * all_paths)
 {
@@ -211,6 +236,8 @@ get_all_paths_sysfs(struct env * conf, struct path * all_paths)
        sdir = sysfs_open_directory(block_path);
        sysfs_read_directory(sdir);
        dlist_for_each_data(sdir->subdirs, devp, struct sysfs_directory) {
+               if (blacklist(devp->name))
+                       continue;
                sysfs_read_directory(devp);
                if(devp->links == NULL)
                        continue;
@@ -660,9 +687,20 @@ usage(char * progname)
        exit(1);
 }
 
+static int
+filepresent(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";
+       char * resched = "/var/run/multipath.reschedule";
        struct multipath * mp;
        struct path * all_paths;
        struct scsi_dev * all_scsi_ids;
@@ -705,11 +743,27 @@ main(int argc, char *argv[])
 
        }
 
+       if (filepresent(run)) {
+               if (conf.verbose) {
+                       fprintf(stderr, "Already running.\n");
+                       fprintf(stderr, "If you know what you do, please ");
+                       fprintf(stderr, "remove %s\n", run);
+               }
+               /* leave a trace that we were called while already running */
+               open(resched, O_CREAT);
+               return 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);
+       }
+start:
+       if(!open(run, O_CREAT))
                exit(1);
 
        if (!conf.with_sysfs) {
@@ -725,11 +779,12 @@ main(int argc, char *argv[])
                fprintf(stdout, "\n");
                print_all_mp(all_paths, mp, nmp);
                fprintf(stdout, "\n");
-               //printf("\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)) {
@@ -738,5 +793,13 @@ main(int argc, char *argv[])
                        add_map(&conf, all_paths, mp, k, DM_DEVICE_CREATE);
                }
        }
+       unlink(run);
+
+       /* start again if we were ask to during this process run */
+       /* ie. do not loose an event-asked run */
+       if (filepresent(resched)) {
+               unlink(resched);
+               goto start;
+       }
        exit(0);
 }