[sheepdog] [PATCH 2/2] collie: add 'collie vdi cache delete' to delete cache
levin li
levin108 at gmail.com
Sat Dec 15 12:37:42 CET 2012
From: levin li <xingke.lwp at taobao.com>
When VMs are migrated or terminated accidentally, the cache of
the VMs won't be deleted at once, by this command we can delete
the cache of an specified VDI in all nodes of the cluster.
Signed-off-by: levin li <xingke.lwp at taobao.com>
---
collie/vdi.c | 29 +++++++++++++++++++++++++++++
include/internal_proto.h | 1 +
sheep/ops.c | 16 ++++++++++++++++
3 files changed, 46 insertions(+)
diff --git a/collie/vdi.c b/collie/vdi.c
index 9adb051..d979bae 100644
--- a/collie/vdi.c
+++ b/collie/vdi.c
@@ -1884,9 +1884,38 @@ out:
return ret;
}
+static int vdi_cache_delete(int argc, char **argv)
+{
+ const char *vdiname = argv[optind++];
+ struct sd_req hdr;
+ uint32_t vid;
+ int ret = EXIT_SUCCESS;
+
+ ret = find_vdi_name(vdiname, vdi_cmd_data.snapshot_id,
+ vdi_cmd_data.snapshot_tag, &vid, 0);
+ if (ret < 0) {
+ fprintf(stderr, "Failed to open VDI %s\n", vdiname);
+ ret = EXIT_FAILURE;
+ goto out;
+ }
+
+ sd_init_req(&hdr, SD_OP_DELETE_CACHE);
+ hdr.obj.oid = vid_to_vdi_oid(vid);
+
+ ret = send_light_req(&hdr, sdhost, sdport);
+ if (ret) {
+ fprintf(stderr, "failed to execute request\n");
+ return EXIT_FAILURE;
+ }
+out:
+ return ret;
+}
+
static struct subcommand vdi_cache_cmd[] = {
{"flush", NULL, NULL, "flush the cache of the vdi specified.",
NULL, 0, vdi_cache_flush},
+ {"delete", NULL, NULL, "delete the cache of the vdi specified in all nodes.",
+ NULL, 0, vdi_cache_delete},
{NULL,},
};
diff --git a/include/internal_proto.h b/include/internal_proto.h
index e2c1baa..6e6e5f7 100644
--- a/include/internal_proto.h
+++ b/include/internal_proto.h
@@ -67,6 +67,7 @@
#define SD_OP_FLUSH_NODES 0xAD
#define SD_OP_FLUSH_PEER 0xAE
#define SD_OP_NOTIFY_VDI_ADD 0xAF
+#define SD_OP_DELETE_CACHE 0xB0
/* internal flags for hdr.flags, must be above 0x80 */
#define SD_FLAG_CMD_RECOVERY 0x0080
diff --git a/sheep/ops.c b/sheep/ops.c
index 8862b78..476f712 100644
--- a/sheep/ops.c
+++ b/sheep/ops.c
@@ -577,6 +577,16 @@ static int cluster_notify_vdi_del(const struct sd_req *req, struct sd_rsp *rsp,
return objlist_cache_cleanup(vid);
}
+static int cluster_delete_cache(const struct sd_req *req, struct sd_rsp *rsp,
+ void *data)
+{
+ uint32_t vid = oid_to_vid(req->obj.oid);
+
+ object_cache_delete(vid);
+
+ return SD_RES_SUCCESS;
+}
+
static int cluster_recovery_completion(const struct sd_req *req,
struct sd_rsp *rsp,
void *data)
@@ -978,6 +988,12 @@ static struct sd_op_template sd_ops[] = {
.process_main = cluster_notify_vdi_add,
},
+ [SD_OP_DELETE_CACHE] = {
+ .name = "DELETE_CACHE",
+ .type = SD_OP_TYPE_CLUSTER,
+ .process_main = cluster_delete_cache,
+ },
+
[SD_OP_COMPLETE_RECOVERY] = {
.name = "COMPLETE_RECOVERY",
.type = SD_OP_TYPE_CLUSTER,
--
1.7.9.5
More information about the sheepdog
mailing list