[sheepdog] [PATCH 2/3] sheep, store: remove oid from farm state

Liu Yuan namei.unix at gmail.com
Wed Jun 13 11:17:27 CEST 2012


From: Liu Yuan <tailai.ly at taobao.com>

Add a new callback named 'remove_object' to properly do store specific
opertaions. This let farm remove oid from trunk active list to avoid
a sha1_file_write fail later on.

Signed-off-by: Liu Yuan <tailai.ly at taobao.com>
---
 sheep/farm/farm.c  |   21 +++++++++++++++++++++
 sheep/ops.c        |   15 +--------------
 sheep/sheep_priv.h |    1 +
 3 files changed, 23 insertions(+), 14 deletions(-)

diff --git a/sheep/farm/farm.c b/sheep/farm/farm.c
index 323b086..215af10 100644
--- a/sheep/farm/farm.c
+++ b/sheep/farm/farm.c
@@ -719,6 +719,26 @@ static int farm_purge_obj(void)
 	return SD_RES_SUCCESS;
 }
 
+static int farm_remove_object(uint64_t oid)
+{
+	char path[PATH_MAX];
+	int ret = SD_RES_SUCCESS;
+
+	sprintf(path, "%s%016"PRIx64, obj_path, oid);
+
+	if (unlink(path) < 0) {
+		if (errno == ENOENT) {
+			ret = SD_RES_NO_OBJ;
+			goto out;
+		}
+		eprintf("%m\n");
+		ret =  SD_RES_EIO;
+	}
+out:
+	trunk_put_entry(oid);
+	return ret;
+}
+
 struct store_driver farm = {
 	.name = "farm",
 	.init = farm_init,
@@ -734,6 +754,7 @@ struct store_driver farm = {
 	.get_snap_file = farm_get_snap_file,
 	.format = farm_format,
 	.purge_obj = farm_purge_obj,
+	.remove_object = farm_remove_object,
 };
 
 add_store_driver(farm);
diff --git a/sheep/ops.c b/sheep/ops.c
index 541882d..a6c5595 100644
--- a/sheep/ops.c
+++ b/sheep/ops.c
@@ -580,24 +580,11 @@ static int read_copy_from_replica(struct vnode_info *vnodes, uint32_t epoch,
 static int store_remove_obj(struct request *req)
 {
 	uint64_t oid = req->rq.obj.oid;
-	struct strbuf buf = STRBUF_INIT;
-	int ret = SD_RES_SUCCESS;
 
 	objlist_cache_remove(oid);
 	object_cache_remove(oid);
 
-	strbuf_addf(&buf, "%s%016" PRIx64, obj_path, oid);
-	if (unlink(buf.buf) < 0) {
-		if (errno == ENOENT) {
-			ret = SD_RES_NO_OBJ;
-			goto out;
-		}
-		eprintf("%m\n");
-		ret =  SD_RES_EIO;
-	}
-out:
-	strbuf_release(&buf);
-	return ret;
+	return sd_store->remove_object(oid);
 }
 
 static int store_read_obj(struct request *req)
diff --git a/sheep/sheep_priv.h b/sheep/sheep_priv.h
index f082c5b..bb41e51 100644
--- a/sheep/sheep_priv.h
+++ b/sheep/sheep_priv.h
@@ -158,6 +158,7 @@ struct store_driver {
 	int (*write)(uint64_t oid, struct siocb *, int create);
 	int (*read)(uint64_t oid, struct siocb *);
 	int (*format)(struct siocb *);
+	int (*remove_object)(uint64_t oid);
 	/* Operations in recovery */
 	int (*link)(uint64_t oid, struct siocb *, uint32_t tgt_epoch);
 	int (*atomic_put)(uint64_t oid, struct siocb *);
-- 
1.7.10.2




More information about the sheepdog mailing list