[sheepdog] [PATCH 2/3] sheep: add an argument to for_each_object_in_wd

MORITA Kazutaka morita.kazutaka at lab.ntt.co.jp
Sun Aug 26 12:50:15 CEST 2012


This prepares for the next patch.

This also makes object_nr in farm/trunk.c a local variable.

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

diff --git a/sheep/farm/trunk.c b/sheep/farm/trunk.c
index 0385e54..4d955a3 100644
--- a/sheep/farm/trunk.c
+++ b/sheep/farm/trunk.c
@@ -66,11 +66,12 @@ out:
 	return ret;
 }
 
-static uint64_t object_nr;
-
-static int inc_object_nr(uint64_t oid)
+static int inc_object_nr(uint64_t oid, void *arg)
 {
-	object_nr++;
+	uint64_t *object_nr = arg;
+
+	(*object_nr)++;
+
 	return 0;
 }
 
@@ -81,11 +82,11 @@ int trunk_file_write(unsigned char *outsha1)
 	struct trunk_entry entry;
 	struct dirent *d;
 	DIR *dir;
-	uint64_t data_size, oid;
+	uint64_t data_size, oid, object_nr = 0;
 	int ret = 0;
 
 	/* Add the hdr first */
-	for_each_object_in_wd(inc_object_nr);
+	for_each_object_in_wd(inc_object_nr, &object_nr);
 	data_size = sizeof(struct trunk_entry) * object_nr;
 	hdr.size = data_size;
 	hdr.priv = object_nr;
@@ -121,7 +122,6 @@ int trunk_file_write(unsigned char *outsha1)
 	}
 	dprintf("trunk sha1: %s\n", sha1_to_hex(outsha1));
 out:
-	object_nr = 0;
 	closedir(dir);
 	strbuf_release(&buf);
 	return ret;
diff --git a/sheep/plain_store.c b/sheep/plain_store.c
index 0129d54..5ed097c 100644
--- a/sheep/plain_store.c
+++ b/sheep/plain_store.c
@@ -47,7 +47,7 @@ static int get_stale_obj_path(uint64_t oid, char *path)
 	return sprintf(path, "%s/%016"PRIx64, stale_dir, oid);
 }
 
-int for_each_object_in_wd(int (*func)(uint64_t oid))
+int for_each_object_in_wd(int (*func)(uint64_t oid, void *arg), void *arg)
 {
 	DIR *dir;
 	struct dirent *d;
@@ -76,7 +76,7 @@ int for_each_object_in_wd(int (*func)(uint64_t oid))
 			continue;
 		}
 
-		ret = func(oid);
+		ret = func(oid, arg);
 		if (ret != SD_RES_SUCCESS)
 			break;
 	}
@@ -184,7 +184,7 @@ static int init_vdi_copy_number(uint64_t oid)
 	return SD_RES_SUCCESS;
 }
 
-static int init_objlist_and_vdi_bitmap(uint64_t oid)
+static int init_objlist_and_vdi_bitmap(uint64_t oid, void *arg)
 {
 	int ret;
 	objlist_cache_insert(oid);
@@ -212,7 +212,7 @@ int default_init(char *p)
 		}
 	}
 
-	return for_each_object_in_wd(init_objlist_and_vdi_bitmap);
+	return for_each_object_in_wd(init_objlist_and_vdi_bitmap, NULL);
 }
 
 static int default_read_from_path(uint64_t oid, char *path,
@@ -337,7 +337,7 @@ out:
 	return ret;
 }
 
-static int move_object_to_stale_dir(uint64_t oid)
+static int move_object_to_stale_dir(uint64_t oid, void *arg)
 {
 	char path[PATH_MAX], stale_path[PATH_MAX];
 
@@ -353,10 +353,10 @@ static int move_object_to_stale_dir(uint64_t oid)
 	return SD_RES_SUCCESS;
 }
 
-static int check_stale_objects(uint64_t oid)
+static int check_stale_objects(uint64_t oid, void *arg)
 {
 	if (oid_stale(oid))
-		return move_object_to_stale_dir(oid);
+		return move_object_to_stale_dir(oid, arg);
 
 	return SD_RES_SUCCESS;
 }
@@ -366,7 +366,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);
+	return for_each_object_in_wd(check_stale_objects, NULL);
 }
 
 int default_format(char *name)
@@ -409,7 +409,7 @@ int default_remove_object(uint64_t oid)
 
 int default_purge_obj(void)
 {
-	return for_each_object_in_wd(move_object_to_stale_dir);
+	return for_each_object_in_wd(move_object_to_stale_dir, NULL);
 }
 
 struct store_driver plain_store = {
diff --git a/sheep/sheep_priv.h b/sheep/sheep_priv.h
index 1bc7e60..1f5a1bd 100644
--- a/sheep/sheep_priv.h
+++ b/sheep/sheep_priv.h
@@ -170,7 +170,7 @@ int default_cleanup(void);
 int default_format(char *name);
 int default_remove_object(uint64_t oid);
 int default_purge_obj(void);
-int for_each_object_in_wd(int (*func)(uint64_t oid));
+int for_each_object_in_wd(int (*func)(uint64_t oid, void *arg), void *arg);
 
 extern struct list_head store_drivers;
 #define add_store_driver(driver)                                 \
-- 
1.7.2.5




More information about the sheepdog mailing list