libmultipath: trigger change uevent on new device creation
[multipath-tools/.git] / libmultipath / configure.c
1 /*
2  * Copyright (c) 2003, 2004, 2005 Christophe Varoqui
3  * Copyright (c) 2005 Benjamin Marzinski, Redhat
4  * Copyright (c) 2005 Kiyoshi Ueda, NEC
5  * Copyright (c) 2005 Patrick Caulfield, Redhat
6  * Copyright (c) 2005 Edward Goggin, EMC
7  */
8
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include <unistd.h>
12 #include <string.h>
13 #include <sys/file.h>
14 #include <errno.h>
15 #include <libdevmapper.h>
16 #include <libudev.h>
17 #include "mpath_cmd.h"
18
19 #include "checkers.h"
20 #include "vector.h"
21 #include "memory.h"
22 #include "devmapper.h"
23 #include "defaults.h"
24 #include "structs.h"
25 #include "structs_vec.h"
26 #include "dmparser.h"
27 #include "config.h"
28 #include "blacklist.h"
29 #include "propsel.h"
30 #include "discovery.h"
31 #include "debug.h"
32 #include "switchgroup.h"
33 #include "dm-generic.h"
34 #include "print.h"
35 #include "configure.h"
36 #include "pgpolicies.h"
37 #include "dict.h"
38 #include "alias.h"
39 #include "prio.h"
40 #include "util.h"
41 #include "uxsock.h"
42 #include "wwids.h"
43 #include "sysfs.h"
44 #include "io_err_stat.h"
45
46 /* group paths in pg by host adapter
47  */
48 int group_by_host_adapter(struct pathgroup *pgp, vector adapters)
49 {
50         struct adapter_group *agp;
51         struct host_group *hgp;
52         struct path *pp, *pp1;
53         char adapter_name1[SLOT_NAME_SIZE];
54         char adapter_name2[SLOT_NAME_SIZE];
55         int i, j;
56         int found_hostgroup = 0;
57
58         while (VECTOR_SIZE(pgp->paths) > 0) {
59
60                 pp = VECTOR_SLOT(pgp->paths, 0);
61
62                 if (sysfs_get_host_adapter_name(pp, adapter_name1))
63                         goto out;
64                 /* create a new host adapter group
65                  */
66                 agp = alloc_adaptergroup();
67                 if (!agp)
68                         goto out;
69                 agp->pgp = pgp;
70
71                 strncpy(agp->adapter_name, adapter_name1, SLOT_NAME_SIZE - 1);
72                 store_adaptergroup(adapters, agp);
73
74                 /* create a new host port group
75                  */
76                 hgp = alloc_hostgroup();
77                 if (!hgp)
78                         goto out;
79                 if (store_hostgroup(agp->host_groups, hgp))
80                         goto out;
81
82                 hgp->host_no = pp->sg_id.host_no;
83                 agp->num_hosts++;
84                 if (store_path(hgp->paths, pp))
85                         goto out;
86
87                 hgp->num_paths++;
88                 /* delete path from path group
89                  */
90                 vector_del_slot(pgp->paths, 0);
91
92                 /* add all paths belonging to same host adapter
93                  */
94                 vector_foreach_slot(pgp->paths, pp1, i) {
95                         if (sysfs_get_host_adapter_name(pp1, adapter_name2))
96                                 goto out;
97                         if (strcmp(adapter_name1, adapter_name2) == 0) {
98                                 found_hostgroup = 0;
99                                 vector_foreach_slot(agp->host_groups, hgp, j) {
100                                         if (hgp->host_no == pp1->sg_id.host_no) {
101                                                 if (store_path(hgp->paths, pp1))
102                                                         goto out;
103                                                 hgp->num_paths++;
104                                                 found_hostgroup = 1;
105                                                 break;
106                                         }
107                                 }
108                                 if (!found_hostgroup) {
109                                         /* this path belongs to new host port
110                                          * within this adapter
111                                          */
112                                         hgp = alloc_hostgroup();
113                                         if (!hgp)
114                                                 goto out;
115
116                                         if (store_hostgroup(agp->host_groups, hgp))
117                                                 goto out;
118
119                                         agp->num_hosts++;
120                                         if (store_path(hgp->paths, pp1))
121                                                 goto out;
122
123                                         hgp->host_no = pp1->sg_id.host_no;
124                                         hgp->num_paths++;
125                                 }
126                                 /* delete paths from original path_group
127                                  * as they are added into adapter group now
128                                  */
129                                 vector_del_slot(pgp->paths, i);
130                                 i--;
131                         }
132                 }
133         }
134         return 0;
135
136 out:    /* add back paths into pg as re-ordering failed
137          */
138         vector_foreach_slot(adapters, agp, i) {
139                         vector_foreach_slot(agp->host_groups, hgp, j) {
140                                 while (VECTOR_SIZE(hgp->paths) > 0) {
141                                         pp = VECTOR_SLOT(hgp->paths, 0);
142                                         if (store_path(pgp->paths, pp))
143                                                 condlog(3, "failed to restore "
144                                                 "path %s into path group",
145                                                  pp->dev);
146                                         vector_del_slot(hgp->paths, 0);
147                                 }
148                         }
149                 }
150         free_adaptergroup(adapters);
151         return 1;
152 }
153
154 /* re-order paths in pg by alternating adapters and host ports
155  * for optimized selection
156  */
157 int order_paths_in_pg_by_alt_adapters(struct pathgroup *pgp, vector adapters,
158                  int total_paths)
159 {
160         int next_adapter_index = 0;
161         struct adapter_group *agp;
162         struct host_group *hgp;
163         struct path *pp;
164
165         while (total_paths > 0) {
166                 agp = VECTOR_SLOT(adapters, next_adapter_index);
167                 if (!agp) {
168                         condlog(0, "can't get adapter group %d", next_adapter_index);
169                         return 1;
170                 }
171
172                 hgp = VECTOR_SLOT(agp->host_groups, agp->next_host_index);
173                 if (!hgp) {
174                         condlog(0, "can't get host group %d of adapter group %d", next_adapter_index, agp->next_host_index);
175                         return 1;
176                 }
177
178                 if (!hgp->num_paths) {
179                         agp->next_host_index++;
180                         agp->next_host_index %= agp->num_hosts;
181                         next_adapter_index++;
182                         next_adapter_index %= VECTOR_SIZE(adapters);
183                         continue;
184                 }
185
186                 pp  = VECTOR_SLOT(hgp->paths, 0);
187
188                 if (store_path(pgp->paths, pp))
189                         return 1;
190
191                 total_paths--;
192
193                 vector_del_slot(hgp->paths, 0);
194
195                 hgp->num_paths--;
196
197                 agp->next_host_index++;
198                 agp->next_host_index %= agp->num_hosts;
199                 next_adapter_index++;
200                 next_adapter_index %= VECTOR_SIZE(adapters);
201         }
202
203         /* all paths are added into path_group
204          * in crafted child order
205          */
206         return 0;
207 }
208
209 /* round-robin: order paths in path group to alternate
210  * between all host adapters
211  */
212 int rr_optimize_path_order(struct pathgroup *pgp)
213 {
214         vector adapters;
215         struct path *pp;
216         int total_paths;
217         int i;
218
219         total_paths = VECTOR_SIZE(pgp->paths);
220         vector_foreach_slot(pgp->paths, pp, i) {
221                 if (pp->sg_id.proto_id != SCSI_PROTOCOL_FCP &&
222                         pp->sg_id.proto_id != SCSI_PROTOCOL_SAS &&
223                         pp->sg_id.proto_id != SCSI_PROTOCOL_ISCSI &&
224                         pp->sg_id.proto_id != SCSI_PROTOCOL_SRP) {
225                         /* return success as default path order
226                          * is maintained in path group
227                          */
228                         return 0;
229                 }
230         }
231         adapters = vector_alloc();
232         if (!adapters)
233                 return 0;
234
235         /* group paths in path group by host adapters
236          */
237         if (group_by_host_adapter(pgp, adapters)) {
238                 /* already freed adapters */
239                 condlog(3, "Failed to group paths by adapters");
240                 return 0;
241         }
242
243         /* re-order paths in pg to alternate between adapters and host ports
244          */
245         if (order_paths_in_pg_by_alt_adapters(pgp, adapters, total_paths)) {
246                 condlog(3, "Failed to re-order paths in pg by adapters "
247                         "and host ports");
248                 free_adaptergroup(adapters);
249                 /* return failure as original paths are
250                  * removed form pgp
251                  */
252                 return 1;
253         }
254
255         free_adaptergroup(adapters);
256         return 0;
257 }
258
259 int setup_map(struct multipath *mpp, char *params, int params_size,
260               struct vectors *vecs)
261 {
262         struct pathgroup * pgp;
263         struct config *conf;
264         int i;
265
266         /*
267          * don't bother if devmap size is unknown
268          */
269         if (mpp->size <= 0) {
270                 condlog(3, "%s: devmap size is unknown", mpp->alias);
271                 return 1;
272         }
273
274         /*
275          * free features, selector, and hwhandler properties if they are being reused
276          */
277         free_multipath_attributes(mpp);
278         if (mpp->disable_queueing && VECTOR_SIZE(mpp->paths) != 0)
279                 mpp->disable_queueing = 0;
280
281         /*
282          * properties selectors
283          *
284          * Ordering matters for some properties:
285          * - features after no_path_retry and retain_hwhandler
286          * - hwhandler after retain_hwhandler
287          * No guarantee that this list is complete, check code in
288          * propsel.c if in doubt.
289          */
290         conf = get_multipath_config();
291         pthread_cleanup_push(put_multipath_config, conf);
292
293         select_pgfailback(conf, mpp);
294         select_pgpolicy(conf, mpp);
295         select_selector(conf, mpp);
296         select_no_path_retry(conf, mpp);
297         select_retain_hwhandler(conf, mpp);
298         select_features(conf, mpp);
299         select_hwhandler(conf, mpp);
300         select_rr_weight(conf, mpp);
301         select_minio(conf, mpp);
302         select_mode(conf, mpp);
303         select_uid(conf, mpp);
304         select_gid(conf, mpp);
305         select_fast_io_fail(conf, mpp);
306         select_dev_loss(conf, mpp);
307         select_reservation_key(conf, mpp);
308         select_deferred_remove(conf, mpp);
309         select_delay_watch_checks(conf, mpp);
310         select_delay_wait_checks(conf, mpp);
311         select_marginal_path_err_sample_time(conf, mpp);
312         select_marginal_path_err_rate_threshold(conf, mpp);
313         select_marginal_path_err_recheck_gap_time(conf, mpp);
314         select_marginal_path_double_failed_time(conf, mpp);
315         select_skip_kpartx(conf, mpp);
316         select_max_sectors_kb(conf, mpp);
317         select_ghost_delay(conf, mpp);
318         select_flush_on_last_del(conf, mpp);
319
320         sysfs_set_scsi_tmo(mpp, conf->checkint);
321         pthread_cleanup_pop(1);
322
323         if (mpp->marginal_path_double_failed_time > 0 &&
324             mpp->marginal_path_err_sample_time > 0 &&
325             mpp->marginal_path_err_recheck_gap_time > 0 &&
326             mpp->marginal_path_err_rate_threshold >= 0)
327                 start_io_err_stat_thread(vecs);
328         /*
329          * assign paths to path groups -- start with no groups and all paths
330          * in mpp->paths
331          */
332         if (mpp->pg) {
333                 vector_foreach_slot (mpp->pg, pgp, i)
334                         free_pathgroup(pgp, KEEP_PATHS);
335
336                 vector_free(mpp->pg);
337                 mpp->pg = NULL;
338         }
339         if (mpp->pgpolicyfn && mpp->pgpolicyfn(mpp))
340                 return 1;
341
342         mpp->nr_active = pathcount(mpp, PATH_UP) + pathcount(mpp, PATH_GHOST);
343
344         /*
345          * ponders each path group and determine highest prio pg
346          * to switch over (default to first)
347          */
348         mpp->bestpg = select_path_group(mpp);
349
350         /* re-order paths in all path groups in an optimized way
351          * for round-robin path selectors to get maximum throughput.
352          */
353         if (!strncmp(mpp->selector, "round-robin", 11)) {
354                 vector_foreach_slot(mpp->pg, pgp, i) {
355                         if (VECTOR_SIZE(pgp->paths) <= 2)
356                                 continue;
357                         if (rr_optimize_path_order(pgp)) {
358                                 condlog(2, "cannot re-order paths for "
359                                         "optimization: %s",
360                                         mpp->alias);
361                                 return 1;
362                         }
363                 }
364         }
365
366         /*
367          * transform the mp->pg vector of vectors of paths
368          * into a mp->params strings to feed the device-mapper
369          */
370         if (assemble_map(mpp, params, params_size)) {
371                 condlog(0, "%s: problem assembing map", mpp->alias);
372                 return 1;
373         }
374         return 0;
375 }
376
377 static void
378 compute_pgid(struct pathgroup * pgp)
379 {
380         struct path * pp;
381         int i;
382
383         vector_foreach_slot (pgp->paths, pp, i)
384                 pgp->id ^= (long)pp;
385 }
386
387 static int
388 pgcmp (struct multipath * mpp, struct multipath * cmpp)
389 {
390         int i, j;
391         struct pathgroup * pgp;
392         struct pathgroup * cpgp;
393         int r = 0;
394
395         if (!mpp)
396                 return 0;
397
398         vector_foreach_slot (mpp->pg, pgp, i) {
399                 compute_pgid(pgp);
400
401                 vector_foreach_slot (cmpp->pg, cpgp, j) {
402                         if (pgp->id == cpgp->id &&
403                             !pathcmp(pgp, cpgp)) {
404                                 r = 0;
405                                 break;
406                         }
407                         r++;
408                 }
409                 if (r)
410                         return r;
411         }
412         return r;
413 }
414
415 static struct udev_device *
416 get_udev_for_mpp(const struct multipath *mpp)
417 {
418         dev_t devnum;
419         struct udev_device *udd;
420
421         if (!mpp || !mpp->dmi) {
422                 condlog(1, "%s called with empty mpp", __func__);
423                 return NULL;
424         }
425
426         devnum = makedev(mpp->dmi->major, mpp->dmi->minor);
427         udd = udev_device_new_from_devnum(udev, 'b', devnum);
428         if (!udd) {
429                 condlog(1, "failed to get udev device for %s", mpp->alias);
430                 return NULL;
431         }
432         return udd;
433 }
434
435 static void
436 trigger_udev_change(const struct multipath *mpp)
437 {
438         static const char change[] = "change";
439         struct udev_device *udd = get_udev_for_mpp(mpp);
440         if (!udd)
441                 return;
442         condlog(3, "triggering %s uevent for %s", change, mpp->alias);
443         sysfs_attr_set_value(udd, "uevent", change, sizeof(change)-1);
444         udev_device_unref(udd);
445 }
446
447 void
448 trigger_paths_udev_change(const struct multipath *mpp)
449 {
450         struct pathgroup *pgp;
451         struct path *pp;
452         int i, j;
453
454         if (!mpp || !mpp->pg)
455                 return;
456
457         vector_foreach_slot (mpp->pg, pgp, i) {
458                 if (!pgp->paths)
459                         continue;
460                 vector_foreach_slot(pgp->paths, pp, j) {
461                         if (!pp->udev)
462                                 continue;
463                         sysfs_attr_set_value(pp->udev, "uevent", "change",
464                                              strlen("change"));
465                 }
466         }
467 }
468
469 static int
470 is_mpp_known_to_udev(const struct multipath *mpp)
471 {
472         struct udev_device *udd = get_udev_for_mpp(mpp);
473         int ret = (udd != NULL);
474         udev_device_unref(udd);
475         return ret;
476 }
477
478 static int
479 sysfs_set_max_sectors_kb(struct multipath *mpp, int is_reload)
480 {
481         struct pathgroup * pgp;
482         struct path *pp;
483         char buff[11];
484         int i, j, ret, err = 0;
485         struct udev_device *udd;
486         int max_sectors_kb;
487
488         if (mpp->max_sectors_kb == MAX_SECTORS_KB_UNDEF)
489                 return 0;
490         max_sectors_kb = mpp->max_sectors_kb;
491         if (is_reload) {
492                 if (!mpp->dmi && dm_get_info(mpp->alias, &mpp->dmi) != 0) {
493                         condlog(1, "failed to get dm info for %s", mpp->alias);
494                         return 1;
495                 }
496                 udd = get_udev_for_mpp(mpp);
497                 if (!udd) {
498                         condlog(1, "failed to get udev device to set max_sectors_kb for %s", mpp->alias);
499                         return 1;
500                 }
501                 ret = sysfs_attr_get_value(udd, "queue/max_sectors_kb", buff,
502                                            sizeof(buff));
503                 udev_device_unref(udd);
504                 if (ret <= 0) {
505                         condlog(1, "failed to get current max_sectors_kb from %s", mpp->alias);
506                         return 1;
507                 }
508                 if (sscanf(buff, "%u\n", &max_sectors_kb) != 1) {
509                         condlog(1, "can't parse current max_sectors_kb from %s",
510                                 mpp->alias);
511                         return 1;
512                 }
513         }
514         snprintf(buff, 11, "%d", max_sectors_kb);
515
516         vector_foreach_slot (mpp->pg, pgp, i) {
517                 vector_foreach_slot(pgp->paths, pp, j) {
518                         ret = sysfs_attr_set_value(pp->udev,
519                                                    "queue/max_sectors_kb",
520                                                    buff, strlen(buff));
521                         if (ret < 0) {
522                                 condlog(1, "failed setting max_sectors_kb on %s : %s", pp->dev, strerror(-ret));
523                                 err = 1;
524                         }
525                 }
526         }
527         return err;
528 }
529
530 static void
531 select_action (struct multipath * mpp, vector curmp, int force_reload)
532 {
533         struct multipath * cmpp;
534         struct multipath * cmpp_by_name;
535         char * mpp_feat, * cmpp_feat;
536
537         cmpp = find_mp_by_wwid(curmp, mpp->wwid);
538         cmpp_by_name = find_mp_by_alias(curmp, mpp->alias);
539
540         if (!cmpp_by_name) {
541                 if (cmpp) {
542                         condlog(2, "%s: rename %s to %s", mpp->wwid,
543                                 cmpp->alias, mpp->alias);
544                         strncpy(mpp->alias_old, cmpp->alias, WWID_SIZE - 1);
545                         mpp->action = ACT_RENAME;
546                         if (force_reload) {
547                                 mpp->force_udev_reload = 1;
548                                 mpp->action = ACT_FORCERENAME;
549                         }
550                         return;
551                 }
552                 mpp->action = ACT_CREATE;
553                 condlog(3, "%s: set ACT_CREATE (map does not exist)",
554                         mpp->alias);
555                 return;
556         }
557
558         if (!cmpp) {
559                 condlog(2, "%s: remove (wwid changed)", mpp->alias);
560                 dm_flush_map(mpp->alias);
561                 strncpy(cmpp_by_name->wwid, mpp->wwid, WWID_SIZE - 1);
562                 drop_multipath(curmp, cmpp_by_name->wwid, KEEP_PATHS);
563                 mpp->action = ACT_CREATE;
564                 condlog(3, "%s: set ACT_CREATE (map wwid change)",
565                         mpp->alias);
566                 return;
567         }
568
569         if (cmpp != cmpp_by_name) {
570                 condlog(2, "%s: unable to rename %s to %s (%s is used by %s)",
571                         mpp->wwid, cmpp->alias, mpp->alias,
572                         mpp->alias, cmpp_by_name->wwid);
573                 /* reset alias to existing alias */
574                 FREE(mpp->alias);
575                 mpp->alias = STRDUP(cmpp->alias);
576                 mpp->action = ACT_IMPOSSIBLE;
577                 return;
578         }
579
580         if (pathcount(mpp, PATH_UP) == 0) {
581                 mpp->action = ACT_IMPOSSIBLE;
582                 condlog(3, "%s: set ACT_IMPOSSIBLE (no usable path)",
583                         mpp->alias);
584                 return;
585         }
586         if (force_reload) {
587                 mpp->force_udev_reload = 1;
588                 mpp->action = ACT_RELOAD;
589                 condlog(3, "%s: set ACT_RELOAD (forced by user)",
590                         mpp->alias);
591                 return;
592         }
593         if (cmpp->size != mpp->size) {
594                 mpp->force_udev_reload = 1;
595                 mpp->action = ACT_RESIZE;
596                 condlog(3, "%s: set ACT_RESIZE (size change)",
597                         mpp->alias);
598                 return;
599         }
600
601         if (mpp->no_path_retry != NO_PATH_RETRY_UNDEF &&
602             !!strstr(mpp->features, "queue_if_no_path") !=
603             !!strstr(cmpp->features, "queue_if_no_path")) {
604                 mpp->action =  ACT_RELOAD;
605                 condlog(3, "%s: set ACT_RELOAD (no_path_retry change)",
606                         mpp->alias);
607                 return;
608         }
609         if ((mpp->retain_hwhandler != RETAIN_HWHANDLER_ON ||
610              strcmp(cmpp->hwhandler, "0") == 0) &&
611             (strlen(cmpp->hwhandler) != strlen(mpp->hwhandler) ||
612              strncmp(cmpp->hwhandler, mpp->hwhandler,
613                     strlen(mpp->hwhandler)))) {
614                 mpp->action = ACT_RELOAD;
615                 condlog(3, "%s: set ACT_RELOAD (hwhandler change)",
616                         mpp->alias);
617                 return;
618         }
619
620         if (mpp->retain_hwhandler != RETAIN_HWHANDLER_UNDEF &&
621             !!strstr(mpp->features, "retain_attached_hw_handler") !=
622             !!strstr(cmpp->features, "retain_attached_hw_handler") &&
623             get_linux_version_code() < KERNEL_VERSION(4, 3, 0)) {
624                 mpp->action = ACT_RELOAD;
625                 condlog(3, "%s: set ACT_RELOAD (retain_hwhandler change)",
626                         mpp->alias);
627                 return;
628         }
629
630         cmpp_feat = STRDUP(cmpp->features);
631         mpp_feat = STRDUP(mpp->features);
632         if (cmpp_feat && mpp_feat) {
633                 remove_feature(&mpp_feat, "queue_if_no_path");
634                 remove_feature(&mpp_feat, "retain_attached_hw_handler");
635                 remove_feature(&cmpp_feat, "queue_if_no_path");
636                 remove_feature(&cmpp_feat, "retain_attached_hw_handler");
637                 if (strncmp(mpp_feat, cmpp_feat, PARAMS_SIZE)) {
638                         mpp->action =  ACT_RELOAD;
639                         condlog(3, "%s: set ACT_RELOAD (features change)",
640                                 mpp->alias);
641                 }
642         }
643         FREE(cmpp_feat);
644         FREE(mpp_feat);
645
646         if (!cmpp->selector || strncmp(cmpp->selector, mpp->selector,
647                     strlen(mpp->selector))) {
648                 mpp->action = ACT_RELOAD;
649                 condlog(3, "%s: set ACT_RELOAD (selector change)",
650                         mpp->alias);
651                 return;
652         }
653         if (cmpp->minio != mpp->minio) {
654                 mpp->action = ACT_RELOAD;
655                 condlog(3, "%s: set ACT_RELOAD (minio change, %u->%u)",
656                         mpp->alias, cmpp->minio, mpp->minio);
657                 return;
658         }
659         if (!cmpp->pg || VECTOR_SIZE(cmpp->pg) != VECTOR_SIZE(mpp->pg)) {
660                 mpp->action = ACT_RELOAD;
661                 condlog(3, "%s: set ACT_RELOAD (path group number change)",
662                         mpp->alias);
663                 return;
664         }
665         if (pgcmp(mpp, cmpp)) {
666                 mpp->action = ACT_RELOAD;
667                 condlog(3, "%s: set ACT_RELOAD (path group topology change)",
668                         mpp->alias);
669                 return;
670         }
671         if (cmpp->nextpg != mpp->bestpg) {
672                 mpp->action = ACT_SWITCHPG;
673                 condlog(3, "%s: set ACT_SWITCHPG (next path group change)",
674                         mpp->alias);
675                 return;
676         }
677         if (!is_mpp_known_to_udev(cmpp)) {
678                 mpp->action = ACT_RELOAD;
679                 condlog(3, "%s: set ACT_RELOAD (udev device not initialized)",
680                         mpp->alias);
681                 return;
682         }
683         mpp->action = ACT_NOTHING;
684         condlog(3, "%s: set ACT_NOTHING (map unchanged)",
685                 mpp->alias);
686         return;
687 }
688
689 int reinstate_paths(struct multipath *mpp)
690 {
691         int i, j;
692         struct pathgroup * pgp;
693         struct path * pp;
694
695         if (!mpp->pg)
696                 return 0;
697
698         vector_foreach_slot (mpp->pg, pgp, i) {
699                 if (!pgp->paths)
700                         continue;
701
702                 vector_foreach_slot (pgp->paths, pp, j) {
703                         if (pp->state != PATH_UP &&
704                             (pgp->status == PGSTATE_DISABLED ||
705                              pgp->status == PGSTATE_ACTIVE))
706                                 continue;
707
708                         if (pp->dmstate == PSTATE_FAILED) {
709                                 if (dm_reinstate_path(mpp->alias, pp->dev_t))
710                                         condlog(0, "%s: error reinstating",
711                                                 pp->dev);
712                         }
713                 }
714         }
715         return 0;
716 }
717
718 static int
719 lock_multipath (struct multipath * mpp, int lock)
720 {
721         struct pathgroup * pgp;
722         struct path * pp;
723         int i, j;
724         int x, y;
725
726         if (!mpp || !mpp->pg)
727                 return 0;
728
729         vector_foreach_slot (mpp->pg, pgp, i) {
730                 if (!pgp->paths)
731                         continue;
732                 vector_foreach_slot(pgp->paths, pp, j) {
733                         if (lock && flock(pp->fd, LOCK_SH | LOCK_NB) &&
734                             errno == EWOULDBLOCK)
735                                 goto fail;
736                         else if (!lock)
737                                 flock(pp->fd, LOCK_UN);
738                 }
739         }
740         return 0;
741 fail:
742         vector_foreach_slot (mpp->pg, pgp, x) {
743                 if (x > i)
744                         return 1;
745                 if (!pgp->paths)
746                         continue;
747                 vector_foreach_slot(pgp->paths, pp, y) {
748                         if (x == i && y >= j)
749                                 return 1;
750                         flock(pp->fd, LOCK_UN);
751                 }
752         }
753         return 1;
754 }
755
756 /*
757  * Return value:
758  */
759 #define DOMAP_RETRY     -1
760 #define DOMAP_FAIL      0
761 #define DOMAP_OK        1
762 #define DOMAP_EXIST     2
763 #define DOMAP_DRY       3
764
765 int domap(struct multipath *mpp, char *params, int is_daemon)
766 {
767         int r = DOMAP_FAIL;
768         struct config *conf;
769         int verbosity;
770
771         /*
772          * last chance to quit before touching the devmaps
773          */
774         if (mpp->action == ACT_DRY_RUN) {
775                 conf = get_multipath_config();
776                 verbosity = conf->verbosity;
777                 put_multipath_config(conf);
778                 print_multipath_topology(mpp, verbosity);
779                 return DOMAP_DRY;
780         }
781
782         if (mpp->action == ACT_CREATE &&
783             dm_map_present(mpp->alias)) {
784                 condlog(3, "%s: map already present", mpp->alias);
785                 mpp->action = ACT_RELOAD;
786         }
787
788         switch (mpp->action) {
789         case ACT_REJECT:
790         case ACT_NOTHING:
791         case ACT_IMPOSSIBLE:
792                 return DOMAP_EXIST;
793
794         case ACT_SWITCHPG:
795                 dm_switchgroup(mpp->alias, mpp->bestpg);
796                 /*
797                  * we may have avoided reinstating paths because there where in
798                  * active or disabled PG. Now that the topology has changed,
799                  * retry.
800                  */
801                 reinstate_paths(mpp);
802                 return DOMAP_EXIST;
803
804         case ACT_CREATE:
805                 if (lock_multipath(mpp, 1)) {
806                         condlog(3, "%s: failed to create map (in use)",
807                                 mpp->alias);
808                         return DOMAP_RETRY;
809                 }
810
811                 sysfs_set_max_sectors_kb(mpp, 0);
812                 if (is_daemon && mpp->ghost_delay > 0 && mpp->nr_active &&
813                     pathcount(mpp, PATH_GHOST) == mpp->nr_active)
814                         mpp->ghost_delay_tick = mpp->ghost_delay;
815                 r = dm_addmap_create(mpp, params);
816
817                 lock_multipath(mpp, 0);
818                 break;
819
820         case ACT_RELOAD:
821                 sysfs_set_max_sectors_kb(mpp, 1);
822                 if (mpp->ghost_delay_tick > 0 && pathcount(mpp, PATH_UP))
823                         mpp->ghost_delay_tick = 0;
824                 r = dm_addmap_reload(mpp, params, 0);
825                 break;
826
827         case ACT_RESIZE:
828                 sysfs_set_max_sectors_kb(mpp, 1);
829                 if (mpp->ghost_delay_tick > 0 && pathcount(mpp, PATH_UP))
830                         mpp->ghost_delay_tick = 0;
831                 r = dm_addmap_reload(mpp, params, 1);
832                 break;
833
834         case ACT_RENAME:
835                 conf = get_multipath_config();
836                 pthread_cleanup_push(put_multipath_config, conf);
837                 r = dm_rename(mpp->alias_old, mpp->alias,
838                               conf->partition_delim, mpp->skip_kpartx);
839                 pthread_cleanup_pop(1);
840                 break;
841
842         case ACT_FORCERENAME:
843                 conf = get_multipath_config();
844                 pthread_cleanup_push(put_multipath_config, conf);
845                 r = dm_rename(mpp->alias_old, mpp->alias,
846                               conf->partition_delim, mpp->skip_kpartx);
847                 pthread_cleanup_pop(1);
848                 if (r) {
849                         sysfs_set_max_sectors_kb(mpp, 1);
850                         if (mpp->ghost_delay_tick > 0 &&
851                             pathcount(mpp, PATH_UP))
852                                 mpp->ghost_delay_tick = 0;
853                         r = dm_addmap_reload(mpp, params, 0);
854                 }
855                 break;
856
857         default:
858                 break;
859         }
860
861         if (r == DOMAP_OK) {
862                 /*
863                  * DM_DEVICE_CREATE, DM_DEVICE_RENAME, or DM_DEVICE_RELOAD
864                  * succeeded
865                  */
866                 mpp->force_udev_reload = 0;
867                 if (mpp->action == ACT_CREATE && remember_wwid(mpp->wwid) == 1)
868                         trigger_paths_udev_change(mpp);
869                 if (!is_daemon) {
870                         /* multipath client mode */
871                         dm_switchgroup(mpp->alias, mpp->bestpg);
872                 } else  {
873                         /* multipath daemon mode */
874                         mpp->stat_map_loads++;
875                         condlog(2, "%s: load table [0 %llu %s %s]", mpp->alias,
876                                 mpp->size, TGT_MPATH, params);
877                         /*
878                          * Required action is over, reset for the stateful daemon.
879                          * But don't do it for creation as we use in the caller the
880                          * mpp->action to figure out whether to start the watievent checker.
881                          */
882                         if (mpp->action != ACT_CREATE)
883                                 mpp->action = ACT_NOTHING;
884                         else {
885                                 conf = get_multipath_config();
886                                 mpp->wait_for_udev = 1;
887                                 mpp->uev_wait_tick = conf->uev_wait_timeout;
888                                 put_multipath_config(conf);
889                         }
890                 }
891                 dm_setgeometry(mpp);
892                 return DOMAP_OK;
893         }
894         return DOMAP_FAIL;
895 }
896
897 static int
898 deadmap (struct multipath * mpp)
899 {
900         int i, j;
901         struct pathgroup * pgp;
902         struct path * pp;
903
904         if (!mpp->pg)
905                 return 1;
906
907         vector_foreach_slot (mpp->pg, pgp, i) {
908                 if (!pgp->paths)
909                         continue;
910
911                 vector_foreach_slot (pgp->paths, pp, j)
912                         if (strlen(pp->dev))
913                                 return 0; /* alive */
914         }
915
916         return 1; /* dead */
917 }
918
919 int check_daemon(void)
920 {
921         int fd;
922         char *reply;
923         int ret = 0;
924         unsigned int timeout;
925         struct config *conf;
926
927         fd = mpath_connect();
928         if (fd == -1)
929                 return 0;
930
931         if (send_packet(fd, "show daemon") != 0)
932                 goto out;
933         conf = get_multipath_config();
934         timeout = conf->uxsock_timeout;
935         put_multipath_config(conf);
936         if (recv_packet(fd, &reply, timeout) != 0)
937                 goto out;
938
939         if (strstr(reply, "shutdown"))
940                 goto out_free;
941
942         ret = 1;
943
944 out_free:
945         FREE(reply);
946 out:
947         mpath_disconnect(fd);
948         return ret;
949 }
950
951 /*
952  * The force_reload parameter determines how coalesce_paths treats existing maps.
953  * FORCE_RELOAD_NONE: existing maps aren't touched at all
954  * FORCE_RELOAD_YES: all maps are rebuilt from scratch and (re)loaded in DM
955  * FORCE_RELOAD_WEAK: existing maps are compared to the current conf and only
956  * reloaded in DM if there's a difference. This is useful during startup.
957  */
958 int coalesce_paths (struct vectors * vecs, vector newmp, char * refwwid,
959                     int force_reload, enum mpath_cmds cmd)
960 {
961         int r = 1;
962         int k, i;
963         int is_daemon = (cmd == CMD_NONE) ? 1 : 0;
964         char params[PARAMS_SIZE];
965         struct multipath * mpp;
966         struct path * pp1;
967         struct path * pp2;
968         vector curmp = vecs->mpvec;
969         vector pathvec = vecs->pathvec;
970         struct config *conf;
971         int allow_queueing;
972
973         /* ignore refwwid if it's empty */
974         if (refwwid && !strlen(refwwid))
975                 refwwid = NULL;
976
977         if (force_reload != FORCE_RELOAD_NONE) {
978                 vector_foreach_slot (pathvec, pp1, k) {
979                         pp1->mpp = NULL;
980                 }
981         }
982         vector_foreach_slot (pathvec, pp1, k) {
983                 int invalid = 0;
984                 /* skip this path for some reason */
985
986                 /* 1. if path has no unique id or wwid blacklisted */
987                 conf = get_multipath_config();
988                 pthread_cleanup_push(put_multipath_config, conf);
989                 if (strlen(pp1->wwid) == 0 || filter_path(conf, pp1) > 0)
990                         invalid = 1;
991                 pthread_cleanup_pop(1);
992                 if (invalid) {
993                         orphan_path(pp1, "wwid blacklisted");
994                         continue;
995                 }
996
997                 /* 2. if path already coalesced */
998                 if (pp1->mpp)
999                         continue;
1000
1001                 /* 3. if path has disappeared */
1002                 if (pp1->state == PATH_REMOVED) {
1003                         orphan_path(pp1, "path removed");
1004                         continue;
1005                 }
1006
1007                 /* 4. path is out of scope */
1008                 if (refwwid && strncmp(pp1->wwid, refwwid, WWID_SIZE - 1))
1009                         continue;
1010
1011                 /* If find_multipaths was selected check if the path is valid */
1012                 if (!refwwid && !should_multipath(pp1, pathvec, curmp)) {
1013                         orphan_path(pp1, "only one path");
1014                         continue;
1015                 }
1016
1017                 /*
1018                  * at this point, we know we really got a new mp
1019                  */
1020                 mpp = add_map_with_path(vecs, pp1, 0);
1021                 if (!mpp) {
1022                         orphan_path(pp1, "failed to create multipath device");
1023                         continue;
1024                 }
1025
1026                 if (pp1->priority == PRIO_UNDEF)
1027                         mpp->action = ACT_REJECT;
1028
1029                 if (!mpp->paths) {
1030                         condlog(0, "%s: skip coalesce (no paths)", mpp->alias);
1031                         remove_map(mpp, vecs, 0);
1032                         continue;
1033                 }
1034
1035                 for (i = k + 1; i < VECTOR_SIZE(pathvec); i++) {
1036                         pp2 = VECTOR_SLOT(pathvec, i);
1037
1038                         if (strcmp(pp1->wwid, pp2->wwid))
1039                                 continue;
1040
1041                         if (!mpp->size && pp2->size)
1042                                 mpp->size = pp2->size;
1043
1044                         if (mpp->size && pp2->size &&
1045                             pp2->size != mpp->size) {
1046                                 /*
1047                                  * ouch, avoid feeding that to the DM
1048                                  */
1049                                 condlog(0, "%s: size %llu, expected %llu. "
1050                                         "Discard", pp2->dev_t, pp2->size,
1051                                         mpp->size);
1052                                 mpp->action = ACT_REJECT;
1053                         }
1054                         if (pp2->priority == PRIO_UNDEF)
1055                                 mpp->action = ACT_REJECT;
1056                 }
1057                 verify_paths(mpp, vecs);
1058
1059                 params[0] = '\0';
1060                 if (setup_map(mpp, params, PARAMS_SIZE, vecs)) {
1061                         remove_map(mpp, vecs, 0);
1062                         continue;
1063                 }
1064
1065                 if (cmd == CMD_DRY_RUN)
1066                         mpp->action = ACT_DRY_RUN;
1067                 if (mpp->action == ACT_UNDEF)
1068                         select_action(mpp, curmp,
1069                                       force_reload == FORCE_RELOAD_YES ? 1 : 0);
1070
1071                 r = domap(mpp, params, is_daemon);
1072
1073                 if (r == DOMAP_FAIL || r == DOMAP_RETRY) {
1074                         condlog(3, "%s: domap (%u) failure "
1075                                    "for create/reload map",
1076                                 mpp->alias, r);
1077                         if (r == DOMAP_FAIL || is_daemon) {
1078                                 condlog(2, "%s: %s map",
1079                                         mpp->alias, (mpp->action == ACT_CREATE)?
1080                                         "ignoring" : "removing");
1081                                 remove_map(mpp, vecs, 0);
1082                                 continue;
1083                         } else /* if (r == DOMAP_RETRY) */
1084                                 return r;
1085                 }
1086                 if (r == DOMAP_DRY)
1087                         continue;
1088
1089                 if (r == DOMAP_EXIST && mpp->action == ACT_NOTHING &&
1090                     force_reload == FORCE_RELOAD_WEAK)
1091                         /*
1092                          * First time we're called, and no changes applied.
1093                          * domap() was a noop. But we can't be sure that
1094                          * udev has already finished setting up this device
1095                          * (udev in initrd may have been shut down while
1096                          * processing this device or its children).
1097                          * Trigger a change event, just in case.
1098                          */
1099                         trigger_udev_change(find_mp_by_wwid(curmp, mpp->wwid));
1100
1101                 conf = get_multipath_config();
1102                 allow_queueing = conf->allow_queueing;
1103                 put_multipath_config(conf);
1104                 if (!is_daemon && !allow_queueing && !check_daemon()) {
1105                         if (mpp->no_path_retry != NO_PATH_RETRY_UNDEF &&
1106                             mpp->no_path_retry != NO_PATH_RETRY_FAIL)
1107                                 condlog(3, "%s: multipathd not running, unset "
1108                                         "queue_if_no_path feature", mpp->alias);
1109                         if (!dm_queue_if_no_path(mpp->alias, 0))
1110                                 remove_feature(&mpp->features,
1111                                                "queue_if_no_path");
1112                 }
1113
1114                 if (!is_daemon && mpp->action != ACT_NOTHING) {
1115                         int verbosity;
1116
1117                         conf = get_multipath_config();
1118                         verbosity = conf->verbosity;
1119                         put_multipath_config(conf);
1120                         print_multipath_topology(mpp, verbosity);
1121                 }
1122
1123                 if (newmp) {
1124                         if (mpp->action != ACT_REJECT) {
1125                                 if (!vector_alloc_slot(newmp))
1126                                         return 1;
1127                                 vector_set_slot(newmp, mpp);
1128                         }
1129                         else
1130                                 remove_map(mpp, vecs, 0);
1131                 }
1132         }
1133         /*
1134          * Flush maps with only dead paths (ie not in sysfs)
1135          * Keep maps with only failed paths
1136          */
1137         if (newmp) {
1138                 vector_foreach_slot (newmp, mpp, i) {
1139                         char alias[WWID_SIZE];
1140
1141                         if (!deadmap(mpp))
1142                                 continue;
1143
1144                         strncpy(alias, mpp->alias, WWID_SIZE - 1);
1145
1146                         vector_del_slot(newmp, i);
1147                         i--;
1148                         remove_map(mpp, vecs, 0);
1149
1150                         if (dm_flush_map(alias))
1151                                 condlog(2, "%s: remove failed (dead)",
1152                                         alias);
1153                         else
1154                                 condlog(2, "%s: remove (dead)", alias);
1155                 }
1156         }
1157         return 0;
1158 }
1159
1160 struct udev_device *get_udev_device(const char *dev, enum devtypes dev_type)
1161 {
1162         struct udev_device *ud = NULL;
1163         const char *base;
1164
1165         if (dev == NULL || *dev == '\0')
1166                 return NULL;
1167
1168         switch (dev_type) {
1169         case DEV_DEVNODE:
1170         case DEV_DEVMAP:
1171                 /* This should be GNU basename, compiler will warn if not */
1172                 base = basename(dev);
1173                 if (*base == '\0')
1174                         break;
1175                 ud = udev_device_new_from_subsystem_sysname(udev, "block",
1176                                                             base);
1177                 break;
1178         case DEV_DEVT:
1179                 ud = udev_device_new_from_devnum(udev, 'b', parse_devt(dev));
1180                 break;
1181         case DEV_UEVENT:
1182                 ud = udev_device_new_from_environment(udev);
1183                 break;
1184         default:
1185                 condlog(0, "Internal error: get_udev_device called with invalid type %d\n",
1186                         dev_type);
1187                 break;
1188         }
1189         if (ud == NULL)
1190                 condlog(2, "get_udev_device: failed to look up %s with type %d",
1191                         dev, dev_type);
1192         return ud;
1193 }
1194
1195 /*
1196  * returns:
1197  * 0 - success
1198  * 1 - failure
1199  * 2 - blacklist
1200  */
1201 int get_refwwid(enum mpath_cmds cmd, char *dev, enum devtypes dev_type,
1202                 vector pathvec, char **wwid)
1203 {
1204         int ret = 1;
1205         struct path * pp;
1206         char buff[FILE_NAME_SIZE];
1207         char * refwwid = NULL, tmpwwid[WWID_SIZE];
1208         int flags = DI_SYSFS | DI_WWID;
1209         struct config *conf;
1210         int invalid = 0;
1211
1212         if (!wwid)
1213                 return 1;
1214         *wwid = NULL;
1215
1216         if (dev_type == DEV_NONE)
1217                 return 1;
1218
1219         if (cmd != CMD_REMOVE_WWID)
1220                 flags |= DI_BLACKLIST;
1221
1222         if (dev_type == DEV_DEVNODE) {
1223                 if (basenamecpy(dev, buff, FILE_NAME_SIZE) == 0) {
1224                         condlog(1, "basename failed for '%s' (%s)",
1225                                 dev, buff);
1226                         return 1;
1227                 }
1228
1229                 pp = find_path_by_dev(pathvec, buff);
1230                 if (!pp) {
1231                         struct udev_device *udevice =
1232                                 get_udev_device(buff, dev_type);
1233
1234                         if (!udevice)
1235                                 return 1;
1236
1237                         conf = get_multipath_config();
1238                         pthread_cleanup_push(put_multipath_config, conf);
1239                         ret = store_pathinfo(pathvec, conf, udevice,
1240                                              flags, &pp);
1241                         pthread_cleanup_pop(1);
1242                         udev_device_unref(udevice);
1243                         if (!pp) {
1244                                 if (ret == 1)
1245                                         condlog(0, "%s: can't store path info",
1246                                                 dev);
1247                                 return ret;
1248                         }
1249                 }
1250                 conf = get_multipath_config();
1251                 pthread_cleanup_push(put_multipath_config, conf);
1252                 if (pp->udev && pp->uid_attribute &&
1253                     filter_property(conf, pp->udev) > 0)
1254                         invalid = 1;
1255                 pthread_cleanup_pop(1);
1256                 if (invalid)
1257                         return 2;
1258
1259                 refwwid = pp->wwid;
1260                 goto out;
1261         }
1262
1263         if (dev_type == DEV_DEVT) {
1264                 strchop(dev);
1265                 if (devt2devname(buff, FILE_NAME_SIZE, dev)) {
1266                         condlog(0, "%s: cannot find block device\n", dev);
1267                         return 1;
1268                 }
1269                 pp = find_path_by_dev(pathvec, buff);
1270                 if (!pp) {
1271                         struct udev_device *udevice =
1272                                 get_udev_device(dev, dev_type);
1273
1274                         if (!udevice)
1275                                 return 1;
1276
1277                         conf = get_multipath_config();
1278                         pthread_cleanup_push(put_multipath_config, conf);
1279                         ret = store_pathinfo(pathvec, conf, udevice,
1280                                              flags, &pp);
1281                         pthread_cleanup_pop(1);
1282                         udev_device_unref(udevice);
1283                         if (!pp) {
1284                                 if (ret == 1)
1285                                         condlog(0, "%s can't store path info",
1286                                                 buff);
1287                                 return ret;
1288                         }
1289                 }
1290                 conf = get_multipath_config();
1291                 pthread_cleanup_push(put_multipath_config, conf);
1292                 if (pp->udev && pp->uid_attribute &&
1293                     filter_property(conf, pp->udev) > 0)
1294                         invalid = 1;
1295                 pthread_cleanup_pop(1);
1296                 if (invalid)
1297                         return 2;
1298                 refwwid = pp->wwid;
1299                 goto out;
1300         }
1301
1302         if (dev_type == DEV_UEVENT) {
1303                 struct udev_device *udevice = get_udev_device(dev, dev_type);
1304
1305                 if (!udevice)
1306                         return 1;
1307
1308                 conf = get_multipath_config();
1309                 pthread_cleanup_push(put_multipath_config, conf);
1310                 ret = store_pathinfo(pathvec, conf, udevice,
1311                                      flags, &pp);
1312                 pthread_cleanup_pop(1);
1313                 udev_device_unref(udevice);
1314                 if (!pp) {
1315                         if (ret == 1)
1316                                 condlog(0, "%s: can't store path info", dev);
1317                         return ret;
1318                 }
1319                 conf = get_multipath_config();
1320                 pthread_cleanup_push(put_multipath_config, conf);
1321                 if (pp->udev && pp->uid_attribute &&
1322                     filter_property(conf, pp->udev) > 0)
1323                         invalid = 1;
1324                 pthread_cleanup_pop(1);
1325                 if (invalid)
1326                         return 2;
1327                 refwwid = pp->wwid;
1328                 goto out;
1329         }
1330
1331         if (dev_type == DEV_DEVMAP) {
1332
1333                 conf = get_multipath_config();
1334                 pthread_cleanup_push(put_multipath_config, conf);
1335                 if (((dm_get_uuid(dev, tmpwwid)) == 0) && (strlen(tmpwwid))) {
1336                         refwwid = tmpwwid;
1337                         goto check;
1338                 }
1339
1340                 /*
1341                  * may be a binding
1342                  */
1343                 if (get_user_friendly_wwid(dev, tmpwwid,
1344                                            conf->bindings_file) == 0) {
1345                         refwwid = tmpwwid;
1346                         goto check;
1347                 }
1348
1349                 /*
1350                  * or may be an alias
1351                  */
1352                 refwwid = get_mpe_wwid(conf->mptable, dev);
1353
1354                 /*
1355                  * or directly a wwid
1356                  */
1357                 if (!refwwid)
1358                         refwwid = dev;
1359
1360 check:
1361                 if (refwwid && strlen(refwwid) &&
1362                     filter_wwid(conf->blist_wwid, conf->elist_wwid, refwwid,
1363                                 NULL) > 0)
1364                         invalid = 1;
1365                 pthread_cleanup_pop(1);
1366                 if (invalid)
1367                         return 2;
1368         }
1369 out:
1370         if (refwwid && strlen(refwwid)) {
1371                 *wwid = STRDUP(refwwid);
1372                 return 0;
1373         }
1374
1375         return 1;
1376 }
1377
1378 int reload_map(struct vectors *vecs, struct multipath *mpp, int refresh,
1379                int is_daemon)
1380 {
1381         char params[PARAMS_SIZE] = {0};
1382         struct path *pp;
1383         int i, r;
1384
1385         update_mpp_paths(mpp, vecs->pathvec);
1386         if (refresh) {
1387                 vector_foreach_slot (mpp->paths, pp, i) {
1388                         struct config *conf = get_multipath_config();
1389                         pthread_cleanup_push(put_multipath_config, conf);
1390                         r = pathinfo(pp, conf, DI_PRIO);
1391                         pthread_cleanup_pop(1);
1392                         if (r) {
1393                                 condlog(2, "%s: failed to refresh pathinfo",
1394                                         mpp->alias);
1395                                 return 1;
1396                         }
1397                 }
1398         }
1399         if (setup_map(mpp, params, PARAMS_SIZE, vecs)) {
1400                 condlog(0, "%s: failed to setup map", mpp->alias);
1401                 return 1;
1402         }
1403         select_action(mpp, vecs->mpvec, 1);
1404
1405         r = domap(mpp, params, is_daemon);
1406         if (r == DOMAP_FAIL || r == DOMAP_RETRY) {
1407                 condlog(3, "%s: domap (%u) failure "
1408                         "for reload map", mpp->alias, r);
1409                 return 1;
1410         }
1411
1412         return 0;
1413 }