[sheepdog] [PATCH v3 1/2] sheep: teach sheep to discard unused objects

Liu Yuan namei.unix at gmail.com
Tue Apr 16 06:58:39 CEST 2013


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

Signed-off-by: Liu Yuan <tailai.ly at taobao.com>
---
 include/sheepdog_proto.h |    1 +
 sheep/ops.c              |   26 ++++++++++++++++++++++++++
 2 files changed, 27 insertions(+)

diff --git a/include/sheepdog_proto.h b/include/sheepdog_proto.h
index f3d69e1..0ddae4a 100644
--- a/include/sheepdog_proto.h
+++ b/include/sheepdog_proto.h
@@ -28,6 +28,7 @@
 #define SD_OP_READ_OBJ       0x02
 #define SD_OP_WRITE_OBJ      0x03
 #define SD_OP_REMOVE_OBJ     0x04
+#define SD_OP_DISCARD_OBJ    0x05
 
 #define SD_OP_NEW_VDI        0x11
 #define SD_OP_LOCK_VDI       0x12
diff --git a/sheep/ops.c b/sheep/ops.c
index a0502b2..bf565fb 100644
--- a/sheep/ops.c
+++ b/sheep/ops.c
@@ -741,6 +741,26 @@ static int local_flush_vdi(struct request *req)
 	return ret;
 }
 
+static int local_discard_obj(struct request *req)
+{
+	uint64_t oid = req->rq.obj.oid;
+	uint32_t vid = oid_to_vid(oid), zero = 0;
+	int ret, cp = get_vdi_copy_number(vid), idx = data_oid_to_idx(oid);
+
+	sd_dprintf("%"PRIx64, oid);
+	ret = write_object(vid_to_vdi_oid(vid), (char *)&zero, sizeof(zero),
+			   SD_INODE_HEADER_SIZE + sizeof(vid) * idx, false, cp);
+	if (ret != SD_RES_SUCCESS)
+		return ret;
+	if (remove_object(oid, cp) != SD_RES_SUCCESS)
+		sd_eprintf("failed to remove %"PRIx64, oid);
+	/*
+	 * Return success even if remove_object fails because we have updated
+	 * inode successfully.
+	 */
+	return SD_RES_SUCCESS;
+}
+
 static int local_flush_and_del(struct request *req)
 {
 	if (!sys->enable_object_cache)
@@ -1109,6 +1129,12 @@ static struct sd_op_template sd_ops[] = {
 		.process_work = local_flush_vdi,
 	},
 
+	[SD_OP_DISCARD_OBJ] = {
+		.name = "DISCARD_OBJ",
+		.type = SD_OP_TYPE_LOCAL,
+		.process_work = local_discard_obj,
+	},
+
 	[SD_OP_FLUSH_DEL_CACHE] = {
 		.name = "DEL_CACHE",
 		.type = SD_OP_TYPE_LOCAL,
-- 
1.7.9.5




More information about the sheepdog mailing list