]> git.proxmox.com Git - qemu-server.git/blobdiff - PVE/CLI/qm.pm
Fix #1999: cli: listsnapshot: handle multiple roots and mark orphaned as root
[qemu-server.git] / PVE / CLI / qm.pm
index 87b97ce08da9e597e1ce37f26d5c984cc4a09d0a..b5e838e1dfa9c78e26cfed2800d0cb6b4db762d2 100755 (executable)
@@ -926,12 +926,13 @@ our $cmddef = {
 
                        my $snapshots = { map { $_->{name} => $_ } @$res };
 
-                       my $root;
+                       my @roots;
                        foreach my $e (@$res) {
-                           if (my $parent = $e->{parent}) {
+                           my $parent;
+                           if (($parent = $e->{parent}) && defined $snapshots->{$parent}) {
                                push @{$snapshots->{$parent}->{children}}, $e->{name};
                            } else {
-                               $root = $e->{name};
+                               push @roots, $e->{name};
                            }
                        }
 
@@ -967,7 +968,9 @@ our $cmddef = {
                            }
                        };
 
-                       $snapshottree->('`->', $root, $snapshots);
+                       foreach my $root (sort $snaptimesort @roots) {
+                           $snapshottree->('`->', $root, $snapshots);
+                       }
                    }],
 
     rollback => [ "PVE::API2::Qemu", 'rollback', ['vmid', 'snapname'], { node => $nodename } , $upid_exit ],