Commit 37f09e5e authored by Paolo Bonzini's avatar Paolo Bonzini Committed by Kevin Wolf
Browse files

vmdk: do not try opening a file as both image and descriptor



This prepares for propagating errors from vmdk_open_sparse and
vmdk_open_desc_file up to the caller of vmdk_open.

Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
Reviewed-by: default avatarFam Zheng <famz@redhat.com>
Signed-off-by: default avatarKevin Wolf <kwolf@redhat.com>
parent d1833ef5
Loading
Loading
Loading
Loading
+15 −7
Original line number Diff line number Diff line
@@ -886,20 +886,28 @@ static int vmdk_open(BlockDriverState *bs, QDict *options, int flags,
    char *buf = NULL;
    int ret;
    BDRVVmdkState *s = bs->opaque;
    uint32_t magic;

    buf = vmdk_read_desc(bs->file, 0, errp);
    if (!buf) {
        return -EINVAL;
    }

    if (vmdk_open_sparse(bs, bs->file, flags, buf, errp) == 0) {
    magic = ldl_be_p(buf);
    switch (magic) {
        case VMDK3_MAGIC:
        case VMDK4_MAGIC:
            ret = vmdk_open_sparse(bs, bs->file, flags, buf, errp);
            s->desc_offset = 0x200;
    } else {
            break;
        default:
            ret = vmdk_open_desc_file(bs, flags, buf, errp);
            break;
    }
    if (ret) {
        goto fail;
    }
    }

    /* try to open parent images, if exist */
    ret = vmdk_parent_open(bs);
    if (ret) {
+2 −2
Original line number Diff line number Diff line
@@ -8,7 +8,7 @@ no file open, try 'help open'
=== Testing too big L2 table size ===
Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864
L2 table size too big
qemu-io: can't open device TEST_DIR/t.vmdk: Could not open 'TEST_DIR/t.vmdk': Wrong medium type
qemu-io: can't open device TEST_DIR/t.vmdk: Could not open 'TEST_DIR/t.vmdk': Invalid argument
no file open, try 'help open'

=== Testing too big L1 table size ===
@@ -2046,7 +2046,7 @@ RW 12582912 VMFS "dummy.IMGFMT" 1
=== Testing truncated sparse ===
Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=107374182400
qemu-img: File truncated, expecting at least 13172736 bytes
qemu-img: Could not open 'TEST_DIR/t.IMGFMT': Could not open 'TEST_DIR/t.IMGFMT': Wrong medium type
qemu-img: Could not open 'TEST_DIR/t.IMGFMT': Could not open 'TEST_DIR/t.IMGFMT': Invalid argument

=== Testing version 3 ===
image: TEST_DIR/iotest-version3.IMGFMT