3 #include <libdevmapper.h>
10 #include <sysfs/libsysfs.h>
11 #include <sysfs/dlist.h>
17 #include <path_state.h>
28 #include <blacklist.h>
33 #include <devmapper.h>
35 #include <discovery.h>
39 #include <switchgroup.h>
40 #include <path_state.h>
48 #include "cli_handlers.h"
50 #define FILE_NAME_SIZE 256
53 #define LOG_MSG(a,b) \
55 condlog(a, "%s: %s", pp->dev_t, b); \
56 memset(b, 0, MAX_CHECKER_MSG_SIZE); \
61 fprintf(stderr, "%s:%s(%i) lock %p\n", __FILE__, __FUNCTION__, __LINE__, a); \
64 fprintf(stderr, "%s:%s(%i) unlock %p\n", __FILE__, __FUNCTION__, __LINE__, a); \
65 pthread_mutex_unlock(a)
66 #define lock_cleanup_pop(a) \
67 fprintf(stderr, "%s:%s(%i) unlock %p\n", __FILE__, __FUNCTION__, __LINE__, a); \
68 pthread_cleanup_pop(1);
70 #define lock(a) pthread_mutex_lock(a)
71 #define unlock(a) pthread_mutex_unlock(a)
72 #define lock_cleanup_pop(a) pthread_cleanup_pop(1);
75 pthread_cond_t exit_cond = PTHREAD_COND_INITIALIZER;
76 pthread_mutex_t exit_mutex = PTHREAD_MUTEX_INITIALIZER;
85 char mapname[WWID_SIZE];
89 static struct event_thread *
93 struct event_thread * wp;
95 wp = (struct event_thread *)MALLOC(sizeof(struct event_thread));
101 free_waiter (void * data)
103 struct event_thread * wp = (struct event_thread *)data;
106 dm_task_destroy(wp->dmt);
111 stop_waiter_thread (struct multipath * mpp, struct vectors * vecs)
113 struct event_thread * wp = (struct event_thread *)mpp->waiter;
114 pthread_t thread = wp->thread;
119 condlog(2, "%s: stop event checker thread", wp->mapname);
120 pthread_kill(thread, SIGHUP);
124 cleanup_lock (void * data)
126 pthread_mutex_unlock((pthread_mutex_t *)data);
130 adopt_paths (struct vectors * vecs, struct multipath * mpp)
138 vector_foreach_slot (vecs->pathvec, pp, i) {
139 if (!strncmp(mpp->wwid, pp->wwid, WWID_SIZE)) {
140 condlog(4, "%s ownership set", pp->dev_t);
147 orphan_path (struct path * pp)
151 pp->dmstate = PSTATE_UNDEF;
152 pp->checker_context = NULL;
163 orphan_paths (struct vectors * vecs, struct multipath * mpp)
168 vector_foreach_slot (vecs->pathvec, pp, i) {
169 if (pp->mpp == mpp) {
170 condlog(4, "%s is orphaned", pp->dev_t);
177 update_multipath_table (struct multipath *mpp, vector pathvec)
182 if (dm_get_map(mpp->alias, &mpp->size, mpp->params))
185 if (disassemble_map(pathvec, mpp->params, mpp))
192 update_multipath_status (struct multipath *mpp)
197 if(dm_get_status(mpp->alias, mpp->status))
200 if (disassemble_status(mpp->status, mpp))
207 update_multipath_strings (struct multipath *mpp, vector pathvec)
211 mpp->selector = NULL;
216 mpp->features = NULL;
219 if (mpp->hwhandler) {
220 FREE(mpp->hwhandler);
221 mpp->hwhandler = NULL;
224 free_pgvec(mpp->pg, KEEP_PATHS);
227 if (update_multipath_table(mpp, pathvec))
230 if (update_multipath_status(mpp))
237 set_multipath_wwid (struct multipath * mpp)
242 dm_get_uuid(mpp->alias, mpp->wwid);
246 pathcount (struct multipath *mpp, int state)
248 struct pathgroup *pgp;
253 vector_foreach_slot (mpp->pg, pgp, i)
254 vector_foreach_slot (pgp->paths, pp, j)
255 if (pp->state == state)
261 * mpp->no_path_retry:
262 * -2 (QUEUE) : queue_if_no_path enabled, never turned off
263 * -1 (FAIL) : fail_if_no_path
264 * 0 (UNDEF) : nothing
265 * >0 : queue_if_no_path enabled, turned off after polling n times
268 update_queue_mode_del_path(struct multipath *mpp)
270 if (--mpp->nr_active == 0 && mpp->no_path_retry > 0) {
273 * meaning of +1: retry_tick may be decremented in
274 * checkerloop before starting retry.
276 mpp->retry_tick = mpp->no_path_retry * conf->checkint + 1;
277 condlog(1, "%s: Entering recovery mode: max_retries=%d",
278 mpp->alias, mpp->no_path_retry);
280 condlog(2, "%s: remaining active paths: %d", mpp->alias, mpp->nr_active);
284 update_queue_mode_add_path(struct multipath *mpp)
286 if (mpp->nr_active++ == 0 && mpp->no_path_retry > 0) {
287 /* come back to normal mode from retry mode */
289 dm_queue_if_no_path(mpp->alias, 1);
290 condlog(2, "%s: queue_if_no_path enabled", mpp->alias);
291 condlog(1, "%s: Recovered to normal mode", mpp->alias);
293 condlog(2, "%s: remaining active paths: %d", mpp->alias, mpp->nr_active);
297 set_no_path_retry(struct multipath *mpp)
300 mpp->nr_active = pathcount(mpp, PATH_UP);
301 select_no_path_retry(mpp);
303 switch (mpp->no_path_retry) {
304 case NO_PATH_RETRY_UNDEF:
306 case NO_PATH_RETRY_FAIL:
307 dm_queue_if_no_path(mpp->alias, 0);
309 case NO_PATH_RETRY_QUEUE:
310 dm_queue_if_no_path(mpp->alias, 1);
313 dm_queue_if_no_path(mpp->alias, 1);
314 if (mpp->nr_active == 0) {
315 /* Enter retry mode */
316 mpp->retry_tick = mpp->no_path_retry * conf->checkint;
317 condlog(1, "%s: Entering recovery mode: max_retries=%d",
318 mpp->alias, mpp->no_path_retry);
324 static struct hwentry *
325 extract_hwe_from_path(struct multipath * mpp)
328 struct pathgroup * pgp;
330 pgp = VECTOR_SLOT(mpp->pg, 0);
331 pp = VECTOR_SLOT(pgp->paths, 0);
337 remove_map (struct multipath * mpp, struct vectors * vecs)
341 stop_waiter_thread(mpp, vecs);
344 * clear references to this map
346 orphan_paths(vecs, mpp);
349 * purge the multipath vector
351 i = find_slot(vecs->mpvec, (void *)mpp);
352 vector_del_slot(vecs->mpvec, i);
357 free_multipath(mpp, KEEP_PATHS);
362 remove_maps (struct vectors * vecs)
365 struct multipath * mpp;
367 vector_foreach_slot (vecs->mpvec, mpp, i) {
368 remove_map(mpp, vecs);
372 vector_free(vecs->mpvec);
377 setup_multipath (struct vectors * vecs, struct multipath * mpp)
379 set_multipath_wwid(mpp);
380 mpp->mpe = find_mpe(mpp->wwid);
381 condlog(4, "discovered map %s", mpp->alias);
383 if (update_multipath_strings(mpp, vecs->pathvec))
386 adopt_paths(vecs, mpp);
387 select_pgfailback(mpp);
388 mpp->hwe = extract_hwe_from_path(mpp);
389 set_no_path_retry(mpp);
393 remove_map(mpp, vecs);
394 condlog(0, "failed to setup multipath");
399 need_switch_pathgroup (struct multipath * mpp, int refresh)
401 struct pathgroup * pgp;
405 if (!mpp || mpp->pgfailback == -FAILBACK_MANUAL)
409 * Refresh path priority values
412 vector_foreach_slot (mpp->pg, pgp, i)
413 vector_foreach_slot (pgp->paths, pp, j)
414 pathinfo(pp, conf->hwtable, DI_PRIO);
416 select_path_group(mpp); /* sets mpp->nextpg */
417 pgp = VECTOR_SLOT(mpp->pg, mpp->nextpg - 1);
419 if (pgp && pgp->status != PGSTATE_ACTIVE)
426 switch_pathgroup (struct multipath * mpp)
428 struct pathgroup * pgp;
430 pgp = VECTOR_SLOT(mpp->pg, mpp->nextpg - 1);
432 if (pgp && pgp->status != PGSTATE_ACTIVE) {
433 dm_switchgroup(mpp->alias, mpp->nextpg);
434 condlog(2, "%s: switch to path group #%i",
435 mpp->alias, mpp->nextpg);
440 update_multipath (struct vectors *vecs, char *mapname)
442 struct multipath *mpp;
443 struct pathgroup *pgp;
448 mpp = find_mp(vecs->mpvec, mapname);
453 free_pgvec(mpp->pg, KEEP_PATHS);
456 if (setup_multipath(vecs, mpp))
457 goto out; /* mpp freed in setup_multipath */
460 * compare checkers states with DM states
462 vector_foreach_slot (mpp->pg, pgp, i) {
463 vector_foreach_slot (pgp->paths, pp, j) {
464 if (pp->dmstate != PSTATE_FAILED)
467 if (pp->state != PATH_DOWN) {
468 condlog(2, "%s: mark as failed", pp->dev_t);
469 pp->state = PATH_DOWN;
470 update_queue_mode_del_path(mpp);
474 * schedule the next check earlier
476 if (pp->tick > conf->checkint)
477 pp->tick = conf->checkint;
484 condlog(0, "failed to update multipath");
489 static sigset_t unblock_sighup(void)
494 sigaddset(&set, SIGHUP);
495 pthread_sigmask(SIG_UNBLOCK, &set, &old);
500 * returns the reschedule delay
501 * negative means *stop*
504 waiteventloop (struct event_thread * waiter)
510 if (!waiter->event_nr)
511 waiter->event_nr = dm_geteventnr(waiter->mapname);
513 if (!(waiter->dmt = dm_task_create(DM_DEVICE_WAITEVENT)))
516 if (!dm_task_set_name(waiter->dmt, waiter->mapname)) {
517 dm_task_destroy(waiter->dmt);
521 if (waiter->event_nr && !dm_task_set_event_nr(waiter->dmt,
523 dm_task_destroy(waiter->dmt);
527 dm_task_no_open_count(waiter->dmt);
529 /* accept wait interruption */
530 set = unblock_sighup();
532 /* interruption spits messages */
536 r = dm_task_run(waiter->dmt);
538 /* wait is over : event or interrupt */
539 pthread_sigmask(SIG_SETMASK, &set, NULL);
542 if (!r) /* wait interrupted by signal */
545 dm_task_destroy(waiter->dmt);
553 condlog(3, "%s: devmap event #%i",
554 waiter->mapname, waiter->event_nr);
559 * 1) a table reload, which means our mpp structure is
560 * obsolete : refresh it through update_multipath()
561 * 2) a path failed by DM : mark as such through
563 * 3) map has gone away : stop the thread.
564 * 4) a path reinstate : nothing to do
565 * 5) a switch group : nothing to do
567 pthread_cleanup_push(cleanup_lock, waiter->vecs->lock);
568 lock(waiter->vecs->lock);
569 r = update_multipath(waiter->vecs, waiter->mapname);
570 lock_cleanup_pop(waiter->vecs->lock);
573 return -1; /* stop the thread */
575 event_nr = dm_geteventnr(waiter->mapname);
577 if (waiter->event_nr == event_nr)
578 return 1; /* upon problem reschedule 1s later */
580 waiter->event_nr = event_nr;
582 return -1; /* never reach there */
586 waitevent (void * et)
589 struct event_thread *waiter;
591 mlockall(MCL_CURRENT | MCL_FUTURE);
593 waiter = (struct event_thread *)et;
594 pthread_cleanup_push(free_waiter, et);
597 r = waiteventloop(waiter);
605 pthread_cleanup_pop(1);
610 start_waiter_thread (struct multipath * mpp, struct vectors * vecs)
613 struct event_thread * wp;
618 if (pthread_attr_init(&attr))
621 pthread_attr_setstacksize(&attr, 32 * 1024);
622 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
629 mpp->waiter = (void *)wp;
630 strncpy(wp->mapname, mpp->alias, WWID_SIZE);
633 if (pthread_create(&wp->thread, &attr, waitevent, wp)) {
634 condlog(0, "%s: cannot create event checker", wp->mapname);
637 condlog(2, "%s: event checker started", wp->mapname);
644 condlog(0, "failed to start waiter thread");
649 uev_add_map (char * devname, struct vectors * vecs)
652 char dev_t[BLK_DEV_SIZE];
654 struct multipath * mpp;
656 if (sysfs_get_dev(sysfs_path, devname, dev_t, BLK_DEV_SIZE))
659 if (sscanf(dev_t, "%d:%d", &major, &minor) != 2)
662 alias = dm_mapname(major, minor);
667 if (!dm_type(alias, DEFAULT_TARGET)) {
668 condlog(4, "%s: not a multipath map", alias);
673 mpp = find_mp(vecs->mpvec, alias);
677 * this should not happen,
678 * we missed a remove map event (not sent ?)
680 condlog(2, "%s: already registered", alias);
681 remove_map(mpp, vecs);
685 * now we can allocate
687 mpp = alloc_multipath();
695 if (setup_multipath(vecs, mpp))
696 return 1; /* mpp freed in setup_multipath */
698 if (!vector_alloc_slot(vecs->mpvec))
701 vector_set_slot(vecs->mpvec, mpp);
702 adopt_paths(vecs, mpp);
704 if (start_waiter_thread(mpp, vecs))
709 condlog(2, "%s: add devmap failed", mpp->alias);
710 remove_map(mpp, vecs);
715 uev_remove_map (char * devname, struct vectors * vecs)
718 struct multipath * mpp;
720 if (sscanf(devname, "dm-%d", &minor) != 1)
723 mpp = find_mp_by_minor(vecs->mpvec, minor);
726 condlog(3, "%s: devmap not registered, can't remove",
731 condlog(2, "remove %s devmap", mpp->alias);
732 remove_map(mpp, vecs);
738 uev_add_path (char * devname, struct vectors * vecs)
742 pp = find_path_by_dev(vecs->pathvec, devname);
745 condlog(3, "%s: already in pathvec");
748 pp = store_pathinfo(vecs->pathvec, conf->hwtable,
749 devname, DI_SYSFS | DI_WWID);
752 condlog(0, "%s: failed to store path info", devname);
756 condlog(2, "%s: path checker registered", devname);
757 pp->mpp = find_mp_by_wwid(vecs->mpvec, pp->wwid);
760 condlog(4, "%s: ownership set to %s",
761 pp->dev_t, pp->mpp->alias);
763 condlog(4, "%s: orphaned", pp->dev_t);
771 uev_remove_path (char * devname, struct vectors * vecs)
776 pp = find_path_by_dev(vecs->pathvec, devname);
779 condlog(3, "%s: not in pathvec");
783 if (pp->mpp && pp->state == PATH_UP)
784 update_queue_mode_del_path(pp->mpp);
786 condlog(2, "remove %s path checker", devname);
787 i = find_slot(vecs->pathvec, (void *)pp);
788 vector_del_slot(vecs->pathvec, i);
795 show_paths (char ** r, int * len, struct vectors * vecs)
801 struct path_layout pl;
803 get_path_layout(&pl, vecs->pathvec);
804 reply = MALLOC(MAX_REPLY_LEN);
810 c += snprint_path_header(c, reply + MAX_REPLY_LEN - c,
811 PRINT_PATH_CHECKER, &pl);
813 vector_foreach_slot(vecs->pathvec, pp, i)
814 c += snprint_path(c, reply + MAX_REPLY_LEN - c,
815 PRINT_PATH_CHECKER, pp, &pl);
818 *len = (int)(c - reply + 1);
823 show_maps (char ** r, int *len, struct vectors * vecs)
826 struct multipath * mpp;
829 struct map_layout ml;
831 get_map_layout(&ml, vecs->mpvec);
832 reply = MALLOC(MAX_REPLY_LEN);
838 c += snprint_map_header(c, reply + MAX_REPLY_LEN - c,
839 PRINT_MAP_FAILBACK, &ml);
841 vector_foreach_slot(vecs->mpvec, mpp, i)
842 c += snprint_map(c, reply + MAX_REPLY_LEN - c,
843 PRINT_MAP_FAILBACK, mpp, &ml);
846 *len = (int)(c - reply + 1);
851 dump_pathvec (char ** r, int * len, struct vectors * vecs)
858 *len = VECTOR_SIZE(vecs->pathvec) * sizeof(struct path);
859 reply = (char *)MALLOC(*len);
867 vector_foreach_slot (vecs->pathvec, pp, i) {
868 memcpy((void *)p, pp, sizeof(struct path));
869 p += sizeof(struct path);
872 /* return negative to hint caller not to add "ok" to the dump */
877 map_discovery (struct vectors * vecs)
880 struct multipath * mpp;
882 if (dm_get_maps(vecs->mpvec, "multipath"))
885 vector_foreach_slot (vecs->mpvec, mpp, i) {
886 if (setup_multipath(vecs, mpp))
888 mpp->minor = dm_get_minor(mpp->alias);
889 start_waiter_thread(mpp, vecs);
896 reconfigure (struct vectors * vecs)
898 struct config * old = conf;
899 struct multipath * mpp;
905 if (load_config(DEFAULT_CONFIGFILE)) {
907 condlog(2, "reconfigure failed, continue with old config");
910 conf->verbosity = old->verbosity;
913 vector_foreach_slot (vecs->mpvec, mpp, i) {
914 mpp->mpe = find_mpe(mpp->wwid);
915 mpp->hwe = extract_hwe_from_path(mpp);
916 adopt_paths(vecs, mpp);
917 set_no_path_retry(mpp);
919 vector_foreach_slot (vecs->pathvec, pp, i) {
924 condlog(2, "reconfigured");
929 uxsock_trigger (char * str, char ** reply, int * len, void * trigger_data)
931 struct vectors * vecs;
936 vecs = (struct vectors *)trigger_data;
938 pthread_cleanup_push(cleanup_lock, vecs->lock);
941 r = parse_cmd(str, reply, len, vecs);
944 *reply = STRDUP("fail\n");
945 *len = strlen(*reply) + 1;
948 else if (!r && *len == 0) {
949 *reply = STRDUP("ok\n");
950 *len = strlen(*reply) + 1;
953 /* else if (r < 0) leave *reply alone */
955 lock_cleanup_pop(vecs->lock);
960 uev_discard(char * devpath)
965 * keep only block devices, discard partitions
967 if (sscanf(devpath, "/block/%10s", a) != 1 ||
968 sscanf(devpath, "/block/%10[^/]/%10s", a, b) == 2) {
969 condlog(4, "discard event on %s", devpath);
976 uev_trigger (struct uevent * uev, void * trigger_data)
980 struct vectors * vecs;
982 vecs = (struct vectors *)trigger_data;
984 if (uev_discard(uev->devpath))
987 basename(uev->devpath, devname);
991 * device map add/remove event
993 if (!strncmp(devname, "dm-", 3)) {
994 if (!strncmp(uev->action, "add", 3)) {
995 r = uev_add_map(devname, vecs);
999 if (!strncmp(uev->action, "remove", 6)) {
1000 r = uev_remove_map(devname, vecs);
1008 * path add/remove event
1010 if (blacklist(conf->blist, devname))
1013 if (!strncmp(uev->action, "add", 3)) {
1014 r = uev_add_path(devname, vecs);
1017 if (!strncmp(uev->action, "remove", 6)) {
1018 r = uev_remove_path(devname, vecs);
1028 ueventloop (void * ap)
1030 if (uevent_listen(&uev_trigger, ap))
1031 fprintf(stderr, "error starting uevent listener");
1037 uxlsnrloop (void * ap)
1042 if (alloc_handlers())
1045 add_handler(LIST+PATHS, cli_list_paths);
1046 add_handler(LIST+MAPS, cli_list_maps);
1047 add_handler(ADD+PATH, cli_add_path);
1048 add_handler(DEL+PATH, cli_del_path);
1049 add_handler(ADD+MAP, cli_add_map);
1050 add_handler(DEL+MAP, cli_del_map);
1051 add_handler(SWITCH+MAP+GROUP, cli_switch_group);
1052 add_handler(DUMP+PATHVEC, cli_dump_pathvec);
1053 add_handler(RECONFIGURE, cli_reconfigure);
1055 uxsock_listen(&uxsock_trigger, ap);
1061 exit_daemon (int status)
1064 fprintf(stderr, "bad exit status. see daemon.log\n");
1066 condlog(3, "unlink pidfile");
1067 unlink(DEFAULT_PIDFILE);
1070 pthread_cond_signal(&exit_cond);
1071 unlock(&exit_mutex);
1077 fail_path (struct path * pp)
1082 condlog(2, "checker failed path %s in map %s",
1083 pp->dev_t, pp->mpp->alias);
1085 dm_fail_path(pp->mpp->alias, pp->dev_t);
1086 update_queue_mode_del_path(pp->mpp);
1090 * caller must have locked the path list before calling that function
1093 reinstate_path (struct path * pp)
1098 if (dm_reinstate(pp->mpp->alias, pp->dev_t))
1099 condlog(0, "%s: reinstate failed", pp->dev_t);
1101 condlog(2, "%s: reinstated", pp->dev_t);
1102 update_queue_mode_add_path(pp->mpp);
1107 enable_group(struct path * pp)
1109 struct pathgroup * pgp;
1112 * if path is added through uev_add_path, pgindex can be unset.
1113 * next update_strings() will set it, upon map reload event.
1115 * we can safely return here, because upon map reload, all
1116 * PG will be enabled.
1121 pgp = VECTOR_SLOT(pp->mpp->pg, pp->pgindex - 1);
1123 if (pgp->status == PGSTATE_DISABLED) {
1124 condlog(2, "%s: enable group #%i", pp->mpp->alias, pp->pgindex);
1125 dm_enablegroup(pp->mpp->alias, pp->pgindex);
1130 mpvec_garbage_collector (struct vectors * vecs)
1132 struct multipath * mpp;
1135 vector_foreach_slot (vecs->mpvec, mpp, i) {
1136 if (mpp && mpp->alias && !dm_map_present(mpp->alias)) {
1137 condlog(2, "%s: remove dead map", mpp->alias);
1138 remove_map(mpp, vecs);
1145 defered_failback_tick (vector mpvec)
1147 struct multipath * mpp;
1150 vector_foreach_slot (mpvec, mpp, i) {
1152 * defered failback getting sooner
1154 if (mpp->pgfailback > 0 && mpp->failback_tick > 0) {
1155 mpp->failback_tick--;
1157 if (!mpp->failback_tick && need_switch_pathgroup(mpp, 1))
1158 switch_pathgroup(mpp);
1164 retry_count_tick(vector mpvec)
1166 struct multipath *mpp;
1169 vector_foreach_slot (mpvec, mpp, i) {
1170 if (mpp->retry_tick) {
1171 condlog(4, "%s: Retrying.. No active path", mpp->alias);
1172 if(--mpp->retry_tick == 0) {
1173 dm_queue_if_no_path(mpp->alias, 0);
1174 condlog(2, "%s: Disable queueing", mpp->alias);
1181 checkerloop (void *ap)
1183 struct vectors *vecs;
1187 char checker_msg[MAX_CHECKER_MSG_SIZE];
1189 mlockall(MCL_CURRENT | MCL_FUTURE);
1191 memset(checker_msg, 0, MAX_CHECKER_MSG_SIZE);
1192 vecs = (struct vectors *)ap;
1194 condlog(2, "path checkers start up");
1197 * init the path check interval
1199 vector_foreach_slot (vecs->pathvec, pp, i) {
1200 pp->checkint = conf->checkint;
1204 pthread_cleanup_push(cleanup_lock, vecs->lock);
1208 vector_foreach_slot (vecs->pathvec, pp, i) {
1212 if (pp->tick && --pp->tick)
1213 continue; /* don't check this path yet */
1216 * provision a next check soonest,
1217 * in case we exit abnormaly from here
1219 pp->tick = conf->checkint;
1222 pathinfo(pp, conf->hwtable, DI_SYSFS);
1227 condlog(0, "%s: checkfn is void", pp->dev);
1230 newstate = pp->checkfn(pp->fd, checker_msg,
1231 &pp->checker_context);
1233 if (newstate != pp->state) {
1234 pp->state = newstate;
1235 LOG_MSG(1, checker_msg);
1238 * upon state change, reset the checkint
1239 * to the shortest delay
1241 pp->checkint = conf->checkint;
1243 if (newstate == PATH_DOWN ||
1244 newstate == PATH_SHAKY) {
1246 * proactively fail path in the DM
1251 * cancel scheduled failback
1253 pp->mpp->failback_tick = 0;
1259 * reinstate this path
1264 * need to switch group ?
1266 update_multipath_strings(pp->mpp,
1270 * schedule defered failback
1272 if (pp->mpp->pgfailback > 0)
1273 pp->mpp->failback_tick =
1274 pp->mpp->pgfailback + 1;
1275 else if (pp->mpp->pgfailback == -FAILBACK_IMMEDIATE &&
1276 need_switch_pathgroup(pp->mpp, 1))
1277 switch_pathgroup(pp->mpp);
1280 * if at least one path is up in a group, and
1281 * the group is disabled, re-enable it
1283 if (newstate == PATH_UP)
1286 else if (newstate == PATH_UP || newstate == PATH_GHOST) {
1287 LOG_MSG(4, checker_msg);
1289 * double the next check delay.
1290 * max at conf->max_checkint
1292 if (pp->checkint < (conf->max_checkint / 2))
1293 pp->checkint = 2 * pp->checkint;
1295 pp->checkint = conf->max_checkint;
1297 pp->tick = pp->checkint;
1298 condlog(4, "%s: delay next check %is",
1299 pp->dev_t, pp->tick);
1302 pp->state = newstate;
1305 * path prio refreshing
1307 condlog(4, "path prio refresh");
1308 pathinfo(pp, conf->hwtable, DI_PRIO);
1310 if (need_switch_pathgroup(pp->mpp, 0)) {
1311 if (pp->mpp->pgfailback > 0)
1312 pp->mpp->failback_tick =
1313 pp->mpp->pgfailback + 1;
1314 else if (pp->mpp->pgfailback ==
1315 -FAILBACK_IMMEDIATE)
1316 switch_pathgroup(pp->mpp);
1319 defered_failback_tick(vecs->mpvec);
1320 retry_count_tick(vecs->mpvec);
1325 condlog(4, "map garbage collection");
1326 mpvec_garbage_collector(vecs);
1330 lock_cleanup_pop(vecs->lock);
1336 static struct vectors *
1339 struct vectors * vecs;
1341 vecs = (struct vectors *)MALLOC(sizeof(struct vectors));
1347 (pthread_mutex_t *)MALLOC(sizeof(pthread_mutex_t));
1352 vecs->pathvec = vector_alloc();
1357 vecs->mpvec = vector_alloc();
1362 pthread_mutex_init(vecs->lock, NULL);
1367 vector_free(vecs->pathvec);
1372 condlog(0, "failed to init paths");
1377 signal_set(int signo, void (*func) (int))
1380 struct sigaction sig;
1381 struct sigaction osig;
1383 sig.sa_handler = func;
1384 sigemptyset(&sig.sa_mask);
1387 r = sigaction(signo, &sig, &osig);
1392 return (osig.sa_handler);
1398 condlog(3, "SIGHUP received");
1401 dbg_free_final(NULL);
1414 signal_set(SIGHUP, sighup);
1415 signal_set(SIGINT, sigend);
1416 signal_set(SIGTERM, sigend);
1417 signal_set(SIGKILL, sigend);
1424 static struct sched_param sched_param = {
1428 res = sched_setscheduler (0, SCHED_RR, &sched_param);
1431 condlog(LOG_WARNING, "Could not set SCHED_RR at priority 99");
1436 set_oom_adj (int val)
1440 fp = fopen("/proc/self/oom_adj", "w");
1445 fprintf(fp, "%i", val);
1450 child (void * param)
1452 pthread_t check_thr, uevent_thr, uxlsnr_thr;
1453 pthread_attr_t attr;
1454 struct vectors * vecs;
1456 mlockall(MCL_CURRENT | MCL_FUTURE);
1461 condlog(2, "--------start up--------");
1462 condlog(2, "read " DEFAULT_CONFIGFILE);
1464 if (load_config(DEFAULT_CONFIGFILE))
1467 setlogmask(LOG_UPTO(conf->verbosity + 3));
1470 * fill the voids left in the config file
1472 if (!conf->checkint) {
1473 conf->checkint = CHECKINT;
1474 conf->max_checkint = MAX_CHECKINT;
1477 if (pidfile_create(DEFAULT_PIDFILE, getpid())) {
1486 vecs = init_paths();
1491 if (sysfs_get_mnt_path(sysfs_path, FILE_NAME_SIZE)) {
1492 condlog(0, "can not find sysfs mount point");
1497 * fetch paths and multipaths lists
1498 * no paths and/or no multipaths are valid scenarii
1499 * vectors maintenance will be driven by events
1501 path_discovery(vecs->pathvec, conf, DI_SYSFS | DI_WWID | DI_CHECKER);
1502 map_discovery(vecs);
1507 pthread_attr_init(&attr);
1508 pthread_attr_setstacksize(&attr, 64 * 1024);
1509 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
1511 pthread_create(&check_thr, &attr, checkerloop, vecs);
1512 pthread_create(&uevent_thr, &attr, ueventloop, vecs);
1513 pthread_create(&uxlsnr_thr, &attr, uxlsnrloop, vecs);
1515 pthread_cond_wait(&exit_cond, &exit_mutex);
1522 free_pathvec(vecs->pathvec, FREE_PATHS);
1524 pthread_cancel(check_thr);
1525 pthread_cancel(uevent_thr);
1526 pthread_cancel(uxlsnr_thr);
1530 free_handlers(handlers);
1535 pthread_mutex_destroy(vecs->lock);
1543 condlog(2, "--------shut down-------");
1549 dbg_free_final(NULL);
1556 main (int argc, char *argv[])
1558 extern char *optarg;
1565 if (getuid() != 0) {
1566 fprintf(stderr, "need to be root\n");
1570 /* make sure we don't lock any path */
1572 umask(umask(077) | 022);
1574 conf = alloc_config();
1579 while ((arg = getopt(argc, argv, ":dv:k::")) != EOF ) {
1583 //debug=1; /* ### comment me out ### */
1586 if (sizeof(optarg) > sizeof(char *) ||
1587 !isdigit(optarg[0]))
1590 conf->verbosity = atoi(optarg);
1613 return (child(NULL));