[sheepdog] [PATCH] dog: check existence of specified snapshot in vdi_restore()

Hitoshi Mitake mitake.hitoshi at lab.ntt.co.jp
Mon Oct 28 07:32:12 CET 2013


Current "dog vdi restore" doesn't check existence of specified
snapshot. So if users specify invalid snapshot ID or tag, the parent
VDI is simply deleted. This behavior causes serious problem. This
patch adds the existence check for preventing it.

Signed-off-by: Hitoshi Mitake <mitake.hitoshi at lab.ntt.co.jp>
---
 dog/vdi.c |   13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/dog/vdi.c b/dog/vdi.c
index 6d00d36..84e2ce3 100644
--- a/dog/vdi.c
+++ b/dog/vdi.c
@@ -1981,6 +1981,7 @@ static int vdi_restore(int argc, char **argv)
 	const char *vdiname = argv[optind++];
 	int ret;
 	char buf[SD_INODE_HEADER_SIZE] = {0};
+	struct sd_inode *inode_for_check = xzalloc(sizeof(*inode_for_check));
 	struct sd_inode *current_inode = xzalloc(sizeof(*current_inode));
 	struct sd_inode *parent_inode = (struct sd_inode *)buf;
 	bool need_current_recovery = false;
@@ -1992,6 +1993,17 @@ static int vdi_restore(int argc, char **argv)
 		goto out;
 	}
 
+	ret = read_vdi_obj(vdiname, vdi_cmd_data.snapshot_id,
+			   vdi_cmd_data.snapshot_tag, NULL, inode_for_check,
+			   SD_INODE_SIZE);
+	if (ret != SD_RES_SUCCESS) {
+		sd_err("You would've specified invalid snapshot"
+		       " ID (%d) or tag (%s)", vdi_cmd_data.snapshot_id,
+		       vdi_cmd_data.snapshot_tag);
+
+		goto out;
+	}
+
 	/*
 	 * delete the current vdi temporarily first to avoid making
 	 * the current state become snapshot
@@ -2038,6 +2050,7 @@ out:
 		}
 	}
 	free(current_inode);
+	free(inode_for_check);
 	return ret;
 }
 
-- 
1.7.10.4




More information about the sheepdog mailing list