From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 19647706E2 for ; Mon, 7 Jun 2021 12:23:26 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 0B453FDCA for ; Mon, 7 Jun 2021 12:23:26 +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 8D6C5FDBF for ; Mon, 7 Jun 2021 12:23:21 +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 67FB242B78 for ; Mon, 7 Jun 2021 12:23:21 +0200 (CEST) Date: Mon, 07 Jun 2021 12:23:11 +0200 From: Fabian =?iso-8859-1?q?Gr=FCnbichler?= To: Proxmox VE development discussion , Stefan Reiter References: <20210604094748.3383339-1-f.gruenbichler@proxmox.com> <20210604094748.3383339-3-f.gruenbichler@proxmox.com> In-Reply-To: MIME-Version: 1.0 User-Agent: astroid/0.15.0 (https://github.com/astroidmail/astroid) Message-Id: <1623060685.ii80j5ty3c.astroid@nora.none> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-SPAM-LEVEL: Spam detection results: 0 AWL 0.938 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 Subject: Re: [pve-devel] [PATCH qemu-server 2/6] drive: factor out read-only helper X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 07 Jun 2021 10:23:26 -0000 On June 7, 2021 11:29 am, Stefan Reiter wrote: > On 6/4/21 11:47 AM, Fabian Gr=C3=BCnbichler wrote: >> we also need it for efidisks. >>=20 >> Signed-off-by: Fabian Gr=C3=BCnbichler >> --- >> PVE/QemuServer.pm | 8 ++------ >> PVE/QemuServer/Drive.pm | 10 ++++++++++ >> 2 files changed, 12 insertions(+), 6 deletions(-) >>=20 >> diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm >> index 25ac052..0d49415 100644 >> --- a/PVE/QemuServer.pm >> +++ b/PVE/QemuServer.pm >> @@ -48,7 +48,7 @@ use PVE::QemuServer::Helpers qw(min_version config_awa= re_timeout); >> use PVE::QemuServer::Cloudinit; >> use PVE::QemuServer::CGroup; >> use PVE::QemuServer::CPUConfig qw(print_cpu_device get_cpu_options); >> -use PVE::QemuServer::Drive qw(is_valid_drivename drive_is_cloudinit dri= ve_is_cdrom parse_drive print_drive); >> +use PVE::QemuServer::Drive qw(is_valid_drivename drive_is_cloudinit dri= ve_is_cdrom drive_is_read_only parse_drive print_drive); >> use PVE::QemuServer::Machine; >> use PVE::QemuServer::Memory; >> use PVE::QemuServer::Monitor qw(mon_cmd); >> @@ -3662,11 +3662,7 @@ sub config_to_command { >> my $drive_cmd =3D print_drive_commandline_full($storecfg, $vmid, $dri= ve, $pbs_name); >> =20 >> # extra protection for templates, but SATA and IDE don't support it.. >> - my $read_only =3D PVE::QemuConfig->is_template($conf) >> - && $drive->{interface} ne 'sata' >> - && $drive->{interface} ne 'ide'; >> - >> - $drive_cmd .=3D ',readonly=3Don' if $read_only; >> + $drive_cmd .=3D ',readonly=3Don' if drive_is_read_only($conf, $drive); >> =20 >> push @$devices, '-drive',$drive_cmd; >> push @$devices, '-device', print_drivedevice_full( >> diff --git a/PVE/QemuServer/Drive.pm b/PVE/QemuServer/Drive.pm >> index 146a4ab..0408e32 100644 >> --- a/PVE/QemuServer/Drive.pm >> +++ b/PVE/QemuServer/Drive.pm >> @@ -12,6 +12,7 @@ our @EXPORT_OK =3D qw( >> is_valid_drivename >> drive_is_cloudinit >> drive_is_cdrom >> +drive_is_read_only >> parse_drive >> print_drive >> ); >> @@ -422,6 +423,15 @@ sub drive_is_cdrom { >> return $drive && $drive->{media} && ($drive->{media} eq 'cdrom'); >> } >> =20 >> +sub drive_is_read_only { >=20 > I really don't like this name, this checks if the drive *should* be=20 > read-only, and only related to template backups, not in general. yeah, `drive_should_be_read_only` would be more apt, but also sounds=20 wrong. I did have the non-template case in mind as well (e.g., adding a=20 'ro' flag to the drive in our VM config as a future addon, like we have=20 for container mountpoints). >=20 > Maybe 'drive_template_read_only'? >=20 > The function does two pretty unrelated things in general IMO, so maybe=20 > it would be clearer to do the is_template check at call site and make=20 > this 'drive_supports_read_only', even if it causes a little bit more=20 > duplication. would work as well. or we drop all of it and no longer mark any drives=20 as read-only, if we use the patch that adds '-snapshot' for=20 'start-template-for-backup'? at the risk of re-doing it if we ever add a=20 'ro' property for individual regular disks/drives.. >=20 >> + my ($conf, $drive) =3D @_; >> + >> + return 0 if !PVE::QemuConfig->is_template($conf); >> + >> + # don't support being marked read-only >> + return $drive->{interface} ne 'sata' && $drive->{interface} ne 'ide= '; >> +} >> + >> # ideX =3D [volume=3D]volume-id[,media=3Dd][,cyls=3Dc,heads=3Dh,secs= =3Ds[,trans=3Dt]] >> # [,snapshot=3Don|off][,cache=3Don|off][,format=3Df][,backup=3D= yes|no] >> # [,rerror=3Dignore|report|stop][,werror=3Denospc|ignore|report= |stop] >>=20 >=20