[sheepdog] [PATCH v3] dog: allow vdi snapshot without snapshot tag
Hitoshi Mitake
mitake.hitoshi at lab.ntt.co.jp
Fri Sep 19 10:00:23 CEST 2014
The commit a21bf27906b23448b92cca9943e1019105ffac2f makes
$ dog vdi snapshot <vdi>
fail if the <vdi> is an ordinal vdi because newly created VDIs have
snapid 0. This patch avoids the failure with checking the VDI is
snapshot or not.
Cc: Ruoyu <liangry at ucweb.com>
Signed-off-by: Hitoshi Mitake <mitake.hitoshi at lab.ntt.co.jp>
---
dog/vdi.c | 36 +++++++++++++++++++++++++-----------
1 file changed, 25 insertions(+), 11 deletions(-)
v3: rework switch case for handling error code of find_vdi_name()
v2: correct vdi existence checking
diff --git a/dog/vdi.c b/dog/vdi.c
index fa6130e..c541706 100644
--- a/dog/vdi.c
+++ b/dog/vdi.c
@@ -567,6 +567,7 @@ static int vdi_snapshot(int argc, char **argv)
int vs_count = 0;
struct node_id owners[SD_MAX_COPIES];
int nr_owners = 0, nr_issued_prevent_inode_update = 0;
+ bool fail_if_snapshot = false;
if (vdi_cmd_data.snapshot_id != 0) {
sd_err("Please specify a non-integer value for "
@@ -577,23 +578,36 @@ static int vdi_snapshot(int argc, char **argv)
ret = find_vdi_name(vdiname, vdi_cmd_data.snapshot_id,
vdi_cmd_data.snapshot_tag, &vid);
switch (ret) {
- case SD_RES_NO_VDI:
- sd_err("Failed to create snapshot for %s: %s",
- vdiname, sd_strerror(ret));
- return EXIT_FAILURE;
case SD_RES_NO_TAG:
break;
+ case SD_RES_SUCCESS:
+ fail_if_snapshot = true;
+ break;
default:
- sd_err("Failed to create snapshot for %s, maybe "
- "snapshot id (%d) or tag (%s) is existed",
- vdiname, vdi_cmd_data.snapshot_id,
- vdi_cmd_data.snapshot_tag);
+ sd_err("Failed to create snapshot for %s: %s",
+ vdiname, sd_strerror(ret));
return EXIT_FAILURE;
}
- ret = read_vdi_obj(vdiname, 0, "", &vid, inode, SD_INODE_HEADER_SIZE);
- if (ret != EXIT_SUCCESS)
- return ret;
+ if (fail_if_snapshot) {
+ ret = dog_read_object(vid_to_vdi_oid(vid), inode,
+ SD_INODE_HEADER_SIZE, 0, true);
+ if (ret != EXIT_SUCCESS)
+ return ret;
+
+ if (vdi_is_snapshot(inode)) {
+ sd_err("Failed to create snapshot for %s, maybe "
+ "snapshot id (%d) or tag (%s) is existed",
+ vdiname, vdi_cmd_data.snapshot_id,
+ vdi_cmd_data.snapshot_tag);
+ return EXIT_FAILURE;
+ }
+ } else {
+ ret = read_vdi_obj(vdiname, 0, "", &vid, inode,
+ SD_INODE_HEADER_SIZE);
+ if (ret != EXIT_SUCCESS)
+ return ret;
+ }
if (inode->store_policy) {
sd_err("creating a snapshot of hypervolume is not supported");
--
1.8.3.2
More information about the sheepdog
mailing list