public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: "Fabian Grünbichler" <f.gruenbichler@proxmox.com>
To: Proxmox VE development discussion <pve-devel@lists.proxmox.com>
Subject: Re: [pve-devel] [PATCH container 2/2] migration: avoid migrating volume images multiple times
Date: Wed, 03 May 2023 11:07:59 +0200	[thread overview]
Message-ID: <1683103216.2rppe57tnl.astroid@yuna.none> (raw)
In-Reply-To: <20230502131732.1875692-3-a.lauterer@proxmox.com>

On May 2, 2023 3:17 pm, Aaron Lauterer wrote:
> Scan the VM config and store the volid and full path for each storage.
> Do the same when we scan each storage.  Then we can have these
> scenarios:
> * multiple storage configurations might point to the same storage
> The result is, that when scanning the storages, we find the volume
> multiple times.
> -> we ignore them
> 
> * a VM might have multiple volumes configured, pointing to the same
>   volume
> -> We fail with a warning that two mpX configs point to the same
> volume

this one really doesn't make much sense for containers (if the volume
contains the default ext4, MMP means the container can't be started?) -
it could be handled though as well (just migrate the volume once, and
replace the references with the target volid?)
> 
> Without these checks, it was possible to multiply the number of volumes
> with each migration (with local disk) if at least another storage was
> configured, pointing to the same place.
> 
> Signed-off-by: Aaron Lauterer <a.lauterer@proxmox.com>
> ---
>  src/PVE/LXC/Migrate.pm | 31 +++++++++++++++++++++++++++++++
>  1 file changed, 31 insertions(+)
> 
> diff --git a/src/PVE/LXC/Migrate.pm b/src/PVE/LXC/Migrate.pm
> index ccf5157..47cb94b 100644
> --- a/src/PVE/LXC/Migrate.pm
> +++ b/src/PVE/LXC/Migrate.pm
> @@ -256,6 +256,28 @@ sub phase1 {
>  	&$log_error($@, $volid) if $@;
>      };
>  
> +    # store and map already referenced absolute paths and volids
> +    my $referencedpath = {}; # path -> volid

wrong name - this contains both referenced and unreferenced paths (and
also, long variable names would benefit from _ for separation of words)

> +    my $referenced = {}; # volid -> config key (e.g. mp0)

also wrong - contains both referenced and unreferenced volids, and also
doesn't always map to the config key ;)

but before diving further into nit territory - we already have $volhash
that is filled for all volumes, wouldn't it make more sense to re-use
it? the order is inverse compared to your patch here, but that doesn't
really matter (and it would avoid iterating over the config twice).
compared to your patch, it also covers snapshots (everything in
snapshots should also be in the current config either still used or as
unusedX, but who knows).

there are three things we'd need to do:
- in $test_volid, if 'ref' is already config, error out (same volid
  referenced in current config multiple times)
- add the path of each volid to the volhash while filling it
- after $volhash is filled, iterate over it and check for aliased paths
  (and depending on where the volid comes from, warn and ignore or error
  out)

or am I missing something?

alternatively, instead of putting the path into volhash, it could be
tracked separately (e.g. in a $path_to_volid hash) and checked directly
while iterating instead of at the end.

> +
> +    # reference volumes in config first
> +    PVE::LXC::Config->foreach_volume_full($conf, { include_unused => 1 }, sub {
> +	my ($key, $volume) = @_;
> +	my $volid = $volume->{volume};
> +	my $path = PVE::Storage::path($self->{storecfg}, $volid);
> +	if (defined $referencedpath->{$path}) {
> +	    my $rkey = $referenced->{$referencedpath->{$path}};
> +	    &$log_error(
> +		"'$key' and '$rkey' reference the same volume. ".
> +		"(check guest and storage configuration?)\n",
> +		$volid
> +	    );
> +	    return;
> +	}
> +	$referencedpath->{$path} = $volid;
> +	$referenced->{$volid} = $key;
> +    });
> +
>      # first unused / lost volumes owned by this container
>      my @sids = PVE::Storage::storage_ids($self->{storecfg});
>      foreach my $storeid (@sids) {
> @@ -280,6 +302,15 @@ sub phase1 {
>  	PVE::Storage::foreach_volid($dl, sub {
>  	    my ($volid, $sid, $volname) = @_;
>  
> +	    # check if volume is already referenced
> +	    my $path = PVE::Storage::path($self->{storecfg}, $volid);
> +	    if (defined $referencedpath->{$path} && !$referenced->{$volid}) {
> +		$self->log('info', "ignoring '$volid' - already referenced by other storage '$referencedpath->{$path}'\n");
> +		next;
> +	    }
> +	    $referencedpath->{$path} = $volid;
> +	    $referenced->{$volid} = 1;
> +
>  	    $volhash->{$volid}->{ref} = 'storage';
>  	    $volhash->{$volid}->{targetsid} = $targetsid;
>  	});
> -- 
> 2.30.2
> 
> 
> 
> _______________________________________________
> pve-devel mailing list
> pve-devel@lists.proxmox.com
> https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
> 
> 
> 




      reply	other threads:[~2023-05-03  9:08 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-02 13:17 [pve-devel] [PATCH qemu-server, container 0/2] avoid migrating disk " Aaron Lauterer
2023-05-02 13:17 ` [pve-devel] [PATCH qemu-server 1/2] migration: " Aaron Lauterer
2023-05-03  9:17   ` Fabian Grünbichler
2023-05-09  7:34   ` Fiona Ebner
2023-05-09 12:55     ` Aaron Lauterer
2023-05-09 14:43       ` Fiona Ebner
2023-05-10  9:57         ` Aaron Lauterer
2023-05-10 11:23           ` Fiona Ebner
2023-05-02 13:17 ` [pve-devel] [PATCH container 2/2] migration: avoid migrating volume " Aaron Lauterer
2023-05-03  9:07   ` Fabian Grünbichler [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=1683103216.2rppe57tnl.astroid@yuna.none \
    --to=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