/* Perform 'df' operation on the domain(s) given in the list. */ static void multi_df (struct domain *domains, size_t n, size_t *errors_r) { size_t i; size_t nd; size_t count; int r; char **devices; char **domain_devices; /* Add all the disks to the handle (since they were added in reverse * order, we must add them here in reverse too). */ for (i = 0, count = 0; i < n; ++i) count += add_disks_to_handle_reverse (domains[i].disks, errors_r); if (count == 0) return; /* Launch the handle. */ if (guestfs_launch (g) == -1) exit (EXIT_FAILURE); devices = guestfs_list_devices (g); if (devices == NULL) exit (EXIT_FAILURE); for (i = 0, nd = 0; i < n; ++i) { /* Find out how many non-failed disks this domain has. */ count = count_non_failed_disks (domains[i].disks); if (count == 0) continue; /* Duplicate the devices into a separate list for convenience. * Note this doesn't duplicate the strings themselves. */ domain_devices = duplicate_first_n (&devices[nd], count); r = df_on_handle (domains[i].name, domains[i].uuid, domain_devices, nd); nd += count; free (domain_devices); /* Something broke in df_on_handle. Give up on the remaining * devices for this handle, but keep going on the next handle. */ if (r == -1) { (*errors_r)++; break; } } for (i = 0; devices[i] != NULL; ++i) free (devices[i]); free (devices); /* Reset the handle. */ reset_guestfs_handle (); }
/* Perform 'df' operation on the domain(s) given in the list. */ static void multi_df (struct domain *domains, size_t n) { size_t i; size_t nd; int r; char **devices; /* Add all the disks to the handle (since they were added in reverse * order, we must add them here in reverse too). */ for (i = 0; i < n; ++i) add_disks_to_handle_reverse (domains[i].disks); /* Launch the handle. */ if (guestfs_launch (g) == -1) exit (EXIT_FAILURE); devices = guestfs_list_devices (g); if (devices == NULL) exit (EXIT_FAILURE); /* Check the number of disks we think we added is the same as the * number of devices returned by libguestfs. */ nd = 0; for (i = 0; i < n; ++i) nd += domains[i].nr_disks; assert (nd == count_strings (devices)); nd = 0; for (i = 0; i < n; ++i) { /* So that &devices[nd] is a NULL-terminated list of strings. */ char *p = devices[nd + domains[i].nr_disks]; devices[nd + domains[i].nr_disks] = NULL; r = df_on_handle (domains[i].name, domains[i].uuid, &devices[nd], nd); /* Restore devices to original. */ devices[nd + domains[i].nr_disks] = p; nd += domains[i].nr_disks; /* Something broke in df_on_handle. Give up on the remaining * devices for this handle, but keep going on the next handle. */ if (r == -1) break; } for (i = 0; devices[i] != NULL; ++i) free (devices[i]); free (devices); /* Reset the handle. */ reset_guestfs_handle (); }