[pve-devel] [PATCH qemu-server] drives: expose 'readonly' flag of qemu

Dominik Csapak d.csapak at proxmox.com
Tue Sep 28 09:48:15 CEST 2021


this allows a user to set a drive to read only. This can be useful
if a disk should not be written to, or if the backing file/source is
not writable (like a mapped pbs backup to /dev/loopX).

while this could also be achieved by setting 'snapshot=1', this would
create a temporary file in /var/tmp which can get quite big.

Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
while forward migration (old->new) worked without issue, i noticed that
when migrating backwards (new->old), the stack lets us do it, but
ignores 'invalid' disk and thus crashes on resume and the disk
is removed from the config.

i am aware that we do not support new->old migration, but is there a way
to handle such sitations more gracefully? shouldn't we deny a start
(at least on migration) for invalid configs instead of ignoring such
lines?

 PVE/QemuServer.pm       | 10 ++++++----
 PVE/QemuServer/Drive.pm |  5 +++++
 2 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index 0fb8628..5209f51 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -1569,10 +1569,12 @@ sub print_drive_commandline_full {
 	$opts .= ",$o=$drive->{$o}" if defined($drive->{$o});
     }
 
-    # snapshot only accepts on|off
-    if (defined($drive->{snapshot})) {
-	my $v = $drive->{snapshot} ? 'on' : 'off';
-	$opts .= ",snapshot=$v";
+    # some options only accepts on|off
+    foreach my $o (qw(snapshot readonly)) {
+	if (defined($drive->{$o})) {
+	    my $v = $drive->{$o} ? 'on' : 'off';
+	    $opts .= ",$o=$v";
+	}
     }
 
     foreach my $type (['', '-total'], [_rd => '-read'], [_wr => '-write']) {
diff --git a/PVE/QemuServer/Drive.pm b/PVE/QemuServer/Drive.pm
index 5110190..c20e74d 100644
--- a/PVE/QemuServer/Drive.pm
+++ b/PVE/QemuServer/Drive.pm
@@ -97,6 +97,11 @@ my %drivedesc_base = (
 	description => "Whether the drive should be included when making backups.",
 	optional => 1,
     },
+    readonly => {
+	type => 'boolean',
+	description => "Whether the drive is read-only.",
+	optional => 1,
+    },
     replicate => {
 	type => 'boolean',
 	description => 'Whether the drive should considered for replication jobs.',
-- 
2.30.2






More information about the pve-devel mailing list