aboutsummaryrefslogtreecommitdiff
path: root/block/sheepdog.c
diff options
context:
space:
mode:
authorLiu Yuan <namei.unix@gmail.com>2013-06-08 01:54:26 +0800
committerKevin Wolf <kwolf@redhat.com>2013-06-17 17:47:58 +0200
commitcede621ffc13ba1e209d9a21e85b21e150b74045 (patch)
tree74ddc9ac96c4ff02d2f130722fad9062ee176a1d /block/sheepdog.c
parentb579ffb3fd64243b64ac5aaf659ac88518f17835 (diff)
sheepdog: support 'qemu-img snapshot -a'
Just call sd_create_branch() in the snapshot_goto to rollback the image is good enough. With this patch, 'loadvm' process for sheepdog is modified: Suppose we have a snapshot chain A --> B --> C, we do 'loadvm A' so as to get a new chain, A --> B | V C1 in the old code: 1 reload inode of A (in snapshot_goto) 2 read vmstate via A's vdi_id (loadvm_state) 3 delete C and create C1, reload inode of C1 (sd_create_branch on write) with this patch applied: 1 reload inode of A, delete C and create C1 (in snapshot_goto) 2 read vmstate via C1's parent, that is A's vdi_id (loadvm_state) This will fix the possible bug that QEMU exit between 2 and 3 in the old code Cc: qemu-devel@nongnu.org Cc: MORITA Kazutaka <morita.kazutaka@lab.ntt.co.jp> Cc: Kevin Wolf <kwolf@redhat.com> Cc: Stefan Hajnoczi <stefanha@redhat.com> Signed-off-by: Liu Yuan <namei.unix@gmail.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Diffstat (limited to 'block/sheepdog.c')
-rw-r--r--block/sheepdog.c12
1 files changed, 5 insertions, 7 deletions
diff --git a/block/sheepdog.c b/block/sheepdog.c
index 94218ac937..1b7c3f19b0 100644
--- a/block/sheepdog.c
+++ b/block/sheepdog.c
@@ -2071,14 +2071,11 @@ static int sd_snapshot_goto(BlockDriverState *bs, const char *snapshot_id)
goto out;
}
- if (!s->inode.vm_state_size) {
- error_report("Invalid snapshot");
- ret = -ENOENT;
+ ret = sd_create_branch(s);
+ if (ret) {
goto out;
}
- s->is_snapshot = true;
-
g_free(old_s);
return 0;
@@ -2196,8 +2193,9 @@ static int do_load_save_vmstate(BDRVSheepdogState *s, uint8_t *data,
int fd, ret = 0, remaining = size;
unsigned int data_len;
uint64_t vmstate_oid;
- uint32_t vdi_index;
uint64_t offset;
+ uint32_t vdi_index;
+ uint32_t vdi_id = load ? s->inode.parent_vdi_id : s->inode.vdi_id;
fd = connect_to_sdog(s);
if (fd < 0) {
@@ -2210,7 +2208,7 @@ static int do_load_save_vmstate(BDRVSheepdogState *s, uint8_t *data,
data_len = MIN(remaining, SD_DATA_OBJ_SIZE - offset);
- vmstate_oid = vid_to_vmstate_oid(s->inode.vdi_id, vdi_index);
+ vmstate_oid = vid_to_vmstate_oid(vdi_id, vdi_index);
create = (offset == 0);
if (load) {