[sheepdog] [PATCH stable-0.9] Make the vdi lock mechanism optional
Hitoshi Mitake
mitake.hitoshi at lab.ntt.co.jp
Mon May 11 13:34:28 CEST 2015
From: Wang Zhengyong <wangzhengyong at cmss.chinamobile.com>
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>
Signed-off-by: Hitoshi Mitake <mitake.hitoshi at lab.ntt.co.jp>
Conflicts:
dog/cluster.c
include/internal_proto.h
Conflicts were resolved by Hitoshi Mitake.
Signed-off-by: Hitoshi Mitake <mitake.hitoshi at lab.ntt.co.jp>
---
dog/cluster.c | 9 ++++++++-
include/internal_proto.h | 1 +
sheep/ops.c | 10 ++++++++++
3 files changed, 19 insertions(+), 1 deletion(-)
diff --git a/dog/cluster.c b/dog/cluster.c
index e42bc54..ad61295 100644
--- a/dog/cluster.c
+++ b/dog/cluster.c
@@ -21,6 +21,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,
@@ -35,6 +36,7 @@ static struct cluster_cmd_data {
bool force;
bool strict;
char name[STORE_LEN];
+ bool use_lock;
} cluster_cmd_data;
#define DEFAULT_STORE "plain"
@@ -123,6 +125,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;
@@ -752,7 +756,7 @@ failure:
static struct subcommand cluster_cmd[] = {
{"info", NULL, "aprhvT", "show cluster information",
NULL, CMD_NEED_NODELIST, cluster_info, cluster_options},
- {"format", NULL, "bctaphT", "create a Sheepdog store",
+ {"format", NULL, "bcltaphT", "create a Sheepdog store",
NULL, CMD_NEED_NODELIST, cluster_format, cluster_options},
{"shutdown", NULL, "aphT", "stop Sheepdog",
NULL, 0, cluster_shutdown, cluster_options},
@@ -797,6 +801,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 85f66b8..151f8cd 100644
--- a/include/internal_proto.h
+++ b/include/internal_proto.h
@@ -142,6 +142,7 @@
#define SD_CLUSTER_FLAG_STRICT 0x0001 /* Strict mode for write */
#define SD_CLUSTER_FLAG_DISKMODE 0x0002 /* Disk mode for cluster */
+#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 b039c58..9e038f6 100644
--- a/sheep/ops.c
+++ b/sheep/ops.c
@@ -1344,6 +1344,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);
@@ -1368,6 +1373,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.9.1
More information about the sheepdog
mailing list