2 * Soft: multipath device mapper target autoconfig
4 * Version: $Id: main.h,v 0.0.1 2003/09/18 15:13:38 cvaroqui Exp $
6 * Author: Christophe Varoqui
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.
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.
18 * Copyright (c) 2003, 2004, 2005 Christophe Varoqui
19 * Copyright (c) 2005 Benjamin Marzinski, Redhat
20 * Copyright (c) 2005 Kiyoshi Ueda, NEC
21 * Copyright (c) 2005 Patrick Caulfield, Redhat
22 * Copyright (c) 2005 Edward Goggin, EMC
28 #include <sysfs/libsysfs.h>
33 #include <libdevmapper.h>
34 #include <devmapper.h>
38 #include <structs_vec.h>
41 #include <blacklist.h>
42 #include <discovery.h>
44 #include <switchgroup.h>
47 #include <configure.h>
48 #include <pgpolicies.h>
52 filter_pathvec (vector pathvec, char * refwwid)
57 if (!refwwid || !strlen(refwwid))
60 vector_foreach_slot (pathvec, pp, i) {
61 if (strncmp(pp->wwid, refwwid, WWID_SIZE) != 0) {
62 condlog(3, "skip path %s : out of scope", pp->dev);
64 vector_del_slot(pathvec, i);
72 usage (char * progname)
74 fprintf (stderr, VERSION_STRING);
75 fprintf (stderr, "Usage: %s\t[-v level] [-d] [-h|-l|-ll|-f|-F]\n",
78 "\t\t\t[-p failover|multibus|group_by_serial|group_by_prio]\n" \
81 "\t-v level\tverbosity level\n" \
82 "\t 0\t\t\tno output\n" \
83 "\t 1\t\t\tprint created devmap names only\n" \
84 "\t 2\t\t\tdefault verbosity\n" \
85 "\t 3\t\t\tprint debug information\n" \
86 "\t-h\t\tprint this usage text\n" \
87 "\t-b file\t\tbindings file location\n" \
88 "\t-d\t\tdry run, do not create or update devmaps\n" \
89 "\t-l\t\tshow multipath topology (sysfs and DM info)\n" \
90 "\t-ll\t\tshow multipath topology (maximum info)\n" \
91 "\t-f\t\tflush a multipath device map\n" \
92 "\t-F\t\tflush all multipath device maps\n" \
93 "\t-p policy\tforce all maps to specified policy :\n" \
94 "\t failover\t\t1 path per priority group\n" \
95 "\t multibus\t\tall paths in 1 priority group\n" \
96 "\t group_by_serial\t1 priority group per serial\n" \
97 "\t group_by_prio\t1 priority group per priority lvl\n" \
98 "\t group_by_node_name\t1 priority group per target node\n" \
100 "\tdevice\t\tlimit scope to the device's multipath\n" \
101 "\t\t\t(udev-style $DEVNAME reference, eg /dev/sdb\n" \
102 "\t\t\tor major:minor or a device map name)\n" \
109 update_paths (struct multipath * mpp)
112 struct pathgroup * pgp;
118 vector_foreach_slot (mpp->pg, pgp, i) {
122 vector_foreach_slot (pgp->paths, pp, j) {
123 if (!strlen(pp->dev)) {
124 if (devt2devname(pp->dev, pp->dev_t)) {
126 * path is not in sysfs anymore
128 pp->state = PATH_DOWN;
132 pathinfo(pp, conf->hwtable, DI_ALL);
136 if (pp->state == PATH_UNCHECKED)
137 pathinfo(pp, conf->hwtable, DI_CHECKER);
139 if (pp->priority == PRIO_UNDEF)
140 pathinfo(pp, conf->hwtable, DI_PRIO);
147 get_dm_mpvec (vector curmp, vector pathvec, char * refwwid)
150 struct multipath * mpp;
152 if (dm_get_maps(curmp, DEFAULT_TARGET))
155 vector_foreach_slot (curmp, mpp, i) {
157 * discard out of scope maps
159 if (mpp->wwid && refwwid &&
160 strncmp(mpp->wwid, refwwid, WWID_SIZE)) {
161 condlog(3, "skip map %s: out of scope", mpp->alias);
162 free_multipath(mpp, KEEP_PATHS);
163 vector_del_slot(curmp, i);
168 condlog(3, "params = %s", mpp->params);
169 condlog(3, "status = %s", mpp->status);
171 disassemble_map(pathvec, mpp->params, mpp);
174 * disassemble_map() can add new paths to pathvec.
175 * If not in "fast list mode", we need to fetch information
182 mpp->bestpg = select_path_group(mpp);
184 disassemble_status(mpp->status, mpp);
187 print_multipath_topology(mpp, conf->verbosity);
190 reinstate_paths(mpp);
206 vector pathvec = NULL;
210 char * refwwid = NULL;
214 * allocate core vectors to store paths and multipaths
216 curmp = vector_alloc();
217 pathvec = vector_alloc();
219 if (!curmp || !pathvec) {
220 condlog(0, "can not allocate memory");
223 vecs.pathvec = pathvec;
227 * dev is "/dev/" . "sysfs block dev"
230 if (!strncmp(conf->dev, "/dev/", 5) &&
231 strlen(conf->dev) > 5)
238 * if we have a blacklisted device parameter, exit early
241 (filter_devnode(conf->blist_devnode, conf->elist_devnode, dev) > 0))
245 * scope limiting must be translated into a wwid
246 * failing the translation is fatal (by policy)
249 refwwid = get_refwwid(conf->dev, conf->dev_type, pathvec);
252 condlog(3, "scope is nul");
255 condlog(3, "scope limited to %s", refwwid);
256 if (filter_wwid(conf->blist_wwid, conf->elist_wwid,
268 /* extended path info '-ll' */
269 di_flag |= DI_SYSFS | DI_CHECKER;
271 /* minimum path info '-l' */
277 if (path_discovery(pathvec, conf, di_flag))
280 if (conf->verbosity > 2)
281 print_all_paths(pathvec, 1);
283 get_path_layout(pathvec);
285 if (get_dm_mpvec(curmp, pathvec, refwwid))
288 filter_pathvec(pathvec, refwwid);
296 * core logic entry point
298 r = coalesce_paths(&vecs, NULL, NULL);
304 free_multipathvec(curmp, KEEP_PATHS);
305 free_pathvec(pathvec, FREE_PATHS);
311 main (int argc, char *argv[])
319 fprintf(stderr, "need to be root\n");
323 if (dm_prereq(DEFAULT_TARGET))
326 if (sysfs_get_mnt_path(sysfs_path, FILE_NAME_SIZE)) {
327 condlog(0, "multipath tools need sysfs mounted");
330 if (load_config(DEFAULT_CONFIGFILE))
333 while ((arg = getopt(argc, argv, ":dhl::FfM:v:p:b:")) != EOF ) {
335 case 1: printf("optarg : %s\n",optarg);
338 if (sizeof(optarg) > sizeof(char *) ||
342 conf->verbosity = atoi(optarg);
345 conf->bindings_file = optarg;
351 conf->remove = FLUSH_ONE;
354 conf->remove = FLUSH_ALL;
360 if (optarg && !strncmp(optarg, "l", 1))
366 debug = atoi(optarg);
370 conf->pgpolicy_flag = get_pgpolicy_id(optarg);
371 if (conf->pgpolicy_flag == -1) {
372 printf("'%s' is not a valid policy\n", optarg);
379 fprintf(stderr, "Missing option arguement\n");
382 fprintf(stderr, "Unknown switch: %s\n", optarg);
389 conf->dev = MALLOC(FILE_NAME_SIZE);
394 strncpy(conf->dev, argv[optind], FILE_NAME_SIZE);
396 if (filepresent(conf->dev))
397 conf->dev_type = DEV_DEVNODE;
398 else if (sscanf(conf->dev, "%d:%d", &i, &i) == 2)
399 conf->dev_type = DEV_DEVT;
401 conf->dev_type = DEV_DEVMAP;
406 if (conf->remove == FLUSH_ONE) {
407 if (conf->dev_type == DEV_DEVMAP)
408 dm_flush_map(conf->dev, DEFAULT_TARGET);
410 condlog(0, "must provide a map name to remove");
414 else if (conf->remove == FLUSH_ALL) {
415 dm_flush_maps(DEFAULT_TARGET);
418 while ((r = configure()) < 0)
419 condlog(3, "restart multipath configuration process");
426 dbg_free_final(NULL);