aboutsummaryrefslogtreecommitdiff
path: root/block
diff options
context:
space:
mode:
authorAnthony Liguori <aliguori@us.ibm.com>2013-06-17 13:14:13 -0500
committerAnthony Liguori <aliguori@us.ibm.com>2013-06-17 13:14:13 -0500
commit128dc2d1e4cb98ddbe9c0df2e0c914dc00925dac (patch)
treeadc3f6aae78c1f1387ebaf0f8ac4f20c99d576ec /block
parent5d71bbc5fb076e6d8a37bb3e320d61432b3c2ce0 (diff)
parent0bed087df24c7b3fae366f239b9d150de3309416 (diff)
Merge remote-tracking branch 'kwolf/for-anthony' into staging
# By Liu Yuan (2) and others # Via Kevin Wolf * kwolf/for-anthony: vmdk: Allow reading variable size descriptor files NVMe: Initial commit for new storage interface curl: Don't set curl options on the handle just before it's going to be deleted. vmdk: byteswap VMDK4Header.desc_offset field block/curl.c: Refuse to open the handle for writes. sheepdog: support 'qemu-img snapshot -a' sheepdog: fix snapshot tag initialization Message-id: 1371486710-17793-1-git-send-email-kwolf@redhat.com Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Diffstat (limited to 'block')
-rw-r--r--block/curl.c8
-rw-r--r--block/sheepdog.c14
-rw-r--r--block/vmdk.c34
3 files changed, 37 insertions, 19 deletions
diff --git a/block/curl.c b/block/curl.c
index 4dc3b4b71b..6af8cb7577 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)) {
@@ -446,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)
diff --git a/block/sheepdog.c b/block/sheepdog.c
index 21a4edf15b..1b7c3f19b0 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);
@@ -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) {
diff --git a/block/vmdk.c b/block/vmdk.c
index 608daaf930..65ae0119c4 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) {
@@ -719,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;
+
+ 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, sizeof(buf));
+ 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)