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 F15AF60995 for ; Thu, 3 Sep 2020 09:56:30 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id DDD691626A for ; Thu, 3 Sep 2020 09:56:00 +0200 (CEST) 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)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id D94DF1625E for ; Thu, 3 Sep 2020 09:55:58 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 9B0C4445FC for ; Thu, 3 Sep 2020 09:55:58 +0200 (CEST) Date: Thu, 03 Sep 2020 09:55:51 +0200 From: Fabian =?iso-8859-1?q?Gr=FCnbichler?= To: Proxmox VE development discussion References: <20200901124421.25901-1-a.lauterer@proxmox.com> <20200901124421.25901-4-a.lauterer@proxmox.com> In-Reply-To: <20200901124421.25901-4-a.lauterer@proxmox.com> MIME-Version: 1.0 User-Agent: astroid/0.15.0 (https://github.com/astroidmail/astroid) Message-Id: <1599119469.zi7lf79gc3.astroid@nora.none> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-SPAM-LEVEL: Spam detection results: 0 AWL 0.031 Adjusted score from AWL reputation of From: address KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust 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. [rbdplugin.pm, lvmplugin.pm, proxmox.com, plugin.pm, zfspoolplugin.pm, storage.pm] Subject: Re: [pve-devel] [PATCH v2 storage 3/5] 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: Thu, 03 Sep 2020 07:56:31 -0000 some small nits inline On September 1, 2020 2:44 pm, Aaron Lauterer wrote: > Functionality has been added for the following storage types: >=20 > * dir based ones > * directory > * NFS > * CIFS > * ZFS > * (thin) LVM > * Ceph >=20 > Signed-off-by: Aaron Lauterer > --- > rfc -> v1 -> v2: nothing changed >=20 > PVE/Storage.pm | 10 ++++++++++ > PVE/Storage/LVMPlugin.pm | 15 +++++++++++++++ > PVE/Storage/Plugin.pm | 21 +++++++++++++++++++++ > PVE/Storage/RBDPlugin.pm | 13 +++++++++++++ > PVE/Storage/ZFSPoolPlugin.pm | 9 +++++++++ > 5 files changed, 68 insertions(+) >=20 > diff --git a/PVE/Storage.pm b/PVE/Storage.pm > index 4a60615..919c606 100755 > --- a/PVE/Storage.pm > +++ b/PVE/Storage.pm > @@ -1759,6 +1759,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/LVMPlugin.pm b/PVE/Storage/LVMPlugin.pm > index c0740d4..28ff6c8 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 > @@ -681,4 +688,12 @@ sub volume_import_write { > input =3D> '<&'.fileno($input_fh)); > } > =20 > +sub reassign_volume { > + my ($class, $scfg, $storeid, $volname, $target_vmid) =3D @_; > + > + my $target_volname =3D $class->find_free_diskname($storeid, $scfg, $= target_vmid); > + lvrename($scfg->{vgname}, $volname, $target_volname); > + return "${storeid}:${target_volname}"; > +} > + > 1; > diff --git a/PVE/Storage/Plugin.pm b/PVE/Storage/Plugin.pm > index 8a58ff4..770a482 100644 > --- a/PVE/Storage/Plugin.pm > +++ b/PVE/Storage/Plugin.pm > @@ -1411,4 +1411,25 @@ sub volume_import_formats { > return (); > } > =20 > +sub reassign_volume { > + my ($class, $scfg, $storeid, $volname, $target_vmid) =3D @_; > + > + my $basedir =3D $class->get_subdir($scfg, 'images'); > + my $imagedir =3D "${basedir}/${target_vmid}"; > + > + mkpath $imagedir; > + > + my @parsed_volname =3D $class->parse_volname($volname); > + my $format =3D $parsed_volname[6]; > + my $target_volname =3D $class->find_free_diskname($storeid, $scfg, $= target_vmid, $format, 1); > + $volname vs $target_volname, but one includes the vmid the other does=20 not? rename 'target_volname' to diskname (like the sub you call), then=20 you can do=20 my $target_volname =3D "$target_vmid/$diskname"; > + my $old_path =3D "${basedir}/${volname}"; > + my $new_path =3D "${imagedir}/${target_volname}"; and construct both paths in the same fashion > + > + rename($old_path, $new_path) || > + die "rename '$old_path' to '$new_path' failed - $!\n"; > + > + return "${storeid}:${target_vmid}/${target_volname}"; and return $storeid:$target_volname here > +} > + > 1; > diff --git a/PVE/Storage/RBDPlugin.pm b/PVE/Storage/RBDPlugin.pm > index 38f2b46..c0bd74c 100644 > --- a/PVE/Storage/RBDPlugin.pm > +++ b/PVE/Storage/RBDPlugin.pm > @@ -719,4 +719,17 @@ sub volume_has_feature { > return undef; > } > =20 > +sub reassign_volume { > + my ($class, $scfg, $storeid, $volname, $target_vmid) =3D @_; > + > + my $target_volname =3D $class->find_free_diskname($storeid, $scfg, $= target_vmid); > + my $cmd =3D $rbd_cmd->($scfg, $storeid, 'rename', $volname, $target_= volname); > + > + run_rbd_command( > + $cmd, > + errmsg =3D> "could not rename image '$volname' to '$target_volname'", > + ); > + return "${storeid}:${target_volname}"; > +} > + > 1; > diff --git a/PVE/Storage/ZFSPoolPlugin.pm b/PVE/Storage/ZFSPoolPlugin.pm > index 10354b3..5baa5c2 100644 > --- a/PVE/Storage/ZFSPoolPlugin.pm > +++ b/PVE/Storage/ZFSPoolPlugin.pm > @@ -749,4 +749,13 @@ 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 $target_volname =3D $class->find_free_diskname($storeid, $scfg, $= target_vmid); > + $class->zfs_request($scfg, 5, 'rename', "$scfg->{pool}/$volname", "$= scfg->{pool}/$target_volname"); > + > + return "${storeid}:${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 =