From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 30E4D61912 for ; Fri, 20 Nov 2020 17:17:57 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 2E21514C91 for ; Fri, 20 Nov 2020 17:17:27 +0100 (CET) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [212.186.127.180]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id B9AFD14C84 for ; Fri, 20 Nov 2020 17:17:24 +0100 (CET) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 8971343D05 for ; Fri, 20 Nov 2020 17:17:24 +0100 (CET) Date: Fri, 20 Nov 2020 17:17:16 +0100 From: Fabian =?iso-8859-1?q?Gr=FCnbichler?= To: Proxmox VE development discussion References: <20201002082354.20204-1-a.lauterer@proxmox.com> <20201002082354.20204-4-a.lauterer@proxmox.com> In-Reply-To: <20201002082354.20204-4-a.lauterer@proxmox.com> MIME-Version: 1.0 User-Agent: astroid/0.15.0 (https://github.com/astroidmail/astroid) Message-Id: <1605888925.p8bohv2ozy.astroid@nora.none> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-SPAM-LEVEL: Spam detection results: 0 AWL -1.128 Adjusted score from AWL reputation of From: address KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment KAM_SHORT 0.001 Use of a URL Shortener for very short URL SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [lvmthinplugin.pm, proxmox.com, cifsplugin.pm, gnu.org, nfsplugin.pm, basedirplugin.pm, glusterfsplugin.pm, plugin.pm, dirplugin.pm] Subject: Re: [pve-devel] [PATCH v4 storage 3/4] add disk reassign feature X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 20 Nov 2020 16:17:57 -0000 small nit inline, also order in series is wrong - this patch goes first,=20 the rest depends on it.. ;) needs a rebase/fixup since APIAGE/VER were bumped in the meantime.. On October 2, 2020 10:23 am, Aaron Lauterer wrote: > Functionality has been added for the following storage types: >=20 > * dir based ones > * directory > * NFS > * CIFS > * gluster > * ZFS > * (thin) LVM > * Ceph >=20 > A new feature `reassign` has been introduced to mark which storage > plugin supports the feature. >=20 > Version API and AGE have been bumped. >=20 > Signed-off-by: Aaron Lauterer > --- > v3 -> v4: > * revert intermediate storage plugin for directory based plugins > * add a `die "not supported"` method in Plugin.pm > * dir based plugins now call the file_reassign_volume method in > Plugin.pm as the generic file/directory based method > * restored old `volume_has_feature` method in Plugin.pm and override it > in directory based plugins to check against the new `reassign` feature > (not too happy about the repetition for each plugin) >=20 > v2 -> v3: > * added feature flags instead of dummy "not implemented" methods in > plugins which do not support it as that would break compatibility with > 3rd party plugins. > Had to make $features available outside the `has_features` method in > Plugins.pm in order to be able to individually add features in the > `BaseDirPlugin.pm`. > * added the BaseDirPlugin.pm to maintain compat with 3rd party plugins, > this is explained in the commit message > * moved the actual renaming from the `reassign_volume` to a dedicated > `rename_volume` method to make this functionality available to other > possible uses in the future. > * added support for linked clones ($base) >=20 >=20 > rfc -> v1 -> v2: nothing changed >=20 >=20 > PVE/Storage.pm | 15 ++++++++-- > PVE/Storage/CIFSPlugin.pm | 19 +++++++++++++ > PVE/Storage/DirPlugin.pm | 19 +++++++++++++ > PVE/Storage/GlusterfsPlugin.pm | 19 +++++++++++++ > PVE/Storage/LVMPlugin.pm | 24 ++++++++++++++++ > PVE/Storage/LvmThinPlugin.pm | 1 + > PVE/Storage/NFSPlugin.pm | 19 +++++++++++++ > PVE/Storage/Plugin.pm | 51 ++++++++++++++++++++++++++++++++++ > PVE/Storage/RBDPlugin.pm | 31 +++++++++++++++++++++ > PVE/Storage/ZFSPoolPlugin.pm | 28 +++++++++++++++++++ > 10 files changed, 224 insertions(+), 2 deletions(-) >=20 > diff --git a/PVE/Storage.pm b/PVE/Storage.pm > index 4a60615..874457b 100755 > --- a/PVE/Storage.pm > +++ b/PVE/Storage.pm > @@ -40,11 +40,11 @@ use PVE::Storage::DRBDPlugin; > use PVE::Storage::PBSPlugin; > =20 > # Storage API version. Icrement it on changes in storage API interface. > -use constant APIVER =3D> 6; > +use constant APIVER =3D> 7; > # Age is the number of versions we're backward compatible with. > # This is like having 'current=3DAPIVER' and age=3D'APIAGE' in libtool, > # see https://www.gnu.org/software/libtool/manual/html_node/Libtool-vers= ioning.html > -use constant APIAGE =3D> 5; > +use constant APIAGE =3D> 6; > =20 > # load standard plugins > PVE::Storage::DirPlugin->register(); > @@ -294,6 +294,7 @@ sub volume_snapshot_delete { > # snapshot - taking a snapshot is possible > # sparseinit - volume is sparsely initialized > # template - conversion to base image is possible > +# reassign - reassigning disks to other guest is possible > # $snap - check if the feature is supported for a given snapshot > # $running - if the guest owning the volume is running > # $opts - hash with further options: > @@ -1759,6 +1760,16 @@ sub complete_volume { > return $res; > } > =20 > +sub reassign_volume { > + my ($cfg, $volid, $target_vmid) =3D @_; > + > + my ($storeid, $volname) =3D parse_volume_id($volid); > + my $scfg =3D storage_config($cfg, $storeid); > + my $plugin =3D PVE::Storage::Plugin->lookup($scfg->{type}); > + > + return $plugin->reassign_volume($scfg, $storeid, $volname, $target_v= mid); > +} > + > # Various io-heavy operations require io/bandwidth limits which can be > # configured on multiple levels: The global defaults in datacenter.cfg, = and > # per-storage overrides. When we want to do a restore from storage A to = storage > diff --git a/PVE/Storage/CIFSPlugin.pm b/PVE/Storage/CIFSPlugin.pm > index 6edbc9d..13c81cc 100644 > --- a/PVE/Storage/CIFSPlugin.pm > +++ b/PVE/Storage/CIFSPlugin.pm > @@ -280,4 +280,23 @@ sub check_connection { > return 1; > } > =20 > +sub reassign_volume { > + my ($class, $scfg, $storeid, $volname, $target_vmid) =3D @_; > + return $class->file_reassign_volume($scfg, $storeid, $volname, $targ= et_vmid); > +} > + > +sub volume_has_feature { > + my ($class, $scfg, $feature, $storeid, $volname, $snapname, $running= , $opts) =3D @_; > + > + my ($vtype, $name, $vmid, $basename, $basevmid, $isBase, $format) = =3D > + $class->parse_volname($volname); > + > + if ($feature eq 'reassign') { > + return 1 if !$isBase && $format =3D~ /^raw$|^qcow2$|^vmdk$/; > + return undef; > + } else { > + return $class->SUPER::volume_has_feature($scfg, $feature, $storeid, $vo= lname, $snapname, $running, $opts); > + } > +} > + > 1; > diff --git a/PVE/Storage/DirPlugin.pm b/PVE/Storage/DirPlugin.pm > index 3c81d24..fa61339 100644 > --- a/PVE/Storage/DirPlugin.pm > +++ b/PVE/Storage/DirPlugin.pm > @@ -128,4 +128,23 @@ sub check_config { > return $opts; > } > =20 > +sub reassign_volume { > + my ($class, $scfg, $storeid, $volname, $target_vmid) =3D @_; > + return $class->file_reassign_volume($scfg, $storeid, $volname, $targ= et_vmid); > +} > + > +sub volume_has_feature { > + my ($class, $scfg, $feature, $storeid, $volname, $snapname, $running= , $opts) =3D @_; > + > + my ($vtype, $name, $vmid, $basename, $basevmid, $isBase, $format) = =3D > + $class->parse_volname($volname); > + > + if ($feature eq 'reassign') { > + return 1 if !$isBase && $format =3D~ /^raw$|^qcow2$|^vmdk$/; > + return undef; > + } else { > + return $class->SUPER::volume_has_feature($scfg, $feature, $storeid, $vo= lname, $snapname, $running, $opts); > + } > +} > + > 1; > diff --git a/PVE/Storage/GlusterfsPlugin.pm b/PVE/Storage/GlusterfsPlugin= .pm > index 2dd414d..5c9fd78 100644 > --- a/PVE/Storage/GlusterfsPlugin.pm > +++ b/PVE/Storage/GlusterfsPlugin.pm > @@ -348,4 +348,23 @@ sub check_connection { > return defined($server) ? 1 : 0; > } > =20 > +sub reassign_volume { > + my ($class, $scfg, $storeid, $volname, $target_vmid) =3D @_; > + return $class->file_reassign_volume($scfg, $storeid, $volname, $targ= et_vmid); > +} > + > +sub volume_has_feature { > + my ($class, $scfg, $feature, $storeid, $volname, $snapname, $running= , $opts) =3D @_; > + > + my ($vtype, $name, $vmid, $basename, $basevmid, $isBase, $format) = =3D > + $class->parse_volname($volname); > + > + if ($feature eq 'reassign') { > + return 1 if !$isBase && $format =3D~ /^raw$|^qcow2$|^vmdk$/; > + return undef; > + } else { > + return $class->SUPER::volume_has_feature($scfg, $feature, $storeid, $vo= lname, $snapname, $running, $opts); > + } > +} > + > 1; > diff --git a/PVE/Storage/LVMPlugin.pm b/PVE/Storage/LVMPlugin.pm > index c0740d4..4203eda 100644 > --- a/PVE/Storage/LVMPlugin.pm > +++ b/PVE/Storage/LVMPlugin.pm > @@ -337,6 +337,13 @@ sub lvcreate { > run_command($cmd, errmsg =3D> "lvcreate '$vg/$name' error"); > } > =20 > +sub lvrename { > + my ($vg, $oldname, $newname) =3D @_; > + > + my $cmd =3D ['/sbin/lvrename', $vg, $oldname, $newname]; > + run_command($cmd, errmsg =3D> "lvrename '${vg}/${oldname}' to '${new= name}' error"); > +} > + > sub alloc_image { > my ($class, $storeid, $scfg, $vmid, $fmt, $name, $size) =3D @_; > =20 > @@ -581,6 +588,7 @@ sub volume_has_feature { > =20 > my $features =3D { > copy =3D> { base =3D> 1, current =3D> 1}, > + reassign =3D> {current =3D> 1}, > }; > =20 > my ($vtype, $name, $vmid, $basename, $basevmid, $isBase) =3D > @@ -681,4 +689,20 @@ sub volume_import_write { > input =3D> '<&'.fileno($input_fh)); > } > =20 > +sub reassign_volume { > + my ($class, $scfg, $storeid, $volname, $target_vmid) =3D @_; > + > + $class->cluster_lock_storage($storeid, $scfg->{shared}, undef, sub { > + my $target_volname =3D $class->find_free_diskname($storeid, $scfg, $tar= get_vmid); > + return $class->rename_volume($scfg, $storeid, $volname, $target_volname= , $target_vmid); > + }); > +} > + > +sub rename_volume { > + my ($class, $scfg, $storeid, $source_volname, $target_volname, $vmid= ) =3D @_; > + > + lvrename($scfg->{vgname}, $source_volname, $target_volname); > + return "${storeid}:${target_volname}"; > +} > + > 1; > diff --git a/PVE/Storage/LvmThinPlugin.pm b/PVE/Storage/LvmThinPlugin.pm > index d1c5b1f..adc4ae2 100644 > --- a/PVE/Storage/LvmThinPlugin.pm > +++ b/PVE/Storage/LvmThinPlugin.pm > @@ -355,6 +355,7 @@ sub volume_has_feature { > template =3D> { current =3D> 1}, > copy =3D> { base =3D> 1, current =3D> 1, snap =3D> 1}, > sparseinit =3D> { base =3D> 1, current =3D> 1}, > + reassign =3D> {current =3D> 1}, > }; > =20 > my ($vtype, $name, $vmid, $basename, $basevmid, $isBase) =3D > diff --git a/PVE/Storage/NFSPlugin.pm b/PVE/Storage/NFSPlugin.pm > index 6abb24b..9d45e9f 100644 > --- a/PVE/Storage/NFSPlugin.pm > +++ b/PVE/Storage/NFSPlugin.pm > @@ -176,4 +176,23 @@ sub check_connection { > return 1; > } > =20 > +sub reassign_volume { > + my ($class, $scfg, $storeid, $volname, $target_vmid) =3D @_; > + return $class->file_reassign_volume($scfg, $storeid, $volname, $targ= et_vmid); > +} > + > +sub volume_has_feature { > + my ($class, $scfg, $feature, $storeid, $volname, $snapname, $running= , $opts) =3D @_; > + > + my ($vtype, $name, $vmid, $basename, $basevmid, $isBase, $format) = =3D > + $class->parse_volname($volname); > + > + if ($feature eq 'reassign') { > + return 1 if !$isBase && $format =3D~ /^raw$|^qcow2$|^vmdk$/; > + return undef; > + } else { > + return $class->SUPER::volume_has_feature($scfg, $feature, $storeid, $vo= lname, $snapname, $running, $opts); > + } > +} > + > 1; > diff --git a/PVE/Storage/Plugin.pm b/PVE/Storage/Plugin.pm > index e6cd99c..d10f1aa 100644 > --- a/PVE/Storage/Plugin.pm > +++ b/PVE/Storage/Plugin.pm > @@ -888,6 +888,7 @@ sub storage_can_replicate { > return 0; > } > =20 > + > sub volume_has_feature { > my ($class, $scfg, $feature, $storeid, $volname, $snapname, $running= , $opts) =3D @_; > =20 > @@ -1411,4 +1412,54 @@ sub volume_import_formats { > return (); > } > =20 > +sub reassign_volume { > + my ($class, $scfg, $storeid, $volname, $target_vmid) =3D @_; > + die "no implemented in class '$class'\n"; not implemented, and maybe s/class/storage plugin/ > +} > + > +# general reassignment method for file/directory based storages > +sub file_reassign_volume { > + my ($class, $scfg, $storeid, $volname, $target_vmid) =3D @_; > + > + my $base; > + my $base_vmid; > + my $format; > + my $source_vmid; > + > + (undef, $volname, $source_vmid, $base, $base_vmid, undef, $format) = =3D $class->parse_volname($volname); > + > + # parse_volname strips the directory from volname > + my $source_volname =3D "${source_vmid}/${volname}"; > + > + if ($base) { > + $base =3D "${base_vmid}/${base}/"; > + } else { > + $base =3D ''; > + } > + > + $class->cluster_lock_storage($storeid, $scfg->{shared}, undef, sub { > + my $target_volname =3D $class->find_free_diskname($storeid, $scfg, $tar= get_vmid, $format, 1); > + > + return $class->rename_volume($scfg, $storeid, $source_volname, $target_= volname, $target_vmid, $base); > + }); > +} > + > +sub rename_volume { > + my ($class, $scfg, $storeid, $source_volname, $target_volname, $vmid= , $base) =3D @_; > + > + my $basedir =3D $class->get_subdir($scfg, 'images'); > + my $imagedir =3D "${basedir}/${vmid}"; > + > + mkpath $imagedir; > + > + my $old_path =3D "${basedir}/${source_volname}"; > + my $new_path =3D "${imagedir}/${target_volname}"; > + > + rename($old_path, $new_path) || > + die "rename '$old_path' to '$new_path' failed - $!\n"; > + > + return "${storeid}:${base}${vmid}/${target_volname}"; > +} > + > + > 1; > diff --git a/PVE/Storage/RBDPlugin.pm b/PVE/Storage/RBDPlugin.pm > index 38f2b46..325937a 100644 > --- a/PVE/Storage/RBDPlugin.pm > +++ b/PVE/Storage/RBDPlugin.pm > @@ -703,6 +703,7 @@ sub volume_has_feature { > template =3D> { current =3D> 1}, > copy =3D> { base =3D> 1, current =3D> 1, snap =3D> 1}, > sparseinit =3D> { base =3D> 1, current =3D> 1}, > + reassign =3D> {current =3D> 1}, > }; > =20 > my ($vtype, $name, $vmid, $basename, $basevmid, $isBase) =3D > @@ -719,4 +720,34 @@ sub volume_has_feature { > return undef; > } > =20 > +sub reassign_volume { > + my ($class, $scfg, $storeid, $volname, $target_vmid) =3D @_; > + > + my $base;; > + (undef, $volname, undef, $base) =3D $class->parse_volname($volname); > + > + if ($base) { > + $base =3D $base . '/'; > + } else { > + $base =3D ''; > + } > + > + $class->cluster_lock_storage($storeid, $scfg->{shared}, undef, sub { > + my $target_volname =3D $class->find_free_diskname($storeid, $scfg, $tar= get_vmid); > + return $class->rename_volume($scfg, $storeid, $volname, $target_volname= , $target_vmid, $base); > + }); > +} > + > +sub rename_volume { > + my ($class, $scfg, $storeid, $source_volname, $target_volname, $vmid= , $base) =3D @_; > + > + my $cmd =3D $rbd_cmd->($scfg, $storeid, 'rename', $source_volname, $= target_volname); > + > + run_rbd_command( > + $cmd, > + errmsg =3D> "could not rename image '${source_volname}' to '${target_vo= lname}'", > + ); > + return "${storeid}:${base}${target_volname}"; > +} > + > 1; > diff --git a/PVE/Storage/ZFSPoolPlugin.pm b/PVE/Storage/ZFSPoolPlugin.pm > index 6ac05b4..42f183c 100644 > --- a/PVE/Storage/ZFSPoolPlugin.pm > +++ b/PVE/Storage/ZFSPoolPlugin.pm > @@ -11,6 +11,8 @@ use PVE::RPCEnvironment; > use PVE::Storage::Plugin; > use PVE::Tools qw(run_command); > =20 > +use Data::Dumper; > + > use base qw(PVE::Storage::Plugin); > =20 > sub type { > @@ -658,6 +660,7 @@ sub volume_has_feature { > copy =3D> { base =3D> 1, current =3D> 1}, > sparseinit =3D> { base =3D> 1, current =3D> 1}, > replicate =3D> { base =3D> 1, current =3D> 1}, > + reassign =3D> {current =3D> 1}, > }; > =20 > my ($vtype, $name, $vmid, $basename, $basevmid, $isBase) =3D > @@ -760,4 +763,29 @@ sub volume_import_formats { > return $class->volume_export_formats($scfg, $storeid, $volname, unde= f, $base_snapshot, $with_snapshots); > } > =20 > +sub reassign_volume { > + my ($class, $scfg, $storeid, $volname, $target_vmid) =3D @_; > + > + my $base;; > + (undef, $volname, undef, $base) =3D $class->parse_volname($volname); > + > + if ($base) { > + $base =3D $base . '/'; > + } else { > + $base =3D ''; > + } > + > + $class->cluster_lock_storage($storeid, $scfg->{shared}, undef, sub { > + my $target_volname =3D $class->find_free_diskname($storeid, $scfg, $tar= get_vmid); > + return $class->rename_volume($scfg, $storeid, $volname, $target_volname= , $target_vmid, $base); > + }); > +} > + > +sub rename_volume { > + my ($class, $scfg, $storeid, $source_volname, $target_volname, $vmid= , $base) =3D @_; > + > + $class->zfs_request($scfg, 5, 'rename', "$scfg->{pool}/$source_volna= me", "$scfg->{pool}/$target_volname"); > + return "${storeid}:${base}${target_volname}"; > +} > + > 1; > --=20 > 2.20.1 >=20 >=20 >=20 > _______________________________________________ > pve-devel mailing list > pve-devel@lists.proxmox.com > https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel >=20 >=20 >=20 =