From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <d.csapak@proxmox.com>
Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68])
 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
 key-exchange X25519 server-signature RSA-PSS (2048 bits))
 (No client certificate requested)
 by lists.proxmox.com (Postfix) with ESMTPS id D70306D4A7
 for <pve-devel@lists.proxmox.com>; Tue, 28 Sep 2021 09:48:23 +0200 (CEST)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
 by firstgate.proxmox.com (Proxmox) with ESMTP id C7725A691
 for <pve-devel@lists.proxmox.com>; Tue, 28 Sep 2021 09:48:23 +0200 (CEST)
Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com
 [94.136.29.106])
 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
 key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256)
 (No client certificate requested)
 by firstgate.proxmox.com (Proxmox) with ESMTPS id 03BA2A687
 for <pve-devel@lists.proxmox.com>; Tue, 28 Sep 2021 09:48:23 +0200 (CEST)
Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1])
 by proxmox-new.maurer-it.com (Proxmox) with ESMTP id CAF2F423C5
 for <pve-devel@lists.proxmox.com>; Tue, 28 Sep 2021 09:48:16 +0200 (CEST)
From: Dominik Csapak <d.csapak@proxmox.com>
To: pve-devel@lists.proxmox.com
Date: Tue, 28 Sep 2021 09:48:15 +0200
Message-Id: <20210928074815.1137033-1-d.csapak@proxmox.com>
X-Mailer: git-send-email 2.30.2
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-SPAM-LEVEL: Spam detection results:  0
 AWL 0.353 Adjusted score from AWL reputation of From: address
 BAYES_00                 -1.9 Bayes spam probability is 0 to 1%
 KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment
 SPF_HELO_NONE           0.001 SPF: HELO does not publish an SPF Record
 SPF_PASS               -0.001 SPF: sender matches SPF record
 URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See
 http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more
 information. [qemuserver.pm, drive.pm]
Subject: [pve-devel] [PATCH qemu-server] drives: expose 'readonly' flag of
 qemu
X-BeenThere: pve-devel@lists.proxmox.com
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Proxmox VE development discussion <pve-devel.lists.proxmox.com>
List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=unsubscribe>
List-Archive: <http://lists.proxmox.com/pipermail/pve-devel/>
List-Post: <mailto:pve-devel@lists.proxmox.com>
List-Help: <mailto:pve-devel-request@lists.proxmox.com?subject=help>
List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=subscribe>
X-List-Received-Date: Tue, 28 Sep 2021 07:48:23 -0000

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@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