public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
* [pve-devel] [PATCH qemu-server v3] drives: expose 'readonly' flag of qemu for scsi/virtio
@ 2021-10-27 11:35 Dominik Csapak
  2021-10-27 15:01 ` [pve-devel] applied: " Thomas Lamprecht
  0 siblings, 1 reply; 2+ messages in thread
From: Dominik Csapak @ 2021-10-27 11:35 UTC (permalink / raw)
  To: pve-devel

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





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

end of thread, other threads:[~2021-10-27 15:01 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-27 11:35 [pve-devel] [PATCH qemu-server v3] drives: expose 'readonly' flag of qemu for scsi/virtio Dominik Csapak
2021-10-27 15:01 ` [pve-devel] applied: " 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