Error messages for unsupoorted image format features
v2 cover Error messages for unsupoorted image format features
With 0.15 we'll most likely get some incompatible image format extensions. This series prepares 0.14 to output more helpful messages if it stumbles over a too new image file.
Kevin Wolf (4):
qerror: Add QERR_UNKNOWN_BLOCK_FORMAT_FEATURE
qcow2: Report error for version > 2
qed: Report error for unsupported features
qemu-img: Improve error messages for failed bdrv_open
block/qcow2.c | 13 +++++++++++-- block/qed.c | 9 ++++++++- qemu-img.c | 10 +++++++--- qerror.c | 5 +++++ qerror.h | 3 +++ 5 files changed, 34 insertions(+), 6 deletions(-)
Signature · 1 line
1.7.2.3
PATCH v2 1/4 qerror: Add QERR_UNKNOWN_BLOCK_FORMAT_FEATURE
--- qerror.c | 5 +++++ qerror.h | 3 +++ 2 files changed, 8 insertions(+), 0 deletions(-)
qerror.c +5 -0
@@ -201,6 +201,11 @@ static const QErrorStringTable qerror_table[] = { .desc = "An undefined error has ocurred", }, { + .error_fmt = QERR_UNKNOWN_BLOCK_FORMAT_FEATURE, + .desc = "'%(device)' uses a %(format) feature which is not " + "supported by this qemu version: %(feature)", + }, + { .error_fmt = QERR_VNC_SERVER_FAILED, .desc = "Could not start VNC server on %(target)", },
qerror.h +3 -0
@@ -165,6 +165,9 @@ QError *qobject_to_qerror(const QObject *obj);#define QERR_UNDEFINED_ERROR \ "{ 'class': 'UndefinedError', 'data': {} }" +#define QERR_UNKNOWN_BLOCK_FORMAT_FEATURE \ + "{ 'class': 'UnknownBlockFormatFeature', 'data': { 'device': %s, 'format': %s, 'feature': %s } }" +#define QERR_VNC_SERVER_FAILED \ "{ 'class': 'VNCServerFailed', 'data': { 'target': %s } }"
Signature · 1 line
1.7.2.3
PATCH v2 2/4 qcow2: Report error for version > 2
In reply to Kevin WolfThe qcow2 driver is now declared responsible for any QCOW image that has version 2 or greater (before this, version 3 would be detected as raw).
For everything newer than version 2, an error is reported.
--- block/qcow2.c | 13 +++++++++++-- 1 files changed, 11 insertions(+), 2 deletions(-)
block/qcow2.c +11 -2
@@ -28,6 +28,7 @@#include "aes.h" #include "block/qcow2.h" #include "qemu-error.h" +#include "qerror.h" /* Differences with QCOW:
@@ -59,7 +60,7 @@ static int qcow2_probe(const uint8_t *buf, int buf_size, const char *filename)if (buf_size >=sizeof (QCowHeader) &&be32_to_cpu (cow_header->magic) ==QCOW_MAGIC && -be32_to_cpu (cow_header->version) ==QCOW_VERSION ) +be32_to_cpu (cow_header->version) >=QCOW_VERSION )return 100 ;else return 0 ;
@@ -163,10 +164,18 @@ static int qcow2_open(BlockDriverState *bs, int flags)be64_to_cpus (&header.snapshots_offset);be32_to_cpus (&header.nb_snapshots); -if (header.magic !=QCOW_MAGIC || header.version !=QCOW_VERSION ) { +if (header.magic !=QCOW_MAGIC ) { ret = -EINVAL ; goto fail; } +if (header.version !=QCOW_VERSION ) { +char version[64 ]; +snprintf (version,sizeof (version),"QCOW version %d" , header.version); +qerror_report (QERR_UNKNOWN_BLOCK_FORMAT_FEATURE , + bs->device_name,"qcow2" , version); + ret = -ENOTSUP ; + goto fail; + }if (header.cluster_bits <MIN_CLUSTER_BITS || header.cluster_bits >MAX_CLUSTER_BITS ) { ret = -EINVAL ;
Signature · 1 line
1.7.2.3
PATCH v2 3/4 qed: Report error for unsupported features
In reply to Kevin WolfInstead of just returning -ENOTSUP, generate a more detailed error.
Unfortunately we don't have a helpful text for features that we don't know yet, so just print the feature mask. It might be useful at least if someone asks for help.
--- block/qed.c | 9 ++++++++- 1 files changed, 8 insertions(+), 1 deletions(-)
block/qed.c +8 -1
@@ -14,6 +14,7 @@#include "trace.h" #include "qed.h" +#include "qerror.h" static void qed_aio_cancel (BlockDriverAIOCB *blockacb) {
@@ -311,7 +312,13 @@ static int bdrv_qed_open(BlockDriverState *bs, int flags)return -EINVAL ; }if (s->header.features & ~QED_FEATURE_MASK ) { -return -ENOTSUP ;/* image uses unsupported feature bits */ +/* image uses unsupported feature bits */ +char buf[64 ]; +snprintf (buf,sizeof (buf),"%" PRIx64, + s->header.features & ~QED_FEATURE_MASK ); +qerror_report (QERR_UNKNOWN_BLOCK_FORMAT_FEATURE , + bs->device_name,"QED" , buf); +return -ENOTSUP ; }if (!qed_is_cluster_size_valid (s->header.cluster_size)) {return -EINVAL ;
Signature · 1 line
1.7.2.3
PATCH v2 4/4 qemu-img: Improve error messages for failed bdrv_open
In reply to Kevin WolfOutput the error message string of the bdrv_open return code. Also set a non-empty device name for the images because the unknown feature error message includes it.
--- qemu-img.c | 10 +++++++--- 1 files changed, 7 insertions(+), 3 deletions(-)
qemu-img.c +7 -3
@@ -213,8 +213,9 @@ static BlockDriverState *bdrv_new_open(const char *filename,BlockDriverState *bs;BlockDriver *drv;char password[256 ]; +int ret; - bs =bdrv_new ("" ); + bs =bdrv_new ("image" );if (fmt) { drv =bdrv_find_format (fmt);
@@ -225,10 +226,13 @@ static BlockDriverState *bdrv_new_open(const char *filename, }else { drv =NULL ; } -if (bdrv_open (bs, filename, flags, drv) <0 ) { -error_report ("Could not open '%s'" , filename); + + ret =bdrv_open (bs, filename, flags, drv); +if (ret <0 ) { +error_report ("Could not open '%s': %s" , filename,strerror (-ret)); goto fail; } +if (bdrv_is_encrypted (bs)) {printf ("Disk image '%s' is encrypted.\n" , filename);if (read_password (password,sizeof (password)) <0 ) {
Signature · 1 line
1.7.2.3
[Qemu-devel] Re: [PATCH v2 3/4] qed: Report error for unsupported features
In reply to Kevin WolfQuoted 10 lines · Kevin Wolf
Instead of just returning
-ENOTSUP, generate a more detailed error.Unfortunately we don't have a helpful text for features that we don't know yet, so just print the feature mask. It might be useful at least if someone asks for help.
Signed-off-by Kevin Wolf <[email protected]>---
block/qed.c | 9 ++++++++-1 files changed, 8 insertions(+), 1 deletions(-)
Thanks!
Quoted 10 lines · Kevin Wolf
With 0.15 we'll most likely get some incompatible image format extensions. This series prepares 0.14 to output more helpful messages if it stumbles over a too new image file.
Kevin Wolf (4):
qerror: AddQERR_UNKNOWN_BLOCK_FORMAT_FEATURE
qcow2: Report error for version> 2
qed: Report error for unsupported features
qemu-img: Improve error messages for failedbdrv_open
Whole series:
Quoted 8 lines
block/qcow2.c | 13 +++++++++++-- block/qed.c | 9 ++++++++- qemu-img.c | 10 +++++++--- qerror.c | 5 +++++ qerror.h | 3 +++ 5 files changed, 34 insertions(+), 6 deletions(-)