[sheepdog] [PATCH stable-0.7 2/2] dog: check existence of specified snapshot in vdi_restore()

Hitoshi Mitake mitake.hitoshi at lab.ntt.co.jp
Tue Oct 29 02:30:10 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>
Signed-off-by: Liu Yuan <namei.unix at gmail.com>
---
 dog/vdi.c |   12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/dog/vdi.c b/dog/vdi.c
index 11c33d6..b650496 100644
--- a/dog/vdi.c
+++ b/dog/vdi.c
@@ -1846,6 +1846,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;
@@ -1857,6 +1858,16 @@ 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("Snapshot ID %d or tag %s doesn't exist",
+		       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
@@ -1902,6 +1913,7 @@ out:
 		}
 	}
 	free(current_inode);
+	free(inode_for_check);
 	return ret;
 }
 
-- 
1.7.10.4




More information about the sheepdog mailing list