public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Stefan Reiter <s.reiter@proxmox.com>
To: "Fabian Grünbichler" <f.gruenbichler@proxmox.com>,
	"Proxmox VE development discussion" <pve-devel@lists.proxmox.com>
Subject: Re: [pve-devel] [PATCH qemu-server 2/6] drive: factor out read-only helper
Date: Mon, 7 Jun 2021 12:35:51 +0200	[thread overview]
Message-ID: <fc296768-465f-fbe6-cf2a-64637ffc107f@proxmox.com> (raw)
In-Reply-To: <1623060685.ii80j5ty3c.astroid@nora.none>

On 6/7/21 12:23 PM, Fabian Grünbichler wrote:
> On June 7, 2021 11:29 am, Stefan Reiter wrote:
>> On 6/4/21 11:47 AM, Fabian Grünbichler wrote:
>>> we also need it for efidisks.
>>>
>>> Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
>>> ---
>>>    PVE/QemuServer.pm       |  8 ++------
>>>    PVE/QemuServer/Drive.pm | 10 ++++++++++
>>>    2 files changed, 12 insertions(+), 6 deletions(-)
>>>
>>> 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_aware_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 drive_is_cdrom parse_drive print_drive);
>>> +use PVE::QemuServer::Drive qw(is_valid_drivename drive_is_cloudinit drive_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 = print_drive_commandline_full($storecfg, $vmid, $drive, $pbs_name);
>>>    
>>>    	# extra protection for templates, but SATA and IDE don't support it..
>>> -	my $read_only = PVE::QemuConfig->is_template($conf)
>>> -	    && $drive->{interface} ne 'sata'
>>> -	    && $drive->{interface} ne 'ide';
>>> -
>>> -	$drive_cmd .= ',readonly=on' if $read_only;
>>> +	$drive_cmd .= ',readonly=on' if drive_is_read_only($conf, $drive);
>>>    
>>>    	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 = 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');
>>>    }
>>>    
>>> +sub drive_is_read_only {
>>
>> I really don't like this name, this checks if the drive *should* be
>> read-only, and only related to template backups, not in general.
> 
> yeah, `drive_should_be_read_only` would be more apt, but also sounds
> wrong. I did have the non-template case in mind as well (e.g., adding a
> 'ro' flag to the drive in our VM config as a future addon, like we have
> for container mountpoints).
> 

Yes, I actually assumed we could already do that before I looked more 
closely when reviewing your patches :)

>>
>> Maybe 'drive_template_read_only'?
>>
>> The function does two pretty unrelated things in general IMO, so maybe
>> it would be clearer to do the is_template check at call site and make
>> this 'drive_supports_read_only', even if it causes a little bit more
>> duplication.
> 
> would work as well. or we drop all of it and no longer mark any drives
> as read-only, if we use the patch that adds '-snapshot' for
> 'start-template-for-backup'? at the risk of re-doing it if we ever add a
> 'ro' property for individual regular disks/drives..
> 

Hm, I do like the idea of marking them read-only if possible, even if we 
pass '-snapshot' - all of this is just preventative anyway, as the guest 
is stopped and should never write anything, so at this point might as 
well make it in-depth if it's cheap like here. And potentially reuseable 
for a ro flag.

>>
>>> +    my ($conf, $drive) = @_;
>>> +
>>> +    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 = [volume=]volume-id[,media=d][,cyls=c,heads=h,secs=s[,trans=t]]
>>>    #        [,snapshot=on|off][,cache=on|off][,format=f][,backup=yes|no]
>>>    #        [,rerror=ignore|report|stop][,werror=enospc|ignore|report|stop]
>>>
>>




  reply	other threads:[~2021-06-07 10:35 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-04  9:47 [pve-devel] [PATCH qemu-server 0/6] fix #2862: more template backup fixes Fabian Grünbichler
2021-06-04  9:47 ` [pve-devel] [PATCH qemu-server 1/6] test: unbreak restore_config_test Fabian Grünbichler
2021-06-04  9:47 ` [pve-devel] [PATCH qemu-server 2/6] drive: factor out read-only helper Fabian Grünbichler
2021-06-07  9:29   ` Stefan Reiter
2021-06-07 10:23     ` Fabian Grünbichler
2021-06-07 10:35       ` Stefan Reiter [this message]
2021-06-04  9:47 ` [pve-devel] [PATCH qemu-server 3/6] template: mark efidisk as read-only Fabian Grünbichler
2021-06-07  9:29   ` Stefan Reiter
2021-06-07 10:23     ` Fabian Grünbichler
2021-06-04  9:47 ` [pve-devel] [PATCH qemu-server 4/6] test: add template drive read-only tests Fabian Grünbichler
2021-06-04  9:47 ` [pve-devel] [PATCH qemu-server 5/6] template: add -snapshot to KVM command Fabian Grünbichler
2021-06-04  9:47 ` [pve-devel] [RFC qemu-server 6/6] template: start VM for VMA backup Fabian Grünbichler
2021-06-07  9:29   ` Stefan Reiter
2021-06-07 10:22     ` Fabian Grünbichler
2021-06-23 10:50 ` [pve-devel] partially-applied: [PATCH qemu-server 0/6] fix #2862: more template backup fixes Thomas Lamprecht

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=fc296768-465f-fbe6-cf2a-64637ffc107f@proxmox.com \
    --to=s.reiter@proxmox.com \
    --cc=f.gruenbichler@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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