* [PATCH storage 0/2] rbd: avoid hanging VM start on EFI disk cache policy
@ 2026-11-20 14:10 Jonas Theisen
2026-11-20 14:10 ` [PATCH storage 1/2] rbd: only set image config if the value differs Jonas Theisen
2026-11-20 14:10 ` [PATCH storage 2/2] rbd: do not let setting the EFI disk cache policy block VM start Jonas Theisen
0 siblings, 2 replies; 3+ messages in thread
From: Jonas Theisen @ 2026-11-20 14:10 UTC (permalink / raw)
To: pve-devel
Starting a VM with an EFI disk on RBD sets the rbd_cache_policy image
config on every start. On the target of a live migration, the source
VM still holds the exclusive lock, so librbd forwards the write to it
and re-sends the request every 30 seconds until the lock owner reports
completion. 'rbd config image set' then hangs without end if:
- the lock owner never reports completion, or
- the completion arrives just after a re-send timed out, but before
the request is sent again. The requester drops it, and the lock
owner answers every further re-send of the finished request with its
result, 0 on success. That is the same answer as for a request still
in progress, so the requester waits for a completion that is never
sent again. See prepare_async_request() in librbd's ImageWatcher.cc.
The VM start on the target, and thus the migration, then hangs until
the rbd process is killed.
Patch 1 reads the current value first and only writes it if it
differs. Reading the image config does not involve the lock owner, and
after the first start the value is already set, so migrations no
longer depend on the lock owner in the common case.
This reverses the choice made in commit 590fb762 ("plugin: qemu block
device: add hints option and EFI disk hint"), which deliberately set
the value unconditionally: querying it was considered to only add
cost, and 'rbd config image get' fails if the key has not been set
yet. The extra read is one cheap command per VM start with an EFI disk
on RBD, which is a small price for not hanging the migration. The
failing 'get' on an unset key is handled by treating any error as "not
set" and falling back to writing the value, as before.
Patch 2 covers the remaining case, where the value does need to be
written while another client holds the lock: the write is aborted
after 60 seconds, which allows for one retry of the remote request,
and a failure only results in a warning. The cache policy only affects
the performance of EFI variable writes, so it should not fail the VM
start, and thus the migration.
In the best case we would not need this because the rbd command never
hangs, but there have been cases in Enterprise Support where this
exact failure mode blocked migrations.
Jonas Theisen (2):
rbd: only set image config if the value differs
rbd: do not let setting the EFI disk cache policy block VM start
src/PVE/Storage/RBDPlugin.pm | 31 ++++++++++++++++++++++++++-----
1 file changed, 26 insertions(+), 5 deletions(-)
--
2.47.3
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH storage 1/2] rbd: only set image config if the value differs
2026-11-20 14:10 [PATCH storage 0/2] rbd: avoid hanging VM start on EFI disk cache policy Jonas Theisen
@ 2026-11-20 14:10 ` Jonas Theisen
2026-11-20 14:10 ` [PATCH storage 2/2] rbd: do not let setting the EFI disk cache policy block VM start Jonas Theisen
1 sibling, 0 replies; 3+ messages in thread
From: Jonas Theisen @ 2026-11-20 14:10 UTC (permalink / raw)
To: pve-devel
Starting a VM with an EFI disk on RBD sets the rbd_cache_policy image
config on every start, including the target side of a live migration.
At that point, the source VM still holds the exclusive lock, so librbd
forwards the metadata write to the lock owner, waits for it to report
completion, and re-sends the request every 30 seconds until it does.
The 'rbd config image set' command can then hang indefinitely if:
- the lock owner never reports completion, or
- its completion arrives just after a re-send timed out, but before
the request is sent again. The requester drops the completion, and
the lock owner answers every further re-send of the finished request
with its result, 0 on success. That is the same answer as for a
request that is still in progress, so the requester keeps waiting
for a completion that is never sent again.
The VM start on the target, and thus the migration, then hangs until
the rbd process is killed.
Reading the image config does not involve the lock owner, and after
the first start of the VM the value is already set. Check it first and
only write it if it differs, so migrations do not need the lock owner
anymore in the common case.
Signed-off-by: Jonas Theisen <j.theisen@proxmox.com>
---
src/PVE/Storage/RBDPlugin.pm | 20 +++++++++++++++++---
1 file changed, 17 insertions(+), 3 deletions(-)
diff --git a/src/PVE/Storage/RBDPlugin.pm b/src/PVE/Storage/RBDPlugin.pm
index 26a1cf8..1b2caf8 100644
--- a/src/PVE/Storage/RBDPlugin.pm
+++ b/src/PVE/Storage/RBDPlugin.pm
@@ -398,9 +398,26 @@ my sub rbd_volume_exists {
}
# Needs to be public, so qemu-server can mock it for cfg2cmd.
+#
+# Skips the write if the value is already set. Writing the image config is forwarded to the
+# exclusive lock owner, e.g. the source VM during live migration, and can block indefinitely if
+# the owner does not complete the request. Reading it does not involve the lock owner.
sub rbd_volume_config_set {
my ($scfg, $storeid, $volname, $key, $value) = @_;
+ my $current;
+ my $get_cmd = $rbd_cmd->($scfg, $storeid, 'config', 'image', 'get', $volname, $key);
+ # fails if the key is not set yet, so just fall back to setting it on any error
+ eval {
+ run_rbd_command(
+ $get_cmd,
+ errmsg => "rbd config image get $volname $key error",
+ errfunc => sub { },
+ outfunc => sub { $current = shift },
+ );
+ };
+ return if !$@ && defined($current) && $current eq $value;
+
my $cmd = $rbd_cmd->($scfg, $storeid, 'config', 'image', 'set', $volname, $key, $value);
run_rbd_command($cmd, errmsg => "rbd config image set $volname $key $value error");
@@ -616,9 +633,6 @@ sub qemu_blockdev_options {
# SPI flash does lots of read-modify-write OPs, without writeback this gets really slow #3329
if ($options->{hints}->{'efi-disk'}) {
- # Querying the value would just cost more and the 'rbd image config get' command will just
- # fail if the config has not been set yet, so it's not even straight-forward to do so.
- # Simply set the value (possibly again).
rbd_volume_config_set($scfg, $storeid, $name, 'rbd_cache_policy', 'writeback');
}
--
2.47.3
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH storage 2/2] rbd: do not let setting the EFI disk cache policy block VM start
2026-11-20 14:10 [PATCH storage 0/2] rbd: avoid hanging VM start on EFI disk cache policy Jonas Theisen
2026-11-20 14:10 ` [PATCH storage 1/2] rbd: only set image config if the value differs Jonas Theisen
@ 2026-11-20 14:10 ` Jonas Theisen
1 sibling, 0 replies; 3+ messages in thread
From: Jonas Theisen @ 2026-11-20 14:10 UTC (permalink / raw)
To: pve-devel
Setting the rbd_cache_policy image config while another client holds
the exclusive lock, e.g. the source VM during a live migration, is
forwarded to the lock owner. If the owner never reports completion, or
its completion is lost in a race with a re-send of the request, the
'rbd config image set' command never returns and the VM start on the
migration target hangs indefinitely.
Abort the command after 60 seconds, which allows for one retry of the
remote request, as librbd retries those every 30 seconds.
The cache policy only affects the performance of EFI variable writes,
so only warn if setting it fails, instead of failing the VM start and
thus the migration.
Signed-off-by: Jonas Theisen <j.theisen@proxmox.com>
---
src/PVE/Storage/RBDPlugin.pm | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/src/PVE/Storage/RBDPlugin.pm b/src/PVE/Storage/RBDPlugin.pm
index 1b2caf8..a209f6f 100644
--- a/src/PVE/Storage/RBDPlugin.pm
+++ b/src/PVE/Storage/RBDPlugin.pm
@@ -419,7 +419,12 @@ sub rbd_volume_config_set {
return if !$@ && defined($current) && $current eq $value;
my $cmd = $rbd_cmd->($scfg, $storeid, 'config', 'image', 'set', $volname, $key, $value);
- run_rbd_command($cmd, errmsg => "rbd config image set $volname $key $value error");
+ # librbd retries a remote request every 30 seconds, so allow for one retry
+ run_rbd_command(
+ $cmd,
+ errmsg => "rbd config image set $volname $key $value error",
+ timeout => 60,
+ );
return;
}
@@ -633,7 +638,9 @@ sub qemu_blockdev_options {
# SPI flash does lots of read-modify-write OPs, without writeback this gets really slow #3329
if ($options->{hints}->{'efi-disk'}) {
- rbd_volume_config_set($scfg, $storeid, $name, 'rbd_cache_policy', 'writeback');
+ # only affects performance, so do not fail the VM start, e.g. on the migration target
+ eval { rbd_volume_config_set($scfg, $storeid, $name, 'rbd_cache_policy', 'writeback') };
+ warn "could not set rbd_cache_policy for EFI disk '$name' - $@" if $@;
}
return $blockdev;
--
2.47.3
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-11-20 14:10 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-20 14:10 [PATCH storage 0/2] rbd: avoid hanging VM start on EFI disk cache policy Jonas Theisen
2026-11-20 14:10 ` [PATCH storage 1/2] rbd: only set image config if the value differs Jonas Theisen
2026-11-20 14:10 ` [PATCH storage 2/2] rbd: do not let setting the EFI disk cache policy block VM start Jonas Theisen
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.