public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
* [PATCH-SERIES storage/qemu-server/container 0/4] volume resize improvements, part 1
@ 2026-11-09 15:39 Fiona Ebner
  2026-11-09 15:39 ` [PATCH storage 1/4] lvm: factor out helper for querying LV size Fiona Ebner
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Fiona Ebner @ 2026-11-09 15:39 UTC (permalink / raw)
  To: pve-devel

Improve resize for qcow2 on LVM, and fix propagating the error status
for 'pct' and 'qm'.

I am working on other improvements in the guest's resize API endpoints
and UI which should improve the situation further, but are independent
of the storage part here.

storage:

Fiona Ebner (2):
  lvm: factor out helper for querying LV size
  lvm: qcow2 resize: do not abort if LV size is already large enough

 src/PVE/Storage/LVMPlugin.pm | 87 ++++++++++++++++++++++--------------
 1 file changed, 53 insertions(+), 34 deletions(-)


qemu-server:

Fiona Ebner (1):
  qm: disk resize: propagate exit status from worker

 src/PVE/CLI/qm.pm | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)


container:

Fiona Ebner (1):
  pct: resize: propagate exit status from worker

 src/PVE/CLI/pct.pm | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)


Summary over all repositories:
  3 files changed, 62 insertions(+), 36 deletions(-)

-- 
Generated by git-murpp 0.5.0




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

* [PATCH storage 1/4] lvm: factor out helper for querying LV size
  2026-11-09 15:39 [PATCH-SERIES storage/qemu-server/container 0/4] volume resize improvements, part 1 Fiona Ebner
@ 2026-11-09 15:39 ` Fiona Ebner
  2026-11-09 15:39 ` [PATCH storage 2/4] lvm: qcow2 resize: do not abort if LV size is already large enough Fiona Ebner
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Fiona Ebner @ 2026-11-09 15:39 UTC (permalink / raw)
  To: pve-devel

No functional change intended. To be used for checking the size of the
LV underlying a qcow2 volume at the beginning of a resize operation.

Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
---
 src/PVE/Storage/LVMPlugin.pm | 54 ++++++++++++++++++++----------------
 1 file changed, 30 insertions(+), 24 deletions(-)

diff --git a/src/PVE/Storage/LVMPlugin.pm b/src/PVE/Storage/LVMPlugin.pm
index 0ab9dc2d..53120e47 100644
--- a/src/PVE/Storage/LVMPlugin.pm
+++ b/src/PVE/Storage/LVMPlugin.pm
@@ -406,6 +406,35 @@ sub lvm_list_volumes {
     return $lvs;
 }
 
+my sub lvm_lv_size_info {
+    my ($path, $timeout) = @_;
+
+    my $cmd = [
+        '/sbin/lvs',
+        '--separator',
+        ':',
+        '--noheadings',
+        '--units',
+        'b',
+        '--unbuffered',
+        '--nosuffix',
+        '--options',
+        'lv_size',
+        $path,
+    ];
+
+    my $size;
+    run_command(
+        $cmd,
+        timeout => $timeout,
+        errmsg => "can't get size of '$path'",
+        outfunc => sub {
+            $size = int(shift);
+        },
+    );
+    return wantarray ? ($size, 'raw', 0, undef) : $size;
+}
+
 # Acquire the storage lock for a cleanup step of volume or snapshot removal, retrying the
 # acquisition so transient lock contention on a busy cluster does not leave a half-removed volume
 # behind. Only the acquisition is retried; $code_started keeps a failure inside the locked section
@@ -1694,30 +1723,7 @@ sub volume_size_info {
 
     return PVE::Storage::Plugin::file_size_info($path, $timeout, $format) if $format eq 'qcow2';
 
-    my $cmd = [
-        '/sbin/lvs',
-        '--separator',
-        ':',
-        '--noheadings',
-        '--units',
-        'b',
-        '--unbuffered',
-        '--nosuffix',
-        '--options',
-        'lv_size',
-        $path,
-    ];
-
-    my $size;
-    run_command(
-        $cmd,
-        timeout => $timeout,
-        errmsg => "can't get size of '$path'",
-        outfunc => sub {
-            $size = int(shift);
-        },
-    );
-    return wantarray ? ($size, 'raw', 0, undef) : $size;
+    return lvm_lv_size_info($path, $timeout);
 }
 
 my sub volume_snapshot_locked {
-- 
2.47.3





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

* [PATCH storage 2/4] lvm: qcow2 resize: do not abort if LV size is already large enough
  2026-11-09 15:39 [PATCH-SERIES storage/qemu-server/container 0/4] volume resize improvements, part 1 Fiona Ebner
  2026-11-09 15:39 ` [PATCH storage 1/4] lvm: factor out helper for querying LV size Fiona Ebner
@ 2026-11-09 15:39 ` Fiona Ebner
  2026-11-09 15:39 ` [PATCH qemu-server 3/4] qm: disk resize: propagate exit status from worker Fiona Ebner
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Fiona Ebner @ 2026-11-09 15:39 UTC (permalink / raw)
  To: pve-devel

The qcow2 size is used as the basis of allocation and resize
operations, and the LV size is calculated based on it. So having a
larger LV for some reason, for example after a manual resize, is not
fundamentally an issue, but the lvextend command can fail with either
of the following during a subsequent resize operation:
1. > No size change.
2. > New size given (769 extents) not larger than existing size (1025 extents)

Warn about having a larger LV size, because it is not expected, but
do not abort the operation.

Reported-by: Daniel Herzig <d.herzig@proxmox.com>
Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
---

We could also just use a normal print/warn rather than a task warning.
For small resizes, the situation might happen because of extent
rounding.

 src/PVE/Storage/LVMPlugin.pm | 33 +++++++++++++++++++++++----------
 1 file changed, 23 insertions(+), 10 deletions(-)

diff --git a/src/PVE/Storage/LVMPlugin.pm b/src/PVE/Storage/LVMPlugin.pm
index 53120e47..1b0c8020 100644
--- a/src/PVE/Storage/LVMPlugin.pm
+++ b/src/PVE/Storage/LVMPlugin.pm
@@ -1692,20 +1692,33 @@ sub volume_resize {
         $class->parse_volname($volname);
 
     my $lvmsize = calculate_lvm_size($size / 1024, $format);
-    $lvmsize = "${lvmsize}k";
 
     my $path = $class->path($scfg, $volname, $storeid, $snapname);
 
-    my $cmd = ['/sbin/lvextend', '-L', $lvmsize, $path];
+    # For qcow2, the expected size of the LV might get out of sync, so check.
+    my ($skip_lvextend, $old_lvmsize);
+    if ($format eq 'qcow2') {
+        $old_lvmsize = lvm_lv_size_info($path, 60);
+        $skip_lvextend = 1 if $old_lvmsize >= $lvmsize * 1024;
+    }
 
-    $class->cluster_lock_storage(
-        $storeid,
-        $scfg->{shared},
-        undef,
-        sub {
-            run_command($cmd, errmsg => "error resizing volume '$path'");
-        },
-    );
+    if ($skip_lvextend) {
+        my $oldsize_h = render_bytes($old_lvmsize);
+        my $size_h = render_bytes($lvmsize * 1024);
+        log_warn("LV '$path' already large enough: $oldsize_h >= $size_h");
+    } else {
+        $lvmsize = "${lvmsize}k";
+        my $cmd = ['/sbin/lvextend', '-L', $lvmsize, $path];
+
+        $class->cluster_lock_storage(
+            $storeid,
+            $scfg->{shared},
+            undef,
+            sub {
+                run_command($cmd, errmsg => "error resizing volume '$path'");
+            },
+        );
+    }
 
     if (!$running && $format eq 'qcow2') {
         my $preallocation = PVE::Storage::Plugin::preallocation_cmd_opt($scfg, $format);
-- 
2.47.3





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

* [PATCH qemu-server 3/4] qm: disk resize: propagate exit status from worker
  2026-11-09 15:39 [PATCH-SERIES storage/qemu-server/container 0/4] volume resize improvements, part 1 Fiona Ebner
  2026-11-09 15:39 ` [PATCH storage 1/4] lvm: factor out helper for querying LV size Fiona Ebner
  2026-11-09 15:39 ` [PATCH storage 2/4] lvm: qcow2 resize: do not abort if LV size is already large enough Fiona Ebner
@ 2026-11-09 15:39 ` Fiona Ebner
  2026-11-09 15:39 ` [PATCH container 4/4] pct: " Fiona Ebner
  2026-11-09 18:18 ` applied: [PATCH-SERIES storage/qemu-server/container 0/4] volume resize improvements, part 1 Thomas Lamprecht
  4 siblings, 0 replies; 6+ messages in thread
From: Fiona Ebner @ 2026-11-09 15:39 UTC (permalink / raw)
  To: pve-devel

Commit 606d9d76 ("fix #2315: api: have resize endpoint spawn a worker
task") changed the 'resize_vm' API endpoint to return a worker UPID,
but forgot to adapt the related 'qm' CLI invocation, which then always
returned success if it reached the point of forking the worker.
Fix this and propagate the exit status from that worker.

Fixes: 606d9d76 ("fix #2315: api: have resize endpoint spawn a worker task")
Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
---
 src/PVE/CLI/qm.pm | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/PVE/CLI/qm.pm b/src/PVE/CLI/qm.pm
index 2fb43246..f62fe036 100755
--- a/src/PVE/CLI/qm.pm
+++ b/src/PVE/CLI/qm.pm
@@ -1439,7 +1439,8 @@ our $cmddef = {
         'move' =>
             ["PVE::API2::Qemu", 'move_vm_disk', ['vmid', 'disk', 'storage'], {%node}, $upid_exit],
         rescan => [__PACKAGE__, 'rescan', []],
-        resize => ["PVE::API2::Qemu", 'resize_vm', ['vmid', 'disk', 'size'], {%node}],
+        resize =>
+            ["PVE::API2::Qemu", 'resize_vm', ['vmid', 'disk', 'size'], {%node}, $upid_exit],
         unlink => ["PVE::API2::Qemu", 'unlink', ['vmid'], {%node}],
     },
 
-- 
2.47.3





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

* [PATCH container 4/4] pct: resize: propagate exit status from worker
  2026-11-09 15:39 [PATCH-SERIES storage/qemu-server/container 0/4] volume resize improvements, part 1 Fiona Ebner
                   ` (2 preceding siblings ...)
  2026-11-09 15:39 ` [PATCH qemu-server 3/4] qm: disk resize: propagate exit status from worker Fiona Ebner
@ 2026-11-09 15:39 ` Fiona Ebner
  2026-11-09 18:18 ` applied: [PATCH-SERIES storage/qemu-server/container 0/4] volume resize improvements, part 1 Thomas Lamprecht
  4 siblings, 0 replies; 6+ messages in thread
From: Fiona Ebner @ 2026-11-09 15:39 UTC (permalink / raw)
  To: pve-devel

Commit 9f3f796 ("Start a worker in lxc resize.") changed the
'resize_vm' API endpoint to return a worker UPID, but forgot to adapt
the related 'pct' CLI invocation, which then always returned success
if it reached the point of forking the worker. Fix this and propagate
the exit status from that worker.

Fixes: 9f3f796 ("Start a worker in lxc resize.")
Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
---
 src/PVE/CLI/pct.pm | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/src/PVE/CLI/pct.pm b/src/PVE/CLI/pct.pm
index ceb0bea..8c210a0 100755
--- a/src/PVE/CLI/pct.pm
+++ b/src/PVE/CLI/pct.pm
@@ -1102,7 +1102,13 @@ our $cmddef = {
     ],
     set => ['PVE::API2::LXC::Config', 'update_vm', ['vmid'], { node => $nodename }],
 
-    resize => ["PVE::API2::LXC", 'resize_vm', ['vmid', 'disk', 'size'], { node => $nodename }],
+    resize => [
+        "PVE::API2::LXC",
+        'resize_vm',
+        ['vmid', 'disk', 'size'],
+        { node => $nodename },
+        $upid_exit,
+    ],
 
     create =>
         ['PVE::API2::LXC', 'create_vm', ['vmid', 'ostemplate'], { node => $nodename }, $upid_exit],
-- 
2.47.3





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

* applied: [PATCH-SERIES storage/qemu-server/container 0/4] volume resize improvements, part 1
  2026-11-09 15:39 [PATCH-SERIES storage/qemu-server/container 0/4] volume resize improvements, part 1 Fiona Ebner
                   ` (3 preceding siblings ...)
  2026-11-09 15:39 ` [PATCH container 4/4] pct: " Fiona Ebner
@ 2026-11-09 18:18 ` Thomas Lamprecht
  4 siblings, 0 replies; 6+ messages in thread
From: Thomas Lamprecht @ 2026-11-09 18:18 UTC (permalink / raw)
  To: pve-devel, Fiona Ebner

On Mon, 09 Nov 2026 16:39:33 +0100, Fiona Ebner wrote:
> Improve resize for qcow2 on LVM, and fix propagating the error status
> for 'pct' and 'qm'.
> 
> I am working on other improvements in the guest's resize API endpoints
> and UI which should improve the situation further, but are independent
> of the storage part here.
> 
> [...]

Applied, thanks!

[storage] applied to pve-storage.git (master)
[1/2] lvm: factor out helper for querying LV size
      https://git.proxmox.com/?p=pve-storage.git;a=commitdiff;h=b96c6eb2e66fae6fd00b10e3a5e84d640a29b947
[2/2] lvm: qcow2 resize: do not abort if LV size is already large enough
      https://git.proxmox.com/?p=pve-storage.git;a=commitdiff;h=95c6cb1a995e534c8680f50a235af848ac69c0f6

[qemu-server] applied to qemu-server.git (master)
[1/1] qm: disk resize: propagate exit status from worker
      https://git.proxmox.com/?p=qemu-server.git;a=commitdiff;h=c557a20984175261926c3bc1c85688b2593cb2fb

[container] applied to git/pve-container.git (master)
[1/1] pct: resize: propagate exit status from worker
      https://git.proxmox.com/?p=qemu-server.git;a=commitdiff;h=d43343346fbc6929926b3907f1389b1ffe86289e




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

end of thread, other threads:[~2026-11-09 18:19 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-09 15:39 [PATCH-SERIES storage/qemu-server/container 0/4] volume resize improvements, part 1 Fiona Ebner
2026-11-09 15:39 ` [PATCH storage 1/4] lvm: factor out helper for querying LV size Fiona Ebner
2026-11-09 15:39 ` [PATCH storage 2/4] lvm: qcow2 resize: do not abort if LV size is already large enough Fiona Ebner
2026-11-09 15:39 ` [PATCH qemu-server 3/4] qm: disk resize: propagate exit status from worker Fiona Ebner
2026-11-09 15:39 ` [PATCH container 4/4] pct: " Fiona Ebner
2026-11-09 18:18 ` applied: [PATCH-SERIES storage/qemu-server/container 0/4] volume resize improvements, part 1 Thomas Lamprecht

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