add generalized functions to manage volume attributes

replacing the ones for handling notes. To ensure backwards
compatibility with external plugins, all plugins that do not just call
another implementation need to call $class->{get, update}_volume_notes
when the attribute is 'notes' to catch any derived implementations.

This is mainly done to avoid the need to add new methods every time a
new attribute is added.

Not adding a timeout parameter like the notes functions have, because
it was not used and can still be added if it ever is needed in the
future.

For get_volume_attribute, undef will indicate that the attribute is
not supported. This makes it possible to distinguish "not supported"
from "error getting the attribute", which is useful when the attribute
is important for an operation. For example, free_image checking for
protection (introduced in a later patch) can abort if getting the
'protected' attribute fails.

Suggested-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
This commit is contained in:
Fabian Ebner
2021-09-30 13:42:06 +02:00
committed by Fabian Grünbichler
parent e0aa2070f6
commit f1de828166
9 changed files with 134 additions and 11 deletions

View File

@ -321,11 +321,12 @@ __PACKAGE__->register_method ({
format => $format,
};
# not all storages/types support notes, so ignore errors here
# keep going if fetching an optional attribute fails
eval {
my $notes = PVE::Storage::get_volume_notes($cfg, $volid);
my $notes = PVE::Storage::get_volume_attribute($cfg, $volid, 'notes');
$entry->{notes} = $notes if defined($notes);
};
warn $@ if $@;
return $entry;
}});
@ -371,7 +372,7 @@ __PACKAGE__->register_method ({
PVE::Storage::check_volume_access($rpcenv, $authuser, $cfg, undef, $volid);
if (exists $param->{notes}) {
PVE::Storage::update_volume_notes($cfg, $volid, $param->{notes});
PVE::Storage::update_volume_attribute($cfg, $volid, 'notes', $param->{notes});
}
return undef;