From b579ffb3fd64243b64ac5aaf659ac88518f17835 Mon Sep 17 00:00:00 2001 From: Liu Yuan Date: Sat, 8 Jun 2013 01:54:25 +0800 Subject: sheepdog: fix snapshot tag initialization This is an old and obvious bug. We should pass snapshot_id to the tag. Or simple command like 'qemu-img snapshot -a tag sheepdog:image' will fail Cc: qemu-devel@nongnu.org Cc: MORITA Kazutaka Cc: Kevin Wolf Cc: Stefan Hajnoczi Reviewed-by: Kevin Wolf Signed-off-by: Liu Yuan Signed-off-by: Kevin Wolf --- block/sheepdog.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'block') diff --git a/block/sheepdog.c b/block/sheepdog.c index 21a4edf..94218ac 100644 --- a/block/sheepdog.c +++ b/block/sheepdog.c @@ -2063,7 +2063,7 @@ static int sd_snapshot_goto(BlockDriverState *bs, const char *snapshot_id) if (snapid) { tag[0] = 0; } else { - pstrcpy(tag, sizeof(tag), s->name); + pstrcpy(tag, sizeof(tag), snapshot_id); } ret = reload_inode(s, snapid, tag); -- cgit v1.1 From cede621ffc13ba1e209d9a21e85b21e150b74045 Mon Sep 17 00:00:00 2001 From: Liu Yuan Date: Sat, 8 Jun 2013 01:54:26 +0800 Subject: 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 Cc: Kevin Wolf Cc: Stefan Hajnoczi Signed-off-by: Liu Yuan Signed-off-by: Kevin Wolf --- block/sheepdog.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'block') diff --git a/block/sheepdog.c b/block/sheepdog.c index 94218ac..1b7c3f1 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) { -- cgit v1.1 From a7cea2ba47ea6d361584072f96d7858f5cc99009 Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Mon, 10 Jun 2013 12:38:43 +0100 Subject: block/curl.c: Refuse to open the handle for writes. Signed-off-by: Richard W.M. Jones Signed-off-by: Fam Zheng Signed-off-by: Kevin Wolf --- block/curl.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'block') diff --git a/block/curl.c b/block/curl.c index 4dc3b4b..0fba451 100644 --- a/block/curl.c +++ b/block/curl.c @@ -406,6 +406,12 @@ static int curl_open(BlockDriverState *bs, QDict *options, int flags) static int inited = 0; + if (flags & BDRV_O_RDWR) { + qerror_report(ERROR_CLASS_GENERIC_ERROR, + "curl block device does not support writes"); + return -EROFS; + } + opts = qemu_opts_create_nofail(&runtime_opts); qemu_opts_absorb_qdict(opts, options, &local_err); if (error_is_set(&local_err)) { -- cgit v1.1 From 5a394b9e96eb3c39676353bdf8a230180ae8d6f4 Mon Sep 17 00:00:00 2001 From: Stefan Hajnoczi Date: Mon, 10 Jun 2013 11:07:33 +0200 Subject: vmdk: byteswap VMDK4Header.desc_offset field Remember to byteswap VMDK4Header.desc_offset on big-endian machines. Cc: qemu-stable@nongnu.org Signed-off-by: Stefan Hajnoczi Signed-off-by: Kevin Wolf --- block/vmdk.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'block') diff --git a/block/vmdk.c b/block/vmdk.c index 608daaf..ee50a73 100644 --- a/block/vmdk.c +++ b/block/vmdk.c @@ -507,8 +507,11 @@ static int vmdk_open_vmdk4(BlockDriverState *bs, if (ret < 0) { return ret; } - if (header.capacity == 0 && header.desc_offset) { - return vmdk_open_desc_file(bs, flags, header.desc_offset << 9); + if (header.capacity == 0) { + int64_t desc_offset = le64_to_cpu(header.desc_offset); + if (desc_offset) { + return vmdk_open_desc_file(bs, flags, desc_offset << 9); + } } if (le64_to_cpu(header.gd_offset) == VMDK4_GD_AT_END) { -- cgit v1.1 From 8da1aa15db2f55c42bdcea95e27b1a190d2be754 Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Mon, 10 Jun 2013 17:40:15 +0100 Subject: curl: Don't set curl options on the handle just before it's going to be deleted. (Found by Kamil Dudka) Signed-off-by: Richard W.M. Jones Cc: Michael Tokarev Signed-off-by: Kevin Wolf --- block/curl.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'block') diff --git a/block/curl.c b/block/curl.c index 0fba451..6af8cb7 100644 --- a/block/curl.c +++ b/block/curl.c @@ -452,8 +452,6 @@ static int curl_open(BlockDriverState *bs, QDict *options, int flags) if (curl_easy_perform(state->curl)) goto out; curl_easy_getinfo(state->curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &d); - curl_easy_setopt(state->curl, CURLOPT_WRITEFUNCTION, (void *)curl_read_cb); - curl_easy_setopt(state->curl, CURLOPT_NOBODY, 0); if (d) s->len = (size_t)d; else if(!s->len) -- cgit v1.1 From 0bed087df24c7b3fae366f239b9d150de3309416 Mon Sep 17 00:00:00 2001 From: Evgeny Budilovsky Date: Wed, 12 Jun 2013 14:06:30 +0300 Subject: vmdk: Allow reading variable size descriptor files the hard-coded 2k buffer on the stack won't allow reading big descriptor files which can be generated when storing big images. For example 500G vmdk splitted to 2G chunks. Signed-off-by: Evgeny Budilovsky Reviewed-by: Stefan Hajnoczi Signed-off-by: Kevin Wolf --- block/vmdk.c | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) (limited to 'block') diff --git a/block/vmdk.c b/block/vmdk.c index ee50a73..65ae011 100644 --- a/block/vmdk.c +++ b/block/vmdk.c @@ -722,27 +722,40 @@ static int vmdk_open_desc_file(BlockDriverState *bs, int flags, int64_t desc_offset) { int ret; - char buf[2048]; + char *buf = NULL; char ct[128]; BDRVVmdkState *s = bs->opaque; + int64_t size; - ret = bdrv_pread(bs->file, desc_offset, buf, sizeof(buf)); + size = bdrv_getlength(bs->file); + if (size < 0) { + return -EINVAL; + } + + size = MIN(size, 1 << 20); /* avoid unbounded allocation */ + buf = g_malloc0(size + 1); + + ret = bdrv_pread(bs->file, desc_offset, buf, size); if (ret < 0) { - return ret; + goto exit; } - buf[2047] = '\0'; if (vmdk_parse_description(buf, "createType", ct, sizeof(ct))) { - return -EMEDIUMTYPE; + ret = -EMEDIUMTYPE; + goto exit; } if (strcmp(ct, "monolithicFlat") && strcmp(ct, "twoGbMaxExtentSparse") && strcmp(ct, "twoGbMaxExtentFlat")) { fprintf(stderr, "VMDK: Not supported image type \"%s\""".\n", ct); - return -ENOTSUP; + ret = -ENOTSUP; + goto exit; } s->desc_offset = 0; - return vmdk_parse_extents(buf, bs, bs->file->filename); + ret = vmdk_parse_extents(buf, bs, bs->file->filename); +exit: + g_free(buf); + return ret; } static int vmdk_open(BlockDriverState *bs, QDict *options, int flags) -- cgit v1.1