|
|
9ae3a8 |
From 9f0ec0582867ea7c45ac5b23bfcbd20e699a4bd4 Mon Sep 17 00:00:00 2001
|
|
|
9ae3a8 |
From: Max Reitz <mreitz@redhat.com>
|
|
|
9ae3a8 |
Date: Mon, 4 Nov 2013 22:32:14 +0100
|
|
|
9ae3a8 |
Subject: [PATCH 21/87] qcow2: Use Error parameter
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
RH-Author: Max Reitz <mreitz@redhat.com>
|
|
|
9ae3a8 |
Message-id: <1383604354-12743-24-git-send-email-mreitz@redhat.com>
|
|
|
9ae3a8 |
Patchwork-id: 55323
|
|
|
9ae3a8 |
O-Subject: [RHEL-7.0 qemu-kvm PATCH 23/43] qcow2: Use Error parameter
|
|
|
9ae3a8 |
Bugzilla: 1026524
|
|
|
9ae3a8 |
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>
|
|
|
9ae3a8 |
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
|
|
|
9ae3a8 |
RH-Acked-by: Fam Zheng <famz@redhat.com>
|
|
|
9ae3a8 |
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
BZ: 1026524
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Employ usage of the new Error ** parameter in qcow2_open, qcow2_create
|
|
|
9ae3a8 |
and associated functions.
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Signed-off-by: Max Reitz <mreitz@redhat.com>
|
|
|
9ae3a8 |
(cherry picked from commit 3ef6c40ad0b350e18c78135ffbdbe209cb479c1f)
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Signed-off-by: Max Reitz <mreitz@redhat.com>
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Conflicts:
|
|
|
9ae3a8 |
block/qcow2.c
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Conflicts because 8ad1898c has not been backported ("qcow2: Change
|
|
|
9ae3a8 |
default for new images to compat=1.1").
|
|
|
9ae3a8 |
---
|
|
|
9ae3a8 |
block/qcow2.c | 134 ++++++++++++++++++++++++++++++++++++++--------------------
|
|
|
9ae3a8 |
1 file changed, 88 insertions(+), 46 deletions(-)
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
9ae3a8 |
---
|
|
|
9ae3a8 |
block/qcow2.c | 134 +++++++++++++++++++++++++++++++++++++-------------------
|
|
|
9ae3a8 |
1 files changed, 88 insertions(+), 46 deletions(-)
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
diff --git a/block/qcow2.c b/block/qcow2.c
|
|
|
9ae3a8 |
index 027d210..880d2cf 100644
|
|
|
9ae3a8 |
--- a/block/qcow2.c
|
|
|
9ae3a8 |
+++ b/block/qcow2.c
|
|
|
9ae3a8 |
@@ -79,7 +79,8 @@ static int qcow2_probe(const uint8_t *buf, int buf_size, const char *filename)
|
|
|
9ae3a8 |
* return 0 upon success, non-0 otherwise
|
|
|
9ae3a8 |
*/
|
|
|
9ae3a8 |
static int qcow2_read_extensions(BlockDriverState *bs, uint64_t start_offset,
|
|
|
9ae3a8 |
- uint64_t end_offset, void **p_feature_table)
|
|
|
9ae3a8 |
+ uint64_t end_offset, void **p_feature_table,
|
|
|
9ae3a8 |
+ Error **errp)
|
|
|
9ae3a8 |
{
|
|
|
9ae3a8 |
BDRVQcowState *s = bs->opaque;
|
|
|
9ae3a8 |
QCowExtension ext;
|
|
|
9ae3a8 |
@@ -100,10 +101,10 @@ static int qcow2_read_extensions(BlockDriverState *bs, uint64_t start_offset,
|
|
|
9ae3a8 |
printf("attempting to read extended header in offset %lu\n", offset);
|
|
|
9ae3a8 |
#endif
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
- if (bdrv_pread(bs->file, offset, &ext, sizeof(ext)) != sizeof(ext)) {
|
|
|
9ae3a8 |
- fprintf(stderr, "qcow2_read_extension: ERROR: "
|
|
|
9ae3a8 |
- "pread fail from offset %" PRIu64 "\n",
|
|
|
9ae3a8 |
- offset);
|
|
|
9ae3a8 |
+ ret = bdrv_pread(bs->file, offset, &ext, sizeof(ext));
|
|
|
9ae3a8 |
+ if (ret < 0) {
|
|
|
9ae3a8 |
+ error_setg_errno(errp, -ret, "qcow2_read_extension: ERROR: "
|
|
|
9ae3a8 |
+ "pread fail from offset %" PRIu64, offset);
|
|
|
9ae3a8 |
return 1;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
be32_to_cpus(&ext.magic);
|
|
|
9ae3a8 |
@@ -113,7 +114,7 @@ static int qcow2_read_extensions(BlockDriverState *bs, uint64_t start_offset,
|
|
|
9ae3a8 |
printf("ext.magic = 0x%x\n", ext.magic);
|
|
|
9ae3a8 |
#endif
|
|
|
9ae3a8 |
if (ext.len > end_offset - offset) {
|
|
|
9ae3a8 |
- error_report("Header extension too large");
|
|
|
9ae3a8 |
+ error_setg(errp, "Header extension too large");
|
|
|
9ae3a8 |
return -EINVAL;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
@@ -123,14 +124,16 @@ static int qcow2_read_extensions(BlockDriverState *bs, uint64_t start_offset,
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
case QCOW2_EXT_MAGIC_BACKING_FORMAT:
|
|
|
9ae3a8 |
if (ext.len >= sizeof(bs->backing_format)) {
|
|
|
9ae3a8 |
- fprintf(stderr, "ERROR: ext_backing_format: len=%u too large"
|
|
|
9ae3a8 |
- " (>=%zu)\n",
|
|
|
9ae3a8 |
- ext.len, sizeof(bs->backing_format));
|
|
|
9ae3a8 |
+ error_setg(errp, "ERROR: ext_backing_format: len=%u too large"
|
|
|
9ae3a8 |
+ " (>=%zu)", ext.len, sizeof(bs->backing_format));
|
|
|
9ae3a8 |
return 2;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
- if (bdrv_pread(bs->file, offset , bs->backing_format,
|
|
|
9ae3a8 |
- ext.len) != ext.len)
|
|
|
9ae3a8 |
+ ret = bdrv_pread(bs->file, offset, bs->backing_format, ext.len);
|
|
|
9ae3a8 |
+ if (ret < 0) {
|
|
|
9ae3a8 |
+ error_setg_errno(errp, -ret, "ERROR: ext_backing_format: "
|
|
|
9ae3a8 |
+ "Could not read format name");
|
|
|
9ae3a8 |
return 3;
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
bs->backing_format[ext.len] = '\0';
|
|
|
9ae3a8 |
#ifdef DEBUG_EXT
|
|
|
9ae3a8 |
printf("Qcow2: Got format extension %s\n", bs->backing_format);
|
|
|
9ae3a8 |
@@ -142,6 +145,8 @@ static int qcow2_read_extensions(BlockDriverState *bs, uint64_t start_offset,
|
|
|
9ae3a8 |
void* feature_table = g_malloc0(ext.len + 2 * sizeof(Qcow2Feature));
|
|
|
9ae3a8 |
ret = bdrv_pread(bs->file, offset , feature_table, ext.len);
|
|
|
9ae3a8 |
if (ret < 0) {
|
|
|
9ae3a8 |
+ error_setg_errno(errp, -ret, "ERROR: ext_feature_table: "
|
|
|
9ae3a8 |
+ "Could not read table");
|
|
|
9ae3a8 |
return ret;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
@@ -161,6 +166,8 @@ static int qcow2_read_extensions(BlockDriverState *bs, uint64_t start_offset,
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
ret = bdrv_pread(bs->file, offset , uext->data, uext->len);
|
|
|
9ae3a8 |
if (ret < 0) {
|
|
|
9ae3a8 |
+ error_setg_errno(errp, -ret, "ERROR: unknown extension: "
|
|
|
9ae3a8 |
+ "Could not read data");
|
|
|
9ae3a8 |
return ret;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
@@ -184,8 +191,8 @@ static void cleanup_unknown_header_ext(BlockDriverState *bs)
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
-static void GCC_FMT_ATTR(2, 3) report_unsupported(BlockDriverState *bs,
|
|
|
9ae3a8 |
- const char *fmt, ...)
|
|
|
9ae3a8 |
+static void GCC_FMT_ATTR(3, 4) report_unsupported(BlockDriverState *bs,
|
|
|
9ae3a8 |
+ Error **errp, const char *fmt, ...)
|
|
|
9ae3a8 |
{
|
|
|
9ae3a8 |
char msg[64];
|
|
|
9ae3a8 |
va_list ap;
|
|
|
9ae3a8 |
@@ -194,17 +201,17 @@ static void GCC_FMT_ATTR(2, 3) report_unsupported(BlockDriverState *bs,
|
|
|
9ae3a8 |
vsnprintf(msg, sizeof(msg), fmt, ap);
|
|
|
9ae3a8 |
va_end(ap);
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
- qerror_report(QERR_UNKNOWN_BLOCK_FORMAT_FEATURE,
|
|
|
9ae3a8 |
- bs->device_name, "qcow2", msg);
|
|
|
9ae3a8 |
+ error_set(errp, QERR_UNKNOWN_BLOCK_FORMAT_FEATURE, bs->device_name, "qcow2",
|
|
|
9ae3a8 |
+ msg);
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
static void report_unsupported_feature(BlockDriverState *bs,
|
|
|
9ae3a8 |
- Qcow2Feature *table, uint64_t mask)
|
|
|
9ae3a8 |
+ Error **errp, Qcow2Feature *table, uint64_t mask)
|
|
|
9ae3a8 |
{
|
|
|
9ae3a8 |
while (table && table->name[0] != '\0') {
|
|
|
9ae3a8 |
if (table->type == QCOW2_FEAT_TYPE_INCOMPATIBLE) {
|
|
|
9ae3a8 |
if (mask & (1 << table->bit)) {
|
|
|
9ae3a8 |
- report_unsupported(bs, "%.46s",table->name);
|
|
|
9ae3a8 |
+ report_unsupported(bs, errp, "%.46s", table->name);
|
|
|
9ae3a8 |
mask &= ~(1 << table->bit);
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
@@ -212,7 +219,8 @@ static void report_unsupported_feature(BlockDriverState *bs,
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
if (mask) {
|
|
|
9ae3a8 |
- report_unsupported(bs, "Unknown incompatible feature: %" PRIx64, mask);
|
|
|
9ae3a8 |
+ report_unsupported(bs, errp, "Unknown incompatible feature: %" PRIx64,
|
|
|
9ae3a8 |
+ mask);
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
@@ -363,6 +371,7 @@ static int qcow2_open(BlockDriverState *bs, QDict *options, int flags,
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
ret = bdrv_pread(bs->file, 0, &header, sizeof(header));
|
|
|
9ae3a8 |
if (ret < 0) {
|
|
|
9ae3a8 |
+ error_setg_errno(errp, -ret, "Could not read qcow2 header");
|
|
|
9ae3a8 |
goto fail;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
be32_to_cpus(&header.magic);
|
|
|
9ae3a8 |
@@ -380,11 +389,12 @@ static int qcow2_open(BlockDriverState *bs, QDict *options, int flags,
|
|
|
9ae3a8 |
be32_to_cpus(&header.nb_snapshots);
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
if (header.magic != QCOW_MAGIC) {
|
|
|
9ae3a8 |
+ error_setg(errp, "Image is not in qcow2 format");
|
|
|
9ae3a8 |
ret = -EMEDIUMTYPE;
|
|
|
9ae3a8 |
goto fail;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
if (header.version < 2 || header.version > 3) {
|
|
|
9ae3a8 |
- report_unsupported(bs, "QCOW version %d", header.version);
|
|
|
9ae3a8 |
+ report_unsupported(bs, errp, "QCOW version %d", header.version);
|
|
|
9ae3a8 |
ret = -ENOTSUP;
|
|
|
9ae3a8 |
goto fail;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
@@ -412,6 +422,8 @@ static int qcow2_open(BlockDriverState *bs, QDict *options, int flags,
|
|
|
9ae3a8 |
ret = bdrv_pread(bs->file, sizeof(header), s->unknown_header_fields,
|
|
|
9ae3a8 |
s->unknown_header_fields_size);
|
|
|
9ae3a8 |
if (ret < 0) {
|
|
|
9ae3a8 |
+ error_setg_errno(errp, -ret, "Could not read unknown qcow2 header "
|
|
|
9ae3a8 |
+ "fields");
|
|
|
9ae3a8 |
goto fail;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
@@ -430,8 +442,8 @@ static int qcow2_open(BlockDriverState *bs, QDict *options, int flags,
|
|
|
9ae3a8 |
if (s->incompatible_features & ~QCOW2_INCOMPAT_MASK) {
|
|
|
9ae3a8 |
void *feature_table = NULL;
|
|
|
9ae3a8 |
qcow2_read_extensions(bs, header.header_length, ext_end,
|
|
|
9ae3a8 |
- &feature_table);
|
|
|
9ae3a8 |
- report_unsupported_feature(bs, feature_table,
|
|
|
9ae3a8 |
+ &feature_table, NULL);
|
|
|
9ae3a8 |
+ report_unsupported_feature(bs, errp, feature_table,
|
|
|
9ae3a8 |
s->incompatible_features &
|
|
|
9ae3a8 |
~QCOW2_INCOMPAT_MASK);
|
|
|
9ae3a8 |
ret = -ENOTSUP;
|
|
|
9ae3a8 |
@@ -442,8 +454,8 @@ static int qcow2_open(BlockDriverState *bs, QDict *options, int flags,
|
|
|
9ae3a8 |
/* Corrupt images may not be written to unless they are being repaired
|
|
|
9ae3a8 |
*/
|
|
|
9ae3a8 |
if ((flags & BDRV_O_RDWR) && !(flags & BDRV_O_CHECK)) {
|
|
|
9ae3a8 |
- error_report("qcow2: Image is corrupt; cannot be opened "
|
|
|
9ae3a8 |
- "read/write.");
|
|
|
9ae3a8 |
+ error_setg(errp, "qcow2: Image is corrupt; cannot be opened "
|
|
|
9ae3a8 |
+ "read/write");
|
|
|
9ae3a8 |
ret = -EACCES;
|
|
|
9ae3a8 |
goto fail;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
@@ -451,7 +463,7 @@ static int qcow2_open(BlockDriverState *bs, QDict *options, int flags,
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
/* Check support for various header values */
|
|
|
9ae3a8 |
if (header.refcount_order != 4) {
|
|
|
9ae3a8 |
- report_unsupported(bs, "%d bit reference counts",
|
|
|
9ae3a8 |
+ report_unsupported(bs, errp, "%d bit reference counts",
|
|
|
9ae3a8 |
1 << header.refcount_order);
|
|
|
9ae3a8 |
ret = -ENOTSUP;
|
|
|
9ae3a8 |
goto fail;
|
|
|
9ae3a8 |
@@ -459,10 +471,13 @@ static int qcow2_open(BlockDriverState *bs, QDict *options, int flags,
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
if (header.cluster_bits < MIN_CLUSTER_BITS ||
|
|
|
9ae3a8 |
header.cluster_bits > MAX_CLUSTER_BITS) {
|
|
|
9ae3a8 |
+ error_setg(errp, "Unsupported cluster size: 2^%i", header.cluster_bits);
|
|
|
9ae3a8 |
ret = -EINVAL;
|
|
|
9ae3a8 |
goto fail;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
if (header.crypt_method > QCOW_CRYPT_AES) {
|
|
|
9ae3a8 |
+ error_setg(errp, "Unsupported encryption method: %i",
|
|
|
9ae3a8 |
+ header.crypt_method);
|
|
|
9ae3a8 |
ret = -EINVAL;
|
|
|
9ae3a8 |
goto fail;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
@@ -491,6 +506,7 @@ static int qcow2_open(BlockDriverState *bs, QDict *options, int flags,
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
l1_vm_state_index = size_to_l1(s, header.size);
|
|
|
9ae3a8 |
if (l1_vm_state_index > INT_MAX) {
|
|
|
9ae3a8 |
+ error_setg(errp, "Image is too big");
|
|
|
9ae3a8 |
ret = -EFBIG;
|
|
|
9ae3a8 |
goto fail;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
@@ -499,6 +515,7 @@ static int qcow2_open(BlockDriverState *bs, QDict *options, int flags,
|
|
|
9ae3a8 |
/* the L1 table must contain at least enough entries to put
|
|
|
9ae3a8 |
header.size bytes */
|
|
|
9ae3a8 |
if (s->l1_size < s->l1_vm_state_index) {
|
|
|
9ae3a8 |
+ error_setg(errp, "L1 table is too small");
|
|
|
9ae3a8 |
ret = -EINVAL;
|
|
|
9ae3a8 |
goto fail;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
@@ -509,6 +526,7 @@ static int qcow2_open(BlockDriverState *bs, QDict *options, int flags,
|
|
|
9ae3a8 |
ret = bdrv_pread(bs->file, s->l1_table_offset, s->l1_table,
|
|
|
9ae3a8 |
s->l1_size * sizeof(uint64_t));
|
|
|
9ae3a8 |
if (ret < 0) {
|
|
|
9ae3a8 |
+ error_setg_errno(errp, -ret, "Could not read L1 table");
|
|
|
9ae3a8 |
goto fail;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
for(i = 0;i < s->l1_size; i++) {
|
|
|
9ae3a8 |
@@ -529,6 +547,7 @@ static int qcow2_open(BlockDriverState *bs, QDict *options, int flags,
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
ret = qcow2_refcount_init(bs);
|
|
|
9ae3a8 |
if (ret != 0) {
|
|
|
9ae3a8 |
+ error_setg_errno(errp, -ret, "Could not initialize refcount handling");
|
|
|
9ae3a8 |
goto fail;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
@@ -536,7 +555,9 @@ static int qcow2_open(BlockDriverState *bs, QDict *options, int flags,
|
|
|
9ae3a8 |
QTAILQ_INIT(&s->discards);
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
/* read qcow2 extensions */
|
|
|
9ae3a8 |
- if (qcow2_read_extensions(bs, header.header_length, ext_end, NULL)) {
|
|
|
9ae3a8 |
+ if (qcow2_read_extensions(bs, header.header_length, ext_end, NULL,
|
|
|
9ae3a8 |
+ &local_err)) {
|
|
|
9ae3a8 |
+ error_propagate(errp, local_err);
|
|
|
9ae3a8 |
ret = -EINVAL;
|
|
|
9ae3a8 |
goto fail;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
@@ -550,6 +571,7 @@ static int qcow2_open(BlockDriverState *bs, QDict *options, int flags,
|
|
|
9ae3a8 |
ret = bdrv_pread(bs->file, header.backing_file_offset,
|
|
|
9ae3a8 |
bs->backing_file, len);
|
|
|
9ae3a8 |
if (ret < 0) {
|
|
|
9ae3a8 |
+ error_setg_errno(errp, -ret, "Could not read backing file name");
|
|
|
9ae3a8 |
goto fail;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
bs->backing_file[len] = '\0';
|
|
|
9ae3a8 |
@@ -557,6 +579,7 @@ static int qcow2_open(BlockDriverState *bs, QDict *options, int flags,
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
ret = qcow2_read_snapshots(bs);
|
|
|
9ae3a8 |
if (ret < 0) {
|
|
|
9ae3a8 |
+ error_setg_errno(errp, -ret, "Could not read snapshots");
|
|
|
9ae3a8 |
goto fail;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
@@ -565,6 +588,7 @@ static int qcow2_open(BlockDriverState *bs, QDict *options, int flags,
|
|
|
9ae3a8 |
s->autoclear_features = 0;
|
|
|
9ae3a8 |
ret = qcow2_update_header(bs);
|
|
|
9ae3a8 |
if (ret < 0) {
|
|
|
9ae3a8 |
+ error_setg_errno(errp, -ret, "Could not update qcow2 header");
|
|
|
9ae3a8 |
goto fail;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
@@ -579,6 +603,7 @@ static int qcow2_open(BlockDriverState *bs, QDict *options, int flags,
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
ret = qcow2_check(bs, &result, BDRV_FIX_ERRORS);
|
|
|
9ae3a8 |
if (ret < 0) {
|
|
|
9ae3a8 |
+ error_setg_errno(errp, -ret, "Could not repair dirty image");
|
|
|
9ae3a8 |
goto fail;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
@@ -587,8 +612,7 @@ static int qcow2_open(BlockDriverState *bs, QDict *options, int flags,
|
|
|
9ae3a8 |
opts = qemu_opts_create_nofail(&qcow2_runtime_opts);
|
|
|
9ae3a8 |
qemu_opts_absorb_qdict(opts, options, &local_err);
|
|
|
9ae3a8 |
if (error_is_set(&local_err)) {
|
|
|
9ae3a8 |
- qerror_report_err(local_err);
|
|
|
9ae3a8 |
- error_free(local_err);
|
|
|
9ae3a8 |
+ error_propagate(errp, local_err);
|
|
|
9ae3a8 |
ret = -EINVAL;
|
|
|
9ae3a8 |
goto fail;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
@@ -609,8 +633,8 @@ static int qcow2_open(BlockDriverState *bs, QDict *options, int flags,
|
|
|
9ae3a8 |
qemu_opts_del(opts);
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
if (s->use_lazy_refcounts && s->qcow_version < 3) {
|
|
|
9ae3a8 |
- qerror_report(ERROR_CLASS_GENERIC_ERROR, "Lazy refcounts require "
|
|
|
9ae3a8 |
- "a qcow2 image with at least qemu 1.1 compatibility level");
|
|
|
9ae3a8 |
+ error_setg(errp, "Lazy refcounts require a qcow2 image with at least "
|
|
|
9ae3a8 |
+ "qemu 1.1 compatibility level");
|
|
|
9ae3a8 |
ret = -EINVAL;
|
|
|
9ae3a8 |
goto fail;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
@@ -1333,7 +1357,8 @@ static int preallocate(BlockDriverState *bs)
|
|
|
9ae3a8 |
static int qcow2_create2(const char *filename, int64_t total_size,
|
|
|
9ae3a8 |
const char *backing_file, const char *backing_format,
|
|
|
9ae3a8 |
int flags, size_t cluster_size, int prealloc,
|
|
|
9ae3a8 |
- QEMUOptionParameter *options, int version)
|
|
|
9ae3a8 |
+ QEMUOptionParameter *options, int version,
|
|
|
9ae3a8 |
+ Error **errp)
|
|
|
9ae3a8 |
{
|
|
|
9ae3a8 |
/* Calculate cluster_bits */
|
|
|
9ae3a8 |
int cluster_bits;
|
|
|
9ae3a8 |
@@ -1341,9 +1366,8 @@ static int qcow2_create2(const char *filename, int64_t total_size,
|
|
|
9ae3a8 |
if (cluster_bits < MIN_CLUSTER_BITS || cluster_bits > MAX_CLUSTER_BITS ||
|
|
|
9ae3a8 |
(1 << cluster_bits) != cluster_size)
|
|
|
9ae3a8 |
{
|
|
|
9ae3a8 |
- error_report(
|
|
|
9ae3a8 |
- "Cluster size must be a power of two between %d and %dk",
|
|
|
9ae3a8 |
- 1 << MIN_CLUSTER_BITS, 1 << (MAX_CLUSTER_BITS - 10));
|
|
|
9ae3a8 |
+ error_setg(errp, "Cluster size must be a power of two between %d and "
|
|
|
9ae3a8 |
+ "%dk", 1 << MIN_CLUSTER_BITS, 1 << (MAX_CLUSTER_BITS - 10));
|
|
|
9ae3a8 |
return -EINVAL;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
@@ -1362,15 +1386,18 @@ static int qcow2_create2(const char *filename, int64_t total_size,
|
|
|
9ae3a8 |
BlockDriverState* bs;
|
|
|
9ae3a8 |
QCowHeader header;
|
|
|
9ae3a8 |
uint8_t* refcount_table;
|
|
|
9ae3a8 |
+ Error *local_err = NULL;
|
|
|
9ae3a8 |
int ret;
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
- ret = bdrv_create_file(filename, options, NULL);
|
|
|
9ae3a8 |
+ ret = bdrv_create_file(filename, options, &local_err);
|
|
|
9ae3a8 |
if (ret < 0) {
|
|
|
9ae3a8 |
+ error_propagate(errp, local_err);
|
|
|
9ae3a8 |
return ret;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
- ret = bdrv_file_open(&bs, filename, NULL, BDRV_O_RDWR, NULL);
|
|
|
9ae3a8 |
+ ret = bdrv_file_open(&bs, filename, NULL, BDRV_O_RDWR, &local_err);
|
|
|
9ae3a8 |
if (ret < 0) {
|
|
|
9ae3a8 |
+ error_propagate(errp, local_err);
|
|
|
9ae3a8 |
return ret;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
@@ -1400,6 +1427,7 @@ static int qcow2_create2(const char *filename, int64_t total_size,
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
ret = bdrv_pwrite(bs, 0, &header, sizeof(header));
|
|
|
9ae3a8 |
if (ret < 0) {
|
|
|
9ae3a8 |
+ error_setg_errno(errp, -ret, "Could not write qcow2 header");
|
|
|
9ae3a8 |
goto out;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
@@ -1409,6 +1437,7 @@ static int qcow2_create2(const char *filename, int64_t total_size,
|
|
|
9ae3a8 |
g_free(refcount_table);
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
if (ret < 0) {
|
|
|
9ae3a8 |
+ error_setg_errno(errp, -ret, "Could not write refcount table");
|
|
|
9ae3a8 |
goto out;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
@@ -1422,13 +1451,16 @@ static int qcow2_create2(const char *filename, int64_t total_size,
|
|
|
9ae3a8 |
BlockDriver* drv = bdrv_find_format("qcow2");
|
|
|
9ae3a8 |
assert(drv != NULL);
|
|
|
9ae3a8 |
ret = bdrv_open(bs, filename, NULL,
|
|
|
9ae3a8 |
- BDRV_O_RDWR | BDRV_O_CACHE_WB | BDRV_O_NO_FLUSH, drv, NULL);
|
|
|
9ae3a8 |
+ BDRV_O_RDWR | BDRV_O_CACHE_WB | BDRV_O_NO_FLUSH, drv, &local_err);
|
|
|
9ae3a8 |
if (ret < 0) {
|
|
|
9ae3a8 |
+ error_propagate(errp, local_err);
|
|
|
9ae3a8 |
goto out;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
ret = qcow2_alloc_clusters(bs, 2 * cluster_size);
|
|
|
9ae3a8 |
if (ret < 0) {
|
|
|
9ae3a8 |
+ error_setg_errno(errp, -ret, "Could not allocate clusters for qcow2 "
|
|
|
9ae3a8 |
+ "header and refcount table");
|
|
|
9ae3a8 |
goto out;
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
} else if (ret != 0) {
|
|
|
9ae3a8 |
@@ -1439,6 +1471,7 @@ static int qcow2_create2(const char *filename, int64_t total_size,
|
|
|
9ae3a8 |
/* Okay, now that we have a valid image, let's give it the right size */
|
|
|
9ae3a8 |
ret = bdrv_truncate(bs, total_size * BDRV_SECTOR_SIZE);
|
|
|
9ae3a8 |
if (ret < 0) {
|
|
|
9ae3a8 |
+ error_setg_errno(errp, -ret, "Could not resize image");
|
|
|
9ae3a8 |
goto out;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
@@ -1446,6 +1479,8 @@ static int qcow2_create2(const char *filename, int64_t total_size,
|
|
|
9ae3a8 |
if (backing_file) {
|
|
|
9ae3a8 |
ret = bdrv_change_backing_file(bs, backing_file, backing_format);
|
|
|
9ae3a8 |
if (ret < 0) {
|
|
|
9ae3a8 |
+ error_setg_errno(errp, -ret, "Could not assign backing file '%s' "
|
|
|
9ae3a8 |
+ "with format '%s'", backing_file, backing_format);
|
|
|
9ae3a8 |
goto out;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
@@ -1457,6 +1492,7 @@ static int qcow2_create2(const char *filename, int64_t total_size,
|
|
|
9ae3a8 |
ret = preallocate(bs);
|
|
|
9ae3a8 |
qemu_co_mutex_unlock(&s->lock);
|
|
|
9ae3a8 |
if (ret < 0) {
|
|
|
9ae3a8 |
+ error_setg_errno(errp, -ret, "Could not preallocate metadata");
|
|
|
9ae3a8 |
goto out;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
@@ -1477,6 +1513,8 @@ static int qcow2_create(const char *filename, QEMUOptionParameter *options,
|
|
|
9ae3a8 |
size_t cluster_size = DEFAULT_CLUSTER_SIZE;
|
|
|
9ae3a8 |
int prealloc = 0;
|
|
|
9ae3a8 |
int version = 2;
|
|
|
9ae3a8 |
+ Error *local_err = NULL;
|
|
|
9ae3a8 |
+ int ret;
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
/* Read out options */
|
|
|
9ae3a8 |
while (options && options->name) {
|
|
|
9ae3a8 |
@@ -1498,8 +1536,8 @@ static int qcow2_create(const char *filename, QEMUOptionParameter *options,
|
|
|
9ae3a8 |
} else if (!strcmp(options->value.s, "metadata")) {
|
|
|
9ae3a8 |
prealloc = 1;
|
|
|
9ae3a8 |
} else {
|
|
|
9ae3a8 |
- fprintf(stderr, "Invalid preallocation mode: '%s'\n",
|
|
|
9ae3a8 |
- options->value.s);
|
|
|
9ae3a8 |
+ error_setg(errp, "Invalid preallocation mode: '%s'",
|
|
|
9ae3a8 |
+ options->value.s);
|
|
|
9ae3a8 |
return -EINVAL;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
} else if (!strcmp(options->name, BLOCK_OPT_COMPAT_LEVEL)) {
|
|
|
9ae3a8 |
@@ -1508,8 +1546,8 @@ static int qcow2_create(const char *filename, QEMUOptionParameter *options,
|
|
|
9ae3a8 |
} else if (!strcmp(options->value.s, "1.1")) {
|
|
|
9ae3a8 |
version = 3;
|
|
|
9ae3a8 |
} else {
|
|
|
9ae3a8 |
- fprintf(stderr, "Invalid compatibility level: '%s'\n",
|
|
|
9ae3a8 |
- options->value.s);
|
|
|
9ae3a8 |
+ error_setg(errp, "Invalid compatibility level: '%s'",
|
|
|
9ae3a8 |
+ options->value.s);
|
|
|
9ae3a8 |
return -EINVAL;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
} else if (!strcmp(options->name, BLOCK_OPT_LAZY_REFCOUNTS)) {
|
|
|
9ae3a8 |
@@ -1519,19 +1557,23 @@ static int qcow2_create(const char *filename, QEMUOptionParameter *options,
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
if (backing_file && prealloc) {
|
|
|
9ae3a8 |
- fprintf(stderr, "Backing file and preallocation cannot be used at "
|
|
|
9ae3a8 |
- "the same time\n");
|
|
|
9ae3a8 |
+ error_setg(errp, "Backing file and preallocation cannot be used at "
|
|
|
9ae3a8 |
+ "the same time");
|
|
|
9ae3a8 |
return -EINVAL;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
if (version < 3 && (flags & BLOCK_FLAG_LAZY_REFCOUNTS)) {
|
|
|
9ae3a8 |
- fprintf(stderr, "Lazy refcounts only supported with compatibility "
|
|
|
9ae3a8 |
- "level 1.1 and above (use compat=1.1 or greater)\n");
|
|
|
9ae3a8 |
+ error_setg(errp, "Lazy refcounts only supported with compatibility "
|
|
|
9ae3a8 |
+ "level 1.1 and above (use compat=1.1 or greater)");
|
|
|
9ae3a8 |
return -EINVAL;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
- return qcow2_create2(filename, sectors, backing_file, backing_fmt, flags,
|
|
|
9ae3a8 |
- cluster_size, prealloc, options, version);
|
|
|
9ae3a8 |
+ ret = qcow2_create2(filename, sectors, backing_file, backing_fmt, flags,
|
|
|
9ae3a8 |
+ cluster_size, prealloc, options, version, &local_err);
|
|
|
9ae3a8 |
+ if (error_is_set(&local_err)) {
|
|
|
9ae3a8 |
+ error_propagate(errp, local_err);
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+ return ret;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
static int qcow2_make_empty(BlockDriverState *bs)
|
|
|
9ae3a8 |
--
|
|
|
9ae3a8 |
1.7.1
|
|
|
9ae3a8 |
|