debuggers.hg

changeset 21267:a4489cf8de22

xl: add "xl info" command

The info subcommand was missing from the xl tool. Use the new libxl
wrapper functions to create a clone of "xm info". The splitting into
several smaller functions is enspired by the implementation in
XendNode.py.

Signed-off-by: Andre Przywara <andre.przywara@amd.com>
Acked-by: Vincent Hanquez <vincent.hanquez@eu.citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Thu Apr 22 09:39:58 2010 +0100 (2010-04-22)
parents 357a30e4c7cf
children 11d20f17f82c
files tools/libxl/xl.c
line diff
     1.1 --- a/tools/libxl/xl.c	Thu Apr 22 09:39:17 2010 +0100
     1.2 +++ b/tools/libxl/xl.c	Thu Apr 22 09:39:58 2010 +0100
     1.3 @@ -30,6 +30,7 @@
     1.4  #include <sys/socket.h>
     1.5  #include <sys/select.h>
     1.6  #include <arpa/inet.h>
     1.7 +#include <sys/utsname.h> /* for utsname in xl info */
     1.8  #include <xenctrl.h>
     1.9  #include <ctype.h>
    1.10  #include <inttypes.h>
    1.11 @@ -2636,6 +2637,117 @@ int main_vcpuset(int argc, char **argv)
    1.12      exit(0);
    1.13  }
    1.14  
    1.15 +static void output_xeninfo(void)
    1.16 +{
    1.17 +    const libxl_version_info *info;
    1.18 +    int sched_id;
    1.19 +
    1.20 +    info = libxl_get_version_info(&ctx);
    1.21 +    if ((sched_id = libxl_get_sched_id(&ctx)) < 0) {
    1.22 +        fprintf(stderr, "get_sched_id sysctl failed.\n");
    1.23 +        return;
    1.24 +    }
    1.25 +
    1.26 +    printf("xen_major              : %d\n", info->xen_version_major);
    1.27 +    printf("xen_minor              : %d\n", info->xen_version_minor);
    1.28 +    printf("xen_extra              : %s\n", info->xen_version_extra);
    1.29 +    printf("xen_caps               : %s\n", info->capabilities);
    1.30 +    printf("xen_scheduler          : %s\n",
    1.31 +        sched_id == XEN_SCHEDULER_SEDF ? "sedf" :
    1.32 +        sched_id == XEN_SCHEDULER_CREDIT ? "credit" :
    1.33 +        sched_id == XEN_SCHEDULER_CREDIT2 ? "credit2" : "unknown");
    1.34 +    printf("xen_pagesize           : %lu\n", info->pagesize);
    1.35 +    printf("platform_params        : virt_start=0x%lx\n", info->virt_start);
    1.36 +    printf("xen_changeset          : %s\n", info->changeset);
    1.37 +    printf("xen_commandline        : %s\n", info->commandline);
    1.38 +    printf("cc_compiler            : %s\n", info->compiler);
    1.39 +    printf("cc_compile_by          : %s\n", info->compile_by);
    1.40 +    printf("cc_compile_domain      : %s\n", info->compile_domain);
    1.41 +    printf("cc_compile_date        : %s\n", info->compile_date);
    1.42 +
    1.43 +    return;
    1.44 +}
    1.45 +
    1.46 +static void output_nodeinfo(void)
    1.47 +{
    1.48 +    struct utsname utsbuf;
    1.49 +
    1.50 +    uname(&utsbuf);
    1.51 +
    1.52 +    printf("host                   : %s\n", utsbuf.nodename);
    1.53 +    printf("release                : %s\n", utsbuf.release);
    1.54 +    printf("version                : %s\n", utsbuf.version);
    1.55 +    printf("machine                : %s\n", utsbuf.machine);
    1.56 +
    1.57 +    return;
    1.58 +}
    1.59 +
    1.60 +static void output_physinfo(void)
    1.61 +{
    1.62 +    struct libxl_physinfo info;
    1.63 +    const libxl_version_info *vinfo;
    1.64 +    unsigned int i;
    1.65 +
    1.66 +    if (libxl_get_physinfo(&ctx, &info) != 0) {
    1.67 +        fprintf(stderr, "libxl_physinfo failed.\n");
    1.68 +        return;
    1.69 +    }
    1.70 +
    1.71 +    printf("nr_cpus                : %d\n", info.nr_cpus);
    1.72 +    printf("nr_nodes               : %d\n", info.nr_nodes);
    1.73 +    printf("cores_per_socket       : %d\n", info.cores_per_socket);
    1.74 +    printf("threads_per_core       : %d\n", info.threads_per_core);
    1.75 +    printf("cpu_mhz                : %d\n", info.cpu_khz / 1000);
    1.76 +    printf("hw_caps                : ");
    1.77 +    for (i = 0; i < 8; i++)
    1.78 +        printf("%08x%c", info.hw_cap[i], i < 7 ? ':' : '\n');
    1.79 +    printf("virt_caps              :");
    1.80 +    if (info.phys_cap & XEN_SYSCTL_PHYSCAP_hvm)
    1.81 +        printf(" hvm");
    1.82 +    if (info.phys_cap & XEN_SYSCTL_PHYSCAP_hvm_directio)
    1.83 +        printf(" hvm_directio");
    1.84 +    printf("\n");
    1.85 +    vinfo = libxl_get_version_info(&ctx);
    1.86 +    i = (1 << 20) / vinfo->pagesize;
    1.87 +    printf("total_memory           : %lu\n", info.total_pages / i);
    1.88 +    printf("free_memory            : %lu\n", info.free_pages / i);
    1.89 +
    1.90 +    return;
    1.91 +}
    1.92 +
    1.93 +void info(int verbose)
    1.94 +{
    1.95 +    output_nodeinfo();
    1.96 +
    1.97 +    output_physinfo();
    1.98 +
    1.99 +    output_xeninfo();
   1.100 +
   1.101 +    printf("xend_config_format     : 4\n");
   1.102 +
   1.103 +    return;
   1.104 +}
   1.105 +
   1.106 +void main_info(int argc, char **argv)
   1.107 +{
   1.108 +    int opt, verbose;
   1.109 +
   1.110 +    verbose = 0;
   1.111 +    while ((opt = getopt(argc, argv, "h")) != -1) {
   1.112 +        switch (opt) {
   1.113 +        case 'h':
   1.114 +            help("vcpu-list");
   1.115 +            exit(0);
   1.116 +        default:
   1.117 +            fprintf(stderr, "option `%c' not supported.\n", opt);
   1.118 +            break;
   1.119 +        }
   1.120 +    }
   1.121 +
   1.122 +    info(verbose);
   1.123 +    exit(0);
   1.124 +}
   1.125 +
   1.126  int main(int argc, char **argv)
   1.127  {
   1.128      if (argc < 2) {
   1.129 @@ -2696,6 +2808,8 @@ int main(int argc, char **argv)
   1.130          main_vcpupin(argc - 1, argv + 1);
   1.131      } else if (!strcmp(argv[1], "vcpu-set")) {
   1.132          main_vcpuset(argc - 1, argv + 1);
   1.133 +    } else if (!strcmp(argv[1], "info")) {
   1.134 +        main_info(argc - 1, argv + 1);
   1.135      } else if (!strcmp(argv[1], "help")) {
   1.136          if (argc > 2)
   1.137              help(argv[2]);