+ my $p = XML::XPath->new (xml => $xml);
+ my @disks = $p->findnodes ('//devices/disk/source/@dev');
+ push (@disks, $p->findnodes ('//devices/disk/source/@file'));
+
+ # Code in Sys::Guestfs::Lib dies here if there are no disks at all.
+
+ return map { $_->getData } @disks;
+}
+
+# Sort the domains by name for display.
+@domains = sort { $a->{name} cmp $b->{name} } @domains;
+
+# Since we got this far, we're somewhat sure we're going to
+# get to print the result, so display the title.
+print_title ();
+
+# To minimize the number of times we have to launch the appliance,
+# shuffle as many domains together as we can, but not exceeding
+# MAX_DISKS per request. If --one-per-guest was requested then only
+# request disks from a single guest each time.
+if ($one_per_guest) {
+ foreach (@domains) {
+ my @request = ( $_ );
+ multi_df (@request);
+ }
+} else {
+ while (@domains) {
+ my $n = 0; # number of disks added so far
+ my @request = ();
+ while (@domains) {
+ my $c = @{$domains[0]->{disks}};
+ if ($c > $max_disks) {
+ warn __x("virt-df: ignoring {name}, it has too many disks ({c} > {max})",
+ name => $domains[0]->{name},
+ c => $c, max => $max_disks);
+ next;
+ }
+ last if $n + $c > $max_disks;
+ $n += $c;
+ push @request, shift (@domains);
+ }
+ multi_df (@request);