[pve-devel] [PATCH v2 guest-common 06/28] Add snapshot_foreach_unused_volume
Fabian Ebner
f.ebner at proxmox.com
Tue Feb 25 13:36:35 CET 2020
On 2/25/20 12:32 PM, Fabian Grünbichler wrote:
> like discussed off-list, this should lose the 'snapshot_' prefix if it
> is to be used as a general method.
>
> alternatively, we could also generalize PVE::LXC::Config::mountpoint_names
> and PVE::QemuServer::Drive::valid_drive_names into a single method
> returning a list of config keys where volumes are found in correct
> order. then foreach_volume could entirely be defined as iteration over
> that, a call to parse_volume, and a call to the passed function. this
> new method could take the $opts defining any extras like include unused
> or include vmstate, or foreach_volume could add them. note that
> pve-container needs an option to reverse iterate, but that could also be
> handled in either method.
>
Sounds good to me. I feel like the options for extras should be handled
directly in foreach_volume which could then simply be:
1. get keys
2. optionally reverse keys
3. iterate over keys
4. optionally iterate over extras
5. optionally also do the same for snapshots
> On February 24, 2020 1:43 pm, Fabian Ebner wrote:
>> Signed-off-by: Fabian Ebner <f.ebner at proxmox.com>
>> ---
>> PVE/AbstractConfig.pm | 13 +++++++++++++
>> 1 file changed, 13 insertions(+)
>>
>> diff --git a/PVE/AbstractConfig.pm b/PVE/AbstractConfig.pm
>> index bd43cbe..5c449f6 100644
>> --- a/PVE/AbstractConfig.pm
>> +++ b/PVE/AbstractConfig.pm
>> @@ -508,6 +508,19 @@ sub __snapshot_foreach_volume {
>> die "abstract method - implement me\n";
>> }
>>
>> +# Iterate over all unused volumes, calling $func for each key/value pair
>> +# with additional parameters @param.
>> +sub snapshot_foreach_unused_volume {
>> + my ($class, $conf, $func, @param) = @_;
>> +
>> + foreach my $key (keys %{$conf}) {
>> + if ($key =~ m/^unused\d+$/) {
>> + my $volume = $class->parse_volume($key, $conf->{$key});
>> + $func->($key, $volume, @param);
>> + }
>> + }
>> +}
>> +
>> # Copy the current config $source to the snapshot config $dest
>> sub __snapshot_copy_config {
>> my ($class, $source, $dest) = @_;
>> --
>> 2.20.1
>>
>>
>> _______________________________________________
>> pve-devel mailing list
>> pve-devel at pve.proxmox.com
>> https://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
>>
>>
>
> _______________________________________________
> pve-devel mailing list
> pve-devel at pve.proxmox.com
> https://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
>
More information about the pve-devel
mailing list