]> git.proxmox.com Git - pve-storage.git/commitdiff
base plugin: return ctime for vm images
authorDietmar Maurer <dietmar@proxmox.com>
Wed, 4 Mar 2020 10:46:21 +0000 (11:46 +0100)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Fri, 6 Mar 2020 18:26:45 +0000 (19:26 +0100)
Changed file_size_info() to additionally return ctime to avoid
another stat() call.

Signed-off-by: Dietmar Maurer <dietmar@proxmox.com>
PVE/Storage/Plugin.pm

index 85af1c8ec94c835e73095a1622508f20617ace50..7951c130ecf169e32d21caac540a7dd48c6d219f 100644 (file)
@@ -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;