[sheepdog] [PATCH v2] logger: clean printf styled log functions

Hitoshi Mitake h.mitake at gmail.com
Wed Jan 23 17:05:01 CET 2013


From: Hitoshi Mitake <mitake.hitoshi at lab.ntt.co.jp>

Current sheep employes names "dprintf" and "vprintf" for its internal
logging usage. Unfortunately glibc provides functions which have same
names.

This patch clean these old functions and prepare new functions as
alternatives. New functions are:

sd_printf(): A simple wrapper for log_write(). Caller has to pass log
	     level as its first parameter.
sd_dprintf(): call log_write() with SDOG_DEBUG
sd_eprintf(): call log_write() with SDOG_ERR
sd_iprintf(): call log_write() with SDOG_INFO

Signed-off-by: Hitoshi Mitake <mitake.hitoshi at lab.ntt.co.jp>
---
v2: git am problem is solved, I believe.
8<---
 include/logger.h          |   39 +++++++++--------
 lib/event.c               |   18 ++++----
 lib/logger.c              |    6 +-
 lib/net.c                 |   64 ++++++++++++++--------------
 lib/util.c                |    6 +-
 sheep/cluster/accord.c    |   21 +++++-----
 sheep/cluster/corosync.c  |   48 +++++++++++----------
 sheep/cluster/local.c     |   33 ++++++++-------
 sheep/cluster/zookeeper.c |   64 +++++++++++++++--------------
 sheep/config.c            |   20 +++++-----
 sheep/farm/farm.c         |   32 +++++++-------
 sheep/farm/sha1_file.c    |   16 ++++----
 sheep/farm/snap.c         |   11 +++--
 sheep/farm/trunk.c        |   10 ++--
 sheep/gateway.c           |   20 +++++-----
 sheep/group.c             |   76 +++++++++++++++++-----------------
 sheep/journal.c           |   32 +++++++-------
 sheep/journal_file.c      |   26 ++++++------
 sheep/migrate.c           |   33 ++++++++-------
 sheep/object_cache.c      |   99 +++++++++++++++++++++++---------------------
 sheep/object_list_cache.c |   10 ++--
 sheep/ops.c               |   34 ++++++++--------
 sheep/plain_store.c       |   72 +++++++++++++++++---------------
 sheep/recovery.c          |   54 ++++++++++++------------
 sheep/request.c           |   52 ++++++++++++------------
 sheep/sheep.c             |   19 +++++----
 sheep/sockfd_cache.c      |   34 ++++++++--------
 sheep/store.c             |   44 ++++++++++---------
 sheep/trace/trace.c       |   28 ++++++------
 sheep/vdi.c               |   66 +++++++++++++++--------------
 sheep/work.c              |    8 ++--
 31 files changed, 562 insertions(+), 533 deletions(-)

diff --git a/include/logger.h b/include/logger.h
index cd46890..a2e8c3c 100644
--- a/include/logger.h
+++ b/include/logger.h
@@ -41,27 +41,30 @@ extern void get_thread_name(char *name);
 #define	SDOG_INFO		LOG_INFO
 #define	SDOG_DEBUG		LOG_DEBUG
 
-#define vprintf(level, fmt, args...)						\
-do {									\
-	log_write(level, __func__, __LINE__, fmt, ##args);		\
-} while (0)
+#define sd_printf(level, fmt, args...)					\
+	do {								\
+		log_write(level, __func__, __LINE__, fmt, ##args);	\
+	} while (0)
 
-#define panic(fmt, args...)			\
-({						\
-	vprintf(SDOG_EMERG, "PANIC: " fmt, ##args);	\
-	abort();				\
-})
+#define panic(fmt, args...)					\
+	({							\
+		sd_printf(SDOG_EMERG, "PANIC: " fmt, ##args);	\
+		abort();					\
+	})
 
-/* don't use the following obsolete functions. use vprintf instead. */
+#define sd_iprintf(fmt, args...)					\
+	do {								\
+		log_write(SDOG_INFO, __func__, __LINE__, fmt, ##args);	\
+	} while (0)
 
-#define eprintf(fmt, args...)						\
-do {									\
-	log_write(LOG_ERR, __func__, __LINE__, fmt, ##args);		\
-} while (0)
+#define sd_eprintf(fmt, args...)					\
+	do {								\
+		log_write(SDOG_ERR, __func__, __LINE__, fmt, ##args);	\
+	} while (0)
 
-#define dprintf(fmt, args...)						\
-do {									\
-	log_write(LOG_DEBUG, __func__, __LINE__, fmt, ##args);		\
-} while (0)
+#define sd_dprintf(fmt, args...)					\
+	do {								\
+		log_write(SDOG_DEBUG, __func__, __LINE__, fmt, ##args);	\
+	} while (0)
 
 #endif	/* LOG_H */
diff --git a/lib/event.c b/lib/event.c
index 6b00e06..a5b1eca 100644
--- a/lib/event.c
+++ b/lib/event.c
@@ -47,7 +47,7 @@ void add_timer(struct timer *t, unsigned int mseconds)
 
 	tfd = timerfd_create(CLOCK_MONOTONIC, TFD_NONBLOCK);
 	if (tfd < 0) {
-		eprintf("timerfd_create: %m\n");
+		sd_eprintf("timerfd_create: %m\n");
 		return;
 	}
 
@@ -56,12 +56,12 @@ void add_timer(struct timer *t, unsigned int mseconds)
 	it.it_value.tv_nsec = (mseconds % 1000) * 1000000;
 
 	if (timerfd_settime(tfd, 0, &it, NULL) < 0) {
-		eprintf("timerfd_settime: %m\n");
+		sd_eprintf("timerfd_settime: %m\n");
 		return;
 	}
 
 	if (register_event(tfd, timer_handler, t) < 0)
-		eprintf("failed to register timer fd\n");
+		sd_eprintf("failed to register timer fd\n");
 }
 
 struct event_info {
@@ -75,7 +75,7 @@ int init_event(int nr)
 {
 	efd = epoll_create(nr);
 	if (efd < 0) {
-		eprintf("failed to create epoll fd\n");
+		sd_eprintf("failed to create epoll fd\n");
 		return -1;
 	}
 	return 0;
@@ -112,7 +112,7 @@ int register_event(int fd, event_handler_t h, void *data)
 
 	ret = epoll_ctl(efd, EPOLL_CTL_ADD, fd, &ev);
 	if (ret) {
-		eprintf("failed to add epoll event: %m\n");
+		sd_eprintf("failed to add epoll event: %m\n");
 		free(ei);
 	} else
 		list_add(&ei->ei_list, &events_list);
@@ -131,7 +131,7 @@ void unregister_event(int fd)
 
 	ret = epoll_ctl(efd, EPOLL_CTL_DEL, fd, NULL);
 	if (ret)
-		eprintf("failed to delete epoll event for fd %d: %m\n", fd);
+		sd_eprintf("failed to delete epoll event for fd %d: %m\n", fd);
 
 	list_del(&ei->ei_list);
 	free(ei);
@@ -145,7 +145,7 @@ int modify_event(int fd, unsigned int events)
 
 	ei = lookup_event(fd);
 	if (!ei) {
-		eprintf("event info for fd %d not found\n", fd);
+		sd_eprintf("event info for fd %d not found\n", fd);
 		return 1;
 	}
 
@@ -155,7 +155,7 @@ int modify_event(int fd, unsigned int events)
 
 	ret = epoll_ctl(efd, EPOLL_CTL_MOD, fd, &ev);
 	if (ret) {
-		eprintf("failed to delete epoll event for fd %d: %m\n", fd);
+		sd_eprintf("failed to delete epoll event for fd %d: %m\n", fd);
 		return 1;
 	}
 	return 0;
@@ -170,7 +170,7 @@ void event_loop(int timeout)
 	if (nr < 0) {
 		if (errno == EINTR)
 			return;
-		eprintf("epoll_wait failed: %m\n");
+		sd_eprintf("epoll_wait failed: %m\n");
 		exit(1);
 	} else if (nr) {
 		for (i = 0; i < nr; i++) {
diff --git a/lib/logger.c b/lib/logger.c
index 9c12bb0..40f06bd 100644
--- a/lib/logger.c
+++ b/lib/logger.c
@@ -315,13 +315,13 @@ static notrace void log_flush(void)
 static notrace void crash_handler(int signo)
 {
 	if (signo == SIGSEGV) {
-		vprintf(SDOG_ERR, "logger pid %d segfaulted.\n",
+		sd_printf(SDOG_ERR, "logger pid %d segfaulted.\n",
 			getpid());
 	} else if (signo == SIGHUP) {
-		vprintf(SDOG_ERR, "sheep pid %d exited unexpectedly.\n",
+		sd_printf(SDOG_ERR, "sheep pid %d exited unexpectedly.\n",
 			sheep_pid);
 	} else {
-		vprintf(SDOG_ERR, "logger pid %d got unexpected signal %d.\n",
+		sd_printf(SDOG_ERR, "logger pid %d got unexpected signal %d.\n",
 			getpid(), signo);
 	}
 
diff --git a/lib/net.c b/lib/net.c
index 76b6eab..596f9a9 100644
--- a/lib/net.c
+++ b/lib/net.c
@@ -25,7 +25,6 @@
 #include <sys/un.h>
 #include <sys/stat.h>
 #include <sys/types.h>
-
 #include "sheepdog_proto.h"
 #include "sheep.h"
 #include "util.h"
@@ -131,7 +130,7 @@ int create_listen_ports(const char *bindaddr, int port,
 
 	ret = getaddrinfo(bindaddr, servname, &hints, &res0);
 	if (ret) {
-		eprintf("failed to get address info: %m\n");
+		sd_eprintf("failed to get address info: %m\n");
 		return 1;
 	}
 
@@ -144,7 +143,7 @@ int create_listen_ports(const char *bindaddr, int port,
 		ret = setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &opt,
 				 sizeof(opt));
 		if (ret)
-			eprintf("failed to set SO_REUSEADDR: %m\n");
+			sd_eprintf("failed to set SO_REUSEADDR: %m\n");
 
 		opt = 1;
 		if (res->ai_family == AF_INET6) {
@@ -158,14 +157,14 @@ int create_listen_ports(const char *bindaddr, int port,
 
 		ret = bind(fd, res->ai_addr, res->ai_addrlen);
 		if (ret) {
-			eprintf("failed to bind server socket: %m\n");
+			sd_eprintf("failed to bind server socket: %m\n");
 			close(fd);
 			continue;
 		}
 
 		ret = listen(fd, SOMAXCONN);
 		if (ret) {
-			eprintf("failed to listen on server socket: %m\n");
+			sd_eprintf("failed to listen on server socket: %m\n");
 			close(fd);
 			continue;
 		}
@@ -188,7 +187,7 @@ int create_listen_ports(const char *bindaddr, int port,
 	freeaddrinfo(res0);
 
 	if (!success)
-		eprintf("failed to create a listening port\n");
+		sd_eprintf("failed to create a listening port\n");
 
 	return !success;
 }
@@ -208,7 +207,7 @@ int connect_to(const char *name, int port)
 
 	ret = getaddrinfo(name, buf, &hints, &res0);
 	if (ret) {
-		eprintf("failed to get address info: %m\n");
+		sd_eprintf("failed to get address info: %m\n");
 		return -1;
 	}
 
@@ -226,28 +225,28 @@ int connect_to(const char *name, int port)
 		ret = setsockopt(fd, SOL_SOCKET, SO_LINGER, &linger_opt,
 				 sizeof(linger_opt));
 		if (ret) {
-			eprintf("failed to set SO_LINGER: %m\n");
+			sd_eprintf("failed to set SO_LINGER: %m\n");
 			close(fd);
 			continue;
 		}
 
 		ret = set_snd_timeout(fd);
 		if (ret) {
-			eprintf("failed to set send timeout: %m\n");
+			sd_eprintf("failed to set send timeout: %m\n");
 			close(fd);
 			break;
 		}
 
 		ret = set_rcv_timeout(fd);
 		if (ret) {
-			eprintf("failed to set recv timeout: %m\n");
+			sd_eprintf("failed to set recv timeout: %m\n");
 			close(fd);
 			break;
 		}
 
 		ret = connect(fd, res->ai_addr, res->ai_addrlen);
 		if (ret) {
-			eprintf("failed to connect to %s:%d: %m\n",
+			sd_eprintf("failed to connect to %s:%d: %m\n",
 				name, port);
 			close(fd);
 			continue;
@@ -255,7 +254,7 @@ int connect_to(const char *name, int port)
 
 		ret = set_nodelay(fd);
 		if (ret) {
-			eprintf("%m\n");
+			sd_eprintf("%m\n");
 			close(fd);
 			break;
 		} else
@@ -264,7 +263,7 @@ int connect_to(const char *name, int port)
 	fd = -1;
 success:
 	freeaddrinfo(res0);
-	dprintf("%d, %s:%d\n", fd, name, port);
+	sd_dprintf("%d, %s:%d\n", fd, name, port);
 	return fd;
 }
 
@@ -279,7 +278,8 @@ reread:
 		if (retry_eagain && errno == EAGAIN)
 			goto reread;
 
-		eprintf("failed to read from socket: %d, %d(%m)\n", ret, errno);
+		sd_eprintf("failed to read from socket: %d, %d(%m)\n",
+			ret, errno);
 		return 1;
 	}
 
@@ -317,7 +317,7 @@ rewrite:
 	if (ret < 0) {
 		if (errno == EINTR)
 			goto rewrite;
-		eprintf("failed to write to socket: %m\n");
+		sd_eprintf("failed to write to socket: %m\n");
 		return 1;
 	}
 
@@ -352,7 +352,7 @@ int send_req(int sockfd, struct sd_req *hdr, void *data, unsigned int wlen)
 
 	ret = do_write(sockfd, &msg, sizeof(*hdr) + wlen);
 	if (ret) {
-		eprintf("failed to send request %x, %d: %m\n", hdr->opcode,
+		sd_eprintf("failed to send request %x, %d: %m\n", hdr->opcode,
 			wlen);
 		ret = -1;
 	}
@@ -379,7 +379,7 @@ int net_exec_req(int sockfd, struct sd_req *hdr, void *data, bool retry_eagain)
 
 	ret = net_do_read(sockfd, rsp, sizeof(*rsp), retry_eagain);
 	if (ret) {
-		eprintf("failed to read a response\n");
+		sd_eprintf("failed to read a response\n");
 		return 1;
 	}
 
@@ -389,7 +389,7 @@ int net_exec_req(int sockfd, struct sd_req *hdr, void *data, bool retry_eagain)
 	if (rlen) {
 		ret = net_do_read(sockfd, data, rlen, retry_eagain);
 		if (ret) {
-			eprintf("failed to read the response data\n");
+			sd_eprintf("failed to read the response data\n");
 			return 1;
 		}
 	}
@@ -445,12 +445,12 @@ int set_nonblocking(int fd)
 
 	ret = fcntl(fd, F_GETFL);
 	if (ret < 0) {
-		eprintf("fcntl F_GETFL failed: %m\n");
+		sd_eprintf("fcntl F_GETFL failed: %m\n");
 		close(fd);
 	} else {
 		ret = fcntl(fd, F_SETFL, ret | O_NONBLOCK);
 		if (ret < 0)
-			eprintf("fcntl O_NONBLOCK failed: %m\n");
+			sd_eprintf("fcntl O_NONBLOCK failed: %m\n");
 	}
 
 	return ret;
@@ -501,22 +501,22 @@ int set_keepalive(int fd)
 	int val = 1;
 
 	if (setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, &val, sizeof(val)) < 0) {
-		dprintf("%m\n");
+		sd_dprintf("%m\n");
 		return -1;
 	}
 	val = 5;
 	if (setsockopt(fd, SOL_TCP, TCP_KEEPIDLE, &val, sizeof(val)) < 0) {
-		dprintf("%m\n");
+		sd_dprintf("%m\n");
 		return -1;
 	}
 	val = 1;
 	if (setsockopt(fd, SOL_TCP, TCP_KEEPINTVL, &val, sizeof(val)) < 0) {
-		dprintf("%m\n");
+		sd_dprintf("%m\n");
 		return -1;
 	}
 	val = 3;
 	if (setsockopt(fd, SOL_TCP, TCP_KEEPCNT, &val, sizeof(val)) < 0) {
-		dprintf("%m\n");
+		sd_dprintf("%m\n");
 		return -1;
 	}
 	return 0;
@@ -528,7 +528,7 @@ int get_local_addr(uint8_t *bytes)
 	int ret = 0;
 
 	if (getifaddrs(&ifaddr) == -1) {
-		eprintf("getifaddrs failed: %m\n");
+		sd_eprintf("getifaddrs failed: %m\n");
 		return -1;
 	}
 
@@ -548,17 +548,17 @@ int get_local_addr(uint8_t *bytes)
 			memset(bytes, 0, 12);
 			memcpy(bytes + 12, &sin->sin_addr, 4);
 			memcpy(bytes + 12, &sin->sin_addr, 4);
-			eprintf("found IPv4 address\n");
+			sd_eprintf("found IPv4 address\n");
 			goto out;
 		case AF_INET6:
 			sin6 = (struct sockaddr_in6 *)ifa->ifa_addr;
 			memcpy(bytes, &sin6->sin6_addr, 16);
-			eprintf("found IPv6 address\n");
+			sd_eprintf("found IPv6 address\n");
 			goto out;
 		}
 	}
 
-	eprintf("no valid interface found\n");
+	sd_eprintf("no valid interface found\n");
 	ret = -1;
 out:
 	freeifaddrs(ifaddr);
@@ -576,19 +576,19 @@ int create_unix_domain_socket(const char *unix_path,
 
 	fd = socket(addr.sun_family, SOCK_STREAM, 0);
 	if (fd < 0) {
-		eprintf("failed to create socket, %m\n");
+		sd_eprintf("failed to create socket, %m\n");
 		return -1;
 	}
 
 	ret = bind(fd, &addr, sizeof(addr));
 	if (ret) {
-		eprintf("failed to bind socket: %m\n");
+		sd_eprintf("failed to bind socket: %m\n");
 		goto err;
 	}
 
 	ret = listen(fd, SOMAXCONN);
 	if (ret) {
-		eprintf("failed to listen on socket: %m\n");
+		sd_eprintf("failed to listen on socket: %m\n");
 		goto err;
 	}
 
@@ -614,7 +614,7 @@ bool inetaddr_is_valid(char *addr)
 
 	af = strstr(addr, ":") ? AF_INET6 : AF_INET;
 	if (!inet_pton(af, addr, buf)) {
-		eprintf("Bad address '%s'\n", addr);
+		sd_eprintf("Bad address '%s'\n", addr);
 		return false;
 	}
 	return true;
diff --git a/lib/util.c b/lib/util.c
index c79ee46..86dcfd6 100644
--- a/lib/util.c
+++ b/lib/util.c
@@ -256,7 +256,7 @@ int rmdir_r(char *dir_path)
 	dir = opendir(dir_path);
 	if (!dir) {
 		if (errno != ENOENT)
-			eprintf("failed to open %s: %m\n", dir_path);
+			sd_eprintf("failed to open %s: %m\n", dir_path);
 		return -errno;
 	}
 
@@ -267,7 +267,7 @@ int rmdir_r(char *dir_path)
 		snprintf(path, sizeof(path), "%s/%s", dir_path, d->d_name);
 		ret = stat(path, &s);
 		if (ret) {
-			eprintf("failed to stat %s: %m\n", path);
+			sd_eprintf("failed to stat %s: %m\n", path);
 			goto out;
 		}
 		if (S_ISDIR(s.st_mode))
@@ -276,7 +276,7 @@ int rmdir_r(char *dir_path)
 			ret = unlink(path);
 
 		if (ret != 0) {
-			eprintf("failed to remove %s %s: %m\n",
+			sd_eprintf("failed to remove %s %s: %m\n",
 					S_ISDIR(s.st_mode) ? "directory" : "file",
 					path);
 			goto out;
diff --git a/sheep/cluster/accord.c b/sheep/cluster/accord.c
index be0cf83..0cfe0ef 100644
--- a/sheep/cluster/accord.c
+++ b/sheep/cluster/accord.c
@@ -111,7 +111,7 @@ again:
 	if (rc == ACRD_SUCCESS)
 		return;
 	else if (rc == ACRD_ERR_EXIST) {
-		dprintf("retry\n");
+		sd_dprintf("retry\n");
 		usleep(10000); /* FIXME: use acrd notification */
 		goto again;
 	} else
@@ -457,12 +457,12 @@ static void acrd_handler(int listen_fd, int events, void *data)
 	enum cluster_join_result res;
 
 	if (events & EPOLLHUP) {
-		eprintf("accord driver received EPOLLHUP event, exiting.\n");
+		sd_eprintf("accord driver received EPOLLHUP event, exiting.\n");
 		log_close();
 		exit(1);
 	}
 
-	dprintf("read event\n");
+	sd_dprintf("read event\n");
 
 	ret = eventfd_read(efd, &value);
 	if (ret < 0)
@@ -487,7 +487,7 @@ static void acrd_handler(int listen_fd, int events, void *data)
 		acrd_queue_push_back(ahandle, &ev);
 
 		if (res == CJ_RES_MASTER_TRANSFER) {
-			eprintf("failed to join sheepdog cluster: "
+			sd_eprintf("failed to join sheepdog cluster: "
 				"please retry when master is up\n");
 			exit(1);
 		}
@@ -526,8 +526,8 @@ static int accord_init(const char *option)
 	int ret;
 
 	if (!option) {
-		eprintf("specify one of the accord servers.\n");
-		eprintf("e.g. sheep /store -c accord:127.0.0.1\n");
+		sd_eprintf("specify one of the accord servers.\n");
+		sd_eprintf("e.g. sheep /store -c accord:127.0.0.1\n");
 		return -1;
 	}
 
@@ -535,19 +535,19 @@ static int accord_init(const char *option)
 
 	ahandle = acrd_init(option, 9090, acrd_join_fn, acrd_leave_fn, NULL);
 	if (!ahandle) {
-		eprintf("failed to connect to accrd server %s\n", option);
+		sd_eprintf("failed to connect to accrd server %s\n", option);
 		return -1;
 	}
 
 	efd = eventfd(0, EFD_NONBLOCK);
 	if (efd < 0) {
-		eprintf("failed to create an event fd: %m\n");
+		sd_eprintf("failed to create an event fd: %m\n");
 		return -1;
 	}
 
 	acrd_wq = init_work_queue("accord", true);
 	if (!acrd_wq) {
-		eprintf("failed to create accord workqueue: %m\n");
+		sd_eprintf("failed to create accord workqueue: %m\n");
 		return -1;
 	}
 
@@ -568,7 +568,8 @@ static int accord_init(const char *option)
 
 	ret = register_event(efd, acrd_handler, NULL);
 	if (ret) {
-		eprintf("failed to register accord event handler (%d)\n", ret);
+		sd_eprintf("failed to register accord event handler (%d)\n",
+			ret);
 		return -1;
 	}
 
diff --git a/sheep/cluster/corosync.c b/sheep/cluster/corosync.c
index a607bae..2372faf 100644
--- a/sheep/cluster/corosync.c
+++ b/sheep/cluster/corosync.c
@@ -119,7 +119,7 @@ static inline void del_cpg_node(struct cpg_node *nodes, size_t nr_nodes,
 
 	idx = find_cpg_node(nodes, nr_nodes, deled);
 	if (idx < 0) {
-		dprintf("cannot find node\n");
+		sd_dprintf("cannot find node\n");
 		return;
 	}
 
@@ -139,12 +139,12 @@ static int corosync_get_local_addr(uint8_t *addr)
 	ret = corosync_cfg_get_node_addrs(cfg_handle, this_node.nodeid, 1,
 					  &nr, &caddr);
 	if (ret != CS_OK) {
-		vprintf(SDOG_ERR, "failed to get node addresses (%d)\n", ret);
+		sd_printf(SDOG_ERR, "failed to get node addresses (%d)\n", ret);
 		return -1;
 	}
 
 	if (!nr) {
-		vprintf(SDOG_ERR, "no node addresses found\n");
+		sd_printf(SDOG_ERR, "no node addresses found\n");
 		return -1;
 	}
 
@@ -156,7 +156,7 @@ static int corosync_get_local_addr(uint8_t *addr)
 		memset(addr, 0, 16);
 		memcpy(addr + 12, saddr, 4);
 	} else {
-		vprintf(SDOG_ERR, "unknown protocol %d\n", ss->ss_family);
+		sd_printf(SDOG_ERR, "unknown protocol %d\n", ss->ss_family);
 		return -1;
 	}
 
@@ -194,11 +194,11 @@ retry:
 	case CS_OK:
 		break;
 	case CS_ERR_TRY_AGAIN:
-		dprintf("failed to send message: retrying\n");
+		sd_dprintf("failed to send message: retrying\n");
 		sleep(1);
 		goto retry;
 	default:
-		eprintf("failed to send message (%d)\n", ret);
+		sd_eprintf("failed to send message (%d)\n", ret);
 		return -1;
 	}
 	return 0;
@@ -306,7 +306,8 @@ static bool __corosync_dispatch_one(struct corosync_event *cevent)
 			     cevent->msg, cevent->msg_len);
 
 		if (res == CJ_RES_MASTER_TRANSFER) {
-			eprintf("failed to join sheepdog cluster: please retry when master is up\n");
+			sd_eprintf("failed to join sheepdog cluster:"	\
+				" please retry when master is up\n");
 			exit(1);
 		}
 
@@ -368,7 +369,7 @@ static void __corosync_dispatch(void)
 		 * when network partition has occured.  To count the
 		 * number of alive nodes correctly, we postpone
 		 * processsing events if there are incoming ones. */
-		dprintf("wait for a next dispatch event\n");
+		sd_dprintf("wait for a next dispatch event\n");
 		return;
 	}
 
@@ -468,7 +469,7 @@ static void cdrv_cpg_deliver(cpg_handle_t handle,
 	struct corosync_message *cmsg = msg;
 	int master;
 
-	dprintf("%d\n", cmsg->type);
+	sd_dprintf("%d\n", cmsg->type);
 
 	switch (cmsg->type) {
 	case COROSYNC_MSG_TYPE_JOIN_REQUEST:
@@ -580,7 +581,7 @@ static void cdrv_cpg_confchg(cpg_handle_t handle,
 	struct cpg_node left_sheep[SD_MAX_NODES];
 	bool promote = true;
 
-	dprintf("mem:%zu, joined:%zu, left:%zu\n",
+	sd_dprintf("mem:%zu, joined:%zu, left:%zu\n",
 		member_list_entries, joined_list_entries,
 		left_list_entries);
 
@@ -664,7 +665,7 @@ static void cdrv_cpg_confchg(cpg_handle_t handle,
 			cevent = find_event(COROSYNC_EVENT_TYPE_JOIN_REQUEST,
 					    &member_sheep[i]);
 			if (!cevent) {
-				dprintf("Not promoting because member is "
+				sd_dprintf("Not promoting because member is "
 					"not in our event list.\n");
 				promote = false;
 				break;
@@ -692,14 +693,14 @@ retry:
 	case CS_OK:
 		break;
 	case CS_ERR_TRY_AGAIN:
-		dprintf("failed to join the sheepdog group: retrying\n");
+		sd_dprintf("failed to join the sheepdog group: retrying\n");
 		sleep(1);
 		goto retry;
 	case CS_ERR_SECURITY:
-		eprintf("permission denied to join the sheepdog group\n");
+		sd_eprintf("permission denied to join the sheepdog group\n");
 		return -1;
 	default:
-		eprintf("failed to join the sheepdog group (%d)\n", ret);
+		sd_eprintf("failed to join the sheepdog group (%d)\n", ret);
 		return -1;
 	}
 
@@ -740,13 +741,14 @@ static void corosync_handler(int listen_fd, int events, void *data)
 	int ret;
 
 	if (events & EPOLLHUP) {
-		eprintf("corosync driver received EPOLLHUP event, exiting.\n");
+		sd_eprintf("corosync driver received EPOLLHUP event,"	\
+			" exiting.\n");
 		goto out;
 	}
 
 	ret = cpg_dispatch(cpg_handle, CS_DISPATCH_ALL);
 	if (ret != CS_OK) {
-		eprintf("cpg_dispatch returned %d\n", ret);
+		sd_eprintf("cpg_dispatch returned %d\n", ret);
 		goto out;
 	}
 
@@ -773,28 +775,28 @@ again:
 		break;
 	case CS_ERR_TRY_AGAIN:
 		if (retry_cnt++ == CPG_INIT_RETRY_CNT) {
-			eprintf("failed to initialize cpg (%d) - "
+			sd_eprintf("failed to initialize cpg (%d) - "
 				"is corosync running?\n", ret);
 			return -1;
 		}
-		dprintf("retry cpg_initialize\n");
+		sd_dprintf("retry cpg_initialize\n");
 		usleep(200000);
 		goto again;
 	default:
-		eprintf("failed to initialize cpg (%d) - "
+		sd_eprintf("failed to initialize cpg (%d) - "
 			"is corosync running?\n", ret);
 		return -1;
 	}
 
 	ret = corosync_cfg_initialize(&cfg_handle, NULL);
 	if (ret != CS_OK) {
-		vprintf(SDOG_ERR, "failed to initialize cfg (%d)\n", ret);
+		sd_printf(SDOG_ERR, "failed to initialize cfg (%d)\n", ret);
 		return -1;
 	}
 
 	ret = corosync_cfg_local_get(cfg_handle, &nodeid);
 	if (ret != CS_OK) {
-		vprintf(SDOG_ERR, "failed to get node id (%d)\n", ret);
+		sd_printf(SDOG_ERR, "failed to get node id (%d)\n", ret);
 		return -1;
 	}
 
@@ -803,13 +805,13 @@ again:
 
 	ret = cpg_fd_get(cpg_handle, &cpg_fd);
 	if (ret != CS_OK) {
-		eprintf("failed to get cpg file descriptor (%d)\n", ret);
+		sd_eprintf("failed to get cpg file descriptor (%d)\n", ret);
 		return -1;
 	}
 
 	ret = register_event(cpg_fd, corosync_handler, NULL);
 	if (ret) {
-		eprintf("failed to register corosync event handler (%d)\n",
+		sd_eprintf("failed to register corosync event handler (%d)\n",
 			ret);
 		return -1;
 	}
diff --git a/sheep/cluster/local.c b/sheep/cluster/local.c
index 20ce325..5a99015 100644
--- a/sheep/cluster/local.c
+++ b/sheep/cluster/local.c
@@ -178,7 +178,7 @@ static void shm_queue_notify(void)
 	nr = get_nodes(lnodes);
 
 	for (i = 0; i < nr; i++) {
-		dprintf("send signal to %s\n", lnode_to_str(lnodes + i));
+		sd_dprintf("send signal to %s\n", lnode_to_str(lnodes + i));
 		kill(lnodes[i].pid, SIGUSR1);
 	}
 }
@@ -285,9 +285,10 @@ static void add_event(enum local_event_type type, struct local_node *lnode,
 		abort();
 	}
 
-	dprintf("type = %d, sender = %s\n", ev.type, lnode_to_str(&ev.sender));
+	sd_dprintf("type = %d, sender = %s\n",
+		ev.type, lnode_to_str(&ev.sender));
 	for (i = 0; i < ev.nr_lnodes; i++)
-		dprintf("%d: %s\n", i, lnode_to_str(ev.lnodes + i));
+		sd_dprintf("%d: %s\n", i, lnode_to_str(ev.lnodes + i));
 
 	shm_queue_push(&ev);
 
@@ -403,13 +404,14 @@ static bool local_process_event(void)
 	if (!ev)
 		return false;
 
-	dprintf("type = %d, sender = %s\n", ev->type,
-		lnode_to_str(&ev->sender));
-	dprintf("callbacked = %d, removed = %d\n", ev->callbacked, ev->removed);
+	sd_dprintf("type = %d, sender = %s\n",
+		ev->type, lnode_to_str(&ev->sender));
+	sd_dprintf("callbacked = %d, removed = %d\n",
+		ev->callbacked, ev->removed);
 
 	nr_nodes = 0;
 	for (i = 0; i < ev->nr_lnodes; i++) {
-		dprintf("%d: %s\n", i, lnode_to_str(ev->lnodes + i));
+		sd_dprintf("%d: %s\n", i, lnode_to_str(ev->lnodes + i));
 		if (!ev->lnodes[i].gateway)
 			nodes[nr_nodes++] = ev->lnodes[i].node;
 	}
@@ -422,7 +424,7 @@ static bool local_process_event(void)
 
 	if (ev->type == EVENT_JOIN_RESPONSE &&
 	    lnode_eq(&this_node, &ev->sender)) {
-		dprintf("join Sheepdog\n");
+		sd_dprintf("join Sheepdog\n");
 		joined = true;
 	}
 
@@ -434,8 +436,8 @@ static bool local_process_event(void)
 			get_nodes(lnodes);
 
 			if (!lnode_eq(&this_node, &lnodes[0])) {
-				dprintf("wait for another node to accept this "
-					"node\n");
+				sd_dprintf("wait for another node"
+					" to accept this node\n");
 				return false;
 			}
 		} else
@@ -452,7 +454,7 @@ static bool local_process_event(void)
 		shm_queue_notify();
 
 		if (res == CJ_RES_MASTER_TRANSFER) {
-			eprintf("failed to join sheepdog cluster: "
+			sd_eprintf("failed to join sheepdog cluster: "
 				"please retry when master is up\n");
 			shm_queue_unlock();
 			exit(1);
@@ -496,12 +498,12 @@ static void local_handler(int listen_fd, int events, void *data)
 	int ret;
 
 	if (events & EPOLLHUP) {
-		eprintf("local driver received EPOLLHUP event, exiting.\n");
+		sd_eprintf("local driver received EPOLLHUP event, exiting.\n");
 		log_close();
 		exit(1);
 	}
 
-	dprintf("read siginfo\n");
+	sd_dprintf("read siginfo\n");
 
 	ret = read(sigfd, &siginfo, sizeof(siginfo));
 	assert(ret == sizeof(siginfo));
@@ -543,7 +545,7 @@ static int local_init(const char *option)
 
 	sigfd = signalfd(-1, &mask, SFD_NONBLOCK);
 	if (sigfd < 0) {
-		eprintf("failed to create a signal fd: %m\n");
+		sd_eprintf("failed to create a signal fd: %m\n");
 		return -1;
 	}
 
@@ -551,7 +553,8 @@ static int local_init(const char *option)
 
 	ret = register_event(sigfd, local_handler, NULL);
 	if (ret) {
-		eprintf("failed to register local event handler (%d)\n", ret);
+		sd_eprintf("failed to register local event handler (%d)\n",
+			ret);
 		return -1;
 	}
 
diff --git a/sheep/cluster/zookeeper.c b/sheep/cluster/zookeeper.c
index 47bc91c..fcb99eb 100644
--- a/sheep/cluster/zookeeper.c
+++ b/sheep/cluster/zookeeper.c
@@ -141,7 +141,7 @@ static inline ZOOAPI int zk_delete_node(const char *path, int version)
 		rc = zoo_delete(zhandle, path, version);
 	} while (rc == ZOPERATIONTIMEOUT || rc == ZCONNECTIONLOSS);
 	if (rc != ZOK)
-		eprintf("failed, path:%s, %s\n", path, zerror(rc));
+		sd_eprintf("failed, path:%s, %s\n", path, zerror(rc));
 	return rc;
 }
 
@@ -168,7 +168,7 @@ zk_create_node(const char *path, const char *value, int valuelen,
 		rc = zoo_create(zhandle, path, value, valuelen, acl,
 				flags, path_buffer, path_buffer_len);
 		if (rc != ZOK && rc != ZNODEEXISTS)
-			eprintf("failed, path:%s, %s\n", path, zerror(rc));
+			sd_eprintf("failed, path:%s, %s\n", path, zerror(rc));
 	} while (rc == ZOPERATIONTIMEOUT || rc == ZCONNECTIONLOSS);
 	return rc;
 }
@@ -197,7 +197,7 @@ static inline ZOOAPI int zk_get_data(const char *path, void *buffer,
 		rc = zoo_get(zhandle, path, 1, (char *)buffer,
 			     buffer_len, NULL);
 		if (rc != ZOK)
-			eprintf("failed, path:%s, %s\n", path, zerror(rc));
+			sd_eprintf("failed, path:%s, %s\n", path, zerror(rc));
 	} while (rc == ZOPERATIONTIMEOUT || rc == ZCONNECTIONLOSS);
 	return rc;
 }
@@ -220,7 +220,7 @@ static inline ZOOAPI int zk_node_exists(const char *path)
 	do {
 		rc = zoo_exists(zhandle, path, 1, NULL);
 		if (rc != ZOK && rc != ZNONODE)
-			eprintf("failed, path:%s, %s\n", path, zerror(rc));
+			sd_eprintf("failed, path:%s, %s\n", path, zerror(rc));
 	} while (rc == ZOPERATIONTIMEOUT || rc == ZCONNECTIONLOSS);
 
 	return rc;
@@ -273,7 +273,7 @@ static void zk_queue_push(struct zk_event *ev)
 		first_push = false;
 	}
 
-	dprintf("create path:%s, queue_pos:%010"PRId32", len:%d\n",
+	sd_dprintf("create path:%s, queue_pos:%010"PRId32", len:%d\n",
 		buf, queue_pos, len);
 }
 
@@ -297,7 +297,7 @@ static void push_join_response(struct zk_event *ev)
 	len = (char *)(ev->buf) - (char *)ev + ev->buf_len;
 	sprintf(path, QUEUE_ZNODE "/%010"PRId32, queue_pos);
 	zk_set_data(path, (char *)ev, len, -1);
-	dprintf("update path:%s, queue_pos:%010"PRId32", len:%d\n",
+	sd_dprintf("update path:%s, queue_pos:%010"PRId32", len:%d\n",
 		path, queue_pos, len);
 }
 
@@ -309,7 +309,7 @@ static void zk_queue_pop_advance(struct zk_event *ev)
 	len = sizeof(*ev);
 	sprintf(path, QUEUE_ZNODE "/%010"PRId32, queue_pos);
 	assert(zk_get_data(path, ev, &len) == ZOK);
-	dprintf("%s, type:%d, len:%d, pos:%"PRId32"\n",
+	sd_dprintf("%s, type:%d, len:%d, pos:%"PRId32"\n",
 		path, ev->type, len, queue_pos);
 	queue_pos++;
 }
@@ -377,7 +377,7 @@ static inline void build_node_list(void)
 		zk = rb_entry(n, struct zk_node, rb);
 		sd_nodes[nr_sd_nodes++] = zk->node;
 	}
-	dprintf("nr_sd_nodes:%zu\n", nr_sd_nodes);
+	sd_dprintf("nr_sd_nodes:%zu\n", nr_sd_nodes);
 }
 
 static inline int zk_master_create(void)
@@ -438,7 +438,7 @@ static void zk_watcher(zhandle_t *zh, int type, int state, const char *path,
 	int ret;
 
 /* CREATED_EVENT 1, DELETED_EVENT 2, CHANGED_EVENT 3, CHILD_EVENT 4 */
-	dprintf("path:%s, type:%d\n", path, type);
+	sd_dprintf("path:%s, type:%d\n", path, type);
 	if (type == ZOO_CREATED_EVENT || type == ZOO_CHANGED_EVENT) {
 		ret = sscanf(path, MEMBER_ZNODE "/%s", str);
 		if (ret == 1)
@@ -497,7 +497,7 @@ static int zk_join(const struct sd_node *myself,
 	sprintf(path, MEMBER_ZNODE "/%s", node_to_str(myself));
 	rc = zk_node_exists(path);
 	if (rc == ZOK) {
-		eprintf("Previous zookeeper session exist, shoot myself.\n");
+		sd_eprintf("Previous zookeeper session exist, shoot myself.\n");
 		exit(1);
 	}
 
@@ -532,7 +532,7 @@ static void zk_handle_join_request(struct zk_event *ev)
 {
 	enum cluster_join_result res;
 
-	dprintf("sender: %s\n", node_to_str(&ev->sender.node));
+	sd_dprintf("sender: %s\n", node_to_str(&ev->sender.node));
 	if (!is_master()) {
 		/* Let's await master acking the join-request */
 		queue_pos--;
@@ -543,12 +543,12 @@ static void zk_handle_join_request(struct zk_event *ev)
 	ev->join_result = res;
 	push_join_response(ev);
 	if (res == CJ_RES_MASTER_TRANSFER) {
-		eprintf("failed to join sheepdog cluster: "
+		sd_eprintf("failed to join sheepdog cluster: "
 			"please retry when master is up\n");
 		add_event(EVENT_LEAVE, &this_node, NULL, 0);
 		exit(1);
 	}
-	dprintf("I'm the master now\n");
+	sd_dprintf("I'm the master now\n");
 }
 
 static void watch_all_nodes(void)
@@ -572,7 +572,7 @@ static void init_node_list(struct zk_event *ev)
 	size_t node_nr = ev->nr_nodes;
 	int i;
 
-	dprintf("%zu\n", node_nr);
+	sd_dprintf("%zu\n", node_nr);
 	for (i = 0; i < node_nr; i++) {
 		struct zk_node zk;
 		mempcpy(&zk.node, p, sizeof(struct sd_node));
@@ -587,7 +587,7 @@ static void zk_handle_join_response(struct zk_event *ev)
 {
 	char path[256];
 
-	dprintf("JOIN RESPONSE\n");
+	sd_dprintf("JOIN RESPONSE\n");
 	if (node_eq(&ev->sender.node, &this_node.node))
 		/* newly joined node */
 		init_node_list(ev);
@@ -600,14 +600,14 @@ static void zk_handle_join_response(struct zk_event *ev)
 		 */
 		zk_tree_destroy();
 
-	dprintf("%s, %d\n", node_to_str(&ev->sender.node), ev->join_result);
+	sd_dprintf("%s, %d\n", node_to_str(&ev->sender.node), ev->join_result);
 	switch (ev->join_result) {
 	case CJ_RES_SUCCESS:
 	case CJ_RES_JOIN_LATER:
 	case CJ_RES_MASTER_TRANSFER:
 		sprintf(path, MEMBER_ZNODE"/%s", node_to_str(&ev->sender.node));
 		if (node_eq(&ev->sender.node, &this_node.node)) {
-			dprintf("create path:%s\n", path);
+			sd_dprintf("create path:%s\n", path);
 			zk_create_node(path, (char *)&ev->sender,
 				       sizeof(ev->sender), &ZOO_OPEN_ACL_UNSAFE,
 				       ZOO_EPHEMERAL, NULL, 0);
@@ -653,7 +653,7 @@ static void zk_handle_leave(struct zk_event *ev)
 	struct zk_node *n = zk_tree_search(&ev->sender.node.nid);
 
 	if (!n) {
-		dprintf("can't find this leave node:%s, ignore it.\n",
+		sd_dprintf("can't find this leave node:%s, ignore it.\n",
 			node_to_str(&ev->sender.node));
 		return;
 	}
@@ -667,7 +667,7 @@ static void zk_handle_block(struct zk_event *ev)
 {
 	struct zk_node *block = xzalloc(sizeof(*block));
 
-	dprintf("BLOCK\n");
+	sd_dprintf("BLOCK\n");
 	block->node = ev->sender.node;
 	list_add_tail(&block->list, &zk_block_list);
 	block = list_first_entry(&zk_block_list, typeof(*block), list);
@@ -679,7 +679,7 @@ static void zk_handle_unblock(struct zk_event *ev)
 {
 	struct zk_node *block;
 
-	dprintf("UNBLOCK\n");
+	sd_dprintf("UNBLOCK\n");
 	if (list_empty(&zk_block_list))
 		return;
 	block = list_first_entry(&zk_block_list, typeof(*block), list);
@@ -692,7 +692,7 @@ static void zk_handle_unblock(struct zk_event *ev)
 
 static void zk_handle_notify(struct zk_event *ev)
 {
-	dprintf("NOTIFY\n");
+	sd_dprintf("NOTIFY\n");
 	sd_notify_handler(&ev->sender.node, ev->buf, ev->buf_len);
 }
 
@@ -712,15 +712,16 @@ static void zk_event_handler(int listen_fd, int events, void *data)
 	eventfd_t value;
 	struct zk_event ev;
 
-	dprintf("%d, %d\n", events, queue_pos);
+	sd_dprintf("%d, %d\n", events, queue_pos);
 	if (events & EPOLLHUP) {
-		eprintf("zookeeper driver received EPOLLHUP event, exiting.\n");
+		sd_eprintf("zookeeper driver received EPOLLHUP event,"
+			" exiting.\n");
 		log_close();
 		exit(1);
 	}
 
 	if (eventfd_read(efd, &value) < 0) {
-		eprintf("%m\n");
+		sd_eprintf("%m\n");
 		return;
 	}
 
@@ -757,24 +758,25 @@ static int zk_init(const char *option)
 	int ret, timeout = SESSION_TIMEOUT;
 
 	if (!option) {
-		eprintf("You must specify zookeeper servers.\n");
+		sd_eprintf("You must specify zookeeper servers.\n");
 		return -1;
 	}
 
 	hosts = strtok((char *)option, "=");
 	if ((to = strtok(NULL, "="))) {
 		if (sscanf(to, "%u", &timeout) != 1) {
-			eprintf("Invalid paramter for timeout\n");
+			sd_eprintf("Invalid paramter for timeout\n");
 			return -1;
 		}
 		p = strstr(hosts, "timeout");
 		*--p = '\0';
 	}
-	dprintf("version %d.%d.%d, address %s, timeout %d\n", ZOO_MAJOR_VERSION,
-		ZOO_MINOR_VERSION, ZOO_PATCH_VERSION, hosts, timeout);
+	sd_dprintf("version %d.%d.%d, address %s, timeout %d\n",
+		ZOO_MAJOR_VERSION, ZOO_MINOR_VERSION, ZOO_PATCH_VERSION,
+		hosts, timeout);
 	zhandle = zookeeper_init(hosts, zk_watcher, timeout, NULL, NULL, 0);
 	if (!zhandle) {
-		eprintf("failed to connect to zk server %s\n", option);
+		sd_eprintf("failed to connect to zk server %s\n", option);
 		return -1;
 	}
 
@@ -782,13 +784,13 @@ static int zk_init(const char *option)
 
 	efd = eventfd(0, EFD_NONBLOCK);
 	if (efd < 0) {
-		eprintf("failed to create an event fd: %m\n");
+		sd_eprintf("failed to create an event fd: %m\n");
 		return -1;
 	}
 
 	ret = register_event(efd, zk_event_handler, NULL);
 	if (ret) {
-		eprintf("failed to register zookeeper event handler (%d)\n",
+		sd_eprintf("failed to register zookeeper event handler (%d)\n",
 			ret);
 		return -1;
 	}
diff --git a/sheep/config.c b/sheep/config.c
index c8f806a..0c13aa7 100644
--- a/sheep/config.c
+++ b/sheep/config.c
@@ -40,19 +40,19 @@ static int write_config(void)
 
 	fd = open(config_path, O_DSYNC | O_WRONLY | O_CREAT, def_fmode);
 	if (fd < 0) {
-		eprintf("failed to open config file, %m\n");
+		sd_eprintf("failed to open config file, %m\n");
 		return SD_RES_EIO;
 	}
 
 	jd = jrnl_begin(&config, sizeof(config), 0, config_path, jrnl_path);
 	if (!jd) {
-		eprintf("failed to write config data to journal, %m\n");
+		sd_eprintf("failed to write config data to journal, %m\n");
 		ret = SD_RES_EIO;
 		goto out;
 	}
 	ret = xwrite(fd, &config, sizeof(config));
 	if (ret != sizeof(config)) {
-		eprintf("failed to write config data, %m\n");
+		sd_eprintf("failed to write config data, %m\n");
 		ret = SD_RES_EIO;
 	} else
 		ret = SD_RES_SUCCESS;
@@ -74,7 +74,7 @@ int init_config_path(const char *base_path)
 	fd = open(config_path, O_RDONLY);
 	if (fd < 0) {
 		if (errno != ENOENT) {
-			eprintf("failed to read config file, %m\n");
+			sd_eprintf("failed to read config file, %m\n");
 			return -1;
 		}
 		goto create;
@@ -86,13 +86,13 @@ int init_config_path(const char *base_path)
 		goto create;
 	}
 	if (ret < 0) {
-		eprintf("failed to read config file, %m\n");
+		sd_eprintf("failed to read config file, %m\n");
 		goto out;
 	}
 
 	if (config.version != SD_FORMAT_VERSION) {
-		eprintf("This sheep version is not compatible with the existing "
-			"data layout, %d\n", config.version);
+		sd_eprintf("This sheep version is not compatible with"
+			" the existing data layout, %d\n", config.version);
 		if (sys->upgrade) {
 			/* upgrade sheep store */
 			ret = sd_migrate_store(config.version, SD_FORMAT_VERSION);
@@ -100,8 +100,8 @@ int init_config_path(const char *base_path)
 				/* reload config file */
 				ret = xpread(fd, &config, sizeof(config), 0);
 				if (ret != sizeof(config)) {
-					eprintf("failed to reload config file,"
-						" %m\n");
+					sd_eprintf("failed to reload config"
+						" file, %m\n");
 					ret = -1;
 				} else
 					ret = 0;
@@ -109,7 +109,7 @@ int init_config_path(const char *base_path)
 			goto out;
 		}
 
-		eprintf("use '-u' option to upgrade sheep store\n");
+		sd_eprintf("use '-u' option to upgrade sheep store\n");
 		ret = -1;
 		goto out;
 	}
diff --git a/sheep/farm/farm.c b/sheep/farm/farm.c
index 6eee745..90178d3 100644
--- a/sheep/farm/farm.c
+++ b/sheep/farm/farm.c
@@ -35,7 +35,7 @@ static int create_directory(const char *p)
 	strbuf_addstr(&buf, ".farm");
 	if (mkdir(buf.buf, 0755) < 0) {
 		if (errno != EEXIST) {
-			eprintf("%m\n");
+			sd_eprintf("%m\n");
 			ret = -1;
 			goto err;
 		}
@@ -47,7 +47,7 @@ static int create_directory(const char *p)
 	strbuf_addstr(&buf, "/objects");
 	if (mkdir(buf.buf, 0755) < 0) {
 		if (errno != EEXIST) {
-			eprintf("%m\n");
+			sd_eprintf("%m\n");
 			ret = -1;
 			goto err;
 		}
@@ -56,7 +56,7 @@ static int create_directory(const char *p)
 		strbuf_addf(&buf, "/%02x", i);
 		if (mkdir(buf.buf, 0755) < 0) {
 			if (errno != EEXIST) {
-				eprintf("%m\n");
+				sd_eprintf("%m\n");
 				ret = -1;
 				goto err;
 			}
@@ -79,7 +79,7 @@ static int get_trunk_sha1(uint32_t epoch, unsigned char *outsha1)
 	struct sha1_file_hdr hdr;
 
 	log_free = log_buf = snap_log_read(&nr_logs);
-	dprintf("%d\n", nr_logs);
+	sd_dprintf("%d\n", nr_logs);
 	if (nr_logs < 0)
 		goto out;
 
@@ -110,12 +110,12 @@ static bool is_xattr_enabled(const char *path)
 
 static int farm_init(const char *p)
 {
-	dprintf("use farm store driver\n");
+	sd_dprintf("use farm store driver\n");
 	if (create_directory(p) < 0)
 		goto err;
 
 	if (!is_xattr_enabled(p)) {
-		eprintf("xattrs are not enabled on %s\n", p);
+		sd_eprintf("xattrs are not enabled on %s\n", p);
 		goto err;
 	}
 
@@ -144,7 +144,7 @@ static int farm_snapshot(const struct siocb *iocb)
 		goto out;
 
 	epoch = log_nr + 1;
-	dprintf("user epoch %d\n", epoch);
+	sd_dprintf("user epoch %d\n", epoch);
 
 	nr_nodes = epoch_log_read(sys->epoch, nodes, sizeof(nodes));
 	if (nr_nodes < 0)
@@ -171,7 +171,7 @@ static int cleanup_working_dir(void)
 	DIR *dir;
 	struct dirent *d;
 
-	dprintf("try clean up working dir\n");
+	sd_dprintf("try clean up working dir\n");
 	dir = opendir(obj_path);
 	if (!dir)
 		return -1;
@@ -182,10 +182,10 @@ static int cleanup_working_dir(void)
 			continue;
 		snprintf(p, sizeof(p), "%s%s", obj_path, d->d_name);
 		if (unlink(p) < 0) {
-			eprintf("%s:%m\n", p);
+			sd_eprintf("%s:%m\n", p);
 			continue;
 		}
-		dprintf("remove file %s\n", d->d_name);
+		sd_dprintf("remove file %s\n", d->d_name);
 	}
 	closedir(dir);
 	return 0;
@@ -217,17 +217,17 @@ static int restore_objects_from_snap(uint32_t epoch)
 		oid = trunk_buf->oid;
 		buffer = sha1_file_read(trunk_buf->sha1, &h);
 		if (!buffer) {
-			eprintf("oid %"PRIx64" not restored\n", oid);
+			sd_eprintf("oid %"PRIx64" not restored\n", oid);
 			goto out;
 		}
 		io.length = h.size;
 		io.buf = buffer;
 		ret = default_create_and_write(oid, &io);
 		if (ret != SD_RES_SUCCESS) {
-			eprintf("oid %"PRIx64" not restored\n", oid);
+			sd_eprintf("oid %"PRIx64" not restored\n", oid);
 			goto out;
 		} else
-			dprintf("oid %"PRIx64" restored\n", oid);
+			sd_dprintf("oid %"PRIx64" restored\n", oid);
 
 		free(buffer);
 	}
@@ -240,10 +240,10 @@ static int farm_restore(const struct siocb *iocb)
 {
 	int ret = SD_RES_EIO, epoch = iocb->epoch;
 
-	dprintf("try recover user epoch %d\n", epoch);
+	sd_dprintf("try recover user epoch %d\n", epoch);
 
 	if (cleanup_working_dir() < 0) {
-		eprintf("failed to clean up the working dir %m\n");
+		sd_eprintf("failed to clean up the working dir %m\n");
 		goto out;
 	}
 
@@ -261,7 +261,7 @@ static int farm_get_snap_file(struct siocb *iocb)
 	size_t size;
 	int nr;
 
-	dprintf("try get snap file\n");
+	sd_dprintf("try get snap file\n");
 	buffer = snap_log_read(&nr);
 	if (!buffer)
 		goto out;
diff --git a/sheep/farm/sha1_file.c b/sheep/farm/sha1_file.c
index 4516078..b12ecbd 100644
--- a/sheep/farm/sha1_file.c
+++ b/sheep/farm/sha1_file.c
@@ -90,7 +90,7 @@ static int put_sha1_file(char *name)
 
 	if (getxattr(name, CNAME, &count, CSIZE) < 0) {
 		if (errno == ENOENT) {
-			dprintf("sha1 file doesn't exist\n");
+			sd_dprintf("sha1 file doesn't exist\n");
 			return -1;
 		} else {
 			panic("%m\n");
@@ -100,10 +100,10 @@ static int put_sha1_file(char *name)
 	count--;
 	if (count == 0) {
 		if (unlink(name) < 0) {
-			dprintf("%m\n");
+			sd_dprintf("%m\n");
 			return -1;
 		}
-		dprintf("%s deleted\n", name);
+		sd_dprintf("%s deleted\n", name);
 	} else {
 		if (setxattr(name, CNAME, &count, CSIZE, 0) < 0)
 			panic("%m\n");
@@ -124,7 +124,7 @@ static int sha1_buffer_write(const unsigned char *sha1, void *buf, unsigned int
 	}
 	len = xwrite(fd, buf, size);
 	if (len != size) {
-		dprintf("%m\n");
+		sd_dprintf("%m\n");
 		close(fd);
 		return -1;
 	}
@@ -163,14 +163,14 @@ static void *map_sha1_file(const unsigned char *sha1, unsigned long *size)
 		return NULL;
 	}
 	if (fstat(fd, &st) < 0) {
-		dprintf("%m\n");
+		sd_dprintf("%m\n");
 		close(fd);
 		return NULL;
 	}
 	map = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
 	close(fd);
 	if (map == MAP_FAILED) {
-		dprintf("%m\n");
+		sd_dprintf("%m\n");
 		return NULL;
 	}
 	*size = st.st_size;
@@ -186,7 +186,7 @@ static void *unpack_sha1_file(void *map, unsigned long mapsize, struct sha1_file
 	hdr_len = sizeof(*hdr);
 	buf = valloc(hdr->size);
 	if (!buf) {
-		dprintf("%m\n");
+		sd_dprintf("%m\n");
 		return NULL;
 	}
 
@@ -204,7 +204,7 @@ static int verify_sha1_file(const unsigned char *sha1, void *buf, unsigned long
 	sha1_final(&c, tmp);
 
 	if (memcmp((char *)tmp, (char *)sha1, SHA1_LEN) != 0) {
-		dprintf("failed, %s != %s\n", sha1_to_hex(sha1),
+		sd_dprintf("failed, %s != %s\n", sha1_to_hex(sha1),
 			sha1_to_hex(tmp));
 		return -1;
 	}
diff --git a/sheep/farm/snap.c b/sheep/farm/snap.c
index 73f9758..e88d77a 100644
--- a/sheep/farm/snap.c
+++ b/sheep/farm/snap.c
@@ -57,7 +57,7 @@ int snap_log_write(uint32_t epoch, unsigned char *sha1)
 
 	fd = open(buf.buf, O_WRONLY | O_APPEND);
 	if (fd < 0) {
-		dprintf("%m\n");
+		sd_dprintf("%m\n");
 		goto out;
 	}
 
@@ -85,11 +85,11 @@ void *snap_log_read(int *out_nr)
 
 	fd = open(buf.buf, O_RDONLY);
 	if (fd < 0) {
-		dprintf("%m\n");
+		sd_dprintf("%m\n");
 		goto out;
 	}
 	if (fstat(fd, &st) < 0) {
-		dprintf("%m\n");
+		sd_dprintf("%m\n");
 		goto out_close;
 	}
 
@@ -113,7 +113,7 @@ void *snap_file_read(unsigned char *sha1, struct sha1_file_hdr *outhdr)
 {
 	void *buffer = NULL;
 
-	dprintf("%s\n", sha1_to_hex(sha1));
+	sd_dprintf("%s\n", sha1_to_hex(sha1));
 	buffer = sha1_file_read(sha1, outhdr);
 	if (!buffer)
 		return NULL;
@@ -145,7 +145,8 @@ int snap_file_write(uint32_t epoch, struct sd_node *nodes, int nr_nodes,
 		goto err;
 	}
 
-	dprintf("epoch: %" PRIu32 ", sha1: %s\n", epoch, sha1_to_hex(outsha1));
+	sd_dprintf("epoch: %" PRIu32 ", sha1: %s\n", epoch,
+		sha1_to_hex(outsha1));
 err:
 	strbuf_release(&buf);
 	return ret;
diff --git a/sheep/farm/trunk.c b/sheep/farm/trunk.c
index 10f361d..e7d1502 100644
--- a/sheep/farm/trunk.c
+++ b/sheep/farm/trunk.c
@@ -41,12 +41,12 @@ static int fill_entry_new_sha1(struct trunk_entry *entry)
 	strbuf_reset(&buf);
 
 	if (fd < 0) {
-		dprintf("%m\n");
+		sd_dprintf("%m\n");
 		ret = -1;
 		goto out;
 	}
 	if (!strbuf_read(&buf, fd, SD_DATA_OBJ_SIZE) == SD_DATA_OBJ_SIZE) {
-		dprintf("strbuf_read fail to read full\n");
+		sd_dprintf("strbuf_read fail to read full\n");
 		ret = -1;
 		goto out_close;
 	}
@@ -57,7 +57,7 @@ static int fill_entry_new_sha1(struct trunk_entry *entry)
 		ret = -1;
 		goto out_close;
 	}
-	dprintf("data sha1:%s, %"PRIx64"\n", sha1_to_hex(entry->sha1),
+	sd_dprintf("data sha1:%s, %"PRIx64"\n", sha1_to_hex(entry->sha1),
 		entry->oid);
 out_close:
 	close(fd);
@@ -120,7 +120,7 @@ int trunk_file_write(unsigned char *outsha1)
 		ret = -1;
 		goto out;
 	}
-	dprintf("trunk sha1: %s\n", sha1_to_hex(outsha1));
+	sd_dprintf("trunk sha1: %s\n", sha1_to_hex(outsha1));
 out:
 	closedir(dir);
 	strbuf_release(&buf);
@@ -131,7 +131,7 @@ void *trunk_file_read(unsigned char *sha1, struct sha1_file_hdr *outhdr)
 {
 	void *buffer;
 
-	dprintf("%s\n", sha1_to_hex(sha1));
+	sd_dprintf("%s\n", sha1_to_hex(sha1));
 	buffer = sha1_file_read(sha1, outhdr);
 	if (!buffer)
 		return NULL;
diff --git a/sheep/gateway.c b/sheep/gateway.c
index 3bca273..d62347c 100644
--- a/sheep/gateway.c
+++ b/sheep/gateway.c
@@ -55,7 +55,7 @@ int gateway_read_obj(struct request *req)
 		if (ret == SD_RES_SUCCESS)
 			goto out;
 
-		eprintf("local read fail %x\n", ret);
+		sd_eprintf("local read fail %x\n", ret);
 		break;
 	}
 
@@ -108,7 +108,7 @@ struct write_info {
 
 static inline void write_info_update(struct write_info *wi, int pos)
 {
-	dprintf("%d, %d\n", wi->nr_sent, pos);
+	sd_dprintf("%d, %d\n", wi->nr_sent, pos);
 	wi->nr_sent--;
 	memmove(wi->ent + pos, wi->ent + pos + 1,
 		sizeof(struct write_info_entry) * (wi->nr_sent - pos));
@@ -162,7 +162,7 @@ again:
 
 		panic("%m\n");
 	} else if (pollret == 0) {
-		eprintf("poll timeout %d\n", wi->nr_sent);
+		sd_eprintf("poll timeout %d\n", wi->nr_sent);
 		/*
 		 * If IO NIC is down, epoch isn't incremented, so we can't retry
 		 * for ever.
@@ -187,14 +187,14 @@ again:
 			break;
 	if (i < nr_sent) {
 		int re = pi.pfds[i].revents;
-		dprintf("%d, revents %x\n", i, re);
+		sd_dprintf("%d, revents %x\n", i, re);
 		if (re & (POLLERR | POLLHUP | POLLNVAL)) {
 			err_ret = SD_RES_NETWORK_ERROR;
 			finish_one_write_err(wi, i);
 			goto finish_write;
 		}
 		if (do_read(pi.pfds[i].fd, rsp, sizeof(*rsp))) {
-			eprintf("remote node might have gone away\n");
+			sd_eprintf("remote node might have gone away\n");
 			err_ret = SD_RES_NETWORK_ERROR;
 			finish_one_write_err(wi, i);
 			goto finish_write;
@@ -202,7 +202,7 @@ again:
 
 		ret = rsp->result;
 		if (ret != SD_RES_SUCCESS) {
-			eprintf("fail %"PRIx32"\n", ret);
+			sd_eprintf("fail %"PRIx32"\n", ret);
 			err_ret = ret;
 		}
 		finish_one_write(wi, i);
@@ -265,7 +265,7 @@ static int gateway_forward_request(struct request *req, bool all_node)
 	struct sd_req hdr;
 	const struct sd_node *target_nodes[SD_MAX_NODES];
 
-	dprintf("%"PRIx64"\n", oid);
+	sd_dprintf("%"PRIx64"\n", oid);
 
 	gateway_init_fwd_hdr(&hdr, &req->rq);
 	op = get_sd_op(hdr.opcode);
@@ -294,7 +294,7 @@ static int gateway_forward_request(struct request *req, bool all_node)
 		if (ret) {
 			sheep_del_sockfd(nid, sfd);
 			err_ret = SD_RES_NETWORK_ERROR;
-			dprintf("fail %d\n", ret);
+			sd_dprintf("fail %d\n", ret);
 			break;
 		}
 		write_info_advance(&wi, nid, sfd);
@@ -305,12 +305,12 @@ static int gateway_forward_request(struct request *req, bool all_node)
 		ret = sheep_do_op_work(op, req);
 
 		if (ret != SD_RES_SUCCESS) {
-			eprintf("fail to write local %"PRIx32"\n", ret);
+			sd_eprintf("fail to write local %"PRIx32"\n", ret);
 			err_ret = ret;
 		}
 	}
 
-	dprintf("nr_sent %d, err %x\n", wi.nr_sent, err_ret);
+	sd_dprintf("nr_sent %d, err %x\n", wi.nr_sent, err_ret);
 	if (wi.nr_sent > 0) {
 		ret = wait_forward_request(&wi, req);
 		if (ret != SD_RES_SUCCESS)
diff --git a/sheep/group.c b/sheep/group.c
index 9462180..f32f625 100644
--- a/sheep/group.c
+++ b/sheep/group.c
@@ -95,7 +95,7 @@ bool have_enough_zones(void)
 
 	max_copies = get_max_copy_number();
 
-	dprintf("flags %d, nr_zones %d, min copies %d\n",
+	sd_dprintf("flags %d, nr_zones %d, min copies %d\n",
 		sys->flags, current_vnode_info->nr_zones, max_copies);
 
 	if (!current_vnode_info->nr_zones)
@@ -240,7 +240,7 @@ static struct vdi_op_message *prepare_cluster_msg(struct request *req,
 
 	msg = zalloc(size);
 	if (!msg) {
-		eprintf("failed to allocate memory\n");
+		sd_eprintf("failed to allocate memory\n");
 		return NULL;
 	}
 
@@ -262,7 +262,7 @@ static void cluster_op_done(struct work *work)
 
 	cluster_op_running = false;
 
-	dprintf("%s (%p)\n", op_name(req->op), req);
+	sd_dprintf("%s (%p)\n", op_name(req->op), req);
 
 	msg = prepare_cluster_msg(req, &size);
 	if (!msg)
@@ -312,7 +312,7 @@ bool sd_block_handler(const struct sd_node *sender)
  */
 void queue_cluster_request(struct request *req)
 {
-	eprintf("%s (%p)\n", op_name(req->op), req);
+	sd_eprintf("%s (%p)\n", op_name(req->op), req);
 
 	if (has_process_work(req->op)) {
 		list_add_tail(&req->pending_list, &sys->pending_block_list);
@@ -466,32 +466,32 @@ static int cluster_sanity_check(struct join_message *jm)
 	uint8_t local_nr_copies;
 
 	if (get_cluster_copies(&local_nr_copies)) {
-		eprintf("failed to get nr_copies\n");
+		sd_eprintf("failed to get nr_copies\n");
 		return CJ_RES_FAIL;
 	}
 
 	if (jm->ctime != local_ctime) {
-		eprintf("joining node ctime doesn't match: %"
+		sd_eprintf("joining node ctime doesn't match: %"
 			PRIu64 " vs %" PRIu64 "\n",
 			jm->ctime, local_ctime);
 		return CJ_RES_FAIL;
 	}
 
 	if (jm->epoch > local_epoch) {
-		eprintf("joining node epoch too large: %"
+		sd_eprintf("joining node epoch too large: %"
 			PRIu32 " vs %" PRIu32 "\n",
 			jm->epoch, local_epoch);
 		return CJ_RES_FAIL;
 	}
 
 	if (jm->nr_copies != local_nr_copies) {
-		eprintf("joining node nr_copies doesn't match: %u vs %u\n",
+		sd_eprintf("joining node nr_copies doesn't match: %u vs %u\n",
 			jm->nr_copies, local_nr_copies);
 		return CJ_RES_FAIL;
 	}
 
 	if (jm->cluster_flags != sys->flags) {
-		eprintf("joining node cluster_flags don't match: %u vs %u\n",
+		sd_eprintf("joining node cluster_flags don't match: %u vs %u\n",
 			jm->cluster_flags, sys->flags);
 		return CJ_RES_FAIL;
 	}
@@ -513,7 +513,7 @@ static int cluster_wait_for_join_check(const struct sd_node *joined,
 	ret = cluster_sanity_check(jm);
 	if (ret != CJ_RES_SUCCESS)  {
 		if (jm->epoch > sys->epoch) {
-			eprintf("transfer mastership (%d, %d)\n",
+			sd_eprintf("transfer mastership (%d, %d)\n",
 				jm->epoch, sys->epoch);
 			return CJ_RES_MASTER_TRANSFER;
 		}
@@ -526,7 +526,7 @@ static int cluster_wait_for_join_check(const struct sd_node *joined,
 		return CJ_RES_FAIL;
 
 	if (jm->epoch < local_epoch) {
-		eprintf("joining node epoch too small: %"
+		sd_eprintf("joining node epoch too small: %"
 			PRIu32 " vs %" PRIu32 "\n",
 			jm->epoch, local_epoch);
 
@@ -537,7 +537,7 @@ static int cluster_wait_for_join_check(const struct sd_node *joined,
 	}
 
 	if (jm->nr_nodes != nr_local_entries) {
-		eprintf("epoch log entries do not match: %d vs %d\n",
+		sd_eprintf("epoch log entries do not match: %d vs %d\n",
 			jm->nr_nodes, nr_local_entries);
 		return CJ_RES_FAIL;
 	}
@@ -545,7 +545,7 @@ static int cluster_wait_for_join_check(const struct sd_node *joined,
 
 	if (memcmp(jm->nodes, local_entries,
 		   sizeof(jm->nodes[0]) * jm->nr_nodes) != 0) {
-		eprintf("epoch log entries does not match\n");
+		sd_eprintf("epoch log entries does not match\n");
 		return CJ_RES_FAIL;
 	}
 
@@ -617,7 +617,7 @@ static int get_vdis_from(struct sd_node *node)
 	rlen = SD_DATA_OBJ_SIZE; /* FIXME */
 	vc = zalloc(rlen);
 	if (!vc) {
-		vprintf(SDOG_ERR, "unable to allocate memory\n");
+		sd_printf(SDOG_ERR, "unable to allocate memory\n");
 		ret = SD_RES_NO_MEM;
 		goto out;
 	}
@@ -752,14 +752,14 @@ static void get_vdis(const struct sd_node *nodes, size_t nr_nodes)
 
 void wait_get_vdis_done(void)
 {
-	dprintf("waiting for vdi list\n");
+	sd_dprintf("waiting for vdi list\n");
 
 	pthread_mutex_lock(&wait_vdis_lock);
 	while (!is_vdi_list_ready)
 		pthread_cond_wait(&wait_vdis_cond, &wait_vdis_lock);
 	pthread_mutex_unlock(&wait_vdis_lock);
 
-	dprintf("vdi list ready\n");
+	sd_dprintf("vdi list ready\n");
 }
 
 void recalculate_vnodes(struct sd_node *nodes, int nr_nodes)
@@ -783,7 +783,7 @@ void recalculate_vnodes(struct sd_node *nodes, int nr_nodes)
 	for (i = 0; i < nr_nodes; i++) {
 		factor = (float)nodes[i].space / (float)avg_size;
 		nodes[i].nr_vnodes = rintf(SD_DEFAULT_VNODES * factor);
-		dprintf("node %d has %d vnodes, free space %" PRIu64 "\n",
+		sd_dprintf("node %d has %d vnodes, free space %" PRIu64 "\n",
 			nodes[i].nid.port, nodes[i].nr_vnodes, nodes[i].space);
 	}
 }
@@ -795,8 +795,8 @@ static void update_cluster_info(const struct join_message *msg,
 {
 	struct vnode_info *old_vnode_info;
 
-	eprintf("status = %d, epoch = %d, finished: %d\n", msg->cluster_status,
-		msg->epoch, sys->join_finished);
+	sd_eprintf("status = %d, epoch = %d, finished: %d\n",
+		msg->cluster_status, msg->epoch, sys->join_finished);
 
 	if (!sys->join_finished)
 		finish_join(msg, joined, nodes, nr_nodes);
@@ -866,7 +866,7 @@ void sd_notify_handler(const struct sd_node *sender, void *data,
 	int ret = msg->rsp.result;
 	struct request *req = NULL;
 
-	dprintf("op %s, size: %zd, from: %s\n",
+	sd_dprintf("op %s, size: %zd, from: %s\n",
 		op_name(op), data_len, node_to_str(sender));
 
 	if (node_is_local(sender)) {
@@ -901,7 +901,7 @@ enum cluster_join_result sd_check_join_cb(const struct sd_node *joining,
 	int ret;
 
 	if (jm->proto_ver != SD_SHEEP_PROTO_VER) {
-		eprintf("%s: invalid protocol version: %d\n", __func__,
+		sd_eprintf("%s: invalid protocol version: %d\n", __func__,
 			jm->proto_ver);
 		return CJ_RES_FAIL;
 	}
@@ -916,7 +916,7 @@ enum cluster_join_result sd_check_join_cb(const struct sd_node *joining,
 		 * becomes the master without sending JOIN.
 		 */
 
-		vprintf(SDOG_DEBUG, "%s\n", node_to_str(&sys->this_node));
+		sd_printf(SDOG_DEBUG, "%s\n", node_to_str(&sys->this_node));
 
 		jm->cluster_status = sys->status;
 
@@ -925,7 +925,7 @@ enum cluster_join_result sd_check_join_cb(const struct sd_node *joining,
 			return CJ_RES_SUCCESS;
 
 		if (sys->status != SD_STATUS_WAIT_FOR_JOIN) {
-			eprintf("unexpected cluster status 0x%x\n",
+			sd_eprintf("unexpected cluster status 0x%x\n",
 				sys->status);
 			return CJ_RES_FAIL;
 		}
@@ -965,11 +965,11 @@ enum cluster_join_result sd_check_join_cb(const struct sd_node *joining,
 		ret = cluster_running_check(jm);
 		break;
 	default:
-		eprintf("invalid system status: 0x%x\n", sys->status);
+		sd_eprintf("invalid system status: 0x%x\n", sys->status);
 		abort();
 	}
 
-	eprintf("%s: ret = 0x%x, cluster_status = 0x%x\n",
+	sd_eprintf("%s: ret = 0x%x, cluster_status = 0x%x\n",
 		addr_to_str(str, sizeof(str), joining->nid.addr, joining->nid.port),
 		ret, jm->cluster_status);
 
@@ -1011,7 +1011,7 @@ static int send_join_request(struct sd_node *ent)
 
 	ret = sys->cdrv->join(ent, msg, get_join_message_size(msg));
 
-	vprintf(SDOG_INFO, "%s\n", node_to_str(&sys->this_node));
+	sd_printf(SDOG_INFO, "%s\n", node_to_str(&sys->this_node));
 
 	free(msg);
 
@@ -1030,7 +1030,7 @@ void sd_join_handler(const struct sd_node *joined,
 
 	if (node_eq(joined, &sys->this_node)) {
 		if (result == CJ_RES_FAIL) {
-			eprintf("Failed to join, exiting.\n");
+			sd_eprintf("Failed to join, exiting.\n");
 			sys->cdrv->leave();
 			exit(1);
 		}
@@ -1041,9 +1041,9 @@ void sd_join_handler(const struct sd_node *joined,
 		add_delayed_node(le, joined);
 		/*FALLTHRU*/
 	case CJ_RES_SUCCESS:
-		dprintf("join %s\n", node_to_str(joined));
+		sd_dprintf("join %s\n", node_to_str(joined));
 		for (i = 0; i < nr_members; i++)
-			dprintf("[%x] %s\n", i, node_to_str(members + i));
+			sd_dprintf("[%x] %s\n", i, node_to_str(members + i));
 
 		if (sys->status == SD_STATUS_SHUTDOWN)
 			break;
@@ -1052,7 +1052,7 @@ void sd_join_handler(const struct sd_node *joined,
 
 		if (node_eq(joined, &sys->this_node))
 			/* this output is used for testing */
-			vprintf(SDOG_DEBUG, "join Sheepdog cluster\n");
+			sd_printf(SDOG_DEBUG, "join Sheepdog cluster\n");
 		break;
 	case CJ_RES_FAIL:
 		if (sys->status != SD_STATUS_WAIT_FOR_JOIN)
@@ -1066,7 +1066,7 @@ void sd_join_handler(const struct sd_node *joined,
 		nr_failed = get_nodes_nr_from(&sys->failed_nodes);
 		nr_delayed_nodes = get_nodes_nr_from(&sys->delayed_nodes);
 
-		dprintf("%d == %d + %d\n", nr_local, nr, nr_failed);
+		sd_dprintf("%d == %d + %d\n", nr_local, nr, nr_failed);
 		if (nr_local == nr + nr_failed - nr_delayed_nodes) {
 			sys->status = SD_STATUS_OK;
 			log_current_epoch();
@@ -1091,7 +1091,7 @@ void sd_join_handler(const struct sd_node *joined,
 		nr_failed = get_nodes_nr_from(&sys->failed_nodes);
 		nr_delayed_nodes = get_nodes_nr_from(&sys->delayed_nodes);
 
-		dprintf("%d == %d + %d\n", nr_local, nr, nr_failed);
+		sd_dprintf("%d == %d + %d\n", nr_local, nr, nr_failed);
 		if (nr_local == nr + nr_failed - nr_delayed_nodes) {
 			sys->status = SD_STATUS_OK;
 			log_current_epoch();
@@ -1099,7 +1099,7 @@ void sd_join_handler(const struct sd_node *joined,
 
 		if (node_eq(joined, &sys->this_node))
 			/* this output is used for testing */
-			vprintf(SDOG_DEBUG, "join Sheepdog cluster\n");
+			sd_printf(SDOG_DEBUG, "join Sheepdog cluster\n");
 		break;
 	}
 }
@@ -1110,9 +1110,9 @@ void sd_leave_handler(const struct sd_node *left, const struct sd_node *members,
 	struct vnode_info *old_vnode_info;
 	int i;
 
-	dprintf("leave %s\n", node_to_str(left));
+	sd_dprintf("leave %s\n", node_to_str(left));
 	for (i = 0; i < nr_members; i++)
-		dprintf("[%x] %s\n", i, node_to_str(members + i));
+		sd_dprintf("[%x] %s\n", i, node_to_str(members + i));
 
 	if (sys->status == SD_STATUS_SHUTDOWN)
 		return;
@@ -1147,11 +1147,11 @@ int create_cluster(int port, int64_t zone, int nr_vnodes,
 	if (!sys->cdrv) {
 		sys->cdrv = find_cdrv("corosync");
 		if (sys->cdrv)
-			dprintf("use corosync cluster driver as default\n");
+			sd_dprintf("use corosync cluster driver as default\n");
 		else {
 			/* corosync cluster driver is not compiled */
 			sys->cdrv = find_cdrv("local");
-			dprintf("use local cluster driver as default\n");
+			sd_dprintf("use local cluster driver as default\n");
 		}
 	}
 
@@ -1176,7 +1176,7 @@ int create_cluster(int port, int64_t zone, int nr_vnodes,
 		sys->this_node.zone = b[0] | b[1] << 8 | b[2] << 16 | b[3] << 24;
 	} else
 		sys->this_node.zone = zone;
-	dprintf("zone id = %u\n", sys->this_node.zone);
+	sd_dprintf("zone id = %u\n", sys->this_node.zone);
 
 	sys->this_node.space = sys->disk_space;
 
diff --git a/sheep/journal.c b/sheep/journal.c
index 8c115c1..e9ec3b2 100644
--- a/sheep/journal.c
+++ b/sheep/journal.c
@@ -43,7 +43,7 @@ static int jrnl_open(struct jrnl_descriptor *jd, const char *path)
 	jd->fd = open(path, O_RDONLY);
 
 	if (jd->fd < 0) {
-		eprintf("failed to open %s: %m\n", jd->path);
+		sd_eprintf("failed to open %s: %m\n", jd->path);
 		if (errno == ENOENT)
 			return SD_RES_NO_OBJ;
 		else
@@ -67,7 +67,7 @@ static int jrnl_create(struct jrnl_descriptor *jd, const char *jrnl_dir)
 	jd->fd = mkostemp(jd->path, O_DSYNC);
 
 	if (jd->fd < 0) {
-		eprintf("failed to create %s: %m\n", jd->path);
+		sd_eprintf("failed to create %s: %m\n", jd->path);
 		return SD_RES_UNKNOWN;
 	}
 
@@ -80,7 +80,7 @@ static int jrnl_remove(struct jrnl_descriptor *jd)
 
 	ret = unlink(jd->path);
 	if (ret) {
-		eprintf("failed to remove %s: %m\n", jd->path);
+		sd_eprintf("failed to remove %s: %m\n", jd->path);
 		ret = SD_RES_EIO;
 	} else
 		ret = SD_RES_SUCCESS;
@@ -227,12 +227,12 @@ int jrnl_recover(const char *jrnl_dir)
 	struct dirent *d;
 	char jrnl_file_path[PATH_MAX];
 
-	eprintf("opening the directory %s\n", jrnl_dir);
+	sd_eprintf("opening the directory %s\n", jrnl_dir);
 	dir = opendir(jrnl_dir);
 	if (!dir)
 		return -1;
 
-	vprintf(SDOG_NOTICE, "starting journal recovery\n");
+	sd_printf(SDOG_NOTICE, "starting journal recovery\n");
 	while ((d = readdir(dir))) {
 		struct jrnl_descriptor jd;
 		uint32_t end_mark = 0;
@@ -245,22 +245,22 @@ int jrnl_recover(const char *jrnl_dir)
 			 jrnl_dir, d->d_name);
 		ret = jrnl_open(&jd, jrnl_file_path);
 		if (ret) {
-			eprintf("unable to open the journal file %s for reading\n",
-				jrnl_file_path);
+			sd_eprintf("unable to open the journal file %s for"
+				" reading\n", jrnl_file_path);
 			goto end_while_3;
 		}
 
 		ret = xpread(jd.fd, &jd.head, sizeof(jd.head), 0);
 		if (ret != sizeof(jd.head)) {
-			eprintf("can't read journal head\n");
+			sd_eprintf("can't read journal head\n");
 			goto end_while_2;
 		}
 
 		ret = xpread(jd.fd, &end_mark, sizeof(end_mark),
 				sizeof(jd.head) + jd.head.size);
 		if (ret != sizeof(end_mark)) {
-			eprintf("can't read journal end mark for object %s\n",
-				jd.head.target_path);
+			sd_eprintf("can't read journal end mark for object"
+				" %s\n", jd.head.target_path);
 			goto end_while_2;
 		}
 
@@ -269,13 +269,13 @@ int jrnl_recover(const char *jrnl_dir)
 
 		jd.target_fd = open(jd.head.target_path, O_DSYNC | O_RDWR);
 		if (jd.target_fd < 0) {
-			eprintf("unable to open the object file %s for recovery\n",
-				jd.head.target_path);
+			sd_eprintf("unable to open the object file %s for"
+				" recovery\n", jd.head.target_path);
 			goto end_while_2;
 		}
 		ret = jrnl_apply_to_target_object(&jd);
 		if (ret)
-			eprintf("unable to recover the object %s\n",
+			sd_eprintf("unable to recover the object %s\n",
 				jd.head.target_path);
 
 		close(jd.target_fd);
@@ -283,12 +283,12 @@ int jrnl_recover(const char *jrnl_dir)
 end_while_2:
 		jrnl_close(&jd);
 end_while_3:
-		vprintf(SDOG_INFO, "recovered the object %s from the journal\n",
-			jrnl_file_path);
+		sd_printf(SDOG_INFO, "recovered the object %s from"
+			" the journal\n", jrnl_file_path);
 		jrnl_remove(&jd);
 	}
 	closedir(dir);
-	vprintf(SDOG_NOTICE, "journal recovery complete\n");
+	sd_printf(SDOG_NOTICE, "journal recovery complete\n");
 
 	return 0;
 }
diff --git a/sheep/journal_file.c b/sheep/journal_file.c
index 9ed0686..799f01f 100644
--- a/sheep/journal_file.c
+++ b/sheep/journal_file.c
@@ -61,11 +61,11 @@ static int create_journal_file(const char *root, const char *name)
 	sprintf(path, "%s/%s", root, name);
 	fd = open(path, flags, 0644);
 	if (fd < 0) {
-		eprintf("open %s %m\n", name);
+		sd_eprintf("open %s %m\n", name);
 		return -1;
 	}
 	if (prealloc(fd, jfile_size) < 0) {
-		eprintf("prealloc %s %m\n", name);
+		sd_eprintf("prealloc %s %m\n", name);
 		return -1;
 	}
 
@@ -86,19 +86,19 @@ static int get_old_new_jfile(const char *p, int *old, int *new)
 		if (errno == ENOENT)
 			return 0;
 
-		eprintf("open1 %m\n");
+		sd_eprintf("open1 %m\n");
 		return -1;
 	}
 	sprintf(path, "%s/%s", p, jfile_name[1]);
 	fd2 = open(path, flags);
 	if (fd2 < 0) {
-		eprintf("open2 %m\n");
+		sd_eprintf("open2 %m\n");
 		close(fd1);
 		return -1;
 	}
 
 	if (fstat(fd1, &st1) < 0 || fstat(fd2, &st2) < 0) {
-		eprintf("stat %m\n");
+		sd_eprintf("stat %m\n");
 		goto out;
 	}
 
@@ -136,7 +136,7 @@ static int replay_journal_entry(struct journal_descriptor *jd)
 	void *buf;
 	char *p = (char *)jd;
 
-	dprintf("%"PRIx64", size %"PRIu64", off %"PRIu64", %d\n",
+	sd_dprintf("%"PRIx64", size %"PRIu64", off %"PRIu64", %d\n",
 		jd->oid, jd->size, jd->offset, jd->create);
 
 	if (jd->create)
@@ -144,7 +144,7 @@ static int replay_journal_entry(struct journal_descriptor *jd)
 	sprintf(path, "%s%016" PRIx64, obj_path, jd->oid);
 	fd = open(path, flags, def_fmode);
 	if (fd < 0) {
-		eprintf("open %m\n");
+		sd_eprintf("open %m\n");
 		return -1;
 	}
 
@@ -158,7 +158,7 @@ static int replay_journal_entry(struct journal_descriptor *jd)
 	memcpy(buf, p, jd->size);
 	size = xpwrite(fd, buf, jd->size, jd->offset);
 	if (size != jd->size) {
-		eprintf("write %zd, size %zu, errno %m\n", size, jd->size);
+		sd_eprintf("write %zd, size %zu, errno %m\n", size, jd->size);
 		ret = -1;
 		goto out;
 	}
@@ -175,14 +175,14 @@ static int do_recover(int fd)
 	struct stat st;
 
 	if (fstat(fd, &st) < 0) {
-		eprintf("fstat %m\n");
+		sd_eprintf("fstat %m\n");
 		return -1;
 	}
 
 	map = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
 	close(fd);
 	if (map == MAP_FAILED) {
-		eprintf("%m\n");
+		sd_eprintf("%m\n");
 		return -1;
 	}
 
@@ -296,7 +296,7 @@ static void switch_journal_file(void)
 
 retry:
 	if (!uatomic_set_true(&jfile.in_commit)) {
-		eprintf("journal file in committing, "
+		sd_eprintf("journal file in committing, "
 			"you might need enlarge jfile size\n");
 		usleep(100000); /* Wait until committing is finished */
 		goto retry;
@@ -351,7 +351,7 @@ int journal_file_write(uint64_t oid, const char *buf, size_t size,
 	}
 	memcpy(p, &marker, JOURNAL_MARKER_SIZE);
 
-	dprintf("oid %lx, pos %zu, wsize %zu\n", oid, jfile.pos, wsize);
+	sd_dprintf("oid %lx, pos %zu, wsize %zu\n", oid, jfile.pos, wsize);
 	/*
 	 * Concurrent writes with the same FD is okay because we don't have any
 	 * critical sections that need lock inside kernel write path, since we
@@ -361,7 +361,7 @@ int journal_file_write(uint64_t oid, const char *buf, size_t size,
 	 */
 	written = xpwrite(jfile.fd, wbuffer, wsize, woff);
 	if (written != wsize) {
-		eprintf("failed, written %zd, len %zu\n", written, wsize);
+		sd_eprintf("failed, written %zd, len %zu\n", written, wsize);
 		ret = err_to_sderr(oid, errno);
 		goto out;
 	}
diff --git a/sheep/migrate.c b/sheep/migrate.c
index 51b5fa9..a8a7617 100644
--- a/sheep/migrate.c
+++ b/sheep/migrate.c
@@ -73,7 +73,7 @@ static int backup_file(char *fname, char *suffix)
 	fd = open(fname, O_RDONLY);
 	if (fd < 0) {
 		if (errno != ENOENT) {
-			eprintf("failed to open %s, %m\n", fname);
+			sd_eprintf("failed to open %s, %m\n", fname);
 			ret = -1;
 		} else
 			ret = 0;
@@ -82,7 +82,7 @@ static int backup_file(char *fname, char *suffix)
 
 	ret = stat(fname, &stbuf);
 	if (ret < 0) {
-		eprintf("failed to stat %s, %m\n", fname);
+		sd_eprintf("failed to stat %s, %m\n", fname);
 		goto out;
 	}
 	len = stbuf.st_size;
@@ -90,7 +90,7 @@ static int backup_file(char *fname, char *suffix)
 	buf = xmalloc(len);
 	ret = xread(fd, buf, len);
 	if (ret != len) {
-		eprintf("failed to read %s, %d %m\n", fname, ret);
+		sd_eprintf("failed to read %s, %d %m\n", fname, ret);
 		ret = -1;
 		goto out;
 	}
@@ -99,14 +99,14 @@ static int backup_file(char *fname, char *suffix)
 
 	fd = open(dst_file, O_CREAT | O_WRONLY | O_DSYNC, 0644);
 	if (fd < 0) {
-		eprintf("failed to create %s, %m\n", dst_file);
+		sd_eprintf("failed to create %s, %m\n", dst_file);
 		ret = -1;
 		goto out;
 	}
 
 	ret = xwrite(fd, buf, len);
 	if (ret != len) {
-		eprintf("failed to write to %s, %d %m\n", dst_file, ret);
+		sd_eprintf("failed to write to %s, %d %m\n", dst_file, ret);
 		ret = -1;
 	}
 out:
@@ -154,14 +154,14 @@ static int migrate_from_v0_to_v1(void)
 
 	fd = open(config_path, O_RDWR);
 	if (fd < 0) {
-		eprintf("failed to open config file, %m\n");
+		sd_eprintf("failed to open config file, %m\n");
 		return -1;
 	}
 
 	memset(&config, 0, sizeof(config));
 	ret = xread(fd, &config, sizeof(config));
 	if (ret < 0) {
-		eprintf("failed to read config file, %m\n");
+		sd_eprintf("failed to read config file, %m\n");
 		close(fd);
 		return ret;
 	}
@@ -169,7 +169,7 @@ static int migrate_from_v0_to_v1(void)
 	config.version = 1;
 	ret = xpwrite(fd, &config, sizeof(config), 0);
 	if (ret != sizeof(config)) {
-		eprintf("failed to write config data, %m\n");
+		sd_eprintf("failed to write config data, %m\n");
 		close(fd);
 		return -1;
 	}
@@ -177,7 +177,7 @@ static int migrate_from_v0_to_v1(void)
 	/* 0.5.1 could wrongly extend the config file, so truncate it here */
 	ret = ftruncate(fd, sizeof(config));
 	if (ret != 0) {
-		eprintf("failed to truncate config data, %m\n");
+		sd_eprintf("failed to truncate config data, %m\n");
 		close(fd);
 		return -1;
 	}
@@ -205,13 +205,15 @@ static int migrate_from_v0_to_v1(void)
 			if (errno == ENOENT)
 				continue;
 
-			eprintf("failed to open epoch %"PRIu32" log\n", epoch);
+			sd_eprintf("failed to open epoch %"PRIu32" log\n",
+				epoch);
 			return -1;
 		}
 
 		ret = xread(fd, nodes_v0, sizeof(nodes_v0));
 		if (ret < 0) {
-			eprintf("failed to read epoch %"PRIu32" log\n", epoch);
+			sd_eprintf("failed to read epoch %"PRIu32" log\n",
+				epoch);
 			close(fd);
 			return ret;
 		}
@@ -228,7 +230,8 @@ static int migrate_from_v0_to_v1(void)
 		len = sizeof(nodes_v1[0]) * nr_nodes;
 		ret = xpwrite(fd, nodes_v1, len, 0);
 		if (ret != len) {
-			eprintf("failed to write epoch %"PRIu32" log\n", epoch);
+			sd_eprintf("failed to write epoch %"PRIu32" log\n",
+				epoch);
 			close(fd);
 			return -1;
 		}
@@ -237,8 +240,8 @@ static int migrate_from_v0_to_v1(void)
 
 		ret = xpwrite(fd, t, sizeof(*t), len);
 		if (ret != sizeof(*t)) {
-			eprintf("failed to write time to epoch %"PRIu32" log\n",
-				epoch);
+			sd_eprintf("failed to write time to epoch %"
+				PRIu32" log\n", epoch);
 			close(fd);
 			return -1;
 		}
@@ -261,7 +264,7 @@ int sd_migrate_store(int from, int to)
 
 	ret = backup_store();
 	if (ret != 0) {
-		eprintf("failed to backup the old store\n");
+		sd_eprintf("failed to backup the old store\n");
 		return ret;
 	}
 
diff --git a/sheep/object_cache.c b/sheep/object_cache.c
index fab6ad4..f0ac231 100644
--- a/sheep/object_cache.c
+++ b/sheep/object_cache.c
@@ -203,9 +203,10 @@ static int remove_cache_object(struct object_cache *oc, uint32_t idx)
 
 	sprintf(path, "%s/%06"PRIx32"/%08"PRIx32, object_cache_dir,
 		oc->vid, idx);
-	dprintf("removing cache object %"PRIx64"\n", idx_to_oid(oc->vid, idx));
+	sd_dprintf("removing cache object %"PRIx64"\n",
+		idx_to_oid(oc->vid, idx));
 	if (unlink(path) < 0) {
-		eprintf("failed to remove cached object %m\n");
+		sd_eprintf("failed to remove cached object %m\n");
 		if (errno == ENOENT)
 			return SD_RES_SUCCESS;
 		ret = SD_RES_EIO;
@@ -229,7 +230,7 @@ static int read_cache_object_noupdate(uint32_t vid, uint32_t idx, void *buf,
 
 	fd = open(p, flags, def_fmode);
 	if (fd < 0) {
-		eprintf("%m\n");
+		sd_eprintf("%m\n");
 		ret = SD_RES_EIO;
 		goto out;
 	}
@@ -237,7 +238,7 @@ static int read_cache_object_noupdate(uint32_t vid, uint32_t idx, void *buf,
 	size = xpread(fd, buf, count, offset);
 
 	if (size != count) {
-		eprintf("size %zu, count:%zu, offset %jd %m\n",
+		sd_eprintf("size %zu, count:%zu, offset %jd %m\n",
 			size, count, (intmax_t)offset);
 		ret = SD_RES_EIO;
 		goto out_close;
@@ -262,7 +263,7 @@ static int write_cache_object_noupdate(uint32_t vid, uint32_t idx, void *buf,
 
 	fd = open(p, flags, def_fmode);
 	if (fd < 0) {
-		eprintf("%m\n");
+		sd_eprintf("%m\n");
 		ret = SD_RES_EIO;
 		goto out;
 	}
@@ -270,7 +271,7 @@ static int write_cache_object_noupdate(uint32_t vid, uint32_t idx, void *buf,
 	size = xpwrite(fd, buf, count, offset);
 
 	if (size != count) {
-		eprintf("size %zu, count:%zu, offset %jd %m\n",
+		sd_eprintf("size %zu, count:%zu, offset %jd %m\n",
 			size, count, (intmax_t)offset);
 		ret = SD_RES_EIO;
 		goto out_close;
@@ -338,7 +339,8 @@ static int write_cache_object(struct object_cache_entry *entry, void *buf,
 
 	ret = exec_local_req(&hdr, buf);
 	if (ret != SD_RES_SUCCESS) {
-		eprintf("failed to write object %" PRIx64 ", %x\n", oid, ret);
+		sd_eprintf("failed to write object %" PRIx64 ", %x\n",
+			oid, ret);
 		return ret;
 	}
 out:
@@ -356,17 +358,17 @@ static int push_cache_object(uint32_t vid, uint32_t idx, uint64_t bmap,
 	uint64_t oid = idx_to_oid(vid, idx);
 	int first_bit, last_bit;
 
-	dprintf("%"PRIx64", create %d\n", oid, create);
+	sd_dprintf("%"PRIx64", create %d\n", oid, create);
 
 	if (!bmap) {
-		dprintf("WARN: nothing to flush\n");
+		sd_dprintf("WARN: nothing to flush\n");
 		return SD_RES_SUCCESS;
 	}
 
 	first_bit = ffsll(bmap) - 1;
 	last_bit = fls64(bmap) - 1;
 
-	dprintf("bmap:0x%"PRIx64", first_bit:%d, last_bit:%d\n",
+	sd_dprintf("bmap:0x%"PRIx64", first_bit:%d, last_bit:%d\n",
 		bmap, first_bit, last_bit);
 	offset = first_bit * CACHE_BLOCK_SIZE;
 	data_length = (last_bit - first_bit + 1) * CACHE_BLOCK_SIZE;
@@ -380,7 +382,7 @@ static int push_cache_object(uint32_t vid, uint32_t idx, uint64_t bmap,
 
 	buf = valloc(data_length);
 	if (buf == NULL) {
-		eprintf("failed to allocate memory\n");
+		sd_eprintf("failed to allocate memory\n");
 		goto out;
 	}
 
@@ -399,7 +401,7 @@ static int push_cache_object(uint32_t vid, uint32_t idx, uint64_t bmap,
 
 	ret = exec_local_req(&hdr, buf);
 	if (ret != SD_RES_SUCCESS)
-		eprintf("failed to push object %x\n", ret);
+		sd_eprintf("failed to push object %x\n", ret);
 out:
 	free(buf);
 	return ret;
@@ -429,11 +431,11 @@ static void do_reclaim_object(struct object_cache *oc)
 	list_for_each_entry_safe(entry, t, &oc->lru_head, lru_list) {
 		oid = idx_to_oid(oc->vid, entry_idx(entry));
 		if (uatomic_read(&entry->refcnt) > 0) {
-			dprintf("%"PRIx64" is in operation, skip...\n", oid);
+			sd_dprintf("%"PRIx64" is in operation, skip...\n", oid);
 			continue;
 		}
 		if (entry_is_dirty(entry)) {
-			dprintf("%"PRIx64" is dirty, skip...\n", oid);
+			sd_dprintf("%"PRIx64" is dirty, skip...\n", oid);
 			continue;
 		}
 		if (remove_cache_object(oc, entry_idx(entry))
@@ -441,7 +443,8 @@ static void do_reclaim_object(struct object_cache *oc)
 			continue;
 		free_cache_entry(entry, &oc->lru_tree);
 		cap = uatomic_sub_return(&gcache.capacity, CACHE_OBJECT_SIZE);
-		dprintf("%"PRIx64" reclaimed. capacity:%"PRId32"\n", oid, cap);
+		sd_dprintf("%"PRIx64" reclaimed. capacity:%"PRId32"\n",
+			oid, cap);
 		if (cap <= HIGH_WATERMARK)
 			break;
 	}
@@ -482,13 +485,14 @@ static void do_reclaim(struct work *work)
 			cap = uatomic_read(&gcache.capacity);
 			if (cap <= HIGH_WATERMARK) {
 				pthread_rwlock_unlock(&hashtable_lock[idx]);
-				dprintf("complete, capacity %"PRIu32"\n", cap);
+				sd_dprintf("complete, capacity %"PRIu32"\n",
+					cap);
 				return;
 			}
 		}
 		pthread_rwlock_unlock(&hashtable_lock[idx]);
 	}
-	dprintf("finished\n");
+	sd_dprintf("finished\n");
 }
 
 static void reclaim_done(struct work *work)
@@ -507,7 +511,7 @@ static int create_dir_for(uint32_t vid)
 	strbuf_addf(&buf, "/%06"PRIx32, vid);
 	if (mkdir(buf.buf, def_dmode) < 0)
 		if (errno != EEXIST) {
-			eprintf("%s, %m\n", buf.buf);
+			sd_eprintf("%s, %m\n", buf.buf);
 			ret = -1;
 			goto err;
 		}
@@ -594,7 +598,7 @@ static void add_to_lru_cache(struct object_cache *oc, uint32_t idx, bool create)
 {
 	struct object_cache_entry *entry = alloc_cache_entry(oc, idx);
 
-	dprintf("oid %"PRIx64" added\n", idx_to_oid(oc->vid, idx));
+	sd_dprintf("oid %"PRIx64" added\n", idx_to_oid(oc->vid, idx));
 
 	pthread_rwlock_wrlock(&oc->lock);
 	assert(!lru_tree_insert(&oc->lru_tree, entry));
@@ -614,7 +618,7 @@ static inline int lookup_path(char *path)
 
 	if (access(path, R_OK | W_OK) < 0) {
 		if (errno != ENOENT) {
-			dprintf("%m\n");
+			sd_dprintf("%m\n");
 			ret = SD_RES_EIO;
 		} else {
 			ret = SD_RES_NO_CACHE;
@@ -637,7 +641,7 @@ static int object_cache_lookup(struct object_cache *oc, uint32_t idx,
 	flags |= O_CREAT | O_TRUNC;
 	fd = open(path, flags, def_fmode);
 	if (fd < 0) {
-		dprintf("%s, %m\n", path);
+		sd_dprintf("%s, %m\n", path);
 		ret = SD_RES_EIO;
 		goto out;
 	}
@@ -667,10 +671,10 @@ static int create_cache_object(struct object_cache *oc, uint32_t idx,
 	fd = open(tmp_path, flags, def_fmode);
 	if (fd < 0) {
 		if (errno == EEXIST) {
-			dprintf("%08"PRIx32" already created\n", idx);
+			sd_dprintf("%08"PRIx32" already created\n", idx);
 			goto out;
 		}
-		dprintf("%m\n");
+		sd_dprintf("%m\n");
 		ret = SD_RES_EIO;
 		goto out;
 	}
@@ -680,7 +684,7 @@ static int create_cache_object(struct object_cache *oc, uint32_t idx,
 		ret = prealloc(fd, obj_size);
 		if (ret < 0) {
 			ret = SD_RES_EIO;
-			eprintf("%m\n");
+			sd_eprintf("%m\n");
 			goto out_close;
 		}
 	}
@@ -688,7 +692,8 @@ static int create_cache_object(struct object_cache *oc, uint32_t idx,
 	ret = xpwrite(fd, buffer, buf_size, offset);
 	if (ret != buf_size) {
 		ret = SD_RES_EIO;
-		eprintf("failed, vid %"PRIx32", idx %"PRIx32"\n", oc->vid, idx);
+		sd_eprintf("failed, vid %"PRIx32", idx %"PRIx32"\n",
+			oc->vid, idx);
 		goto out_close;
 	}
 	/* This is intended to take care of partial write due to crash */
@@ -700,12 +705,12 @@ static int create_cache_object(struct object_cache *oc, uint32_t idx,
 			ret = SD_RES_OID_EXIST;
 			goto out_close;
 		}
-		dprintf("failed to link %s to %s: %m\n", tmp_path, path);
+		sd_dprintf("failed to link %s to %s: %m\n", tmp_path, path);
 		ret = err_to_sderr(idx_to_oid(oc->vid, idx), errno);
 		goto out_close;
 	}
 	ret = SD_RES_SUCCESS;
-	dprintf("%08"PRIx32" size %zu\n", idx, obj_size);
+	sd_dprintf("%08"PRIx32" size %zu\n", idx, obj_size);
 out_close:
 	close(fd);
 	unlink(tmp_path);
@@ -735,7 +740,7 @@ static int object_cache_pull(struct object_cache *oc, uint32_t idx)
 	if (ret != SD_RES_SUCCESS)
 		goto err;
 
-	dprintf("oid %"PRIx64" pulled successfully\n", oid);
+	sd_dprintf("oid %"PRIx64" pulled successfully\n", oid);
 	ret = create_cache_object(oc, idx, buf, rsp->data_length,
 				  rsp->obj.offset, data_length);
 	/*
@@ -857,11 +862,11 @@ static int object_cache_flush_and_delete(struct object_cache *oc)
 	int ret = 0;
 	char p[PATH_MAX];
 
-	dprintf("%"PRIx32"\n", vid);
+	sd_dprintf("%"PRIx32"\n", vid);
 	sprintf(p, "%s/%06"PRIx32, object_cache_dir, vid);
 	dir = opendir(p);
 	if (!dir) {
-		dprintf("%m\n");
+		sd_dprintf("%m\n");
 		ret = -1;
 		goto out;
 	}
@@ -870,9 +875,9 @@ static int object_cache_flush_and_delete(struct object_cache *oc)
 		if (!strncmp(d->d_name, ".", 1))
 			continue;
 		if (strcmp(d->d_name + 8, ".tmp") == 0) {
-			dprintf("try to del %s\n", d->d_name);
+			sd_dprintf("try to del %s\n", d->d_name);
 			if (unlinkat(dirfd(dir), d->d_name, 0) < 0)
-				eprintf("%m\n");
+				sd_eprintf("%m\n");
 			continue;
 		}
 
@@ -881,7 +886,7 @@ static int object_cache_flush_and_delete(struct object_cache *oc)
 			continue;
 		if (push_cache_object(vid, idx, all, true) !=
 				SD_RES_SUCCESS) {
-			dprintf("failed to push %"PRIx64"\n",
+			sd_dprintf("failed to push %"PRIx64"\n",
 				idx_to_oid(vid, idx));
 			ret = -1;
 			goto out_close_dir;
@@ -940,7 +945,7 @@ int object_cache_handle_request(struct request *req)
 	int ret;
 	bool create = false;
 
-	dprintf("%08"PRIx32", len %"PRIu32", off %"PRIu64"\n", idx,
+	sd_dprintf("%08"PRIx32", len %"PRIu32", off %"PRIu64"\n", idx,
 		hdr->data_length, hdr->obj.offset);
 
 	cache = find_object_cache(vid, true);
@@ -962,7 +967,7 @@ retry:
 
 	entry = get_cache_entry(cache, idx);
 	if (!entry) {
-		dprintf("retry oid %"PRIx64"\n", oid);
+		sd_dprintf("retry oid %"PRIx64"\n", oid);
 		/*
 		 * For the case that object exists but isn't added to object
 		 * list yet, we call pthread_yield() to expect other thread can
@@ -999,11 +1004,11 @@ int object_cache_write(uint64_t oid, char *data, unsigned int datalen,
 	struct object_cache_entry *entry;
 	int ret;
 
-	dprintf("%" PRIx64 "\n", oid);
+	sd_dprintf("%" PRIx64 "\n", oid);
 	cache = find_object_cache(vid, false);
 	entry = get_cache_entry(cache, idx);
 	if (!entry) {
-		dprintf("%" PRIx64 " doesn't exist\n", oid);
+		sd_dprintf("%" PRIx64 " doesn't exist\n", oid);
 		return SD_RES_NO_CACHE;
 	}
 
@@ -1021,11 +1026,11 @@ int object_cache_read(uint64_t oid, char *data, unsigned int datalen,
 	struct object_cache_entry *entry;
 	int ret;
 
-	dprintf("%" PRIx64 "\n", oid);
+	sd_dprintf("%" PRIx64 "\n", oid);
 	cache = find_object_cache(vid, false);
 	entry = get_cache_entry(cache, idx);
 	if (!entry) {
-		dprintf("%" PRIx64 " doesn't exist\n", oid);
+		sd_dprintf("%" PRIx64 " doesn't exist\n", oid);
 		return SD_RES_NO_CACHE;
 	}
 
@@ -1041,7 +1046,7 @@ int object_cache_flush_vdi(const struct request *req)
 
 	cache = find_object_cache(vid, false);
 	if (!cache) {
-		dprintf("%"PRIx32" not found\n", vid);
+		sd_dprintf("%"PRIx32" not found\n", vid);
 		return SD_RES_SUCCESS;
 	}
 
@@ -1093,7 +1098,7 @@ static int load_cache_object(struct object_cache *cache)
 	sprintf(path, "%s/%06"PRIx32, object_cache_dir, cache->vid);
 	dir = opendir(path);
 	if (!dir) {
-		dprintf("%m\n");
+		sd_dprintf("%m\n");
 		ret = -1;
 		goto out;
 	}
@@ -1103,9 +1108,9 @@ static int load_cache_object(struct object_cache *cache)
 			continue;
 
 		if (strcmp(d->d_name + 8, ".tmp") == 0) {
-			dprintf("try to del %s\n", d->d_name);
+			sd_dprintf("try to del %s\n", d->d_name);
 			if (unlinkat(dirfd(dir), d->d_name, 0) < 0)
-				eprintf("%m\n");
+				sd_eprintf("%m\n");
 			continue;
 		}
 
@@ -1120,7 +1125,7 @@ static int load_cache_object(struct object_cache *cache)
 		 * cluster isn't fully working.
 		 */
 		add_to_lru_cache(cache, idx, true);
-		dprintf("%"PRIx64"\n", idx_to_oid(cache->vid, idx));
+		sd_dprintf("%"PRIx64"\n", idx_to_oid(cache->vid, idx));
 	}
 
 	closedir(dir);
@@ -1139,7 +1144,7 @@ static int load_cache(void)
 	sprintf(path, "%s", object_cache_dir);
 	dir = opendir(path);
 	if (!dir) {
-		dprintf("%m\n");
+		sd_dprintf("%m\n");
 		ret = -1;
 		goto out;
 	}
@@ -1167,7 +1172,7 @@ int object_cache_init(const char *p)
 	strbuf_addstr(&buf, p);
 	if (mkdir(buf.buf, def_dmode) < 0) {
 		if (errno != EEXIST) {
-			eprintf("%s %m\n", buf.buf);
+			sd_eprintf("%s %m\n", buf.buf);
 			ret = -1;
 			goto err;
 		}
@@ -1175,7 +1180,7 @@ int object_cache_init(const char *p)
 	strbuf_addstr(&buf, "/cache");
 	if (mkdir(buf.buf, def_dmode) < 0) {
 		if (errno != EEXIST) {
-			eprintf("%s %m\n", buf.buf);
+			sd_eprintf("%s %m\n", buf.buf);
 			ret = -1;
 			goto err;
 		}
diff --git a/sheep/object_list_cache.c b/sheep/object_list_cache.c
index c6b85ee..a830bab 100644
--- a/sheep/object_list_cache.c
+++ b/sheep/object_list_cache.c
@@ -115,7 +115,7 @@ int objlist_cache_insert(uint64_t oid)
 	entry = zalloc(sizeof(*entry));
 
 	if (!entry) {
-		eprintf("no memory to allocate cache entry.\n");
+		sd_eprintf("no memory to allocate cache entry.\n");
 		return -1;
 	}
 
@@ -163,7 +163,7 @@ int get_obj_list(const struct sd_list_req *hdr, struct sd_list_rsp *rsp, void *d
 out:
 	if (hdr->data_length < obj_list_cache.cache_size * sizeof(uint64_t)) {
 		pthread_rwlock_unlock(&obj_list_cache.lock);
-		eprintf("GET_OBJ_LIST buffer too small\n");
+		sd_eprintf("GET_OBJ_LIST buffer too small\n");
 		return SD_RES_BUFFER_SMALL;
 	}
 
@@ -187,8 +187,8 @@ static void objlist_deletion_work(struct work *work)
 	 * again, in which case we should not reclaim the cached entry.
 	 */
 	if (vdi_exist(vid)) {
-		eprintf("VDI (%" PRIx32 ") is still in use, can not be deleted\n",
-			vid);
+		sd_eprintf("VDI (%" PRIx32 ") is still in use, can not be"
+			" deleted\n", vid);
 		return;
 	}
 
@@ -197,7 +197,7 @@ static void objlist_deletion_work(struct work *work)
 		entry_vid = oid_to_vid(entry->oid);
 		if (entry_vid != vid)
 			continue;
-		dprintf("delete object entry %" PRIx64 "\n", entry->oid);
+		sd_dprintf("delete object entry %" PRIx64 "\n", entry->oid);
 		list_del(&entry->list);
 		rb_erase(&entry->node, &obj_list_cache.root);
 		free(entry);
diff --git a/sheep/ops.c b/sheep/ops.c
index c4bd41c..bc06acf 100644
--- a/sheep/ops.c
+++ b/sheep/ops.c
@@ -136,7 +136,7 @@ static int post_cluster_new_vdi(const struct sd_req *req, struct sd_rsp *rsp,
 	unsigned long nr = rsp->vdi.vdi_id;
 	int ret = rsp->result;
 
-	vprintf(SDOG_INFO, "done %d %ld\n", ret, nr);
+	sd_printf(SDOG_INFO, "done %d %ld\n", ret, nr);
 	if (ret == SD_RES_SUCCESS)
 		set_bit(nr, sys->vdi_inuse);
 
@@ -231,18 +231,18 @@ static int remove_epoch(uint32_t epoch)
 	int ret;
 	char path[PATH_MAX];
 
-	dprintf("remove epoch %"PRIu32"\n", epoch);
+	sd_dprintf("remove epoch %"PRIu32"\n", epoch);
 	snprintf(path, sizeof(path), "%s%08u", epoch_path, epoch);
 	ret = unlink(path);
 	if (ret && ret != -ENOENT) {
-		eprintf("failed to remove %s: %s\n", path, strerror(-ret));
+		sd_eprintf("failed to remove %s: %s\n", path, strerror(-ret));
 		return SD_RES_EIO;
 	}
 
 	snprintf(path, sizeof(path), "%s%08u/", jrnl_path, epoch);
 	ret = rmdir_r(path);
 	if (ret && ret != -ENOENT) {
-		eprintf("failed to remove %s: %s\n", path, strerror(-ret));
+		sd_eprintf("failed to remove %s: %s\n", path, strerror(-ret));
 		return SD_RES_EIO;
 	}
 	return 0;
@@ -462,7 +462,7 @@ static int local_get_epoch(struct request *req)
 	uint32_t epoch = req->rq.obj.tgt_epoch;
 	int nr_nodes;
 
-	dprintf("%d\n", epoch);
+	sd_dprintf("%d\n", epoch);
 
 	nr_nodes = epoch_log_read(epoch, req->data, req->rq.data_length);
 	if (nr_nodes == -1)
@@ -500,7 +500,7 @@ static int cluster_force_recover(const struct sd_req *req, struct sd_rsp *rsp,
 
 	old_vnode_info = get_vnode_info_epoch(sys->epoch);
 	if (!old_vnode_info) {
-		eprintf("cannot get vnode info for epoch %d\n", sys->epoch);
+		sd_eprintf("cannot get vnode info for epoch %d\n", sys->epoch);
 		return SD_RES_EIO;
 	}
 
@@ -604,7 +604,7 @@ static int cluster_recovery_completion(const struct sd_req *req,
 		return SD_RES_SUCCESS;
 
 	if (latest_epoch < epoch) {
-		dprintf("new epoch %d\n", epoch);
+		sd_dprintf("new epoch %d\n", epoch);
 		latest_epoch = epoch;
 		nr_recovereds = 0;
 	}
@@ -612,9 +612,9 @@ static int cluster_recovery_completion(const struct sd_req *req,
 	recovereds[nr_recovereds++] = *(struct sd_node *)node;
 	qsort(recovereds, nr_recovereds, sizeof(*recovereds), node_id_cmp);
 
-	dprintf("%s is recovered at epoch %d\n", node_to_str(node), epoch);
+	sd_dprintf("%s is recovered at epoch %d\n", node_to_str(node), epoch);
 	for (i = 0; i < nr_recovereds; i++)
-		dprintf("[%x] %s\n", i, node_to_str(recovereds + i));
+		sd_dprintf("[%x] %s\n", i, node_to_str(recovereds + i));
 
 	if (sys->epoch != latest_epoch)
 		return SD_RES_SUCCESS;
@@ -624,7 +624,7 @@ static int cluster_recovery_completion(const struct sd_req *req,
 	if (vnode_info->nr_nodes == nr_recovereds &&
 	    memcmp(vnode_info->nodes, recovereds,
 		   sizeof(*recovereds) * nr_recovereds) == 0) {
-		dprintf("all nodes are recovered at epoch %d\n", epoch);
+		sd_dprintf("all nodes are recovered at epoch %d\n", epoch);
 		if (sd_store->cleanup)
 			sd_store->cleanup();
 	}
@@ -640,7 +640,7 @@ static int local_set_cache_size(const struct sd_req *req, struct sd_rsp *rsp,
 	uint32_t cache_size = *(uint32_t *)data;
 
 	uatomic_set(&sys->object_cache_size, cache_size);
-	dprintf("Max cache size set to %dM\n", cache_size);
+	sd_dprintf("Max cache size set to %dM\n", cache_size);
 
 	object_cache_try_to_reclaim(0);
 
@@ -725,7 +725,7 @@ static int local_trace_read_buf(struct request *request)
 		return SD_RES_AGAIN;
 
 	rsp->data_length = ret;
-	dprintf("%u\n", rsp->data_length);
+	sd_dprintf("%u\n", rsp->data_length);
 	return SD_RES_SUCCESS;
 }
 
@@ -851,18 +851,18 @@ int peer_create_and_write_obj(struct request *req)
 	iocb.flags = hdr->flags;
 	iocb.length = get_objsize(oid);
 	if (hdr->flags & SD_FLAG_CMD_COW) {
-		dprintf("%" PRIx64 ", %" PRIx64 "\n", oid, hdr->obj.cow_oid);
+		sd_dprintf("%" PRIx64 ", %" PRIx64 "\n", oid, hdr->obj.cow_oid);
 
 		buf = valloc(SD_DATA_OBJ_SIZE);
 		if (!buf) {
-			eprintf("can not allocate memory\n");
+			sd_eprintf("can not allocate memory\n");
 			goto out;
 		}
 		if (hdr->data_length != SD_DATA_OBJ_SIZE) {
 			ret = read_copy_from_replica(req, hdr->epoch,
 						     hdr->obj.cow_oid, buf);
 			if (ret != SD_RES_SUCCESS) {
-				eprintf("failed to read cow object\n");
+				sd_eprintf("failed to read cow object\n");
 				goto out;
 			}
 		}
@@ -1235,14 +1235,14 @@ void do_process_work(struct work *work)
 	struct request *req = container_of(work, struct request, work);
 	int ret = SD_RES_SUCCESS;
 
-	dprintf("%x, %" PRIx64", %"PRIu32"\n",
+	sd_dprintf("%x, %" PRIx64", %"PRIu32"\n",
 		req->rq.opcode, req->rq.obj.oid, req->rq.epoch);
 
 	if (req->op->process_work)
 		ret = req->op->process_work(req);
 
 	if (ret != SD_RES_SUCCESS) {
-		dprintf("failed: %x, %" PRIx64" , %u, %"PRIx32"\n",
+		sd_dprintf("failed: %x, %" PRIx64" , %u, %"PRIx32"\n",
 			req->rq.opcode, req->rq.obj.oid, req->rq.epoch, ret);
 	}
 
diff --git a/sheep/plain_store.c b/sheep/plain_store.c
index 33e40a9..0ddaecb 100644
--- a/sheep/plain_store.c
+++ b/sheep/plain_store.c
@@ -67,7 +67,7 @@ int for_each_object_in_wd(int (*func)(uint64_t oid, void *arg), bool cleanup,
 
 	dir = opendir(obj_path);
 	if (!dir) {
-		eprintf("failed to open %s, %m\n", obj_path);
+		sd_eprintf("failed to open %s, %m\n", obj_path);
 		return SD_RES_EIO;
 	}
 
@@ -84,7 +84,7 @@ int for_each_object_in_wd(int (*func)(uint64_t oid, void *arg), bool cleanup,
 		    strcmp(d->d_name + 16, ".tmp") == 0) {
 			if (cleanup) {
 				get_tmp_obj_path(oid, path);
-				dprintf("remove tmp object %s\n", path);
+				sd_dprintf("remove tmp object %s\n", path);
 				unlink(path);
 			}
 			continue;
@@ -105,7 +105,8 @@ bool default_exist(uint64_t oid)
 	get_obj_path(oid, path);
 	if (access(path, R_OK | W_OK) < 0) {
 		if (errno != ENOENT)
-			eprintf("failed to check object %"PRIx64", %m\n", oid);
+			sd_eprintf("failed to check object %"PRIx64", %m\n",
+				oid);
 		return false;
 	}
 
@@ -119,17 +120,17 @@ int err_to_sderr(uint64_t oid, int err)
 	switch (err) {
 	case ENOENT:
 		if (stat(obj_path, &s) < 0) {
-			eprintf("corrupted\n");
+			sd_eprintf("corrupted\n");
 			return SD_RES_EIO;
 		}
-		dprintf("object %016" PRIx64 " not found locally\n", oid);
+		sd_dprintf("object %016" PRIx64 " not found locally\n", oid);
 		return SD_RES_NO_OBJ;
 	case ENOSPC:
 		/* TODO: stop automatic recovery */
-		eprintf("diskfull, oid=%"PRIx64"\n", oid);
+		sd_eprintf("diskfull, oid=%"PRIx64"\n", oid);
 		return SD_RES_NO_SPACE;
 	default:
-		eprintf("oid=%"PRIx64", %m\n", oid);
+		sd_eprintf("oid=%"PRIx64", %m\n", oid);
 		return SD_RES_EIO;
 	}
 }
@@ -142,7 +143,8 @@ int default_write(uint64_t oid, const struct siocb *iocb)
 	ssize_t size;
 
 	if (iocb->epoch < sys_epoch()) {
-		dprintf("%"PRIu32" sys %"PRIu32"\n", iocb->epoch, sys_epoch());
+		sd_dprintf("%"PRIu32" sys %"PRIu32"\n",
+			iocb->epoch, sys_epoch());
 		return SD_RES_OLD_NODE_VER;
 	}
 
@@ -152,7 +154,7 @@ int default_write(uint64_t oid, const struct siocb *iocb)
 	    journal_file_write(oid, iocb->buf, iocb->length, iocb->offset,
 			       false)
 	    != SD_RES_SUCCESS) {
-		eprintf("turn off journaling\n");
+		sd_eprintf("turn off journaling\n");
 		uatomic_set_false(&sys->use_journal);
 		flags |= O_DSYNC;
 		sync();
@@ -164,7 +166,7 @@ int default_write(uint64_t oid, const struct siocb *iocb)
 
 	size = xpwrite(fd, iocb->buf, iocb->length, iocb->offset);
 	if (size != iocb->length) {
-		eprintf("failed to write object %"PRIx64", path=%s, offset=%"
+		sd_eprintf("failed to write object %"PRIx64", path=%s, offset=%"
 			PRId64", size=%"PRId32", result=%zd, %m\n", oid, path,
 			iocb->offset, iocb->length, size);
 		ret = err_to_sderr(oid, errno);
@@ -179,7 +181,7 @@ int default_cleanup(void)
 {
 	rmdir_r(stale_dir);
 	if (mkdir(stale_dir, 0755) < 0) {
-		eprintf("%m\n");
+		sd_eprintf("%m\n");
 		return SD_RES_EIO;
 	}
 
@@ -196,14 +198,14 @@ static int init_vdi_copy_number(uint64_t oid)
 
 	fd = open(path, flags);
 	if (fd < 0) {
-		eprintf("failed to open %s, %m\n", path);
+		sd_eprintf("failed to open %s, %m\n", path);
 		ret = SD_RES_EIO;
 		goto out;
 	}
 
 	ret = xpread(fd, inode, SD_INODE_HEADER_SIZE, 0);
 	if (ret != SD_INODE_HEADER_SIZE) {
-		eprintf("failed to read inode header, path=%s, %m\n", path);
+		sd_eprintf("failed to read inode header, path=%s, %m\n", path);
 		ret = SD_RES_EIO;
 		goto out;
 	}
@@ -222,7 +224,7 @@ static int init_objlist_and_vdi_bitmap(uint64_t oid, void *arg)
 	objlist_cache_insert(oid);
 
 	if (is_vdi_obj(oid)) {
-		vprintf(SDOG_DEBUG, "found the VDI object %" PRIx64 "\n", oid);
+		sd_dprintf("found the VDI object %" PRIx64 "\n", oid);
 		set_bit(oid_to_vid(oid), sys->vdi_inuse);
 		ret = init_vdi_copy_number(oid);
 		if (ret != SD_RES_SUCCESS)
@@ -233,13 +235,13 @@ static int init_objlist_and_vdi_bitmap(uint64_t oid, void *arg)
 
 int default_init(const char *p)
 {
-	dprintf("use plain store driver\n");
+	sd_dprintf("use plain store driver\n");
 
 	/* create a stale directory */
 	snprintf(stale_dir, sizeof(stale_dir), "%s/.stale", p);
 	if (mkdir(stale_dir, 0755) < 0) {
 		if (errno != EEXIST) {
-			eprintf("%m\n");
+			sd_eprintf("%m\n");
 			return SD_RES_EIO;
 		}
 	}
@@ -261,7 +263,7 @@ static int default_read_from_path(uint64_t oid, const char *path,
 
 	size = xpread(fd, iocb->buf, iocb->length, iocb->offset);
 	if (size != iocb->length) {
-		eprintf("failed to read object %"PRIx64", path=%s, offset=%"
+		sd_eprintf("failed to read object %"PRIx64", path=%s, offset=%"
 			PRId64", size=%"PRId32", result=%zd, %m\n", oid, path,
 			iocb->offset, iocb->length, size);
 		ret = err_to_sderr(oid, errno);
@@ -300,7 +302,7 @@ int prealloc(int fd, uint32_t size)
 	int ret = fallocate(fd, 0, 0, size);
 	if (ret < 0) {
 		if (errno != ENOSYS && errno != EOPNOTSUPP) {
-			eprintf("failed to preallocate space, %m\n");
+			sd_eprintf("failed to preallocate space, %m\n");
 			return ret;
 		}
 
@@ -323,7 +325,7 @@ int default_create_and_write(uint64_t oid, const struct siocb *iocb)
 	if (uatomic_is_true(&sys->use_journal) &&
 	    journal_file_write(oid, iocb->buf, iocb->length, iocb->offset, true)
 	    != SD_RES_SUCCESS) {
-		eprintf("turn off journaling\n");
+		sd_eprintf("turn off journaling\n");
 		uatomic_set_false(&sys->use_journal);
 		flags |= O_DSYNC;
 		sync();
@@ -337,11 +339,11 @@ int default_create_and_write(uint64_t oid, const struct siocb *iocb)
 			 * recovery process could also recover the object at the
 			 * same time.  They should try to write the same date,
 			 * so it is okay to simply return success here. */
-			dprintf("%s exists\n", tmp_path);
+			sd_dprintf("%s exists\n", tmp_path);
 			return SD_RES_SUCCESS;
 		}
 
-		eprintf("failed to open %s: %m\n", tmp_path);
+		sd_eprintf("failed to open %s: %m\n", tmp_path);
 		return err_to_sderr(oid, errno);
 	}
 
@@ -355,18 +357,18 @@ int default_create_and_write(uint64_t oid, const struct siocb *iocb)
 
 	ret = xpwrite(fd, iocb->buf, len, iocb->offset);
 	if (ret != len) {
-		eprintf("failed to write object. %m\n");
+		sd_eprintf("failed to write object. %m\n");
 		ret = err_to_sderr(oid, errno);
 		goto out;
 	}
 
 	ret = rename(tmp_path, path);
 	if (ret < 0) {
-		eprintf("failed to rename %s to %s: %m\n", tmp_path, path);
+		sd_eprintf("failed to rename %s to %s: %m\n", tmp_path, path);
 		ret = err_to_sderr(oid, errno);
 		goto out;
 	}
-	dprintf("%"PRIx64"\n", oid);
+	sd_dprintf("%"PRIx64"\n", oid);
 	ret = SD_RES_SUCCESS;
 out:
 	if (ret != SD_RES_SUCCESS)
@@ -379,14 +381,14 @@ int default_link(uint64_t oid, uint32_t tgt_epoch)
 {
 	char path[PATH_MAX], stale_path[PATH_MAX];
 
-	dprintf("try link %"PRIx64" from snapshot with epoch %d\n", oid,
+	sd_dprintf("try link %"PRIx64" from snapshot with epoch %d\n", oid,
 		tgt_epoch);
 
 	get_obj_path(oid, path);
 	get_stale_obj_path(oid, tgt_epoch, stale_path);
 
 	if (link(stale_path, path) < 0) {
-		eprintf("failed to link from %s to %s, %m\n", stale_path,
+		sd_eprintf("failed to link from %s to %s, %m\n", stale_path,
 			path);
 		return err_to_sderr(oid, errno);
 	}
@@ -432,12 +434,12 @@ static int move_object_to_stale_dir(uint64_t oid, void *arg)
 	get_stale_obj_path(oid, tgt_epoch, stale_path);
 
 	if (rename(path, stale_path) < 0) {
-		eprintf("failed to move stale object %"PRIX64" to %s, %m\n",
+		sd_eprintf("failed to move stale object %"PRIX64" to %s, %m\n",
 			oid, path);
 		return SD_RES_EIO;
 	}
 
-	dprintf("moved object %"PRIx64"\n", oid);
+	sd_dprintf("moved object %"PRIx64"\n", oid);
 	return SD_RES_SUCCESS;
 }
 
@@ -462,14 +464,15 @@ int default_format(void)
 {
 	unsigned ret;
 
-	dprintf("try get a clean store\n");
+	sd_dprintf("try get a clean store\n");
 	ret = rmdir_r(obj_path);
 	if (ret && ret != -ENOENT) {
-		eprintf("failed to remove %s: %s\n", obj_path, strerror(-ret));
+		sd_eprintf("failed to remove %s: %s\n",
+			obj_path, strerror(-ret));
 		return SD_RES_EIO;
 	}
 	if (mkdir(obj_path, def_dmode) < 0) {
-		eprintf("%m\n");
+		sd_eprintf("%m\n");
 		return SD_RES_EIO;
 	}
 	if (is_object_cache_enabled())
@@ -488,7 +491,7 @@ int default_remove_object(uint64_t oid)
 		if (errno == ENOENT)
 			return SD_RES_NO_OBJ;
 
-		eprintf("failed to remove object %"PRIx64", %m\n", oid);
+		sd_eprintf("failed to remove object %"PRIx64", %m\n", oid);
 		return SD_RES_EIO;
 	}
 
@@ -516,12 +519,13 @@ int default_flush(void)
 
 	fd = open(obj_path, O_RDONLY);
 	if (fd < 0) {
-		eprintf("error at open() %s, %s\n", obj_path, strerror(errno));
+		sd_eprintf("error at open() %s, %s\n",
+			obj_path, strerror(errno));
 		return SD_RES_NO_OBJ;
 	}
 
 	if (syncfs(fd)) {
-		eprintf("error at syncfs(), %s\n", strerror(errno));
+		sd_eprintf("error at syncfs(), %s\n", strerror(errno));
 		ret = SD_RES_EIO;
 	}
 
diff --git a/sheep/recovery.c b/sheep/recovery.c
index fcfc33a..5595d73 100644
--- a/sheep/recovery.c
+++ b/sheep/recovery.c
@@ -82,7 +82,7 @@ static int recover_object_from_replica(uint64_t oid,
 	rlen = get_objsize(oid);
 	buf = valloc(rlen);
 	if (!buf) {
-		eprintf("%m\n");
+		sd_eprintf("%m\n");
 		goto out;
 	}
 
@@ -103,7 +103,7 @@ static int recover_object_from_replica(uint64_t oid,
 	ret = sd_store->create_and_write(oid, &iocb);
 out:
 	if (ret == SD_RES_SUCCESS) {
-		dprintf("recovered oid %"PRIx64" from %d to epoch %d\n", oid,
+		sd_dprintf("recovered oid %"PRIx64" from %d to epoch %d\n", oid,
 			tgt_epoch, epoch);
 		objlist_cache_insert(oid);
 	}
@@ -139,7 +139,7 @@ static int do_recover_object(struct recovery_work *rw)
 	old = grab_vnode_info(rw->old_vinfo);
 
 again:
-	dprintf("try recover object %"PRIx64" from epoch %"PRIu32"\n",
+	sd_dprintf("try recover object %"PRIx64" from epoch %"PRIu32"\n",
 		oid, tgt_epoch);
 
 	/* Let's do a breadth-first search */
@@ -171,7 +171,7 @@ again:
 rollback:
 		tgt_epoch--;
 		if (tgt_epoch < 1) {
-			eprintf("can not recover oid %"PRIx64"\n", oid);
+			sd_eprintf("can not recover oid %"PRIx64"\n", oid);
 			ret = -1;
 			goto err;
 		}
@@ -197,17 +197,17 @@ static void recover_object_work(struct work *work)
 	uint64_t oid = rw->oids[rw->done];
 	int ret;
 
-	eprintf("done:%"PRIu32" count:%"PRIu32", oid:%"PRIx64"\n",
+	sd_eprintf("done:%"PRIu32" count:%"PRIu32", oid:%"PRIx64"\n",
 		rw->done, rw->count, oid);
 
 	if (sd_store->exist(oid)) {
-		dprintf("the object is already recovered\n");
+		sd_dprintf("the object is already recovered\n");
 		return;
 	}
 
 	ret = do_recover_object(rw);
 	if (ret < 0)
-		eprintf("failed to recover object %"PRIx64"\n", oid);
+		sd_eprintf("failed to recover object %"PRIx64"\n", oid);
 }
 
 bool node_in_recovery(void)
@@ -236,8 +236,8 @@ static inline void prepare_schedule_oid(uint64_t oid)
 	 */
 	for (i = 0; i < rw->done; i++)
 		if (rw->oids[i] == oid) {
-			dprintf("%"PRIx64" not recovered, don't schedule it\n",
-				oid);
+			sd_dprintf("%"PRIx64" not recovered, don't"
+				" schedule it\n", oid);
 			return;
 		}
 	/* When auto recovery is enabled, the oid is currently being
@@ -250,7 +250,7 @@ static inline void prepare_schedule_oid(uint64_t oid)
 	rw->prio_oids[rw->nr_prio_oids - 1] = oid;
 	resume_suspended_recovery();
 
-	dprintf("%"PRIx64" nr_prio_oids %d\n", oid, rw->nr_prio_oids);
+	sd_dprintf("%"PRIx64" nr_prio_oids %d\n", oid, rw->nr_prio_oids);
 }
 
 bool oid_in_recovery(uint64_t oid)
@@ -262,7 +262,7 @@ bool oid_in_recovery(uint64_t oid)
 		return false;
 
 	if (sd_store->exist(oid)) {
-		dprintf("the object %" PRIx64 " is already recoverd\n", oid);
+		sd_dprintf("the object %" PRIx64 " is already recoverd\n", oid);
 		return false;
 	}
 
@@ -287,7 +287,7 @@ bool oid_in_recovery(uint64_t oid)
 	 * in the list
 	 */
 	if (i == rw->count) {
-		eprintf("%"PRIx64" is not in the recovery list\n", oid);
+		sd_eprintf("%"PRIx64" is not in the recovery list\n", oid);
 		return false;
 	}
 
@@ -311,7 +311,7 @@ static inline void run_next_rw(struct recovery_work *rw)
 	recovering_work = rw;
 	flush_wait_obj_requests();
 	queue_work(sys->recovery_wqueue, &rw->work);
-	dprintf("recovery work is superseded\n");
+	sd_dprintf("recovery work is superseded\n");
 }
 
 static void notify_recovery_completion_work(struct work *work)
@@ -328,7 +328,7 @@ static void notify_recovery_completion_work(struct work *work)
 
 	ret = exec_local_req(&hdr, &sys->this_node);
 	if (ret != SD_RES_SUCCESS)
-		eprintf("failed to notify recovery completion, %d\n",
+		sd_eprintf("failed to notify recovery completion, %d\n",
 			rw->epoch);
 }
 
@@ -352,7 +352,7 @@ static inline void finish_recovery(struct recovery_work *rw)
 	rw->work.done = notify_recovery_completion_main;
 	queue_work(sys->recovery_wqueue, &rw->work);
 
-	dprintf("recovery complete: new epoch %"PRIu32"\n",
+	sd_dprintf("recovery complete: new epoch %"PRIu32"\n",
 		sys->recovered_epoch);
 }
 
@@ -395,7 +395,7 @@ static inline void finish_schedule_oids(struct recovery_work *rw)
 		new_oids[new_idx++] = rw->oids[i];
 	}
 	/* rw->count should eq new_idx, otherwise something is wrong */
-	dprintf("%snr_recovered %d, nr_prio_oids %d, count %d = new %d\n",
+	sd_dprintf("%snr_recovered %d, nr_prio_oids %d, count %d = new %d\n",
 		rw->count == new_idx ? "" : "WARN: ", nr_recovered,
 		rw->nr_prio_oids, rw->count, new_idx);
 
@@ -431,7 +431,7 @@ static void recover_next_object(struct recovery_work *rw)
 		finish_schedule_oids(rw);
 
 	if (sys->disable_recovery && !has_scheduled_objects(rw)) {
-		dprintf("suspended\n");
+		sd_dprintf("suspended\n");
 		rw->suspended = true;
 		/* suspend until resume_suspended_recovery() is called */
 		return;
@@ -465,7 +465,7 @@ static void recover_object_main(struct work *work)
 		 * requests
 		 */
 		flush_wait_obj_requests();
-		dprintf("recovery is stopped\n");
+		sd_dprintf("recovery is stopped\n");
 		return;
 	}
 
@@ -517,7 +517,7 @@ static uint64_t *fetch_object_list(struct sd_node *e, uint32_t epoch,
 	int ret;
 
 	addr_to_str(name, sizeof(name), e->nid.addr, 0);
-	dprintf("%s %"PRIu32"\n", name, e->nid.port);
+	sd_dprintf("%s %"PRIu32"\n", name, e->nid.port);
 
 retry:
 	sd_init_req((struct sd_req *)&hdr, SD_OP_GET_OBJ_LIST);
@@ -538,7 +538,7 @@ retry:
 	}
 
 	*nr_oids = rsp->data_length / sizeof(uint64_t);
-	dprintf("%zu\n", *nr_oids);
+	sd_dprintf("%zu\n", *nr_oids);
 	return buf;
 }
 
@@ -554,8 +554,8 @@ static void screen_object_list(struct recovery_work *rw,
 	for (i = 0; i < nr_oids; i++) {
 		nr_objs = get_obj_copy_number(oids[i], rw->cur_vinfo->nr_zones);
 		if (!nr_objs) {
-			eprintf("ERROR: can not find copy number for object %"
-				PRIx64 "\n", oids[i]);
+			sd_eprintf("ERROR: can not find copy number for object"
+				" %" PRIx64 "\n", oids[i]);
 			continue;
 		}
 		oid_to_vnodes(rw->cur_vinfo->vnodes, rw->cur_vinfo->nr_vnodes,
@@ -598,7 +598,7 @@ static void prepare_object_list(struct work *work)
 	int start = random() % cur_nr, i, end = cur_nr;
 	uint64_t *oids;
 
-	dprintf("%u\n", rw->epoch);
+	sd_dprintf("%u\n", rw->epoch);
 	wait_get_vdis_done();
 again:
 	/* We need to start at random node for better load balance */
@@ -607,7 +607,7 @@ again:
 		struct sd_node *node = cur + i;
 
 		if (next_rw) {
-			dprintf("go to the next recovery\n");
+			sd_dprintf("go to the next recovery\n");
 			return;
 		}
 		if (newly_joined(node, rw))
@@ -627,7 +627,7 @@ again:
 		goto again;
 	}
 
-	dprintf("%d\n", rw->count);
+	sd_dprintf("%d\n", rw->count);
 }
 
 static inline bool node_is_gateway_only(void)
@@ -644,7 +644,7 @@ int start_recovery(struct vnode_info *cur_vinfo, struct vnode_info *old_vinfo)
 
 	rw = zalloc(sizeof(struct recovery_work));
 	if (!rw) {
-		eprintf("%m\n");
+		sd_eprintf("%m\n");
 		return -1;
 	}
 
@@ -669,7 +669,7 @@ int start_recovery(struct vnode_info *cur_vinfo, struct vnode_info *old_vinfo)
 		/* skip the previous epoch recovery */
 		if (next_rw)
 			free_recovery_work(next_rw);
-		dprintf("recovery skipped\n");
+		sd_dprintf("recovery skipped\n");
 		next_rw = rw;
 
 		/* This is necesary to invoke run_next_rw when
diff --git a/sheep/request.c b/sheep/request.c
index 877b75e..009d279 100644
--- a/sheep/request.c
+++ b/sheep/request.c
@@ -51,13 +51,13 @@ static void io_op_done(struct work *work)
 	case SD_RES_EIO:
 		req->rp.result = SD_RES_NETWORK_ERROR;
 
-		eprintf("leaving sheepdog cluster\n");
+		sd_eprintf("leaving sheepdog cluster\n");
 		leave_cluster();
 		break;
 	case SD_RES_SUCCESS:
 		break;
 	default:
-		dprintf("unhandled error %d\n", req->rp.result);
+		sd_dprintf("unhandled error %d\n", req->rp.result);
 		break;
 
 	}
@@ -88,7 +88,7 @@ static void gateway_op_done(struct work *work)
 	case SD_RES_WAIT_FOR_JOIN:
 	case SD_RES_WAIT_FOR_FORMAT:
 	case SD_RES_KILLED:
-		dprintf("retrying failed I/O request "
+		sd_dprintf("retrying failed I/O request "
 			"op %s result %x epoch %"PRIu32", sys epoch %"PRIu32"\n",
 			op_name(req->op),
 			req->rp.result,
@@ -97,7 +97,7 @@ static void gateway_op_done(struct work *work)
 		goto retry;
 	case SD_RES_EIO:
 		if (is_access_local(req, hdr->obj.oid)) {
-			eprintf("leaving sheepdog cluster\n");
+			sd_eprintf("leaving sheepdog cluster\n");
 			leave_cluster();
 			goto retry;
 		}
@@ -105,7 +105,7 @@ static void gateway_op_done(struct work *work)
 	case SD_RES_SUCCESS:
 		break;
 	default:
-		dprintf("unhandled error %d\n", req->rp.result);
+		sd_dprintf("unhandled error %d\n", req->rp.result);
 		break;
 	}
 
@@ -130,7 +130,7 @@ static void local_op_done(struct work *work)
 static int check_request_epoch(struct request *req)
 {
 	if (before(req->rq.epoch, sys->epoch)) {
-		eprintf("old node version %u, %u (%s)\n",
+		sd_eprintf("old node version %u, %u (%s)\n",
 			sys->epoch, req->rq.epoch, op_name(req->op));
 		/* ask gateway to retry. */
 		req->rp.result = SD_RES_OLD_NODE_VER;
@@ -138,7 +138,7 @@ static int check_request_epoch(struct request *req)
 		put_request(req);
 		return -1;
 	} else if (after(req->rq.epoch, sys->epoch)) {
-		eprintf("new node version %u, %u (%s)\n",
+		sd_eprintf("new node version %u, %u (%s)\n",
 			sys->epoch, req->rq.epoch, op_name(req->op));
 
 		/* put on local wait queue, waiting for local epoch
@@ -174,12 +174,12 @@ static bool request_in_recovery(struct request *req)
 		 * Put request on wait queues of local node
 		 */
 		if (is_recovery_init()) {
-			dprintf("%"PRIx64" on rw_queue\n", req->local_oid);
+			sd_dprintf("%"PRIx64" on rw_queue\n", req->local_oid);
 			req->rp.result = SD_RES_OBJ_RECOVERING;
 			list_add_tail(&req->request_list,
 				      &sys->wait_rw_queue);
 		} else {
-			dprintf("%"PRIx64" on obj_queue\n", req->local_oid);
+			sd_dprintf("%"PRIx64" on obj_queue\n", req->local_oid);
 			list_add_tail(&req->request_list,
 				      &sys->wait_obj_queue);
 		}
@@ -232,7 +232,7 @@ void resume_wait_recovery_requests(void)
 		if (req->rp.result != SD_RES_OBJ_RECOVERING)
 			continue;
 
-		dprintf("resume wait oid %" PRIx64 "\n", req->local_oid);
+		sd_dprintf("resume wait oid %" PRIx64 "\n", req->local_oid);
 		list_del(&req->request_list);
 		requeue_request(req);
 	}
@@ -253,7 +253,7 @@ void resume_wait_obj_requests(uint64_t oid)
 
 		/* the object requested by a pending request has been
 		 * recovered, notify the pending request. */
-		dprintf("retry %" PRIx64 "\n", req->local_oid);
+		sd_dprintf("retry %" PRIx64 "\n", req->local_oid);
 		list_del(&req->request_list);
 		requeue_request(req);
 	}
@@ -347,12 +347,12 @@ static void queue_request(struct request *req)
 
 	req->op = get_sd_op(hdr->opcode);
 	if (!req->op) {
-		eprintf("invalid opcode %d\n", hdr->opcode);
+		sd_eprintf("invalid opcode %d\n", hdr->opcode);
 		rsp->result = SD_RES_INVALID_PARMS;
 		goto done;
 	}
 
-	dprintf("%s, %d\n", op_name(req->op), sys->status);
+	sd_dprintf("%s, %d\n", op_name(req->op), sys->status);
 
 	switch (sys->status) {
 	case SD_STATUS_KILLED:
@@ -403,7 +403,7 @@ static void queue_request(struct request *req)
 		hdr->epoch = sys->epoch;
 		queue_cluster_request(req);
 	} else {
-		eprintf("unknown operation %d\n", hdr->opcode);
+		sd_eprintf("unknown operation %d\n", hdr->opcode);
 		rsp->result = SD_RES_SYSTEM_ERROR;
 		goto done;
 	}
@@ -473,7 +473,7 @@ again:
 	/* In error case (for e.g, EINTR) just retry read */
 	ret = eventfd_read(req->wait_efd, &value);
 	if (ret < 0) {
-		eprintf("%m\n");
+		sd_eprintf("%m\n");
 		if (errno == EINTR)
 			goto again;
 		/* Fake the result to ask for retry */
@@ -593,7 +593,7 @@ static inline int begin_rx(struct client_info *ci)
 		ret = rx(conn, C_IO_END);
 		break;
 	default:
-		eprintf("bug: unknown state %d\n", conn->c_rx_state);
+		sd_eprintf("bug: unknown state %d\n", conn->c_rx_state);
 	}
 
 	if (is_conn_dead(conn)) {
@@ -615,7 +615,7 @@ static inline void finish_rx(struct client_info *ci)
 	req = ci->rx_req;
 	init_rx_hdr(ci);
 
-	dprintf("%d, %s:%d\n", ci->conn.fd, ci->conn.ipstr, ci->conn.port);
+	sd_dprintf("%d, %s:%d\n", ci->conn.fd, ci->conn.ipstr, ci->conn.port);
 	queue_request(req);
 }
 
@@ -701,7 +701,7 @@ static inline int finish_tx(struct client_info *ci)
 {
 	/* Finish sending one response */
 	if (ci->conn.c_tx_state == C_IO_END) {
-		dprintf("connection from: %d, %s:%d\n", ci->conn.fd,
+		sd_dprintf("connection from: %d, %s:%d\n", ci->conn.fd,
 			ci->conn.ipstr, ci->conn.port);
 		free_request(ci->tx_req);
 		ci->tx_req = NULL;
@@ -732,7 +732,7 @@ static void do_client_tx(struct client_info *ci)
 
 static void destroy_client(struct client_info *ci)
 {
-	dprintf("connection from: %s:%d\n", ci->conn.ipstr, ci->conn.port);
+	sd_dprintf("connection from: %s:%d\n", ci->conn.ipstr, ci->conn.port);
 	close(ci->conn.fd);
 	free(ci);
 }
@@ -741,7 +741,7 @@ static void clear_client_info(struct client_info *ci)
 {
 	struct request *req, *t;
 
-	dprintf("connection seems to be dead\n");
+	sd_dprintf("connection seems to be dead\n");
 
 	if (ci->rx_req) {
 		free_request(ci->rx_req);
@@ -760,7 +760,7 @@ static void clear_client_info(struct client_info *ci)
 
 	unregister_event(ci->conn.fd);
 
-	dprintf("refcnt:%d, fd:%d, %s:%d\n",
+	sd_dprintf("refcnt:%d, fd:%d, %s:%d\n",
 		ci->refcnt, ci->conn.fd,
 		ci->conn.ipstr, ci->conn.port);
 
@@ -811,7 +811,7 @@ static void client_handler(int fd, int events, void *data)
 {
 	struct client_info *ci = (struct client_info *)data;
 
-	dprintf("%x, rx %d, tx %d\n", events, ci->conn.c_rx_state,
+	sd_dprintf("%x, rx %d, tx %d\n", events, ci->conn.c_rx_state,
 		ci->conn.c_tx_state);
 
 	if (events & (EPOLLERR | EPOLLHUP) || is_conn_dead(&ci->conn))
@@ -833,7 +833,7 @@ static void listen_handler(int listen_fd, int events, void *data)
 	bool is_inet_socket = *(bool *)data;
 
 	if (sys->status == SD_STATUS_SHUTDOWN) {
-		dprintf("unregistering connection %d\n", listen_fd);
+		sd_dprintf("unregistering connection %d\n", listen_fd);
 		unregister_event(listen_fd);
 		return;
 	}
@@ -841,7 +841,7 @@ static void listen_handler(int listen_fd, int events, void *data)
 	namesize = sizeof(from);
 	fd = accept(listen_fd, (struct sockaddr *)&from, &namesize);
 	if (fd < 0) {
-		eprintf("failed to accept a new connection: %m\n");
+		sd_eprintf("failed to accept a new connection: %m\n");
 		return;
 	}
 
@@ -871,7 +871,7 @@ static void listen_handler(int listen_fd, int events, void *data)
 		return;
 	}
 
-	dprintf("accepted a new connection: %d\n", fd);
+	sd_dprintf("accepted a new connection: %d\n", fd);
 }
 
 static int create_listen_port_fn(int fd, void *data)
@@ -907,7 +907,7 @@ static void req_handler(int listen_fd, int events, void *data)
 	int ret;
 
 	if (events & EPOLLERR)
-		eprintf("request handler error\n");
+		sd_eprintf("request handler error\n");
 
 	ret = eventfd_read(listen_fd, &value);
 	if (ret < 0)
diff --git a/sheep/sheep.c b/sheep/sheep.c
index 737b7ca..61e166c 100644
--- a/sheep/sheep.c
+++ b/sheep/sheep.c
@@ -131,13 +131,13 @@ static void signal_handler(int listen_fd, int events, void *data)
 
 	ret = read(sigfd, &siginfo, sizeof(siginfo));
 	assert(ret == sizeof(siginfo));
-	dprintf("signal %d\n", siginfo.ssi_signo);
+	sd_dprintf("signal %d\n", siginfo.ssi_signo);
 	switch (siginfo.ssi_signo) {
 	case SIGTERM:
 		sys->status = SD_STATUS_KILLED;
 		break;
 	default:
-		eprintf("signal %d unhandled\n", siginfo.ssi_signo);
+		sd_eprintf("signal %d unhandled\n", siginfo.ssi_signo);
 		break;
 	}
 }
@@ -157,17 +157,17 @@ static int init_signal(void)
 
 	sigfd = signalfd(-1, &mask, SFD_NONBLOCK);
 	if (sigfd < 0) {
-		eprintf("failed to create a signal fd: %m\n");
+		sd_eprintf("failed to create a signal fd: %m\n");
 		return -1;
 	}
 
 	ret = register_event(sigfd, signal_handler, NULL);
 	if (ret) {
-		eprintf("failed to register signal handler (%d)\n", ret);
+		sd_eprintf("failed to register signal handler (%d)\n", ret);
 		return -1;
 	}
 
-	dprintf("register signal_handler for %d\n", sigfd);
+	sd_dprintf("register signal_handler for %d\n", sigfd);
 
 	return 0;
 }
@@ -593,7 +593,7 @@ int main(int argc, char **argv)
 
 	ret = create_cluster(port, zone, nr_vnodes, explicit_addr);
 	if (ret) {
-		eprintf("failed to create sheepdog cluster\n");
+		sd_eprintf("failed to create sheepdog cluster\n");
 		exit(1);
 	}
 
@@ -602,7 +602,7 @@ int main(int argc, char **argv)
 		if (!strlen(jpath))
 			/* internal journal */
 			memcpy(jpath, dir, strlen(dir));
-		dprintf("%s, %zu, %d\n", jpath, jsize, jskip);
+		sd_dprintf("%s, %zu, %d\n", jpath, jsize, jskip);
 		ret = journal_file_init(jpath, jsize, jskip);
 		if (ret)
 			exit(1);
@@ -650,14 +650,15 @@ int main(int argc, char **argv)
 	}
 
 	free(dir);
-	vprintf(SDOG_NOTICE, "sheepdog daemon (version %s) started\n", PACKAGE_VERSION);
+	sd_printf(SDOG_NOTICE, "sheepdog daemon (version %s) started\n",
+		PACKAGE_VERSION);
 
 	while (sys->nr_outstanding_reqs != 0 ||
 	       (sys->status != SD_STATUS_KILLED &&
 		sys->status != SD_STATUS_SHUTDOWN))
 		event_loop(-1);
 
-	vprintf(SDOG_INFO, "shutdown\n");
+	sd_printf(SDOG_INFO, "shutdown\n");
 
 	leave_cluster();
 	log_close();
diff --git a/sheep/sockfd_cache.c b/sheep/sockfd_cache.c
index 1096328..f1124c0 100644
--- a/sheep/sockfd_cache.c
+++ b/sheep/sockfd_cache.c
@@ -153,7 +153,7 @@ static struct sockfd_cache_entry *sockfd_cache_grab(const struct node_id *nid,
 		char name[INET6_ADDRSTRLEN];
 
 		addr_to_str(name, sizeof(name), nid->addr, 0);
-		dprintf("failed node %s:%d\n", name, nid->port);
+		sd_dprintf("failed node %s:%d\n", name, nid->port);
 		goto out;
 	}
 
@@ -196,12 +196,12 @@ static bool sockfd_cache_destroy(const struct node_id *nid)
 	pthread_rwlock_wrlock(&sockfd_cache.lock);
 	entry = sockfd_cache_search(nid);
 	if (!entry) {
-		dprintf("It is already destroyed\n");
+		sd_dprintf("It is already destroyed\n");
 		goto false_out;
 	}
 
 	if (!slots_all_free(entry)) {
-		dprintf("Some victim still holds it\n");
+		sd_dprintf("Some victim still holds it\n");
 		goto false_out;
 	}
 
@@ -228,7 +228,7 @@ void sockfd_cache_del(const struct node_id *nid)
 
 	n = uatomic_sub_return(&sockfd_cache.count, 1);
 	addr_to_str(name, sizeof(name), nid->addr, 0);
-	dprintf("%s:%d, count %d\n", name, nid->port, n);
+	sd_dprintf("%s:%d, count %d\n", name, nid->port, n);
 }
 
 static void sockfd_cache_add_nolock(const struct node_id *nid)
@@ -253,7 +253,7 @@ void sockfd_cache_add_group(const struct sd_node *nodes, int nr)
 {
 	const struct sd_node *p;
 
-	dprintf("%d\n", nr);
+	sd_dprintf("%d\n", nr);
 	pthread_rwlock_wrlock(&sockfd_cache.lock);
 	while (nr--) {
 		p = nodes + nr;
@@ -285,7 +285,7 @@ void sockfd_cache_add(const struct node_id *nid)
 	pthread_rwlock_unlock(&sockfd_cache.lock);
 	n = uatomic_add_return(&sockfd_cache.count, 1);
 	addr_to_str(name, sizeof(name), nid->addr, 0);
-	dprintf("%s:%d, count %d\n", name, nid->port, n);
+	sd_dprintf("%s:%d, count %d\n", name, nid->port, n);
 }
 
 static void do_grow_fds(struct work *work)
@@ -294,7 +294,7 @@ static void do_grow_fds(struct work *work)
 	struct rb_node *p;
 	int old_fds_count, new_fds_count, new_size, i;
 
-	dprintf("%d\n", fds_count);
+	sd_dprintf("%d\n", fds_count);
 	pthread_rwlock_wrlock(&sockfd_cache.lock);
 	old_fds_count = fds_count;
 	new_fds_count = fds_count * 2;
@@ -317,7 +317,7 @@ static void grow_fds_done(struct work *work)
 {
 	fds_count *= 2;
 	fds_high_watermark = FDS_WATERMARK(fds_count);
-	dprintf("fd count has been grown into %d\n", fds_count);
+	sd_dprintf("fd count has been grown into %d\n", fds_count);
 	uatomic_set_false(&fds_in_grow);
 	free(work);
 }
@@ -392,16 +392,16 @@ grab:
 	}
 	check_idx(idx);
 	if (entry->fds[idx].fd != -1) {
-		dprintf("%s:%d, idx %d\n", name, port, idx);
+		sd_dprintf("%s:%d, idx %d\n", name, port, idx);
 		goto out;
 	}
 
 	/* Create a new cached connection for this vnode */
-	dprintf("create cache connection %s:%d idx %d\n", name, port, idx);
+	sd_dprintf("create cache connection %s:%d idx %d\n", name, port, idx);
 	fd = connect_to(name, port);
 	if (fd < 0) {
 		if (use_io) {
-			eprintf("fallback to non-io connection\n");
+			sd_eprintf("fallback to non-io connection\n");
 			fd = connect_to_addr(nid->addr, nid->port);
 			if (fd >= 0)
 				goto new;
@@ -427,7 +427,7 @@ static void sockfd_cache_put(const struct node_id *nid, int idx)
 	char name[INET6_ADDRSTRLEN];
 
 	addr_to_str(name, sizeof(name), addr, 0);
-	dprintf("%s:%d idx %d\n", name, port, idx);
+	sd_dprintf("%s:%d idx %d\n", name, port, idx);
 
 	pthread_rwlock_rdlock(&sockfd_cache.lock);
 	entry = sockfd_cache_search(nid);
@@ -462,7 +462,7 @@ struct sockfd *sheep_get_sockfd(const struct node_id *nid)
 	sfd = xmalloc(sizeof(*sfd));
 	sfd->idx = -1;
 	sfd->fd = fd;
-	dprintf("%d\n", fd);
+	sd_dprintf("%d\n", fd);
 	return sfd;
 }
 
@@ -480,7 +480,7 @@ struct sockfd *sheep_get_sockfd(const struct node_id *nid)
 void sheep_put_sockfd(const struct node_id *nid, struct sockfd *sfd)
 {
 	if (sfd->idx == -1) {
-		dprintf("%d\n", sfd->fd);
+		sd_dprintf("%d\n", sfd->fd);
 		close(sfd->fd);
 		free(sfd);
 		return;
@@ -500,7 +500,7 @@ void sheep_put_sockfd(const struct node_id *nid, struct sockfd *sfd)
 void sheep_del_sockfd(const struct node_id *nid, struct sockfd *sfd)
 {
 	if (sfd->idx == -1) {
-		dprintf("%d\n", sfd->fd);
+		sd_dprintf("%d\n", sfd->fd);
 		close(sfd->fd);
 		free(sfd);
 		return;
@@ -523,13 +523,13 @@ int sheep_exec_req(const struct node_id *nid, struct sd_req *hdr, void *buf)
 
 	ret = exec_req(sfd->fd, hdr, buf);
 	if (ret) {
-		dprintf("remote node might have gone away\n");
+		sd_dprintf("remote node might have gone away\n");
 		sheep_del_sockfd(nid, sfd);
 		return SD_RES_NETWORK_ERROR;
 	}
 	ret = rsp->result;
 	if (ret != SD_RES_SUCCESS)
-		eprintf("failed %x\n", ret);
+		sd_eprintf("failed %x\n", ret);
 
 	sheep_put_sockfd(nid, sfd);
 	return ret;
diff --git a/sheep/store.c b/sheep/store.c
index b0dc7e7..477c5f3 100644
--- a/sheep/store.c
+++ b/sheep/store.c
@@ -45,7 +45,7 @@ int update_epoch_log(uint32_t epoch, struct sd_node *nodes, size_t nr_nodes)
 	time_t t;
 	char path[PATH_MAX];
 
-	dprintf("update epoch: %d, %zd\n", epoch, nr_nodes);
+	sd_dprintf("update epoch: %d, %zd\n", epoch, nr_nodes);
 
 	snprintf(path, sizeof(path), "%s%08u", epoch_path, epoch);
 	fd = open(path, O_RDWR | O_CREAT | O_DSYNC, def_fmode);
@@ -71,7 +71,7 @@ int update_epoch_log(uint32_t epoch, struct sd_node *nodes, size_t nr_nodes)
 err:
 	close(fd);
 err_open:
-	dprintf("%s\n", strerror(errno));
+	sd_dprintf("%s\n", strerror(errno));
 	return -1;
 }
 
@@ -121,7 +121,7 @@ int epoch_log_read(uint32_t epoch, struct sd_node *nodes, int len)
 	snprintf(path, sizeof(path), "%s%08u", epoch_path, epoch);
 	fd = open(path, O_RDONLY);
 	if (fd < 0) {
-		eprintf("failed to open epoch %"PRIu32" log\n", epoch);
+		sd_eprintf("failed to open epoch %"PRIu32" log\n", epoch);
 		return -1;
 	}
 
@@ -130,7 +130,7 @@ int epoch_log_read(uint32_t epoch, struct sd_node *nodes, int len)
 	close(fd);
 
 	if (len < 0) {
-		eprintf("failed to read epoch %"PRIu32" log\n", epoch);
+		sd_eprintf("failed to read epoch %"PRIu32" log\n", epoch);
 		return -1;
 	}
 	return len / sizeof(*nodes);
@@ -145,7 +145,7 @@ uint32_t get_latest_epoch(void)
 
 	dir = opendir(epoch_path);
 	if (!dir) {
-		vprintf(SDOG_EMERG, "failed to get the latest epoch: %m\n");
+		sd_printf(SDOG_EMERG, "failed to get the latest epoch: %m\n");
 		abort();
 	}
 
@@ -176,13 +176,13 @@ again:
 	ret = stat(d, &s);
 	if (ret) {
 		if (retry || errno != ENOENT) {
-			eprintf("cannot handle the directory %s: %m\n", d);
+			sd_eprintf("cannot handle the directory %s: %m\n", d);
 			return 1;
 		}
 
 		ret = mkdir(d, def_dmode);
 		if (ret) {
-			eprintf("cannot create the directory %s: %m\n", d);
+			sd_eprintf("cannot create the directory %s: %m\n", d);
 			return 1;
 		} else {
 			if (new)
@@ -193,7 +193,7 @@ again:
 	}
 
 	if (!S_ISDIR(s.st_mode)) {
-		eprintf("%s is not a directory\n", d);
+		sd_eprintf("%s is not a directory\n", d);
 		return 1;
 	}
 
@@ -213,7 +213,7 @@ static int lock_base_dir(const char *d)
 
 	fd = open(lock_path, O_WRONLY|O_CREAT, def_fmode);
 	if (fd < 0) {
-		eprintf("failed to open lock file %s (%s)\n",
+		sd_eprintf("failed to open lock file %s (%s)\n",
 			lock_path, strerror(errno));
 		ret = -1;
 		goto out;
@@ -221,9 +221,9 @@ static int lock_base_dir(const char *d)
 
 	if (lockf(fd, F_TLOCK, 1) < 0) {
 		if (errno == EACCES || errno == EAGAIN) {
-			eprintf("another sheep daemon is using %s\n", d);
+			sd_eprintf("another sheep daemon is using %s\n", d);
 		} else {
-			eprintf("unable to get base dir lock (%s)\n",
+			sd_eprintf("unable to get base dir lock (%s)\n",
 				strerror(errno));
 		}
 		ret = -1;
@@ -256,7 +256,7 @@ int init_obj_path(const char *base_path)
 	 * HEX_LEN + 3 = '/' + hex(2) + '/' + hex(38) + '\0'
 	 */
 	if (len + HEX_LEN + 3 > PATH_MAX) {
-		eprintf("insanely long object directory %s", base_path);
+		sd_eprintf("insanely long object directory %s", base_path);
 		return -1;
 	}
 
@@ -317,7 +317,7 @@ int init_store_driver(void)
 		 * If the driver name is not NUL terminated we are in deep
 		 * trouble, let's get out here.
 		 */
-		dprintf("store name not NUL terminated\n");
+		sd_dprintf("store name not NUL terminated\n");
 		return SD_RES_NO_STORE;
 	}
 
@@ -330,7 +330,7 @@ int init_store_driver(void)
 
 	sd_store = find_store_driver(driver_name);
 	if (!sd_store) {
-		dprintf("store %s not found\n", driver_name);
+		sd_dprintf("store %s not found\n", driver_name);
 		return SD_RES_NO_STORE;
 	}
 
@@ -359,7 +359,7 @@ int init_disk_space(const char *base_path)
 
 	ret = statvfs(base_path, &fs);
 	if (ret < 0) {
-		dprintf("get disk space failed %m\n");
+		sd_dprintf("get disk space failed %m\n");
 		ret = SD_RES_EIO;
 		goto out;
 	}
@@ -367,7 +367,7 @@ int init_disk_space(const char *base_path)
 	sys->disk_space = (uint64_t)fs.f_frsize * fs.f_bfree;
 	ret = set_cluster_space(sys->disk_space);
 out:
-	dprintf("disk free space is %" PRIu64 "\n", sys->disk_space);
+	sd_dprintf("disk free space is %" PRIu64 "\n", sys->disk_space);
 	return ret;
 }
 
@@ -411,7 +411,7 @@ int write_object(uint64_t oid, char *data, unsigned int datalen,
 			goto forward_write;
 
 		if (ret != 0) {
-			eprintf("write cache failed %"PRIx64" %"PRIx32"\n",
+			sd_eprintf("write cache failed %"PRIx64" %"PRIx32"\n",
 				oid, ret);
 			return ret;
 		}
@@ -431,7 +431,8 @@ forward_write:
 
 	ret = exec_local_req(&hdr, data);
 	if (ret != SD_RES_SUCCESS)
-		eprintf("failed to write object %" PRIx64 ", %x\n", oid, ret);
+		sd_eprintf("failed to write object %" PRIx64 ", %x\n",
+			oid, ret);
 
 	return ret;
 }
@@ -451,7 +452,7 @@ int read_backend_object(uint64_t oid, char *data, unsigned int datalen,
 
 	ret = exec_local_req(&hdr, data);
 	if (ret != SD_RES_SUCCESS)
-		eprintf("failed to read object %" PRIx64 ", %x\n", oid, ret);
+		sd_eprintf("failed to read object %" PRIx64 ", %x\n", oid, ret);
 
 	untrim_zero_sectors(data, rsp->obj.offset, rsp->data_length, datalen);
 
@@ -470,7 +471,7 @@ int read_object(uint64_t oid, char *data, unsigned int datalen,
 	if (is_object_cache_enabled() && object_is_cached(oid)) {
 		ret = object_cache_read(oid, data, datalen, offset);
 		if (ret != SD_RES_SUCCESS) {
-			eprintf("try forward read %"PRIx64" %"PRIx32"\n",
+			sd_eprintf("try forward read %"PRIx64" %"PRIx32"\n",
 				oid, ret);
 			goto forward_read;
 		}
@@ -494,7 +495,8 @@ int remove_object(uint64_t oid, int copies)
 
 	ret = exec_local_req(&hdr, NULL);
 	if (ret != SD_RES_SUCCESS)
-		eprintf("failed to remove object %" PRIx64 ", %x\n", oid, ret);
+		sd_eprintf("failed to remove object %" PRIx64 ", %x\n",
+			oid, ret);
 
 	return ret;
 }
diff --git a/sheep/trace/trace.c b/sheep/trace/trace.c
index b63f4d2..adaf4e6 100644
--- a/sheep/trace/trace.c
+++ b/sheep/trace/trace.c
@@ -124,14 +124,14 @@ notrace struct caller *trace_lookup_ip(unsigned long ip, bool create)
 	}
 not_found:
 	if (get_ipinfo(ip, &info) < 0) {
-		dprintf("ip: %lx not found\n", ip);
+		sd_dprintf("ip: %lx not found\n", ip);
 		new = NULL;
 		goto out;
 	}
 	if (create) {
 		new = malloc(sizeof(*new));
 		if (!new) {
-			eprintf("out of memory\n");
+			sd_eprintf("out of memory\n");
 			goto out;
 		}
 		new->mcount = ip;
@@ -139,9 +139,9 @@ not_found:
 		new->name = info.fn_name;
 		hlist_add_head(&new->hash, head);
 		list_add(&new->list, &caller_list);
-		dprintf("add %.*s\n", info.fn_namelen, info.fn_name);
+		sd_dprintf("add %.*s\n", info.fn_namelen, info.fn_name);
 	} else {
-		dprintf("%.*s\n not found", info.fn_namelen, info.fn_name);
+		sd_dprintf("%.*s\n not found", info.fn_namelen, info.fn_name);
 		new = NULL;
 	}
 out:
@@ -187,7 +187,7 @@ static notrace void suspend_worker_threads(void)
 	list_for_each_entry(wi, &worker_info_list, worker_info_siblings) {
 		if (wi->ordered &&
 		    pthread_kill(wi->worker_thread, SIGUSR2) != 0)
-			dprintf("%m\n");
+			sd_dprintf("%m\n");
 	}
 
 wait_for_worker_suspend:
@@ -247,7 +247,7 @@ static notrace void enable_tracer(int fd, int events, void *data)
 	 * expected to be waken up by epoll again.
 	 */
 	if (ret < 0) {
-		eprintf("%m\n");
+		sd_eprintf("%m\n");
 		return;
 	}
 
@@ -259,7 +259,7 @@ static notrace void enable_tracer(int fd, int events, void *data)
 	resume_worker_threads();
 	unregister_event(trace_efd);
 	trace_in_patch = false;
-	dprintf("tracer enabled\n");
+	sd_dprintf("tracer enabled\n");
 }
 
 static notrace void disable_tracer(int fd, int events, void *data)
@@ -269,7 +269,7 @@ static notrace void disable_tracer(int fd, int events, void *data)
 
 	ret = eventfd_read(fd, &value);
 	if (ret < 0) {
-		eprintf("%m\n");
+		sd_eprintf("%m\n");
 		return;
 	}
 
@@ -281,13 +281,13 @@ static notrace void disable_tracer(int fd, int events, void *data)
 	resume_worker_threads();
 	unregister_event(trace_efd);
 	trace_in_patch = false;
-	dprintf("tracer disabled\n");
+	sd_dprintf("tracer disabled\n");
 }
 
 notrace int trace_enable(void)
 {
 	if (trace_func == trace_call) {
-		dprintf("no tracer available\n");
+		sd_dprintf("no tracer available\n");
 		return SD_RES_NO_TAG;
 	}
 
@@ -313,7 +313,7 @@ int trace_init_signal(void)
 	act.sa_handler = suspend;
 	/* trace uses this signal to suspend the worker threads */
 	if (sigaction(SIGUSR2, &act, NULL) < 0) {
-		dprintf("%m\n");
+		sd_dprintf("%m\n");
 		return -1;
 	}
 	return 0;
@@ -370,12 +370,12 @@ notrace int trace_init(void)
 	sigemptyset(&block);
 	sigaddset(&block, SIGUSR2);
 	if (pthread_sigmask(SIG_BLOCK, &block, NULL) != 0) {
-		dprintf("%m\n");
+		sd_dprintf("%m\n");
 		return -1;
 	}
 
 	if (make_text_writable((unsigned long)mcount_call) < 0) {
-		dprintf("%m\n");
+		sd_dprintf("%m\n");
 		return -1;
 	}
 
@@ -388,6 +388,6 @@ notrace int trace_init(void)
 
 	trace_efd = eventfd(0, EFD_NONBLOCK);
 
-	dprintf("trace support enabled. cpu count %d.\n", nr_cpu);
+	sd_dprintf("trace support enabled. cpu count %d.\n", nr_cpu);
 	return 0;
 }
diff --git a/sheep/vdi.c b/sheep/vdi.c
index eabe19e..6133e4d 100644
--- a/sheep/vdi.c
+++ b/sheep/vdi.c
@@ -79,7 +79,7 @@ int get_vdi_copy_number(uint32_t vid)
 	pthread_rwlock_unlock(&vdi_copy_lock);
 
 	if (!entry) {
-		eprintf("No VDI copy entry for %" PRIx32 " found\n", vid);
+		sd_eprintf("No VDI copy entry for %" PRIx32 " found\n", vid);
 		return 0;
 	}
 
@@ -122,7 +122,7 @@ int add_vdi_copy_number(uint32_t vid, int nr_copies)
 	entry->vid = vid;
 	entry->nr_copies = nr_copies;
 
-	dprintf("%" PRIx32 ", %d\n", vid, nr_copies);
+	sd_dprintf("%" PRIx32 ", %d\n", vid, nr_copies);
 
 	pthread_rwlock_wrlock(&vdi_copy_lock);
 	old = vdi_copy_insert(&vdi_copy_root, entry);
@@ -177,7 +177,7 @@ int vdi_exist(uint32_t vid)
 	ret = read_object(vid_to_vdi_oid(vid), (char *)inode,
 			  sizeof(*inode), 0, nr_copies);
 	if (ret != SD_RES_SUCCESS) {
-		eprintf("fail to read vdi inode (%" PRIx32 ")\n", vid);
+		sd_eprintf("fail to read vdi inode (%" PRIx32 ")\n", vid);
 		ret = 0;
 		goto out;
 	}
@@ -205,14 +205,14 @@ static int create_vdi_obj(struct vdi_iocb *iocb, uint32_t new_vid,
 
 	new = zalloc(sizeof(*new));
 	if (!new) {
-		eprintf("failed to allocate memory\n");
+		sd_eprintf("failed to allocate memory\n");
 		goto out;
 	}
 
 	if (iocb->base_vid) {
 		base = zalloc(sizeof(*base));
 		if (!base) {
-			eprintf("failed to allocate memory\n");
+			sd_eprintf("failed to allocate memory\n");
 			goto out;
 		}
 	}
@@ -220,7 +220,7 @@ static int create_vdi_obj(struct vdi_iocb *iocb, uint32_t new_vid,
 	if (iocb->create_snapshot && cur_vid != iocb->base_vid) {
 		cur = zalloc(SD_INODE_HEADER_SIZE);
 		if (!cur) {
-			eprintf("failed to allocate memory\n");
+			sd_eprintf("failed to allocate memory\n");
 			goto out;
 		}
 	}
@@ -238,13 +238,13 @@ static int create_vdi_obj(struct vdi_iocb *iocb, uint32_t new_vid,
 
 	if (iocb->create_snapshot) {
 		if (cur_vid != iocb->base_vid) {
-			vprintf(SDOG_INFO, "tree snapshot %s %" PRIx32 " %" PRIx32 "\n",
-				name, cur_vid, iocb->base_vid);
+			sd_printf(SDOG_INFO, "tree snapshot %s %" PRIx32 " %"
+				PRIx32 "\n", name, cur_vid, iocb->base_vid);
 
 			ret = read_object(vid_to_vdi_oid(cur_vid), (char *)cur,
 					  SD_INODE_HEADER_SIZE, 0, 0);
 			if (ret != SD_RES_SUCCESS) {
-				vprintf(SDOG_ERR, "failed\n");
+				sd_printf(SDOG_ERR, "failed\n");
 				ret = SD_RES_BASE_VDI_READ;
 				goto out;
 			}
@@ -286,7 +286,7 @@ static int create_vdi_obj(struct vdi_iocb *iocb, uint32_t new_vid,
 		ret = write_object(vid_to_vdi_oid(cur_vid), (char *)cur,
 				   SD_INODE_HEADER_SIZE, 0, 0, false, 0);
 		if (ret != 0) {
-			vprintf(SDOG_ERR, "failed\n");
+			sd_printf(SDOG_ERR, "failed\n");
 			ret = SD_RES_BASE_VDI_READ;
 			goto out;
 		}
@@ -296,7 +296,7 @@ static int create_vdi_obj(struct vdi_iocb *iocb, uint32_t new_vid,
 		ret = write_object(vid_to_vdi_oid(iocb->base_vid), (char *)base,
 				   SD_INODE_HEADER_SIZE, 0, 0, false, 0);
 		if (ret != 0) {
-			vprintf(SDOG_ERR, "failed\n");
+			sd_printf(SDOG_ERR, "failed\n");
 			ret = SD_RES_BASE_VDI_WRITE;
 			goto out;
 		}
@@ -328,7 +328,7 @@ static int find_first_vdi(unsigned long start, unsigned long end,
 
 	inode = malloc(SD_INODE_HEADER_SIZE);
 	if (!inode) {
-		eprintf("failed to allocate memory\n");
+		sd_eprintf("failed to allocate memory\n");
 		goto out;
 	}
 
@@ -390,7 +390,7 @@ static int do_lookup_vdi(const char *name, int namelen, uint32_t *vid,
 
 	start_nr = fnv_64a_buf(name, namelen, FNV1A_64_INIT) & (SD_NR_VDIS - 1);
 
-	vprintf(SDOG_INFO, "looking for %s (%lx)\n", name, start_nr);
+	sd_printf(SDOG_INFO, "looking for %s (%lx)\n", name, start_nr);
 
 	/* bitmap search from the hash point */
 	nr = find_next_zero_bit(sys->vdi_inuse, SD_NR_VDIS, start_nr);
@@ -454,7 +454,7 @@ static int notify_vdi_add(uint32_t vdi_id, uint32_t nr_copies)
 
 	ret = exec_local_req(&hdr, buf);
 	if (ret != SD_RES_SUCCESS)
-		eprintf("fail to notify vdi add event(%" PRIx32 ", %d)\n",
+		sd_eprintf("fail to notify vdi add event(%" PRIx32 ", %d)\n",
 			vdi_id, nr_copies);
 
 	free(buf);
@@ -483,7 +483,8 @@ int add_vdi(struct vdi_iocb *iocb, uint32_t *new_vid)
 	if (iocb->create_snapshot) {
 		if (ret != SD_RES_SUCCESS) {
 			if (ret == SD_RES_NO_VDI)
-				vprintf(SDOG_CRIT, "VDI %s does not exist\n", name);
+				sd_printf(SDOG_CRIT, "VDI %s does not exist\n",
+					name);
 			return ret;
 		}
 		nr = right_nr;
@@ -505,7 +506,7 @@ int add_vdi(struct vdi_iocb *iocb, uint32_t *new_vid)
 
 	notify_vdi_add(nr, iocb->nr_copies);
 
-	vprintf(SDOG_INFO, "creating new %s %s: size %" PRIu64 ", vid %"
+	sd_printf(SDOG_INFO, "creating new %s %s: size %" PRIu64 ", vid %"
 		PRIx32 ", base %" PRIx32 ", cur %" PRIx32 ", copies %d\n",
 		iocb->create_snapshot ? "snapshot" : "vdi", name, iocb->size,
 		*new_vid, iocb->base_vid, cur_vid, iocb->nr_copies);
@@ -577,7 +578,7 @@ static int delete_inode(struct deletion_work *dw)
 
 	inode = zalloc(sizeof(*inode));
 	if (!inode) {
-		eprintf("no memory to allocate inode.\n");
+		sd_eprintf("no memory to allocate inode.\n");
 		goto out;
 	}
 
@@ -613,7 +614,7 @@ static int notify_vdi_deletion(uint32_t vdi_id)
 
 	ret = exec_local_req(&hdr, &vdi_id);
 	if (ret != SD_RES_SUCCESS)
-		eprintf("fail to notify vdi deletion(%" PRIx32 "), %d\n",
+		sd_eprintf("fail to notify vdi deletion(%" PRIx32 "), %d\n",
 			vdi_id, ret);
 
 	return ret;
@@ -627,11 +628,11 @@ static void delete_one(struct work *work)
 	struct sheepdog_inode *inode = NULL;
 	int nr_copies;
 
-	eprintf("%d %d, %16x\n", dw->done, dw->count, vdi_id);
+	sd_eprintf("%d %d, %16x\n", dw->done, dw->count, vdi_id);
 
 	inode = malloc(sizeof(*inode));
 	if (!inode) {
-		eprintf("failed to allocate memory\n");
+		sd_eprintf("failed to allocate memory\n");
 		goto out;
 	}
 
@@ -640,7 +641,7 @@ static void delete_one(struct work *work)
 			  (void *)inode, sizeof(*inode), 0, nr_copies);
 
 	if (ret != SD_RES_SUCCESS) {
-		eprintf("cannot find VDI object\n");
+		sd_eprintf("cannot find VDI object\n");
 		goto out;
 	}
 
@@ -656,14 +657,15 @@ static void delete_one(struct work *work)
 		oid = vid_to_data_oid(inode->data_vdi_id[i], i);
 
 		if (inode->data_vdi_id[i] != inode->vdi_id) {
-			dprintf("object %" PRIx64 " is base's data, would not be deleted.\n",
-				oid);
+			sd_dprintf("object %" PRIx64 " is base's data, would"
+				" not be deleted.\n", oid);
 			continue;
 		}
 
 		ret = remove_object(oid, nr_copies);
 		if (ret != SD_RES_SUCCESS)
-			eprintf("remove object %" PRIx64 " fail, %d\n", oid, ret);
+			sd_eprintf("remove object %" PRIx64 " fail, %d\n",
+				oid, ret);
 
 		nr_deleted++;
 	}
@@ -719,7 +721,7 @@ static int fill_vdi_list(struct deletion_work *dw, uint32_t root_vid)
 
 	inode = malloc(SD_INODE_HEADER_SIZE);
 	if (!inode) {
-		eprintf("failed to allocate memory\n");
+		sd_eprintf("failed to allocate memory\n");
 		goto err;
 	}
 
@@ -731,7 +733,7 @@ again:
 			  SD_INODE_HEADER_SIZE, 0, nr_copies);
 
 	if (ret != SD_RES_SUCCESS) {
-		eprintf("cannot find VDI object\n");
+		sd_eprintf("cannot find VDI object\n");
 		goto err;
 	}
 
@@ -764,7 +766,7 @@ static uint64_t get_vdi_root(uint32_t vid, bool *cloned)
 
 	inode = malloc(SD_INODE_HEADER_SIZE);
 	if (!inode) {
-		eprintf("failed to allocate memory\n");
+		sd_eprintf("failed to allocate memory\n");
 		vid = 0;
 		goto out;
 	}
@@ -776,13 +778,13 @@ next:
 	if (vid == inode->vdi_id && inode->snap_id == 1
 			&& inode->parent_vdi_id != 0
 			&& !inode->snap_ctime) {
-		dprintf("vdi %" PRIx32 " is a cloned vdi.\n", vid);
+		sd_dprintf("vdi %" PRIx32 " is a cloned vdi.\n", vid);
 		/* current vdi is a cloned vdi */
 		*cloned = true;
 	}
 
 	if (ret != SD_RES_SUCCESS) {
-		eprintf("cannot find VDI object\n");
+		sd_eprintf("cannot find VDI object\n");
 		vid = 0;
 		goto out;
 	}
@@ -837,7 +839,7 @@ static int start_deletion(struct request *req, uint32_t vid)
 			dw->buf[0] = vid;
 			dw->count = 1;
 		} else {
-			dprintf("snapshot chain has valid vdi, "
+			sd_dprintf("snapshot chain has valid vdi, "
 				"just mark vdi %" PRIx32 " as deleted.\n",
 				dw->vid);
 			delete_inode(dw);
@@ -845,7 +847,7 @@ static int start_deletion(struct request *req, uint32_t vid)
 		}
 	}
 
-	dprintf("%d\n", dw->count);
+	sd_dprintf("%d\n", dw->count);
 
 	if (dw->count == 0)
 		goto out;
@@ -937,7 +939,7 @@ int get_vdi_attr(struct sheepdog_vdi_attr *vattr, int data_len,
 		(*attrid)++;
 	}
 
-	dprintf("there is no space for new VDIs\n");
+	sd_dprintf("there is no space for new VDIs\n");
 	ret = SD_RES_FULL_VDI;
 out:
 	return ret;
diff --git a/sheep/work.c b/sheep/work.c
index 49eac9a..bf3dccf 100644
--- a/sheep/work.c
+++ b/sheep/work.c
@@ -190,13 +190,13 @@ int init_wqueue_eventfd(void)
 
 	efd = eventfd(0, EFD_NONBLOCK);
 	if (efd < 0) {
-		eprintf("failed to create an event fd: %m\n");
+		sd_eprintf("failed to create an event fd: %m\n");
 		return 1;
 	}
 
 	ret = register_event(efd, bs_thread_request_done, NULL);
 	if (ret) {
-		eprintf("failed to register event fd %m\n");
+		sd_eprintf("failed to register event fd %m\n");
 		close(efd);
 		return 1;
 	}
@@ -232,7 +232,7 @@ struct work_queue *init_work_queue(const char *name, bool ordered)
 		ret = pthread_create(&wi->worker_thread, NULL, worker_routine,
 				     wi);
 		if (ret) {
-			eprintf("failed to create worker thread: %s\n",
+			sd_eprintf("failed to create worker thread: %s\n",
 				strerror(ret));
 			goto destroy_threads;
 		}
@@ -249,7 +249,7 @@ destroy_threads:
 	wi->q.wq_state |= WQ_DEAD;
 	pthread_mutex_unlock(&wi->startup_lock);
 	pthread_join(wi->worker_thread, NULL);
-	eprintf("stopped worker thread\n");
+	sd_eprintf("stopped worker thread\n");
 
 /* destroy_cond_mutex: */
 	pthread_cond_destroy(&wi->pending_cond);
-- 
1.7.5.1




More information about the sheepdog mailing list