]> git.proxmox.com Git - pve-storage.git/commitdiff
Allow passing options to volume_has_feature
authorFabian Ebner <f.ebner@proxmox.com>
Mon, 23 Mar 2020 11:18:50 +0000 (12:18 +0100)
committerFabian Grünbichler <f.gruenbichler@proxmox.com>
Fri, 27 Mar 2020 07:50:23 +0000 (08:50 +0100)
With the option valid_target_formats it's possible
to let the caller specify possible formats for the target
of an operation.
[0]: If the option is not set, assume that every format is valid.

In most cases the format of the the target and the format
of the source will agree (and therefore assumption [0] is
not actually assuming very much and ensures backwards
compatability). But when cloning a volume on a storage
using Plugin.pm's implementation (e.g. directory based
storages), the result is always a qcow2 image.

When cloning containers, the new option can be used to detect
that qcow2 is not valid and hence the clone feature is not
available.

Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
PVE/Storage.pm
PVE/Storage/Plugin.pm

index a46550c92ef48b7f5286a2225cd9a9402282b8e5..fcfc6afc67f2f82d3a66e8e76048df7c54f42616 100755 (executable)
@@ -39,11 +39,11 @@ use PVE::Storage::DRBDPlugin;
 use PVE::Storage::PBSPlugin;
 
 # Storage API version. Icrement it on changes in storage API interface.
-use constant APIVER => 3;
+use constant APIVER => 4;
 # Age is the number of versions we're backward compatible with.
 # This is like having 'current=APIVER' and age='APIAGE' in libtool,
 # see https://www.gnu.org/software/libtool/manual/html_node/Libtool-versioning.html
-use constant APIAGE => 2;
+use constant APIAGE => 3;
 
 # load standard plugins
 PVE::Storage::DirPlugin->register();
@@ -286,13 +286,13 @@ sub volume_snapshot_delete {
 }
 
 sub volume_has_feature {
-    my ($cfg, $feature, $volid, $snap, $running) = @_;
+    my ($cfg, $feature, $volid, $snap, $running, $opts) = @_;
 
     my ($storeid, $volname) = parse_volume_id($volid, 1);
     if ($storeid) {
         my $scfg = storage_config($cfg, $storeid);
         my $plugin = PVE::Storage::Plugin->lookup($scfg->{type});
-        return $plugin->volume_has_feature($scfg, $feature, $storeid, $volname, $snap, $running);
+        return $plugin->volume_has_feature($scfg, $feature, $storeid, $volname, $snap, $running, $opts);
     } elsif ($volid =~ m|^(/.+)$| && -e $volid) {
        return undef;
     } else {
index 223226166a19490b38d80999bbb687bc56b0833f..8c0dae1e09222426e12239e26a6551222465536f 100644 (file)
@@ -828,7 +828,7 @@ sub storage_can_replicate {
 }
 
 sub volume_has_feature {
-    my ($class, $scfg, $feature, $storeid, $volname, $snapname, $running) = @_;
+    my ($class, $scfg, $feature, $storeid, $volname, $snapname, $running, $opts) = @_;
 
     my $features = {
        snapshot => { current => { qcow2 => 1}, snap => { qcow2 => 1} },
@@ -841,6 +841,11 @@ sub volume_has_feature {
                        current => {qcow2 => 1, raw => 1, vmdk => 1} },
     };
 
+    # clone_image creates a qcow2 volume
+    return 0 if $feature eq 'clone' &&
+               defined($opts->{valid_target_formats}) &&
+               !(grep { $_ eq 'qcow2' } @{$opts->{valid_target_formats}});
+
     my ($vtype, $name, $vmid, $basename, $basevmid, $isBase, $format) =
        $class->parse_volname($volname);