[sheepdog] [PATCH] Make the vdi lock mechanism optional
Wang Zhengyong
wangzhengyong at cmss.chinamobile.com
Thu Feb 12 09:53:25 CET 2015
Current sheepdog driver will send LOCK_VDI/RELEASE_VDI ops,
while start/stop QEMU VM with sheepdog protocol, this mechanism
will lead qemu-img/qemu-io report error when the sheepdog VDI is locking
To keep backward compatiblity, this patch modify the functionality
that make the vdi lock mechanism optional(with --lock opention),
default VDI lock is disabled
Enable VDI lock:
e.g. dog cluster format --lock
Cc: Hitoshi Mitake <mitake.hitoshi at gmail.com>
Signed-off-by: Wang Zhengyong <wangzhengyong at cmss.chinamobile.com>
---
dog/cluster.c | 9 ++++++++-
include/internal_proto.h | 2 ++
sheep/ops.c | 10 ++++++++++
3 files changed, 20 insertions(+), 1 deletions(-)
diff --git a/dog/cluster.c b/dog/cluster.c
index 6a2db6e..e252316 100644
--- a/dog/cluster.c
+++ b/dog/cluster.c
@@ -22,6 +22,7 @@ static struct sd_option cluster_options[] = {
{'b', "store", true, "specify backend store"},
{'c', "copies", true, "specify the default data redundancy (number of copies)"},
{'f', "force", false, "do not prompt for confirmation"},
+ {'l', "lock", false, "Lock vdi to exclude multiple users"},
{'m', "multithread", false,
"use multi-thread for 'cluster snapshot save'"},
{'t', "strict", false,
@@ -41,6 +42,7 @@ static struct cluster_cmd_data {
bool strict;
char name[STORE_LEN];
bool fixed_vnodes;
+ bool use_lock;
} cluster_cmd_data;
#define DEFAULT_STORE "plain"
@@ -165,6 +167,8 @@ static int cluster_format(int argc, char **argv)
hdr.flags |= SD_FLAG_CMD_WRITE;
if (cluster_cmd_data.strict)
hdr.cluster.flags |= SD_CLUSTER_FLAG_STRICT;
+ if (cluster_cmd_data.use_lock)
+ hdr.cluster.flags |= SD_CLUSTER_FLAG_USE_LOCK;
#ifdef HAVE_DISKVNODES
hdr.cluster.flags |= SD_CLUSTER_FLAG_DISKMODE;
@@ -816,7 +820,7 @@ failure:
static struct subcommand cluster_cmd[] = {
{"info", NULL, "aprhvT", "show cluster information",
NULL, CMD_NEED_NODELIST, cluster_info, cluster_options},
- {"format", NULL, "bctaphzTV", "create a Sheepdog store",
+ {"format", NULL, "bcltaphzTV", "create a Sheepdog store",
NULL, CMD_NEED_NODELIST, cluster_format, cluster_options},
{"shutdown", NULL, "aphT", "stop Sheepdog",
NULL, 0, cluster_shutdown, cluster_options},
@@ -862,6 +866,9 @@ static int cluster_parser(int ch, const char *opt)
case 'f':
cluster_cmd_data.force = true;
break;
+ case 'l':
+ cluster_cmd_data.use_lock = true;
+ break;
case 'm':
cluster_cmd_data.multithread = true;
case 't':
diff --git a/include/internal_proto.h b/include/internal_proto.h
index 225cc28..e4de527 100644
--- a/include/internal_proto.h
+++ b/include/internal_proto.h
@@ -148,6 +148,8 @@
#define SD_CLUSTER_FLAG_STRICT 0x0001 /* Strict mode for write */
#define SD_CLUSTER_FLAG_DISKMODE 0x0002 /* Disk mode for cluster */
#define SD_CLUSTER_FLAG_AUTO_VNODES 0x0004 /* Cluster vnodes strategy */
+#define SD_CLUSTER_FLAG_USE_LOCK 0x0008 /* Lock/Unlock vdi */
+
enum sd_status {
SD_STATUS_OK = 1,
diff --git a/sheep/ops.c b/sheep/ops.c
index f31f62e..cba5573 100644
--- a/sheep/ops.c
+++ b/sheep/ops.c
@@ -1409,6 +1409,11 @@ static int cluster_lock_vdi_main(const struct sd_req *req, struct sd_rsp *rsp,
return SD_RES_SUCCESS;
}
+ if (!(sys->cinfo.flags & SD_CLUSTER_FLAG_USE_LOCK)) {
+ sd_debug("vdi lock is disabled");
+ return SD_RES_SUCCESS;
+ }
+
sd_info("node: %s is locking VDI (type: %s): %"PRIx32,
node_to_str(sender),
req->vdi.type == LOCK_TYPE_NORMAL ? "normal" : "shared", vid);
@@ -1433,6 +1438,11 @@ static int cluster_release_vdi_main(const struct sd_req *req,
return SD_RES_SUCCESS;
}
+ if (!(sys->cinfo.flags & SD_CLUSTER_FLAG_USE_LOCK)) {
+ sd_debug("vdi lock is disabled");
+ return SD_RES_SUCCESS;
+ }
+
sd_info("node: %s is unlocking VDI (type: %s): %"PRIx32, node_to_str(sender),
req->vdi.type == LOCK_TYPE_NORMAL ? "normal" : "shared", vid);
--
1.7.1
More information about the sheepdog
mailing list