structs.o discovery.o propsel.o dict.o \
pgpolicies.o debug.o regex.o defaults.o uevent.o \
switchgroup.o uxsock.o print.o alias.o log_pthread.o \
- log.o configure.o structs_vec.o sysfs.o prio.o checkers.o
-
-#ifeq ($(strip $(DAEMON)),1)
- OBJS += lock.o waiter.o
- CFLAGS += -DDAEMON
-#endif
+ log.o configure.o structs_vec.o sysfs.o prio.o checkers.o \
+ lock.o waiter.o
LIBDM_API_FLUSH = $(shell if test -d /lib64 ; then objdump -T /lib64/libdevmapper.so* ; else objdump -T /lib/libdevmapper.so.* ; fi | grep -c dm_task_no_flush)
* DM_DEVICE_CREATE, DM_DEVICE_RENAME, or DM_DEVICE_RELOAD
* succeeded
*/
-#ifndef DAEMON
- dm_switchgroup(mpp->alias, mpp->bestpg);
- if (mpp->action != ACT_NOTHING)
- print_multipath_topology(mpp, conf->verbosity);
-#else
- mpp->stat_map_loads++;
- condlog(2, "%s: load table [0 %llu %s %s]", mpp->alias,
- mpp->size, DEFAULT_TARGET, mpp->params);
- /*
- * Required action is over, reset for the stateful daemon
- */
- mpp->action = ACT_NOTHING;
-#endif
+ if (!mpp->waiter) {
+ /* multipath client mode */
+ dm_switchgroup(mpp->alias, mpp->bestpg);
+ if (mpp->action != ACT_NOTHING)
+ print_multipath_topology(mpp, conf->verbosity);
+ } else {
+ /* multipath daemon mode */
+ mpp->stat_map_loads++;
+ condlog(2, "%s: load table [0 %llu %s %s]", mpp->alias,
+ mpp->size, DEFAULT_TARGET, mpp->params);
+ /*
+ * Required action is over, reset for the stateful daemon
+ */
+ mpp->action = ACT_NOTHING;
+ }
return DOMAP_OK;
}
return DOMAP_FAIL;
#include <stdlib.h>
#include <stdarg.h>
-#if DAEMON
#include "log_pthread.h"
#include <sys/types.h>
#include <time.h>
-#endif
#include "vector.h"
#include "config.h"
thres = (conf) ? conf->verbosity : 0;
if (prio <= thres) {
-#if DAEMON
if (!sink) {
time_t t = time(NULL);
struct tm *tb = localtime(&t);
char buff[16];
-
+
strftime(buff, sizeof(buff), "%b %d %H:%M:%S", tb);
buff[sizeof(buff)-1] = '\0';
}
else
log_safe(prio + 3, fmt, ap);
-#else
- vfprintf(stdout, fmt, ap);
-#endif
}
va_end(ap);
}
void dlog (int sink, int prio, const char * fmt, ...)
__attribute__((format(printf, 3, 4)));
-#if DAEMON
#include <pthread.h>
#include <stdarg.h>
#include "log_pthread.h"
-int logsink;
+extern int logsink;
#define condlog(prio, fmt, args...) \
dlog(logsink, prio, fmt "\n", ##args)
-
-#else /* DAEMON */
-
-#define condlog(prio, fmt, args...) \
- dlog(0, prio, fmt "\n", ##args)
-
-#endif /* DAEMON */
#include "devmapper.h"
#include "config.h"
-#if DAEMON
#include "log_pthread.h"
#include <sys/types.h>
#include <time.h>
-#endif
#define MAX_WAIT 5
#define LOOPS_PER_SEC 5
if (thres <= 3 || level > thres)
return;
- va_start(ap, f);
-#if DAEMON
+ va_start(ap, f);
if (!logsink) {
time_t t = time(NULL);
struct tm *tb = localtime(&t);
condlog(level, "libdevmapper: %s(%i): ", file, line);
log_safe(level + 3, f, ap);
}
-#else
- fprintf(stdout, "libdevmapper: %s(%i): ", file, line);
- vfprintf(stdout, f, ap);
- fprintf(stdout, "\n");
-#endif
- va_end(ap);
+ va_end(ap);
return;
}
if (mask & DI_WWID && !strlen(pp->wwid))
get_uid(pp);
-#ifndef DAEMON
- close(pp->fd);
- pp->fd = -1;
-#endif
return 0;
blank:
*/
memset(pp->wwid, 0, WWID_SIZE);
pp->state = PATH_DOWN;
-#ifndef DAEMON
- if (pp->fd > 0){
- close(pp->fd);
- pp->fd = -1;
- }
-#endif
+
return 0;
}
strncpy(pp->dev_t, word, BLK_DEV_SIZE);
-#ifndef DAEMON
- if (store_path(pathvec, pp))
+ /* Only call this in multipath client mode */
+ if (!mpp->waiter && store_path(pathvec, pp))
goto out;
-#endif
}
FREE(word);
if (mpp->dmi)
FREE(mpp->dmi);
-
-#if DAEMON
+
/*
* better own vecs->lock here
*/
if (mpp->waiter)
((struct event_thread *)mpp->waiter)->mpp = NULL;
-#endif
free_pathvec(mpp->paths, free_paths);
free_pgvec(mpp->pg, free_paths);
condlog(3, "%s: ownership set to %s",
pp->dev, mpp->alias);
pp->mpp = mpp;
-
+
if (!mpp->paths && !(mpp->paths = vector_alloc()))
return 1;
char new_alias[WWID_SIZE];
/*
- * detect an external rename of the multipath device
+ * detect an external rename of the multipath device
*/
if (dm_get_name(mpp->wwid, DEFAULT_TARGET, new_alias)) {
condlog(3, "%s multipath mapped device name has "
"changed from %s to %s", mpp->wwid,
mpp->alias, new_alias);
strcpy(mpp->alias, new_alias);
-#if DAEMON
- if (mpp->waiter)
+
+ if (mpp->waiter)
strncpy(((struct event_thread *)mpp->waiter)->mapname,
new_alias, WWID_SIZE);
-#endif
goto retry;
}
condlog(0, "%s: failed to setup multipath", mpp->alias);
if (adopt_paths(vecs->pathvec, mpp))
goto out;
-
+
if (!vector_alloc_slot(vecs->mpvec))
goto out;
#define _STRUCTS_VEC_H
struct vectors {
-#if DAEMON
pthread_mutex_t *lock;
-#endif
vector pathvec;
vector mpvec;
};
int send_packet(int fd, const char *buf, size_t len)
{
int ret = 0;
-#ifdef DAEMON
sigset_t set, old;
/* Block SIGPIPE */
sigemptyset(&set);
sigaddset(&set, SIGPIPE);
pthread_sigmask(SIG_BLOCK, &set, &old);
-#endif
+
if (write_all(fd, &len, sizeof(len)) != sizeof(len))
ret = -1;
if (!ret && write_all(fd, buf, len) != len)
ret = -1;
-#ifdef DAEMON
/* And unblock it again */
pthread_sigmask(SIG_SETMASK, &old, NULL);
-#endif
+
return ret;
}
#ifndef _WAITER_H
#define _WAITER_H
-#if DAEMON
-
struct event_thread {
struct dm_task *dmt;
pthread_t thread;
int waiteventloop (struct event_thread *waiter);
void *waitevent (void *et);
-#endif /* DAEMON */
#endif /* _WAITER_H */
#include <pgpolicies.h>
#include <version.h>
+int logsink;
+
static int
filter_pathvec (vector pathvec, char * refwwid)
{
#
# basic flags setting
#
-CFLAGS += -DDAEMON -I$(multipathdir) -Wl,-rpath,$(libdir)
+CFLAGS += -I$(multipathdir) -Wl,-rpath,$(libdir)
LDFLAGS += -lpthread -ldevmapper -lreadline -lncurses -laio \
-lmultipath -L$(multipathdir)
pthread_cond_t exit_cond = PTHREAD_COND_INITIALIZER;
pthread_mutex_t exit_mutex = PTHREAD_MUTEX_INITIALIZER;
+int logsink;
+
/*
* global copy of vecs for use in sig handlers
*/