[Sheepdog] [PATCH 05/18] save cluster creation time to the epoch dir

MORITA Kazutaka morita.kazutaka at lab.ntt.co.jp
Thu Mar 11 07:48:04 CET 2010


All nodes need to know when make fs is invoked to support safe start up.

Signed-off-by: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>
---
 collie/collie.h     |    2 ++
 collie/store.c      |   42 +++++++++++++++++++++++++++++++++++++++++-
 shepherd/shepherd.c |    8 ++++++--
 3 files changed, 49 insertions(+), 3 deletions(-)

diff --git a/collie/collie.h b/collie/collie.h
index d24a6c4..89eb8f8 100644
--- a/collie/collie.h
+++ b/collie/collie.h
@@ -107,6 +107,8 @@ extern struct work_queue *dobj_queue;
 
 int epoch_log_write(uint32_t epoch, char *buf, int len);
 int epoch_log_read(uint32_t epoch, char *buf, int len);
+int set_cluster_ctime(uint64_t ctime);
+uint64_t get_cluster_ctime(void);
 
 int start_recovery(uint32_t epoch, int add);
 
diff --git a/collie/store.c b/collie/store.c
index 1c416d2..e46ca46 100644
--- a/collie/store.c
+++ b/collie/store.c
@@ -22,6 +22,7 @@
 #include "meta.h"
 
 #define ANAME_LAST_OID "user.sheepdog.last_oid"
+#define ANAME_CTIME "user.sheepdog.ctime"
 #define ANAME_COPIES "user.sheepdog.copies"
 
 static char *vdi_path;
@@ -829,7 +830,13 @@ void so_queue_request(struct work *work, int idx)
 		ret = fsetxattr(fd, ANAME_LAST_OID, &last_oid,
 				sizeof(last_oid), 0);
 		if (ret) {
-			close(fd);
+			result = SD_RES_EIO;
+			goto out;
+		}
+
+		ret = fsetxattr(fd, ANAME_CTIME, &hdr->ctime,
+				sizeof(hdr->ctime), 0);
+		if (ret) {
 			result = SD_RES_EIO;
 			goto out;
 		}
@@ -1034,6 +1041,39 @@ int epoch_log_read(uint32_t epoch, char *buf, int len)
 	return len;
 }
 
+int set_cluster_ctime(uint64_t ctime)
+{
+	int fd, ret;
+
+	fd = open(epoch_path, O_RDONLY);
+	if (fd < 0)
+		return -1;
+
+	ret = fsetxattr(fd, ANAME_CTIME, &ctime, sizeof(ctime), 0);
+	close(fd);
+
+	if (ret)
+		return -1;
+	return 0;
+}
+
+uint64_t get_cluster_ctime(void)
+{
+	int fd, ret;
+	uint64_t ctime;
+
+	fd = open(epoch_path, O_RDONLY);
+	if (fd < 0)
+		return 0;
+
+	ret = fgetxattr(fd, ANAME_CTIME, &ctime, sizeof(ctime));
+	close(fd);
+
+	if (ret != sizeof(ctime))
+		return 0;
+	return ctime;
+}
+
 static int node_distance(int my, int her, int nr)
 {
 	return (my + nr - her) % nr;
diff --git a/shepherd/shepherd.c b/shepherd/shepherd.c
index f639fe2..52383bd 100644
--- a/shepherd/shepherd.c
+++ b/shepherd/shepherd.c
@@ -207,19 +207,23 @@ out:
 static int mkfs(int copies)
 {
 	int fd, ret;
-	struct sd_obj_req hdr;
-	struct sd_obj_rsp *rsp = (struct sd_obj_rsp *)&hdr;
+	struct sd_so_req hdr;
+	struct sd_so_rsp *rsp = (struct sd_so_rsp *)&hdr;
 	unsigned rlen, wlen;
+	struct timeval tv;
 
 	fd = connect_to("localhost", sdport);
 	if (fd < 0)
 		return -1;
 
+	gettimeofday(&tv, NULL);
+
 	memset(&hdr, 0, sizeof(hdr));
 
 	hdr.opcode = SD_OP_MAKE_FS;
 	hdr.copies = copies;
 	hdr.epoch = node_list_version;
+	hdr.ctime = (uint64_t) tv.tv_sec << 32 | tv.tv_usec * 1000;
 
 	rlen = 0;
 	wlen = 0;
-- 
1.5.6.5




More information about the sheepdog mailing list