block/blkio: fix opening virtio-blk drivers
v2 cover block/blkio: fix opening virtio-blk drivers
There is a problem with virtio-blk-vhost-vdpa.
The first patch does some preparation changes. The second and third patches fix the issues, the last patch tries to prepare QEMU for a future version of libblkio where we can use blkio_set_fd() to check whether the property is supported or not.
While testing, I realized that the main problem was that qemu_open() does not support UDS, but still the problem with blkio_connect() which can fail remains.
v2:
- added first patch in preparation of the others
- reworked patch 2 retrying blkio_connect [Stefan]
- added patch 3 since qemu_open() fails in UDS
- changed patch 4 commit description [Stefan]
v1: https://lore.kernel.org/qemu-devel/[email protected]/
Based on stefanha/block branch.
Stefano Garzarella (4):
block/blkio: move blkio_connect() in the drivers functions block/blkio: retry blkio_connect() if it fails using fd block/blkio: fall back on using path when fd setting fails block/blkio: use blkio_set_int("fd") to check fd support
block/blkio.c | 108 +++++++++++++++++++++++++++++++++++--------------- 1 file changed, 75 insertions(+), 33 deletions(-)
Signature · 1 line
2.41.0
PATCH v2 1/4 block/blkio: move blkio_connect() in the drivers functions
This is in preparation for the next patch, where for virtio-blk drivers we need to handle the failure of blkio_connect().
Let's also rename the *_open() functions to *_connect() to make the code reflect the changes applied.
--- block/blkio.c | 67 ++++++++++++++++++++++++++++++--------------------- 1 file changed, 40 insertions(+), 27 deletions(-)
block/blkio.c +40 -27
@@ -603,8 +603,8 @@ static void blkio_unregister_buf(BlockDriverState *bs, void *host, size_t size) } } -static int blkio_io_uring_open (BlockDriverState *bs,QDict *options,int flags, -Error **errp) +static int blkio_io_uring_connect (BlockDriverState *bs,QDict *options, +int flags,Error **errp) {const char *filename =qdict_get_str (options,"filename" );BDRVBlkioState *s = bs->opaque;
@@ -627,11 +627,18 @@ static int blkio_io_uring_open(BlockDriverState *bs, QDict *options, int flags, } } + ret =blkio_connect (s->blkio); +if (ret <0 ) { +error_setg_errno (errp, -ret,"blkio_connect failed: %s" , +blkio_get_error_msg ()); +return ret; + } +return 0 ; } -static int blkio_nvme_io_uring (BlockDriverState *bs,QDict *options,int flags, -Error **errp) +static int blkio_nvme_io_uring_connect (BlockDriverState *bs,QDict *options, +int flags,Error **errp) {const char *path =qdict_get_try_str (options,"path" );BDRVBlkioState *s = bs->opaque;
@@ -655,11 +662,18 @@ static int blkio_nvme_io_uring(BlockDriverState *bs, QDict *options, int flags,return -EINVAL ; } + ret =blkio_connect (s->blkio); +if (ret <0 ) { +error_setg_errno (errp, -ret,"blkio_connect failed: %s" , +blkio_get_error_msg ()); +return ret; + } +return 0 ; } -static int blkio_virtio_blk_common_open (BlockDriverState *bs, -QDict *options,int flags,Error **errp) +static int blkio_virtio_blk_connect (BlockDriverState *bs,QDict *options, +int flags,Error **errp) {const char *path =qdict_get_try_str (options,"path" );BDRVBlkioState *s = bs->opaque;
@@ -718,6 +732,13 @@ static int blkio_virtio_blk_common_open(BlockDriverState *bs, } } + ret =blkio_connect (s->blkio); +if (ret <0 ) { +error_setg_errno (errp, -ret,"blkio_connect failed: %s" , +blkio_get_error_msg ()); +return ret; + } +qdict_del (options,"path" );return 0 ;
@@ -737,24 +758,6 @@ static int blkio_file_open(BlockDriverState *bs, QDict *options, int flags,return ret; } -if (strcmp (blkio_driver,"io_uring" ) ==0 ) { - ret =blkio_io_uring_open (bs, options, flags, errp); - }else if (strcmp (blkio_driver,"nvme-io_uring" ) ==0 ) { - ret =blkio_nvme_io_uring (bs, options, flags, errp); - }else if (strcmp (blkio_driver,"virtio-blk-vfio-pci" ) ==0 ) { - ret =blkio_virtio_blk_common_open (bs, options, flags, errp); - }else if (strcmp (blkio_driver,"virtio-blk-vhost-user" ) ==0 ) { - ret =blkio_virtio_blk_common_open (bs, options, flags, errp); - }else if (strcmp (blkio_driver,"virtio-blk-vhost-vdpa" ) ==0 ) { - ret =blkio_virtio_blk_common_open (bs, options, flags, errp); - }else { -g_assert_not_reached (); - } -if (ret <0 ) { -blkio_destroy (&s->blkio); -return ret; - } -if (!(flags &BDRV_O_RDWR )) { ret =blkio_set_bool (s->blkio,"read-only" , true);if (ret <0 ) {
@@ -765,10 +768,20 @@ static int blkio_file_open(BlockDriverState *bs, QDict *options, int flags, } } - ret =blkio_connect (s->blkio); +if (strcmp (blkio_driver,"io_uring" ) ==0 ) { + ret =blkio_io_uring_connect (bs, options, flags, errp); + }else if (strcmp (blkio_driver,"nvme-io_uring" ) ==0 ) { + ret =blkio_nvme_io_uring_connect (bs, options, flags, errp); + }else if (strcmp (blkio_driver,"virtio-blk-vfio-pci" ) ==0 ) { + ret =blkio_virtio_blk_connect (bs, options, flags, errp); + }else if (strcmp (blkio_driver,"virtio-blk-vhost-user" ) ==0 ) { + ret =blkio_virtio_blk_connect (bs, options, flags, errp); + }else if (strcmp (blkio_driver,"virtio-blk-vhost-vdpa" ) ==0 ) { + ret =blkio_virtio_blk_connect (bs, options, flags, errp); + }else { +g_assert_not_reached (); + }if (ret <0 ) { -error_setg_errno (errp, -ret,"blkio_connect failed: %s" , -blkio_get_error_msg ());blkio_destroy (&s->blkio);return ret; }
Signature · 1 line
2.41.0
PATCH v2 2/4 block/blkio: retry blkio_connect() if it fails using `fd`
In reply to Stefano Garzarellalibblkio 1.3.0 added support of "fd" property for virtio-blk-vhost-vdpa driver. In QEMU, starting from commit cad2ccc395 ("block/blkio: use qemu_open() to support fd passing for virtio-blk") we are using blkio_get_int(..., "fd") to check if the "fd" property is supported for all the virtio-blk-* driver.
Unfortunately that property is also available for those driver that do not support it, such as virtio-blk-vhost-user.
So, blkio_get_int() is not enough to check whether the driver supports the fd property or not. This is because the virito-blk common libblkio driver only checks whether or not fd is set during blkio_connect() and fails with -EINVAL for those transports that do not support it (all except vhost-vdpa for now).
So let's handle the blkio_connect() failure, retrying it using path directly.
---
Notes:
v2:
- reworked retrying blkio_connect() [Stefan]
block/blkio.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+)
block/blkio.c +29 -0
@@ -733,6 +733,35 @@ static int blkio_virtio_blk_connect(BlockDriverState *bs, QDict *options, } ret =blkio_connect (s->blkio); +/* +* If the libblkio driver doesn't support the `fd` property, blkio_connect() +* will fail with -EINVAL. So let's try calling blkio_connect() again by +* directly setting `path`. +*/ +if (fd_supported && ret == -EINVAL ) { +qemu_close (fd); + +/* +* We need to clear the `fd` property we set previously by setting +* it to -1. +*/ + ret =blkio_set_int (s->blkio,"fd" ,-1 ); +if (ret <0 ) { +error_setg_errno (errp, -ret,"failed to set fd: %s" , +blkio_get_error_msg ()); +return ret; + } + + ret =blkio_set_str (s->blkio,"path" , path); +if (ret <0 ) { +error_setg_errno (errp, -ret,"failed to set path: %s" , +blkio_get_error_msg ()); +return ret; + } + + ret =blkio_connect (s->blkio); + } +if (ret <0 ) {error_setg_errno (errp, -ret,"blkio_connect failed: %s" ,blkio_get_error_msg ());
Signature · 1 line
2.41.0
PATCH v2 3/4 block/blkio: fall back on using `path` when `fd` setting fails
In reply to Stefano Garzarellaqemu_open() fails if called with an unix domain socket in this way:
-blockdev node-name=drive0,driver=virtio-blk-vhost-user,path=vhost-user-blk.sock,cache.direct=on: Could not open 'vhost-user-blk.sock': No such device or address
Since virtio-blk-vhost-user does not support fd passing, lets always fall back on using path` if we fail the fd passing.
--- block/blkio.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-)
block/blkio.c +10 -10
@@ -711,19 +711,19 @@ static int blkio_virtio_blk_connect(BlockDriverState *bs, QDict *options,* In order to open the device read-only, we are using the `read-only` * property of the libblkio driver in blkio_file_open(). */ - fd =qemu_open (path,O_RDWR , errp); + fd =qemu_open (path,O_RDWR ,NULL );if (fd <0 ) { -return -EINVAL ; + fd_supported = false; + }else { + ret =blkio_set_int (s->blkio,"fd" , fd); +if (ret <0 ) { + fd_supported = false; +qemu_close (fd); + } } + } - ret =blkio_set_int (s->blkio,"fd" , fd); -if (ret <0 ) { -error_setg_errno (errp, -ret,"failed to set fd: %s" , -blkio_get_error_msg ()); -qemu_close (fd); -return ret; - } - }else { +if (!fd_supported) { ret =blkio_set_str (s->blkio,"path" , path);if (ret <0 ) { error_setg_errno(errp, -ret, "failed to set path: %s",
Signature · 1 line
2.41.0
PATCH v2 4/4 block/blkio: use blkio_set_int("fd") to check fd support
In reply to Stefano GarzarellaSetting the fd property fails with virtio-blk-* libblkio drivers that do not support fd passing since
https://gitlab.com/libblkio/libblkio/-/merge_requests/208.
Getting the fd property, on the other hand, always succeeds for virtio-blk-* libblkio drivers even when they don't support fd passing.
This patch switches to setting the fd property because it is a better mechanism for probing fd passing support than getting the fd property.
---
Notes:
v2:
- changed commit description [Stefan]
block/blkio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
block/blkio.c +1 -1
@@ -690,7 +690,7 @@ static int blkio_virtio_blk_connect(BlockDriverState *bs, QDict *options,return -EINVAL ; } -if (blkio_get_int (s->blkio,"fd" , &fd) ==0 ) { +if (blkio_set_int (s->blkio,"fd" ,-1 ) ==0 ) { fd_supported = true; }
Signature · 1 line
2.41.0
Stefan Hajnoczi
AppliedQuoted 19 lines · Stefano Garzarella
There is a problem with virtio-blk-vhost-vdpa.
The first patch does some preparation changes. The second and third patches fix the issues, the last patch tries to prepare QEMU for a future version of libblkio where we can useblkio_set_fd()to check whether the property is supported or not.While testing, I realized that the main problem was that
qemu_open()does not support UDS, but still the problem withblkio_connect()which can fail remains.v2:
- added first patch in preparation of the others
- reworked patch 2 retryingblkio_connect[Stefan]
- added patch 3 sinceqemu_open()fails in UDS
- changed patch 4 commit description [Stefan]v1: https://lore.kernel.org/qemu-devel/[email protected]/
Based on stefanha/block branch.
Quoted 12 lines
Stefano Garzarella (4):
block/blkio: moveblkio_connect()in the drivers functions block/blkio: retryblkio_connect()if it fails usingfdblock/blkio: fall back on usingpathwhenfdsetting fails block/blkio: useblkio_set_int("fd")to check fd supportblock/blkio.c | 108 +++++++++++++++++++++++++++++++++++--------------- 1 file changed, 75 insertions(+), 33 deletions(-)Signature · 1 line
2.41.0
Thanks, applied to my block tree:
https://gitlab.com/stefanha/qemu/commits/block
Stefan