[sheepdog] [PATCH 2/2] object cache: try to delete cache entris in every node when deleting a VDI

levin li levin108 at gmail.com
Wed Sep 5 10:41:59 CEST 2012


From: levin li <xingke.lwp at taobao.com>

Every node that starts VM in writeback mode can create cache entries, so we
can not only remove cache entries in the node that executes the VDI deletion
work, but should notify to try to delete cache entries on every node

Signed-off-by: levin li <xingke.lwp at taobao.com>
---
 sheep/object_cache.c |    2 +-
 sheep/ops.c          |   45 ++++++++++++++++++++++++++++++++++++++++++---
 2 files changed, 43 insertions(+), 4 deletions(-)

diff --git a/sheep/object_cache.c b/sheep/object_cache.c
index 5bd7060..89a24c1 100644
--- a/sheep/object_cache.c
+++ b/sheep/object_cache.c
@@ -203,6 +203,7 @@ del_from_object_tree_and_list(struct object_cache_entry *entry,
 			      struct rb_root *object_tree)
 {
 	rb_erase(&entry->node, object_tree);
+	list_del_init(&entry->object_list);
 	cds_list_del_rcu(&entry->lru_list);
 }
 
@@ -865,7 +866,6 @@ void object_cache_delete(uint32_t vid)
 	rmdir_r(buf.buf);
 
 	strbuf_release(&buf);
-
 }
 
 static struct object_cache_entry *
diff --git a/sheep/ops.c b/sheep/ops.c
index 7b25270..ba29235 100644
--- a/sheep/ops.c
+++ b/sheep/ops.c
@@ -155,15 +155,53 @@ static int cluster_del_vdi(struct request *req)
 	ret = del_vdi(req, req->data, hdr->data_length,
 		      &vid, hdr->vdi.snapid, &nr_copies);
 
-	if (sys->enable_write_cache && ret == SD_RES_SUCCESS)
-		object_cache_delete(vid);
-
 	rsp->vdi.vdi_id = vid;
 	rsp->vdi.copies = nr_copies;
 
 	return ret;
 }
 
+struct cache_deletion_work {
+	uint32_t vid;
+	struct work work;
+};
+
+static void cache_delete_work(struct work *work)
+{
+	struct cache_deletion_work *dw =
+		container_of(work, struct cache_deletion_work, work);
+
+	object_cache_delete(dw->vid);
+}
+
+static void cache_delete_done(struct work *work)
+{
+	struct cache_deletion_work *dw =
+		container_of(work, struct cache_deletion_work, work);
+
+	free(dw);
+}
+
+static int post_cluster_del_vdi(const struct sd_req *req, struct sd_rsp *rsp,
+				void *data)
+{
+	unsigned long vid = rsp->vdi.vdi_id;
+	struct cache_deletion_work *dw;
+	int ret = rsp->result;
+
+	if (!sys->enable_write_cache)
+		return ret;
+
+	dw = xzalloc(sizeof(*dw));
+	dw->vid = vid;
+	dw->work.fn = cache_delete_work;
+	dw->work.done = cache_delete_done;
+
+	queue_work(sys->deletion_wqueue, &dw->work);
+
+	return ret;
+}
+
 static int cluster_get_vdi_info(struct request *req)
 {
 	const struct sd_req *hdr = &req->rq;
@@ -925,6 +963,7 @@ static struct sd_op_template sd_ops[] = {
 		.name = "DEL_VDI",
 		.type = SD_OP_TYPE_CLUSTER,
 		.process_work = cluster_del_vdi,
+		.process_main = post_cluster_del_vdi,
 	},
 
 	[SD_OP_GET_VDI_INFO] = {
-- 
1.7.1




More information about the sheepdog mailing list