public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
* [pve-devel] [PATCH-SERIES qemu 0/3] prepartion for blockdev
@ 2025-06-26 16:04 Fiona Ebner
  2025-06-26 16:04 ` [pve-devel] [PATCH qemu 1/3] PVE backup: prepare for the switch to using blockdev rather than drive Fiona Ebner
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Fiona Ebner @ 2025-06-26 16:04 UTC (permalink / raw)
  To: pve-devel

Preparation to make the zeroinit driver and backup work with blockdev.

Fiona Ebner (3):
  PVE backup: prepare for the switch to using blockdev rather than drive
  block/zeroinit: support using as blockdev driver
  blockdev: query file child QMP command

 block/zeroinit.c     | 12 ++++++++---
 blockdev.c           | 22 +++++++++++++++++++
 pve-backup.c         | 51 +++++++++++++++++++++++++++++++++-----------
 qapi/block-core.json | 18 ++++++++++++++--
 4 files changed, 86 insertions(+), 17 deletions(-)

-- 
2.47.2



_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel


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

* [pve-devel] [PATCH qemu 1/3] PVE backup: prepare for the switch to using blockdev rather than drive
  2025-06-26 16:04 [pve-devel] [PATCH-SERIES qemu 0/3] prepartion for blockdev Fiona Ebner
@ 2025-06-26 16:04 ` Fiona Ebner
  2025-06-26 16:04 ` [pve-devel] [PATCH qemu 2/3] block/zeroinit: support using as blockdev driver Fiona Ebner
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 7+ messages in thread
From: Fiona Ebner @ 2025-06-26 16:04 UTC (permalink / raw)
  To: pve-devel

Also allow finding block nodes by their node name rather than just via
an associated block backend, which might not exist for block nodes.

For regular drives, it is essential to not use the throttle group,
because otherwise the limits intended only for the guest would also
apply to the backup job.

Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
---
 pve-backup.c | 51 +++++++++++++++++++++++++++++++++++++++------------
 1 file changed, 39 insertions(+), 12 deletions(-)

diff --git a/pve-backup.c b/pve-backup.c
index 0450303017..457fcb7e5c 100644
--- a/pve-backup.c
+++ b/pve-backup.c
@@ -847,29 +847,56 @@ static PVEBackupDevInfo coroutine_fn GRAPH_RDLOCK *get_single_device_info(
     Error **errp)
 {
     BlockBackend *blk = blk_by_name(device);
-    if (!blk) {
-        error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND,
-                  "Device '%s' not found", device);
-        return NULL;
+    BlockDriverState *root_bs, *bs;
+
+    if (blk) {
+        root_bs = bs = blk_bs(blk);
+    } else {
+        /* TODO PVE 10 - fleecing will always be attached without blk */
+        root_bs = bs = bdrv_find_node(device);
+        if (!bs) {
+            error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND,
+                      "Device '%s' not found", device);
+            return NULL;
+        }
+        /* For TPM, bs is already correct, otherwise need the file child. */
+        if (!strncmp(bs->drv->format_name, "throttle", 8)) {
+            if (!bs->file || !bs->file->bs) {
+                error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND,
+                          "Device '%s' not found (no file child)", device);
+                return NULL;
+            }
+            bs = bs->file->bs;
+        }
     }
-    BlockDriverState *bs = blk_bs(blk);
+
     if (!bdrv_co_is_inserted(bs)) {
         error_setg(errp, "Device '%s' has no medium", device);
         return NULL;
     }
+
     PVEBackupDevInfo *di = g_new0(PVEBackupDevInfo, 1);
     di->bs = bs;
-    di->device_name = g_strdup(bdrv_get_device_name(bs));
+    /* Need the name of the root node, e.g. drive-scsi0 */
+    di->device_name = g_strdup(bdrv_get_device_or_node_name(root_bs));
 
     if (device_uses_fleecing && device_uses_fleecing(device)) {
         g_autofree gchar *fleecing_devid = g_strconcat(device, "-fleecing", NULL);
+        BlockDriverState *fleecing_bs;
+
         BlockBackend *fleecing_blk = blk_by_name(fleecing_devid);
-        if (!fleecing_blk) {
-            error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND,
-                      "Device '%s' not found", fleecing_devid);
-            goto fail;
+        if (fleecing_blk) {
+            fleecing_bs = blk_bs(fleecing_blk);
+        } else {
+            /* TODO PVE 10 - fleecing will always be attached without blk */
+            fleecing_bs = bdrv_find_node(fleecing_devid);
+            if (!fleecing_bs) {
+                error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND,
+                          "Device '%s' not found", fleecing_devid);
+                goto fail;
+            }
         }
-        BlockDriverState *fleecing_bs = blk_bs(fleecing_blk);
+
         if (!bdrv_co_is_inserted(fleecing_bs)) {
             error_setg(errp, "Device '%s' has no medium", fleecing_devid);
             goto fail;
@@ -927,7 +954,7 @@ static GList coroutine_fn GRAPH_RDLOCK *get_device_info(
 
             PVEBackupDevInfo *di = g_new0(PVEBackupDevInfo, 1);
             di->bs = bs;
-            di->device_name = g_strdup(bdrv_get_device_name(bs));
+            di->device_name = g_strdup(bdrv_get_device_or_node_name(bs));
             di_list = g_list_append(di_list, di);
         }
     }
-- 
2.47.2



_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel


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

* [pve-devel] [PATCH qemu 2/3] block/zeroinit: support using as blockdev driver
  2025-06-26 16:04 [pve-devel] [PATCH-SERIES qemu 0/3] prepartion for blockdev Fiona Ebner
  2025-06-26 16:04 ` [pve-devel] [PATCH qemu 1/3] PVE backup: prepare for the switch to using blockdev rather than drive Fiona Ebner
@ 2025-06-26 16:04 ` Fiona Ebner
  2025-06-26 16:04 ` [pve-devel] [PATCH qemu 3/3] blockdev: query file child QMP command Fiona Ebner
  2025-06-27 15:51 ` [pve-devel] [PATCH qemu 4/4] block/alloc-track: support using as blockdev driver Fiona Ebner
  3 siblings, 0 replies; 7+ messages in thread
From: Fiona Ebner @ 2025-06-26 16:04 UTC (permalink / raw)
  To: pve-devel

Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
---
 block/zeroinit.c     | 12 +++++++++---
 qapi/block-core.json |  5 +++--
 2 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/block/zeroinit.c b/block/zeroinit.c
index f9d513db15..036edb17f5 100644
--- a/block/zeroinit.c
+++ b/block/zeroinit.c
@@ -66,6 +66,7 @@ static int zeroinit_open(BlockDriverState *bs, QDict *options, int flags,
     QemuOpts *opts;
     Error *local_err = NULL;
     int ret;
+    const char *next = NULL;
 
     s->extents = 0;
 
@@ -77,9 +78,14 @@ static int zeroinit_open(BlockDriverState *bs, QDict *options, int flags,
         goto fail;
     }
 
-    /* Open the raw file */
-    ret = bdrv_open_file_child(qemu_opt_get(opts, "x-next"), options, "next",
-                               bs, &local_err);
+
+    next = qemu_opt_get(opts, "x-next");
+
+    if (next) {
+        ret = bdrv_open_file_child(next, options, "next", bs, &local_err);
+    } else { /* when opened as a blockdev, there is no 'next' option */
+        ret = bdrv_open_file_child(NULL, options, "file", bs, &local_err);
+    }
     if (ret < 0) {
         error_propagate(errp, local_err);
         goto fail;
diff --git a/qapi/block-core.json b/qapi/block-core.json
index 2fb51215f2..f8ed564cf0 100644
--- a/qapi/block-core.json
+++ b/qapi/block-core.json
@@ -3586,7 +3586,7 @@
             { 'name': 'virtio-blk-vfio-pci', 'if': 'CONFIG_BLKIO' },
             { 'name': 'virtio-blk-vhost-user', 'if': 'CONFIG_BLKIO' },
             { 'name': 'virtio-blk-vhost-vdpa', 'if': 'CONFIG_BLKIO' },
-            'vmdk', 'vpc', 'vvfat' ] }
+            'vmdk', 'vpc', 'vvfat', 'zeroinit' ] }
 
 ##
 # @BlockdevOptionsFile:
@@ -5172,7 +5172,8 @@
                       'if': 'CONFIG_BLKIO' },
       'vmdk':       'BlockdevOptionsGenericCOWFormat',
       'vpc':        'BlockdevOptionsGenericFormat',
-      'vvfat':      'BlockdevOptionsVVFAT'
+      'vvfat':      'BlockdevOptionsVVFAT',
+      'zeroinit':   'BlockdevOptionsGenericFormat'
   } }
 
 ##
-- 
2.47.2



_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel


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

* [pve-devel] [PATCH qemu 3/3] blockdev: query file child QMP command
  2025-06-26 16:04 [pve-devel] [PATCH-SERIES qemu 0/3] prepartion for blockdev Fiona Ebner
  2025-06-26 16:04 ` [pve-devel] [PATCH qemu 1/3] PVE backup: prepare for the switch to using blockdev rather than drive Fiona Ebner
  2025-06-26 16:04 ` [pve-devel] [PATCH qemu 2/3] block/zeroinit: support using as blockdev driver Fiona Ebner
@ 2025-06-26 16:04 ` Fiona Ebner
  2025-06-30 12:43   ` Fabian Grünbichler
  2025-06-27 15:51 ` [pve-devel] [PATCH qemu 4/4] block/alloc-track: support using as blockdev driver Fiona Ebner
  3 siblings, 1 reply; 7+ messages in thread
From: Fiona Ebner @ 2025-06-26 16:04 UTC (permalink / raw)
  To: pve-devel

There currently does not seem to be a good way to obtain information
about the file child of a node, so add a custom command. The
query-block and query-named-block-nodes commands lack the necessary
info and while x-debug-query-block-graph exists, that is explicitly
only for debugging and experimental.

This is requried for e.g. blockdev-mirror in PVE to determine the
node below the top throttle node.

Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
---

Alternatively, we could think about adding the node name of the file
child to the info returned by query-named-block-nodes. I can give that
a shot and also ask upstream which approach is prefered.

 blockdev.c           | 22 ++++++++++++++++++++++
 qapi/block-core.json | 13 +++++++++++++
 2 files changed, 35 insertions(+)

diff --git a/blockdev.c b/blockdev.c
index 17de5d2ae4..3be209767a 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -57,6 +57,7 @@
 #include "system/system.h"
 #include "system/iothread.h"
 #include "block/block_int.h"
+#include "block/qapi.h"
 #include "block/trace.h"
 #include "system/runstate.h"
 #include "system/replay.h"
@@ -2782,6 +2783,27 @@ XDbgBlockGraph *qmp_x_debug_query_block_graph(Error **errp)
     return bdrv_get_xdbg_block_graph(errp);
 }
 
+BlockDeviceInfo *qmp_block_node_query_file_child(const char *node_name,
+                                                 Error **errp)
+{
+    GRAPH_RDLOCK_GUARD_MAINLOOP();
+
+    BlockDriverState *bs;
+
+    bs = bdrv_find_node(node_name);
+    if (!bs) {
+        error_setg(errp, "Failed to find node with node-name='%s'", node_name);
+        return NULL;
+    }
+
+    if (!bs->file || !bs->file->bs) {
+        error_setg(errp, "Node '%s' has no 'file' child", node_name);
+        return NULL;
+    }
+
+    return bdrv_block_device_info(NULL, bs->file->bs, false, errp);
+}
+
 void qmp_blockdev_backup(BlockdevBackup *backup, Error **errp)
 {
     TransactionAction action = {
diff --git a/qapi/block-core.json b/qapi/block-core.json
index f8ed564cf0..6c683b00ec 100644
--- a/qapi/block-core.json
+++ b/qapi/block-core.json
@@ -2463,6 +2463,19 @@
   'features': [ 'unstable' ],
   'allow-preconfig': true }
 
+##
+# @block-node-query-file-child:
+#
+# Get information about a child of the specified block node.
+#
+# @node-name: the block node name of the node to query.
+#
+# Returns: the BlockDeviceInfo of the file child.
+##
+{ 'command': 'block-node-query-file-child',
+  'data': { 'node-name': 'str' },
+  'returns': 'BlockDeviceInfo' }
+
 ##
 # @drive-mirror:
 #
-- 
2.47.2



_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel


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

* [pve-devel] [PATCH qemu 4/4] block/alloc-track: support using as blockdev driver
  2025-06-26 16:04 [pve-devel] [PATCH-SERIES qemu 0/3] prepartion for blockdev Fiona Ebner
                   ` (2 preceding siblings ...)
  2025-06-26 16:04 ` [pve-devel] [PATCH qemu 3/3] blockdev: query file child QMP command Fiona Ebner
@ 2025-06-27 15:51 ` Fiona Ebner
  3 siblings, 0 replies; 7+ messages in thread
From: Fiona Ebner @ 2025-06-27 15:51 UTC (permalink / raw)
  To: pve-devel

Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
---

Follow-up required for live-{import,restore}.

 qapi/block-core.json | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)

diff --git a/qapi/block-core.json b/qapi/block-core.json
index 6c683b00ec..79581288d8 100644
--- a/qapi/block-core.json
+++ b/qapi/block-core.json
@@ -3580,7 +3580,8 @@
 # Since: 2.9
 ##
 { 'enum': 'BlockdevDriver',
-  'data': [ 'blkdebug', 'blklogwrites', 'blkreplay', 'blkverify', 'bochs',
+  'data': [ 'alloc-track',
+            'blkdebug', 'blklogwrites', 'blkreplay', 'blkverify', 'bochs',
             'cloop', 'compress', 'copy-before-write', 'copy-on-read', 'dmg',
             'file', 'snapshot-access', 'ftp', 'ftps',
             {'name': 'gluster', 'features': [ 'deprecated' ] },
@@ -3681,6 +3682,21 @@
 { 'struct': 'BlockdevOptionsNull',
   'data': { '*size': 'int', '*latency-ns': 'uint64', '*read-zeroes': 'bool' } }
 
+##
+# @BlockdevOptionsAllocTrack:
+#
+# Driver specific block device options for the alloc-track backend.
+#
+# @backing: backing file with the data.
+#
+# @auto-remove: whether the alloc-track driver should drop itself
+#     after completing the stream.
+#
+##
+{ 'struct': 'BlockdevOptionsAllocTrack',
+  'base': 'BlockdevOptionsGenericFormat',
+  'data': { 'auto-remove': 'bool', 'backing': 'BlockdevRefOrNull' } }
+
 ##
 # @BlockdevOptionsPbs:
 #
@@ -5127,6 +5143,7 @@
             '*detect-zeroes': 'BlockdevDetectZeroesOptions' },
   'discriminator': 'driver',
   'data': {
+      'alloc-track':'BlockdevOptionsAllocTrack',
       'blkdebug':   'BlockdevOptionsBlkdebug',
       'blklogwrites':'BlockdevOptionsBlklogwrites',
       'blkverify':  'BlockdevOptionsBlkverify',
-- 
2.47.2



_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel


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

* Re: [pve-devel] [PATCH qemu 3/3] blockdev: query file child QMP command
  2025-06-26 16:04 ` [pve-devel] [PATCH qemu 3/3] blockdev: query file child QMP command Fiona Ebner
@ 2025-06-30 12:43   ` Fabian Grünbichler
  2025-06-30 14:23     ` Fiona Ebner
  0 siblings, 1 reply; 7+ messages in thread
From: Fabian Grünbichler @ 2025-06-30 12:43 UTC (permalink / raw)
  To: Proxmox VE development discussion

On June 26, 2025 6:04 pm, Fiona Ebner wrote:
> There currently does not seem to be a good way to obtain information
> about the file child of a node, so add a custom command. The
> query-block and query-named-block-nodes commands lack the necessary
> info and while x-debug-query-block-graph exists, that is explicitly
> only for debugging and experimental.
> 
> This is requried for e.g. blockdev-mirror in PVE to determine the
> node below the top throttle node.
> 
> Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
> ---
> 
> Alternatively, we could think about adding the node name of the file
> child to the info returned by query-named-block-nodes. I can give that
> a shot and also ask upstream which approach is prefered.

that might be nice, or alternatively if we go with our custom solution
here for now - give it a prefixed name to avoid potential clashes with a
future upstream variant?

> 
>  blockdev.c           | 22 ++++++++++++++++++++++
>  qapi/block-core.json | 13 +++++++++++++
>  2 files changed, 35 insertions(+)
> 
> diff --git a/blockdev.c b/blockdev.c
> index 17de5d2ae4..3be209767a 100644
> --- a/blockdev.c
> +++ b/blockdev.c
> @@ -57,6 +57,7 @@
>  #include "system/system.h"
>  #include "system/iothread.h"
>  #include "block/block_int.h"
> +#include "block/qapi.h"
>  #include "block/trace.h"
>  #include "system/runstate.h"
>  #include "system/replay.h"
> @@ -2782,6 +2783,27 @@ XDbgBlockGraph *qmp_x_debug_query_block_graph(Error **errp)
>      return bdrv_get_xdbg_block_graph(errp);
>  }
>  
> +BlockDeviceInfo *qmp_block_node_query_file_child(const char *node_name,
> +                                                 Error **errp)
> +{
> +    GRAPH_RDLOCK_GUARD_MAINLOOP();
> +
> +    BlockDriverState *bs;
> +
> +    bs = bdrv_find_node(node_name);
> +    if (!bs) {
> +        error_setg(errp, "Failed to find node with node-name='%s'", node_name);
> +        return NULL;
> +    }
> +
> +    if (!bs->file || !bs->file->bs) {
> +        error_setg(errp, "Node '%s' has no 'file' child", node_name);
> +        return NULL;
> +    }
> +
> +    return bdrv_block_device_info(NULL, bs->file->bs, false, errp);
> +}
> +
>  void qmp_blockdev_backup(BlockdevBackup *backup, Error **errp)
>  {
>      TransactionAction action = {
> diff --git a/qapi/block-core.json b/qapi/block-core.json
> index f8ed564cf0..6c683b00ec 100644
> --- a/qapi/block-core.json
> +++ b/qapi/block-core.json
> @@ -2463,6 +2463,19 @@
>    'features': [ 'unstable' ],
>    'allow-preconfig': true }
>  
> +##
> +# @block-node-query-file-child:
> +#
> +# Get information about a child of the specified block node.
> +#
> +# @node-name: the block node name of the node to query.
> +#
> +# Returns: the BlockDeviceInfo of the file child.
> +##
> +{ 'command': 'block-node-query-file-child',
> +  'data': { 'node-name': 'str' },
> +  'returns': 'BlockDeviceInfo' }
> +
>  ##
>  # @drive-mirror:
>  #
> -- 
> 2.47.2
> 
> 
> 
> _______________________________________________
> pve-devel mailing list
> pve-devel@lists.proxmox.com
> https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
> 
> 
> 


_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel


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

* Re: [pve-devel] [PATCH qemu 3/3] blockdev: query file child QMP command
  2025-06-30 12:43   ` Fabian Grünbichler
@ 2025-06-30 14:23     ` Fiona Ebner
  0 siblings, 0 replies; 7+ messages in thread
From: Fiona Ebner @ 2025-06-30 14:23 UTC (permalink / raw)
  To: Proxmox VE development discussion, Fabian Grünbichler

Am 30.06.25 um 14:43 schrieb Fabian Grünbichler:
> On June 26, 2025 6:04 pm, Fiona Ebner wrote:
>> There currently does not seem to be a good way to obtain information
>> about the file child of a node, so add a custom command. The
>> query-block and query-named-block-nodes commands lack the necessary
>> info and while x-debug-query-block-graph exists, that is explicitly
>> only for debugging and experimental.
>>
>> This is requried for e.g. blockdev-mirror in PVE to determine the
>> node below the top throttle node.
>>
>> Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
>> ---
>>
>> Alternatively, we could think about adding the node name of the file
>> child to the info returned by query-named-block-nodes. I can give that
>> a shot and also ask upstream which approach is prefered.
> 
> that might be nice, or alternatively if we go with our custom solution
> here for now - give it a prefixed name to avoid potential clashes with a
> future upstream variant?

Since the variant mentioned here is much nicer for the
unplug-after-mirror scenario and seems quite natural, I'll go with that:

https://lore.kernel.org/qemu-devel/20250630141421.1558724-1-f.ebner@proxmox.com/


_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel

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

end of thread, other threads:[~2025-06-30 14:23 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-06-26 16:04 [pve-devel] [PATCH-SERIES qemu 0/3] prepartion for blockdev Fiona Ebner
2025-06-26 16:04 ` [pve-devel] [PATCH qemu 1/3] PVE backup: prepare for the switch to using blockdev rather than drive Fiona Ebner
2025-06-26 16:04 ` [pve-devel] [PATCH qemu 2/3] block/zeroinit: support using as blockdev driver Fiona Ebner
2025-06-26 16:04 ` [pve-devel] [PATCH qemu 3/3] blockdev: query file child QMP command Fiona Ebner
2025-06-30 12:43   ` Fabian Grünbichler
2025-06-30 14:23     ` Fiona Ebner
2025-06-27 15:51 ` [pve-devel] [PATCH qemu 4/4] block/alloc-track: support using as blockdev driver Fiona Ebner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal