2 * Copyright (c) 2004, 2005 Christophe Varoqui
3 * Copyright (c) 2005 Kiyoshi Ueda, NEC
4 * Copyright (c) 2005 Benjamin Marzinski, Redhat
5 * Copyright (c) 2005 Edward Goggin, EMC
9 #include <libdevmapper.h>
12 #include <sys/types.h>
19 #include <sysfs/libsysfs.h>
20 #include <sysfs/dlist.h>
39 #include <blacklist.h>
40 #include <structs_vec.h>
42 #include <devmapper.h>
44 #include <discovery.h>
48 #include <switchgroup.h>
50 #include <configure.h>
57 #include "cli_handlers.h"
61 #define FILE_NAME_SIZE 256
64 #define LOG_MSG(a,b) \
65 if (strlen(b)) condlog(a, "%s: %s", pp->dev_t, b);
67 pthread_cond_t exit_cond = PTHREAD_COND_INITIALIZER;
68 pthread_mutex_t exit_mutex = PTHREAD_MUTEX_INITIALIZER;
71 * global copy of vecs for use in sig handlers
73 struct vectors * gvecs;
76 need_switch_pathgroup (struct multipath * mpp, int refresh)
78 struct pathgroup * pgp;
82 if (!mpp || mpp->pgfailback == -FAILBACK_MANUAL)
86 * Refresh path priority values
89 vector_foreach_slot (mpp->pg, pgp, i)
90 vector_foreach_slot (pgp->paths, pp, j)
91 pathinfo(pp, conf->hwtable, DI_PRIO);
93 mpp->bestpg = select_path_group(mpp);
95 if (mpp->bestpg != mpp->nextpg)
102 switch_pathgroup (struct multipath * mpp)
104 mpp->stat_switchgroup++;
105 dm_switchgroup(mpp->alias, mpp->bestpg);
106 condlog(2, "%s: switch to path group #%i",
107 mpp->alias, mpp->bestpg);
111 coalesce_maps(struct vectors *vecs, vector nmpv)
113 struct multipath * ompp;
114 vector ompv = vecs->mpvec;
117 vector_foreach_slot (ompv, ompp, i) {
118 if (!find_mp_by_wwid(nmpv, ompp->wwid)) {
120 * remove all current maps not allowed by the
121 * current configuration
123 if (dm_flush_map(ompp->alias, DEFAULT_TARGET)) {
124 condlog(0, "%s: unable to flush devmap",
127 * may be just because the device is open
129 if (!vector_alloc_slot(nmpv))
132 vector_set_slot(nmpv, ompp);
133 setup_multipath(vecs, ompp);
135 if ((j = find_slot(ompv, (void *)ompp)) != -1)
136 vector_del_slot(ompv, j);
142 condlog(3, "%s devmap removed", ompp->alias);
150 sync_map_state(struct multipath *mpp)
153 struct pathgroup *pgp;
156 vector_foreach_slot (mpp->pg, pgp, i){
157 vector_foreach_slot (pgp->paths, pp, j){
158 if (pp->state <= PATH_UNCHECKED)
160 if ((pp->dmstate == PSTATE_FAILED ||
161 pp->dmstate == PSTATE_UNDEF) &&
162 (pp->state == PATH_UP || pp->state == PATH_GHOST))
163 dm_reinstate_path(mpp->alias, pp->dev_t);
164 else if ((pp->dmstate == PSTATE_ACTIVE ||
165 pp->dmstate == PSTATE_UNDEF) &&
166 (pp->state == PATH_DOWN ||
167 pp->state == PATH_SHAKY))
168 dm_fail_path(mpp->alias, pp->dev_t);
174 sync_maps_state(vector mpvec)
177 struct multipath *mpp;
179 vector_foreach_slot (mpvec, mpp, i)
184 flush_map(struct multipath * mpp, struct vectors * vecs)
187 * clear references to this map before flushing so we can ignore
188 * the spurious uevent we may generate with the dm_flush_map call below
190 if (dm_flush_map(mpp->alias, DEFAULT_TARGET)) {
192 * May not really be an error -- if the map was already flushed
193 * from the device mapper by dmsetup(8) for instance.
195 condlog(0, "%s: can't flush", mpp->alias);
200 condlog(3, "%s: devmap removed", mpp->alias);
203 orphan_paths(vecs->pathvec, mpp);
204 remove_map(mpp, vecs, stop_waiter_thread, 1);
210 uev_add_map (char * devname, struct vectors * vecs)
212 condlog(2, "%s: add map (uevent)", devname);
213 return ev_add_map(devname, vecs);
217 ev_add_map (char * devname, struct vectors * vecs)
220 char dev_t[BLK_DEV_SIZE];
223 struct multipath * mpp;
227 if (sscanf(devname, "dm-%d", &minor) == 1 &&
228 !sysfs_get_dev(sysfs_path, devname, dev_t, BLK_DEV_SIZE) &&
229 sscanf(dev_t, "%d:%d", &major, &minor) == 2)
230 alias = dm_mapname(major, minor);
232 alias = STRDUP(devname);
237 map_present = dm_map_present(alias);
239 if (map_present && dm_type(alias, DEFAULT_TARGET) <= 0) {
240 condlog(4, "%s: not a multipath map", alias);
245 mpp = find_mp_by_alias(vecs->mpvec, alias);
249 * Not really an error -- we generate our own uevent
250 * if we create a multipath mapped device as a result
253 condlog(0, "%s: devmap already registered",
260 * now we can register the map
262 if (map_present && (mpp = add_map_without_path(vecs, minor, alias,
263 start_waiter_thread))) {
265 condlog(3, "%s: devmap %s added", alias, devname);
268 refwwid = get_refwwid(devname, DEV_DEVMAP, vecs->pathvec);
271 r = coalesce_paths(vecs, NULL, refwwid);
276 condlog(3, "%s: devmap %s added", alias, devname);
278 condlog(0, "%s: uev_add_map %s failed", alias, devname);
286 uev_remove_map (char * devname, struct vectors * vecs)
288 condlog(2, "%s: remove map (uevent)", devname);
289 return ev_remove_map(devname, vecs);
293 ev_remove_map (char * devname, struct vectors * vecs)
295 struct multipath * mpp;
297 mpp = find_mp_by_str(vecs->mpvec, devname);
300 condlog(3, "%s: devmap not registered, can't remove",
304 flush_map(mpp, vecs);
310 uev_umount_map (char * devname, struct vectors * vecs)
312 struct multipath * mpp;
314 condlog(2, "%s: umount map (uevent)", devname);
316 mpp = find_mp_by_str(vecs->mpvec, devname);
321 update_mpp_paths(mpp, vecs->pathvec);
322 verify_paths(mpp, vecs, NULL);
324 if (!VECTOR_SIZE(mpp->paths))
325 flush_map(mpp, vecs);
331 uev_add_path (char * devname, struct vectors * vecs)
333 condlog(2, "%s: add path (uevent)", devname);
334 return (ev_add_path(devname, vecs) != 1)? 0 : 1;
345 ev_add_path (char * devname, struct vectors * vecs)
347 struct multipath * mpp;
349 char empty_buff[WWID_SIZE] = {0};
351 pp = find_path_by_dev(vecs->pathvec, devname);
354 condlog(0, "%s: spurious uevent, path already in pathvec",
361 * get path vital state
363 if (!(pp = store_pathinfo(vecs->pathvec, conf->hwtable,
365 condlog(0, "%s: failed to store path info", devname);
368 pp->checkint = conf->checkint;
372 * need path UID to go any further
374 if (memcmp(empty_buff, pp->wwid, WWID_SIZE) == 0) {
375 condlog(0, "%s: failed to get path uid", devname);
376 return 1; /* leave path added to pathvec */
378 if (blacklist_path(conf, pp)){
379 int i = find_slot(vecs->pathvec, (void *)pp);
381 vector_del_slot(vecs->pathvec, i);
385 mpp = pp->mpp = find_mp_by_wwid(vecs->mpvec, pp->wwid);
388 if (adopt_paths(vecs->pathvec, mpp))
389 return 1; /* leave path added to pathvec */
391 verify_paths(mpp, vecs, NULL);
392 mpp->action = ACT_RELOAD;
395 if ((mpp = add_map_with_path(vecs, pp, 1)))
396 mpp->action = ACT_CREATE;
398 return 1; /* leave path added to pathvec */
402 * push the map to the device-mapper
404 if (setup_map(mpp)) {
405 condlog(0, "%s: failed to setup map for addition of new "
406 "path %s", mpp->alias, devname);
410 * reload the map for the multipath mapped device
412 if (domap(mpp) <= 0) {
413 condlog(0, "%s: failed in domap for addition of new "
414 "path %s", mpp->alias, devname);
416 * deal with asynchronous uevents :((
418 if (mpp->action == ACT_RELOAD) {
419 condlog(0, "%s: uev_add_path sleep", mpp->alias);
421 update_mpp_paths(mpp, vecs->pathvec);
430 * update our state from kernel regardless of create or reload
432 if (setup_multipath(vecs, mpp))
437 if (mpp->action == ACT_CREATE &&
438 start_waiter_thread(mpp, vecs))
441 condlog(3, "%s path added to devmap %s", devname, mpp->alias);
445 remove_map(mpp, vecs, NULL, 1);
450 uev_remove_path (char * devname, struct vectors * vecs)
452 condlog(2, "%s: remove path (uevent)", devname);
453 return ev_remove_path(devname, vecs);
457 ev_remove_path (char * devname, struct vectors * vecs)
459 struct multipath * mpp;
464 pp = find_path_by_dev(vecs->pathvec, devname);
467 condlog(0, "%s: spurious uevent, path not in pathvec", devname);
472 * avoid referring to the map of an orphanned path
474 if ((mpp = pp->mpp)) {
477 * remove the map IFF removing the last path
479 if (pathcount(mpp, PATH_WILD) > 1) {
480 vector rpvec = vector_alloc();
483 * transform the mp->pg vector of vectors of paths
484 * into a mp->params string to feed the device-mapper
486 update_mpp_paths(mpp, vecs->pathvec);
487 if ((i = find_slot(mpp->paths, (void *)pp)) != -1)
488 vector_del_slot(mpp->paths, i);
490 if (VECTOR_SIZE(mpp->paths) == 0) {
491 char alias[WWID_SIZE];
494 * flush_map will fail if the device is open
496 strncpy(alias, mpp->alias, WWID_SIZE);
497 if (flush_map(mpp, vecs))
500 condlog(3, "%s: removed map after removing"
501 " multiple paths", alias);
504 if (setup_map(mpp)) {
505 condlog(0, "%s: failed to setup map for"
506 " removal of path %s", mpp->alias, devname);
507 free_pathvec(rpvec, KEEP_PATHS);
513 mpp->action = ACT_RELOAD;
514 if (domap(mpp) <= 0) {
515 condlog(0, "%s: failed in domap for "
516 "removal of path %s",
517 mpp->alias, devname);
519 * Delete path from pathvec so that
520 * update_mpp_paths wont find it later
521 * when/if another path is removed.
523 if ((i = find_slot(vecs->pathvec, (void *)pp)) != -1)
524 vector_del_slot(vecs->pathvec, i);
529 * update our state from kernel
531 if (setup_multipath(vecs, mpp)) {
532 free_pathvec(rpvec, KEEP_PATHS);
537 condlog(3, "%s path removed from devmap %s",
538 devname, mpp->alias);
540 free_pathvec(rpvec, KEEP_PATHS);
543 char alias[WWID_SIZE];
546 * flush_map will fail if the device is open
548 strncpy(alias, mpp->alias, WWID_SIZE);
549 if (flush_map(mpp, vecs))
552 condlog(3, "%s: removed map", alias);
557 if ((i = find_slot(vecs->pathvec, (void *)pp)) != -1)
558 vector_del_slot(vecs->pathvec, i);
565 remove_map(mpp, vecs, stop_waiter_thread, 1);
570 map_discovery (struct vectors * vecs)
573 struct multipath * mpp;
575 if (dm_get_maps(vecs->mpvec, "multipath"))
578 vector_foreach_slot (vecs->mpvec, mpp, i)
579 if (setup_multipath(vecs, mpp))
586 uxsock_trigger (char * str, char ** reply, int * len, void * trigger_data)
588 struct vectors * vecs;
593 vecs = (struct vectors *)trigger_data;
595 pthread_cleanup_push(cleanup_lock, vecs->lock);
598 r = parse_cmd(str, reply, len, vecs);
601 *reply = STRDUP("fail\n");
602 *len = strlen(*reply) + 1;
605 else if (!r && *len == 0) {
606 *reply = STRDUP("ok\n");
607 *len = strlen(*reply) + 1;
610 /* else if (r < 0) leave *reply alone */
612 lock_cleanup_pop(vecs->lock);
617 uev_discard(char * devpath)
622 * keep only block devices, discard partitions
624 if (sscanf(devpath, "/block/%10s", a) != 1 ||
625 sscanf(devpath, "/block/%10[^/]/%10s", a, b) == 2) {
626 condlog(4, "discard event on %s", devpath);
633 uev_trigger (struct uevent * uev, void * trigger_data)
637 struct vectors * vecs;
639 vecs = (struct vectors *)trigger_data;
641 if (uev_discard(uev->devpath))
644 basename(uev->devpath, devname);
648 * device map add/remove event
650 if (!strncmp(devname, "dm-", 3)) {
651 if (!strncmp(uev->action, "add", 3)) {
652 r = uev_add_map(devname, vecs);
655 if (!strncmp(uev->action, "remove", 6)) {
656 r = uev_remove_map(devname, vecs);
659 if (!strncmp(uev->action, "umount", 6)) {
660 r = uev_umount_map(devname, vecs);
667 * path add/remove event
669 if (blacklist(conf->blist_devnode, devname))
672 if (!strncmp(uev->action, "add", 3)) {
673 r = uev_add_path(devname, vecs);
676 if (!strncmp(uev->action, "remove", 6)) {
677 r = uev_remove_path(devname, vecs);
687 ueventloop (void * ap)
689 if (uevent_listen(&uev_trigger, ap))
690 fprintf(stderr, "error starting uevent listener");
696 uxlsnrloop (void * ap)
701 if (alloc_handlers())
704 add_handler(LIST+PATHS, cli_list_paths);
705 add_handler(LIST+MAPS, cli_list_maps);
706 add_handler(LIST+MAPS+STATUS, cli_list_maps_status);
707 add_handler(LIST+MAPS+STATS, cli_list_maps_stats);
708 add_handler(LIST+MAPS+TOPOLOGY, cli_list_maps_topology);
709 add_handler(LIST+TOPOLOGY, cli_list_maps_topology);
710 add_handler(LIST+MAP+TOPOLOGY, cli_list_map_topology);
711 add_handler(LIST+CONFIG, cli_list_config);
712 add_handler(ADD+PATH, cli_add_path);
713 add_handler(DEL+PATH, cli_del_path);
714 add_handler(ADD+MAP, cli_add_map);
715 add_handler(DEL+MAP, cli_del_map);
716 add_handler(SWITCH+MAP+GROUP, cli_switch_group);
717 add_handler(RECONFIGURE, cli_reconfigure);
718 add_handler(SUSPEND+MAP, cli_suspend);
719 add_handler(RESUME+MAP, cli_resume);
720 add_handler(REINSTATE+PATH, cli_reinstate);
721 add_handler(FAIL+PATH, cli_fail);
723 uxsock_listen(&uxsock_trigger, ap);
729 exit_daemon (int status)
732 fprintf(stderr, "bad exit status. see daemon.log\n");
734 condlog(3, "unlink pidfile");
735 unlink(DEFAULT_PIDFILE);
738 pthread_cond_signal(&exit_cond);
745 fail_path (struct path * pp, int del_active)
750 condlog(2, "checker failed path %s in map %s",
751 pp->dev_t, pp->mpp->alias);
753 dm_fail_path(pp->mpp->alias, pp->dev_t);
755 update_queue_mode_del_path(pp->mpp);
759 * caller must have locked the path list before calling that function
762 reinstate_path (struct path * pp, int add_active)
767 if (dm_reinstate_path(pp->mpp->alias, pp->dev_t))
768 condlog(0, "%s: reinstate failed", pp->dev_t);
770 condlog(2, "%s: reinstated", pp->dev_t);
772 update_queue_mode_add_path(pp->mpp);
777 enable_group(struct path * pp)
779 struct pathgroup * pgp;
782 * if path is added through uev_add_path, pgindex can be unset.
783 * next update_strings() will set it, upon map reload event.
785 * we can safely return here, because upon map reload, all
786 * PG will be enabled.
788 if (!pp->mpp->pg || !pp->pgindex)
791 pgp = VECTOR_SLOT(pp->mpp->pg, pp->pgindex - 1);
793 if (pgp->status == PGSTATE_DISABLED) {
794 condlog(2, "%s: enable group #%i", pp->mpp->alias, pp->pgindex);
795 dm_enablegroup(pp->mpp->alias, pp->pgindex);
800 mpvec_garbage_collector (struct vectors * vecs)
802 struct multipath * mpp;
805 vector_foreach_slot (vecs->mpvec, mpp, i) {
806 if (mpp && mpp->alias && !dm_map_present(mpp->alias)) {
807 condlog(2, "%s: remove dead map", mpp->alias);
808 remove_map(mpp, vecs, stop_waiter_thread, 1);
815 defered_failback_tick (vector mpvec)
817 struct multipath * mpp;
820 vector_foreach_slot (mpvec, mpp, i) {
822 * defered failback getting sooner
824 if (mpp->pgfailback > 0 && mpp->failback_tick > 0) {
825 mpp->failback_tick--;
827 if (!mpp->failback_tick && need_switch_pathgroup(mpp, 1))
828 switch_pathgroup(mpp);
834 retry_count_tick(vector mpvec)
836 struct multipath *mpp;
839 vector_foreach_slot (mpvec, mpp, i) {
840 if (mpp->retry_tick) {
841 mpp->stat_total_queueing_time++;
842 condlog(4, "%s: Retrying.. No active path", mpp->alias);
843 if(--mpp->retry_tick == 0) {
844 dm_queue_if_no_path(mpp->alias, 0);
845 condlog(2, "%s: Disable queueing", mpp->alias);
852 checkerloop (void *ap)
854 struct vectors *vecs;
859 mlockall(MCL_CURRENT | MCL_FUTURE);
860 vecs = (struct vectors *)ap;
861 condlog(2, "path checkers start up");
864 * init the path check interval
866 vector_foreach_slot (vecs->pathvec, pp, i) {
867 pp->checkint = conf->checkint;
871 pthread_cleanup_push(cleanup_lock, vecs->lock);
875 vector_foreach_slot (vecs->pathvec, pp, i) {
879 if (pp->tick && --pp->tick)
880 continue; /* don't check this path yet */
883 * provision a next check soonest,
884 * in case we exit abnormaly from here
886 pp->tick = conf->checkint;
888 if (!checker_selected(&pp->checker)) {
889 pathinfo(pp, conf->hwtable, DI_SYSFS);
893 if (!checker_selected(&pp->checker)) {
894 condlog(0, "%s: checker is not set", pp->dev);
897 newstate = checker_check(&pp->checker);
900 condlog(2, "%s: unusable path", pp->dev);
901 pathinfo(pp, conf->hwtable, 0);
905 if (newstate != pp->state) {
906 int oldstate = pp->state;
907 pp->state = newstate;
908 LOG_MSG(1, checker_message(&pp->checker));
911 * upon state change, reset the checkint
912 * to the shortest delay
914 pp->checkint = conf->checkint;
916 if (newstate == PATH_DOWN ||
917 newstate == PATH_SHAKY ||
918 update_multipath_strings(pp->mpp,
921 * proactively fail path in the DM
923 if (oldstate == PATH_UP ||
924 oldstate == PATH_GHOST)
930 * cancel scheduled failback
932 pp->mpp->failback_tick = 0;
934 pp->mpp->stat_path_failures++;
939 * reinstate this path
941 if (oldstate != PATH_UP &&
942 oldstate != PATH_GHOST)
943 reinstate_path(pp, 1);
945 reinstate_path(pp, 0);
948 * schedule [defered] failback
950 if (pp->mpp->pgfailback > 0)
951 pp->mpp->failback_tick =
952 pp->mpp->pgfailback + 1;
953 else if (pp->mpp->pgfailback == -FAILBACK_IMMEDIATE &&
954 need_switch_pathgroup(pp->mpp, 1))
955 switch_pathgroup(pp->mpp);
958 * if at least one path is up in a group, and
959 * the group is disabled, re-enable it
961 if (newstate == PATH_UP)
964 else if (newstate == PATH_UP || newstate == PATH_GHOST) {
965 LOG_MSG(4, checker_message(&pp->checker));
967 * double the next check delay.
968 * max at conf->max_checkint
970 if (pp->checkint < (conf->max_checkint / 2))
971 pp->checkint = 2 * pp->checkint;
973 pp->checkint = conf->max_checkint;
975 pp->tick = pp->checkint;
976 condlog(4, "%s: delay next check %is",
977 pp->dev_t, pp->tick);
979 else if (newstate == PATH_DOWN)
980 LOG_MSG(2, checker_message(&pp->checker));
982 pp->state = newstate;
985 * path prio refreshing
987 condlog(4, "path prio refresh");
988 pathinfo(pp, conf->hwtable, DI_PRIO);
990 if (need_switch_pathgroup(pp->mpp, 0)) {
991 if (pp->mpp->pgfailback > 0 &&
992 pp->mpp->failback_tick <= 0)
993 pp->mpp->failback_tick =
994 pp->mpp->pgfailback + 1;
995 else if (pp->mpp->pgfailback ==
997 switch_pathgroup(pp->mpp);
1000 defered_failback_tick(vecs->mpvec);
1001 retry_count_tick(vecs->mpvec);
1006 condlog(4, "map garbage collection");
1007 mpvec_garbage_collector(vecs);
1011 lock_cleanup_pop(vecs->lock);
1018 configure (struct vectors * vecs, int start_waiters)
1020 struct multipath * mpp;
1025 if (!(vecs->pathvec = vector_alloc()))
1028 if (!(vecs->mpvec = vector_alloc()))
1031 if (!(mpvec = vector_alloc()))
1035 * probe for current path (from sysfs) and map (from dm) sets
1037 path_discovery(vecs->pathvec, conf, DI_ALL);
1039 vector_foreach_slot (vecs->pathvec, pp, i){
1040 if (blacklist_path(conf, pp)){
1041 vector_del_slot(vecs->pathvec, i);
1046 pp->checkint = conf->checkint;
1048 if (map_discovery(vecs))
1052 * create new set of maps & push changed ones into dm
1054 if (coalesce_paths(vecs, mpvec, NULL))
1058 * may need to remove some maps which are no longer relevant
1059 * e.g., due to blacklist changes in conf file
1061 if (coalesce_maps(vecs, mpvec))
1066 sync_maps_state(mpvec);
1068 if (conf->verbosity > 2)
1069 vector_foreach_slot(mpvec, mpp, i)
1073 * purge dm of old maps
1075 remove_maps(vecs, NULL);
1078 * save new set of maps formed by considering current path state
1080 vecs->mpvec = mpvec;
1083 * start dm event waiter threads for these new maps
1085 vector_foreach_slot(vecs->mpvec, mpp, i) {
1086 if (setup_multipath(vecs, mpp))
1089 if (start_waiter_thread(mpp, vecs))
1096 reconfigure (struct vectors * vecs)
1098 struct config * old = conf;
1101 * free old map and path vectors ... they use old conf state
1103 if (VECTOR_SIZE(vecs->mpvec))
1104 remove_maps(vecs, stop_waiter_thread);
1106 if (VECTOR_SIZE(vecs->pathvec))
1107 free_pathvec(vecs->pathvec, FREE_PATHS);
1111 if (load_config(DEFAULT_CONFIGFILE))
1114 conf->verbosity = old->verbosity;
1116 if (!conf->checkint) {
1117 conf->checkint = DEFAULT_CHECKINT;
1118 conf->max_checkint = MAX_CHECKINT(conf->checkint);
1125 static struct vectors *
1128 struct vectors * vecs;
1130 vecs = (struct vectors *)MALLOC(sizeof(struct vectors));
1136 (pthread_mutex_t *)MALLOC(sizeof(pthread_mutex_t));
1141 vecs->pathvec = vector_alloc();
1146 vecs->mpvec = vector_alloc();
1151 pthread_mutex_init(vecs->lock, NULL);
1156 vector_free(vecs->pathvec);
1161 condlog(0, "failed to init paths");
1166 signal_set(int signo, void (*func) (int))
1169 struct sigaction sig;
1170 struct sigaction osig;
1172 sig.sa_handler = func;
1173 sigemptyset(&sig.sa_mask);
1176 r = sigaction(signo, &sig, &osig);
1181 return (osig.sa_handler);
1187 condlog(2, "reconfigure (SIGHUP)");
1191 unlock(gvecs->lock);
1194 dbg_free_final(NULL);
1207 condlog(3, "SIGUSR1 received");
1213 signal_set(SIGHUP, sighup);
1214 signal_set(SIGUSR1, sigusr1);
1215 signal_set(SIGINT, sigend);
1216 signal_set(SIGTERM, sigend);
1217 signal_set(SIGKILL, sigend);
1224 static struct sched_param sched_param = {
1228 res = sched_setscheduler (0, SCHED_RR, &sched_param);
1231 condlog(LOG_WARNING, "Could not set SCHED_RR at priority 99");
1236 set_oom_adj (int val)
1240 fp = fopen("/proc/self/oom_adj", "w");
1245 fprintf(fp, "%i", val);
1250 child (void * param)
1252 pthread_t check_thr, uevent_thr, uxlsnr_thr;
1253 pthread_attr_t attr;
1254 struct vectors * vecs;
1256 mlockall(MCL_CURRENT | MCL_FUTURE);
1261 condlog(2, "--------start up--------");
1262 condlog(2, "read " DEFAULT_CONFIGFILE);
1264 if (load_config(DEFAULT_CONFIGFILE))
1267 setlogmask(LOG_UPTO(conf->verbosity + 3));
1270 * fill the voids left in the config file
1272 if (!conf->checkint) {
1273 conf->checkint = DEFAULT_CHECKINT;
1274 conf->max_checkint = MAX_CHECKINT(conf->checkint);
1277 if (pidfile_create(DEFAULT_PIDFILE, getpid())) {
1286 vecs = gvecs = init_vecs();
1291 if (sysfs_get_mnt_path(sysfs_path, FILE_NAME_SIZE)) {
1292 condlog(0, "can not find sysfs mount point");
1297 * fetch and configure both paths and multipaths
1299 if (configure(vecs, 1)) {
1300 condlog(0, "failure during configuration");
1307 pthread_attr_init(&attr);
1308 pthread_attr_setstacksize(&attr, 64 * 1024);
1309 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
1311 pthread_create(&check_thr, &attr, checkerloop, vecs);
1312 pthread_create(&uevent_thr, &attr, ueventloop, vecs);
1313 pthread_create(&uxlsnr_thr, &attr, uxlsnrloop, vecs);
1315 pthread_cond_wait(&exit_cond, &exit_mutex);
1321 remove_maps(vecs, stop_waiter_thread);
1322 free_pathvec(vecs->pathvec, FREE_PATHS);
1324 pthread_cancel(check_thr);
1325 pthread_cancel(uevent_thr);
1326 pthread_cancel(uxlsnr_thr);
1330 free_handlers(handlers);
1335 pthread_mutex_destroy(vecs->lock);
1343 condlog(2, "--------shut down-------");
1352 dbg_free_final(NULL);
1364 if( (pid = fork()) < 0){
1365 fprintf(stderr, "Failed first fork : %s\n", strerror(errno));
1373 if ( (pid = fork()) < 0)
1374 fprintf(stderr, "Failed second fork : %s\n", strerror(errno));
1378 in_fd = open("/dev/null", O_RDONLY);
1380 fprintf(stderr, "cannot open /dev/null for input : %s\n",
1384 out_fd = open("/dev/console", O_WRONLY);
1386 fprintf(stderr, "cannot open /dev/console for output : %s\n",
1391 close(STDIN_FILENO);
1393 close(STDOUT_FILENO);
1395 close(STDERR_FILENO);
1406 main (int argc, char *argv[])
1408 extern char *optarg;
1415 if (getuid() != 0) {
1416 fprintf(stderr, "need to be root\n");
1420 /* make sure we don't lock any path */
1422 umask(umask(077) | 022);
1424 conf = alloc_config();
1429 while ((arg = getopt(argc, argv, ":dv:k::")) != EOF ) {
1433 //debug=1; /* ### comment me out ### */
1436 if (sizeof(optarg) > sizeof(char *) ||
1437 !isdigit(optarg[0]))
1440 conf->verbosity = atoi(optarg);
1463 return (child(NULL));