[sheepdog] [PATCH 2/2] dog: add a dog_out helper

Liu Yuan namei.unix at gmail.com
Tue Nov 12 09:14:22 CET 2013


Signed-off-by: Liu Yuan <namei.unix at gmail.com>
---
 dog/dog.h  |   16 +++++++++++-----
 dog/node.c |    6 +++---
 dog/vdi.c  |   16 ++++++++--------
 3 files changed, 22 insertions(+), 16 deletions(-)

diff --git a/dog/dog.h b/dog/dog.h
index c86e9a4..3b28435 100644
--- a/dog/dog.h
+++ b/dog/dog.h
@@ -101,11 +101,17 @@ int do_loglevel_get(const struct node_id *nid, int32_t *ret_loglevel);
 const char *loglevel_to_str(int loglevel);
 void dump_loglevels(bool err);
 
-#define dog_err(fmt, args...)		\
-({					\
-	fprintf(stderr, fmt, ##args);	\
-	fprintf(stderr, "\n");		\
-	fflush(stderr);			\
+#define dog_print(stream, fmt, args...)	\
+({						\
+	fprintf(stream, fmt, ##args);		\
+	fprintf(stream, "\n");			\
+	fflush(stream);				\
 })
 
+#define dog_err(fmt, args...) \
+	dog_print(stderr, fmt, ##args)
+
+#define dog_out(fmt, args...) \
+	dog_print(stdout, fmt, ##args)
+
 #endif
diff --git a/dog/node.c b/dog/node.c
index 3755e43..f409ab1 100644
--- a/dog/node.c
+++ b/dog/node.c
@@ -336,7 +336,7 @@ static int node_md_info(struct node_id *nid)
 		uint64_t size = info.disk[i].free + info.disk[i].used;
 		int ratio = (int)(((double)info.disk[i].used / size) * 100);
 
-		fprintf(stdout, "%2d\t%s\t%s\t%s\t%3d%%\t%s\n",
+		dog_out("%2d\t%s\t%s\t%s\t%3d%%\t%s",
 			info.disk[i].idx, strnumber(size),
 			strnumber(info.disk[i].used),
 			strnumber(info.disk[i].free),
@@ -350,13 +350,13 @@ static int md_info(int argc, char **argv)
 	struct sd_node *n;
 	int ret, i = 0;
 
-	fprintf(stdout, "Id\tSize\tUsed\tAvail\tUse%%\tPath\n");
+	dog_out("Id\tSize\tUsed\tAvail\tUse%%\tPath");
 
 	if (!node_cmd_data.all_nodes)
 		return node_md_info(&sd_nid);
 
 	rb_for_each_entry(n, &sd_nroot, rb) {
-		fprintf(stdout, "Node %d:\n", i++);
+		dog_out("Node %d:", i++);
 		ret = node_md_info(&n->nid);
 		if (ret != EXIT_SUCCESS)
 			return EXIT_FAILURE;
diff --git a/dog/vdi.c b/dog/vdi.c
index 85ad3d7..17d410a 100644
--- a/dog/vdi.c
+++ b/dog/vdi.c
@@ -1483,9 +1483,9 @@ static void vdi_repair_main(struct work *work)
 	struct vdi_check_info *info = vcw->info;
 
 	if (vcw->object_found)
-		fprintf(stdout, "fixed replica %"PRIx64"\n", info->oid);
+		dog_out("fixed replica %"PRIx64, info->oid);
 	else
-		fprintf(stdout, "fixed missing %"PRIx64"\n", info->oid);
+		dog_out("fixed missing %"PRIx64, info->oid);
 
 	info->refcnt--;
 	if (info->refcnt == 0)
@@ -1626,8 +1626,8 @@ static void check_erasure_object(struct vdi_check_info *info)
 			ec_decode_buffer(ctx, ds, input_idx, obj, m);
 			write_object_to(info->vcw[m].vnode, oid, obj, true,
 					info->vcw[m].ec_index);
-			fprintf(stdout, "fixed missing %"PRIx64", "
-				"copy index %d\n", info->oid, m);
+			dog_out("fixed missing %"PRIx64", "
+				"copy index %d", info->oid, m);
 		}
 	}
 out:
@@ -1758,7 +1758,7 @@ int do_vdi_check(const struct sd_inode *inode)
 
 	work_queue_wait(wq);
 
-	fprintf(stdout, "finish check&repair %s\n", inode->name);
+	dog_out("finish check&repair %s", inode->name);
 
 	return EXIT_SUCCESS;
 }
@@ -2207,7 +2207,7 @@ static int vdi_cache_info(int argc, char **argv)
 		return EXIT_FAILURE;
 	}
 
-	fprintf(stdout, "Name\tTag\tTotal\tDirty\tClean\n");
+	dog_out("Name\tTag\tTotal\tDirty\tClean");
 	for (i = 0; i < info.count; i++) {
 		uint64_t total = info.caches[i].total * SD_DATA_OBJ_SIZE,
 			 dirty = info.caches[i].dirty * SD_DATA_OBJ_SIZE,
@@ -2217,12 +2217,12 @@ static int vdi_cache_info(int argc, char **argv)
 		ret = vid_to_name_tag(info.caches[i].vid, name, tag);
 		if (ret != SD_RES_SUCCESS)
 			return EXIT_FAILURE;
-		fprintf(stdout, "%s\t%s\t%s\t%s\t%s\n",
+		dog_out("%s\t%s\t%s\t%s\t%s",
 			name, tag, strnumber(total), strnumber(dirty),
 			strnumber(clean));
 	}
 
-	fprintf(stdout, "\nCache size %s, used %s, %s\n",
+	dog_out("\nCache size %s, used %s, %s",
 		strnumber(info.size), strnumber(info.used),
 		info.directio ? "directio" : "non-directio");
 
-- 
1.7.9.5




More information about the sheepdog mailing list