qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v5 0/2] block/blkio: support fd passing for virtio-blk-vhost-vdpa driver
@ 2023-05-30  7:19 Stefano Garzarella
  2023-05-30  7:19 ` [PATCH v5 1/2] block/blkio: use qemu_open() to support fd passing for virtio-blk Stefano Garzarella
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Stefano Garzarella @ 2023-05-30  7:19 UTC (permalink / raw)
  To: qemu-devel
  Cc: Philippe Mathieu-Daudé, Kevin Wolf, Thomas Huth,
	Markus Armbruster, Paolo Bonzini, Stefan Hajnoczi, Eric Blake,
	Marc-André Lureau, Jonathon Jongsma, Daniel P. Berrangé,
	Hanna Reitz, qemu-block, Stefano Garzarella

v5:
- moved `features` to the object level to simplify libvirt code [Jonathon]
- wrapped a line too long in the documentation [Markus]
- added Stefan R-b tags

v4: https://lore.kernel.org/qemu-devel/20230526150304.158206-1-sgarzare@redhat.com/
- added patch 02 to allow libvirt to discover we support fdset [Markus]
- modified the commit description of patch 01

v3: https://lore.kernel.org/qemu-devel/20230511091527.46620-1-sgarzare@redhat.com/
- use qemu_open() on `path` to simplify libvirt code [Jonathon]
- remove patch 01 since we are not using monitor_fd_param() anymore

v2: https://lore.kernel.org/qemu-devel/20230504092843.62493-1-sgarzare@redhat.com/
- added patch 01 to use monitor_fd_param() in the blkio module
- use monitor_fd_param() to parse the fd like vhost devices [Stefan]

v1: https://lore.kernel.org/qemu-devel/20230502145050.224615-1-sgarzare@redhat.com/

The virtio-blk-vhost-vdpa driver in libblkio 1.3.0 supports the new
'fd' property. Let's expose this to the user, so the management layer
can pass the file descriptor of an already opened vhost-vdpa character
device. This is useful especially when the device can only be accessed
with certain privileges.

Stefano Garzarella (2):
  block/blkio: use qemu_open() to support fd passing for virtio-blk
  qapi: add '@fdset' feature for BlockdevOptionsVirtioBlkVhostVdpa

 meson.build          |  4 ++++
 qapi/block-core.json |  6 +++++
 block/blkio.c        | 53 ++++++++++++++++++++++++++++++++++++--------
 3 files changed, 54 insertions(+), 9 deletions(-)

-- 
2.40.1



^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v5 1/2] block/blkio: use qemu_open() to support fd passing for virtio-blk
  2023-05-30  7:19 [PATCH v5 0/2] block/blkio: support fd passing for virtio-blk-vhost-vdpa driver Stefano Garzarella
@ 2023-05-30  7:19 ` Stefano Garzarella
  2023-05-30  7:19 ` [PATCH v5 2/2] qapi: add '@fdset' feature for BlockdevOptionsVirtioBlkVhostVdpa Stefano Garzarella
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Stefano Garzarella @ 2023-05-30  7:19 UTC (permalink / raw)
  To: qemu-devel
  Cc: Philippe Mathieu-Daudé, Kevin Wolf, Thomas Huth,
	Markus Armbruster, Paolo Bonzini, Stefan Hajnoczi, Eric Blake,
	Marc-André Lureau, Jonathon Jongsma, Daniel P. Berrangé,
	Hanna Reitz, qemu-block, Stefano Garzarella

Some virtio-blk drivers (e.g. virtio-blk-vhost-vdpa) supports the fd
passing. Let's expose this to the user, so the management layer
can pass the file descriptor of an already opened path.

If the libblkio virtio-blk driver supports fd passing, let's always
use qemu_open() to open the `path`, so we can handle fd passing
from the management layer through the "/dev/fdset/N" special path.

Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
---

Notes:
    v4:
    - modified commit description
    
    v3:
    - use qemu_open() on `path` to simplify libvirt code [Jonathon]

 block/blkio.c | 53 ++++++++++++++++++++++++++++++++++++++++++---------
 1 file changed, 44 insertions(+), 9 deletions(-)

diff --git a/block/blkio.c b/block/blkio.c
index 0cdc99a729..6a6f20f923 100644
--- a/block/blkio.c
+++ b/block/blkio.c
@@ -672,25 +672,60 @@ static int blkio_virtio_blk_common_open(BlockDriverState *bs,
 {
     const char *path = qdict_get_try_str(options, "path");
     BDRVBlkioState *s = bs->opaque;
-    int ret;
+    bool fd_supported = false;
+    int fd, ret;
 
     if (!path) {
         error_setg(errp, "missing 'path' option");
         return -EINVAL;
     }
 
-    ret = blkio_set_str(s->blkio, "path", path);
-    qdict_del(options, "path");
-    if (ret < 0) {
-        error_setg_errno(errp, -ret, "failed to set path: %s",
-                         blkio_get_error_msg());
-        return ret;
-    }
-
     if (!(flags & BDRV_O_NOCACHE)) {
         error_setg(errp, "cache.direct=off is not supported");
         return -EINVAL;
     }
+
+    if (blkio_get_int(s->blkio, "fd", &fd) == 0) {
+        fd_supported = true;
+    }
+
+    /*
+     * If the libblkio driver supports fd passing, let's always use qemu_open()
+     * to open the `path`, so we can handle fd passing from the management
+     * layer through the "/dev/fdset/N" special path.
+     */
+    if (fd_supported) {
+        int open_flags;
+
+        if (flags & BDRV_O_RDWR) {
+            open_flags = O_RDWR;
+        } else {
+            open_flags = O_RDONLY;
+        }
+
+        fd = qemu_open(path, open_flags, errp);
+        if (fd < 0) {
+            return -EINVAL;
+        }
+
+        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 {
+        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;
+        }
+    }
+
+    qdict_del(options, "path");
+
     return 0;
 }
 
-- 
2.40.1



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v5 2/2] qapi: add '@fdset' feature for BlockdevOptionsVirtioBlkVhostVdpa
  2023-05-30  7:19 [PATCH v5 0/2] block/blkio: support fd passing for virtio-blk-vhost-vdpa driver Stefano Garzarella
  2023-05-30  7:19 ` [PATCH v5 1/2] block/blkio: use qemu_open() to support fd passing for virtio-blk Stefano Garzarella
@ 2023-05-30  7:19 ` Stefano Garzarella
  2023-05-31 13:37 ` [PATCH v5 0/2] block/blkio: support fd passing for virtio-blk-vhost-vdpa driver Jonathon Jongsma
  2023-06-01 15:08 ` Stefan Hajnoczi
  3 siblings, 0 replies; 5+ messages in thread
From: Stefano Garzarella @ 2023-05-30  7:19 UTC (permalink / raw)
  To: qemu-devel
  Cc: Philippe Mathieu-Daudé, Kevin Wolf, Thomas Huth,
	Markus Armbruster, Paolo Bonzini, Stefan Hajnoczi, Eric Blake,
	Marc-André Lureau, Jonathon Jongsma, Daniel P. Berrangé,
	Hanna Reitz, qemu-block, Stefano Garzarella

The virtio-blk-vhost-vdpa driver in libblkio 1.3.0 supports the fd
passing through the new 'fd' property.

Since now we are using qemu_open() on '@path' if the virtio-blk driver
supports the fd passing, let's announce it.
In this way, the management layer can pass the file descriptor of an
already opened vhost-vdpa character device. This is useful especially
when the device can only be accessed with certain privileges.

Add the '@fdset' feature only when the virtio-blk-vhost-vdpa driver
in libblkio supports it.

Suggested-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
---

Notes:
    v5:
    - moved `features` to the object level to simplify libvirt code [Jonathon]
    - wrapped a line too long in the documentation [Markus]
    v4:
    - added this patch to allow libvirt to discover we support fdset [Markus]

 meson.build          | 4 ++++
 qapi/block-core.json | 6 ++++++
 2 files changed, 10 insertions(+)

diff --git a/meson.build b/meson.build
index 2d48aa1e2e..4a9fa4c435 100644
--- a/meson.build
+++ b/meson.build
@@ -2106,6 +2106,10 @@ config_host_data.set('CONFIG_LZO', lzo.found())
 config_host_data.set('CONFIG_MPATH', mpathpersist.found())
 config_host_data.set('CONFIG_MPATH_NEW_API', mpathpersist_new_api)
 config_host_data.set('CONFIG_BLKIO', blkio.found())
+if blkio.found()
+  config_host_data.set('CONFIG_BLKIO_VHOST_VDPA_FD',
+                       blkio.version().version_compare('>=1.3.0'))
+endif
 config_host_data.set('CONFIG_CURL', curl.found())
 config_host_data.set('CONFIG_CURSES', curses.found())
 config_host_data.set('CONFIG_GBM', gbm.found())
diff --git a/qapi/block-core.json b/qapi/block-core.json
index 98d9116dae..4bf89171c6 100644
--- a/qapi/block-core.json
+++ b/qapi/block-core.json
@@ -3955,10 +3955,16 @@
 #
 # @path: path to the vhost-vdpa character device.
 #
+# Features:
+# @fdset: Member @path supports the special "/dev/fdset/N" path
+#     (since 8.1)
+#
 # Since: 7.2
 ##
 { 'struct': 'BlockdevOptionsVirtioBlkVhostVdpa',
   'data': { 'path': 'str' },
+  'features': [ { 'name' :'fdset',
+                  'if': 'CONFIG_BLKIO_VHOST_VDPA_FD' } ],
   'if': 'CONFIG_BLKIO' }
 
 ##
-- 
2.40.1



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v5 0/2] block/blkio: support fd passing for virtio-blk-vhost-vdpa driver
  2023-05-30  7:19 [PATCH v5 0/2] block/blkio: support fd passing for virtio-blk-vhost-vdpa driver Stefano Garzarella
  2023-05-30  7:19 ` [PATCH v5 1/2] block/blkio: use qemu_open() to support fd passing for virtio-blk Stefano Garzarella
  2023-05-30  7:19 ` [PATCH v5 2/2] qapi: add '@fdset' feature for BlockdevOptionsVirtioBlkVhostVdpa Stefano Garzarella
@ 2023-05-31 13:37 ` Jonathon Jongsma
  2023-06-01 15:08 ` Stefan Hajnoczi
  3 siblings, 0 replies; 5+ messages in thread
From: Jonathon Jongsma @ 2023-05-31 13:37 UTC (permalink / raw)
  To: Stefano Garzarella, qemu-devel
  Cc: Philippe Mathieu-Daudé, Kevin Wolf, Thomas Huth,
	Markus Armbruster, Paolo Bonzini, Stefan Hajnoczi, Eric Blake,
	Marc-André Lureau, Daniel P. Berrangé, Hanna Reitz,
	qemu-block

On 5/30/23 2:19 AM, Stefano Garzarella wrote:
> v5:
> - moved `features` to the object level to simplify libvirt code [Jonathon]
> - wrapped a line too long in the documentation [Markus]
> - added Stefan R-b tags
> 
> v4: https://lore.kernel.org/qemu-devel/20230526150304.158206-1-sgarzare@redhat.com/
> - added patch 02 to allow libvirt to discover we support fdset [Markus]
> - modified the commit description of patch 01
> 
> v3: https://lore.kernel.org/qemu-devel/20230511091527.46620-1-sgarzare@redhat.com/
> - use qemu_open() on `path` to simplify libvirt code [Jonathon]
> - remove patch 01 since we are not using monitor_fd_param() anymore
> 
> v2: https://lore.kernel.org/qemu-devel/20230504092843.62493-1-sgarzare@redhat.com/
> - added patch 01 to use monitor_fd_param() in the blkio module
> - use monitor_fd_param() to parse the fd like vhost devices [Stefan]
> 
> v1: https://lore.kernel.org/qemu-devel/20230502145050.224615-1-sgarzare@redhat.com/
> 
> The virtio-blk-vhost-vdpa driver in libblkio 1.3.0 supports the new
> 'fd' property. Let's expose this to the user, so the management layer
> can pass the file descriptor of an already opened vhost-vdpa character
> device. This is useful especially when the device can only be accessed
> with certain privileges.
> 
> Stefano Garzarella (2):
>    block/blkio: use qemu_open() to support fd passing for virtio-blk
>    qapi: add '@fdset' feature for BlockdevOptionsVirtioBlkVhostVdpa
> 
>   meson.build          |  4 ++++
>   qapi/block-core.json |  6 +++++
>   block/blkio.c        | 53 ++++++++++++++++++++++++++++++++++++--------
>   3 files changed, 54 insertions(+), 9 deletions(-)
> 


Looks good from my perspective as a libvirt developer.

Thanks,
Jonathon



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v5 0/2] block/blkio: support fd passing for virtio-blk-vhost-vdpa driver
  2023-05-30  7:19 [PATCH v5 0/2] block/blkio: support fd passing for virtio-blk-vhost-vdpa driver Stefano Garzarella
                   ` (2 preceding siblings ...)
  2023-05-31 13:37 ` [PATCH v5 0/2] block/blkio: support fd passing for virtio-blk-vhost-vdpa driver Jonathon Jongsma
@ 2023-06-01 15:08 ` Stefan Hajnoczi
  3 siblings, 0 replies; 5+ messages in thread
From: Stefan Hajnoczi @ 2023-06-01 15:08 UTC (permalink / raw)
  To: Stefano Garzarella
  Cc: qemu-devel, Philippe Mathieu-Daudé, Kevin Wolf, Thomas Huth,
	Markus Armbruster, Paolo Bonzini, Eric Blake,
	Marc-André Lureau, Jonathon Jongsma, Daniel P. Berrangé,
	Hanna Reitz, qemu-block

[-- Attachment #1: Type: text/plain, Size: 1822 bytes --]

On Tue, May 30, 2023 at 09:19:39AM +0200, Stefano Garzarella wrote:
> v5:
> - moved `features` to the object level to simplify libvirt code [Jonathon]
> - wrapped a line too long in the documentation [Markus]
> - added Stefan R-b tags
> 
> v4: https://lore.kernel.org/qemu-devel/20230526150304.158206-1-sgarzare@redhat.com/
> - added patch 02 to allow libvirt to discover we support fdset [Markus]
> - modified the commit description of patch 01
> 
> v3: https://lore.kernel.org/qemu-devel/20230511091527.46620-1-sgarzare@redhat.com/
> - use qemu_open() on `path` to simplify libvirt code [Jonathon]
> - remove patch 01 since we are not using monitor_fd_param() anymore
> 
> v2: https://lore.kernel.org/qemu-devel/20230504092843.62493-1-sgarzare@redhat.com/
> - added patch 01 to use monitor_fd_param() in the blkio module
> - use monitor_fd_param() to parse the fd like vhost devices [Stefan]
> 
> v1: https://lore.kernel.org/qemu-devel/20230502145050.224615-1-sgarzare@redhat.com/
> 
> The virtio-blk-vhost-vdpa driver in libblkio 1.3.0 supports the new
> 'fd' property. Let's expose this to the user, so the management layer
> can pass the file descriptor of an already opened vhost-vdpa character
> device. This is useful especially when the device can only be accessed
> with certain privileges.
> 
> Stefano Garzarella (2):
>   block/blkio: use qemu_open() to support fd passing for virtio-blk
>   qapi: add '@fdset' feature for BlockdevOptionsVirtioBlkVhostVdpa
> 
>  meson.build          |  4 ++++
>  qapi/block-core.json |  6 +++++
>  block/blkio.c        | 53 ++++++++++++++++++++++++++++++++++++--------
>  3 files changed, 54 insertions(+), 9 deletions(-)
> 
> -- 
> 2.40.1
> 

Thanks, applied to my block tree:
https://gitlab.com/stefanha/qemu/commits/block

Stefan

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-06-01 15:09 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-05-30  7:19 [PATCH v5 0/2] block/blkio: support fd passing for virtio-blk-vhost-vdpa driver Stefano Garzarella
2023-05-30  7:19 ` [PATCH v5 1/2] block/blkio: use qemu_open() to support fd passing for virtio-blk Stefano Garzarella
2023-05-30  7:19 ` [PATCH v5 2/2] qapi: add '@fdset' feature for BlockdevOptionsVirtioBlkVhostVdpa Stefano Garzarella
2023-05-31 13:37 ` [PATCH v5 0/2] block/blkio: support fd passing for virtio-blk-vhost-vdpa driver Jonathon Jongsma
2023-06-01 15:08 ` Stefan Hajnoczi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).