[Sheepdog] [PATCH 03/10] add snapshot id and tag support to sheepdog_vdi_info struct

FUJITA Tomonori fujita.tomonori at lab.ntt.co.jp
Tue Jan 26 05:34:49 CET 2010


this is a preparation for snapshot id and tag support.

Signed-off-by: FUJITA Tomonori <fujita.tomonori at lab.ntt.co.jp>
---
 collie/store.c           |    8 ++++----
 include/meta.h           |   19 +++++--------------
 include/sheepdog_proto.h |    2 ++
 shepherd/shepherd.c      |   13 ++++++-------
 4 files changed, 17 insertions(+), 25 deletions(-)

diff --git a/collie/store.c b/collie/store.c
index 0244789..255eca3 100644
--- a/collie/store.c
+++ b/collie/store.c
@@ -581,7 +581,7 @@ static int so_read_vdis(struct request *req)
 	struct dirent *dent, *vdent;
 	char *p;
 	char vpath[1024];
-	struct sheepdog_dir_entry *sde = req->data;
+	struct sheepdog_vdi_info *sde = req->data;
 
 	dir = opendir(vdi_path);
 	if (!dir)
@@ -614,15 +614,15 @@ static int so_read_vdis(struct request *req)
 
 			sde->oid = strtoull(vdent->d_name, NULL, 16);
 			if (p)
-				sde->tag = strtoull(p + 1, NULL, 16);
+				sde->id = strtoull(p + 1, NULL, 16);
 			else {
-				sde->tag = 0;
+				sde->id = 0;
 				sde->flags = FLAG_CURRENT;
 			}
 
 			sde->name_len = strlen(dent->d_name);
 			strcpy(sde->name, dent->d_name);
-			sde = next_entry(sde);
+			sde++;
 		}
 
 		closedir(vdir);
diff --git a/include/meta.h b/include/meta.h
index 801f31e..34ed800 100644
--- a/include/meta.h
+++ b/include/meta.h
@@ -51,27 +51,18 @@ static inline int is_data_obj(uint64_t oid)
 
 #define FLAG_CURRENT 1
 
-struct sheepdog_dir_entry {
+struct sheepdog_vdi_info {
 	uint64_t oid;
-	uint32_t tag;
+	uint16_t id;
 	uint16_t name_len;
+	uint16_t tag_len;
 	uint8_t type;
 	uint8_t flags;
 	uint32_t epoch;
-	uint32_t pad;
-	char name[0];
+	char name[SD_MAX_VDI_LEN];
+	char tag[SD_MAX_VDI_LEN];
 };
 
-#define SD_DIR_ALIGN 8
-
-static inline struct sheepdog_dir_entry *next_entry(struct sheepdog_dir_entry *ent)
-{
-	int len = offsetof(struct sheepdog_dir_entry, name)
-		+ roundup(ent->name_len, SD_DIR_ALIGN);
-
-	return (struct sheepdog_dir_entry *)((char *)ent + len);
-}
-
 #define MAX_DATA_OBJS (1 << 18)
 #define MAX_CHILDREN 1024
 
diff --git a/include/sheepdog_proto.h b/include/sheepdog_proto.h
index 2d14abc..cf803b7 100644
--- a/include/sheepdog_proto.h
+++ b/include/sheepdog_proto.h
@@ -20,6 +20,8 @@
 #define SD_MAX_NODES 1024
 #define SD_MAX_VMS   4096
 
+#define SD_MAX_VDI_LEN 256
+
 /* -> vmon */
 
 #define SD_OP_NEW_VDI        0x11
diff --git a/shepherd/shepherd.c b/shepherd/shepherd.c
index a13bed7..bebf0b5 100644
--- a/shepherd/shepherd.c
+++ b/shepherd/shepherd.c
@@ -27,8 +27,8 @@
 #include <term.h>
 #include <curses.h>
 
-#include "meta.h"
 #include "sheepdog_proto.h"
+#include "meta.h"
 #include "net.h"
 #include "treeview.h"
 
@@ -377,7 +377,7 @@ typedef void (*vdi_parser_func_t)(uint64_t oid, char *name, uint32_t tag, uint32
  */
 int parse_vdi(vdi_parser_func_t func, void *data)
 {
-	struct sheepdog_dir_entry *prv, *ent;
+	struct sheepdog_vdi_info *ent;
 	char *buf;
 	int rest, ret;
 	struct sheepdog_inode i;
@@ -400,7 +400,7 @@ int parse_vdi(vdi_parser_func_t func, void *data)
 		goto out;
 	}
 
-	ent = (struct sheepdog_dir_entry *) buf;
+	ent = (struct sheepdog_vdi_info *)buf;
 	rest = ret;
 	while (rest > 0) {
 		if (!ent->name_len)
@@ -410,11 +410,10 @@ int parse_vdi(vdi_parser_func_t func, void *data)
 				  ent->oid, (void *)&i, sizeof(i), 0, nr_nodes);
 
 		if (ret == sizeof(i))
-			func(ent->oid, ent->name, ent->tag, ent->flags, &i, data);
+			func(ent->oid, ent->name, ent->id, ent->flags, &i, data);
 
-		prv = ent;
-		ent = next_entry(prv);
-		rest -= ((char *)ent - (char *)prv);
+		ent++;
+		rest -= sizeof(*ent);
 	}
 
 out:
-- 
1.5.6.5




More information about the sheepdog mailing list