[sheepdog] [PATCH 1/2] sheep: journaling epoch file write

Liu Yuan namei.unix at gmail.com
Wed Apr 3 09:06:16 CEST 2013


From: Liu Yuan <tailai.ly at taobao.com>

Also bundle two writes into one.

Signed-off-by: Liu Yuan <tailai.ly at taobao.com>
---
 sheep/store.c |   31 +++++++++++++++++++------------
 1 file changed, 19 insertions(+), 12 deletions(-)

diff --git a/sheep/store.c b/sheep/store.c
index 5b1e457..f112751 100644
--- a/sheep/store.c
+++ b/sheep/store.c
@@ -39,28 +39,35 @@ LIST_HEAD(store_drivers);
 
 int update_epoch_log(uint32_t epoch, struct sd_node *nodes, size_t nr_nodes)
 {
-	int fd, ret, len;
+	int fd, ret, len, nodes_len, flags = O_RDWR | O_CREAT | O_DSYNC;
 	time_t t;
-	char path[PATH_MAX];
+	char path[PATH_MAX], *buf;
 
 	sd_dprintf("update epoch: %d, %zd", epoch, nr_nodes);
 
+	/* Piggyback the epoch creation time for 'collie cluster info' */
+	time(&t);
+	nodes_len = nr_nodes * sizeof(struct sd_node);
+	len = nodes_len + sizeof(time_t);
+	buf = xmalloc(len);
+	memcpy(buf, nodes, nodes_len);
+	memcpy(buf + nodes_len, &t, sizeof(time_t));
+
+	if (uatomic_is_true(&sys->use_journal) &&
+	    journal_write_epoch(buf, len, epoch) != SD_RES_SUCCESS) {
+		sd_eprintf("turn off journaling");
+		uatomic_set_false(&sys->use_journal);
+		sync();
+	}
+
 	snprintf(path, sizeof(path), "%s%08u", epoch_path, epoch);
-	fd = open(path, O_RDWR | O_CREAT | O_DSYNC, def_fmode);
+	fd = open(path, flags, def_fmode);
 	if (fd < 0) {
 		ret = fd;
 		goto err_open;
 	}
 
-	len = nr_nodes * sizeof(struct sd_node);
-	ret = xwrite(fd, (char *)nodes, len);
-	if (ret != len)
-		goto err;
-
-	/* Piggyback the epoch creation time for 'collie cluster info' */
-	time(&t);
-	len = sizeof(t);
-	ret = xwrite(fd, (char *)&t, len);
+	ret = xwrite(fd, buf, len);
 	if (ret != len)
 		goto err;
 
-- 
1.7.9.5




More information about the sheepdog mailing list