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 07B49798C6
 for <pve-devel@lists.proxmox.com>; Wed, 27 Oct 2021 13:35:30 +0200 (CEST)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
 by firstgate.proxmox.com (Proxmox) with ESMTP id F15181249B
 for <pve-devel@lists.proxmox.com>; Wed, 27 Oct 2021 13:35:29 +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))
 (No client certificate requested)
 by firstgate.proxmox.com (Proxmox) with ESMTPS id 586EE12492
 for <pve-devel@lists.proxmox.com>; Wed, 27 Oct 2021 13:35:29 +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 3116345FB1
 for <pve-devel@lists.proxmox.com>; Wed, 27 Oct 2021 13:35:29 +0200 (CEST)
From: Dominik Csapak <d.csapak@proxmox.com>
To: pve-devel@lists.proxmox.com
Date: Wed, 27 Oct 2021 13:35:27 +0200
Message-Id: <20211027113527.17267-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.266 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 v3] drives: expose 'readonly' flag
 of qemu for scsi/virtio
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: Wed, 27 Oct 2021 11:35:30 -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).

the option is named 'ro', to achieve consistency with containers

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>
---
changes from v2:
* renamed option to 'ro' to be in line with containers

 PVE/QemuServer.pm       |  6 ++++++
 PVE/QemuServer/Drive.pm | 11 +++++++++++
 2 files changed, 17 insertions(+)

diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index 0fb8628..5b31ad0 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -1575,6 +1575,12 @@ sub print_drive_commandline_full {
 	$opts .= ",snapshot=$v";
     }
 
+    # ro is 'readonly', and only accepts on|off
+    if (defined($drive->{ro})) {
+	my $v = $drive->{ro} ? 'on' : 'off';
+	$opts .= ",readonly=$v";
+    }
+
     foreach my $type (['', '-total'], [_rd => '-read'], [_wr => '-write']) {
 	my ($dir, $qmpname) = @$type;
 	if (my $v = $drive->{"mbps$dir"}) {
diff --git a/PVE/QemuServer/Drive.pm b/PVE/QemuServer/Drive.pm
index 5110190..3eadf03 100644
--- a/PVE/QemuServer/Drive.pm
+++ b/PVE/QemuServer/Drive.pm
@@ -175,6 +175,14 @@ my %queues_fmt = (
     }
 );
 
+my %readonly_fmt = (
+    ro => {
+	type => 'boolean',
+	description => "Whether the drive is read-only.",
+	optional => 1,
+    },
+);
+
 my %scsiblock_fmt = (
     scsiblock => {
 	type => 'boolean',
@@ -269,6 +277,7 @@ my $scsi_fmt = {
     %drivedesc_base,
     %iothread_fmt,
     %queues_fmt,
+    %readonly_fmt,
     %scsiblock_fmt,
     %ssd_fmt,
     %wwn_fmt,
@@ -297,6 +306,7 @@ PVE::JSONSchema::register_standard_option("pve-qm-sata", $satadesc);
 my $virtio_fmt = {
     %drivedesc_base,
     %iothread_fmt,
+    %readonly_fmt,
 };
 my $virtiodesc = {
     optional => 1,
@@ -311,6 +321,7 @@ my $alldrive_fmt = {
     %iothread_fmt,
     %model_fmt,
     %queues_fmt,
+    %readonly_fmt,
     %scsiblock_fmt,
     %ssd_fmt,
     %wwn_fmt,
-- 
2.30.2