[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [WIP PATCH 13/16] WIP: tools/xl: Purge list_domains()
Everything previously done by list_domains() is now done with build_list_domain_format() and format(). Signed-off-by: Elliott Mitchell <ehem+xen@xxxxxxx> --- tools/xl/xl_list.c | 90 +++++++++++++++++++++++++++------------------- 1 file changed, 53 insertions(+), 37 deletions(-) diff --git a/tools/xl/xl_list.c b/tools/xl/xl_list.c index ee20d2feee..3ed6da8feb 100644 --- a/tools/xl/xl_list.c +++ b/tools/xl/xl_list.c @@ -342,6 +342,31 @@ const format_table_t formats = { (int *)&_discard->domid - (int *)_discard, {.i = 0}}, }; +static char *build_list_domain_format(bool verbose, bool context, bool claim, + bool numa, bool cpupool) +{ + int size = 4096; + char *fmt = malloc(size); + const char lead[] = "%-40n %5i %5m %5v %s %8.1t"; + + if (!fmt) return NULL; + + memcpy(fmt, lead, sizeof(lead)); + + if (verbose) strcat(fmt, " %u %r %16l"); + else if (context) strcat(fmt, " %16l"); + + if (claim) strcat(fmt, " %5c"); + + if (cpupool) strcat(fmt, " %16p"); + + if (numa) strcat(fmt, " %A"); + + strcat(fmt, "\n"); + + return realloc(fmt, strlen(fmt) + 1); +} + static void list_vm(void) { @@ -365,36 +390,6 @@ static void list_vm(void) libxl_vminfo_list_free(info, nb_vm); } -static void list_domains(bool verbose, bool context, bool claim, bool numa, - bool cpupool, const libxl_dominfo *info, int nb_domain) -{ - int i; - const char lead[] = "%-40n %5i %5m %5v %s %8.1t"; - - format(formats, lead, NULL); - if (verbose) { - format(formats, " %u %r %16l", NULL); - } else if (context) format(formats, " %16l", NULL); - if (claim) format(formats, " %5c", NULL); - if (cpupool) format(formats, " %16p", NULL); - if (numa) format(formats, " %A", NULL); - printf("\n"); - for (i = 0; i < nb_domain; i++) { - format(formats, lead, info + i); - if (verbose) - format(formats, " %u %r", info + i); - if (claim) - format(formats, " %5c", info + i); - if (verbose || context) - format(formats, " %16l", info + i); - if (cpupool) - format(formats, " %16p", info + i); - if (numa) - format(formats, " %A", info + i); - putchar('\n'); - } -} - int main_list(int argc, char **argv) { @@ -470,7 +465,17 @@ int main_list(int argc, char **argv) if (details) dump_by_dominfo_list(default_output_format, stdout, info, nb_domain); - else if (formatstr) { + else { + char *fr = NULL; + + if (!formatstr) formatstr = fr = build_list_domain_format(verbose, + context, false /* claim */, numa, cpupool); + + if (!formatstr) { + fprintf(stderr, "Memory allocation failure.\n"); + return EXIT_FAILURE; + } + format(formats, formatstr, NULL); while (nb_domain) { @@ -478,9 +483,9 @@ int main_list(int argc, char **argv) ++info; --nb_domain; } - } else - list_domains(verbose, context, false /* claim */, numa, cpupool, - info, nb_domain); + + if (fr) free(fr); + } if (info_free) libxl_dominfo_list_free(info_free, nb_domain); @@ -506,7 +511,8 @@ int main_claims(int argc, char **argv) { libxl_dominfo *info; int opt; - int nb_domain; + int nb_domain, i; + char *fmt; SWITCH_FOREACH_OPT(opt, "", NULL, "claims", 0) { /* No options */ @@ -521,9 +527,19 @@ int main_claims(int argc, char **argv) return 1; } - list_domains(false /* verbose */, false /* context */, true /* claim */, - false /* numa */, false /* cpupool */, info, nb_domain); + fmt = build_list_domain_format(false /* verbose */, false /* context */, + true /* claim */, false /* numa */, false /* cpupool */); + + if (!fmt) { + fprintf(stderr, "Memory allocation failure.\n"); + return 1; + } + + format(formats, fmt, NULL); + + for (i = 0; i < nb_domain; ++i) format(formats, fmt, info + i); + free(fmt); libxl_dominfo_list_free(info, nb_domain); return 0; } -- -- (\___(\___(\______ --=> 8-) EHM <=-- ______/)___/)___/) \BS ( | ehem+sigmsg@xxxxxxx PGP 87145445 | ) / \_CS\ | _____ -O #include <stddisclaimer.h> O- _____ | / _/ 8A19\___\_|_/58D2 7E3D DDF4 7BA6 <-PGP-> 41D1 B375 37D0 8714\_|_/___/5445
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |