Remove DAEMON defines
authorHannes Reinecke <hare@suse.de>
Wed, 30 Apr 2008 09:04:50 +0000 (11:04 +0200)
committerChristophe Varoqui <christophe.varoqui@free.fr>
Wed, 30 Apr 2008 11:25:15 +0000 (13:25 +0200)
We're now building just one shared library for both programs,
multipath and multipathd. So any DAEMON defines are quite
pointless.
Remove them and use 'mpp->waiter == NULL' to distinguish between
multipath and multipathd where required.

Signed-off-by: Hannes Reinecke <hare@suse.de>
15 files changed:
libmultipath/Makefile
libmultipath/configure.c
libmultipath/debug.c
libmultipath/debug.h
libmultipath/devmapper.c
libmultipath/discovery.c
libmultipath/dmparser.c
libmultipath/structs.c
libmultipath/structs_vec.c
libmultipath/structs_vec.h
libmultipath/uxsock.c
libmultipath/waiter.h
multipath/main.c
multipathd/Makefile
multipathd/main.c

index 18241a2..05bcc37 100644 (file)
@@ -11,12 +11,8 @@ OBJS = memory.o parser.o vector.o devmapper.o callout.o \
        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)
 
index df31cdd..d9fa397 100644 (file)
@@ -367,19 +367,21 @@ domap (struct multipath * mpp)
                 * 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;
index 05dfb06..d30517d 100644 (file)
@@ -5,11 +5,9 @@
 #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"
@@ -23,12 +21,11 @@ void dlog (int sink, int prio, const char * fmt, ...)
        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';
 
@@ -37,9 +34,6 @@ void dlog (int sink, int prio, const char * fmt, ...)
                }
                else
                        log_safe(prio + 3, fmt, ap);
-#else
-               vfprintf(stdout, fmt, ap);
-#endif
        }
        va_end(ap);
 }
index 082fff1..c6120c1 100644 (file)
@@ -1,21 +1,13 @@
 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 */
index f21d3ab..cc01486 100644 (file)
 #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
@@ -47,8 +45,7 @@ dm_write_log (int level, const char *file, int line, const char *f, ...)
        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);
@@ -65,12 +62,7 @@ dm_write_log (int level, const char *file, int line, const char *f, ...)
                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;
 }
index 8cfb53f..7baa9e7 100644 (file)
@@ -716,10 +716,6 @@ pathinfo (struct path *pp, vector hwtable, int mask)
        if (mask & DI_WWID && !strlen(pp->wwid))
                get_uid(pp);
 
-#ifndef DAEMON
-       close(pp->fd);
-       pp->fd = -1;
-#endif
        return 0;
 
 blank:
@@ -728,11 +724,6 @@ 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;
 }
index fe7d986..df7a0c3 100644 (file)
@@ -277,10 +277,9 @@ disassemble_map (vector pathvec, char * params, struct multipath * mpp)
 
                                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);
 
index 11f3061..082d53f 100644 (file)
@@ -170,14 +170,12 @@ free_multipath (struct multipath * mpp, int free_paths)
 
        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);
index f4d69bb..6757eb9 100644 (file)
@@ -62,7 +62,7 @@ adopt_paths (vector pathvec, struct multipath * mpp)
                        condlog(3, "%s: ownership set to %s",
                                pp->dev, mpp->alias);
                        pp->mpp = mpp;
-                       
+
                        if (!mpp->paths && !(mpp->paths = vector_alloc()))
                                return 1;
 
@@ -294,18 +294,17 @@ retry:
                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);
@@ -341,7 +340,7 @@ add_map_without_path (struct vectors * vecs,
 
        if (adopt_paths(vecs->pathvec, mpp))
                goto out;
-       
+
        if (!vector_alloc_slot(vecs->mpvec))
                goto out;
 
index b8a416f..19a2387 100644 (file)
@@ -2,9 +2,7 @@
 #define _STRUCTS_VEC_H
 
 struct vectors {
-#if DAEMON
        pthread_mutex_t *lock;
-#endif
        vector pathvec;
        vector mpvec;
 };
index 7f3530d..a070943 100644 (file)
@@ -129,23 +129,21 @@ size_t read_all(int fd, void *buf, size_t len)
 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;
 }
 
index 0223924..468ce5f 100644 (file)
@@ -1,8 +1,6 @@
 #ifndef _WAITER_H
 #define _WAITER_H
 
-#if DAEMON
-
 struct event_thread {
        struct dm_task *dmt;
        pthread_t thread;
@@ -19,5 +17,4 @@ int start_waiter_thread (struct multipath *mpp, struct vectors *vecs);
 int waiteventloop (struct event_thread *waiter);
 void *waitevent (void *et);
 
-#endif /* DAEMON */
 #endif /* _WAITER_H */
index c554ca3..f1ac256 100644 (file)
@@ -49,6 +49,8 @@
 #include <pgpolicies.h>
 #include <version.h>
 
+int logsink;
+
 static int
 filter_pathvec (vector pathvec, char * refwwid)
 {
index 6beb993..dd223c4 100644 (file)
@@ -5,7 +5,7 @@ include ../Makefile.inc
 #
 # 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)
 
index eb7ba14..ac9cd36 100644 (file)
@@ -65,6 +65,8 @@
 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
  */