Commit 8fcffa98 authored by Max Reitz's avatar Max Reitz Committed by Kevin Wolf
Browse files

qcow2: Return useful error code in refcount_init()



If bdrv_pread() returns an error, it is very unlikely that it was
ENOMEM. In this case, the return value should be passed along; as
bdrv_pread() will always either return the number of bytes read or a
negative value (the error code), the condition for checking whether
bdrv_pread() failed can be simplified (and clarified) as well.

Signed-off-by: default avatarMax Reitz <mreitz@redhat.com>
Signed-off-by: default avatarKevin Wolf <kwolf@redhat.com>
Reviewed-by: default avatarBenoit Canet <benoit@irqsave.net>
parent 7504edf4
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -50,19 +50,21 @@ int qcow2_refcount_init(BlockDriverState *bs)

    if (s->refcount_table_size > 0) {
        if (s->refcount_table == NULL) {
            ret = -ENOMEM;
            goto fail;
        }
        BLKDBG_EVENT(bs->file, BLKDBG_REFTABLE_LOAD);
        ret = bdrv_pread(bs->file, s->refcount_table_offset,
                         s->refcount_table, refcount_table_size2);
        if (ret != refcount_table_size2)
        if (ret < 0) {
            goto fail;
        }
        for(i = 0; i < s->refcount_table_size; i++)
            be64_to_cpus(&s->refcount_table[i]);
    }
    return 0;
 fail:
    return -ENOMEM;
    return ret;
}

void qcow2_refcount_close(BlockDriverState *bs)