X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=extras%2Fmultipath%2Fmain.c;h=a8e29e8ba60e876e39c8ec9d882a91c0ce743ee6;hp=b5ab664433165d8b661f34e45757ccbb143f170a;hb=b02d14d0a6210ceb76e097a56109abeecdd2b112;hpb=359618cd6ed05adcad97380f51790198ff653f87 diff --git a/extras/multipath/main.c b/extras/multipath/main.c index b5ab66443..a8e29e8ba 100644 --- a/extras/multipath/main.c +++ b/extras/multipath/main.c @@ -1,5 +1,5 @@ /* - * Soft: Description here... + * Soft: multipath device mapper target autoconfig * * Version: $Id: main.h,v 0.0.1 2003/09/18 15:13:38 cvaroqui Exp $ * @@ -26,7 +26,7 @@ #include #include #include -#include +#include "libdevmapper/libdevmapper.h" #include "main.h" static int @@ -82,32 +82,6 @@ do_inq(int sg_fd, int cmddt, int evpd, unsigned int pg_op, return -1; } -static int -do_tur(int fd) -{ - unsigned char turCmdBlk[TUR_CMD_LEN] = { 0x00, 0, 0, 0, 0, 0 }; - struct sg_io_hdr io_hdr; - unsigned char sense_buffer[32]; - - memset(&io_hdr, 0, sizeof (struct sg_io_hdr)); - io_hdr.interface_id = 'S'; - io_hdr.cmd_len = sizeof (turCmdBlk); - io_hdr.mx_sb_len = sizeof (sense_buffer); - io_hdr.dxfer_direction = SG_DXFER_NONE; - io_hdr.cmdp = turCmdBlk; - io_hdr.sbp = sense_buffer; - io_hdr.timeout = 20000; - io_hdr.pack_id = 0; - if (ioctl(fd, SG_IO, &io_hdr) < 0) { - close(fd); - return 0; - } - if (io_hdr.info & SG_INFO_OK_MASK) { - return 0; - } - return 1; -} - static void sprint_wwid(char * buff, const char * str) { @@ -126,112 +100,229 @@ sprint_wwid(char * buff, const char * str) buff[WWID_SIZE - 1] = '\0'; } +static void +basename(char * str1, char * str2) +{ + char *p = str1 + (strlen(str1) - 1); + + while (*--p != '/') + continue; + strcpy(str2, ++p); +} + static int -get_lun_strings(int fd, struct path * mypath) +get_lun_strings(struct env * conf, struct path * mypath) { + int fd; char buff[36]; + char attr_path[FILE_NAME_SIZE]; + char basedev[FILE_NAME_SIZE]; - if (0 == do_inq(fd, 0, 0, 0, buff, 36, 1)) { + if(conf->with_sysfs) { + /* sysfs style */ + basename(mypath->sg_dev, basedev); + + sprintf(attr_path, "%s/block/%s/device/vendor", + conf->sysfs_path, basedev); + if (0 > sysfs_read_attribute_value(attr_path, + mypath->vendor_id, 8)) return 0; + + sprintf(attr_path, "%s/block/%s/device/model", + conf->sysfs_path, basedev); + if (0 > sysfs_read_attribute_value(attr_path, + mypath->product_id, 16)) return 0; + + sprintf(attr_path, "%s/block/%s/device/rev", + conf->sysfs_path, basedev); + if (0 > sysfs_read_attribute_value(attr_path, + mypath->rev, 4)) return 0; + } else { + /* ioctl style */ + if ((fd = open(mypath->sg_dev, O_RDONLY)) < 0) + return 0; + if (0 != do_inq(fd, 0, 0, 0, buff, 36, 1)) + return 0; memcpy(mypath->vendor_id, &buff[8], 8); memcpy(mypath->product_id, &buff[16], 16); memcpy(mypath->rev, &buff[32], 4); + close(fd); return 1; } return 0; } -/* -static int -get_serial (int fd, char * str) -{ - char buff[MX_ALLOC_LEN + 1]; - int len; - - if (0 == do_inq(fd, 0, 1, 0x80, buff, MX_ALLOC_LEN, 0)) { - len = buff[3]; - if (len > 0) { - memcpy(str, buff + 4, len); - buff[len] = '\0'; - } - return 1; - } - return 0; -} -*/ - /* hardware vendor specifics : add support for new models below */ + +/* this one get EVPD page 0x83 off 8 */ +/* tested ok with StorageWorks */ static int -get_storageworks_wwid(int fd, char *str) +get_evpd_wwid(struct path * mypath) { + int fd; char buff[64]; + if ((fd = open(mypath->sg_dev, O_RDONLY)) < 0) + return 0; + if (0 == do_inq(fd, 0, 1, 0x83, buff, sizeof (buff), 1)) { - sprint_wwid(str, &buff[8]); - return 1; + sprint_wwid(mypath->wwid, &buff[8]); + close(fd); + return 1; /* success */ } - return 0; + close(fd); + return 0; /* not good */ } /* White list switch */ static int -get_unique_id(int fd, struct path * mypath) +get_unique_id(struct path * mypath) { - if (strncmp(mypath->product_id, "HSV110 (C)COMPAQ", 16) == 0 || - strncmp(mypath->product_id, "HSG80 ", 16) == 0) { - get_storageworks_wwid(fd, mypath->wwid); - return 0; + int i; + static struct { + char * vendor; + char * product; + int iopolicy; + int (*getuid) (struct path *); + } wlist[] = { + {"COMPAQ ", "HSV110 (C)COMPAQ", MULTIBUS, &get_evpd_wwid}, + {"COMPAQ ", "MSA1000 ", MULTIBUS, &get_evpd_wwid}, + {"COMPAQ ", "MSA1000 VOLUME ", MULTIBUS, &get_evpd_wwid}, + {"DEC ", "HSG80 ", MULTIBUS, &get_evpd_wwid}, + {"HP ", "HSV100 ", MULTIBUS, &get_evpd_wwid}, + {"HP ", "A6189A ", MULTIBUS, &get_evpd_wwid}, + {"HP ", "OPEN- ", MULTIBUS, &get_evpd_wwid}, + {"DDN ", "SAN DataDirector", MULTIBUS, &get_evpd_wwid}, + {"FSC ", "CentricStor ", MULTIBUS, &get_evpd_wwid}, + {"HITACHI ", "DF400 ", MULTIBUS, &get_evpd_wwid}, + {"HITACHI ", "DF500 ", MULTIBUS, &get_evpd_wwid}, + {"HITACHI ", "DF600 ", MULTIBUS, &get_evpd_wwid}, + {"IBM ", "ProFibre 4000R ", MULTIBUS, &get_evpd_wwid}, + {"SGI ", "TP9100 ", MULTIBUS, &get_evpd_wwid}, + {"SGI ", "TP9300 ", MULTIBUS, &get_evpd_wwid}, + {"SGI ", "TP9400 ", MULTIBUS, &get_evpd_wwid}, + {"SGI ", "TP9500 ", MULTIBUS, &get_evpd_wwid}, + {NULL, NULL, 0, NULL}, + }; + + for (i = 0; wlist[i].vendor; i++) { + if (strncmp(mypath->vendor_id, wlist[i].vendor, 8) == 0 && + strncmp(mypath->product_id, wlist[i].product, 16) == 0) { + mypath->iopolicy = wlist[i].iopolicy; + if (!wlist[i].getuid(mypath)) + return 0; + } } - return 1; } -static void -basename(char * str1, char * str2) -{ - char *p = str1 + (strlen(str1) - 1); - - while (*--p != '/') - continue; - 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) == 0) + return 1; + } + return 0; } static int get_all_paths_sysfs(struct env * conf, struct path * all_paths) { int k=0; - int sg_fd; struct sysfs_directory * sdir; struct sysfs_directory * devp; struct sysfs_link * linkp; + char refwwid[WWID_SIZE]; + char empty_buff[WWID_SIZE]; char buff[FILE_NAME_SIZE]; + char path[FILE_NAME_SIZE]; + struct path curpath; - char block_path[FILE_NAME_SIZE]; + /* if called from hotplug, only consider the paths that relate to */ + /* to the device pointed by conf.hotplugdev */ + memset(empty_buff, 0, WWID_SIZE); + memset(refwwid, 0, WWID_SIZE); + if (strncmp("/devices", conf->hotplugdev, 8) == 0) { + sprintf(buff, "%s%s/block", + conf->sysfs_path, conf->hotplugdev); + memset(conf->hotplugdev, 0, FILE_NAME_SIZE); + + /* if called from hotplug but with no block, leave */ + if (0 > readlink(buff, conf->hotplugdev, FILE_NAME_SIZE)) + return 0; + + basename(conf->hotplugdev, buff); + sprintf(curpath.sg_dev, "/dev/%s", buff); + + get_lun_strings(conf, &curpath); + if (!get_unique_id(&curpath)) + return 0; + strcpy(refwwid, curpath.wwid); + memset(&curpath, 0, sizeof(path)); + } - sprintf(block_path, "%s/block", conf->sysfs_path); - sdir = sysfs_open_directory(block_path); + sprintf(path, "%s/block", conf->sysfs_path); + sdir = sysfs_open_directory(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; + dlist_for_each_data(devp->links, linkp, struct sysfs_link) { if (!strncmp(linkp->name, "device", 6)) break; } + if (linkp == NULL) { continue; } basename(devp->path, buff); - sprintf(all_paths[k].sg_dev, "/dev/%s", buff); - strcpy(all_paths[k].dev, all_paths[k].sg_dev); - if ((sg_fd = open(all_paths[k].sg_dev, O_RDONLY)) < 0) { + sprintf(curpath.sg_dev, "/dev/%s", buff); + + get_lun_strings(conf, &curpath); + if(!get_unique_id(&curpath)) { + memset(&curpath, 0, sizeof(path)); continue; } - get_lun_strings(sg_fd, &all_paths[k]); - get_unique_id(sg_fd, &all_paths[k]); - all_paths[k].state = do_tur(sg_fd); - close(sg_fd); + + if (memcmp(empty_buff, refwwid, WWID_SIZE) != 0 && + strncmp(curpath.wwid, refwwid, WWID_SIZE) != 0) { + memset(&curpath, 0, sizeof(path)); + continue; + } + + strcpy(all_paths[k].sg_dev, curpath.sg_dev); + strcpy(all_paths[k].dev, curpath.sg_dev); + strcpy(all_paths[k].wwid, curpath.wwid); + strcpy(all_paths[k].vendor_id, curpath.vendor_id); + strcpy(all_paths[k].product_id, curpath.product_id); + all_paths[k].iopolicy = curpath.iopolicy; + + /* done with curpath, zero for reuse */ + memset(&curpath, 0, sizeof(path)); + basename(linkp->target, buff); sscanf(buff, "%i:%i:%i:%i", &all_paths[k].sg_id.host_no, @@ -241,7 +332,6 @@ get_all_paths_sysfs(struct env * conf, struct path * all_paths) k++; } sysfs_close_directory(sdir); - return 0; } @@ -249,7 +339,7 @@ static int get_all_paths_nosysfs(struct env * conf, struct path * all_paths, struct scsi_dev * all_scsi_ids) { - int k, i, sg_fd; + int k, i, fd; char buff[FILE_NAME_SIZE]; char file_name[FILE_NAME_SIZE]; @@ -258,16 +348,19 @@ get_all_paths_nosysfs(struct env * conf, struct path * all_paths, sprintf(buff, "%d", k); strncat(file_name, buff, FILE_NAME_SIZE); strcpy(all_paths[k].sg_dev, file_name); - if ((sg_fd = open(file_name, O_RDONLY)) < 0) + + get_lun_strings(conf, &all_paths[k]); + if (!get_unique_id(&all_paths[k])) continue; - get_lun_strings(sg_fd, &all_paths[k]); - get_unique_id(sg_fd, &all_paths[k]); - all_paths[k].state = do_tur(sg_fd); - if (0 > ioctl(sg_fd, SG_GET_SCSI_ID, &(all_paths[k].sg_id))) + + if ((fd = open(all_paths[k].sg_dev, O_RDONLY)) < 0) + return 0; + + if (0 > ioctl(fd, SG_GET_SCSI_ID, &(all_paths[k].sg_id))) printf("device %s failed on sg ioctl, skip\n", file_name); - close(sg_fd); + close(fd); for (i = 0; i < conf->max_devs; i++) { if ((all_paths[k].sg_id.host_no == @@ -301,7 +394,8 @@ get_all_scsi_ids(struct env * conf, struct scsi_dev * all_scsi_ids) buff[0] = 'a' + (char) k; buff[1] = '\0'; strcat(fname, buff); - } else if (k <= 255) { /* assumes sequence goes x,y,z,aa,ab,ac etc */ + } else if (k <= 255) { + /* assumes sequence goes x,y,z,aa,ab,ac etc */ big = k / 26; little = k - (26 * big); big = big - 1; @@ -313,8 +407,12 @@ get_all_scsi_ids(struct env * conf, struct scsi_dev * all_scsi_ids) } else strcat(fname, "xxxx"); - if ((fd = open(fname, O_RDONLY)) < 0) + if ((fd = open(fname, O_RDONLY)) < 0) { + if (conf->verbose) + fprintf(stderr, "can't open %s. mknod ?", + fname); continue; + } res = ioctl(fd, SCSI_IOCTL_GET_IDLUN, &my_scsi_id); if (res < 0) { @@ -354,8 +452,8 @@ print_path(struct path * all_paths, int k, int style) all_paths[k].sg_id.host_no, all_paths[k].sg_id.channel, all_paths[k].sg_id.scsi_id, all_paths[k].sg_id.lun); - printf("%s ", all_paths[k].sg_dev); - printf("op:%i ", all_paths[k].state); + if(0 != strcmp(all_paths[k].sg_dev, all_paths[k].dev)) + printf("%s ", all_paths[k].sg_dev); printf("%s ", all_paths[k].dev); printf("[%.16s]\n", all_paths[k].product_id); } @@ -386,6 +484,32 @@ print_all_mp(struct path * all_paths, struct multipath * mp, int nmp) } } +static long +get_disk_size (struct env * conf, char * dev) { + long size; + int fd; + char attr_path[FILE_NAME_SIZE]; + char buff[FILE_NAME_SIZE]; + char basedev[FILE_NAME_SIZE]; + + if(conf->with_sysfs) { + basename(dev, basedev); + sprintf(attr_path, "%s/block/%s/size", + conf->sysfs_path, basedev); + if (0 > sysfs_read_attribute_value(attr_path, buff, + FILE_NAME_SIZE * sizeof(char))) + return -1; + size = atoi(buff); + return size; + } else { + if ((fd = open(dev, O_RDONLY)) < 0) + return -1; + if(!ioctl(fd, BLKGETSIZE, &size)) + return size; + } + return -1; +} + static int coalesce_paths(struct env * conf, struct multipath * mp, struct path * all_paths) @@ -398,25 +522,31 @@ coalesce_paths(struct env * conf, struct multipath * mp, memset(empty_buff, 0, WWID_SIZE); for (k = 0; k < conf->max_devs - 1; k++) { - /* skip this path if no unique id has been found */ + /* skip this path for some reason */ + + /* 1. if path has no unique id */ if (memcmp(empty_buff, all_paths[k].wwid, WWID_SIZE) == 0) continue; - np = 0; + /* 2. mp with this uid already instanciated */ for (i = 0; i <= nmp; i++) { if (0 == strcmp(mp[i].wwid, all_paths[k].wwid)) already_done = 1; } - if (already_done) { already_done = 0; continue; } + /* at this point, we know we really got a new mp */ + np = 0; nmp++; strcpy(mp[nmp].wwid, all_paths[k].wwid); PINDEX(nmp,np) = k; + if (mp[nmp].size == 0) + mp[nmp].size = get_disk_size(conf, all_paths[k].dev); + for (i = k + 1; i < conf->max_devs; i++) { if (0 == strcmp(all_paths[k].wwid, all_paths[i].wwid)) { np++; @@ -428,39 +558,11 @@ coalesce_paths(struct env * conf, struct multipath * mp, return nmp; } -static long -get_disk_size (struct env * conf, char * dev) { - long size; - int fd; - char attr_path[FILE_NAME_SIZE]; - char buff[FILE_NAME_SIZE]; - char basedev[FILE_NAME_SIZE]; - - if(conf->with_sysfs) { - basename(dev, basedev); - sprintf(attr_path, "%s/block/%s/size", - conf->sysfs_path, basedev); - if (0 > sysfs_read_attribute_value(attr_path, buff, - FILE_NAME_SIZE * sizeof(char))) - return -1; - size = atoi(buff); - return size; - } else { - if ((fd = open(dev, O_RDONLY)) < 0) - return -1; - if(!ioctl(fd, BLKGETSIZE, &size)) - return size; - } - return -1; -} - 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 +588,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); @@ -501,127 +598,122 @@ make_dm_node(char * str) } -/* future use ? static int -del_map(char * str) { +dm_simplecmd(int task, const char *name) { + int r = 0; + struct dm_task *dmt; + + if (!(dmt = dm_task_create(task))) + return 0; + + if (!dm_task_set_name(dmt, name)) + goto out; + + r = dm_task_run(dmt); + + out: + dm_task_destroy(dmt); + return r; +} + +static int +dm_addmap(int task, const char *name, const char *params, long size) { struct dm_task *dmt; - if (!(dmt = dm_task_create(DM_DEVICE_REMOVE))) + if (!(dmt = dm_task_create(task))) return 0; - if (!dm_task_set_name(dmt, str)) - goto delout; - if (!dm_task_run(dmt)) - goto delout; - printf("Deleted device map : %s\n", str); + if (!dm_task_set_name(dmt, name)) + goto addout; - delout: + if (!dm_task_add_target(dmt, 0, size, DM_TARGET, params)) + goto addout; + + if (!dm_task_run(dmt)) + goto addout; + + addout: dm_task_destroy(dmt); return 1; } -*/ static int -add_map(struct env * conf, struct path * all_paths, +setup_map(struct env * conf, struct path * all_paths, struct multipath * mp, int index, int op) { char params[255]; char * params_p; - struct dm_task *dmt; int i, np; - long size = -1; - if (!(dmt = dm_task_create(op))) - return 0; + /* defaults for multipath target */ + int dm_pg_prio = 1; + char * dm_ps_name = "round-robin"; + int dm_ps_nr_args = 0; - if (!dm_task_set_name(dmt, mp[index].wwid)) - goto addout; params_p = ¶ms[0]; np = 0; for (i=0; i<=mp[index].npaths; i++) { - if ((1 == all_paths[PINDEX(index,i)].state) && - (0 == all_paths[PINDEX(index,i)].sg_id.scsi_type)) + if (0 == all_paths[PINDEX(index,i)].sg_id.scsi_type) np++; } - if (np == 0) - goto addout; - params_p += sprintf(params_p, "%i 32", np); - - for (i=0; i<=mp[index].npaths; i++) { - if (( 0 == all_paths[PINDEX(index,i)].state) || - (0 != all_paths[PINDEX(index,i)].sg_id.scsi_type)) - continue; - if (size < 0) - size = get_disk_size(conf, all_paths[PINDEX(index,0)].dev); - params_p += sprintf(params_p, " %s %i", - all_paths[PINDEX(index,i)].dev, 0); + + if (np < 1) + return 0; + + params_p += sprintf(params_p, "%i", conf->dm_path_test_int); + + if (all_paths[PINDEX(index,0)].iopolicy == MULTIBUS && + !conf->forcedfailover ) { + params_p += sprintf(params_p, " %i %s %i %i", + dm_pg_prio, dm_ps_name, np, dm_ps_nr_args); + + for (i=0; i<=mp[index].npaths; i++) { + if (0 != all_paths[PINDEX(index,i)].sg_id.scsi_type) + continue; + params_p += sprintf(params_p, " %s", + all_paths[PINDEX(index,i)].dev); + } } - if (size < 0) - goto addout; + if (all_paths[PINDEX(index,0)].iopolicy == FAILOVER || + conf->forcedfailover) { + for (i=0; i<=mp[index].npaths; i++) { + if (0 != all_paths[PINDEX(index,i)].sg_id.scsi_type) + continue; + params_p += sprintf(params_p, " %i %s ", + dm_pg_prio, dm_ps_name); + params_p += sprintf(params_p, "1 %i", + dm_ps_nr_args); + params_p += sprintf(params_p, " %s", + all_paths[PINDEX(index,i)].dev); + } + } + + if (mp[index].size < 0) + return 0; if (!conf->quiet) { if (op == DM_DEVICE_RELOAD) - printf("U|"); + printf("U:"); if (op == DM_DEVICE_CREATE) - printf("N|"); - printf("%s : 0 %li %s %s\n", - mp[index].wwid, size, DM_TARGET, params); + printf("N:"); + printf("%s:0 %li %s %s\n", + mp[index].wwid, mp[index].size, DM_TARGET, params); } - if (!dm_task_add_target(dmt, 0, size, DM_TARGET, params)) - goto addout; + if (op == DM_DEVICE_RELOAD) + dm_simplecmd(DM_DEVICE_SUSPEND, mp[index].wwid); - if (!dm_task_run(dmt)) - goto addout; + dm_addmap(op, mp[index].wwid, params, mp[index].size); + if (op == DM_DEVICE_RELOAD) + dm_simplecmd(DM_DEVICE_RESUME, mp[index].wwid); make_dm_node(mp[index].wwid); - - addout: - dm_task_destroy(dmt); return 1; } -/* -static int -get_table(const char * str) -{ - int r = 0; - struct dm_task *dmt; - void *next = NULL; - uint64_t start, length; - char *target_type = NULL; - char *params; - - if (!(dmt = dm_task_create(DM_DEVICE_TABLE))) - return 0; - - if (!dm_task_set_name(dmt, str)) - goto out; - - if (!dm_task_run(dmt)) - goto out; - - do { - next = dm_get_next_target(dmt, next, &start, &length, - &target_type, ¶ms); - if (target_type) { - printf("%" PRIu64 " %" PRIu64 " %s %s\n", - start, length, target_type, params); - } - } while (next); - - r = 1; - - out: - dm_task_destroy(dmt); - return r; - -} -*/ - static int map_present(char * str) { @@ -659,11 +751,14 @@ static void usage(char * progname) { fprintf(stderr, VERSION_STRING); - fprintf(stderr, "Usage: %s [-v|-q] [-d] [-m max_devs]\n", progname); - fprintf(stderr, "\t-v\t\tverbose, print all paths and multipaths\n"); - fprintf(stderr, "\t-q\t\tquiet, no output at all\n"); + fprintf(stderr, "Usage: %s [-v|-q] [-d] [-i int] [-m max_devs]\n", + progname); fprintf(stderr, "\t-d\t\tdry run, do not create or update devmaps\n"); + fprintf(stderr, "\t-f\t\tforce maps to failover mode (1 path/pg)\n"); + fprintf(stderr, "\t-i\t\tmultipath target param : polling interval\n"); fprintf(stderr, "\t-m max_devs\tscan {max_devs} devices at most\n"); + fprintf(stderr, "\t-q\t\tquiet, no output at all\n"); + fprintf(stderr, "\t-v\t\tverbose, print all paths and multipaths\n"); exit(1); } @@ -682,6 +777,7 @@ main(int argc, char *argv[]) conf.verbose = 0; /* 1 == Print all_paths and mp */ conf.quiet = 0; /* 1 == Do not even print devmaps */ conf.with_sysfs = 0; /* Default to compat / suboptimal behaviour */ + conf.dm_path_test_int = 10; /* kindly provided by libsysfs */ if (0 == sysfs_get_mnt_path(conf.sysfs_path, FILE_NAME_SIZE)) @@ -702,6 +798,12 @@ main(int argc, char *argv[]) conf.quiet = 1; } else if (0 == strcmp("-d", argv[i])) conf.dry_run = 1; + else if (0 == strcmp("-f", argv[i])) + conf.forcedfailover = 1; + else if (0 == strcmp("-i", argv[i])) + conf.dm_path_test_int = atoi(argv[++i]); + else if (0 == strcmp("scsi", argv[i])) + strcpy(conf.hotplugdev, argv[++i]); else if (*argv[i] == '-') { fprintf(stderr, "Unknown switch: %s\n", argv[i]); usage(argv[0]); @@ -729,9 +831,9 @@ 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) @@ -739,10 +841,16 @@ main(int argc, char *argv[]) for (k=0; k<=nmp; k++) { if (map_present(mp[k].wwid)) { - add_map(&conf, all_paths, mp, k, DM_DEVICE_RELOAD); + setup_map(&conf, all_paths, mp, k, DM_DEVICE_RELOAD); } else { - add_map(&conf, all_paths, mp, k, DM_DEVICE_CREATE); + setup_map(&conf, all_paths, mp, k, DM_DEVICE_CREATE); } } + + /* free allocs */ + free(mp); + free(all_paths); + free(all_scsi_ids); + exit(0); }