Improve bdrv_open error messages
cover Improve bdrv_open error messages
Most of the block drivers are not using the Error** argument to bdrv_open, and instead just printing errors to stderr. This series improves that, using Error** instead of abusing errno numbers too.
The only hurdle (caught by qemu-iotests, too) is VMDK, where we currently parse a file first as image, and second as a descriptor. This makes it hard to pick a good error message, because you do not know which attempt gave the most reasonable error message. For this reason patches 15-17 modify this approach and push up the detection of vmdk image file magic numbers.
Apart from this, and from a segfault fixed by patch 7, the series consists of mostly trivial patches.
Paolo
Paolo Bonzini (20):
nbd: produce a better error if neither host nor port is passed
nbd: correctly propagate errors
nbd: inline tcp_socket_incoming_spec into sole caller
nbd: move socket wrappers to qemu-nbd
iscsi: fix indentation
iscsi: correctly propagate errors in iscsi_open
gluster: default scheme to gluster:// and host to localhost.
gluster: correctly propagate errors
cow: correctly propagate errors
curl: correctly propagate errors
qcow: correctly propagate errors
qed: correctly propagate errors
vhdx: correctly propagate errors
vvfat: correctly propagate errors
vmdk: extract vmdk_read_desc
vmdk: push vmdk_read_desc up to caller
vmdk: do not try opening a file as both image and descriptor
vmdk: correctly propagate errors
block: do not abuse EMEDIUMTYPE
vdi: say why an image is bad
block/bochs.c | 3 +- block/cow.c | 15 ++--- block/curl.c | 13 ++--- block/gluster.c | 28 ++++----- block/iscsi.c | 141 +++++++++++++++++++++++---------------------- block/nbd.c | 43 +++++++------- block/parallels.c | 3 +- block/qcow.c | 19 +++--- block/qcow2.c | 2 +- block/qed.c | 19 +++--- block/vdi.c | 29 ++++++---- block/vhdx.c | 21 +++---- block/vmdk.c | 121 ++++++++++++++++++++++++-------------- block/vpc.c | 3 +- block/vvfat.c | 9 +-- include/block/nbd.h | 6 -- nbd.c | 66 --------------------- qemu-nbd.c | 52 +++++++++++++++++ tests/qemu-iotests/059.out | 6 +- 19 files changed, 302 insertions(+), 297 deletions(-)
Signature · 1 line
1.8.5.3
PATCH 1/20 nbd: produce a better error if neither host nor port is passed
Before:
$ qemu-io-old
qemu-io-old> open -r -o file.driver=nbd
qemu-io-old: can't open device (null): Could not open image: Invalid argument
$ ./qemu-io-old
qemu-io-old> open -r -o file.driver=nbd,file.host=foo,file.path=bar
path and host may not be used at the same time.
qemu-io-old: can't open device (null): Could not open image: Invalid argumentAfter:
$ ./qemu-io
qemu-io> open -r -o file.driver=nbd
one of path and host must be specified.
qemu-io: can't open device (null): Could not open image: Invalid argument
$ ./qemu-io
qemu-io> open -r -o file.driver=nbd,file.host=foo,file.path=bar
path and host may not be used at the same time.
qemu-io: can't open device (null): Could not open image: Invalid argumentNext patch will fix the error propagation.
--- block/nbd.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-)
block/nbd.c +6 -7
@@ -192,19 +192,18 @@ static int nbd_config(BDRVNBDState *s, QDict *options, char **export) {Error *local_err =NULL ; -if (qdict_haskey (options,"path" )) { -if (qdict_haskey (options,"host" )) { +if (qdict_haskey (options,"path" ) ==qdict_haskey (options,"host" )) { +if (qdict_haskey (options,"path" )) {qerror_report (ERROR_CLASS_GENERIC_ERROR ,"path and host may not " "be used at the same time." ); -return -EINVAL ; + }else { +qerror_report (ERROR_CLASS_GENERIC_ERROR ,"one of path and host " +"must be specified." ); } - s->client.is_unix = true; - }else if (qdict_haskey (options,"host" )) { - s->client.is_unix = false; - }else {return -EINVAL ; } + s->client.is_unix =qdict_haskey (options,"path" ); s->socket_opts =qemu_opts_create (&socket_optslist,NULL ,0 , &error_abort);
Signature · 1 line
1.8.5.3
Re: [Qemu-devel] [PATCH 01/20] nbd: produce a better error if neither host nor port is passed
Quoted 61 lines · Paolo Bonzini
Before:
$ qemu-io-old qemu-io-old> open -r -o file.driver=nbd qemu-io-old: can't open device (null): Could not open image: Invalid argument $ ./qemu-io-old qemu-io-old> open -r -o file.driver=nbd,file.host=foo,file.path=bar path and host may not be used at the same time. qemu-io-old: can't open device (null): Could not open image: Invalid argumentAfter:
$ ./qemu-io qemu-io> open -r -o file.driver=nbd one of path and host must be specified. qemu-io: can't open device (null): Could not open image: Invalid argument $ ./qemu-io qemu-io> open -r -o file.driver=nbd,file.host=foo,file.path=bar path and host may not be used at the same time. qemu-io: can't open device (null): Could not open image: Invalid argumentNext patch will fix the error propagation.
Signed-off-by Paolo Bonzini <[email protected]>--- block/nbd.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-)block/nbd.c +6
-7@@ -192,19 +192,18 @@ static int nbd_config(BDRVNBDState *s, QDict *options, char **export) {Error *local_err =NULL ; -if (qdict_haskey (options,"path" )) { -if (qdict_haskey (options,"host" )) { +if (qdict_haskey (options,"path" ) ==qdict_haskey (options,"host" )) { +if (qdict_haskey (options,"path" )) {qerror_report (ERROR_CLASS_GENERIC_ERROR ,"path and host may not " "be used at the same time." ); -return -EINVAL ; + }else { +qerror_report (ERROR_CLASS_GENERIC_ERROR ,"one of path and host " +"must be specified." ); } - s->client.is_unix = true; - }else if (qdict_haskey (options,"host" )) { - s->client.is_unix = false; - }else {return -EINVAL ; } + s->client.is_unix =qdict_haskey (options,"path" ); s->socket_opts =qemu_opts_create (&socket_optslist,NULL ,0 , &error_abort);Signature · 1 line
1.8.5.3
PATCH 2/20 nbd: correctly propagate errors
In reply to Paolo BonziniBefore:
$ ./qemu-io-old
qemu-io-old> open -r -o file.driver=nbd
one of path and host must be specified.
qemu-io-old: can't open device (null): Could not open image: Invalid argument
$ ./qemu-io-old
qemu-io-old> open -r -o file.driver=nbd,file.host=foo,file.path=bar
path and host may not be used at the same time.
qemu-io-old: can't open device (null): Could not open image: Invalid argumentAfter:
$ ./qemu-io
qemu-io> open -r -o file.driver=nbd
qemu-io: can't open device (null): one of path and host must be specified.
$ ./qemu-io
qemu-io> open -r -o file.driver=nbd,file.host=foo,file.path=bar
qemu-io: can't open device (null): path and host may not be used at the same time.--- block/nbd.c | 34 ++++++++++++++++------------------ include/block/nbd.h | 1 - nbd.c | 12 ------------ 3 files changed, 16 insertions(+), 31 deletions(-)
block/nbd.c +16 -18
@@ -188,19 +188,18 @@ out:g_free (file); } -static int nbd_config (BDRVNBDState *s,QDict *options,char **export) +static void nbd_config (BDRVNBDState *s,QDict *options,char **export, +Error **errp) {Error *local_err =NULL ;if (qdict_haskey (options,"path" ) ==qdict_haskey (options,"host" )) {if (qdict_haskey (options,"path" )) { -qerror_report (ERROR_CLASS_GENERIC_ERROR ,"path and host may not " -"be used at the same time." ); +error_setg (errp,"path and host may not be used at the same time." ); }else { -qerror_report (ERROR_CLASS_GENERIC_ERROR ,"one of path and host " -"must be specified." ); +error_setg (errp,"one of path and host must be specified." ); } -return -EINVAL ; +return ; } s->client.is_unix =qdict_haskey (options,"path" );
@@ -209,9 +208,8 @@ static int nbd_config(BDRVNBDState *s, QDict *options, char **export)qemu_opts_absorb_qdict (s->socket_opts, options, &local_err);if (error_is_set (&local_err)) { -qerror_report_err (local_err); -error_free (local_err); -return -EINVAL ; +error_propagate (errp, local_err); +return ; }if (!qemu_opt_get (s->socket_opts,"port" )) {
@@ -222,19 +220,17 @@ static int nbd_config(BDRVNBDState *s, QDict *options, char **export)if (*export) {qdict_del (options,"export" ); } - -return 0 ; } -static int nbd_establish_connection (BlockDriverState *bs) +static int nbd_establish_connection (BlockDriverState *bs,Error **errp) {BDRVNBDState *s = bs->opaque;int sock;if (s->client.is_unix) { - sock =unix_socket_outgoing (qemu_opt_get (s->socket_opts,"path" )); + sock =unix_connect (qemu_opt_get (s->socket_opts,"path" ), errp); }else { - sock =tcp_socket_outgoing_opts (s->socket_opts); + sock =inet_connect_opts (s->socket_opts, errp,NULL ,NULL );if (sock >=0 ) {socket_set_nodelay (sock); }
@@ -255,17 +251,19 @@ static int nbd_open(BlockDriverState *bs, QDict *options, int flags,BDRVNBDState *s = bs->opaque;char *export =NULL ;int result, sock; +Error *local_err =NULL ;/* Pop the config into our state object. Exit if invalid. */ - result =nbd_config (s, options, &export); -if (result !=0 ) { -return result; +nbd_config (s, options, &export, &local_err); +if (local_err) { +error_propagate (errp, local_err); +return -EINVAL ; }/* establish TCP connection, return error if it fails * TODO: Configurable retry-until-timeout behaviour. */ - sock =nbd_establish_connection (bs); + sock =nbd_establish_connection (bs, errp);if (sock <0 ) {return sock; }
include/block/nbd.h +0 -1
@@ -64,7 +64,6 @@ enum {ssize_t nbd_wr_sync (int fd,void *buffer,size_t size,bool do_read);int tcp_socket_incoming (const char *address,uint16_t port);int tcp_socket_incoming_spec (const char *address_and_port); -int tcp_socket_outgoing_opts (QemuOpts *opts);int unix_socket_outgoing (const char *path);int unix_socket_incoming (const char *path);
nbd.c +0 -12
@@ -199,18 +199,6 @@ static void combine_addr(char *buf, size_t len, const char* address, } } -int tcp_socket_outgoing_opts (QemuOpts *opts) -{ -Error *local_err =NULL ; -int fd =inet_connect_opts (opts, &local_err,NULL ,NULL ); -if (local_err !=NULL ) { -qerror_report_err (local_err); -error_free (local_err); - } - -return fd; -} -int tcp_socket_incoming (const char *address,uint16_t port) {char address_and_port[128 ];
Signature · 1 line
1.8.5.3
Re: [Qemu-devel] [PATCH 02/20] nbd: correctly propagate errors
Quoted 73 lines · Paolo Bonzini
Before:
$ ./qemu-io-old qemu-io-old> open -r -o file.driver=nbd one of path and host must be specified. qemu-io-old: can't open device (null): Could not open image: Invalid argument $ ./qemu-io-old qemu-io-old> open -r -o file.driver=nbd,file.host=foo,file.path=bar path and host may not be used at the same time. qemu-io-old: can't open device (null): Could not open image: Invalid argumentAfter:
$ ./qemu-io qemu-io> open -r -o file.driver=nbd qemu-io: can't open device (null): one of path and host must be specified. $ ./qemu-io qemu-io> open -r -o file.driver=nbd,file.host=foo,file.path=bar qemu-io: can't open device (null): path and host may not be used at the same time.Signed-off-by Paolo Bonzini <[email protected]>--- block/nbd.c | 34 ++++++++++++++++------------------ include/block/nbd.h | 1 - nbd.c | 12 ------------ 3 files changed, 16 insertions(+), 31 deletions(-)block/nbd.c +7
-11@@ -188,19 +188,18 @@ out:g_free (file); } -static int nbd_config (BDRVNBDState *s,QDict *options,char **export) +static void nbd_config (BDRVNBDState *s,QDict *options,char **export, +Error **errp) {Error *local_err =NULL ;if (qdict_haskey (options,"path" ) ==qdict_haskey (options,"host" )) {if (qdict_haskey (options,"path" )) { -qerror_report (ERROR_CLASS_GENERIC_ERROR ,"path and host may not " -"be used at the same time." ); +error_setg (errp,"path and host may not be used at the same time." ); }else { -qerror_report (ERROR_CLASS_GENERIC_ERROR ,"one of path and host " -"must be specified." ); +error_setg (errp,"one of path and host must be specified." ); } -return -EINVAL ; +return ; } s->client.is_unix =qdict_haskey (options,"path" );@@ -209,9 +208,8 @@ static int nbd_config(BDRVNBDState *s, QDict *options, char **export)qemu_opts_absorb_qdict (s->socket_opts, options, &local_err);if (error_is_set (&local_err)) { -qerror_report_err (local_err); -error_free (local_err); -return -EINVAL ; +error_propagate (errp, local_err); +return ; }if (!qemu_opt_get (s->socket_opts,"port" )) {@@ -222,19 +220,17 @@ static int nbd_config(BDRVNBDState *s, QDict *options, char **export)if (*export) {qdict_del (options,"export" ); } - -return 0 ; }
block/nbd.c static int nbd_config(BDRVNBDState *s, QDict *options, char **export) · line 231
Quoted 10 lines
block/nbd.c +2
-2-static int nbd_establish_connection (BlockDriverState *bs) +static int nbd_establish_connection (BlockDriverState *bs,Error **errp) {BDRVNBDState *s = bs->opaque;int sock;if (s->client.is_unix) { - sock =unix_socket_outgoing (qemu_opt_get (s->socket_opts,"path" )); + sock =unix_connect (qemu_opt_get (s->socket_opts,"path" ), errp);
Why not use unix_connect_opts like below?
Quoted 8 lines
block/nbd.c +1
-1}else { - sock =tcp_socket_outgoing_opts (s->socket_opts); + sock =inet_connect_opts (s->socket_opts, errp,NULL ,NULL );if (sock >=0 ) {socket_set_nodelay (sock); }@@ -255,17 +251,19 @@ static int nbd_open(BlockDriverState *bs, QDict *options, int flags,BDRVNBDState *s = bs->opaque;
block/nbd.c static int nbd_open(BlockDriverState *bs, QDict *options, int flags, · line 258
Quoted 10 lines
block/nbd.c +3
-3char *export =NULL ;int result, sock; +Error *local_err =NULL ;/* Pop the config into our state object. Exit if invalid. */ - result =nbd_config (s, options, &export); -if (result !=0 ) { -return result; +nbd_config (s, options, &export, &local_err); +if (local_err) {
Isn't error_is_set() better here?
block/nbd.c static int nbd_open(BlockDriverState *bs, QDict *options, int flags, · line 269
Quoted 12 lines
block/nbd.c +3
-1+error_propagate (errp, local_err); +return -EINVAL ; }/* establish TCP connection, return error if it fails * TODO: Configurable retry-until-timeout behaviour. */ - sock =nbd_establish_connection (bs); + sock =nbd_establish_connection (bs, errp);if (sock <0 ) {return sock; }
Thanks,
Fam
Re: [Qemu-devel] [PATCH 02/20] nbd: correctly propagate errors
Il 10/02/2014 08:38, Fam Zheng ha scritto:
Quoted 4 lines
Quoted 3 lines
block/nbd.c static int nbd_config(BDRVNBDState *s, QDict *options, char **export) · line 231
Quoted 3 lines
if (s->client.is_unix) {block/nbd.c +1
-1- sock =unix_socket_outgoing (qemu_opt_get (s->socket_opts,"path" )); + sock =unix_connect (qemu_opt_get (s->socket_opts,"path" ), errp);Why not use
unix_connect_optslike below?
Right!
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
} else {block/nbd.c +2
-1- sock =tcp_socket_outgoing_opts (s->socket_opts); + sock =inet_connect_opts (s->socket_opts, errp,NULL ,NULL );if (sock >=0 ) {socket_set_nodelay (sock); }@@ -255,17 +251,19 @@ static int nbd_open(BlockDriverState *bs, QDict *options, int flags,BDRVNBDState *s = bs->opaque;char *export =NULL ;int result, sock; +Error *local_err =NULL ;
Quoted 7 lines
Quoted 6 lines
block/nbd.c static int nbd_open(BlockDriverState *bs, QDict *options, int flags, · line 258
Quoted 6 lines
block/nbd.c +2
-3/* Pop the config into our state object. Exit if invalid. */ - result =nbd_config (s, options, &export); -if (result !=0 ) { -return result; +nbd_config (s, options, &export, &local_err); +if (local_err) {Isn't
error_is_set()better here?
No, error_is_set(&foo) is the same as foo != NULL.
So we use error_is_set only with Error**, which really should never happen because you miss errors if the errp is NULL. :)
Paolo
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
block/nbd.c +2
-0+error_propagate (errp, local_err); +return -EINVAL ; }
Re: [Qemu-devel] [PATCH 02/20] nbd: correctly propagate errors
Quoted 28 lines · Paolo Bonzini
Il 10/02/2014 08:38, Fam Zheng ha scritto:
Quoted 4 lines
Quoted 3 lines
block/nbd.c static int nbd_config(BDRVNBDState *s, QDict *options, char **export) · line 231
Quoted 3 lines
if (s->client.is_unix) {block/nbd.c +1
-1- sock =unix_socket_outgoing (qemu_opt_get (s->socket_opts,"path" )); + sock =unix_connect (qemu_opt_get (s->socket_opts,"path" ), errp);Why not use
unix_connect_optslike below?Right!
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
} else {block/nbd.c +2
-1- sock =tcp_socket_outgoing_opts (s->socket_opts); + sock =inet_connect_opts (s->socket_opts, errp,NULL ,NULL );if (sock >=0 ) {socket_set_nodelay (sock); }@@ -255,17 +251,19 @@ static int nbd_open(BlockDriverState *bs, QDict *options, int flags,BDRVNBDState *s = bs->opaque;char *export =NULL ;int result, sock; +Error *local_err =NULL ;Quoted 7 lines
Quoted 6 lines
block/nbd.c static int nbd_open(BlockDriverState *bs, QDict *options, int flags, · line 258
Quoted 6 lines
block/nbd.c +2
-3/* Pop the config into our state object. Exit if invalid. */ - result =nbd_config (s, options, &export); -if (result !=0 ) { -return result; +nbd_config (s, options, &export, &local_err); +if (local_err) {Isn't
error_is_set()better here?
Quoted 5 lines
No,
error_is_set(&foo)is the same as foo != NULL.So we use
error_is_setonly with Error**, which really should never happen because you miss errors if the errp is NULL. :)
Clear! Thanks for the explanation!
Fam
PATCH 3/20 nbd: inline tcp_socket_incoming_spec into sole caller
In reply to Paolo Bonzini--- include/block/nbd.h | 1 - nbd.c | 8 ++------ 2 files changed, 2 insertions(+), 7 deletions(-)
include/block/nbd.h +0 -1
@@ -63,7 +63,6 @@ enum {ssize_t nbd_wr_sync (int fd,void *buffer,size_t size,bool do_read);int tcp_socket_incoming (const char *address,uint16_t port); -int tcp_socket_incoming_spec (const char *address_and_port);int unix_socket_outgoing (const char *path);int unix_socket_incoming (const char *path);
nbd.c +2 -6
@@ -202,13 +202,9 @@ static void combine_addr(char *buf, size_t len, const char* address,int tcp_socket_incoming (const char *address,uint16_t port) {char address_and_port[128 ]; -combine_addr (address_and_port,128 , address, port); -return tcp_socket_incoming_spec (address_and_port); -} - -int tcp_socket_incoming_spec (const char *address_and_port) -{Error *local_err =NULL ; + +combine_addr (address_and_port,128 , address, port);int fd =inet_listen (address_and_port,NULL ,0 ,SOCK_STREAM ,0 , &local_err);if (local_err !=NULL ) {
Signature · 1 line
1.8.5.3
Re: [Qemu-devel] [PATCH 03/20] nbd: inline tcp_socket_incoming_spec into sole caller
Quoted 41 lines · Paolo Bonzini
Signed-off-by Paolo Bonzini <[email protected]>--- include/block/nbd.h | 1 - nbd.c | 8 ++------ 2 files changed, 2 insertions(+), 7 deletions(-)include/block/nbd.h +0
-1@@ -63,7 +63,6 @@ enum {ssize_t nbd_wr_sync (int fd,void *buffer,size_t size,bool do_read);int tcp_socket_incoming (const char *address,uint16_t port); -int tcp_socket_incoming_spec (const char *address_and_port);int unix_socket_outgoing (const char *path);int unix_socket_incoming (const char *path);nbd.c +2
-6@@ -202,13 +202,9 @@ static void combine_addr(char *buf, size_t len, const char* address,int tcp_socket_incoming (const char *address,uint16_t port) {char address_and_port[128 ]; -combine_addr (address_and_port,128 , address, port); -return tcp_socket_incoming_spec (address_and_port); -} - -int tcp_socket_incoming_spec (const char *address_and_port) -{Error *local_err =NULL ; + +combine_addr (address_and_port,128 , address, port);int fd =inet_listen (address_and_port,NULL ,0 ,SOCK_STREAM ,0 , &local_err);if (local_err !=NULL ) {Signature · 1 line
1.8.5.3
PATCH 4/20 nbd: move socket wrappers to qemu-nbd
In reply to Paolo Bonziniqemu-nbd is one of the few valid users of qerror_report_err. Move the error-reporting socket wrappers there.
--- include/block/nbd.h | 4 ---- nbd.c | 50 -------------------------------------------------- qemu-nbd.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+), 54 deletions(-)
include/block/nbd.h +0 -4
@@ -62,10 +62,6 @@ enum {#define NBD_MAX_BUFFER_SIZE (32 * 1024 * 1024)ssize_t nbd_wr_sync (int fd,void *buffer,size_t size,bool do_read); -int tcp_socket_incoming (const char *address,uint16_t port); -int unix_socket_outgoing (const char *path); -int unix_socket_incoming (const char *path); -int nbd_receive_negotiate (int csock,const char *name,uint32_t *flags,off_t *size,size_t *blocksize);int nbd_init (int fd,int csock,uint32_t flags,off_t size,size_t blocksize);
nbd.c +0 -50
56 lines not on this page · raw message
qemu-nbd.c +52 -0
64 lines not on this page · raw message
Signature · 1 line
1.8.5.3
Re: [Qemu-devel] [PATCH 04/20] nbd: move socket wrappers to qemu-nbd
Quoted 161 lines · Paolo Bonzini
qemu-nbd is one of the few valid users of
qerror_report_err. Move the error-reporting socket wrappers there.Signed-off-by Paolo Bonzini <[email protected]>--- include/block/nbd.h | 4 ---- nbd.c | 50 -------------------------------------------------- qemu-nbd.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+), 54 deletions(-)include/block/nbd.h +0
-4@@ -62,10 +62,6 @@ enum {#define NBD_MAX_BUFFER_SIZE (32 * 1024 * 1024)ssize_t nbd_wr_sync (int fd,void *buffer,size_t size,bool do_read); -int tcp_socket_incoming (const char *address,uint16_t port); -int unix_socket_outgoing (const char *path); -int unix_socket_incoming (const char *path); -int nbd_receive_negotiate (int csock,const char *name,uint32_t *flags,off_t *size,size_t *blocksize);int nbd_init (int fd,int csock,uint32_t flags,off_t size,size_t blocksize);nbd.c +0
-50@@ -188,56 +188,6 @@ static ssize_t write_sync(int fd, void *buffer, size_t size)return ret; } -static void combine_addr (char *buf,size_t len,const char * address, -uint16_t port) -{ -/* If the address-part contains a colon, it's an IPv6 IP so needs [] */ -if (strstr (address,":" )) { -snprintf (buf, len,"[%s]:%u" , address, port); - }else { -snprintf (buf, len,"%s:%u" , address, port); - } -} - -int tcp_socket_incoming (const char *address,uint16_t port) -{ -char address_and_port[128 ]; -Error *local_err =NULL ; - -combine_addr (address_and_port,128 , address, port); -int fd =inet_listen (address_and_port,NULL ,0 ,SOCK_STREAM ,0 , &local_err); - -if (local_err !=NULL ) { -qerror_report_err (local_err); -error_free (local_err); - } -return fd; -} - -int unix_socket_incoming (const char *path) -{ -Error *local_err =NULL ; -int fd =unix_listen (path,NULL ,0 , &local_err); - -if (local_err !=NULL ) { -qerror_report_err (local_err); -error_free (local_err); - } -return fd; -} - -int unix_socket_outgoing (const char *path) -{ -Error *local_err =NULL ; -int fd =unix_connect (path, &local_err); - -if (local_err !=NULL ) { -qerror_report_err (local_err); -error_free (local_err); - } -return fd; -} -/* Basic flow for negotiation Server Client qemu-nbd.c +52
-0@@ -20,6 +20,8 @@#include "block/block.h" #include "block/nbd.h" #include "qemu/main-loop.h" +#include "qemu/sockets.h" +#include "qemu/error-report.h" #include "block/snapshot.h" #include <stdarg.h> @@ -201,6 +203,56 @@ static void termsig_handler(int signum)qemu_notify_event (); } +static void combine_addr (char *buf,size_t len,const char * address, +uint16_t port) +{ +/* If the address-part contains a colon, it's an IPv6 IP so needs [] */ +if (strstr (address,":" )) { +snprintf (buf, len,"[%s]:%u" , address, port); + }else { +snprintf (buf, len,"%s:%u" , address, port); + } +} + +static int tcp_socket_incoming (const char *address,uint16_t port) +{ +char address_and_port[128 ]; +Error *local_err =NULL ; + +combine_addr (address_and_port,128 , address, port); +int fd =inet_listen (address_and_port,NULL ,0 ,SOCK_STREAM ,0 , &local_err); + +if (local_err !=NULL ) { +qerror_report_err (local_err); +error_free (local_err); + } +return fd; +} + +static int unix_socket_incoming (const char *path) +{ +Error *local_err =NULL ; +int fd =unix_listen (path,NULL ,0 , &local_err); + +if (local_err !=NULL ) { +qerror_report_err (local_err); +error_free (local_err); + } +return fd; +} + +static int unix_socket_outgoing (const char *path) +{ +Error *local_err =NULL ; +int fd =unix_connect (path, &local_err); + +if (local_err !=NULL ) { +qerror_report_err (local_err); +error_free (local_err); + } +return fd; +} +static void *show_parts (void *arg) {char *device = arg;Signature · 1 line
1.8.5.3
PATCH 5/20 iscsi: fix indentation
In reply to Paolo Bonzini--- block/iscsi.c | 45 +++++++++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 22 deletions(-)
block/iscsi.c +23 -22
@@ -1065,35 +1065,36 @@ static QemuOptsList runtime_opts = { }, }; -static struct scsi_task *iscsi_do_inquiry (struct iscsi_context *iscsi, -int lun,int evpd,int pc) { -int full_size; -struct scsi_task *task =NULL ; - task =iscsi_inquiry_sync (iscsi, lun, evpd, pc,64 ); +static struct scsi_task *iscsi_do_inquiry (struct iscsi_context *iscsi,int lun, +int evpd,int pc) +{ +int full_size; +struct scsi_task *task =NULL ; + task =iscsi_inquiry_sync (iscsi, lun, evpd, pc,64 ); +if (task ==NULL || task->status !=SCSI_STATUS_GOOD ) { + goto fail; + } + full_size =scsi_datain_getfullsize (task); +if (full_size > task->datain.size) { +scsi_free_scsi_task (task); + +/* we need more data for the full list */ + task =iscsi_inquiry_sync (iscsi, lun, evpd, pc, full_size);if (task ==NULL || task->status !=SCSI_STATUS_GOOD ) { goto fail; } - full_size =scsi_datain_getfullsize (task); -if (full_size > task->datain.size) { -scsi_free_scsi_task (task); - -/* we need more data for the full list */ - task =iscsi_inquiry_sync (iscsi, lun, evpd, pc, full_size); -if (task ==NULL || task->status !=SCSI_STATUS_GOOD ) { - goto fail; - } - } + } -return task; +return task; fail: -error_report ("iSCSI: Inquiry command failed : %s" , -iscsi_get_error (iscsi)); -if (task) { -scsi_free_scsi_task (task); -return NULL ; - } +error_report ("iSCSI: Inquiry command failed : %s" , +iscsi_get_error (iscsi)); +if (task) { +scsi_free_scsi_task (task);return NULL ; + } +return NULL ; }/*
Signature · 1 line
1.8.5.3
Re: [Qemu-devel] [PATCH 05/20] iscsi: fix indentation
Quoted 71 lines · Paolo Bonzini
Signed-off-by Paolo Bonzini <[email protected]>--- block/iscsi.c | 45 +++++++++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 22 deletions(-)block/iscsi.c +23
-22@@ -1065,35 +1065,36 @@ static QemuOptsList runtime_opts = { }, }; -static struct scsi_task *iscsi_do_inquiry (struct iscsi_context *iscsi, -int lun,int evpd,int pc) { -int full_size; -struct scsi_task *task =NULL ; - task =iscsi_inquiry_sync (iscsi, lun, evpd, pc,64 ); +static struct scsi_task *iscsi_do_inquiry (struct iscsi_context *iscsi,int lun, +int evpd,int pc) +{ +int full_size; +struct scsi_task *task =NULL ; + task =iscsi_inquiry_sync (iscsi, lun, evpd, pc,64 ); +if (task ==NULL || task->status !=SCSI_STATUS_GOOD ) { + goto fail; + } + full_size =scsi_datain_getfullsize (task); +if (full_size > task->datain.size) { +scsi_free_scsi_task (task); + +/* we need more data for the full list */ + task =iscsi_inquiry_sync (iscsi, lun, evpd, pc, full_size);if (task ==NULL || task->status !=SCSI_STATUS_GOOD ) { goto fail; } - full_size =scsi_datain_getfullsize (task); -if (full_size > task->datain.size) { -scsi_free_scsi_task (task); - -/* we need more data for the full list */ - task =iscsi_inquiry_sync (iscsi, lun, evpd, pc, full_size); -if (task ==NULL || task->status !=SCSI_STATUS_GOOD ) { - goto fail; - } - } + } -return task; +return task; fail: -error_report ("iSCSI: Inquiry command failed : %s" , -iscsi_get_error (iscsi)); -if (task) { -scsi_free_scsi_task (task); -return NULL ; - } +error_report ("iSCSI: Inquiry command failed : %s" , +iscsi_get_error (iscsi)); +if (task) { +scsi_free_scsi_task (task);return NULL ; + } +return NULL ; }/* Signature · 1 line
1.8.5.3
PATCH 6/20 iscsi: correctly propagate errors in iscsi_open
In reply to Paolo BonziniBefore:
$ ./qemu-io-old
qemu-io-old> open -r -o file.driver=iscsi,file.filename=foo
Failed to parse URL : foo
qemu-io-old: can't open device (null): Could not open 'foo': Invalid argumentAfter:
$ ./qemu-io
qemu-io> open -r -o file.driver=iscsi,file.filename=foo
qemu-io: can't open device (null): Failed to parse URL : foo--- block/iscsi.c | 102 ++++++++++++++++++++++++++++++---------------------------- 1 file changed, 52 insertions(+), 50 deletions(-)
block/iscsi.c +52 -50
@@ -856,7 +856,8 @@ retry:#endif /* SCSI_SENSE_ASCQ_CAPACITY_DATA_HAS_CHANGED */ -static int parse_chap (struct iscsi_context *iscsi,const char *target) +static void parse_chap (struct iscsi_context *iscsi,const char *target, +Error **errp) {QemuOptsList *list;QemuOpts *opts;
@@ -865,37 +866,35 @@ static int parse_chap(struct iscsi_context *iscsi, const char *target) list =qemu_find_opts ("iscsi" );if (!list) { -return 0 ; +return ; } opts =qemu_opts_find (list, target);if (opts ==NULL ) { opts =QTAILQ_FIRST (&list->head);if (!opts) { -return 0 ; +return ; } } user =qemu_opt_get (opts,"user" );if (!user) { -return 0 ; +return ; } password =qemu_opt_get (opts,"password" );if (!password) { -error_report ("CHAP username specified but no password was given" ); -return -1 ; +error_setg (errp,"CHAP username specified but no password was given" ); +return ; }if (iscsi_set_initiator_username_pwd (iscsi, user, password)) { -error_report ("Failed to set initiator username and password" ); -return -1 ; +error_setg (errp,"Failed to set initiator username and password" ); } - -return 0 ; } -static void parse_header_digest (struct iscsi_context *iscsi,const char *target) +static void parse_header_digest (struct iscsi_context *iscsi,const char *target, +Error **errp) {QemuOptsList *list;QemuOpts *opts;
@@ -928,7 +927,7 @@ static void parse_header_digest(struct iscsi_context *iscsi, const char *target) }else if (!strcmp (digest,"NONE-CRC32C" )) {iscsi_set_header_digest (iscsi,ISCSI_HEADER_DIGEST_NONE_CRC32C ); }else { -error_report ("Invalid header-digest setting : %s" , digest); +error_setg (errp,"Invalid header-digest setting : %s" , digest); } }
@@ -986,12 +985,11 @@ static void iscsi_nop_timed_event(void *opaque) }#endif -static int iscsi_readcapacity_sync (IscsiLun *iscsilun) +static void iscsi_readcapacity_sync (IscsiLun *iscsilun,Error **errp) {struct scsi_task *task =NULL ;struct scsi_readcapacity10 *rc10 =NULL ;struct scsi_readcapacity16 *rc16 =NULL ; -int ret =0 ;int retries =ISCSI_CMD_RETRIES ; do {
@@ -1006,8 +1004,7 @@ static int iscsi_readcapacity_sync(IscsiLun *iscsilun)if (task !=NULL && task->status ==SCSI_STATUS_GOOD ) { rc16 =scsi_datain_unmarshall (task);if (rc16 ==NULL ) { -error_report ("iSCSI: Failed to unmarshall readcapacity16 data." ); - ret = -EINVAL ; +error_setg (errp,"iSCSI: Failed to unmarshall readcapacity16 data." ); }else { iscsilun->block_size = rc16->block_length; iscsilun->num_blocks = rc16->returned_lba +1 ;
@@ -1021,8 +1018,7 @@ static int iscsi_readcapacity_sync(IscsiLun *iscsilun)if (task !=NULL && task->status ==SCSI_STATUS_GOOD ) { rc10 =scsi_datain_unmarshall (task);if (rc10 ==NULL ) { -error_report ("iSCSI: Failed to unmarshall readcapacity10 data." ); - ret = -EINVAL ; +error_setg (errp,"iSCSI: Failed to unmarshall readcapacity10 data." ); }else { iscsilun->block_size = rc10->block_size;if (rc10->lba ==0 ) {
@@ -1035,20 +1031,18 @@ static int iscsi_readcapacity_sync(IscsiLun *iscsilun) }break ;default : -return 0 ; +return ; } }while (task !=NULL && task->status ==SCSI_STATUS_CHECK_CONDITION && task->sense.key ==SCSI_SENSE_UNIT_ATTENTION && retries-- >0 );if (task ==NULL || task->status !=SCSI_STATUS_GOOD ) { -error_report ("iSCSI: failed to send readcapacity10 command." ); - ret = -EINVAL ; +error_setg (errp,"iSCSI: failed to send readcapacity10 command." ); }if (task) {scsi_free_scsi_task (task); } -return ret; }/* TODO Convert to fine grained options */
@@ -1066,7 +1060,7 @@ static QemuOptsList runtime_opts = { };static struct scsi_task *iscsi_do_inquiry (struct iscsi_context *iscsi,int lun, -int evpd,int pc) +int evpd,int pc,Error **errp) {int full_size;struct scsi_task *task =NULL ;
@@ -1088,8 +1082,8 @@ static struct scsi_task *iscsi_do_inquiry(struct iscsi_context *iscsi, int lun,return task; fail: -error_report ("iSCSI: Inquiry command failed : %s" , -iscsi_get_error (iscsi)); +error_setg (errp,"iSCSI: Inquiry command failed : %s" , +iscsi_get_error (iscsi));if (task) {scsi_free_scsi_task (task);return NULL ;
@@ -1116,27 +1110,25 @@ static int iscsi_open(BlockDriverState *bs, QDict *options, int flags,int ret;if ((BDRV_SECTOR_SIZE %512 ) !=0 ) { -error_report ("iSCSI: Invalid BDRV_SECTOR_SIZE. " -"BDRV_SECTOR_SIZE(%lld) is not a multiple " -"of 512" ,BDRV_SECTOR_SIZE ); +error_setg (errp,"iSCSI: Invalid BDRV_SECTOR_SIZE. " +"BDRV_SECTOR_SIZE(%lld) is not a multiple " +"of 512" ,BDRV_SECTOR_SIZE );return -EINVAL ; } opts =qemu_opts_create (&runtime_opts,NULL ,0 , &error_abort);qemu_opts_absorb_qdict (opts, options, &local_err);if (error_is_set (&local_err)) { -qerror_report_err (local_err); -error_free (local_err); +error_propagate (errp, local_err); ret = -EINVAL ; goto out; } filename =qemu_opt_get (opts,"filename" ); - iscsi_url =iscsi_parse_full_url (iscsi, filename);if (iscsi_url ==NULL ) { -error_report ("Failed to parse URL : %s" , filename); +error_setg (errp,"Failed to parse URL : %s" , filename); ret = -EINVAL ; goto out; }
@@ -1147,13 +1139,13 @@ static int iscsi_open(BlockDriverState *bs, QDict *options, int flags, iscsi =iscsi_create_context (initiator_name);if (iscsi ==NULL ) { -error_report ("iSCSI: Failed to create iSCSI context." ); +error_setg (errp,"iSCSI: Failed to create iSCSI context." ); ret = -ENOMEM ; goto out; }if (iscsi_set_targetname (iscsi, iscsi_url->target)) { -error_report ("iSCSI: Failed to set target name." ); +error_setg (errp,"iSCSI: Failed to set target name." ); ret = -EINVAL ; goto out; }
@@ -1162,21 +1154,22 @@ static int iscsi_open(BlockDriverState *bs, QDict *options, int flags, ret =iscsi_set_initiator_username_pwd (iscsi, iscsi_url->user, iscsi_url->passwd);if (ret !=0 ) { -error_report ("Failed to set initiator username and password" ); +error_setg (errp,"Failed to set initiator username and password" ); ret = -EINVAL ; goto out; } }/* check if we got CHAP username/password via the options */ -if (parse_chap (iscsi, iscsi_url->target) !=0 ) { -error_report ("iSCSI: Failed to set CHAP user/password" ); +parse_chap (iscsi, iscsi_url->target, &local_err); +if (local_err !=NULL ) { +error_propagate (errp, local_err); ret = -EINVAL ; goto out; }if (iscsi_set_session_type (iscsi,ISCSI_SESSION_NORMAL ) !=0 ) { -error_report ("iSCSI: Failed to set session type to normal." ); +error_setg (errp,"iSCSI: Failed to set session type to normal." ); ret = -EINVAL ; goto out; }
@@ -1184,10 +1177,15 @@ static int iscsi_open(BlockDriverState *bs, QDict *options, int flags,iscsi_set_header_digest (iscsi,ISCSI_HEADER_DIGEST_NONE_CRC32C );/* check if we got HEADER_DIGEST via the options */ -parse_header_digest (iscsi, iscsi_url->target); +parse_header_digest (iscsi, iscsi_url->target, &local_err); +if (local_err !=NULL ) { +error_propagate (errp, local_err); + ret = -EINVAL ; + goto out; + }if (iscsi_full_connect_sync (iscsi, iscsi_url->portal, iscsi_url->lun) !=0 ) { -error_report ("iSCSI: Failed to connect to LUN : %s" , +error_setg (errp,"iSCSI: Failed to connect to LUN : %s" ,iscsi_get_error (iscsi)); ret = -EINVAL ; goto out;
@@ -1199,14 +1197,14 @@ static int iscsi_open(BlockDriverState *bs, QDict *options, int flags, task =iscsi_inquiry_sync (iscsi, iscsilun->lun,0 ,0 ,36 );if (task ==NULL || task->status !=SCSI_STATUS_GOOD ) { -error_report ("iSCSI: failed to send inquiry command." ); +error_setg (errp,"iSCSI: failed to send inquiry command." ); ret = -EINVAL ; goto out; } inq =scsi_datain_unmarshall (task);if (inq ==NULL ) { -error_report ("iSCSI: Failed to unmarshall inquiry data." ); +error_setg (errp,"iSCSI: Failed to unmarshall inquiry data." ); ret = -EINVAL ; goto out; }
@@ -1214,7 +1212,9 @@ static int iscsi_open(BlockDriverState *bs, QDict *options, int flags, iscsilun->type = inq->periperal_device_type; iscsilun->has_write_same = true; -if ((ret =iscsi_readcapacity_sync (iscsilun)) !=0 ) { +iscsi_readcapacity_sync (iscsilun, &local_err); +if (local_err !=NULL ) { +error_propagate (errp, local_err); goto out; } bs->total_sectors =sector_lun2qemu (iscsilun->num_blocks, iscsilun);
@@ -1232,14 +1232,15 @@ static int iscsi_open(BlockDriverState *bs, QDict *options, int flags,if (iscsilun->lbpme) {struct scsi_inquiry_logical_block_provisioning *inq_lbp; task =iscsi_do_inquiry (iscsilun->iscsi, iscsilun->lun,1 , -SCSI_INQUIRY_PAGECODE_LOGICAL_BLOCK_PROVISIONING ); +SCSI_INQUIRY_PAGECODE_LOGICAL_BLOCK_PROVISIONING , + errp);if (task ==NULL ) { ret = -EINVAL ; goto out; } inq_lbp =scsi_datain_unmarshall (task);if (inq_lbp ==NULL ) { -error_report ("iSCSI: failed to unmarshall inquiry datain blob" ); +error_setg (errp,"iSCSI: failed to unmarshall inquiry datain blob" ); ret = -EINVAL ; goto out; }
@@ -1252,14 +1253,14 @@ static int iscsi_open(BlockDriverState *bs, QDict *options, int flags,if (iscsilun->lbp.lbpu || iscsilun->lbp.lbpws) {struct scsi_inquiry_block_limits *inq_bl; task =iscsi_do_inquiry (iscsilun->iscsi, iscsilun->lun,1 , -SCSI_INQUIRY_PAGECODE_BLOCK_LIMITS ); +SCSI_INQUIRY_PAGECODE_BLOCK_LIMITS , errp);if (task ==NULL ) { ret = -EINVAL ; goto out; } inq_bl =scsi_datain_unmarshall (task);if (inq_bl ==NULL ) { -error_report ("iSCSI: failed to unmarshall inquiry datain blob" ); +error_setg (errp,"iSCSI: failed to unmarshall inquiry datain blob" ); ret = -EINVAL ; goto out; }
@@ -1349,14 +1350,15 @@ static int iscsi_reopen_prepare(BDRVReopenState *state,static int iscsi_truncate (BlockDriverState *bs,int64_t offset) {IscsiLun *iscsilun = bs->opaque; -int ret =0 ; +Error *local_err =NULL ;if (iscsilun->type !=TYPE_DISK ) {return -ENOTSUP ; } -if ((ret =iscsi_readcapacity_sync (iscsilun)) !=0 ) { -return ret; +iscsi_readcapacity_sync (iscsilun, &local_err); +if (local_err !=NULL ) { +return -EIO ; }if (offset >iscsi_getlength (bs)) {
Signature · 1 line
1.8.5.3
Re: [Qemu-devel] [PATCH 06/20] iscsi: correctly propagate errors in iscsi_open
Quoted 217 lines · Paolo Bonzini
Before:
$ ./qemu-io-old qemu-io-old> open -r -o file.driver=iscsi,file.filename=foo Failed to parse URL : foo qemu-io-old: can't open device (null): Could not open 'foo': Invalid argumentAfter:
$ ./qemu-io qemu-io> open -r -o file.driver=iscsi,file.filename=foo qemu-io: can't open device (null): Failed to parse URL : fooSigned-off-by Paolo Bonzini <[email protected]>--- block/iscsi.c | 102 ++++++++++++++++++++++++++++++---------------------------- 1 file changed, 52 insertions(+), 50 deletions(-)block/iscsi.c +27
-35@@ -856,7 +856,8 @@ retry:#endif /* SCSI_SENSE_ASCQ_CAPACITY_DATA_HAS_CHANGED */ -static int parse_chap (struct iscsi_context *iscsi,const char *target) +static void parse_chap (struct iscsi_context *iscsi,const char *target, +Error **errp) {QemuOptsList *list;QemuOpts *opts;@@ -865,37 +866,35 @@ static int parse_chap(struct iscsi_context *iscsi, const char *target) list =qemu_find_opts ("iscsi" );if (!list) { -return 0 ; +return ; } opts =qemu_opts_find (list, target);if (opts ==NULL ) { opts =QTAILQ_FIRST (&list->head);if (!opts) { -return 0 ; +return ; } } user =qemu_opt_get (opts,"user" );if (!user) { -return 0 ; +return ; } password =qemu_opt_get (opts,"password" );if (!password) { -error_report ("CHAP username specified but no password was given" ); -return -1 ; +error_setg (errp,"CHAP username specified but no password was given" ); +return ; }if (iscsi_set_initiator_username_pwd (iscsi, user, password)) { -error_report ("Failed to set initiator username and password" ); -return -1 ; +error_setg (errp,"Failed to set initiator username and password" ); } - -return 0 ; } -static void parse_header_digest (struct iscsi_context *iscsi,const char *target) +static void parse_header_digest (struct iscsi_context *iscsi,const char *target, +Error **errp) {QemuOptsList *list;QemuOpts *opts;@@ -928,7 +927,7 @@ static void parse_header_digest(struct iscsi_context *iscsi, const char *target) }else if (!strcmp (digest,"NONE-CRC32C" )) {iscsi_set_header_digest (iscsi,ISCSI_HEADER_DIGEST_NONE_CRC32C ); }else { -error_report ("Invalid header-digest setting : %s" , digest); +error_setg (errp,"Invalid header-digest setting : %s" , digest); } }@@ -986,12 +985,11 @@ static void iscsi_nop_timed_event(void *opaque) }#endif -static int iscsi_readcapacity_sync (IscsiLun *iscsilun) +static void iscsi_readcapacity_sync (IscsiLun *iscsilun,Error **errp) {struct scsi_task *task =NULL ;struct scsi_readcapacity10 *rc10 =NULL ;struct scsi_readcapacity16 *rc16 =NULL ; -int ret =0 ;int retries =ISCSI_CMD_RETRIES ; do {@@ -1006,8 +1004,7 @@ static int iscsi_readcapacity_sync(IscsiLun *iscsilun)if (task !=NULL && task->status ==SCSI_STATUS_GOOD ) { rc16 =scsi_datain_unmarshall (task);if (rc16 ==NULL ) { -error_report ("iSCSI: Failed to unmarshall readcapacity16 data." ); - ret = -EINVAL ; +error_setg (errp,"iSCSI: Failed to unmarshall readcapacity16 data." ); }else { iscsilun->block_size = rc16->block_length; iscsilun->num_blocks = rc16->returned_lba +1 ;@@ -1021,8 +1018,7 @@ static int iscsi_readcapacity_sync(IscsiLun *iscsilun)if (task !=NULL && task->status ==SCSI_STATUS_GOOD ) { rc10 =scsi_datain_unmarshall (task);if (rc10 ==NULL ) { -error_report ("iSCSI: Failed to unmarshall readcapacity10 data." ); - ret = -EINVAL ; +error_setg (errp,"iSCSI: Failed to unmarshall readcapacity10 data." ); }else { iscsilun->block_size = rc10->block_size;if (rc10->lba ==0 ) {@@ -1035,20 +1031,18 @@ static int iscsi_readcapacity_sync(IscsiLun *iscsilun) }break ;default : -return 0 ; +return ; } }while (task !=NULL && task->status ==SCSI_STATUS_CHECK_CONDITION && task->sense.key ==SCSI_SENSE_UNIT_ATTENTION && retries-- >0 );if (task ==NULL || task->status !=SCSI_STATUS_GOOD ) { -error_report ("iSCSI: failed to send readcapacity10 command." ); - ret = -EINVAL ; +error_setg (errp,"iSCSI: failed to send readcapacity10 command." ); }if (task) {scsi_free_scsi_task (task); } -return ret; }/* TODO Convert to fine grained options */ @@ -1066,7 +1060,7 @@ static QemuOptsList runtime_opts = { };static struct scsi_task *iscsi_do_inquiry (struct iscsi_context *iscsi,int lun, -int evpd,int pc) +int evpd,int pc,Error **errp) {int full_size;struct scsi_task *task =NULL ;@@ -1088,8 +1082,8 @@ static struct scsi_task *iscsi_do_inquiry(struct iscsi_context *iscsi, int lun,return task; fail: -error_report ("iSCSI: Inquiry command failed : %s" , -iscsi_get_error (iscsi)); +error_setg (errp,"iSCSI: Inquiry command failed : %s" , +iscsi_get_error (iscsi));if (task) {scsi_free_scsi_task (task);return NULL ;@@ -1116,27 +1110,25 @@ static int iscsi_open(BlockDriverState *bs, QDict *options, int flags,int ret;if ((BDRV_SECTOR_SIZE %512 ) !=0 ) { -error_report ("iSCSI: Invalid BDRV_SECTOR_SIZE. " -"BDRV_SECTOR_SIZE(%lld) is not a multiple " -"of 512" ,BDRV_SECTOR_SIZE ); +error_setg (errp,"iSCSI: Invalid BDRV_SECTOR_SIZE. " +"BDRV_SECTOR_SIZE(%lld) is not a multiple " +"of 512" ,BDRV_SECTOR_SIZE );return -EINVAL ; } opts =qemu_opts_create (&runtime_opts,NULL ,0 , &error_abort);qemu_opts_absorb_qdict (opts, options, &local_err);if (error_is_set (&local_err)) { -qerror_report_err (local_err); -error_free (local_err); +error_propagate (errp, local_err); ret = -EINVAL ; goto out; } filename =qemu_opt_get (opts,"filename" ); - iscsi_url =iscsi_parse_full_url (iscsi, filename);if (iscsi_url ==NULL ) { -error_report ("Failed to parse URL : %s" , filename); +error_setg (errp,"Failed to parse URL : %s" , filename); ret = -EINVAL ; goto out; }@@ -1147,13 +1139,13 @@ static int iscsi_open(BlockDriverState *bs, QDict *options, int flags, iscsi =iscsi_create_context (initiator_name);if (iscsi ==NULL ) { -error_report ("iSCSI: Failed to create iSCSI context." ); +error_setg (errp,"iSCSI: Failed to create iSCSI context." ); ret = -ENOMEM ; goto out; }if (iscsi_set_targetname (iscsi, iscsi_url->target)) { -error_report ("iSCSI: Failed to set target name." ); +error_setg (errp,"iSCSI: Failed to set target name." ); ret = -EINVAL ; goto out; }@@ -1162,21 +1154,22 @@ static int iscsi_open(BlockDriverState *bs, QDict *options, int flags, ret =iscsi_set_initiator_username_pwd (iscsi, iscsi_url->user, iscsi_url->passwd);if (ret !=0 ) { -error_report ("Failed to set initiator username and password" ); +error_setg (errp,"Failed to set initiator username and password" );
block/iscsi.c static int iscsi_open(BlockDriverState *bs, QDict *options, int flags, · line 1165
Quoted 10 lines
block/iscsi.c +2
-2ret = -EINVAL ; goto out; } }/* check if we got CHAP username/password via the options */ -if (parse_chap (iscsi, iscsi_url->target) !=0 ) { -error_report ("iSCSI: Failed to set CHAP user/password" ); +parse_chap (iscsi, iscsi_url->target, &local_err); +if (local_err !=NULL ) {
Should we use error_is_set()?
Quoted 12 lines
block/iscsi.c +2
-1+error_propagate (errp, local_err); ret = -EINVAL ; goto out; }if (iscsi_set_session_type (iscsi,ISCSI_SESSION_NORMAL ) !=0 ) { -error_report ("iSCSI: Failed to set session type to normal." ); +error_setg (errp,"iSCSI: Failed to set session type to normal." ); ret = -EINVAL ; goto out; }
block/iscsi.c static int iscsi_open(BlockDriverState *bs, QDict *options, int flags, · line 1181
Quoted 6 lines
block/iscsi.c +2
-1@@ -1184,10 +1177,15 @@ static int iscsi_open(BlockDriverState *bs, QDict *options, int flags,iscsi_set_header_digest (iscsi,ISCSI_HEADER_DIGEST_NONE_CRC32C );/* check if we got HEADER_DIGEST via the options */ -parse_header_digest (iscsi, iscsi_url->target); +parse_header_digest (iscsi, iscsi_url->target, &local_err); +if (local_err !=NULL ) {
Same here.
Quoted 29 lines
block/iscsi.c +7
-3+error_propagate (errp, local_err); + ret = -EINVAL ; + goto out; + }if (iscsi_full_connect_sync (iscsi, iscsi_url->portal, iscsi_url->lun) !=0 ) { -error_report ("iSCSI: Failed to connect to LUN : %s" , +error_setg (errp,"iSCSI: Failed to connect to LUN : %s" ,iscsi_get_error (iscsi)); ret = -EINVAL ; goto out;@@ -1199,14 +1197,14 @@ static int iscsi_open(BlockDriverState *bs, QDict *options, int flags, task =iscsi_inquiry_sync (iscsi, iscsilun->lun,0 ,0 ,36 );if (task ==NULL || task->status !=SCSI_STATUS_GOOD ) { -error_report ("iSCSI: failed to send inquiry command." ); +error_setg (errp,"iSCSI: failed to send inquiry command." ); ret = -EINVAL ; goto out; } inq =scsi_datain_unmarshall (task);if (inq ==NULL ) { -error_report ("iSCSI: Failed to unmarshall inquiry data." ); +error_setg (errp,"iSCSI: Failed to unmarshall inquiry data." ); ret = -EINVAL ; goto out; }
block/iscsi.c static int iscsi_open(BlockDriverState *bs, QDict *options, int flags, · line 1216
Quoted 6 lines
block/iscsi.c +2
-1@@ -1214,7 +1212,9 @@ static int iscsi_open(BlockDriverState *bs, QDict *options, int flags, iscsilun->type = inq->periperal_device_type; iscsilun->has_write_same = true; -if ((ret =iscsi_readcapacity_sync (iscsilun)) !=0 ) { +iscsi_readcapacity_sync (iscsilun, &local_err); +if (local_err !=NULL ) {
And here.
Quoted 44 lines
block/iscsi.c +6
-5+error_propagate (errp, local_err); goto out; } bs->total_sectors =sector_lun2qemu (iscsilun->num_blocks, iscsilun);@@ -1232,14 +1232,15 @@ static int iscsi_open(BlockDriverState *bs, QDict *options, int flags,if (iscsilun->lbpme) {struct scsi_inquiry_logical_block_provisioning *inq_lbp; task =iscsi_do_inquiry (iscsilun->iscsi, iscsilun->lun,1 , -SCSI_INQUIRY_PAGECODE_LOGICAL_BLOCK_PROVISIONING ); +SCSI_INQUIRY_PAGECODE_LOGICAL_BLOCK_PROVISIONING , + errp);if (task ==NULL ) { ret = -EINVAL ; goto out; } inq_lbp =scsi_datain_unmarshall (task);if (inq_lbp ==NULL ) { -error_report ("iSCSI: failed to unmarshall inquiry datain blob" ); +error_setg (errp,"iSCSI: failed to unmarshall inquiry datain blob" ); ret = -EINVAL ; goto out; }@@ -1252,14 +1253,14 @@ static int iscsi_open(BlockDriverState *bs, QDict *options, int flags,if (iscsilun->lbp.lbpu || iscsilun->lbp.lbpws) {struct scsi_inquiry_block_limits *inq_bl; task =iscsi_do_inquiry (iscsilun->iscsi, iscsilun->lun,1 , -SCSI_INQUIRY_PAGECODE_BLOCK_LIMITS ); +SCSI_INQUIRY_PAGECODE_BLOCK_LIMITS , errp);if (task ==NULL ) { ret = -EINVAL ; goto out; } inq_bl =scsi_datain_unmarshall (task);if (inq_bl ==NULL ) { -error_report ("iSCSI: failed to unmarshall inquiry datain blob" ); +error_setg (errp,"iSCSI: failed to unmarshall inquiry datain blob" ); ret = -EINVAL ; goto out; }@@ -1349,14 +1350,15 @@ static int iscsi_reopen_prepare(BDRVReopenState *state,static int iscsi_truncate (BlockDriverState *bs,int64_t offset) {IscsiLun *iscsilun = bs->opaque; -int ret =0 ;
block/iscsi.c static int iscsi_reopen_prepare(BDRVReopenState *state, · line 1360
Quoted 10 lines
block/iscsi.c +3
-2+Error *local_err =NULL ;if (iscsilun->type !=TYPE_DISK ) {return -ENOTSUP ; } -if ((ret =iscsi_readcapacity_sync (iscsilun)) !=0 ) { -return ret; +iscsi_readcapacity_sync (iscsilun, &local_err); +if (local_err !=NULL ) {
And here.
And local_err needs error_free() before returning.
Thanks,
Fam
Quoted 9 lines
block/iscsi.c +1
-0+return -EIO ; }if (offset >iscsi_getlength (bs)) {Signature · 1 line
1.8.5.3
PATCH 7/20 gluster: default scheme to gluster:// and host to localhost.
In reply to Paolo BonziniCurrently, "gluster:///volname/img" and (using file. options) "file.driver=gluster,file.filename=foo" will segfault. Also, "//host/volname/img" will be rejected, but it is a valid URL that should be accepted just fine with "file.driver=gluster". Accept all of these, by inferring missing transport and host as TCP and localhost respectively.
--- block/gluster.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
block/gluster.c +2 -2
@@ -127,7 +127,7 @@ static int qemu_gluster_parseuri(GlusterConf *gconf, const char *filename) }/* transport */ -if (!strcmp (uri->scheme,"gluster" )) { +if (!uri->scheme || !strcmp (uri->scheme,"gluster" )) { gconf->transport =g_strdup ("tcp" ); }else if (!strcmp (uri->scheme,"gluster+tcp" )) { gconf->transport =g_strdup ("tcp" );
@@ -163,7 +163,7 @@ static int qemu_gluster_parseuri(GlusterConf *gconf, const char *filename) } gconf->server =g_strdup (qp->p[0 ].value); }else { - gconf->server =g_strdup (uri->server); + gconf->server =g_strdup (uri->server ? uri->server :"localhost" ); gconf->port = uri->port; }
Signature · 1 line
1.8.5.3
Re: [Qemu-devel] [PATCH 07/20] gluster: default scheme to gluster:// and host to localhost.
Quoted 39 lines · Paolo Bonzini
Currently, "gluster:///volname/img" and (using file. options) "file.driver=gluster,file.filename=foo" will segfault. Also, "//host/volname/img" will be rejected, but it is a valid URL that should be accepted just fine with "file.driver=gluster". Accept all of these, by inferring missing transport and host as TCP and localhost respectively.
Signed-off-by Paolo Bonzini <[email protected]>--- block/gluster.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)block/gluster.c +2
-2@@ -127,7 +127,7 @@ static int qemu_gluster_parseuri(GlusterConf *gconf, const char *filename) }/* transport */ -if (!strcmp (uri->scheme,"gluster" )) { +if (!uri->scheme || !strcmp (uri->scheme,"gluster" )) { gconf->transport =g_strdup ("tcp" ); }else if (!strcmp (uri->scheme,"gluster+tcp" )) { gconf->transport =g_strdup ("tcp" );@@ -163,7 +163,7 @@ static int qemu_gluster_parseuri(GlusterConf *gconf, const char *filename) } gconf->server =g_strdup (qp->p[0 ].value); }else { - gconf->server =g_strdup (uri->server); + gconf->server =g_strdup (uri->server ? uri->server :"localhost" ); gconf->port = uri->port; }Signature · 1 line
1.8.5.3
PATCH 8/20 gluster: correctly propagate errors
In reply to Paolo Bonzini--- block/gluster.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-)
block/gluster.c +13 -11
@@ -175,7 +175,8 @@ out:return ret; } -static struct glfs *qemu_gluster_init (GlusterConf *gconf,const char *filename) +static struct glfs *qemu_gluster_init (GlusterConf *gconf,const char *filename, +Error **errp) {struct glfs *glfs =NULL ;int ret;
@@ -183,8 +184,8 @@ static struct glfs *qemu_gluster_init(GlusterConf *gconf, const char *filename) ret =qemu_gluster_parseuri (gconf, filename);if (ret <0 ) { -error_report ("Usage: file=gluster[+transport]://[server[:port]]/" -"volname/image[?socket=...]" ); +error_setg (errp,"Usage: file=gluster[+transport]://[server[:port]]/" +"volname/image[?socket=...]" ); errno = -ret; goto out; }
@@ -211,9 +212,11 @@ static struct glfs *qemu_gluster_init(GlusterConf *gconf, const char *filename) ret =glfs_init (glfs);if (ret) { -error_report ("Gluster connection failed for server=%s port=%d " -"volume=%s image=%s transport=%s" , gconf->server, gconf->port, - gconf->volname, gconf->image, gconf->transport); +error_setg_errno (errp, errno, +"Gluster connection failed for server=%s port=%d " +"volume=%s image=%s transport=%s" , gconf->server, + gconf->port, gconf->volname, gconf->image, + gconf->transport); goto out; }return glfs;
@@ -283,15 +286,14 @@ static int qemu_gluster_open(BlockDriverState *bs, QDict *options, opts =qemu_opts_create (&runtime_opts,NULL ,0 , &error_abort);qemu_opts_absorb_qdict (opts, options, &local_err);if (error_is_set (&local_err)) { -qerror_report_err (local_err); -error_free (local_err); +error_propagate (errp, local_err); ret = -EINVAL ; goto out; } filename =qemu_opt_get (opts,"filename" ); - s->glfs =qemu_gluster_init (gconf, filename); + s->glfs =qemu_gluster_init (gconf, filename, errp);if (!s->glfs) { ret = -errno; goto out;
@@ -389,9 +391,9 @@ static int qemu_gluster_create(const char *filename,int64_t total_size =0 ;GlusterConf *gconf =g_malloc0 (sizeof (GlusterConf)); - glfs =qemu_gluster_init (gconf, filename); + glfs =qemu_gluster_init (gconf, filename, errp);if (!glfs) { - ret = -errno; + ret = -EINVAL ; goto out; }
Signature · 1 line
1.8.5.3
Re: [Qemu-devel] [PATCH 08/20] gluster: correctly propagate errors
Quoted 64 lines · Paolo Bonzini
Signed-off-by Paolo Bonzini <[email protected]>--- block/gluster.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-)block/gluster.c +11
-9@@ -175,7 +175,8 @@ out:return ret; } -static struct glfs *qemu_gluster_init (GlusterConf *gconf,const char *filename) +static struct glfs *qemu_gluster_init (GlusterConf *gconf,const char *filename, +Error **errp) {struct glfs *glfs =NULL ;int ret;@@ -183,8 +184,8 @@ static struct glfs *qemu_gluster_init(GlusterConf *gconf, const char *filename) ret =qemu_gluster_parseuri (gconf, filename);if (ret <0 ) { -error_report ("Usage: file=gluster[+transport]://[server[:port]]/" -"volname/image[?socket=...]" ); +error_setg (errp,"Usage: file=gluster[+transport]://[server[:port]]/" +"volname/image[?socket=...]" ); errno = -ret; goto out; }@@ -211,9 +212,11 @@ static struct glfs *qemu_gluster_init(GlusterConf *gconf, const char *filename) ret =glfs_init (glfs);if (ret) { -error_report ("Gluster connection failed for server=%s port=%d " -"volume=%s image=%s transport=%s" , gconf->server, gconf->port, - gconf->volname, gconf->image, gconf->transport); +error_setg_errno (errp, errno, +"Gluster connection failed for server=%s port=%d " +"volume=%s image=%s transport=%s" , gconf->server, + gconf->port, gconf->volname, gconf->image, + gconf->transport); goto out; }return glfs;@@ -283,15 +286,14 @@ static int qemu_gluster_open(BlockDriverState *bs, QDict *options, opts =qemu_opts_create (&runtime_opts,NULL ,0 , &error_abort);qemu_opts_absorb_qdict (opts, options, &local_err);if (error_is_set (&local_err)) { -qerror_report_err (local_err); -error_free (local_err); +error_propagate (errp, local_err); ret = -EINVAL ; goto out; } filename =qemu_opt_get (opts,"filename" ); - s->glfs =qemu_gluster_init (gconf, filename); + s->glfs =qemu_gluster_init (gconf, filename, errp);if (!s->glfs) { ret = -errno; goto out;
block/gluster.c static int qemu_gluster_create(const char *filename, · line 396
Quoted 8 lines
block/gluster.c +2
-2@@ -389,9 +391,9 @@ static int qemu_gluster_create(const char *filename,int64_t total_size =0 ;GlusterConf *gconf =g_malloc0 (sizeof (GlusterConf)); - glfs =qemu_gluster_init (gconf, filename); + glfs =qemu_gluster_init (gconf, filename, errp);if (!glfs) { - ret = -errno; + ret = -EINVAL ;
Why dropping -errno here?
Thanks,
Fam
Re: [Qemu-devel] [PATCH 08/20] gluster: correctly propagate errors
Il 10/02/2014 09:02, Fam Zheng ha scritto:
Quoted 68 lines · Paolo Bonzini
Quoted 67 lines
Quoted 67 lines
Signed-off-by Paolo Bonzini <[email protected]>--- block/gluster.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-)block/gluster.c +11
-9@@ -175,7 +175,8 @@ out:return ret; } -static struct glfs *qemu_gluster_init (GlusterConf *gconf,const char *filename) +static struct glfs *qemu_gluster_init (GlusterConf *gconf,const char *filename, +Error **errp) {struct glfs *glfs =NULL ;int ret;@@ -183,8 +184,8 @@ static struct glfs *qemu_gluster_init(GlusterConf *gconf, const char *filename) ret =qemu_gluster_parseuri (gconf, filename);if (ret <0 ) { -error_report ("Usage: file=gluster[+transport]://[server[:port]]/" -"volname/image[?socket=...]" ); +error_setg (errp,"Usage: file=gluster[+transport]://[server[:port]]/" +"volname/image[?socket=...]" ); errno = -ret; goto out; }@@ -211,9 +212,11 @@ static struct glfs *qemu_gluster_init(GlusterConf *gconf, const char *filename) ret =glfs_init (glfs);if (ret) { -error_report ("Gluster connection failed for server=%s port=%d " -"volume=%s image=%s transport=%s" , gconf->server, gconf->port, - gconf->volname, gconf->image, gconf->transport); +error_setg_errno (errp, errno, +"Gluster connection failed for server=%s port=%d " +"volume=%s image=%s transport=%s" , gconf->server, + gconf->port, gconf->volname, gconf->image, + gconf->transport); goto out; }return glfs;@@ -283,15 +286,14 @@ static int qemu_gluster_open(BlockDriverState *bs, QDict *options, opts =qemu_opts_create (&runtime_opts,NULL ,0 , &error_abort);qemu_opts_absorb_qdict (opts, options, &local_err);if (error_is_set (&local_err)) { -qerror_report_err (local_err); -error_free (local_err); +error_propagate (errp, local_err); ret = -EINVAL ; goto out; } filename =qemu_opt_get (opts,"filename" ); - s->glfs =qemu_gluster_init (gconf, filename); + s->glfs =qemu_gluster_init (gconf, filename, errp);if (!s->glfs) { ret = -errno; goto out;@@ -389,9 +391,9 @@ static int qemu_gluster_create(const char *filename,int64_t total_size =0 ;GlusterConf *gconf =g_malloc0 (sizeof (GlusterConf));
Quoted 6 lines
Quoted 5 lines
block/gluster.c static int qemu_gluster_create(const char *filename, · line 396
Quoted 5 lines
block/gluster.c +2
-2- glfs =qemu_gluster_init (gconf, filename); + glfs =qemu_gluster_init (gconf, filename, errp);if (!glfs) { - ret = -errno; + ret = -EINVAL ;Why dropping -errno here?
Because it is not applicable for the usage error messages. Anyway nothing is lost because the errno is already embedded in the error if applicable. If the Error* is set to non-NULL, the caller of drv->bdrv_open ignores the return value except to check that it is <0.
Paolo
Fam Zheng
Reviewed-byRe: [Qemu-devel] [PATCH 08/20] gluster: correctly propagate errors
Quoted 76 lines · Paolo Bonzini
Il 10/02/2014 09:02, Fam Zheng ha scritto:
Quoted 68 lines · Paolo Bonzini
Quoted 67 lines
Quoted 67 lines
Signed-off-by Paolo Bonzini <[email protected]>--- block/gluster.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-)block/gluster.c +11
-9@@ -175,7 +175,8 @@ out:return ret; } -static struct glfs *qemu_gluster_init (GlusterConf *gconf,const char *filename) +static struct glfs *qemu_gluster_init (GlusterConf *gconf,const char *filename, +Error **errp) {struct glfs *glfs =NULL ;int ret;@@ -183,8 +184,8 @@ static struct glfs *qemu_gluster_init(GlusterConf *gconf, const char *filename) ret =qemu_gluster_parseuri (gconf, filename);if (ret <0 ) { -error_report ("Usage: file=gluster[+transport]://[server[:port]]/" -"volname/image[?socket=...]" ); +error_setg (errp,"Usage: file=gluster[+transport]://[server[:port]]/" +"volname/image[?socket=...]" ); errno = -ret; goto out; }@@ -211,9 +212,11 @@ static struct glfs *qemu_gluster_init(GlusterConf *gconf, const char *filename) ret =glfs_init (glfs);if (ret) { -error_report ("Gluster connection failed for server=%s port=%d " -"volume=%s image=%s transport=%s" , gconf->server, gconf->port, - gconf->volname, gconf->image, gconf->transport); +error_setg_errno (errp, errno, +"Gluster connection failed for server=%s port=%d " +"volume=%s image=%s transport=%s" , gconf->server, + gconf->port, gconf->volname, gconf->image, + gconf->transport); goto out; }return glfs;@@ -283,15 +286,14 @@ static int qemu_gluster_open(BlockDriverState *bs, QDict *options, opts =qemu_opts_create (&runtime_opts,NULL ,0 , &error_abort);qemu_opts_absorb_qdict (opts, options, &local_err);if (error_is_set (&local_err)) { -qerror_report_err (local_err); -error_free (local_err); +error_propagate (errp, local_err); ret = -EINVAL ; goto out; } filename =qemu_opt_get (opts,"filename" ); - s->glfs =qemu_gluster_init (gconf, filename); + s->glfs =qemu_gluster_init (gconf, filename, errp);if (!s->glfs) { ret = -errno; goto out;@@ -389,9 +391,9 @@ static int qemu_gluster_create(const char *filename,int64_t total_size =0 ;GlusterConf *gconf =g_malloc0 (sizeof (GlusterConf));Quoted 6 lines
Quoted 5 lines
block/gluster.c static int qemu_gluster_create(const char *filename, · line 396
Quoted 5 lines
block/gluster.c +2
-2- glfs =qemu_gluster_init (gconf, filename); + glfs =qemu_gluster_init (gconf, filename, errp);if (!glfs) { - ret = -errno; + ret = -EINVAL ;Why dropping -errno here?
Quoted 5 lines
Because it is not applicable for the usage error messages. Anyway nothing is lost because the errno is already embedded in the error if applicable. If the Error* is set to non-NULL, the caller of
drv->bdrv_openignores the return value except to check that it is <0.
OK, then,
PATCH 9/20 cow: correctly propagate errors
In reply to Paolo Bonzini--- block/cow.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-)
block/cow.c +3 -9
@@ -82,7 +82,7 @@ static int cow_open(BlockDriverState *bs, QDict *options, int flags,char version[64 ];snprintf (version,sizeof (version),"COW version %d" , cow_header.version); -qerror_report (QERR_UNKNOWN_BLOCK_FORMAT_FEATURE , +error_set (errp,QERR_UNKNOWN_BLOCK_FORMAT_FEATURE , bs->device_name,"cow" , version); ret = -ENOTSUP ; goto fail;
@@ -330,7 +330,6 @@ static int cow_create(const char *filename, QEMUOptionParameter *options,struct stat st;int64_t image_sectors =0 ;const char *image_filename =NULL ; -Error *local_err =NULL ;int ret;BlockDriverState *cow_bs;
@@ -344,18 +343,13 @@ static int cow_create(const char *filename, QEMUOptionParameter *options, options++; } - ret =bdrv_create_file (filename, options, &local_err); + ret =bdrv_create_file (filename, options, errp);if (ret <0 ) { -qerror_report_err (local_err); -error_free (local_err);return ret; } - ret =bdrv_file_open (&cow_bs, filename,NULL ,NULL ,BDRV_O_RDWR , - &local_err); + ret =bdrv_file_open (&cow_bs, filename,NULL ,NULL ,BDRV_O_RDWR , errp);if (ret <0 ) { -qerror_report_err (local_err); -error_free (local_err);return ret; }
Signature · 1 line
1.8.5.3
Re: [Qemu-devel] [PATCH 09/20] cow: correctly propagate errors
Quoted 50 lines · Paolo Bonzini
Signed-off-by Paolo Bonzini <[email protected]>--- block/cow.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-)block/cow.c +3
-9@@ -82,7 +82,7 @@ static int cow_open(BlockDriverState *bs, QDict *options, int flags,char version[64 ];snprintf (version,sizeof (version),"COW version %d" , cow_header.version); -qerror_report (QERR_UNKNOWN_BLOCK_FORMAT_FEATURE , +error_set (errp,QERR_UNKNOWN_BLOCK_FORMAT_FEATURE , bs->device_name,"cow" , version); ret = -ENOTSUP ; goto fail;@@ -330,7 +330,6 @@ static int cow_create(const char *filename, QEMUOptionParameter *options,struct stat st;int64_t image_sectors =0 ;const char *image_filename =NULL ; -Error *local_err =NULL ;int ret;BlockDriverState *cow_bs;@@ -344,18 +343,13 @@ static int cow_create(const char *filename, QEMUOptionParameter *options, options++; } - ret =bdrv_create_file (filename, options, &local_err); + ret =bdrv_create_file (filename, options, errp);if (ret <0 ) { -qerror_report_err (local_err); -error_free (local_err);return ret; } - ret =bdrv_file_open (&cow_bs, filename,NULL ,NULL ,BDRV_O_RDWR , - &local_err); + ret =bdrv_file_open (&cow_bs, filename,NULL ,NULL ,BDRV_O_RDWR , errp);if (ret <0 ) { -qerror_report_err (local_err); -error_free (local_err);return ret; }Signature · 1 line
1.8.5.3
I'm never sure about choice of using local_err with error_propagate, or straightly pass errp, but the logic still looks right to me, so,
Re: [Qemu-devel] [PATCH 09/20] cow: correctly propagate errors
Il 10/02/2014 09:04, Fam Zheng ha scritto:
Quoted 2 lines
I'm never sure about choice of using
local_errwitherror_propagate, or straightly pass errp, but the logic still looks right to me, so,
Basically, never use error_is_set. If you do, you probably should have used instead &local_err and error_propagate. If you are not using error_is_set, it's fine to use errp directly with no error_propagate.
Paolo
Quoted 1 line
Reviewed-by Fam Zheng <[email protected]>
PATCH 10/20 curl: correctly propagate errors
In reply to Paolo Bonzini--- block/curl.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-)
block/curl.c +5 -8
@@ -456,30 +456,27 @@ 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" ); +error_setg (errp,"curl block device does not support writes" );return -EROFS ; } opts =qemu_opts_create (&runtime_opts,NULL ,0 , &error_abort);qemu_opts_absorb_qdict (opts, options, &local_err);if (error_is_set (&local_err)) { -qerror_report_err (local_err); -error_free (local_err); +error_propagate (errp, local_err); goto out_noclean; } s->readahead_size =qemu_opt_get_size (opts,"readahead" ,READ_AHEAD_SIZE );if ((s->readahead_size &0x1ff ) !=0 ) { -fprintf (stderr,"HTTP_READAHEAD_SIZE %zd is not a multiple of 512\n" , - s->readahead_size); +error_setg (errp,"HTTP_READAHEAD_SIZE %zd is not a multiple of 512\n" , + s->readahead_size); goto out_noclean; } file =qemu_opt_get (opts,"url" );if (file ==NULL ) { -qerror_report (ERROR_CLASS_GENERIC_ERROR ,"curl block driver requires " -"an 'url' option" ); +error_setg (errp,"curl block driver requires an 'url' option" ); goto out_noclean; }
Signature · 1 line
1.8.5.3
Re: [Qemu-devel] [PATCH 10/20] curl: correctly propagate errors
Quoted 24 lines · Paolo Bonzini
Signed-off-by Paolo Bonzini <[email protected]>--- block/curl.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-)block/curl.c +1
-4@@ -456,30 +456,27 @@ 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" ); +error_setg (errp,"curl block device does not support writes" );return -EROFS ; } opts =qemu_opts_create (&runtime_opts,NULL ,0 , &error_abort);qemu_opts_absorb_qdict (opts, options, &local_err);if (error_is_set (&local_err)) { -qerror_report_err (local_err); -error_free (local_err);
block/curl.c static int curl_open(BlockDriverState *bs, QDict *options, int flags, · line 473
Quoted 10 lines
block/curl.c +3
-2+error_propagate (errp, local_err); goto out_noclean; } s->readahead_size =qemu_opt_get_size (opts,"readahead" ,READ_AHEAD_SIZE );if ((s->readahead_size &0x1ff ) !=0 ) { -fprintf (stderr,"HTTP_READAHEAD_SIZE %zd is not a multiple of 512\n" , - s->readahead_size); +error_setg (errp,"HTTP_READAHEAD_SIZE %zd is not a multiple of 512\n" , + s->readahead_size);
Getting rid of the inconsistency of fprintf(stderr,...)'s are good!
Quoted 16 lines
block/curl.c +1
-2goto out_noclean; } file =qemu_opt_get (opts,"url" );if (file ==NULL ) { -qerror_report (ERROR_CLASS_GENERIC_ERROR ,"curl block driver requires " -"an 'url' option" ); +error_setg (errp,"curl block driver requires an 'url' option" ); goto out_noclean; }Signature · 1 line
1.8.5.3
Thanks,
PATCH 11/20 qcow: correctly propagate errors
In reply to Paolo Bonzini--- block/qcow.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-)
block/qcow.c +6 -10
@@ -119,17 +119,19 @@ static int qcow_open(BlockDriverState *bs, QDict *options, int flags,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,"qcow" , version); +error_set (errp,QERR_UNKNOWN_BLOCK_FORMAT_FEATURE , + bs->device_name,"qcow" , version); ret = -ENOTSUP ; goto fail; }if (header.size <=1 || header.cluster_bits <9 ) { +error_setg (errp,"invalid value in qcow header\n" ); ret = -EINVAL ; goto fail; }if (header.crypt_method >QCOW_CRYPT_AES ) { +error_setg (errp,"invalid encryption method in qcow header\n" ); ret = -EINVAL ; goto fail; }
@@ -668,7 +670,6 @@ static int qcow_create(const char *filename, QEMUOptionParameter *options,int64_t total_size =0 ;const char *backing_file =NULL ;int flags =0 ; -Error *local_err =NULL ;int ret;BlockDriverState *qcow_bs;
@@ -684,18 +685,13 @@ static int qcow_create(const char *filename, QEMUOptionParameter *options, options++; } - ret =bdrv_create_file (filename, options, &local_err); + ret =bdrv_create_file (filename, options, errp);if (ret <0 ) { -qerror_report_err (local_err); -error_free (local_err);return ret; } - ret =bdrv_file_open (&qcow_bs, filename,NULL ,NULL ,BDRV_O_RDWR , - &local_err); + ret =bdrv_file_open (&qcow_bs, filename,NULL ,NULL ,BDRV_O_RDWR , errp);if (ret <0 ) { -qerror_report_err (local_err); -error_free (local_err);return ret; }
Signature · 1 line
1.8.5.3
Re: [Qemu-devel] [PATCH 11/20] qcow: correctly propagate errors
Quoted 13 lines · Paolo Bonzini
Signed-off-by Paolo Bonzini <[email protected]>--- block/qcow.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-)block/qcow.c +0
-0@@ -119,17 +119,19 @@ static int qcow_open(BlockDriverState *bs, QDict *options, int flags,if (header.version !=QCOW_VERSION ) {char version[64 ];snprintf (version,sizeof (version),"QCOW version %d" , header.version);
block/qcow.c static int qcow_open(BlockDriverState *bs, QDict *options, int flags, · line 129
Quoted 10 lines
block/qcow.c +3
-2-qerror_report (QERR_UNKNOWN_BLOCK_FORMAT_FEATURE , - bs->device_name,"qcow" , version); +error_set (errp,QERR_UNKNOWN_BLOCK_FORMAT_FEATURE , + bs->device_name,"qcow" , version); ret = -ENOTSUP ; goto fail; }if (header.size <=1 || header.cluster_bits <9 ) { +error_setg (errp,"invalid value in qcow header\n" );
The convention is not adding "\n" in the end of error messages.
block/qcow.c static int qcow_open(BlockDriverState *bs, QDict *options, int flags, · line 134
Quoted 5 lines
block/qcow.c +1
-0ret = -EINVAL ; goto fail; }if (header.crypt_method >QCOW_CRYPT_AES ) { +error_setg (errp,"invalid encryption method in qcow header\n" );
Same here.
Thanks,
Fam
Re: [Qemu-devel] [PATCH 11/20] qcow: correctly propagate errors
Il 10/02/2014 09:09, Fam Zheng ha scritto:
Quoted 27 lines · Paolo Bonzini
Quoted 13 lines
Signed-off-by Paolo Bonzini <[email protected]>--- block/qcow.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-)block/qcow.c +0
-0@@ -119,17 +119,19 @@ static int qcow_open(BlockDriverState *bs, QDict *options, int flags,if (header.version !=QCOW_VERSION ) {char version[64 ];snprintf (version,sizeof (version),"QCOW version %d" , header.version);block/qcow.c static int qcow_open(BlockDriverState *bs, QDict *options, int flags, · line 129
Quoted 10 lines
block/qcow.c +3
-2-qerror_report (QERR_UNKNOWN_BLOCK_FORMAT_FEATURE , - bs->device_name,"qcow" , version); +error_set (errp,QERR_UNKNOWN_BLOCK_FORMAT_FEATURE , + bs->device_name,"qcow" , version); ret = -ENOTSUP ; goto fail; }if (header.size <=1 || header.cluster_bits <9 ) { +error_setg (errp,"invalid value in qcow header\n" );The convention is not adding "\n" in the end of error messages.
Quoted 7 lines
block/qcow.c static int qcow_open(BlockDriverState *bs, QDict *options, int flags, · line 134
Quoted 5 lines
block/qcow.c +1
-0ret = -EINVAL ; goto fail; }if (header.crypt_method >QCOW_CRYPT_AES ) { +error_setg (errp,"invalid encryption method in qcow header\n" );Same here.
Oops, I'll fix all of them.
Paolo
PATCH 12/20 qed: correctly propagate errors
In reply to Paolo Bonzini--- block/qed.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-)
block/qed.c +6 -10
@@ -398,7 +398,7 @@ static int bdrv_qed_open(BlockDriverState *bs, QDict *options, int flags,char buf[64 ];snprintf (buf,sizeof (buf),"%" PRIx64, s->header.features & ~QED_FEATURE_MASK ); -qerror_report (QERR_UNKNOWN_BLOCK_FORMAT_FEATURE , +error_set (errp,QERR_UNKNOWN_BLOCK_FORMAT_FEATURE , bs->device_name,"QED" , buf);return -ENOTSUP ; }
@@ -545,7 +545,8 @@ static void bdrv_qed_close(BlockDriverState *bs)static int qed_create (const char *filename,uint32_t cluster_size,uint64_t image_size,uint32_t table_size, -const char *backing_file,const char *backing_fmt) +const char *backing_file,const char *backing_fmt, +Error **errp) {QEDHeader header = { .magic =QED_MAGIC ,
@@ -560,22 +561,17 @@ static int qed_create(const char *filename, uint32_t cluster_size,QEDHeader le_header;uint8_t *l1_table =NULL ;size_t l1_size = header.cluster_size * header.table_size; -Error *local_err =NULL ;int ret =0 ;BlockDriverState *bs =NULL ; - ret =bdrv_create_file (filename,NULL , &local_err); + ret =bdrv_create_file (filename,NULL , errp);if (ret <0 ) { -qerror_report_err (local_err); -error_free (local_err);return ret; } ret =bdrv_file_open (&bs, filename,NULL ,NULL , -BDRV_O_RDWR |BDRV_O_CACHE_WB , &local_err); +BDRV_O_RDWR |BDRV_O_CACHE_WB , errp);if (ret <0 ) { -qerror_report_err (local_err); -error_free (local_err);return ret; }
@@ -665,7 +661,7 @@ static int bdrv_qed_create(const char *filename, QEMUOptionParameter *options, }return qed_create (filename, cluster_size, image_size, table_size, - backing_file, backing_fmt); + backing_file, backing_fmt, errp); } typedef struct {
Signature · 1 line
1.8.5.3
Re: [Qemu-devel] [PATCH 12/20] qed: correctly propagate errors
Quoted 65 lines · Paolo Bonzini
Signed-off-by Paolo Bonzini <[email protected]>--- block/qed.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-)block/qed.c +6
-10@@ -398,7 +398,7 @@ static int bdrv_qed_open(BlockDriverState *bs, QDict *options, int flags,char buf[64 ];snprintf (buf,sizeof (buf),"%" PRIx64, s->header.features & ~QED_FEATURE_MASK ); -qerror_report (QERR_UNKNOWN_BLOCK_FORMAT_FEATURE , +error_set (errp,QERR_UNKNOWN_BLOCK_FORMAT_FEATURE , bs->device_name,"QED" , buf);return -ENOTSUP ; }@@ -545,7 +545,8 @@ static void bdrv_qed_close(BlockDriverState *bs)static int qed_create (const char *filename,uint32_t cluster_size,uint64_t image_size,uint32_t table_size, -const char *backing_file,const char *backing_fmt) +const char *backing_file,const char *backing_fmt, +Error **errp) {QEDHeader header = { .magic =QED_MAGIC ,@@ -560,22 +561,17 @@ static int qed_create(const char *filename, uint32_t cluster_size,QEDHeader le_header;uint8_t *l1_table =NULL ;size_t l1_size = header.cluster_size * header.table_size; -Error *local_err =NULL ;int ret =0 ;BlockDriverState *bs =NULL ; - ret =bdrv_create_file (filename,NULL , &local_err); + ret =bdrv_create_file (filename,NULL , errp);if (ret <0 ) { -qerror_report_err (local_err); -error_free (local_err);return ret; } ret =bdrv_file_open (&bs, filename,NULL ,NULL , -BDRV_O_RDWR |BDRV_O_CACHE_WB , &local_err); +BDRV_O_RDWR |BDRV_O_CACHE_WB , errp);if (ret <0 ) { -qerror_report_err (local_err); -error_free (local_err);return ret; }@@ -665,7 +661,7 @@ static int bdrv_qed_create(const char *filename, QEMUOptionParameter *options, }return qed_create (filename, cluster_size, image_size, table_size, - backing_file, backing_fmt); + backing_file, backing_fmt, errp); } typedef struct {Signature · 1 line
1.8.5.3
PATCH 13/20 vhdx: correctly propagate errors
In reply to Paolo Bonzini--- block/vhdx.c | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-)
block/vhdx.c +9 -12
@@ -402,9 +402,10 @@ int vhdx_update_headers(BlockDriverState *bs, BDRVVHDXState *s, }/* opens the specified header block from the VHDX file header section */ -static int vhdx_parse_header (BlockDriverState *bs,BDRVVHDXState *s) +static void vhdx_parse_header (BlockDriverState *bs,BDRVVHDXState *s, +Error **errp) { -int ret =0 ; +int ret;VHDXHeader *header1;VHDXHeader *header2;bool h1_valid = false;
@@ -462,7 +463,6 @@ static int vhdx_parse_header(BlockDriverState *bs, BDRVVHDXState *s) }else if (!h1_valid && h2_valid) { s->curr_header =1 ; }else if (!h1_valid && !h2_valid) { - ret = -EINVAL ; goto fail; }else {/* If both headers are valid, then we choose the active one by the
@@ -473,27 +473,22 @@ static int vhdx_parse_header(BlockDriverState *bs, BDRVVHDXState *s) }else if (h2_seq > h1_seq) { s->curr_header =1 ; }else { - ret = -EINVAL ; goto fail; } }vhdx_region_register (s, s->headers[s->curr_header]->log_offset, s->headers[s->curr_header]->log_length); - - ret =0 ; - goto exit; fail: -qerror_report (ERROR_CLASS_GENERIC_ERROR ,"No valid VHDX header found" ); +error_setg_errno (errp, -ret,"No valid VHDX header found" );qemu_vfree (header1);qemu_vfree (header2); s->headers[0 ] =NULL ; s->headers[1 ] =NULL ; exit:qemu_vfree (buffer); -return ret; }
@@ -878,7 +873,7 @@ static int vhdx_open(BlockDriverState *bs, QDict *options, int flags,int ret =0 ;uint32_t i;uint64_t signature; - +Error *local_err =NULL ; s->bat =NULL ; s->first_visible_write = true;
@@ -901,8 +896,10 @@ static int vhdx_open(BlockDriverState *bs, QDict *options, int flags,* header update */ vhdx_guid_generate (&s->session_guid); - ret =vhdx_parse_header (bs, s); -if (ret <0 ) { +vhdx_parse_header (bs, s, &local_err); +if (local_err !=NULL ) { +error_propagate (errp, local_err); + ret = -EINVAL ; goto fail; }
Signature · 1 line
1.8.5.3
Re: [Qemu-devel] [PATCH 13/20] vhdx: correctly propagate errors
Quoted 84 lines · Paolo Bonzini
Signed-off-by Paolo Bonzini <[email protected]>--- block/vhdx.c | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-)block/vhdx.c +9
-12@@ -402,9 +402,10 @@ int vhdx_update_headers(BlockDriverState *bs, BDRVVHDXState *s, }/* opens the specified header block from the VHDX file header section */ -static int vhdx_parse_header (BlockDriverState *bs,BDRVVHDXState *s) +static void vhdx_parse_header (BlockDriverState *bs,BDRVVHDXState *s, +Error **errp) { -int ret =0 ; +int ret;VHDXHeader *header1;VHDXHeader *header2;bool h1_valid = false;@@ -462,7 +463,6 @@ static int vhdx_parse_header(BlockDriverState *bs, BDRVVHDXState *s) }else if (!h1_valid && h2_valid) { s->curr_header =1 ; }else if (!h1_valid && !h2_valid) { - ret = -EINVAL ; goto fail; }else {/* If both headers are valid, then we choose the active one by the @@ -473,27 +473,22 @@ static int vhdx_parse_header(BlockDriverState *bs, BDRVVHDXState *s) }else if (h2_seq > h1_seq) { s->curr_header =1 ; }else { - ret = -EINVAL ; goto fail; } }vhdx_region_register (s, s->headers[s->curr_header]->log_offset, s->headers[s->curr_header]->log_length); - - ret =0 ; - goto exit; fail: -qerror_report (ERROR_CLASS_GENERIC_ERROR ,"No valid VHDX header found" ); +error_setg_errno (errp, -ret,"No valid VHDX header found" );qemu_vfree (header1);qemu_vfree (header2); s->headers[0 ] =NULL ; s->headers[1 ] =NULL ; exit:qemu_vfree (buffer); -return ret; }@@ -878,7 +873,7 @@ static int vhdx_open(BlockDriverState *bs, QDict *options, int flags,int ret =0 ;uint32_t i;uint64_t signature; - +Error *local_err =NULL ; s->bat =NULL ; s->first_visible_write = true;@@ -901,8 +896,10 @@ static int vhdx_open(BlockDriverState *bs, QDict *options, int flags,* header update */ vhdx_guid_generate (&s->session_guid); - ret =vhdx_parse_header (bs, s); -if (ret <0 ) { +vhdx_parse_header (bs, s, &local_err); +if (local_err !=NULL ) { +error_propagate (errp, local_err); + ret = -EINVAL ; goto fail; }Signature · 1 line
1.8.5.3
PATCH 14/20 vvfat: correctly propagate errors
In reply to Paolo BonziniBefore:
$ ./qemu-io-old
qemu-io-old> open -r -o driver=vvfat,fat-type=24,dir=i386-softmmu
Valid FAT types are only 12, 16 and 32
qemu-io-old: can't open device (null): Could not open image: Invalid argumentAfter:
$ ./qemu-io
qemu-io> open -r -o driver=vvfat,fat-type=24,dir=i386-softmmu
qemu-io: can't open device (null): Valid FAT types are only 12, 16 and 32--- block/vvfat.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-)
block/vvfat.c +3 -6
@@ -1086,16 +1086,14 @@ DLOG(if (stderr == NULL) { opts =qemu_opts_create (&runtime_opts,NULL ,0 , &error_abort);qemu_opts_absorb_qdict (opts, options, &local_err);if (error_is_set (&local_err)) { -qerror_report_err (local_err); -error_free (local_err); +error_propagate (errp, local_err); ret = -EINVAL ; goto fail; } dirname =qemu_opt_get (opts,"dir" );if (!dirname) { -qerror_report (ERROR_CLASS_GENERIC_ERROR ,"vvfat block driver requires " -"a 'dir' option" ); +error_setg (errp,"vvfat block driver requires a 'dir' option" ); ret = -EINVAL ; goto fail; }
@@ -1135,8 +1133,7 @@ DLOG(if (stderr == NULL) {case 12 :break ;default : -qerror_report (ERROR_CLASS_GENERIC_ERROR ,"Valid FAT types are only " -"12, 16 and 32" ); +error_setg (errp,"Valid FAT types are only 12, 16 and 32" ); ret = -EINVAL ; goto fail; }
Signature · 1 line
1.8.5.3
Re: [Qemu-devel] [PATCH 14/20] vvfat: correctly propagate errors
Quoted 53 lines · Paolo Bonzini
Before:
$ ./qemu-io-old qemu-io-old> open -r -o driver=vvfat,fat-type=24,dir=i386-softmmu Valid FAT types are only 12, 16 and 32 qemu-io-old: can't open device (null): Could not open image: Invalid argumentAfter:
$ ./qemu-io qemu-io> open -r -o driver=vvfat,fat-type=24,dir=i386-softmmu qemu-io: can't open device (null): Valid FAT types are only 12, 16 and 32Signed-off-by Paolo Bonzini <[email protected]>--- block/vvfat.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-)block/vvfat.c +3
-6@@ -1086,16 +1086,14 @@ DLOG(if (stderr == NULL) { opts =qemu_opts_create (&runtime_opts,NULL ,0 , &error_abort);qemu_opts_absorb_qdict (opts, options, &local_err);if (error_is_set (&local_err)) { -qerror_report_err (local_err); -error_free (local_err); +error_propagate (errp, local_err); ret = -EINVAL ; goto fail; } dirname =qemu_opt_get (opts,"dir" );if (!dirname) { -qerror_report (ERROR_CLASS_GENERIC_ERROR ,"vvfat block driver requires " -"a 'dir' option" ); +error_setg (errp,"vvfat block driver requires a 'dir' option" ); ret = -EINVAL ; goto fail; }@@ -1135,8 +1133,7 @@ DLOG(if (stderr == NULL) {case 12 :break ;default : -qerror_report (ERROR_CLASS_GENERIC_ERROR ,"Valid FAT types are only " -"12, 16 and 32" ); +error_setg (errp,"Valid FAT types are only 12, 16 and 32" ); ret = -EINVAL ; goto fail; }Signature · 1 line
1.8.5.3
PATCH 15/20 vmdk: extract vmdk_read_desc
In reply to Paolo Bonzini--- block/vmdk.c | 40 +++++++++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 11 deletions(-)
block/vmdk.c +29 -11
@@ -529,6 +529,31 @@ static int vmdk_open_vmfs_sparse(BlockDriverState *bs,static int vmdk_open_desc_file (BlockDriverState *bs,int flags,uint64_t desc_offset,Error **errp); +static char *vmdk_read_desc (BlockDriverState *file,uint64_t desc_offset, +Error **errp) +{ +int64_t size; +char *buf; +int ret; + + size =bdrv_getlength (file); +if (size <0 ) { +error_setg_errno (errp, -size,"Could not access file" ); +return NULL ; + } + + size =MIN (size,1 <<20 );/* avoid unbounded allocation */ + buf =g_malloc0 (size +1 ); + + ret =bdrv_pread (file, desc_offset, buf, size); +if (ret <0 ) { +error_setg_errno (errp, -ret,"Could not read from file" ); +return NULL ; + } + +return buf; +} +static int vmdk_open_vmdk4 (BlockDriverState *bs,BlockDriverState *file,int flags,Error **errp)
@@ -822,23 +847,16 @@ static int vmdk_open_desc_file(BlockDriverState *bs, int flags, uint64_t desc_offset, Error **errp) { int ret; -char *buf =NULL ; +char *buf;char ct[128 ];BDRVVmdkState *s = bs->opaque; -int64_t size; - size =bdrv_getlength (bs->file); -if (size <0 ) { + buf =vmdk_read_desc (bs->file, desc_offset, errp); +if (!buf) {return -EINVAL ; - } - - size =MIN (size,1 <<20 );/* avoid unbounded allocation */ - buf =g_malloc0 (size +1 ); - - ret =bdrv_pread (bs->file, desc_offset, buf, size); -if (ret <0 ) { goto exit; } +if (vmdk_parse_description (buf,"createType" , ct,sizeof (ct))) { ret = -EMEDIUMTYPE ; goto exit;
Signature · 1 line
1.8.5.3
Re: [Qemu-devel] [PATCH 15/20] vmdk: extract vmdk_read_desc
Quoted 22 lines · Paolo Bonzini
Signed-off-by Paolo Bonzini <[email protected]>--- block/vmdk.c | 40 +++++++++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 11 deletions(-)block/vmdk.c +9
-0@@ -529,6 +529,31 @@ static int vmdk_open_vmfs_sparse(BlockDriverState *bs,static int vmdk_open_desc_file (BlockDriverState *bs,int flags,uint64_t desc_offset,Error **errp); +static char *vmdk_read_desc (BlockDriverState *file,uint64_t desc_offset, +Error **errp) +{ +int64_t size; +char *buf; +int ret; + + size =bdrv_getlength (file); +if (size <0 ) {
block/vmdk.c static int vmdk_open_vmfs_sparse(BlockDriverState *bs, · line 550
Quoted 10 lines
block/vmdk.c +10
-0+error_setg_errno (errp, -size,"Could not access file" ); +return NULL ; + } + + size =MIN (size,1 <<20 );/* avoid unbounded allocation */ + buf =g_malloc0 (size +1 ); + + ret =bdrv_pread (file, desc_offset, buf, size); +if (ret <0 ) { +error_setg_errno (errp, -ret,"Could not read from file" );
buf is leaked here.
Fam
Quoted 41 lines
block/vmdk.c +10
-11+return NULL ; + } + +return buf; +} +static int vmdk_open_vmdk4 (BlockDriverState *bs,BlockDriverState *file,int flags,Error **errp)@@ -822,23 +847,16 @@ static int vmdk_open_desc_file(BlockDriverState *bs, int flags, uint64_t desc_offset, Error **errp) { int ret; -char *buf =NULL ; +char *buf;char ct[128 ];BDRVVmdkState *s = bs->opaque; -int64_t size; - size =bdrv_getlength (bs->file); -if (size <0 ) { + buf =vmdk_read_desc (bs->file, desc_offset, errp); +if (!buf) {return -EINVAL ; - } - - size =MIN (size,1 <<20 );/* avoid unbounded allocation */ - buf =g_malloc0 (size +1 ); - - ret =bdrv_pread (bs->file, desc_offset, buf, size); -if (ret <0 ) { goto exit; } +if (vmdk_parse_description (buf,"createType" , ct,sizeof (ct))) { ret = -EMEDIUMTYPE ; goto exit;Signature · 1 line
1.8.5.3
PATCH 16/20 vmdk: push vmdk_read_desc up to caller
In reply to Paolo BonziniCurrently, we just try reading a VMDK file as both image and descriptor. This makes it hard to choose which of the two attempts gave the best error. We'll decide in advance if the file looks like an image or a descriptor, and this patch is the first step to that end.
--- block/vmdk.c | 54 ++++++++++++++++++++++++++++++------------------------ 1 file changed, 30 insertions(+), 24 deletions(-)
block/vmdk.c +30 -24
@@ -526,8 +526,8 @@ static int vmdk_open_vmfs_sparse(BlockDriverState *bs,return ret; } -static int vmdk_open_desc_file (BlockDriverState *bs,int flags, -uint64_t desc_offset,Error **errp); +static int vmdk_open_desc_file (BlockDriverState *bs,int flags,char *buf, +Error **errp);static char *vmdk_read_desc (BlockDriverState *file,uint64_t desc_offset,Error **errp)
@@ -575,7 +575,13 @@ static int vmdk_open_vmdk4(BlockDriverState *bs,if (header.capacity ==0 ) {uint64_t desc_offset =le64_to_cpu (header.desc_offset);if (desc_offset) { -return vmdk_open_desc_file (bs, flags, desc_offset <<9 , errp); +char *buf =vmdk_read_desc (file, desc_offset <<9 , errp); +if (!buf) { +return -EINVAL ; + } + ret =vmdk_open_desc_file (bs, flags, buf, errp); +g_free (buf); +return ret; } }
@@ -726,16 +732,12 @@ static int vmdk_parse_description(const char *desc, const char *opt_name,/* Open an extent file and append to bs array */ static int vmdk_open_sparse (BlockDriverState *bs, -BlockDriverState *file, -int flags,Error **errp) +BlockDriverState *file,int flags, +char *buf,Error **errp) {uint32_t magic; -if (bdrv_pread (file,0 , &magic,sizeof (magic)) !=sizeof (magic)) { -return -EIO ; - } - - magic =be32_to_cpu (magic); + magic =ldl_be_p (buf);switch (magic) {case VMDK3_MAGIC :return vmdk_open_vmfs_sparse (bs, file, flags, errp);
@@ -819,7 +821,12 @@ static int vmdk_parse_extents(const char *desc, BlockDriverState *bs, extent->flat_start_offset = flat_offset <<9 ; }else if (!strcmp (type,"SPARSE" ) || !strcmp (type,"VMFSSPARSE" )) {/* SPARSE extent and VMFSSPARSE extent are both "COWD" sparse file*/ - ret =vmdk_open_sparse (bs, extent_file, bs->open_flags, errp); +char *buf =vmdk_read_desc (extent_file,0 , errp); +if (!buf) { + ret = -EINVAL ; + }else { + ret =vmdk_open_sparse (bs, extent_file, bs->open_flags, buf, errp); + }if (ret) {bdrv_unref (extent_file);return ret;
@@ -843,20 +850,13 @@ next_line:return 0 ; } -static int vmdk_open_desc_file (BlockDriverState *bs,int flags, -uint64_t desc_offset,Error **errp) +static int vmdk_open_desc_file (BlockDriverState *bs,int flags,char *buf, +Error **errp) {int ret; -char *buf;char ct[128 ];BDRVVmdkState *s = bs->opaque; - buf =vmdk_read_desc (bs->file, desc_offset, errp); -if (!buf) { -return -EINVAL ; - goto exit; - } -if (vmdk_parse_description (buf,"createType" , ct,sizeof (ct))) { ret = -EMEDIUMTYPE ; goto exit;
@@ -874,20 +874,25 @@ static int vmdk_open_desc_file(BlockDriverState *bs, int flags, s->desc_offset =0 ; ret =vmdk_parse_extents (buf, bs, bs->file->filename, errp); exit: -g_free (buf);return ret; }static int vmdk_open (BlockDriverState *bs,QDict *options,int flags,Error **errp) { +char *buf =NULL ;int ret;BDRVVmdkState *s = bs->opaque; -if (vmdk_open_sparse (bs, bs->file, flags, errp) ==0 ) { + buf =vmdk_read_desc (bs->file,0 , errp); +if (!buf) { +return -EINVAL ; + } + +if (vmdk_open_sparse (bs, bs->file, flags, buf, errp) ==0 ) { s->desc_offset =0x200 ; }else { - ret =vmdk_open_desc_file (bs, flags,0 , errp); + ret =vmdk_open_desc_file (bs, flags, buf, errp);if (ret) { goto fail; }
@@ -906,10 +911,11 @@ static int vmdk_open(BlockDriverState *bs, QDict *options, int flags,QERR_BLOCK_FORMAT_FEATURE_NOT_SUPPORTED , "vmdk", bs->device_name, "live migration");migrate_add_blocker (s->migration_blocker); - +g_free (buf);return 0 ; fail: +g_free (buf);g_free (s->create_type); s->create_type =NULL ;vmdk_free_extents (bs);
Signature · 1 line
1.8.5.3
Re: [Qemu-devel] [PATCH 16/20] vmdk: push vmdk_read_desc up to caller
Quoted 62 lines · Paolo Bonzini
Currently, we just try reading a VMDK file as both image and descriptor. This makes it hard to choose which of the two attempts gave the best error. We'll decide in advance if the file looks like an image or a descriptor, and this patch is the first step to that end.
Signed-off-by Paolo Bonzini <[email protected]>--- block/vmdk.c | 54 ++++++++++++++++++++++++++++++------------------------ 1 file changed, 30 insertions(+), 24 deletions(-)block/vmdk.c +12
-10@@ -526,8 +526,8 @@ static int vmdk_open_vmfs_sparse(BlockDriverState *bs,return ret; } -static int vmdk_open_desc_file (BlockDriverState *bs,int flags, -uint64_t desc_offset,Error **errp); +static int vmdk_open_desc_file (BlockDriverState *bs,int flags,char *buf, +Error **errp);static char *vmdk_read_desc (BlockDriverState *file,uint64_t desc_offset,Error **errp)@@ -575,7 +575,13 @@ static int vmdk_open_vmdk4(BlockDriverState *bs,if (header.capacity ==0 ) {uint64_t desc_offset =le64_to_cpu (header.desc_offset);if (desc_offset) { -return vmdk_open_desc_file (bs, flags, desc_offset <<9 , errp); +char *buf =vmdk_read_desc (file, desc_offset <<9 , errp); +if (!buf) { +return -EINVAL ; + } + ret =vmdk_open_desc_file (bs, flags, buf, errp); +g_free (buf); +return ret; } }@@ -726,16 +732,12 @@ static int vmdk_parse_description(const char *desc, const char *opt_name,/* Open an extent file and append to bs array */ static int vmdk_open_sparse (BlockDriverState *bs, -BlockDriverState *file, -int flags,Error **errp) +BlockDriverState *file,int flags, +char *buf,Error **errp) {uint32_t magic; -if (bdrv_pread (file,0 , &magic,sizeof (magic)) !=sizeof (magic)) { -return -EIO ; - } - - magic =be32_to_cpu (magic); + magic =ldl_be_p (buf);switch (magic) {case VMDK3_MAGIC :return vmdk_open_vmfs_sparse (bs, file, flags, errp);@@ -819,7 +821,12 @@ static int vmdk_parse_extents(const char *desc, BlockDriverState *bs, extent->flat_start_offset = flat_offset <<9 ;
block/vmdk.c static int vmdk_parse_extents(const char *desc, BlockDriverState *bs, · line 830
Quoted 10 lines
block/vmdk.c +6
-1}else if (!strcmp (type,"SPARSE" ) || !strcmp (type,"VMFSSPARSE" )) {/* SPARSE extent and VMFSSPARSE extent are both "COWD" sparse file*/ - ret =vmdk_open_sparse (bs, extent_file, bs->open_flags, errp); +char *buf =vmdk_read_desc (extent_file,0 , errp); +if (!buf) { + ret = -EINVAL ; + }else { + ret =vmdk_open_sparse (bs, extent_file, bs->open_flags, buf, errp); + }if (ret) {
Is buf leaked here when vmdk_open_sparse fails?
Fam
Quoted 2 lines
block/vmdk.c +0
-0bdrv_unref (extent_file);return ret;
PATCH 17/20 vmdk: do not try opening a file as both image and descriptor
In reply to Paolo BonziniThis prepares for propagating errors from vmdk_open_sparse and vmdk_open_desc_file up to the caller of vmdk_open.
--- block/vmdk.c | 22 +++++++++++++++------- tests/qemu-iotests/059.out | 4 ++-- 2 files changed, 17 insertions(+), 9 deletions(-)
block/vmdk.c +15 -7
@@ -883,20 +883,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 ) { - s->desc_offset =0x200 ; - }else { - ret =vmdk_open_desc_file (bs, flags, buf, errp); -if (ret) { - goto fail; - } + 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 ; +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) {
tests/qemu-iotests/059.out +2 -2
@@ -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
Signature · 1 line
1.8.5.3
Re: [Qemu-devel] [PATCH 17/20] vmdk: do not try opening a file as both image and descriptor
Quoted 76 lines · Paolo Bonzini
This prepares for propagating errors from
vmdk_open_sparseandvmdk_open_desc_fileup to the caller ofvmdk_open.Signed-off-by Paolo Bonzini <[email protected]>--- block/vmdk.c | 22 +++++++++++++++------- tests/qemu-iotests/059.out | 4 ++-- 2 files changed, 17 insertions(+), 9 deletions(-)block/vmdk.c +15
-7@@ -883,20 +883,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 ) { - s->desc_offset =0x200 ; - }else { - ret =vmdk_open_desc_file (bs, flags, buf, errp); -if (ret) { - goto fail; - } + 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 ; +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) {tests/qemu-iotests/059.out +2
-2@@ -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.IMGFMTSignature · 1 line
1.8.5.3
PATCH 18/20 vmdk: correctly propagate errors
In reply to Paolo BonziniNow that we can return the "right" errors, use the Error** parameter to pass them back instead of just printing them.
--- block/vmdk.c | 11 ++++++----- tests/qemu-iotests/059.out | 6 ++---- 2 files changed, 8 insertions(+), 9 deletions(-)
block/vmdk.c +6 -5
@@ -571,6 +571,7 @@ static int vmdk_open_vmdk4(BlockDriverState *bs,error_setg_errno (errp, -ret,"Could not read header from file '%s'" , file->filename); +return -EINVAL ; }if (header.capacity ==0 ) {uint64_t desc_offset =le64_to_cpu (header.desc_offset);
@@ -640,8 +641,8 @@ static int vmdk_open_vmdk4(BlockDriverState *bs,char buf[64 ];snprintf (buf,sizeof (buf),"VMDK version %d" ,le32_to_cpu (header.version)); -qerror_report (QERR_UNKNOWN_BLOCK_FORMAT_FEATURE , - bs->device_name,"vmdk" , buf); +error_set (errp,QERR_UNKNOWN_BLOCK_FORMAT_FEATURE , + bs->device_name,"vmdk" , buf);return -ENOTSUP ; }else if (le32_to_cpu (header.version) ==3 && (flags &BDRV_O_RDWR )) {/* VMware KB 2064959 explains that version 3 added support for
@@ -653,7 +654,7 @@ static int vmdk_open_vmdk4(BlockDriverState *bs, }if (le32_to_cpu (header.num_gtes_per_gt) >512 ) { -error_report ("L2 table size too big" ); +error_setg (errp,"L2 table size too big" );return -EINVAL ; }
@@ -669,8 +670,8 @@ static int vmdk_open_vmdk4(BlockDriverState *bs, }if (bdrv_getlength (file) <le64_to_cpu (header.grain_offset) *BDRV_SECTOR_SIZE ) { -error_report ("File truncated, expecting at least %lld bytes" , -le64_to_cpu (header.grain_offset) *BDRV_SECTOR_SIZE ); +error_setg (errp,"File truncated, expecting at least %lld bytes" , +le64_to_cpu (header.grain_offset) *BDRV_SECTOR_SIZE );return -EINVAL ; }
tests/qemu-iotests/059.out +2 -4
@@ -7,8 +7,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': Invalid argument +qemu-io: can't open device TEST_DIR/t.vmdk: L2 table size too big no file open, try 'help open' === Testing too big L1 table size ===
@@ -2045,8 +2044,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': Invalid argument +qemu-img: Could not open 'TEST_DIR/t.IMGFMT': File truncated, expecting at least 13172736 bytes === Testing version 3 === image: TEST_DIR/iotest-version3.IMGFMT
Signature · 1 line
1.8.5.3
Re: [Qemu-devel] [PATCH 18/20] vmdk: correctly propagate errors
Quoted 81 lines · Paolo Bonzini
Now that we can return the "right" errors, use the Error** parameter to pass them back instead of just printing them.
Signed-off-by Paolo Bonzini <[email protected]>--- block/vmdk.c | 11 ++++++----- tests/qemu-iotests/059.out | 6 ++---- 2 files changed, 8 insertions(+), 9 deletions(-)block/vmdk.c +6
-5@@ -571,6 +571,7 @@ static int vmdk_open_vmdk4(BlockDriverState *bs,error_setg_errno (errp, -ret,"Could not read header from file '%s'" , file->filename); +return -EINVAL ; }if (header.capacity ==0 ) {uint64_t desc_offset =le64_to_cpu (header.desc_offset);@@ -640,8 +641,8 @@ static int vmdk_open_vmdk4(BlockDriverState *bs,char buf[64 ];snprintf (buf,sizeof (buf),"VMDK version %d" ,le32_to_cpu (header.version)); -qerror_report (QERR_UNKNOWN_BLOCK_FORMAT_FEATURE , - bs->device_name,"vmdk" , buf); +error_set (errp,QERR_UNKNOWN_BLOCK_FORMAT_FEATURE , + bs->device_name,"vmdk" , buf);return -ENOTSUP ; }else if (le32_to_cpu (header.version) ==3 && (flags &BDRV_O_RDWR )) {/* VMware KB 2064959 explains that version 3 added support for @@ -653,7 +654,7 @@ static int vmdk_open_vmdk4(BlockDriverState *bs, }if (le32_to_cpu (header.num_gtes_per_gt) >512 ) { -error_report ("L2 table size too big" ); +error_setg (errp,"L2 table size too big" );return -EINVAL ; }@@ -669,8 +670,8 @@ static int vmdk_open_vmdk4(BlockDriverState *bs, }if (bdrv_getlength (file) <le64_to_cpu (header.grain_offset) *BDRV_SECTOR_SIZE ) { -error_report ("File truncated, expecting at least %lld bytes" , -le64_to_cpu (header.grain_offset) *BDRV_SECTOR_SIZE ); +error_setg (errp,"File truncated, expecting at least %lld bytes" , +le64_to_cpu (header.grain_offset) *BDRV_SECTOR_SIZE );return -EINVAL ; }tests/qemu-iotests/059.out +2
-4@@ -7,8 +7,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': Invalid argument +qemu-io: can't open device TEST_DIR/t.vmdk: L2 table size too big no file open, try 'help open' === Testing too big L1 table size ===@@ -2045,8 +2044,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': Invalid argument +qemu-img: Could not open 'TEST_DIR/t.IMGFMT': File truncated, expecting at least 13172736 bytes === Testing version 3 === image: TEST_DIR/iotest-version3.IMGFMTSignature · 1 line
1.8.5.3
PATCH 19/20 block: do not abuse EMEDIUMTYPE
In reply to Paolo BonziniReturning "Wrong medium type" for an image that does not have a valid header is a bit weird. Improve the error by mentioning what format was trying to open it.
--- block/bochs.c | 3 ++- block/cow.c | 3 ++- block/parallels.c | 3 ++- block/qcow.c | 3 ++- block/qcow2.c | 2 +- block/qed.c | 3 ++- block/vdi.c | 4 ++-- block/vmdk.c | 6 ++++-- block/vpc.c | 3 ++- 9 files changed, 19 insertions(+), 11 deletions(-)
block/bochs.c +2 -1
@@ -129,7 +129,8 @@ static int bochs_open(BlockDriverState *bs, QDict *options, int flags, strcmp(bochs.subtype, GROWING_TYPE) || ((le32_to_cpu(bochs.version) != HEADER_VERSION) && (le32_to_cpu(bochs.version) != HEADER_V1))) { -return -EMEDIUMTYPE ; +error_setg (errp,"invalid Bochs image header\n" ); +return -EINVAL ; }if (le32_to_cpu (bochs.version) ==HEADER_V1 ) {
block/cow.c +2 -1
@@ -74,7 +74,8 @@ static int cow_open(BlockDriverState *bs, QDict *options, int flags, }if (be32_to_cpu (cow_header.magic) !=COW_MAGIC ) { - ret = -EMEDIUMTYPE ; +error_setg (errp,"invalid COW image header\n" ); + ret = -EINVAL ; goto fail; }
block/parallels.c +2 -1
@@ -85,7 +85,8 @@ static int parallels_open(BlockDriverState *bs, QDict *options, int flags,if (memcmp (ph.magic,HEADER_MAGIC ,16 ) || (le32_to_cpu (ph.version) !=HEADER_VERSION )) { - ret = -EMEDIUMTYPE ; +error_setg (errp,"invalid Parallels image header\n" ); + ret = -EINVAL ; goto fail; }
block/qcow.c +2 -1
@@ -113,7 +113,8 @@ static int qcow_open(BlockDriverState *bs, QDict *options, int flags,be64_to_cpus (&header.l1_table_offset);if (header.magic !=QCOW_MAGIC ) { - ret = -EMEDIUMTYPE ; +error_setg (errp,"invalid qcow image header\n" ); + ret = -EINVAL ; goto fail; }if (header.version !=QCOW_VERSION ) {
block/qcow2.c +1 -1
@@ -449,7 +449,7 @@ static int qcow2_open(BlockDriverState *bs, QDict *options, int flags,if (header.magic !=QCOW_MAGIC ) {error_setg (errp,"Image is not in qcow2 format" ); - ret = -EMEDIUMTYPE ; + ret = -EINVAL ; goto fail; }if (header.version <2 || header.version >3 ) {
block/qed.c +2 -1
@@ -391,7 +391,8 @@ static int bdrv_qed_open(BlockDriverState *bs, QDict *options, int flags,qed_header_le_to_cpu (&le_header, &s->header);if (s->header.magic !=QED_MAGIC ) { -return -EMEDIUMTYPE ; +error_setg (errp,"invalid QED image header\n" ); +return -EINVAL ; }if (s->header.features & ~QED_FEATURE_MASK ) {/* image uses unsupported feature bits */
block/vdi.c +2 -2
@@ -395,8 +395,8 @@ static int vdi_open(BlockDriverState *bs, QDict *options, int flags, }if (header.signature !=VDI_SIGNATURE ) { -logout ("bad vdi signature %08x\n" , header.signature); - ret = -EMEDIUMTYPE ; +error_setg (errp,"invalid VDI image (bad signature %08x)\n" , header.signature); + ret = -EINVAL ; goto fail; }else if (header.version !=VDI_VERSION_1_1 ) { logout("unsupported version %u.%u\n",
block/vmdk.c +4 -2
@@ -747,7 +747,8 @@ static int vmdk_open_sparse(BlockDriverState *bs,return vmdk_open_vmdk4 (bs, file, flags, errp);break ;default : -return -EMEDIUMTYPE ; +error_setg (errp,"invalid VMDK image header\n" ); +return -EINVAL ;break ; } }
@@ -859,7 +860,8 @@ static int vmdk_open_desc_file(BlockDriverState *bs, int flags, char *buf,BDRVVmdkState *s = bs->opaque;if (vmdk_parse_description (buf,"createType" , ct,sizeof (ct))) { - ret = -EMEDIUMTYPE ; +error_setg (errp,"invalid VMDK image descriptor\n" ); + ret = -EINVAL ; goto exit; } if (strcmp(ct, "monolithicFlat") &&
block/vpc.c +2 -1
@@ -190,7 +190,8 @@ static int vpc_open(BlockDriverState *bs, QDict *options, int flags, goto fail; }if (strncmp (footer->creator,"conectix" ,8 )) { - ret = -EMEDIUMTYPE ; +error_setg (errp,"invalid VPC image\n" ); + ret = -EINVAL ; goto fail; } disk_type =VHD_FIXED ;
Signature · 1 line
1.8.5.3
Re: [Qemu-devel] [PATCH 19/20] block: do not abuse EMEDIUMTYPE
block/bochs.c static int bochs_open(BlockDriverState *bs, QDict *options, int flags, · line 132
Quoted 10 lines · Paolo Bonzini
block/bochs.c +1
-1@@ -129,7 +129,8 @@ static int bochs_open(BlockDriverState *bs, QDict *options, int flags, strcmp(bochs.subtype, GROWING_TYPE) || ((le32_to_cpu(bochs.version) != HEADER_VERSION) && (le32_to_cpu(bochs.version) != HEADER_V1))) { -return -EMEDIUMTYPE ; +error_setg (errp,"invalid Bochs image header\n" );
Ending "\n" is not necessary, including all following cases.
Quoted 4 lines
block/bochs.c +1
-0+return -EINVAL ; }if (le32_to_cpu (bochs.version) ==HEADER_V1 ) {
<snip>
block/qcow2.c static int qcow2_open(BlockDriverState *bs, QDict *options, int flags, · line 451
Quoted 8 lines
block/qcow2.c +0
-0@@ -449,7 +449,7 @@ static int qcow2_open(BlockDriverState *bs, QDict *options, int flags,if (header.magic !=QCOW_MAGIC ) {error_setg (errp,"Image is not in qcow2 format" );
It might be good to have a consistent message pattern in qcow2 as others. Is it worth adding a QERR_ error class for unexpected format magic?
Fam
Quoted 5 lines
block/qcow2.c +1
-1- ret = -EMEDIUMTYPE ; + ret = -EINVAL ; goto fail; }if (header.version <2 || header.version >3 ) {
Re: [Qemu-devel] [PATCH 19/20] block: do not abuse EMEDIUMTYPE
Il 10/02/2014 09:47, Fam Zheng ha scritto:
Quoted 5 lines
Quoted 4 lines
block/qcow2.c static int qcow2_open(BlockDriverState *bs, QDict *options, int flags, · line 451
Quoted 4 lines
block/qcow2.c +0
-0@@ -449,7 +449,7 @@ static int qcow2_open(BlockDriverState *bs, QDict *options, int flags,if (header.magic !=QCOW_MAGIC ) {error_setg (errp,"Image is not in qcow2 format" );It might be good to have a consistent message pattern in qcow2 as others.
Right, I'll fix the others.
Quoted 1 line
Is it worth adding a
QERR_error class for unexpected format magic?
We're not adding QERR_ anymore, but if anyone has ideas I can do something to improve the homogeneity of the errors.
Paolo
PATCH 20/20 vdi: say why an image is bad
In reply to Paolo BonziniInstead of just putting it in debugging output, we can now put the value in an Error.
--- block/vdi.c | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-)
block/vdi.c +16 -9
@@ -399,39 +399,46 @@ static int vdi_open(BlockDriverState *bs, QDict *options, int flags, ret = -EINVAL ; goto fail; }else if (header.version !=VDI_VERSION_1_1 ) { -logout ("unsupported version %u.%u\n" , - header.version >>16 , header.version &0xffff ); +error_setg (errp,"unsupported VDI image (version %u.%u)\n" , + header.version >>16 , header.version &0xffff ); ret = -ENOTSUP ; goto fail; }else if (header.offset_bmap %SECTOR_SIZE !=0 ) {/* We only support block maps which start on a sector boundary. */ -logout ("unsupported block map offset 0x%x B\n" , header.offset_bmap); +error_setg (errp,"unsupported VDI image (unaligned block map offset 0x%x)\n" , + header.offset_bmap); ret = -ENOTSUP ; goto fail; }else if (header.offset_data %SECTOR_SIZE !=0 ) {/* We only support data blocks which start on a sector boundary. */ -logout ("unsupported data offset 0x%x B\n" , header.offset_data); +error_setg (errp,"unsupported VDI image (unaligned data offset 0x%x)\n" , + header.offset_data); ret = -ENOTSUP ; goto fail; }else if (header.sector_size !=SECTOR_SIZE ) { -logout ("unsupported sector size %u B\n" , header.sector_size); +error_setg (errp,"unsupported VDI image (sector size %u is not %u)\n" , + header.sector_size,SECTOR_SIZE ); ret = -ENOTSUP ; goto fail; }else if (header.block_size !=1 * MiB) { -logout ("unsupported block size %u B\n" , header.block_size); +error_setg (errp,"unsupported VDI image (sector size %u is not %u)\n" , + header.block_size,1 * MiB); ret = -ENOTSUP ; goto fail; }else if (header.disk_size > (uint64_t )header.blocks_in_image * header.block_size) { -logout ("unsupported disk size %" PRIu64" B\n" , header.disk_size); +error_setg (errp,"unsupported VDI image (disk size %" PRIu64", " +"image bitmap has room for %" PRIu64")\n" , + header.disk_size, + (uint64_t )header.blocks_in_image * header.block_size); ret = -ENOTSUP ; goto fail; }else if (!uuid_is_null (header.uuid_link)) { -logout ("link uuid != 0, unsupported\n" ); +error_setg (errp,"unsupported VDI image (non-NULL link UUID)\n" ); ret = -ENOTSUP ; goto fail; }else if (!uuid_is_null (header.uuid_parent)) { -logout ("parent uuid != 0, unsupported\n" ); +error_setg (errp,"unsupported VDI image (non-NULL parent UUID)\n" ); ret = -ENOTSUP ; goto fail; }
Signature · 1 line
1.8.5.3
Re: [Qemu-devel] [PATCH 20/20] vdi: say why an image is bad
Quoted 35 lines · Paolo Bonzini
Instead of just putting it in debugging output, we can now put the value in an Error.
Signed-off-by Paolo Bonzini <[email protected]>--- block/vdi.c | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-)block/vdi.c +6
-4@@ -399,39 +399,46 @@ static int vdi_open(BlockDriverState *bs, QDict *options, int flags, ret = -EINVAL ; goto fail; }else if (header.version !=VDI_VERSION_1_1 ) { -logout ("unsupported version %u.%u\n" , - header.version >>16 , header.version &0xffff ); +error_setg (errp,"unsupported VDI image (version %u.%u)\n" , + header.version >>16 , header.version &0xffff ); ret = -ENOTSUP ; goto fail; }else if (header.offset_bmap %SECTOR_SIZE !=0 ) {/* We only support block maps which start on a sector boundary. */ -logout ("unsupported block map offset 0x%x B\n" , header.offset_bmap); +error_setg (errp,"unsupported VDI image (unaligned block map offset 0x%x)\n" , + header.offset_bmap); ret = -ENOTSUP ; goto fail; }else if (header.offset_data %SECTOR_SIZE !=0 ) {/* We only support data blocks which start on a sector boundary. */ -logout ("unsupported data offset 0x%x B\n" , header.offset_data); +error_setg (errp,"unsupported VDI image (unaligned data offset 0x%x)\n" , + header.offset_data); ret = -ENOTSUP ;
block/vdi.c static int vdi_open(BlockDriverState *bs, QDict *options, int flags, · line 424
Quoted 10 lines
block/vdi.c +3
-2goto fail; }else if (header.sector_size !=SECTOR_SIZE ) { -logout ("unsupported sector size %u B\n" , header.sector_size); +error_setg (errp,"unsupported VDI image (sector size %u is not %u)\n" , + header.sector_size,SECTOR_SIZE ); ret = -ENOTSUP ; goto fail; }else if (header.block_size !=1 * MiB) { -logout ("unsupported block size %u B\n" , header.block_size); + error_setg(errp, "unsupported VDI image (sector size %u is not %u)\n",
s/sector size/block size/
block/vdi.c static int vdi_open(BlockDriverState *bs, QDict *options, int flags, · line 433
Quoted 10 lines
block/vdi.c +5
-1+ header.block_size, 1 * MiB); ret = -ENOTSUP ; goto fail; }else if (header.disk_size > (uint64_t )header.blocks_in_image * header.block_size) { -logout ("unsupported disk size %" PRIu64" B\n" , header.disk_size); +error_setg (errp,"unsupported VDI image (disk size %" PRIu64", " +"image bitmap has room for %" PRIu64")\n" , + header.disk_size, + (uint64_t )header.blocks_in_image * header.block_size);
Improved, good!
block/vdi.c static int vdi_open(BlockDriverState *bs, QDict *options, int flags, · line 444
Quoted 13 lines
block/vdi.c +2
-2ret = -ENOTSUP ; goto fail; }else if (!uuid_is_null (header.uuid_link)) { -logout ("link uuid != 0, unsupported\n" ); +error_setg (errp,"unsupported VDI image (non-NULL link UUID)\n" ); ret = -ENOTSUP ; goto fail; }else if (!uuid_is_null (header.uuid_parent)) { -logout ("parent uuid != 0, unsupported\n" ); +error_setg (errp,"unsupported VDI image (non-NULL parent UUID)\n" ); ret = -ENOTSUP ; goto fail; }
There are also unnecessary ending "\n" in the messages.
Fam