Add a new helper for the full objlist removal implementation to
object_list_cache.c and thus allow hiding struct objlist_cache there.

Rename check_and_insert_objlist_cache to objlist_cache_insert to
describe it's purpose better and keep function names uniform.

Signed-off-by: Christoph Hellwig <hch@lst.de>

diff --git a/sheep/object_list_cache.c b/sheep/object_list_cache.c
index 110f810..a3d320e 100644
--- a/sheep/object_list_cache.c
+++ b/sheep/object_list_cache.c
@@ -26,6 +26,15 @@ struct objlist_cache_entry {
 	struct rb_node node;
 };
 
+struct objlist_cache {
+	int tree_version;
+	int buf_version;
+	int cache_size;
+	struct strbuf buffer;
+	struct rb_root root;
+	pthread_rwlock_t lock;
+};
+
 struct objlist_cache obj_list_cache = {
 			1, /* tree_version */
 			0, /* buf_version */
@@ -54,7 +63,7 @@ int init_objlist_cache(void)
 		sd_store->get_objlist(&iocb);
 
 		for (i = 0; i < iocb.length; i++)
-			check_and_insert_objlist_cache(buf[i]);
+			objlist_cache_insert(buf[i]);
 
 		free(buf);
 	}
@@ -86,7 +95,7 @@ static struct objlist_cache_entry *objlist_cache_rb_insert(struct rb_root *root,
 	return NULL; /* insert successfully */
 }
 
-int objlist_cache_rb_remove(struct rb_root *root, uint64_t oid)
+static int objlist_cache_rb_remove(struct rb_root *root, uint64_t oid)
 {
 	struct rb_node **p = &root->rb_node;
 	struct rb_node *parent = NULL;
@@ -109,7 +118,17 @@ int objlist_cache_rb_remove(struct rb_root *root, uint64_t oid)
 	return -1; /* fail to remove */
 }
 
-int check_and_insert_objlist_cache(uint64_t oid)
+void objlist_cache_remove(uint64_t oid)
+{
+	pthread_rwlock_wrlock(&obj_list_cache.lock);
+	if (!objlist_cache_rb_remove(&obj_list_cache.root, oid)) {
+		obj_list_cache.cache_size--;
+		obj_list_cache.tree_version++;
+	}
+	pthread_rwlock_unlock(&obj_list_cache.lock);
+}
+
+int objlist_cache_insert(uint64_t oid)
 {
 	struct objlist_cache_entry *entry, *p;
 
diff --git a/sheep/ops.c b/sheep/ops.c
index b63955c..b662b9e 100644
--- a/sheep/ops.c
+++ b/sheep/ops.c
@@ -724,12 +724,7 @@ static int store_remove_obj(struct request *req)
 		eprintf("%m\n");
 		ret =  SD_RES_EIO;
 	}
-	pthread_rwlock_wrlock(&obj_list_cache.lock);
-	if (!objlist_cache_rb_remove(&obj_list_cache.root, oid)) {
-		obj_list_cache.cache_size--;
-		obj_list_cache.tree_version++;
-	}
-	pthread_rwlock_unlock(&obj_list_cache.lock);
+	objlist_cache_remove(oid);
  out:
 	strbuf_release(&buf);
 	return ret;
@@ -849,7 +844,7 @@ static int store_create_and_write_obj(struct request *req)
 		ret = do_write_obj(&iocb, hdr, epoch, req->data, 1);
 
 	if (SD_RES_SUCCESS == ret)
-		check_and_insert_objlist_cache(oid);
+		objlist_cache_insert(oid);
 out:
 	if (buf)
 		free(buf);
diff --git a/sheep/recovery.c b/sheep/recovery.c
index d5408e3..9b71d9b 100644
--- a/sheep/recovery.c
+++ b/sheep/recovery.c
@@ -170,7 +170,7 @@ done:
 	dprintf("recovered oid %"PRIx64" from %d to epoch %d\n", oid, tgt_epoch, epoch);
 out:
 	if (ret == SD_RES_SUCCESS)
-		check_and_insert_objlist_cache(oid);
+		objlist_cache_insert(oid);
 	free(buf);
 	return ret;
 }
diff --git a/sheep/sheep_priv.h b/sheep/sheep_priv.h
index 2958443..a3ade74 100644
--- a/sheep/sheep_priv.h
+++ b/sheep/sheep_priv.h
@@ -188,15 +188,6 @@ static inline struct store_driver *find_store_driver(const char *name)
 	return NULL;
 }
 
-struct objlist_cache {
-	int tree_version;
-	int buf_version;
-	int cache_size;
-	struct strbuf buffer;
-	struct rb_root root;
-	pthread_rwlock_t lock;
-};
-
 extern struct cluster_info *sys;
 extern struct store_driver *sd_store;
 extern char *obj_path;
@@ -205,7 +196,6 @@ extern char *jrnl_path;
 extern char *epoch_path;
 extern mode_t def_fmode;
 extern mode_t def_dmode;
-extern struct objlist_cache obj_list_cache;
 
 /* One should call this function to get sys->epoch outside main thread */
 static inline uint32_t sys_epoch(void)
@@ -310,8 +300,8 @@ int get_sheep_fd(uint8_t *addr, uint16_t port, int node_idx, uint32_t epoch);
 int prealloc(int fd, uint32_t size);
 
 int init_objlist_cache(void);
-int objlist_cache_rb_remove(struct rb_root *root, uint64_t oid);
-int check_and_insert_objlist_cache(uint64_t oid);
+int objlist_cache_insert(uint64_t oid);
+void objlist_cache_remove(uint64_t oid);
 
 void req_done(struct request *req);
 


