summaryrefslogtreecommitdiffstats
path: root/align/scan.c
diff options
context:
space:
mode:
authorRichard W.M. Jones <rjones@redhat.com>2012-04-17 10:38:07 +0100
committerRichard W.M. Jones <rjones@redhat.com>2012-04-17 10:38:07 +0100
commitfb401ebff837f9df7c06acb8467b2c03d5b8ced0 (patch)
tree2cd06b9a60fd314e5a5ea4505cd944a60ee280a2 /align/scan.c
parent5ec0fba56e76409b234b0e0daa8a0edf06104812 (diff)
downloadlibguestfs-fb401ebff837f9df7c06acb8467b2c03d5b8ced0.tar.gz
libguestfs-fb401ebff837f9df7c06acb8467b2c03d5b8ced0.tar.xz
libguestfs-fb401ebff837f9df7c06acb8467b2c03d5b8ced0.zip
virt-alignment-scan: Add ability to list all domains.
The output looks like this: F16x64:/dev/sda1 1048576 1024K ok F16x64:/dev/sda2 2097152 2048K ok F16x64:/dev/sda3 526385152 2048K ok If the --uuid option is used, then UUIDs are shown instead of names.
Diffstat (limited to 'align/scan.c')
-rw-r--r--align/scan.c71
1 files changed, 49 insertions, 22 deletions
diff --git a/align/scan.c b/align/scan.c
index 7b4631ab..e1fd0d04 100644
--- a/align/scan.c
+++ b/align/scan.c
@@ -39,6 +39,7 @@
#include "guestfs.h"
#include "options.h"
+#include "scan.h"
/* These globals are shared with options.c. */
guestfs_h *g;
@@ -53,8 +54,6 @@ int inspector = 0;
static int quiet = 0; /* --quiet */
-static int scan (void);
-
static inline char *
bad_cast (char const *s)
{
@@ -111,6 +110,7 @@ main (int argc, char *argv[])
{ "format", 2, 0, 0 },
{ "help", 0, 0, HELP_OPTION },
{ "quiet", 0, 0, 'q' },
+ { "uuid", 0, 0, 0, },
{ "verbose", 0, 0, 'v' },
{ "version", 0, 0, 'V' },
{ 0, 0, 0, 0 }
@@ -120,6 +120,9 @@ main (int argc, char *argv[])
const char *format = NULL;
int c;
int option_index;
+ int uuid = 0;
+ /* This just needs to be larger than any alignment we care about. */
+ size_t worst_alignment = UINT_MAX;
int exit_code;
g = guestfs_create ();
@@ -141,6 +144,8 @@ main (int argc, char *argv[])
format = NULL;
else
format = optarg;
+ } else if (STREQ (long_options[option_index].name, "uuid")) {
+ uuid = 1;
} else {
fprintf (stderr, _("%s: unknown long option: %s (%d)\n"),
program_name, long_options[option_index].name, option_index);
@@ -197,30 +202,50 @@ main (int argc, char *argv[])
usage (EXIT_FAILURE);
/* The user didn't specify any drives to scan. */
- if (drvs == NULL)
- usage (EXIT_FAILURE);
+ if (drvs == NULL) {
+#if defined(HAVE_LIBVIRT) && defined(HAVE_LIBXML2)
+ get_domains_from_libvirt (uuid, &worst_alignment);
+#else
+ fprintf (stderr, _("%s: compiled without support for libvirt and/or libxml2.\n"),
+ program_name);
+ exit (EXIT_FAILURE);
+#endif
+ } else {
+ if (uuid) {
+ fprintf (stderr, _("%s: --uuid option cannot be used with -a or -d\n"),
+ program_name);
+ exit (EXIT_FAILURE);
+ }
- /* Add domains/drives from the command line (for a single guest). */
- add_drives (drvs, 'a');
+ /* Add domains/drives from the command line (for a single guest). */
+ add_drives (drvs, 'a');
- if (guestfs_launch (g) == -1)
- exit (EXIT_FAILURE);
+ if (guestfs_launch (g) == -1)
+ exit (EXIT_FAILURE);
+
+ /* Free up data structures, no longer needed after this point. */
+ free_drives (drvs);
- /* Free up data structures, no longer needed after this point. */
- free_drives (drvs);
+ /* Perform the scan. */
+ scan (&worst_alignment, NULL);
- /* Perform the scan. */
- exit_code = scan ();
+ guestfs_close (g);
+ }
- guestfs_close (g);
+ /* Decide on an appropriate exit code. */
+ if (worst_alignment < 4096)
+ exit_code = 3;
+ else if (worst_alignment < 65536)
+ exit_code = 2;
+ else
+ exit_code = 0;
exit (exit_code);
}
-static int
-scan (void)
+void
+scan (size_t *worst_alignment, const char *prefix)
{
- int exit_code = 0;
char **devices;
size_t i, j;
size_t alignment;
@@ -247,9 +272,13 @@ scan (void)
/* Start offset of the partition in bytes. */
start = parts->val[j].part_start;
- if (!quiet)
+ if (!quiet) {
+ if (prefix)
+ printf ("%s:", prefix);
+
printf ("%s%d %12" PRIu64 " ",
devices[i], (int) parts->val[j].part_num, start);
+ }
/* What's the alignment? */
if (start == 0) /* Probably not possible, but anyway. */
@@ -267,13 +296,13 @@ scan (void)
printf ("- ");
}
+ if (alignment < *worst_alignment)
+ *worst_alignment = alignment;
+
if (alignment < 12) { /* Bad in general: < 4K alignment */
- exit_code = 3;
if (!quiet)
printf ("bad (%s)\n", _("alignment < 4K"));
} else if (alignment < 16) { /* Bad on NetApps: < 64K alignment */
- if (exit_code < 2)
- exit_code = 2;
if (!quiet)
printf ("bad (%s)\n", _("alignment < 64K"));
} else {
@@ -286,6 +315,4 @@ scan (void)
free (devices[i]);
}
free (devices);
-
- return exit_code;
}