[sheepdog] [PATCH 1/5] sheep: don't use journal for epoch write

MORITA Kazutaka morita.kazutaka at gmail.com
Fri May 31 19:15:46 CEST 2013


From: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>

It doesn't often happen to write data to epoch files.  Let's use
atomic_create_write() for it since it is much simpler than journaling.

This can also removes check_epoch(), which wrongly removes epoch files
after we change the epoch format size.

Signed-off-by: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>
---
 sheep/journal.c    |   19 -------------------
 sheep/sheep_priv.h |    2 --
 sheep/store.c      |   50 +++-----------------------------------------------
 3 files changed, 3 insertions(+), 68 deletions(-)

diff --git a/sheep/journal.c b/sheep/journal.c
index b62ff58..50783f2 100644
--- a/sheep/journal.c
+++ b/sheep/journal.c
@@ -51,7 +51,6 @@ struct journal_descriptor {
 #define JOURNAL_END_MARKER 0xdeadbeef
 
 #define JF_STORE 0
-#define JF_EPOCH 1
 #define JF_REMOVE_OBJ 2
 
 static const char *jfile_name[2] = { "journal_file0", "journal_file1", };
@@ -149,11 +148,6 @@ static void journal_get_path(struct journal_descriptor *jd, char *path)
 		else		/* JF_REMOVE_OBJ */
 			sd_iprintf("%s (remove)", path);
 		break;
-	case JF_EPOCH:
-		snprintf(path, PATH_MAX, "%s/%08"PRIu32, epoch_path, jd->epoch);
-		sd_iprintf("%s, %"PRIu32" size %"PRIu64,
-			   path, jd->epoch, jd->size);
-		break;
 	default:
 		panic("unknown type of journal flag: %d", jd->flag);
 		break;
@@ -439,19 +433,6 @@ int journal_write_store(uint64_t oid, const char *buf, size_t size,
 	return journal_file_write(&jd, buf);
 }
 
-int journal_write_epoch(const char *buf, size_t size, uint32_t epoch)
-{
-	struct journal_descriptor jd = {
-		.magic = JOURNAL_DESC_MAGIC,
-		.flag = JF_EPOCH,
-		.offset = 0,
-		.size = size,
-		.create = true,
-	};
-	jd.epoch = epoch;
-	return journal_file_write(&jd, buf);
-}
-
 int journal_remove_object(uint64_t oid)
 {
 	struct journal_descriptor jd = {
diff --git a/sheep/sheep_priv.h b/sheep/sheep_priv.h
index dddec70..cdf8b7a 100644
--- a/sheep/sheep_priv.h
+++ b/sheep/sheep_priv.h
@@ -401,8 +401,6 @@ int journal_file_init(const char *path, size_t size, bool skip);
 void clean_journal_file(const char *p);
 int
 journal_write_store(uint64_t oid, const char *buf, size_t size, off_t, bool);
-int journal_write_epoch(const char *buf, size_t size, uint32_t epoch);
-int journal_write_config(const char *buf, size_t size);
 int journal_remove_object(uint64_t oid);
 
 /* md.c */
diff --git a/sheep/store.c b/sheep/store.c
index 658904b..c8253ca 100644
--- a/sheep/store.c
+++ b/sheep/store.c
@@ -35,7 +35,7 @@ LIST_HEAD(store_drivers);
 
 int update_epoch_log(uint32_t epoch, struct sd_node *nodes, size_t nr_nodes)
 {
-	int fd, ret, len, nodes_len, flags = O_RDWR | O_CREAT | O_DSYNC;
+	int ret, len, nodes_len;
 	time_t t;
 	char path[PATH_MAX], *buf;
 
@@ -49,34 +49,11 @@ int update_epoch_log(uint32_t epoch, struct sd_node *nodes, size_t nr_nodes)
 	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);
 
-	if (uatomic_is_true(&sys->use_journal))
-		flags &= ~O_DSYNC;
-
-	fd = open(path, flags, sd_def_fmode);
-	if (fd < 0) {
-		free(buf);
-		return -1;
-	}
+	ret = atomic_create_and_write(path, buf, len);
 
-	ret = xwrite(fd, buf, len);
-	if (ret != len) {
-		sd_eprintf("write failed %d, len %d", ret, len);
-		ret = -1;
-		goto err;
-	}
-	ret = 0;
-err:
 	free(buf);
-	close(fd);
 	return ret;
 }
 
@@ -147,27 +124,6 @@ int epoch_log_read_with_timestamp(uint32_t epoch, struct sd_node *nodes,
 	return do_epoch_log_read(epoch, nodes, len, timestamp);
 }
 
-static bool check_epoch(uint32_t epoch)
-{
-	char path[PATH_MAX];
-	struct stat st;
-
-	snprintf(path, PATH_MAX, "%s/%08"PRIu32, epoch_path, epoch);
-
-	if (stat(path, &st) < 0)
-		goto err;
-
-	/* Both empty file and ill-sized case are handled */
-	if ((st.st_size - sizeof(time_t)) % sizeof(struct sd_node))
-		goto err;
-
-	return true;
-err:
-	sd_iprintf("remove broken epoch file %s", path);
-	unlink(path);
-	return false;
-}
-
 uint32_t get_latest_epoch(void)
 {
 	DIR *dir;
@@ -187,7 +143,7 @@ uint32_t get_latest_epoch(void)
 		if (strlen(d->d_name) != 8)
 			continue;
 
-		if (check_epoch(e) && e > epoch)
+		if (e > epoch)
 			epoch = e;
 	}
 	closedir(dir);
-- 
1.7.9.5




More information about the sheepdog mailing list