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>
32 #include <libdevmapper.h>
33 #include <devmapper.h>
34 #include <path_state.h>
35 #include <blacklist.h>
39 #include <structs_vec.h>
42 #include <discovery.h>
44 #include <switchgroup.h>
47 #include <configure.h>
48 #include <pgpolicies.h>
53 filter_pathvec (vector pathvec, char * refwwid)
58 if (!refwwid || !strlen(refwwid))
61 vector_foreach_slot (pathvec, pp, i) {
62 if (strncmp(pp->wwid, refwwid, WWID_SIZE) != 0) {
63 condlog(3, "skip path %s : out of scope", pp->dev);
65 vector_del_slot(pathvec, i);
73 usage (char * progname)
75 fprintf (stderr, VERSION_STRING);
76 fprintf (stderr, "Usage: %s\t[-v level] [-d] [-l|-ll|-f|-F]\n",
79 "\t\t\t[-p failover|multibus|group_by_serial|group_by_prio]\n" \
82 "\t-v level\tverbosity level\n" \
83 "\t 0\t\t\tno output\n" \
84 "\t 1\t\t\tprint created devmap names only\n" \
85 "\t 2\t\t\tdefault verbosity\n" \
86 "\t 3\t\t\tprint debug information\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;
131 pathinfo(pp, conf->hwtable, DI_ALL);
134 if (pp->state == PATH_UNCHECKED)
135 pathinfo(pp, conf->hwtable, DI_CHECKER);
138 pathinfo(pp, conf->hwtable, DI_PRIO);
145 get_dm_mpvec (vector curmp, vector pathvec, char * refwwid)
148 struct multipath * mpp;
150 if (dm_get_maps(curmp, DEFAULT_TARGET))
153 vector_foreach_slot (curmp, mpp, i) {
155 * discard out of scope maps
157 if (mpp->wwid && refwwid &&
158 strncmp(mpp->wwid, refwwid, WWID_SIZE)) {
159 condlog(3, "skip map %s: out of scope", mpp->alias);
160 free_multipath(mpp, KEEP_PATHS);
161 vector_del_slot(curmp, i);
166 condlog(3, "params = %s", mpp->params);
167 condlog(3, "status = %s", mpp->status);
169 disassemble_map(pathvec, mpp->params, mpp);
172 * disassemble_map() can add new paths to pathvec.
173 * If not in "fast list mode", we need to fetch information
180 mpp->bestpg = select_path_group(mpp);
182 disassemble_status(mpp->status, mpp);
185 print_mp(mpp, conf->verbosity);
188 reinstate_paths(mpp);
204 vector pathvec = NULL;
208 char * refwwid = NULL;
212 * allocate core vectors to store paths and multipaths
214 curmp = vector_alloc();
215 pathvec = vector_alloc();
217 if (!curmp || !pathvec) {
218 condlog(0, "can not allocate memory");
221 vecs.pathvec = pathvec;
225 * if we have a blacklisted device parameter, exit early
228 if (!strncmp(conf->dev, "/dev/", 5) &&
229 strlen(conf->dev) > 5)
235 if (dev && blacklist(conf->blist, dev))
239 * scope limiting must be translated into a wwid
240 * failing the translation is fatal (by policy)
243 refwwid = get_refwwid(conf->dev, conf->dev_type, pathvec);
246 condlog(3, "scope is nul");
249 condlog(3, "scope limited to %s", refwwid);
259 /* extended path info '-ll' */
260 di_flag |= DI_SYSFS | DI_CHECKER;
262 /* minimum path info '-l' */
268 if (path_discovery(pathvec, conf, di_flag))
271 if (conf->verbosity > 2)
272 print_all_paths(pathvec, 1);
274 get_path_layout(pathvec);
276 if (get_dm_mpvec(curmp, pathvec, refwwid))
279 filter_pathvec(pathvec, refwwid);
285 * core logic entry point
287 r = coalesce_paths(&vecs, NULL, NULL);
293 free_multipathvec(curmp, KEEP_PATHS);
294 free_pathvec(pathvec, FREE_PATHS);
300 main (int argc, char *argv[])
308 fprintf(stderr, "need to be root\n");
312 if (dm_prereq(DEFAULT_TARGET, 1, 0, 3))
315 if (sysfs_get_mnt_path(sysfs_path, FILE_NAME_SIZE)) {
316 condlog(0, "multipath tools need sysfs mounted");
319 if (load_config(DEFAULT_CONFIGFILE))
322 while ((arg = getopt(argc, argv, ":qdl::Ffi:M:v:p:b:")) != EOF ) {
324 case 1: printf("optarg : %s\n",optarg);
327 if (sizeof(optarg) > sizeof(char *) ||
331 conf->verbosity = atoi(optarg);
334 conf->bindings_file = optarg;
340 conf->remove = FLUSH_ONE;
343 conf->remove = FLUSH_ALL;
349 if (optarg && !strncmp(optarg, "l", 1))
355 debug = atoi(optarg);
359 conf->pgpolicy_flag = get_pgpolicy_id(optarg);
360 if (conf->pgpolicy_flag == -1) {
361 printf("'%s' is not a valid policy\n", optarg);
366 fprintf(stderr, "Missing option arguement\n");
369 fprintf(stderr, "Unknown switch: %s\n", optarg);
376 conf->dev = MALLOC(FILE_NAME_SIZE);
381 strncpy(conf->dev, argv[optind], FILE_NAME_SIZE);
383 if (filepresent(conf->dev))
384 conf->dev_type = DEV_DEVNODE;
385 else if (sscanf(conf->dev, "%d:%d", &i, &i) == 2)
386 conf->dev_type = DEV_DEVT;
388 conf->dev_type = DEV_DEVMAP;
392 if (conf->remove == FLUSH_ONE) {
393 if (conf->dev_type == DEV_DEVMAP)
394 dm_flush_map(conf->dev, DEFAULT_TARGET);
396 condlog(0, "must provide a map name to remove");
400 else if (conf->remove == FLUSH_ALL) {
401 dm_flush_maps(DEFAULT_TARGET);
404 while ((r = configure()) < 0)
405 condlog(3, "restart multipath configuration process");
412 dbg_free_final(NULL);