[pve-devel] [PATCH pve-storage 5/6] PVE/Storage/Plugin.pm: return ctime for vm images

Dietmar Maurer dietmar at proxmox.com
Wed Mar 4 11:46:21 CET 2020


Changed file_size_info() to additionally return ctime to avoid
another stat() call.

Signed-off-by: Dietmar Maurer <dietmar at proxmox.com>
---
 PVE/Storage/Plugin.pm | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/PVE/Storage/Plugin.pm b/PVE/Storage/Plugin.pm
index 85af1c8..7951c13 100644
--- a/PVE/Storage/Plugin.pm
+++ b/PVE/Storage/Plugin.pm
@@ -718,8 +718,12 @@ sub free_image {
 sub file_size_info {
     my ($filename, $timeout) = @_;
 
-    if (-d $filename) {
-	return wantarray ? (0, 'subvol', 0, undef) : 1;
+    my @fs = stat($filename);
+    my $mode = $fs[2];
+    my $ctime = $fs[10];
+
+    if (S_ISDIR($mode)) {
+	return wantarray ? (0, 'subvol', 0, undef, $ctime) : 1;
     }
 
     my $json = '';
@@ -737,7 +741,7 @@ sub file_size_info {
 
     my ($size, $format, $used, $parent) = $info->@{qw(virtual-size format actual-size backing-filename)};
 
-    return wantarray ? ($size, $format, $used, $parent) : $size;
+    return wantarray ? ($size, $format, $used, $parent, $ctime) : $size;
 }
 
 sub volume_size_info {
@@ -872,7 +876,7 @@ sub list_images {
 
 	next if !$vollist && defined($vmid) && ($owner ne $vmid);
 
-	my ($size, $format, $used, $parent) = file_size_info($fn);
+	my ($size, $format, $used, $parent, $ctime) = file_size_info($fn);
 	next if !($format && defined($size));
 
 	my $volid;
@@ -888,10 +892,14 @@ sub list_images {
 	    next if !$found;
 	}
 
-	push @$res, {
+        my $info = {
 	    volid => $volid, format => $format,
 	    size => $size, vmid => $owner, used => $used, parent => $parent
 	};
+
+        $info->{ctime} = $ctime if $ctime;
+
+        push @$res, $info;
     }
 
     return $res;
-- 
2.20.1




More information about the pve-devel mailing list