From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) by lore.proxmox.com (Postfix) with ESMTPS id 9128B1FF183 for ; Wed, 16 Jul 2025 08:33:16 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id DD9F5166F2; Wed, 16 Jul 2025 08:33:06 +0200 (CEST) To: pve-devel@lists.proxmox.com Date: Wed, 16 Jul 2025 08:31:49 +0200 In-Reply-To: <20250716063153.1647681-1-alexandre.derumier@groupe-cyllene.com> References: <20250716063153.1647681-1-alexandre.derumier@groupe-cyllene.com> MIME-Version: 1.0 Message-ID: List-Id: Proxmox VE development discussion List-Post: From: Alexandre Derumier via pve-devel Precedence: list Cc: Alexandre Derumier X-Mailman-Version: 2.1.29 X-BeenThere: pve-devel@lists.proxmox.com List-Subscribe: , List-Unsubscribe: , List-Archive: Reply-To: Proxmox VE development discussion List-Help: Subject: [pve-devel] [PATCH FOLLOW-UP storage 10/14] lvmplugin: add volume_snapshot_info Content-Type: multipart/mixed; boundary="===============0217112922834313239==" Errors-To: pve-devel-bounces@lists.proxmox.com Sender: "pve-devel" --===============0217112922834313239== Content-Type: message/rfc822 Content-Disposition: inline Return-Path: X-Original-To: pve-devel@lists.proxmox.com Delivered-To: pve-devel@lists.proxmox.com 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 21FA6DAE16 for ; Wed, 16 Jul 2025 08:33:05 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 07FFE15D05 for ; Wed, 16 Jul 2025 08:32:11 +0200 (CEST) Received: from bastiontest.odiso.net (unknown [IPv6:2a0a:1580:2000:6700::14]) (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 for ; Wed, 16 Jul 2025 08:32:06 +0200 (CEST) Received: from formationkvm1.odiso.net (unknown [10.11.201.57]) by bastiontest.odiso.net (Postfix) with ESMTP id 537EA862E59; Wed, 16 Jul 2025 08:31:56 +0200 (CEST) Received: by formationkvm1.odiso.net (Postfix, from userid 0) id 515EF104D614; Wed, 16 Jul 2025 08:31:56 +0200 (CEST) From: Alexandre Derumier To: pve-devel@lists.proxmox.com Subject: [PATCH FOLLOW-UP storage 10/14] lvmplugin: add volume_snapshot_info Date: Wed, 16 Jul 2025 08:31:49 +0200 Message-Id: <20250716063153.1647681-15-alexandre.derumier@groupe-cyllene.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250716063153.1647681-1-alexandre.derumier@groupe-cyllene.com> References: <20250716063153.1647681-1-alexandre.derumier@groupe-cyllene.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 1 AWL -1.350 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_NONE 0.1 DMARC none policy HEADER_FROM_DIFFERENT_DOMAINS 0.001 From and EnvelopeFrom 2nd level mail domains are different KAM_DMARC_NONE 0.25 DKIM has Failed or SPF has failed on the message and the domain has no DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment KAM_LAZY_DOMAIN_SECURITY 1 Sending domain does not have any anti-forgery methods RDNS_NONE 0.793 Delivered to internal network by a host with no rDNS SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_NONE 0.001 SPF: sender does not publish an SPF Record URIBL_BLACK 3 Contains an URL listed in the URIBL blacklist [plugin.pm] and remove public methods: get_snapname_from_path get_snap_volname Signed-off-by: Alexandre Derumier --- src/PVE/Storage/LVMPlugin.pm | 76 ++++++++++++++++++++++++++---------- src/PVE/Storage/Plugin.pm | 41 ++++++++----------- 2 files changed, 73 insertions(+), 44 deletions(-) diff --git a/src/PVE/Storage/LVMPlugin.pm b/src/PVE/Storage/LVMPlugin.pm index 8a61bc5..0e2c38c 100644 --- a/src/PVE/Storage/LVMPlugin.pm +++ b/src/PVE/Storage/LVMPlugin.pm @@ -443,20 +443,6 @@ sub parse_volname { die "unable to parse lvm volume name '$volname'\n"; } -#return snapshot name from a file path -sub get_snapname_from_path { - my ($class, $volname, $path) = @_; - - my $basepath = basename($path); - my $name = ($volname =~ s/\.[^.]+$//r); - if ($basepath =~ m/^snap_${name}_(.*)\.qcow2$/) { - return $1; - } elsif ($basepath eq $volname) { - return 'current'; - } - return undef; -} - my sub get_snap_name { my ($class, $volname, $snapname) = @_; @@ -472,12 +458,6 @@ my sub get_snap_name { } } -sub get_snap_volname { - my ($class, $volname, $snapname) = @_; - - return get_snap_name($class, $volname, $snapname); -} - sub filesystem_path { my ($class, $scfg, $volname, $snapname) = @_; @@ -787,6 +767,62 @@ sub status { return undef; } +sub volume_snapshot_info { + my ($class, $scfg, $storeid, $volname) = @_; + + my $get_snapname_from_path = sub { + my ($volname, $path) = @_; + + my $basepath = basename($path); + my $name = ($volname =~ s/\.[^.]+$//r); + if ($basepath =~ m/^snap_${name}_(.*)\.qcow2$/) { + return $1; + } elsif ($basepath eq $volname) { + return 'current'; + } + return undef; + }; + + my $path = $class->filesystem_path($scfg, $volname); + my ($vtype, $name, $vmid, $basename, $basevmid, $isBase, $format) = + $class->parse_volname($volname); + + my $json = PVE::Storage::Common::qemu_img_info($path, undef, 10, 1); + die "failed to query file information with qemu-img\n" if !$json; + my $json_decode = eval { decode_json($json) }; + if ($@) { + die "Can't decode qemu snapshot list. Invalid JSON: $@\n"; + } + my $info = {}; + my $order = 0; + return $info if ref($json_decode) ne 'ARRAY'; + + #no snapshot or external snapshots is an arrayref + my $snapshots = $json_decode; + for my $snap (@$snapshots) { + my $snapfile = $snap->{filename}; + my $snapname = $get_snapname_from_path->($volname, $snapfile); + #not a proxmox snapshot + next if !$snapname; + + my $snapvolname = get_snap_name($class, $volname, $snapname); + + $info->{$snapname}->{order} = $order; + $info->{$snapname}->{file} = $snapfile; + $info->{$snapname}->{volname} = "$snapvolname"; + $info->{$snapname}->{volid} = "$storeid:$snapvolname"; + + my $parentfile = $snap->{'backing-filename'}; + if ($parentfile) { + my $parentname = $get_snapname_from_path->($volname, $parentfile); + $info->{$snapname}->{parent} = $parentname; + $info->{$parentname}->{child} = $snapname; + } + $order++; + } + return $info; +} + sub activate_storage { my ($class, $storeid, $scfg, $cache) = @_; diff --git a/src/PVE/Storage/Plugin.pm b/src/PVE/Storage/Plugin.pm index 8ea62e4..aafb13c 100644 --- a/src/PVE/Storage/Plugin.pm +++ b/src/PVE/Storage/Plugin.pm @@ -1718,27 +1718,6 @@ sub status { return ($res->{total}, $res->{avail}, $res->{used}, 1); } -sub get_snap_volname { - my ($class, $volname, $snapname) = @_; - - my $vmid = ($class->parse_volname($volname))[2]; - my $name = get_snap_name($class, $volname, $snapname); - return "$vmid/$name"; -} - -#return snapshot name from a file path -sub get_snapname_from_path { - my ($class, $volname, $path) = @_; - - my $basepath = basename($path); - if ($basepath =~ m/^snap-(.*)-vm(.*)$/) { - return $1; - } elsif ($basepath eq basename($volname)) { - return 'current'; - } - return undef; -} - # Returns a hash with the snapshot names as keys and the following data: # id - Unique id to distinguish different snapshots even if the have the same name. # timestamp - Creation time of the snapshot (seconds since epoch). @@ -1746,6 +1725,18 @@ sub get_snapname_from_path { sub volume_snapshot_info { my ($class, $scfg, $storeid, $volname) = @_; + my $get_snapname_from_path = sub { + my ($volname, $path) = @_; + + my $basepath = basename($path); + if ($basepath =~ m/^snap-(.*)-vm(.*)$/) { + return $1; + } elsif ($basepath eq basename($volname)) { + return 'current'; + } + return undef; + }; + my $path = $class->filesystem_path($scfg, $volname); my ($vtype, $name, $vmid, $basename, $basevmid, $isBase, $format) = $class->parse_volname($volname); @@ -1772,11 +1763,13 @@ sub volume_snapshot_info { my $snapshots = $json_decode; for my $snap (@$snapshots) { my $snapfile = $snap->{filename}; - my $snapname = $class->get_snapname_from_path($volname, $snapfile); + my $snapname = $get_snapname_from_path->($volname, $snapfile); #not a proxmox snapshot next if !$snapname; - my $snapvolname = $class->get_snap_volname($volname, $snapname); + my $snapvolname = get_snap_name($class, $volname, $snapname); + $snapvolname = "$vmid/$snapvolname"; + $info->{$snapname}->{order} = $order; $info->{$snapname}->{file} = $snapfile; $info->{$snapname}->{volname} = "$snapvolname"; @@ -1785,7 +1778,7 @@ sub volume_snapshot_info { my $parentfile = $snap->{'backing-filename'}; if ($parentfile) { - my $parentname = $class->get_snapname_from_path($volname, $parentfile); + my $parentname = $get_snapname_from_path->($volname, $parentfile); $info->{$snapname}->{parent} = $parentname; $info->{$parentname}->{child} = $snapname; } -- 2.39.5 --===============0217112922834313239== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel --===============0217112922834313239==--