[sheepdog] [PATCH 3/4] sheep: remove tempoary objects only when sheep starts up

MORITA Kazutaka morita.kazutaka at lab.ntt.co.jp
Sun Sep 9 18:13:17 CEST 2012


It is not safe to remove temporary objects while sheep is running.

Signed-off-by: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>
---
 sheep/farm/trunk.c  |    2 +-
 sheep/plain_store.c |   20 ++++++++++++--------
 sheep/sheep_priv.h  |    3 ++-
 3 files changed, 15 insertions(+), 10 deletions(-)

diff --git a/sheep/farm/trunk.c b/sheep/farm/trunk.c
index ca7631b..10f361d 100644
--- a/sheep/farm/trunk.c
+++ b/sheep/farm/trunk.c
@@ -86,7 +86,7 @@ int trunk_file_write(unsigned char *outsha1)
 	int ret = 0;
 
 	/* Add the hdr first */
-	for_each_object_in_wd(inc_object_nr, &object_nr);
+	for_each_object_in_wd(inc_object_nr, false, &object_nr);
 	data_size = sizeof(struct trunk_entry) * object_nr;
 	hdr.size = data_size;
 	hdr.priv = object_nr;
diff --git a/sheep/plain_store.c b/sheep/plain_store.c
index 933fefe..91ba527 100644
--- a/sheep/plain_store.c
+++ b/sheep/plain_store.c
@@ -48,7 +48,9 @@ static int get_stale_obj_path(uint64_t oid, uint32_t epoch, char *path)
 	return sprintf(path, "%s/%016"PRIx64".%"PRIx32, stale_dir, oid, epoch);
 }
 
-int for_each_object_in_wd(int (*func)(uint64_t oid, void *arg), void *arg)
+/* If cleanup is true, temporary objects will be removed */
+int for_each_object_in_wd(int (*func)(uint64_t oid, void *arg), bool cleanup,
+			  void *arg)
 {
 	DIR *dir;
 	struct dirent *d;
@@ -70,12 +72,14 @@ int for_each_object_in_wd(int (*func)(uint64_t oid, void *arg), void *arg)
 		if (oid == 0 || oid == ULLONG_MAX)
 			continue;
 
-		/* remove object if it is temporary one */
+		/* don't call callback against temporary objects */
 		if (strlen(d->d_name) == 20 &&
 		    strcmp(d->d_name + 16, ".tmp") == 0) {
-			get_tmp_obj_path(oid, path);
-			dprintf("remove tmp object %s\n", path);
-			unlink(path);
+			if (cleanup) {
+				get_tmp_obj_path(oid, path);
+				dprintf("remove tmp object %s\n", path);
+				unlink(path);
+			}
 			continue;
 		}
 
@@ -224,7 +228,7 @@ int default_init(char *p)
 		}
 	}
 
-	return for_each_object_in_wd(init_objlist_and_vdi_bitmap, NULL);
+	return for_each_object_in_wd(init_objlist_and_vdi_bitmap, true, NULL);
 }
 
 static int default_read_from_path(uint64_t oid, char *path,
@@ -389,7 +393,7 @@ int default_end_recover(uint32_t old_epoch, struct vnode_info *old_vnode_info)
 	if (old_epoch == 0)
 		return SD_RES_SUCCESS;
 
-	return for_each_object_in_wd(check_stale_objects, &old_epoch);
+	return for_each_object_in_wd(check_stale_objects, false, &old_epoch);
 }
 
 int default_format(void)
@@ -431,7 +435,7 @@ int default_purge_obj(void)
 {
 	uint32_t tgt_epoch = get_latest_epoch();
 
-	return for_each_object_in_wd(move_object_to_stale_dir, &tgt_epoch);
+	return for_each_object_in_wd(move_object_to_stale_dir, true, &tgt_epoch);
 }
 
 #ifndef HAVE_SYNCFS
diff --git a/sheep/sheep_priv.h b/sheep/sheep_priv.h
index 5cd9d3f..6eb7e2c 100644
--- a/sheep/sheep_priv.h
+++ b/sheep/sheep_priv.h
@@ -177,7 +177,8 @@ int default_cleanup(void);
 int default_format(void);
 int default_remove_object(uint64_t oid);
 int default_purge_obj(void);
-int for_each_object_in_wd(int (*func)(uint64_t oid, void *arg), void *arg);
+int for_each_object_in_wd(int (*func)(uint64_t oid, void *arg), bool cleanup,
+			  void *arg);
 
 extern struct list_head store_drivers;
 #define add_store_driver(driver)                                 \
-- 
1.7.2.5




More information about the sheepdog mailing list