chiark / gitweb /
[PATCH] allow to specify node permissions in the rule
[elogind.git] / extras / multipath / main.c
1 /*
2  * Soft:        multipath device mapper target autoconfig
3  *
4  * Version:     $Id: main.h,v 0.0.1 2003/09/18 15:13:38 cvaroqui Exp $
5  *
6  * Author:      Copyright (C) 2003 Christophe Varoqui
7  *
8  *              This program is distributed in the hope that it will be useful,
9  *              but WITHOUT ANY WARRANTY; without even the implied warranty of
10  *              MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11  *              See the GNU General Public License for more details.
12  *
13  *              This program is free software; you can redistribute it and/or
14  *              modify it under the terms of the GNU General Public License
15  *              as published by the Free Software Foundation; either version
16  *              2 of the License, or (at your option) any later version.
17  */
18
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <unistd.h>
22 #include <fcntl.h>
23 #include <sys/types.h>
24 #include <sys/stat.h>
25 #include <linux/kdev_t.h>
26 #include <string.h>
27 #include <sys/ioctl.h>
28 #include <sysfs/libsysfs.h>
29 #include "libdevmapper/libdevmapper.h"
30 #include "main.h"
31 #include "devinfo.h"
32
33 /* White list switch */
34 static int
35 get_unique_id(struct path * mypath)
36 {
37         int i;
38         static struct {
39                 char * vendor;
40                 char * product;
41                 int iopolicy;
42                 int (*getuid) (char *, char *);
43         } wlist[] = {
44                 {"COMPAQ  ", "HSV110 (C)COMPAQ", GROUP_BY_SERIAL, &get_evpd_wwid},
45                 {"COMPAQ  ", "MSA1000         ", GROUP_BY_SERIAL, &get_evpd_wwid},
46                 {"COMPAQ  ", "MSA1000 VOLUME  ", GROUP_BY_SERIAL, &get_evpd_wwid},
47                 {"DEC     ", "HSG80           ", GROUP_BY_SERIAL, &get_evpd_wwid},
48                 {"HP      ", "HSV100          ", GROUP_BY_SERIAL, &get_evpd_wwid},
49                 {"HP      ", "A6189A          ", MULTIBUS, &get_evpd_wwid},
50                 {"HP      ", "OPEN-           ", MULTIBUS, &get_evpd_wwid},
51                 {"DDN     ", "SAN DataDirector", MULTIBUS, &get_evpd_wwid},
52                 {"FSC     ", "CentricStor     ", MULTIBUS, &get_evpd_wwid},
53                 {"HITACHI ", "DF400           ", MULTIBUS, &get_evpd_wwid},
54                 {"HITACHI ", "DF500           ", MULTIBUS, &get_evpd_wwid},
55                 {"HITACHI ", "DF600           ", MULTIBUS, &get_evpd_wwid},
56                 {"IBM     ", "ProFibre 4000R  ", MULTIBUS, &get_evpd_wwid},
57                 {"SGI     ", "TP9100          ", MULTIBUS, &get_evpd_wwid},
58                 {"SGI     ", "TP9300          ", MULTIBUS, &get_evpd_wwid},
59                 {"SGI     ", "TP9400          ", MULTIBUS, &get_evpd_wwid},
60                 {"SGI     ", "TP9500          ", MULTIBUS, &get_evpd_wwid},
61                 {NULL, NULL, 0, NULL},
62         };
63
64         for (i = 0; wlist[i].vendor; i++) {
65                 if (strncmp(mypath->vendor_id, wlist[i].vendor, 8) == 0 &&
66                     strncmp(mypath->product_id, wlist[i].product, 16) == 0) {
67                         mypath->iopolicy = wlist[i].iopolicy;
68                         if (!wlist[i].getuid(mypath->sg_dev, mypath->wwid))
69                                 return 0;
70                 }
71         }
72         return 1;
73 }
74
75 static int
76 blacklist (char * dev) {
77         int i;
78         static struct {
79                 char * headstr;
80                 int lengh;
81         } blist[] = {
82                 {"cciss", 5},
83                 {"hd", 2},
84                 {"md", 2},
85                 {"dm", 2},
86                 {"sr", 2},
87                 {"scd", 3},
88                 {"ram", 3},
89                 {"raw", 3},
90                 {NULL, 0},
91         };
92
93         for (i = 0; blist[i].lengh; i++) {
94                 if (strncmp(dev, blist[i].headstr, blist[i].lengh) == 0)
95                         return 1;
96         }
97         return 0;
98 }
99
100 static int
101 get_all_paths_sysfs(struct env * conf, struct path * all_paths)
102 {
103         int k=0;
104         struct sysfs_directory * sdir;
105         struct sysfs_directory * devp;
106         struct sysfs_link * linkp;
107         char refwwid[WWID_SIZE];
108         char empty_buff[WWID_SIZE];
109         char buff[FILE_NAME_SIZE];
110         char path[FILE_NAME_SIZE];
111         struct path curpath;
112
113         /* if called from hotplug, only consider the paths that relate */
114         /* to the device pointed by conf.hotplugdev */
115         memset(empty_buff, 0, WWID_SIZE);
116         memset(refwwid, 0, WWID_SIZE);
117         if (strncmp("/devices", conf->hotplugdev, 8) == 0) {
118                 sprintf(buff, "%s%s/block",
119                         conf->sysfs_path, conf->hotplugdev);
120                 memset(conf->hotplugdev, 0, FILE_NAME_SIZE);
121
122                 /* if called from hotplug but with no block, leave */
123                 if (0 > readlink(buff, conf->hotplugdev, FILE_NAME_SIZE))
124                         return 0;
125
126                 basename(conf->hotplugdev, buff);
127                 sprintf(curpath.sg_dev, "/dev/%s", buff);
128
129                 get_lun_strings(curpath.vendor_id,
130                                 curpath.product_id,
131                                 curpath.rev,
132                                 curpath.sg_dev);
133                 get_serial(curpath.serial, curpath.sg_dev);
134                 if (!get_unique_id(&curpath))
135                         return 0;
136                 strcpy(refwwid, curpath.wwid);
137                 memset(&curpath, 0, sizeof(path));
138         }
139
140         sprintf(path, "%s/block", conf->sysfs_path);
141         sdir = sysfs_open_directory(path);
142         sysfs_read_directory(sdir);
143
144         dlist_for_each_data(sdir->subdirs, devp, struct sysfs_directory) {
145                 if (blacklist(devp->name))
146                         continue;
147
148                 sysfs_read_directory(devp);
149
150                 if(devp->links == NULL)
151                         continue;
152
153                 dlist_for_each_data(devp->links, linkp, struct sysfs_link) {
154                         if (!strncmp(linkp->name, "device", 6))
155                                 break;
156                 }
157
158                 if (linkp == NULL) {
159                         continue;
160                 }
161
162                 basename(devp->path, buff);
163                 sprintf(curpath.sg_dev, "/dev/%s", buff);
164
165                 get_lun_strings(curpath.vendor_id,
166                                 curpath.product_id,
167                                 curpath.rev,
168                                 curpath.sg_dev);
169                 get_serial(curpath.serial, curpath.sg_dev);
170                 if(!get_unique_id(&curpath)) {
171                         memset(&curpath, 0, sizeof(path));
172                         continue;
173                 }
174
175                 if (memcmp(empty_buff, refwwid, WWID_SIZE) != 0 && 
176                     strncmp(curpath.wwid, refwwid, WWID_SIZE) != 0) {
177                         memset(&curpath, 0, sizeof(path));
178                         continue;
179                 }
180
181                 strcpy(all_paths[k].sg_dev, curpath.sg_dev);
182                 strcpy(all_paths[k].dev, curpath.sg_dev);
183                 strcpy(all_paths[k].wwid, curpath.wwid);
184                 strcpy(all_paths[k].vendor_id, curpath.vendor_id);
185                 strcpy(all_paths[k].product_id, curpath.product_id);
186                 all_paths[k].iopolicy = curpath.iopolicy;
187
188                 /* done with curpath, zero for reuse */
189                 memset(&curpath, 0, sizeof(path));
190
191                 basename(linkp->target, buff);
192                 sscanf(buff, "%i:%i:%i:%i",
193                         &all_paths[k].sg_id.host_no,
194                         &all_paths[k].sg_id.channel,
195                         &all_paths[k].sg_id.scsi_id,
196                         &all_paths[k].sg_id.lun);
197                 k++;
198         }
199         sysfs_close_directory(sdir);
200         return 0;
201 }
202
203 static int
204 get_all_paths_nosysfs(struct env * conf, struct path * all_paths,
205                       struct scsi_dev * all_scsi_ids)
206 {
207         int k, i, fd;
208         char buff[FILE_NAME_SIZE];
209         char file_name[FILE_NAME_SIZE];
210
211         for (k = 0; k < conf->max_devs; k++) {
212                 strcpy(file_name, "/dev/sg");
213                 sprintf(buff, "%d", k);
214                 strncat(file_name, buff, FILE_NAME_SIZE);
215                 strcpy(all_paths[k].sg_dev, file_name);
216
217                 get_lun_strings(all_paths[k].vendor_id,
218                                 all_paths[k].product_id,
219                                 all_paths[k].rev,
220                                 all_paths[k].sg_dev);
221                 get_serial(all_paths[k].serial, all_paths[k].sg_dev);
222                 if (!get_unique_id(&all_paths[k]))
223                         continue;
224
225                 if ((fd = open(all_paths[k].sg_dev, O_RDONLY)) < 0)
226                         return 0;
227
228                 if (0 > ioctl(fd, SG_GET_SCSI_ID, &(all_paths[k].sg_id)))
229                         printf("device %s failed on sg ioctl, skip\n",
230                                file_name);
231
232                 close(fd);
233
234                 for (i = 0; i < conf->max_devs; i++) {
235                         if ((all_paths[k].sg_id.host_no ==
236                              all_scsi_ids[i].host_no)
237                             && (all_paths[k].sg_id.scsi_id ==
238                                 (all_scsi_ids[i].scsi_id.dev_id & 0xff))
239                             && (all_paths[k].sg_id.lun ==
240                                 ((all_scsi_ids[i].scsi_id.dev_id >> 8) & 0xff))
241                             && (all_paths[k].sg_id.channel ==
242                                 ((all_scsi_ids[i].scsi_id.
243                                   dev_id >> 16) & 0xff))) {
244                                 strcpy(all_paths[k].dev, all_scsi_ids[i].dev);
245                                 break;
246                         }
247                 }
248         }
249         return 0;
250 }
251
252 static int
253 get_all_scsi_ids(struct env * conf, struct scsi_dev * all_scsi_ids)
254 {
255         int k, big, little, res, host_no, fd;
256         char buff[64];
257         char fname[FILE_NAME_SIZE];
258         struct scsi_idlun my_scsi_id;
259
260         for (k = 0; k < conf->max_devs; k++) {
261                 strcpy(fname, "/dev/sd");
262                 if (k < 26) {
263                         buff[0] = 'a' + (char) k;
264                         buff[1] = '\0';
265                         strcat(fname, buff);
266                 } else if (k <= 255) {
267                         /* assumes sequence goes x,y,z,aa,ab,ac etc */
268                         big = k / 26;
269                         little = k - (26 * big);
270                         big = big - 1;
271
272                         buff[0] = 'a' + (char) big;
273                         buff[1] = 'a' + (char) little;
274                         buff[2] = '\0';
275                         strcat(fname, buff);
276                 } else
277                         strcat(fname, "xxxx");
278
279                 if ((fd = open(fname, O_RDONLY)) < 0) {
280                         if (conf->verbose)
281                                 fprintf(stderr, "can't open %s. mknod ?",
282                                         fname); 
283                         continue;
284                 }
285
286                 res = ioctl(fd, SCSI_IOCTL_GET_IDLUN, &my_scsi_id);
287                 if (res < 0) {
288                         close(fd);
289                         printf("Could not get scsi idlun\n");
290                         continue;
291                 }
292
293                 res = ioctl(fd, SCSI_IOCTL_GET_BUS_NUMBER, &host_no);
294                 if (res < 0) {
295                         close(fd);
296                         printf("Could not get host_no\n");
297                         continue;
298                 }
299
300                 close(fd);
301
302                 strcpy(all_scsi_ids[k].dev, fname);
303                 all_scsi_ids[k].scsi_id = my_scsi_id;
304                 all_scsi_ids[k].host_no = host_no;
305         }
306         return 0;
307 }
308
309 /* print_path style */
310 #define ALL     0
311 #define NOWWID  1
312
313 static void
314 print_path(struct path * all_paths, int k, int style)
315 {
316         if (style != NOWWID)
317                 printf("%s ", all_paths[k].wwid);
318         else
319                 printf(" \\_");
320         printf("(%i %i %i %i) ",
321                all_paths[k].sg_id.host_no,
322                all_paths[k].sg_id.channel,
323                all_paths[k].sg_id.scsi_id, all_paths[k].sg_id.lun);
324         if(0 != strcmp(all_paths[k].sg_dev, all_paths[k].dev))
325                 printf("%s ", all_paths[k].sg_dev);
326         printf("%s ", all_paths[k].dev);
327         printf("[%.16s]\n", all_paths[k].product_id);
328 }
329
330 static void
331 print_all_path(struct env * conf, struct path * all_paths)
332 {
333         int k;
334         char empty_buff[WWID_SIZE];
335
336         memset(empty_buff, 0, WWID_SIZE);
337         for (k = 0; k < conf->max_devs; k++) {
338                 if (memcmp(empty_buff, all_paths[k].wwid, WWID_SIZE) == 0)
339                         continue;
340                 print_path(all_paths, k, ALL);
341         }
342 }
343
344 static void
345 print_all_mp(struct path * all_paths, struct multipath * mp, int nmp)
346 {
347         int k, i;
348
349         for (k = 0; k <= nmp; k++) {
350                 printf("%s\n", mp[k].wwid);
351                 for (i = 0; i <= mp[k].npaths; i++)
352                         print_path(all_paths, PINDEX(k,i), NOWWID);
353         }
354 }
355
356 static int
357 coalesce_paths(struct env * conf, struct multipath * mp,
358                struct path * all_paths)
359 {
360         int k, i, nmp, np, already_done;
361         char empty_buff[WWID_SIZE];
362
363         nmp = -1;
364         already_done = 0;
365         memset(empty_buff, 0, WWID_SIZE);
366
367         for (k = 0; k < conf->max_devs - 1; k++) {
368                 /* skip this path for some reason */
369
370                 /* 1. if path has no unique id */
371                 if (memcmp(empty_buff, all_paths[k].wwid, WWID_SIZE) == 0)
372                         continue;
373
374                 /* 2. if mp with this uid already instanciated */
375                 for (i = 0; i <= nmp; i++) {
376                         if (0 == strcmp(mp[i].wwid, all_paths[k].wwid))
377                                 already_done = 1;
378                 }
379                 if (already_done) {
380                         already_done = 0;
381                         continue;
382                 }
383
384                 /* at this point, we know we really got a new mp */
385                 np = 0;
386                 nmp++;
387                 strcpy(mp[nmp].wwid, all_paths[k].wwid);
388                 PINDEX(nmp,np) = k;
389
390                 if (mp[nmp].size == 0)
391                         mp[nmp].size = get_disk_size(all_paths[k].dev);
392
393                 for (i = k + 1; i < conf->max_devs; i++) {
394                         if (0 == strcmp(all_paths[k].wwid, all_paths[i].wwid)) {
395                                 np++;
396                                 PINDEX(nmp,np) = i;
397                                 mp[nmp].npaths = np;
398                         }
399                 }
400         }
401         return nmp;
402 }
403
404 static void
405 group_by_serial(struct multipath * mp, struct path * all_paths, char * str) {
406         int path_count, pg_count = 0;
407         int i, k;
408         int * bitmap;
409         char path_buff[FILE_NAME_SIZE];
410         char pg_buff[FILE_NAME_SIZE];
411         char * path_buff_p = &path_buff[0];
412         char * pg_buff_p = &pg_buff[0];
413
414         /* init the bitmap */
415         bitmap = malloc((mp->npaths + 1) * sizeof(int));
416         memset(bitmap, 0, (mp->npaths + 1) * sizeof(int));
417
418         for (i = 0; i <= mp->npaths; i++) {
419                 if (bitmap[i])
420                         continue;
421
422                 /* here, we really got a new pg */
423                 pg_count++;
424                 path_count = 1;
425                 memset(&path_buff, 0, FILE_NAME_SIZE * sizeof(char));
426                 path_buff_p = &path_buff[0];
427
428                 path_buff_p += sprintf(path_buff_p, " %s", all_paths[mp->pindex[i]].dev);
429                 bitmap[i] = 1;
430
431                 for (k = i + 1; k <= mp->npaths; k++) {
432                         if (bitmap[k])
433                                 continue;
434                         if (0 == strcmp(all_paths[mp->pindex[i]].serial,
435                                         all_paths[mp->pindex[k]].serial)) {
436                                 path_buff_p += sprintf(path_buff_p, " %s", all_paths[mp->pindex[k]].dev);
437                                 bitmap[k] = 1;
438                                 path_count++;
439                         }
440                 }
441                 pg_buff_p += sprintf(pg_buff_p, " 1 round-robin %i 0%s",
442                                      path_count, path_buff);
443         }
444         sprintf(str, " %i%s", pg_count, pg_buff);
445         free(bitmap);
446 }
447
448 static int
449 dm_simplecmd(int task, const char *name) {
450         int r = 0;
451         struct dm_task *dmt;
452
453         if (!(dmt = dm_task_create(task)))
454                 return 0;
455
456         if (!dm_task_set_name(dmt, name))
457                 goto out;
458
459         r = dm_task_run(dmt);
460
461         out:
462                 dm_task_destroy(dmt);
463                 return r;
464 }
465
466 static int
467 dm_addmap(int task, const char *name, const char *params, long size) {
468         struct dm_task *dmt;
469
470         if (!(dmt = dm_task_create(task)))
471                 return 0;
472
473         if (!dm_task_set_name(dmt, name))
474                 goto addout;
475
476         if (!dm_task_add_target(dmt, 0, size, DM_TARGET, params))
477                 goto addout;
478
479         if (!dm_task_run(dmt))
480                 goto addout;
481
482         addout:
483         dm_task_destroy(dmt);
484         return 1;
485 }
486
487 static int
488 setup_map(struct env * conf, struct path * all_paths,
489         struct multipath * mp, int index, int op)
490 {
491         char params[255];
492         char * params_p;
493         int i, np;
494
495         /* defaults for multipath target */
496         int dm_pg_prio              = 1;
497         char * dm_ps_name           = "round-robin";
498         int dm_ps_nr_args           = 0;
499
500         params_p = &params[0];
501
502         np = 0;
503         for (i=0; i<=mp[index].npaths; i++) {
504                 if (0 == all_paths[PINDEX(index,i)].sg_id.scsi_type)
505                         np++;
506         }
507
508         if (np < 1)
509                 return 0;
510
511         if ((all_paths[PINDEX(index,0)].iopolicy == MULTIBUS &&
512             conf->iopolicy == -1) || conf->iopolicy == MULTIBUS) {
513                 params_p += sprintf(params_p, " 1 %i %s %i %i",
514                                     dm_pg_prio, dm_ps_name, np, dm_ps_nr_args);
515                 
516                 for (i=0; i<=mp[index].npaths; i++) {
517                         if (0 != all_paths[PINDEX(index,i)].sg_id.scsi_type)
518                                 continue;
519                         params_p += sprintf(params_p, " %s",
520                                             all_paths[PINDEX(index,i)].dev);
521                 }
522         }
523
524         if ((all_paths[PINDEX(index,0)].iopolicy == FAILOVER &&
525              conf->iopolicy == -1) || conf->iopolicy == FAILOVER) {
526                 params_p += sprintf(params_p, " %i", mp[index].npaths + 1);
527                 for (i=0; i<=mp[index].npaths; i++) {
528                         if (0 != all_paths[PINDEX(index,i)].sg_id.scsi_type)
529                                 continue;
530                         params_p += sprintf(params_p, " %i %s ",
531                                             dm_pg_prio, dm_ps_name);
532                         params_p += sprintf(params_p, "1 %i",
533                                             dm_ps_nr_args);
534                         params_p += sprintf(params_p, " %s",
535                                             all_paths[PINDEX(index,i)].dev);
536                 }
537         }
538
539         if ((all_paths[PINDEX(index,0)].iopolicy == GROUP_BY_SERIAL &&
540              conf->iopolicy == -1) || conf->iopolicy == GROUP_BY_SERIAL) {
541                 group_by_serial(&mp[index], all_paths, params_p);
542         }
543
544         if (mp[index].size < 0)
545                 return 0;
546
547         if (!conf->quiet) {
548                 if (op == DM_DEVICE_RELOAD)
549                         printf("U:");
550                 if (op == DM_DEVICE_CREATE)
551                         printf("N:");
552                 printf("%s:0 %li %s %s\n",
553                         mp[index].wwid, mp[index].size, DM_TARGET, params);
554         }
555
556         if (op == DM_DEVICE_RELOAD)
557                 dm_simplecmd(DM_DEVICE_SUSPEND, mp[index].wwid);
558
559         dm_addmap(op, mp[index].wwid, params, mp[index].size);
560
561         if (op == DM_DEVICE_RELOAD)
562                 dm_simplecmd(DM_DEVICE_RESUME, mp[index].wwid);
563
564         return 1;
565 }
566
567 static int
568 map_present(char * str)
569 {
570         int r = 0;
571         struct dm_task *dmt;
572         struct dm_names *names;
573         unsigned next = 0;
574
575         if (!(dmt = dm_task_create(DM_DEVICE_LIST)))
576                 return 0;
577
578         if (!dm_task_run(dmt))
579                 goto out;
580
581         if (!(names = dm_task_get_names(dmt)))
582                 goto out;
583
584         if (!names->dev) {
585                 goto out;
586         }
587
588         do {
589                 if (0 == strcmp(names->name, str))
590                         r = 1;
591                 next = names->next;
592                 names = (void *) names + next;
593         } while (next);
594
595         out:
596         dm_task_destroy(dmt);
597         return r;
598 }
599
600 static void
601 usage(char * progname)
602 {
603         fprintf(stderr, VERSION_STRING);
604         fprintf(stderr, "Usage: %s [-v|-q] [-d] [-m max_devs]",
605                 progname);
606         fprintf(stderr, "[-p failover|multibus|group_by_serial] [device]\n");
607         fprintf(stderr, "\t-v\t\tverbose, print all paths and multipaths\n");
608         fprintf(stderr, "\t-q\t\tquiet, no output at all\n");
609         fprintf(stderr, "\t-d\t\tdry run, do not create or update devmaps\n");
610         fprintf(stderr, "\t-m max_devs\tscan {max_devs} devices at most\n");
611         fprintf(stderr, "\t-p policy\tforce maps to specified policy :\n");
612         fprintf(stderr, "\t   failover\t\t- 1 path per priority group\n");
613         fprintf(stderr, "\t   multibus\t\t- all paths in 1 priority group\n");
614         fprintf(stderr, "\t   group_by_serial\t- 1 priority group per serial\n");
615         fprintf(stderr, "\tdevice\t\tlimit scope to the device's multipath\n");
616         fprintf(stderr, "\t\t\t(hotplug-style $DEVPATH reference)\n");
617         exit(1);
618 }
619
620 int
621 main(int argc, char *argv[])
622 {
623         struct multipath * mp;
624         struct path * all_paths;
625         struct scsi_dev * all_scsi_ids;
626         struct env conf;
627         int i, k, nmp;
628
629         /* Default behaviour */
630         conf.max_devs = MAX_DEVS;
631         conf.dry_run = 0;       /* 1 == Do not Create/Update devmaps */
632         conf.verbose = 0;       /* 1 == Print all_paths and mp */
633         conf.quiet = 0;         /* 1 == Do not even print devmaps */
634         conf.iopolicy = -1;     /* Apply the defaults in get_unique_id() */
635
636         for (i = 1; i < argc; ++i) {
637                 if (0 == strcmp("-v", argv[i])) {
638                         if (conf.quiet == 1)
639                                 usage(argv[0]);
640                         conf.verbose = 1;
641                 } else if (0 == strcmp("-m", argv[i])) {
642                         conf.max_devs = atoi(argv[++i]);
643                         if (conf.max_devs < 2)
644                                 usage(argv[0]);
645                 } else if (0 == strcmp("-q", argv[i])) {
646                         if (conf.verbose == 1)
647                                 usage(argv[0]);
648                         conf.quiet = 1;
649                 } else if (0 == strcmp("-d", argv[i]))
650                         conf.dry_run = 1;
651                 else if (0 == strcmp("-p", argv[i])) {
652                         i++;
653                         if (!strcmp(argv[i], "failover"))
654                                 conf.iopolicy = FAILOVER;
655                         if (!strcmp(argv[i], "multibus"))
656                                 conf.iopolicy = MULTIBUS;
657                         if (!strcmp(argv[i], "group_by_serial"))
658                                 conf.iopolicy = GROUP_BY_SERIAL;
659                 } else if (*argv[i] == '-') {
660                         fprintf(stderr, "Unknown switch: %s\n", argv[i]);
661                         usage(argv[0]);
662                 } else
663                         strncpy(conf.hotplugdev, argv[i], FILE_NAME_SIZE);
664         }
665
666         /* dynamic allocations */
667         mp = malloc(conf.max_devs * sizeof(struct multipath));
668         all_paths = malloc(conf.max_devs * sizeof(struct path));
669         all_scsi_ids = malloc(conf.max_devs * sizeof(struct scsi_dev));
670         if (mp == NULL || all_paths == NULL || all_scsi_ids == NULL)
671                 exit(1);
672
673         if (sysfs_get_mnt_path(conf.sysfs_path, FILE_NAME_SIZE)) {
674                 get_all_scsi_ids(&conf, all_scsi_ids);
675                 get_all_paths_nosysfs(&conf, all_paths, all_scsi_ids);
676         } else {
677                 get_all_paths_sysfs(&conf, all_paths);
678         }
679         nmp = coalesce_paths(&conf, mp, all_paths);
680
681         if (conf.verbose) {
682                 print_all_path(&conf, all_paths);
683                 fprintf(stdout, "\n");
684                 print_all_mp(all_paths, mp, nmp);
685                 fprintf(stdout, "\n");
686         }
687
688         if (conf.dry_run)
689                 exit(0);
690
691         for (k=0; k<=nmp; k++) {
692                 if (map_present(mp[k].wwid)) {
693                         setup_map(&conf, all_paths, mp, k, DM_DEVICE_RELOAD);
694                 } else {
695                         setup_map(&conf, all_paths, mp, k, DM_DEVICE_CREATE);
696                 }
697         }
698
699         /* free allocs */
700         free(mp);
701         free(all_paths);
702         free(all_scsi_ids);
703
704         exit(0);
705 }