From: Fabian Ebner <f.ebner@proxmox.com>
To: pve-devel@lists.proxmox.com, Oguz Bektas <o.bektas@proxmox.com>
Subject: Re: [pve-devel] [PATCH v2 guest-common 2/2] snapshots: abort if new snapshot name is already parent to existing one
Date: Thu, 14 Oct 2021 09:34:44 +0200 [thread overview]
Message-ID: <982749a2-e94c-2bc0-b076-869756c08648@proxmox.com> (raw)
In-Reply-To: <20211013123154.1221852-3-o.bektas@proxmox.com>
Am 13.10.21 um 14:31 schrieb Oguz Bektas:
> Signed-off-by: Oguz Bektas <o.bektas@proxmox.com>
> ---
> src/PVE/AbstractConfig.pm | 12 ++++++++++--
> 1 file changed, 10 insertions(+), 2 deletions(-)
>
> diff --git a/src/PVE/AbstractConfig.pm b/src/PVE/AbstractConfig.pm
> index 3348d8a..6849664 100644
> --- a/src/PVE/AbstractConfig.pm
> +++ b/src/PVE/AbstractConfig.pm
> @@ -721,14 +721,22 @@ sub __snapshot_prepare {
>
> $conf->{lock} = 'snapshot';
>
> + my $snapshots = $conf->{snapshots};
> +
> die "snapshot name '$snapname' already used\n"
> - if defined($conf->{snapshots}->{$snapname});
> + if defined($snapshots->{$snapname});
>
> my $storecfg = PVE::Storage::config();
> die "snapshot feature is not available\n"
> if !$class->has_feature('snapshot', $conf, $storecfg, undef, undef, $snapname eq 'vzdump');
>
> - $snap = $conf->{snapshots}->{$snapname} = {};
> + foreach my $existing_snapshot (keys %$snapshots) {
> + my $parent_name = $snapshots->{$existing_snapshot}->{parent} // '';
> + die "snapshot '$snapname' cannot be used, $snapname already a parent for $existing_snapshot\n"
> + if $snapname eq $parent_name;
> + }
Personally, I'd prefer the "automatically fix it up"-approach, because
we we're the ones introducing the invalid property in the first place.
But if we go for the "error out"-approach, the error message should be
different. You're telling the user that the snapshot name cannot be
used, but they'll just wonder why. Instead, the error should rather tell
the user that manual fix-up is required and that the parent property is
invalid, because the parent doesn't exist.
> +
> + $snap = $snapshots->{$snapname} = {};
>
> if ($save_vmstate && $class->__snapshot_check_running($vmid)) {
> $class->__snapshot_save_vmstate($vmid, $conf, $snapname, $storecfg);
>
prev parent reply other threads:[~2021-10-14 7:34 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-13 12:31 [pve-devel] [PATCH v2 container guest-common 0/2] snapshot parent checks for containers Oguz Bektas
2021-10-13 12:31 ` [pve-devel] [PATCH v2 container 1/2] api: clone_vm: don't include snapshot properties Oguz Bektas
2021-10-14 10:01 ` [pve-devel] applied: " Thomas Lamprecht
2021-10-13 12:31 ` [pve-devel] [PATCH v2 guest-common 2/2] snapshots: abort if new snapshot name is already parent to existing one Oguz Bektas
2021-10-14 7:34 ` Fabian Ebner [this message]
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=982749a2-e94c-2bc0-b076-869756c08648@proxmox.com \
--to=f.ebner@proxmox.com \
--cc=o.bektas@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