[sheepdog] [PATCH v2] sheep: new journal flag JF_REMOVE_OBJ for removing object

Hitoshi Mitake mitake.hitoshi at gmail.com
Wed May 8 16:21:25 CEST 2013


sheep provides an operation for removing object. The journaling
mechanism must provide a corresponding journal record.

Signed-off-by: Hitoshi Mitake <mitake.hitoshi at lab.ntt.co.jp>
---
v2:
 - rebasing
 - change naming scheme from delete to remove for unifying

 sheep/journal.c     |   29 +++++++++++++++++++++++++++--
 sheep/plain_store.c |    3 +++
 sheep/sheep_priv.h  |    1 +
 3 files changed, 31 insertions(+), 2 deletions(-)

diff --git a/sheep/journal.c b/sheep/journal.c
index 23a0ab7..e2fce5c 100644
--- a/sheep/journal.c
+++ b/sheep/journal.c
@@ -52,6 +52,7 @@ struct journal_descriptor {
 
 #define JF_STORE 0
 #define JF_EPOCH 1
+#define JF_REMOVE_OBJ 2
 
 static const char *jfile_name[2] = { "journal_file0", "journal_file1", };
 static int jfile_fds[2];
@@ -139,16 +140,23 @@ static void journal_get_path(struct journal_descriptor *jd, char *path)
 {
 	switch (jd->flag) {
 	case JF_STORE:
+	case JF_REMOVE_OBJ:
 		snprintf(path, PATH_MAX, "%s/%016"PRIx64,
 			 get_object_path(jd->oid), jd->oid);
-		sd_iprintf("%s, size %"PRIu64", off %"PRIu64", %d",
-			   path, jd->size, jd->offset, jd->create);
+		if (jd->flag == JF_STORE)
+			sd_iprintf("%s, size %"PRIu64", off %"PRIu64", %d",
+				path, jd->size, jd->offset, jd->create);
+		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;
 	}
 }
 
@@ -160,6 +168,12 @@ static int replay_journal_entry(struct journal_descriptor *jd)
 	void *buf = NULL;
 	char *p = (char *)jd;
 
+	if (jd->flag == JF_REMOVE_OBJ) {
+		journal_get_path(jd, path);
+		unlink(path);
+		return 0;
+	}
+
 	if (jd->create)
 		flags |= O_CREAT;
 
@@ -438,6 +452,17 @@ int journal_write_epoch(const char *buf, size_t size, uint32_t epoch)
 	return journal_file_write(&jd, buf);
 }
 
+int journal_remove_object(uint64_t oid)
+{
+	struct journal_descriptor jd = {
+		.magic = JOURNAL_DESC_MAGIC,
+		.flag = JF_REMOVE_OBJ,
+		.size = 0,
+	};
+	jd.oid = oid;
+	return journal_file_write(&jd, NULL);
+}
+
 static __attribute__((used)) void journal_c_build_bug_ons(void)
 {
 	/* never called, only for checking BUILD_BUG_ON()s */
diff --git a/sheep/plain_store.c b/sheep/plain_store.c
index 640f769..89e68b6 100644
--- a/sheep/plain_store.c
+++ b/sheep/plain_store.c
@@ -460,6 +460,9 @@ int default_remove_object(uint64_t oid)
 {
 	char path[PATH_MAX];
 
+	if (uatomic_is_true(&sys->use_journal))
+		journal_remove_object(oid);
+
 	get_obj_path(oid, path);
 
 	if (unlink(path) < 0) {
diff --git a/sheep/sheep_priv.h b/sheep/sheep_priv.h
index d01d408..f830f8d 100644
--- a/sheep/sheep_priv.h
+++ b/sheep/sheep_priv.h
@@ -443,6 +443,7 @@ 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 */
 void md_add_disk(char *path);
-- 
1.7.5.1




More information about the sheepdog mailing list