[sheepdog] [PATCH v2 1/6] move vdi_is_snapshot() to sheepdog_proto.h

MORITA Kazutaka morita.kazutaka at lab.ntt.co.jp
Wed May 1 10:41:44 CEST 2013


This allows us to use the macro outside of sheep/vdi.c.

Signed-off-by: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>
---
 collie/common.c          |  7 +------
 collie/node.c            |  2 +-
 collie/vdi.c             | 20 ++++++++++----------
 include/sheepdog_proto.h |  5 +++++
 sheep/vdi.c              |  5 -----
 5 files changed, 17 insertions(+), 22 deletions(-)

diff --git a/collie/common.c b/collie/common.c
index 063a932..60c6701 100644
--- a/collie/common.c
+++ b/collie/common.c
@@ -11,11 +11,6 @@
 
 #include "collie.h"
 
-bool is_current(const struct sd_inode *i)
-{
-	return !i->snap_ctime;
-}
-
 char *size_to_str(uint64_t _size, char *str, int str_size)
 {
 	const char *units[] = {"MB", "GB", "TB", "PB", "EB", "ZB", "YB"};
@@ -165,7 +160,7 @@ int parse_vdi(vdi_parser_func_t func, size_t size, void *data)
 			}
 		}
 
-		snapid = is_current(&i) ? 0 : i.snap_id;
+		snapid = vdi_is_snapshot(&i) ? i.snap_id : 0;
 		func(i.vdi_id, i.name, i.tag, snapid, 0, &i, data);
 	}
 
diff --git a/collie/node.c b/collie/node.c
index 1f89482..b8999e3 100644
--- a/collie/node.c
+++ b/collie/node.c
@@ -21,7 +21,7 @@ static void cal_total_vdi_size(uint32_t vid, const char *name, const char *tag,
 {
 	uint64_t *size = data;
 
-	if (is_current(i))
+	if (!vdi_is_snapshot(i))
 		*size += i->vdi_size;
 }
 
diff --git a/collie/vdi.c b/collie/vdi.c
index b81866e..c0bbf65 100644
--- a/collie/vdi.c
+++ b/collie/vdi.c
@@ -126,7 +126,7 @@ static void print_vdi_list(uint32_t vid, const char *name, const char *tag,
 		is_clone = true;
 
 	if (raw_output) {
-		printf("%c ", is_current(i) ? (is_clone ? 'c' : '=') : 's');
+		printf("%c ", vdi_is_snapshot(i) ? 's' : (is_clone ? 'c' : '='));
 		while (*name) {
 			if (isspace(*name) || *name == '\\')
 				putchar('\\');
@@ -137,7 +137,7 @@ static void print_vdi_list(uint32_t vid, const char *name, const char *tag,
 				i->nr_copies, i->tag);
 	} else {
 		printf("%c %-8s %5d %7s %7s %7s %s  %7" PRIx32 " %5d %13s\n",
-				is_current(i) ? (is_clone ? 'c' : ' ') : 's',
+				vdi_is_snapshot(i) ? 's' : (is_clone ? 'c' : ' '),
 				name, snapid, vdi_size_str, my_objs_str, cow_objs_str,
 				dbuf, vid, i->nr_copies, i->tag);
 	}
@@ -151,17 +151,17 @@ static void print_vdi_tree(uint32_t vid, const char *name, const char *tag,
 	struct tm tm;
 	char buf[128];
 
-	if (is_current(i))
-		pstrcpy(buf, sizeof(buf), "(you are here)");
-	else {
+	if (vdi_is_snapshot(i)) {
 		ti = i->create_time >> 32;
 		localtime_r(&ti, &tm);
 
 		strftime(buf, sizeof(buf),
 			 "[%Y-%m-%d %H:%M]", &tm);
-	}
+	} else
+		pstrcpy(buf, sizeof(buf), "(you are here)");
 
-	add_vdi_tree(name, buf, vid, i->parent_vdi_id, highlight && is_current(i));
+	add_vdi_tree(name, buf, vid, i->parent_vdi_id,
+		     highlight && !vdi_is_snapshot(i));
 }
 
 static void print_vdi_graph(uint32_t vid, const char *name, const char *tag,
@@ -191,10 +191,10 @@ static void print_vdi_graph(uint32_t vid, const char *name, const char *tag,
 	       "Time: %10s",
 	       name, snapid, size_str, dbuf, tbuf);
 
-	if (is_current(i))
-		printf("\",\n    color=\"red\"\n  ];\n\n");
-	else
+	if (vdi_is_snapshot(i))
 		printf("\"\n  ];\n\n");
+	else
+		printf("\",\n    color=\"red\"\n  ];\n\n");
 
 }
 
diff --git a/include/sheepdog_proto.h b/include/sheepdog_proto.h
index 89ded0d..8f14105 100644
--- a/include/sheepdog_proto.h
+++ b/include/sheepdog_proto.h
@@ -305,6 +305,11 @@ static inline uint32_t attr_oid_to_vid(uint64_t oid)
 	return (~VDI_ATTR_BIT & oid) >> VDI_SPACE_SHIFT;
 }
 
+static inline bool vdi_is_snapshot(const struct sd_inode *inode)
+{
+	return !!inode->snap_ctime;
+}
+
 static inline __attribute__((used)) void __sd_proto_build_bug_ons(void)
 {
         /* never called, only for checking BUILD_BUG_ON()s */
diff --git a/sheep/vdi.c b/sheep/vdi.c
index afb4417..259eacb 100644
--- a/sheep/vdi.c
+++ b/sheep/vdi.c
@@ -329,11 +329,6 @@ static int get_vdi_bitmap_range(const char *name, unsigned long *left,
 	return SD_RES_SUCCESS;
 }
 
-static inline bool vdi_is_snapshot(struct sd_inode *inode)
-{
-	return !!inode->snap_ctime;
-}
-
 static inline bool vdi_has_tag(struct vdi_iocb *iocb)
 {
 	if ((iocb->tag && iocb->tag[0]) || iocb->snapid)
-- 
1.8.1.3.566.gaa39828




More information about the sheepdog mailing list