chiark / gitweb /
[PATCH] more extras/multipath updates
[elogind.git] / extras / multipath / main.c
1 /*
2  * Soft:        Description here...
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 <libsysfs.h>
29 #include "libdevmapper/libdevmapper.h"
30 #include "main.h"
31
32 static int
33 do_inq(int sg_fd, int cmddt, int evpd, unsigned int pg_op,
34        void *resp, int mx_resp_len, int noisy)
35 {
36         unsigned char inqCmdBlk[INQUIRY_CMDLEN] =
37             { INQUIRY_CMD, 0, 0, 0, 0, 0 };
38         unsigned char sense_b[SENSE_BUFF_LEN];
39         struct sg_io_hdr io_hdr;
40
41         if (cmddt)
42                 inqCmdBlk[1] |= 2;
43         if (evpd)
44                 inqCmdBlk[1] |= 1;
45         inqCmdBlk[2] = (unsigned char) pg_op;
46         inqCmdBlk[4] = (unsigned char) mx_resp_len;
47         memset(&io_hdr, 0, sizeof (struct sg_io_hdr));
48         io_hdr.interface_id = 'S';
49         io_hdr.cmd_len = sizeof (inqCmdBlk);
50         io_hdr.mx_sb_len = sizeof (sense_b);
51         io_hdr.dxfer_direction = SG_DXFER_FROM_DEV;
52         io_hdr.dxfer_len = mx_resp_len;
53         io_hdr.dxferp = resp;
54         io_hdr.cmdp = inqCmdBlk;
55         io_hdr.sbp = sense_b;
56         io_hdr.timeout = DEF_TIMEOUT;
57
58         if (ioctl(sg_fd, SG_IO, &io_hdr) < 0) {
59                 perror("SG_IO (inquiry) error");
60                 return -1;
61         }
62
63         /* treat SG_ERR here to get rid of sg_err.[ch] */
64         io_hdr.status &= 0x7e;
65         if ((0 == io_hdr.status) && (0 == io_hdr.host_status) &&
66             (0 == io_hdr.driver_status))
67                 return 0;
68         if ((SCSI_CHECK_CONDITION == io_hdr.status) ||
69             (SCSI_COMMAND_TERMINATED == io_hdr.status) ||
70             (SG_ERR_DRIVER_SENSE == (0xf & io_hdr.driver_status))) {
71                 if (io_hdr.sbp && (io_hdr.sb_len_wr > 2)) {
72                         int sense_key;
73                         unsigned char * sense_buffer = io_hdr.sbp;
74                         if (sense_buffer[0] & 0x2)
75                                 sense_key = sense_buffer[1] & 0xf;
76                         else
77                                 sense_key = sense_buffer[2] & 0xf;
78                         if(RECOVERED_ERROR == sense_key)
79                                 return 0;
80                 }
81         }
82         return -1;
83 }
84
85 static int
86 do_tur(int fd)
87 {
88         unsigned char turCmdBlk[TUR_CMD_LEN] = { 0x00, 0, 0, 0, 0, 0 };
89         struct sg_io_hdr io_hdr;
90         unsigned char sense_buffer[32];
91
92         memset(&io_hdr, 0, sizeof (struct sg_io_hdr));
93         io_hdr.interface_id = 'S';
94         io_hdr.cmd_len = sizeof (turCmdBlk);
95         io_hdr.mx_sb_len = sizeof (sense_buffer);
96         io_hdr.dxfer_direction = SG_DXFER_NONE;
97         io_hdr.cmdp = turCmdBlk;
98         io_hdr.sbp = sense_buffer;
99         io_hdr.timeout = 20000;
100         io_hdr.pack_id = 0;
101         if (ioctl(fd, SG_IO, &io_hdr) < 0) {
102                 close(fd);
103                 return 0;
104         }
105         if (io_hdr.info & SG_INFO_OK_MASK) {
106                 return 0;
107         }
108         return 1;
109 }
110
111 static void
112 sprint_wwid(char * buff, const char * str)
113 {
114         int i;
115         const char *p;
116         char *cursor;
117         unsigned char c;
118
119         p = str;
120         cursor = buff;
121         for (i = 0; i <= WWID_SIZE / 2 - 1; i++) {
122                 c = *p++;
123                 sprintf(cursor, "%.2x", (int) (unsigned char) c);
124                 cursor += 2;
125         }
126         buff[WWID_SIZE - 1] = '\0';
127 }
128
129 static int
130 get_lun_strings(int fd, struct path * mypath)
131 {
132         char buff[36];
133
134         if (0 == do_inq(fd, 0, 0, 0, buff, 36, 1)) {
135                 memcpy(mypath->vendor_id, &buff[8], 8);
136                 memcpy(mypath->product_id, &buff[16], 16);
137                 memcpy(mypath->rev, &buff[32], 4);
138                 return 1;
139         }
140         return 0;
141 }
142
143 /*
144 static int
145 get_serial (int fd, char * str)
146 {
147         char buff[MX_ALLOC_LEN + 1];
148         int len;
149
150         if (0 == do_inq(fd, 0, 1, 0x80, buff, MX_ALLOC_LEN, 0)) {
151                 len = buff[3];
152                 if (len > 0) {
153                         memcpy(str, buff + 4, len);
154                         buff[len] = '\0';
155                 }
156                 return 1;
157         }
158         return 0;
159 }
160 */
161
162 /* hardware vendor specifics : add support for new models below */
163 static int
164 get_storageworks_wwid(int fd, char *str)
165 {
166         char buff[64];
167
168         if (0 == do_inq(fd, 0, 1, 0x83, buff, sizeof (buff), 1)) {
169                 sprint_wwid(str, &buff[8]);
170                 return 1;
171         }
172         return 0;
173 }
174
175 /* White list switch */
176 static int
177 get_unique_id(int fd, struct path * mypath)
178 {
179         if (strncmp(mypath->product_id, "HSV110 (C)COMPAQ", 16) == 0 ||
180             strncmp(mypath->product_id, "HSG80           ", 16) == 0) {
181                 get_storageworks_wwid(fd, mypath->wwid);
182                 return 0;
183         }
184
185         return 1;
186 }
187
188 static void
189 basename(char * str1, char * str2)
190 {
191         char *p = str1 + (strlen(str1) - 1);
192
193         while (*--p != '/')
194                 continue;
195         strcpy(str2, ++p);
196 }
197
198 static int
199 get_all_paths_sysfs(struct env * conf, struct path * all_paths)
200 {
201         int k=0;
202         int sg_fd;
203         struct sysfs_directory * sdir;
204         struct sysfs_directory * devp;
205         struct sysfs_link * linkp;
206         char buff[FILE_NAME_SIZE];
207
208         char block_path[FILE_NAME_SIZE];
209
210         sprintf(block_path, "%s/block", conf->sysfs_path);
211         sdir = sysfs_open_directory(block_path);
212         sysfs_read_directory(sdir);
213         dlist_for_each_data(sdir->subdirs, devp, struct sysfs_directory) {
214                 sysfs_read_directory(devp);
215                 if(devp->links == NULL)
216                         continue;
217                 dlist_for_each_data(devp->links, linkp, struct sysfs_link) {
218                         if (!strncmp(linkp->name, "device", 6))
219                                 break;
220                 }
221                 if (linkp == NULL) {
222                         continue;
223                 }
224
225                 basename(devp->path, buff);
226                 sprintf(all_paths[k].sg_dev, "/dev/%s", buff);
227                 strcpy(all_paths[k].dev, all_paths[k].sg_dev);
228                 if ((sg_fd = open(all_paths[k].sg_dev, O_RDONLY)) < 0) {
229                         continue;
230                 }
231                 get_lun_strings(sg_fd, &all_paths[k]);
232                 get_unique_id(sg_fd, &all_paths[k]);
233                 all_paths[k].state = do_tur(sg_fd);
234                 close(sg_fd);
235                 basename(linkp->target, buff);
236                 sscanf(buff, "%i:%i:%i:%i",
237                         &all_paths[k].sg_id.host_no,
238                         &all_paths[k].sg_id.channel,
239                         &all_paths[k].sg_id.scsi_id,
240                         &all_paths[k].sg_id.lun);
241                 k++;
242         }
243         sysfs_close_directory(sdir);
244
245         return 0;
246 }
247
248 static int
249 get_all_paths_nosysfs(struct env * conf, struct path * all_paths,
250                       struct scsi_dev * all_scsi_ids)
251 {
252         int k, i, sg_fd;
253         char buff[FILE_NAME_SIZE];
254         char file_name[FILE_NAME_SIZE];
255
256         for (k = 0; k < conf->max_devs; k++) {
257                 strcpy(file_name, "/dev/sg");
258                 sprintf(buff, "%d", k);
259                 strncat(file_name, buff, FILE_NAME_SIZE);
260                 strcpy(all_paths[k].sg_dev, file_name);
261                 if ((sg_fd = open(file_name, O_RDONLY)) < 0)
262                         continue;
263                 get_lun_strings(sg_fd, &all_paths[k]);
264                 get_unique_id(sg_fd, &all_paths[k]);
265                 all_paths[k].state = do_tur(sg_fd);
266                 if (0 > ioctl(sg_fd, SG_GET_SCSI_ID, &(all_paths[k].sg_id)))
267                         printf("device %s failed on sg ioctl, skip\n",
268                                file_name);
269
270                 close(sg_fd);
271
272                 for (i = 0; i < conf->max_devs; i++) {
273                         if ((all_paths[k].sg_id.host_no ==
274                              all_scsi_ids[i].host_no)
275                             && (all_paths[k].sg_id.scsi_id ==
276                                 (all_scsi_ids[i].scsi_id.dev_id & 0xff))
277                             && (all_paths[k].sg_id.lun ==
278                                 ((all_scsi_ids[i].scsi_id.dev_id >> 8) & 0xff))
279                             && (all_paths[k].sg_id.channel ==
280                                 ((all_scsi_ids[i].scsi_id.
281                                   dev_id >> 16) & 0xff))) {
282                                 strcpy(all_paths[k].dev, all_scsi_ids[i].dev);
283                                 break;
284                         }
285                 }
286         }
287         return 0;
288 }
289
290 static int
291 get_all_scsi_ids(struct env * conf, struct scsi_dev * all_scsi_ids)
292 {
293         int k, big, little, res, host_no, fd;
294         char buff[64];
295         char fname[FILE_NAME_SIZE];
296         struct scsi_idlun my_scsi_id;
297
298         for (k = 0; k < conf->max_devs; k++) {
299                 strcpy(fname, "/dev/sd");
300                 if (k < 26) {
301                         buff[0] = 'a' + (char) k;
302                         buff[1] = '\0';
303                         strcat(fname, buff);
304                 } else if (k <= 255) {  /* assumes sequence goes x,y,z,aa,ab,ac etc */
305                         big = k / 26;
306                         little = k - (26 * big);
307                         big = big - 1;
308
309                         buff[0] = 'a' + (char) big;
310                         buff[1] = 'a' + (char) little;
311                         buff[2] = '\0';
312                         strcat(fname, buff);
313                 } else
314                         strcat(fname, "xxxx");
315
316                 if ((fd = open(fname, O_RDONLY)) < 0)
317                         continue;
318
319                 res = ioctl(fd, SCSI_IOCTL_GET_IDLUN, &my_scsi_id);
320                 if (res < 0) {
321                         close(fd);
322                         printf("Could not get scsi idlun\n");
323                         continue;
324                 }
325
326                 res = ioctl(fd, SCSI_IOCTL_GET_BUS_NUMBER, &host_no);
327                 if (res < 0) {
328                         close(fd);
329                         printf("Could not get host_no\n");
330                         continue;
331                 }
332
333                 close(fd);
334
335                 strcpy(all_scsi_ids[k].dev, fname);
336                 all_scsi_ids[k].scsi_id = my_scsi_id;
337                 all_scsi_ids[k].host_no = host_no;
338         }
339         return 0;
340 }
341
342 /* print_path style */
343 #define ALL     0
344 #define NOWWID  1
345
346 static void
347 print_path(struct path * all_paths, int k, int style)
348 {
349         if (style != NOWWID)
350                 printf("%s ", all_paths[k].wwid);
351         else
352                 printf(" \\_");
353         printf("(%i %i %i %i) ",
354                all_paths[k].sg_id.host_no,
355                all_paths[k].sg_id.channel,
356                all_paths[k].sg_id.scsi_id, all_paths[k].sg_id.lun);
357         printf("%s ", all_paths[k].sg_dev);
358         printf("op:%i ", all_paths[k].state);
359         printf("%s ", all_paths[k].dev);
360         printf("[%.16s]\n", all_paths[k].product_id);
361 }
362
363 static void
364 print_all_path(struct env * conf, struct path * all_paths)
365 {
366         int k;
367         char empty_buff[WWID_SIZE];
368
369         memset(empty_buff, 0, WWID_SIZE);
370         for (k = 0; k < conf->max_devs; k++) {
371                 if (memcmp(empty_buff, all_paths[k].wwid, WWID_SIZE) == 0)
372                         continue;
373                 print_path(all_paths, k, ALL);
374         }
375 }
376
377 static void
378 print_all_mp(struct path * all_paths, struct multipath * mp, int nmp)
379 {
380         int k, i;
381
382         for (k = 0; k <= nmp; k++) {
383                 printf("%s\n", mp[k].wwid);
384                 for (i = 0; i <= mp[k].npaths; i++)
385                         print_path(all_paths, PINDEX(k,i), NOWWID);
386         }
387 }
388
389 static int
390 coalesce_paths(struct env * conf, struct multipath * mp,
391                struct path * all_paths)
392 {
393         int k, i, nmp, np, already_done;
394         char empty_buff[WWID_SIZE];
395
396         nmp = -1;
397         already_done = 0;
398         memset(empty_buff, 0, WWID_SIZE);
399
400         for (k = 0; k < conf->max_devs - 1; k++) {
401                 /* skip this path if no unique id has been found */
402                 if (memcmp(empty_buff, all_paths[k].wwid, WWID_SIZE) == 0)
403                         continue;
404                 np = 0;
405
406                 for (i = 0; i <= nmp; i++) {
407                         if (0 == strcmp(mp[i].wwid, all_paths[k].wwid))
408                                 already_done = 1;
409                 }
410
411                 if (already_done) {
412                         already_done = 0;
413                         continue;
414                 }
415
416                 nmp++;
417                 strcpy(mp[nmp].wwid, all_paths[k].wwid);
418                 PINDEX(nmp,np) = k;
419
420                 for (i = k + 1; i < conf->max_devs; i++) {
421                         if (0 == strcmp(all_paths[k].wwid, all_paths[i].wwid)) {
422                                 np++;
423                                 PINDEX(nmp,np) = i;
424                                 mp[nmp].npaths = np;
425                         }
426                 }
427         }
428         return nmp;
429 }
430
431 static long
432 get_disk_size (struct env * conf, char * dev) {
433         long size;
434         int fd;
435         char attr_path[FILE_NAME_SIZE];
436         char buff[FILE_NAME_SIZE];
437         char basedev[FILE_NAME_SIZE];
438
439         if(conf->with_sysfs) {
440                 basename(dev, basedev);
441                 sprintf(attr_path, "%s/block/%s/size",
442                         conf->sysfs_path, basedev);
443                 if (0 > sysfs_read_attribute_value(attr_path, buff,
444                                          FILE_NAME_SIZE * sizeof(char)))
445                         return -1;
446                 size = atoi(buff);
447                 return size;
448         } else {
449                 if ((fd = open(dev, O_RDONLY)) < 0)
450                         return -1;
451                 if(!ioctl(fd, BLKGETSIZE, &size))
452                         return size;
453         }
454         return -1;
455 }
456
457 static int
458 make_dm_node(char * str)
459 {
460         int r = 0;
461         char buff[FILE_NAME_SIZE];
462         struct dm_names * names;
463         unsigned next = 0;
464         struct dm_task *dmt;
465
466         if (!(dmt = dm_task_create(DM_DEVICE_LIST)))
467                 return 0;
468
469         if (!dm_task_run(dmt))
470                 goto out;
471
472         if (!(names = dm_task_get_names(dmt)))
473                 goto out;
474
475         if (!names->dev) {
476                 r = 1;
477                 goto out;
478         }
479
480         do {
481                 if (0 == strcmp(names->name, str))
482                         break;
483                 next = names->next;
484                 names = (void *) names + next;
485         } while (next);
486
487         sprintf(buff, "/dev/mapper/%s", str);
488         unlink(buff);
489         mknod(buff, 0600 | S_IFBLK, names->dev);
490
491         out:
492         dm_task_destroy(dmt);
493         return r;
494
495 }
496
497 /* future use ?
498 static int
499 del_map(char * str) {
500         struct dm_task *dmt;
501
502         if (!(dmt = dm_task_create(DM_DEVICE_REMOVE)))
503                 return 0;
504         if (!dm_task_set_name(dmt, str))
505                 goto delout;
506         if (!dm_task_run(dmt))
507                 goto delout;
508
509         printf("Deleted device map : %s\n", str);
510
511         delout:
512         dm_task_destroy(dmt);
513         return 1;
514 }
515 */
516
517 static int
518 add_map(struct env * conf, struct path * all_paths,
519         struct multipath * mp, int index, int op)
520 {
521         char params[255];
522         char * params_p;
523         struct dm_task *dmt;
524         int i, np;
525         long size = -1;
526
527         if (!(dmt = dm_task_create(op)))
528                 return 0;
529
530         if (!dm_task_set_name(dmt, mp[index].wwid))
531                 goto addout;
532         params_p = &params[0];
533
534         np = 0;
535         for (i=0; i<=mp[index].npaths; i++) {
536                 if ((1 == all_paths[PINDEX(index,i)].state) &&
537                         (0 == all_paths[PINDEX(index,i)].sg_id.scsi_type))
538                         np++;
539         }
540         if (np == 0)
541                 goto addout;
542         params_p += sprintf(params_p, "%i 32", np);
543         
544         for (i=0; i<=mp[index].npaths; i++) {
545                 if (( 0 == all_paths[PINDEX(index,i)].state) ||
546                         (0 != all_paths[PINDEX(index,i)].sg_id.scsi_type))
547                         continue;
548                 if (size < 0)
549                         size = get_disk_size(conf, all_paths[PINDEX(index,0)].dev);
550                 params_p += sprintf(params_p, " %s %i",
551                         all_paths[PINDEX(index,i)].dev, 0);
552         }
553
554         if (size < 0)
555                 goto addout;
556
557         if (!conf->quiet) {
558                 if (op == DM_DEVICE_RELOAD)
559                         printf("U|");
560                 if (op == DM_DEVICE_CREATE)
561                         printf("N|");
562                 printf("%s : 0 %li %s %s\n",
563                         mp[index].wwid, size, DM_TARGET, params);
564         }
565
566         if (!dm_task_add_target(dmt, 0, size, DM_TARGET, params))
567                 goto addout;
568
569         if (!dm_task_run(dmt))
570                 goto addout;
571
572
573         make_dm_node(mp[index].wwid);
574
575         addout:
576         dm_task_destroy(dmt);
577         return 1;
578 }
579
580 /*
581 static int
582 get_table(const char * str)
583 {
584         int r = 0;
585         struct dm_task *dmt;
586         void *next = NULL;
587         uint64_t start, length;
588         char *target_type = NULL;
589         char *params;
590
591         if (!(dmt = dm_task_create(DM_DEVICE_TABLE)))
592                 return 0;
593
594         if (!dm_task_set_name(dmt, str))
595                 goto out;
596
597         if (!dm_task_run(dmt))
598                 goto out;
599
600         do {
601                 next = dm_get_next_target(dmt, next, &start, &length,
602                                           &target_type, &params);
603                 if (target_type) {
604                         printf("%" PRIu64 " %" PRIu64 " %s %s\n",
605                                start, length, target_type, params);
606                 }
607         } while (next);
608
609         r = 1;
610
611       out:
612         dm_task_destroy(dmt);
613         return r;
614
615 }
616 */
617
618 static int
619 map_present(char * str)
620 {
621         int r = 0;
622         struct dm_task *dmt;
623         struct dm_names *names;
624         unsigned next = 0;
625
626         if (!(dmt = dm_task_create(DM_DEVICE_LIST)))
627                 return 0;
628
629         if (!dm_task_run(dmt))
630                 goto out;
631
632         if (!(names = dm_task_get_names(dmt)))
633                 goto out;
634
635         if (!names->dev) {
636                 goto out;
637         }
638
639         do {
640                 if (0 == strcmp(names->name, str))
641                         r = 1;
642                 next = names->next;
643                 names = (void *) names + next;
644         } while (next);
645
646         out:
647         dm_task_destroy(dmt);
648         return r;
649 }
650
651 static void
652 usage(char * progname)
653 {
654         fprintf(stderr, VERSION_STRING);
655         fprintf(stderr, "Usage: %s [-v|-q] [-d] [-m max_devs]\n", progname);
656         fprintf(stderr, "\t-v\t\tverbose, print all paths and multipaths\n");
657         fprintf(stderr, "\t-q\t\tquiet, no output at all\n");
658         fprintf(stderr, "\t-d\t\tdry run, do not create or update devmaps\n");
659         fprintf(stderr, "\t-m max_devs\tscan {max_devs} devices at most\n");
660         exit(1);
661 }
662
663 static int
664 running(char * run) {
665         struct stat buf;
666
667         if(!stat(run, &buf))
668                 return 1;
669         return 0;
670 }
671
672 int
673 main(int argc, char *argv[])
674 {
675         char * run = "/var/run/multipath.run";
676         struct multipath * mp;
677         struct path * all_paths;
678         struct scsi_dev * all_scsi_ids;
679         struct env conf;
680         int i, k, nmp;
681
682         /* Default behaviour */
683         conf.max_devs = MAX_DEVS;
684         conf.dry_run = 0;       /* 1 == Do not Create/Update devmaps */
685         conf.verbose = 0;       /* 1 == Print all_paths and mp */
686         conf.quiet = 0;         /* 1 == Do not even print devmaps */
687         conf.with_sysfs = 0;    /* Default to compat / suboptimal behaviour */
688
689         /* kindly provided by libsysfs */
690         if (0 == sysfs_get_mnt_path(conf.sysfs_path, FILE_NAME_SIZE))
691                 conf.with_sysfs = 1;
692
693         for (i = 1; i < argc; ++i) {
694                 if (0 == strcmp("-v", argv[i])) {
695                         if (conf.quiet == 1)
696                                 usage(argv[0]);
697                         conf.verbose = 1;
698                 } else if (0 == strcmp("-m", argv[i])) {
699                         conf.max_devs = atoi(argv[++i]);
700                         if (conf.max_devs < 2)
701                                 usage(argv[0]);
702                 } else if (0 == strcmp("-q", argv[i])) {
703                         if (conf.verbose == 1)
704                                 usage(argv[0]);
705                         conf.quiet = 1;
706                 } else if (0 == strcmp("-d", argv[i]))
707                         conf.dry_run = 1;
708                 else if (*argv[i] == '-') {
709                         fprintf(stderr, "Unknown switch: %s\n", argv[i]);
710                         usage(argv[0]);
711                 } else if (*argv[i] != '-') {
712                         fprintf(stderr, "Unknown argument\n");
713                         usage(argv[0]);
714                 }
715
716         }
717
718         if (running(run)) {
719                 if (conf.verbose) {
720                         fprintf(stderr, "Already running.\n");
721                         fprintf(stderr, "If you know what you do, please ");
722                         fprintf(stderr, "remove %s\n", run);
723                 }
724                 return 1;
725         }
726
727         if(!open(run, O_CREAT))
728                 exit(1);
729
730         /* dynamic allocations */
731         mp = malloc(conf.max_devs * sizeof(struct multipath));
732         all_paths = malloc(conf.max_devs * sizeof(struct path));
733         all_scsi_ids = malloc(conf.max_devs * sizeof(struct scsi_dev));
734         if (mp == NULL || all_paths == NULL || all_scsi_ids == NULL) {
735                 unlink(run);
736                 exit(1);
737         }
738
739         if (!conf.with_sysfs) {
740                 get_all_scsi_ids(&conf, all_scsi_ids);
741                 get_all_paths_nosysfs(&conf, all_paths, all_scsi_ids);
742         } else {
743                 get_all_paths_sysfs(&conf, all_paths);
744         }
745         nmp = coalesce_paths(&conf, mp, all_paths);
746
747         if (conf.verbose) {
748                 print_all_path(&conf, all_paths);
749                 fprintf(stdout, "\n");
750                 print_all_mp(all_paths, mp, nmp);
751                 fprintf(stdout, "\n");
752         }
753
754         if (conf.dry_run) {
755                 unlink(run);
756                 exit(0);
757         }
758
759         for (k=0; k<=nmp; k++) {
760                 if (map_present(mp[k].wwid)) {
761                         add_map(&conf, all_paths, mp, k, DM_DEVICE_RELOAD);
762                 } else {
763                         add_map(&conf, all_paths, mp, k, DM_DEVICE_CREATE);
764                 }
765         }
766         unlink(run);
767         exit(0);
768 }