# HG changeset patch
# User Ian Jackson <Ian.Jackson@xxxxxxxxxxxxx>
# Date 1280499176 -3600
# Node ID 84f8ad68bc58a4039e70da2d9949cc0d059f105b
# Parent 64fa1a9c723ca60a9246283b133c85a1a81806e2
xl: support "xl list <domain>"
xm list takes an optional domain argument; make xl list do likewise.
This also gets rid of a small amount of code which was duplicated
between list_domains and list_domains_details.
Signed-off-by: Ian Jackson <Ian.Jackson@xxxxxxxxxxxxx>
Acked-by: Ian Campbell <ian.campbell@xxxxxxxxxx>
Committed-by: Ian Jackson <ian.jackson@xxxxxxxxxxxxx>
---
tools/libxl/xl_cmdimpl.c | 66 +++++++++++++++++++++++++++--------------------
1 files changed, 39 insertions(+), 27 deletions(-)
diff -r 64fa1a9c723c -r 84f8ad68bc58 tools/libxl/xl_cmdimpl.c
--- a/tools/libxl/xl_cmdimpl.c Fri Jul 30 15:12:10 2010 +0100
+++ b/tools/libxl/xl_cmdimpl.c Fri Jul 30 15:12:56 2010 +0100
@@ -2126,22 +2126,15 @@ void reboot_domain(char *p)
if (rc) { fprintf(stderr,"reboot failed (rc=%d)\n.",rc);exit(-1); }
}
-void list_domains_details(void)
-{
- libxl_dominfo *info;
+void list_domains_details(const libxl_dominfo *info, int nb_domain)
+{
struct domain_config d_config;
char *config_file;
uint8_t *data;
- int nb_domain, i, len, rc;
+ int i, len, rc;
libxl_device_model_info dm_info;
- info = libxl_list_domain(&ctx, &nb_domain);
-
- if (!info) {
- fprintf(stderr, "libxl_domain_infolist failed.\n");
- exit(1);
- }
for (i = 0; i < nb_domain; i++) {
rc = libxl_userdata_retrieve(&ctx, info[i].domid, "xl", &data, &len);
if (rc)
@@ -2153,20 +2146,12 @@ void list_domains_details(void)
free(data);
free(config_file);
}
- free(info);
-}
-
-void list_domains(int verbose)
-{
- libxl_dominfo *info;
- int nb_domain, i;
-
- info = libxl_list_domain(&ctx, &nb_domain);
-
- if (!info) {
- fprintf(stderr, "libxl_domain_infolist failed.\n");
- exit(1);
- }
+}
+
+void list_domains(int verbose, const libxl_dominfo *info, int nb_domain)
+{
+ int i;
+
printf("Name ID Mem
VCPUs\tState\tTime(s)\n");
for (i = 0; i < nb_domain; i++) {
printf("%-40s %5d %5lu %5d %c%c%c%c%c%c %8.1f",
@@ -2187,7 +2172,6 @@ void list_domains(int verbose)
}
putchar('\n');
}
- free(info);
}
void list_vm(void)
@@ -2992,6 +2976,10 @@ int main_list(int argc, char **argv)
{0, 0, 0, 0}
};
+ libxl_dominfo info_buf;
+ libxl_dominfo *info, *info_free=0;
+ int nb_domain, rc;
+
while (1) {
opt = getopt_long(argc, argv, "lvh", long_options, &option_index);
if (opt == -1)
@@ -3013,10 +3001,34 @@ int main_list(int argc, char **argv)
}
}
+ if (optind >= argc) {
+ info = libxl_list_domain(&ctx, &nb_domain);
+ if (!info) {
+ fprintf(stderr, "libxl_domain_infolist failed.\n");
+ exit(1);
+ }
+ info_free = info;
+ } else if (optind == argc-1) {
+ find_domain(argv[optind]);
+ rc = libxl_domain_info(&ctx, &info_buf, domid);
+ if (rc) {
+ fprintf(stderr, "libxl_domain_info failed (code %d).\n", rc);
+ exit(-rc);
+ }
+ info = &info_buf;
+ nb_domain = 1;
+ } else {
+ help("list");
+ exit(2);
+ }
+
if (details)
- list_domains_details();
+ list_domains_details(info, nb_domain);
else
- list_domains(verbose);
+ list_domains(verbose, info, nb_domain);
+
+ free(info_free);
+
exit(0);
}
_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog
|