[Sheepdog] [PATCH 5/5] logger: fix the vprintf() bug

Andychen sanjie.cyg at taobao.com
Wed Oct 12 17:55:34 CEST 2011


From: Andy chen <sanjie.cyg at taobao.com>


Signed-off-by: Andychen <sanjie.cyg at taobao.com>
---
 include/logger.h         |    6 ++--
 lib/logger.c             |    4 +-
 sheep/cluster/corosync.c |   10 ++++----
 sheep/group.c            |   47 +++++++++++++++++++++++----------------------
 sheep/sheep.c            |    4 +-
 sheep/store.c            |   16 +++++++-------
 sheep/vdi.c              |   16 +++++++-------
 7 files changed, 52 insertions(+), 51 deletions(-)

diff --git a/include/logger.h b/include/logger.h
index cdd7642..461f2d9 100644
--- a/include/logger.h
+++ b/include/logger.h
@@ -64,14 +64,14 @@ extern void log_write(int prio, const char *func, int line, const char *fmt, ...
 #define	SDOG_INFO		LOG_INFO
 #define	SDOG_DEBUG		LOG_DEBUG
 
-#define vprintf(fmt, args...)						\
+#define vprintf(level, fmt, args...)						\
 do {									\
-	log_write(LOG_INFO, __func__, __LINE__, fmt, ##args);		\
+	log_write(level, __func__, __LINE__, fmt, ##args);		\
 } while (0)
 
 #define panic(fmt, args...)			\
 ({						\
-	vprintf(SDOG_EMERG fmt, ##args);	\
+	vprintf(SDOG_EMERG, fmt, ##args);	\
 	abort();				\
 })
 
diff --git a/lib/logger.c b/lib/logger.c
index 688c9b8..9cfc746 100644
--- a/lib/logger.c
+++ b/lib/logger.c
@@ -364,7 +364,7 @@ static void log_flush(void)
 
 static void log_sigsegv(void)
 {
-	vprintf(SDOG_ERR "sheep logger exits abnormally, pid:%d\n", getpid());
+	vprintf(SDOG_ERR, "sheep logger exits abnormally, pid:%d\n", getpid());
 	log_flush();
 	closelog();
 	free_logarea();
@@ -456,7 +456,7 @@ void log_close(void)
 		la->active = 0;
 		waitpid(pid, NULL, 0);
 
-		vprintf(SDOG_WARNING "sheep logger stopped, pid:%d\n", pid);
+		vprintf(SDOG_WARNING, "sheep logger stopped, pid:%d\n", pid);
 		log_flush();
 		closelog();
 		free_logarea();
diff --git a/sheep/cluster/corosync.c b/sheep/cluster/corosync.c
index 002e06f..e99238a 100644
--- a/sheep/cluster/corosync.c
+++ b/sheep/cluster/corosync.c
@@ -33,12 +33,12 @@ static int nodeid_to_addr(uint32_t nodeid, uint8_t *addr)
 
 	ret = corosync_cfg_get_node_addrs(cfg_handle, nodeid, 1, &nr, &caddr);
 	if (ret != CS_OK) {
-		vprintf(SDOG_ERR "failed to get addr %d\n", ret);
+		vprintf(SDOG_ERR, "failed to get addr %d\n", ret);
 		return -1;
 	}
 
 	if (!nr) {
-		vprintf(SDOG_ERR "we got no address\n");
+		vprintf(SDOG_ERR, "we got no address\n");
 		return -1;
 	}
 
@@ -50,7 +50,7 @@ static int nodeid_to_addr(uint32_t nodeid, uint8_t *addr)
 		memset(addr, 0, 16);
 		memcpy(addr + 12, saddr, 4);
 	} else {
-		vprintf(SDOG_ERR "unknown protocol %d\n", ss->ss_family);
+		vprintf(SDOG_ERR, "unknown protocol %d\n", ss->ss_family);
 		return -1;
 	}
 
@@ -150,13 +150,13 @@ static int corosync_init(struct cdrv_handlers *handlers, struct sheepid *myid)
 
 	ret = corosync_cfg_initialize(&cfg_handle, NULL);
 	if (ret != CS_OK) {
-		vprintf(SDOG_ERR "failed to initiazize cfg %d\n", ret);
+		vprintf(SDOG_ERR, "failed to initiazize cfg %d\n", ret);
 		return -1;
 	}
 
 	ret = corosync_cfg_local_get(cfg_handle, &nodeid);
 	if (ret != CS_OK) {
-		vprintf(SDOG_ERR "failed to get nodeid %d\n", ret);
+		vprintf(SDOG_ERR, "failed to get nodeid %d\n", ret);
 		return -1;
 	}
 
diff --git a/sheep/group.c b/sheep/group.c
index f6743f5..eb64207 100644
--- a/sheep/group.c
+++ b/sheep/group.c
@@ -690,12 +690,12 @@ static int get_vdi_bitmap_from(struct sheepdog_node_list_entry *node)
 
 	fd = connect_to(host, node->port);
 	if (fd < 0) {
-		vprintf(SDOG_ERR "can't get the vdi bitmap %s, %m\n", host);
+		vprintf(SDOG_ERR, "can't get the vdi bitmap %s, %m\n", host);
 		ret = -SD_RES_EIO;
 		goto out;
 	}
 
-	vprintf(SDOG_ERR "get the vdi bitmap from %s\n", host);
+	vprintf(SDOG_ERR, "get the vdi bitmap from %s\n", host);
 
 	memset(&hdr, 0, sizeof(hdr));
 	hdr.opcode = SD_OP_READ_VDIS;
@@ -710,7 +710,7 @@ static int get_vdi_bitmap_from(struct sheepdog_node_list_entry *node)
 	close(fd);
 
 	if (ret || rsp->result != SD_RES_SUCCESS) {
-		vprintf(SDOG_ERR "can't get the vdi bitmap %d %d\n", ret,
+		vprintf(SDOG_ERR, "can't get the vdi bitmap %d %d\n", ret,
 				rsp->result);
 		goto out;
 	}
@@ -806,7 +806,7 @@ static void update_cluster_info(struct join_message *msg)
 		 * the JOIN response however it has gone.
 		 */
 		if (ret)
-			vprintf(SDOG_INFO "%s has gone\n",
+			vprintf(SDOG_INFO, "%s has gone\n",
 				sheepid_to_str(&msg->nodes[i].sheepid));
 	}
 
@@ -825,7 +825,7 @@ join_finished:
 	 * host from msg on cpg_node_list.
 	 */
 	if (ret)
-		vprintf(SDOG_ERR "%s has gone\n",
+		vprintf(SDOG_ERR, "%s has gone\n",
 			sheepid_to_str(&msg->header.sheepid));
 
 	if (msg->cluster_status == SD_STATUS_OK) {
@@ -927,7 +927,7 @@ static void vdi_op_done(struct vdi_op_message *msg)
 	case SD_OP_NEW_VDI:
 	{
 		unsigned long nr = rsp->vdi_id;
-		vprintf(SDOG_INFO "done %d %ld\n", ret, nr);
+		vprintf(SDOG_INFO, "done %d %ld\n", ret, nr);
 		set_bit(nr, sys->vdi_inuse);
 		break;
 	}
@@ -1208,7 +1208,7 @@ static void sd_notify_handler(struct sheepid *sender, void *msg, size_t msg_len)
 	cevent = &w->cev;
 	cevent->ctype = CPG_EVENT_NOTIFY;
 
-	vprintf(SDOG_DEBUG "allow new deliver, %p\n", cevent);
+	vprintf(SDOG_DEBUG, "allow new deliver, %p\n", cevent);
 
 	w->msg = zalloc(msg_len);
 	if (!w->msg)
@@ -1349,7 +1349,7 @@ static void send_join_request(struct sheepid *id)
 
 	sys->cdrv->notify(&msg, msg.header.msg_length);
 
-	vprintf(SDOG_INFO "%s\n", sheepid_to_str(&sys->this_sheepid));
+	vprintf(SDOG_INFO, "%s\n", sheepid_to_str(&sys->this_sheepid));
 }
 
 static void __sd_join_done(struct cpg_event *cevent)
@@ -1383,7 +1383,7 @@ static void __sd_join_done(struct cpg_event *cevent)
 		 * becomes the master without sending JOIN.
 		 */
 
-		vprintf(SDOG_DEBUG "%s\n", sheepid_to_str(&sys->this_sheepid));
+		vprintf(SDOG_DEBUG, "%s\n", sheepid_to_str(&sys->this_sheepid));
 
 		memset(&msg, 0, sizeof(msg));
 
@@ -1459,7 +1459,7 @@ static void cpg_event_fn(struct work *work, int idx)
 {
 	struct cpg_event *cevent = sys->cur_cevent;
 
-	vprintf(SDOG_DEBUG "%p, %d %lx\n", cevent, cevent->ctype,
+	vprintf(SDOG_DEBUG, "%p, %d %lx\n", cevent, cevent->ctype,
 		sys->cpg_event_work_flags);
 
 	/*
@@ -1476,15 +1476,15 @@ static void cpg_event_fn(struct work *work, int idx)
 	case CPG_EVENT_NOTIFY:
 	{
 		struct work_notify *w = container_of(cevent, struct work_notify, cev);
-		vprintf(SDOG_DEBUG "%d\n", w->msg->state);
+		vprintf(SDOG_DEBUG, "%d\n", w->msg->state);
 		__sd_notify(cevent);
 		break;
 	}
 	case CPG_EVENT_REQUEST:
-		vprintf(SDOG_ERR "should not happen\n");
+		vprintf(SDOG_ERR, "should not happen\n");
 		break;
 	default:
-		vprintf(SDOG_ERR "unknown event %d\n", cevent->ctype);
+		vprintf(SDOG_ERR, "unknown event %d\n", cevent->ctype);
 	}
 }
 
@@ -1493,12 +1493,12 @@ static void cpg_event_done(struct work *work, int idx)
 	struct cpg_event *cevent;
 
 	if (!sys->cur_cevent)
-		vprintf(SDOG_ERR "bug\n");
+		vprintf(SDOG_ERR, "bug\n");
 
 	cevent = sys->cur_cevent;
 	sys->cur_cevent = NULL;
 
-	vprintf(SDOG_DEBUG "%p\n", cevent);
+	vprintf(SDOG_DEBUG, "%p\n", cevent);
 
 	if (cpg_event_suspended())
 		goto out;
@@ -1535,7 +1535,7 @@ static void cpg_event_done(struct work *work, int idx)
 					container_of(f_cevent, struct work_notify, cev);
 				if (f_cevent->ctype == CPG_EVENT_NOTIFY &&
 				    fw->msg->state == DM_FIN) {
-					vprintf("already got fin %p\n",
+					vprintf(SDOG_INFO, "already got fin %p\n",
 						f_cevent);
 
 					list_del(&f_cevent->cpg_event_list);
@@ -1553,13 +1553,14 @@ static void cpg_event_done(struct work *work, int idx)
 		break;
 	}
 	case CPG_EVENT_REQUEST:
-		vprintf(SDOG_ERR "should not happen\n");
+		vprintf(SDOG_ERR, "should not happen\n");
+		break;
 	default:
-		vprintf(SDOG_ERR "unknown event %d\n", cevent->ctype);
+		vprintf(SDOG_ERR, "unknown event %d\n", cevent->ctype);
 	}
 
 out:
-	vprintf(SDOG_DEBUG "free %p\n", cevent);
+	vprintf(SDOG_DEBUG, "free %p\n", cevent);
 	cpg_event_free(cevent);
 	cpg_event_clear_running();
 
@@ -1645,12 +1646,12 @@ void start_cpg_event_work(void)
 	int retry;
 
 	if (list_empty(&sys->cpg_event_siblings))
-		vprintf(SDOG_ERR "bug\n");
+		vprintf(SDOG_ERR, "bug\n");
 
 	cevent = list_first_entry(&sys->cpg_event_siblings,
 				  struct cpg_event, cpg_event_list);
 
-	vprintf(SDOG_DEBUG "%lx %u\n", sys->cpg_event_work_flags,
+	vprintf(SDOG_DEBUG, "%lx %u\n", sys->cpg_event_work_flags,
 		cevent->ctype);
 
 	/*
@@ -1817,7 +1818,7 @@ static void sd_join_handler(struct sheepid *joined, struct sheepid *members,
 	cevent->ctype = CPG_EVENT_JOIN;
 
 
-	vprintf(SDOG_DEBUG "allow new confchg, %p\n", cevent);
+	vprintf(SDOG_DEBUG, "allow new confchg, %p\n", cevent);
 
 	size = sizeof(struct sheepid) * nr_members;
 	w->member_list = zalloc(size);
@@ -1863,7 +1864,7 @@ static void sd_leave_handler(struct sheepid *left, struct sheepid *members,
 	cevent->ctype = CPG_EVENT_LEAVE;
 
 
-	vprintf(SDOG_DEBUG "allow new confchg, %p\n", cevent);
+	vprintf(SDOG_DEBUG, "allow new confchg, %p\n", cevent);
 
 	size = sizeof(struct sheepid) * nr_members;
 	w->member_list = zalloc(size);
diff --git a/sheep/sheep.c b/sheep/sheep.c
index d6467dc..27859ca 100644
--- a/sheep/sheep.c
+++ b/sheep/sheep.c
@@ -210,12 +210,12 @@ int main(int argc, char **argv)
 		exit(1);
 	}
 
-	vprintf(SDOG_NOTICE "Sheepdog daemon (version %s) started\n", PACKAGE_VERSION);
+	vprintf(SDOG_NOTICE, "Sheepdog daemon (version %s) started\n", PACKAGE_VERSION);
 
 	while (sys->status != SD_STATUS_SHUTDOWN || sys->nr_outstanding_reqs != 0)
 		event_loop(-1);
 
-	vprintf(SDOG_INFO "shutdown\n");
+	vprintf(SDOG_INFO, "shutdown\n");
 
 	log_close();
 
diff --git a/sheep/store.c b/sheep/store.c
index 12e54d9..abaab9f 100644
--- a/sheep/store.c
+++ b/sheep/store.c
@@ -893,7 +893,7 @@ int epoch_log_read_remote(uint32_t epoch, char *buf, int len)
 		addr_to_str(host, sizeof(host), nodes[i].addr, 0);
 		fd = connect_to(host, nodes[i].port);
 		if (fd < 0) {
-			vprintf(SDOG_ERR "can't connect to %s, %m\n", host);
+			vprintf(SDOG_ERR, "can't connect to %s, %m\n", host);
 			continue;
 		}
 
@@ -944,7 +944,7 @@ int get_latest_epoch(void)
 
 	dir = opendir(epoch_path);
 	if (!dir) {
-		vprintf(SDOG_EMERG "failed to get the latest epoch, %m\n");
+		vprintf(SDOG_EMERG, "failed to get the latest epoch, %m\n");
 		abort();
 	}
 
@@ -1952,14 +1952,14 @@ static int init_epoch_path(const char *base_path)
 	for (epoch = 1; epoch <= latest_epoch; epoch++) {
 		snprintf(path, sizeof(path), "%s/%08u", obj_path, epoch);
 
-		vprintf(SDOG_INFO "found the obj dir, %s\n", path);
+		vprintf(SDOG_INFO, "found the obj dir, %s\n", path);
 
 		dir = opendir(path);
 		if (!dir) {
 			if (errno == ENOENT)
 				continue;
 
-			vprintf(SDOG_ERR "failed to open the epoch dir, %m\n");
+			vprintf(SDOG_ERR, "failed to open the epoch dir, %m\n");
 			return SD_RES_EIO;
 		}
 
@@ -1973,7 +1973,7 @@ static int init_epoch_path(const char *base_path)
 			if (!is_vdi_obj(oid))
 				continue;
 
-			vprintf(SDOG_DEBUG "found the vdi obj, %" PRIx64 "\n", oid);
+			vprintf(SDOG_DEBUG, "found the vdi obj, %" PRIx64 "\n", oid);
 
 			set_bit(oid_to_vid(oid), sys->vdi_inuse);
 		}
@@ -2280,7 +2280,7 @@ int jrnl_recover(void)
 	if (!dir)
 		return -1;
 
-	vprintf(SDOG_NOTICE "start jrnl_recovery.\n");
+	vprintf(SDOG_NOTICE, "start jrnl_recovery.\n");
 	while ((d = readdir(dir))) {
 		int ret;
 		struct jrnl_file_desc jfd;
@@ -2316,12 +2316,12 @@ int jrnl_recover(void)
 end_while_2:
 		jrnl_close(&jfd);
 end_while_3:
-		vprintf(SDOG_INFO "recovered the object in journal, %s\n",
+		vprintf(SDOG_INFO, "recovered the object in journal, %s\n",
 			jrnl_file_path);
 		jrnl_remove(&jfd);
 	}
 	closedir(dir);
-	vprintf(SDOG_NOTICE "end jrnl_recovery.\n");
+	vprintf(SDOG_NOTICE, "end jrnl_recovery.\n");
 
 	return 0;
 }
diff --git a/sheep/vdi.c b/sheep/vdi.c
index 392d429..42111c9 100644
--- a/sheep/vdi.c
+++ b/sheep/vdi.c
@@ -76,14 +76,14 @@ static int create_vdi_obj(uint32_t epoch, char *name, uint32_t new_vid, uint64_t
 
 	if (is_snapshot) {
 		if (cur_vid != base_vid) {
-			vprintf(SDOG_INFO "tree snapshot %s %" PRIx32 " %" PRIx32 "\n",
+			vprintf(SDOG_INFO, "tree snapshot %s %" PRIx32 " %" PRIx32 "\n",
 				name, cur_vid, base_vid);
 
 			ret = read_object(entries, nr_vnodes, nr_zones, epoch,
 					  vid_to_vdi_oid(cur_vid), (char *)cur,
 					  SD_INODE_HEADER_SIZE, 0, copies);
 			if (ret < 0) {
-				vprintf(SDOG_ERR "failed\n");
+				vprintf(SDOG_ERR, "failed\n");
 				ret = SD_RES_BASE_VDI_READ;
 				goto out;
 			}
@@ -126,7 +126,7 @@ static int create_vdi_obj(uint32_t epoch, char *name, uint32_t new_vid, uint64_t
 				   vid_to_vdi_oid(cur_vid), (char *)cur,
 				   SD_INODE_HEADER_SIZE, 0, copies, 0);
 		if (ret != 0) {
-			vprintf(SDOG_ERR "failed\n");
+			vprintf(SDOG_ERR, "failed\n");
 			ret = SD_RES_BASE_VDI_READ;
 			goto out;
 		}
@@ -137,7 +137,7 @@ static int create_vdi_obj(uint32_t epoch, char *name, uint32_t new_vid, uint64_t
 				   vid_to_vdi_oid(base_vid), (char *)base,
 				   SD_INODE_HEADER_SIZE, 0, copies, 0);
 		if (ret != 0) {
-			vprintf(SDOG_ERR "failed\n");
+			vprintf(SDOG_ERR, "failed\n");
 			ret = SD_RES_BASE_VDI_WRITE;
 			goto out;
 		}
@@ -233,7 +233,7 @@ static int do_lookup_vdi(uint32_t epoch, 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 %d, %lx\n", name, namelen, start_nr);
+	vprintf(SDOG_INFO, "looking for %s %d, %lx\n", name, namelen, start_nr);
 
 	/* bitmap search from the hash point */
 	nr = find_next_zero_bit(sys->vdi_inuse, SD_NR_VDIS, start_nr);
@@ -306,7 +306,7 @@ int add_vdi(uint32_t epoch, char *data, int data_len, uint64_t size,
 	if (is_snapshot) {
 		if (ret != SD_RES_SUCCESS) {
 			if (ret == SD_RES_NO_VDI)
-				vprintf(SDOG_CRIT "we dont's have %s\n", name);
+				vprintf(SDOG_CRIT, "we dont's have %s\n", name);
 			return ret;
 		}
 		nr = right_nr;
@@ -328,12 +328,12 @@ int add_vdi(uint32_t epoch, char *data, int data_len, uint64_t size,
 
 	*new_vid = nr;
 
-	vprintf(SDOG_INFO "we create a new vdi, %d %s (%zd) %" PRIu64 ", vid: %"
+	vprintf(SDOG_INFO, "we create a new vdi, %d %s (%zd) %" PRIu64 ", vid: %"
 		PRIx32 ", base %" PRIx32 ", cur %" PRIx32 " \n",
 		is_snapshot, name, strlen(name), size, *new_vid, base_vid, cur_vid);
 
 	if (!copies) {
-		vprintf(SDOG_WARNING "qemu doesn't specify the copies... %d\n",
+		vprintf(SDOG_WARNING, "qemu doesn't specify the copies... %d\n",
 			sys->nr_sobjs);
 		copies = sys->nr_sobjs;
 	}
-- 
1.7.6.4




More information about the sheepdog mailing list