Add "xl info" command
v2 cover Add "xl info" command
The "info" subcommand is missing from the xl tool.
The attached patchset adds support for this, extending libxl on the way to provide the necessary info only by using own functions. On my system the output of xm info and xl info was identical, I omitted the recent NUMA additions from xl info for now and will provide the necessary patches later.
Reworked version due to comments from Ian and Vincent (thanks for the review!) Changes to version 1:
- use Xen public headers for constants instead of (re-)defining them
- comment the meaning of the return value of get_sched_id()
- remove the masking feature for get_version_info
- make the version_info structure a member of libxl_ctx and fill it on demand, omitting the need to free it manually
Please apply!
Regards,
Andre.
Signature · 3 lines
Andre Przywara AMD-Operating System Research Center (OSRC), Dresden, Germany Tel: +49 351 488-3567-12
PATCH v2 1/4 libxl: extend physinfo structure
The libxl version of the physinfo sysctl does not contain some fields like nr_nodes or capabilities needed for xl info output. Add them to the structure and the retrieving function.
--- tools/libxl/libxl.c | 4 ++++ tools/libxl/libxl.h | 4 ++++ 2 files changed, 8 insertions(+), 0 deletions(-)
tools/libxl/libxl.c +4 -0
@@ -2344,6 +2344,10 @@ int libxl_get_physinfo(struct libxl_ctx *ctx, struct libxl_physinfo *physinfo) physinfo->total_pages = xcphysinfo.total_pages; physinfo->free_pages = xcphysinfo.free_pages; physinfo->scrub_pages = xcphysinfo.scrub_pages; + physinfo->nr_nodes = xcphysinfo.nr_nodes; +memcpy (physinfo->hw_cap,xcphysinfo.hw_cap,sizeof (physinfo->hw_cap)); + physinfo->phys_cap = xcphysinfo.capabilities; +return 0 ; }
tools/libxl/libxl.h +4 -0
@@ -426,6 +426,10 @@ struct libxl_physinfo {uint64_t total_pages;uint64_t free_pages;uint64_t scrub_pages; + +uint32_t nr_nodes; +uint32_t hw_cap[8 ]; +uint32_t phys_cap; };int libxl_get_physinfo (struct libxl_ctx *ctx,struct libxl_physinfo *physinfo);
Signature · 1 line
1.6.4
Re: [PATCHv2 1/4] libxl: extend physinfo structure
Quoted 3 lines · Andre Przywara
The libxl version of the physinfo sysctl does not contain some fields like
nr_nodesor capabilities needed for xl info output. Add them to the structure and the retrieving function.
Vincent, Stefano, is it okay to break the ABI?
If so, I suggest adding an initial member to be filled with sizeof() of the structure, similar to many Win32 APIs like GetVersionEx.
http://msdn.microsoft.com/en-us/library/ms724451%28VS.85%29.aspx
http://msdn.microsoft.com/en-us/library/ms724834%28VS.85%29.aspx
http://msdn.microsoft.com/en-us/library/ms724833%28VS.85%29.aspx
Paolo
Re: [PATCHv2 1/4] libxl: extend physinfo structure
Paolo Bonzini writes ("Re: [PATCHv2 1/4] libxl: extend physinfo structure"):
Quoted 1 line
Vincent, Stefano, is it okay to break the ABI?
Yes, it is fine to break the ABI.
Quoted 2 lines
If so, I suggest adding an initial member to be filled with
sizeof()of the structure, similar to many Win32 APIs like GetVersionEx.
We've basically decided we don't need to do that. Libraries from different major versions of Xen will not be ABI-compatible and will have different sonames. We intend that binaries linked to old libraries will continue to work.
Ian.
Re: [PATCHv2 1/4] libxl: extend physinfo structure
Quoted 4 lines · I wrote:
We've basically decided we don't need to do that. Libraries from different major versions of Xen will not be ABI-compatible and will have different sonames. We intend that binaries linked to old libraries will continue to work.
I mean, will continue to work _with the old library_ but the new hypervisor/dom0.
Ian.
Re: [PATCHv2 1/4] libxl: extend physinfo structure
In reply to Ian JacksonQuoted 5 lines · Ian Jackson
Paolo Bonzini writes ("Re: [PATCHv2 1/4] libxl: extend physinfo structure"):
Quoted 1 line
Vincent, Stefano, is it okay to break the ABI?
Yes, it is fine to break the ABI.
Quoted 7 lines
Quoted 2 lines
If so, I suggest adding an initial member to be filled with
sizeof()of the structure, similar to many Win32 APIs like GetVersionEx.We've basically decided we don't need to do that. Libraries from different major versions of Xen will not be ABI-compatible and will have different sonames. We intend that binaries linked to old libraries will continue to work.
Indeed.
We want to keep the library as simple as possible while providing all the needed capabilities, and I think this simple schema provides just that.
PATCH v2 2/4 libxl: add sched_get_id function
In reply to Andre PrzywaraTo get the name of the currently used scheduler, Xen provides a sched_id sysctl.
Add a libxl wrapper around the libxc function to query this.
--- tools/libxl/libxl.c | 13 +++++++++++++ tools/libxl/libxl.h | 2 ++ 2 files changed, 15 insertions(+), 0 deletions(-)
tools/libxl/libxl.c +13 -0
@@ -2421,3 +2421,16 @@ int libxl_set_vcpucount(struct libxl_ctx *ctx, uint32_t domid, uint32_t count) }return 0 ; } + +/* +* returns one of the XEN_SCHEDULER_* constants from public/domctl.h +* or -1 if an error occured. +*/ +int libxl_get_sched_id (struct libxl_ctx *ctx) +{ +int sched, ret; + +if ((ret =xc_sched_id (ctx->xch, &sched)) !=0 ) +return ret; +return sched; +}
tools/libxl/libxl.h +2 -0
@@ -438,5 +438,7 @@ struct libxl_vcpuinfo *libxl_list_vcpu(struct libxl_ctx *ctx, uint32_t domid,int libxl_set_vcpuaffinity (struct libxl_ctx *ctx,uint32_t domid,uint32_t vcpuid,uint64_t *cpumap,int cpusize);int libxl_set_vcpucount (struct libxl_ctx *ctx,uint32_t domid,uint32_t count); + +int libxl_get_sched_id (struct libxl_ctx *ctx);#endif /* LIBXL_H */
Signature · 1 line
1.6.4
PATCH v2 3/4 libxl: add version_info function
In reply to Andre PrzywaraXen provides a xen_version hypercall to query the values of several interesting things (like hypervisor version, commandline used, actual changeset, etc.). Create a user-friendly and efficient wrapper around the libxc function to provide values for xl info output. Since the information is static during the whole runtime, we store it within the libxl_ctx structure and just deliver the pointer on subsequent calls.
--- tools/libxl/libxl.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ tools/libxl/libxl.h | 18 ++++++++++++++++++ 2 files changed, 64 insertions(+), 0 deletions(-)
tools/libxl/libxl.h +18 -0
@@ -41,6 +41,21 @@ struct libxl_vminfo {uint32_t domid; }; +typedef struct { +int xen_version_major; +int xen_version_minor; +char *xen_version_extra; +char *compiler; +char *compile_by; +char *compile_domain; +char *compile_date; +char *capabilities; +char *changeset; +unsigned long virt_start; +unsigned long pagesize; +char *commandline; +}libxl_version_info ; +struct libxl_ctx {int xch;struct xs_handle *xsh;
@@ -56,8 +71,11 @@ struct libxl_ctx {* set this after libxl_init and before any other call - or * may leave them untouched */ int (*waitpid_instead)(pid_t pid,int *status,int flags); +libxl_version_info version_info; }; +const libxl_version_info *libxl_get_version_info (struct libxl_ctx *ctx); + typedef struct { bool hvm; bool hap;
tools/libxl/libxl.c +46 -0
58 lines not on this page · raw message
Signature · 1 line
1.6.4
Re: [PATCHv2 3/4] libxl: add version_info function
tools/libxl/libxl.c int libxl_get_physinfo(struct libxl_ctx *ctx, struct libxl_physinfo *physinfo) · line 2395
Quoted 3 lines · Andre Przywara
tools/libxl/libxl.c +3
-0+ +xc_version (ctx->xch, XENVER_commandline,&u.xen_commandline); + info->commandline =libxl_sprintf (ctx, u.xen_commandline);
oh actually just missed that; it's important to not include a variable as the format string: if for some reason any of this field end up containing a %something, it will lead usually to segfault.
can you please replace all:
libxl_sprintf(ctx, ..);
by:
libxl_sprintf(ctx, "%s", ...);
Thanks,
Signature · 1 line
Vincent
PATCH v2 3/4 libxl: add version_info function
Xen provides a xen_version hypercall to query the values of several interesting things (like hypervisor version, commandline used, actual changeset, etc.). Create a user-friendly and efficient wrapper around the libxc function to provide values for xl info output. Since the information is static during the whole runtime, we store it within the libxl_ctx structure and just deliver the pointer on subsequent calls.
--- tools/libxl/libxl.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ tools/libxl/libxl.h | 18 ++++++++++++++++++ 2 files changed, 64 insertions(+), 0 deletions(-)
tools/libxl/libxl.c +46 -0
@@ -45,6 +45,7 @@ int libxl_ctx_init(struct libxl_ctx *ctx, int version) ctx->alloc_ptrs =calloc (ctx->alloc_maxsize,sizeof (void *));if (!ctx->alloc_ptrs)return ERROR_NOMEM ; +memset (&ctx->version_info,0 ,sizeof (libxl_version_info)); ctx->xch =xc_interface_open ();if (ctx->xch ==-1 ) {
@@ -2351,6 +2352,51 @@ int libxl_get_physinfo(struct libxl_ctx *ctx, struct libxl_physinfo *physinfo)return 0 ; } +const libxl_version_info *libxl_get_version_info (struct libxl_ctx *ctx) +{ +union { +xen_extraversion_t xen_extra; +xen_compile_info_t xen_cc; +xen_changeset_info_t xen_chgset; +xen_capabilities_info_t xen_caps; +xen_platform_parameters_t p_parms; +xen_commandline_t xen_commandline; + } u; +long xen_version; +libxl_version_info *info = &ctx->version_info; + +if (info->xen_version_extra !=NULL ) +return info; + + xen_version =xc_version (ctx->xch, XENVER_version,NULL ); + info->xen_version_major = xen_version >>16 ; + info->xen_version_minor = xen_version &0xFF ; +xc_version (ctx->xch, XENVER_extraversion, &u.xen_extra); + info->xen_version_extra =libxl_sprintf (ctx,"%s" , u.xen_extra); + +xc_version (ctx->xch, XENVER_compile_info, &u.xen_cc); + info->compiler =libxl_sprintf (ctx,"%s" , u.xen_cc.compiler); + info->compile_by =libxl_sprintf (ctx,"%s" , u.xen_cc.compile_by); + info->compile_domain =libxl_sprintf (ctx,"%s" , u.xen_cc.compile_domain); + info->compile_date =libxl_sprintf (ctx,"%s" , u.xen_cc.compile_date); + +xc_version (ctx->xch, XENVER_capabilities, &u.xen_caps); + info->capabilities =libxl_sprintf (ctx,"%s" , u.xen_caps); + +xc_version (ctx->xch, XENVER_changeset, &u.xen_chgset); + info->changeset =libxl_sprintf (ctx,"%s" , u.xen_chgset); + +xc_version (ctx->xch, XENVER_platform_parameters, &u.p_parms); + info->virt_start = u.p_parms.virt_start; + + info->pagesize =xc_version (ctx->xch, XENVER_pagesize,NULL ); + +xc_version (ctx->xch, XENVER_commandline, &u.xen_commandline); + info->commandline =libxl_sprintf (ctx,"%s" , u.xen_commandline); + +return info; +} +struct libxl_vcpuinfo *libxl_list_vcpu (struct libxl_ctx *ctx,uint32_t domid,int *nb_vcpu,int *cpusize) {
tools/libxl/libxl.h +18 -0
@@ -41,6 +41,21 @@ struct libxl_vminfo {uint32_t domid; }; +typedef struct { +int xen_version_major; +int xen_version_minor; +char *xen_version_extra; +char *compiler; +char *compile_by; +char *compile_domain; +char *compile_date; +char *capabilities; +char *changeset; +unsigned long virt_start; +unsigned long pagesize; +char *commandline; +}libxl_version_info ; +struct libxl_ctx {int xch;struct xs_handle *xsh;
@@ -56,8 +71,11 @@ struct libxl_ctx {* set this after libxl_init and before any other call - or * may leave them untouched */ int (*waitpid_instead)(pid_t pid,int *status,int flags); +libxl_version_info version_info; }; +const libxl_version_info *libxl_get_version_info (struct libxl_ctx *ctx); + typedef struct { bool hvm; bool hap;
Signature · 1 line
1.6.4
Re: [PATCHv2 3/4] libxl: add version_info function
In reply to Vincent HanquezQuoted 6 lines · Vincent Hanquez
tools/libxl/libxl.c int libxl_get_physinfo(struct libxl_ctx *ctx, struct libxl_physinfo *physinfo) · line 2395
Quoted 3 lines · Andre Przywara
tools/libxl/libxl.c +3
-0+ +xc_version (ctx->xch, XENVER_commandline,&u.xen_commandline); + info->commandline =libxl_sprintf (ctx, u.xen_commandline);oh actually just missed that; it's important to not include a variable as the format string: if for some reason any of this field end up containing a %something, it will lead usually to segfault.
Of course! I could tell you that I just wanted to know if someone will find this, but actually I was so keen on just replacing strdup with libxl_sprintf that I totally overlooked the changed semantic of the call.
Quoted 9 lines
can you please replace all:
libxl_sprintf(ctx, ..);by:
libxl_sprintf(ctx, "%s", ...);
Sure! Corrected patch follows!
Thanks for looking carefully!
Andre.
Signature · 3 lines
Andre Przywara AMD-Operating System Research Center (OSRC), Dresden, Germany Tel: +49 351 488-3567-12
PATCH v2 4/4 xl: add "xl info" command
In reply to Andre PrzywaraThe 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.
--- tools/libxl/xl.c | 114 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 114 insertions(+), 0 deletions(-)
tools/libxl/xl.c +114 -0
@@ -30,6 +30,7 @@#include <sys/socket.h> #include <sys/select.h> #include <arpa/inet.h> +#include <sys/utsname.h> /* for utsname in xl info */ #include <xenctrl.h> #include <ctype.h> #include <inttypes.h>
@@ -2636,6 +2637,117 @@ int main_vcpuset(int argc, char **argv)exit (0 ); } +static void output_xeninfo (void ) +{ +const libxl_version_info *info; +int sched_id; + + info =libxl_get_version_info (&ctx); +if ((sched_id =libxl_get_sched_id (&ctx)) <0 ) { +fprintf (stderr,"get_sched_id sysctl failed.\n" ); +return ; + } + +printf ("xen_major : %d\n" , info->xen_version_major); +printf ("xen_minor : %d\n" , info->xen_version_minor); +printf ("xen_extra : %s\n" , info->xen_version_extra); +printf ("xen_caps : %s\n" , info->capabilities); +printf ("xen_scheduler : %s\n" , + sched_id ==XEN_SCHEDULER_SEDF ?"sedf" : + sched_id ==XEN_SCHEDULER_CREDIT ?"credit" : + sched_id ==XEN_SCHEDULER_CREDIT2 ?"credit2" :"unknown" ); +printf ("xen_pagesize : %lu\n" , info->pagesize); +printf ("platform_params : virt_start=0x%lx\n" , info->virt_start); +printf ("xen_changeset : %s\n" , info->changeset); +printf ("xen_commandline : %s\n" , info->commandline); +printf ("cc_compiler : %s\n" , info->compiler); +printf ("cc_compile_by : %s\n" , info->compile_by); +printf ("cc_compile_domain : %s\n" , info->compile_domain); +printf ("cc_compile_date : %s\n" , info->compile_date); + +return ; +} + +static void output_nodeinfo (void ) +{ +struct utsname utsbuf; + +uname (&utsbuf); + +printf ("host : %s\n" , utsbuf.nodename); +printf ("release : %s\n" , utsbuf.release); +printf ("version : %s\n" , utsbuf.version); +printf ("machine : %s\n" , utsbuf.machine); + +return ; +} + +static void output_physinfo (void ) +{ +struct libxl_physinfo info; +const libxl_version_info *vinfo; +unsigned int i; + +if (libxl_get_physinfo (&ctx, &info) !=0 ) { +fprintf (stderr,"libxl_physinfo failed.\n" ); +return ; + } + +printf ("nr_cpus : %d\n" , info.nr_cpus); +printf ("nr_nodes : %d\n" , info.nr_nodes); +printf ("cores_per_socket : %d\n" , info.cores_per_socket); +printf ("threads_per_core : %d\n" , info.threads_per_core); +printf ("cpu_mhz : %d\n" , info.cpu_khz /1000 ); +printf ("hw_caps : " ); +for (i =0 ; i <8 ; i++) +printf ("%08x%c" , info.hw_cap[i], i <7 ?':' :'\n' ); +printf ("virt_caps :" ); +if (info.phys_cap & XEN_SYSCTL_PHYSCAP_hvm) +printf (" hvm" ); +if (info.phys_cap & XEN_SYSCTL_PHYSCAP_hvm_directio) +printf (" hvm_directio" ); +printf ("\n" ); + vinfo =libxl_get_version_info (&ctx); + i = (1 <<20 ) / vinfo->pagesize; +printf ("total_memory : %lu\n" , info.total_pages / i); +printf ("free_memory : %lu\n" , info.free_pages / i); + +return ; +} + +void info (int verbose) +{ +output_nodeinfo (); + +output_physinfo (); + +output_xeninfo (); + +printf ("xend_config_format : 4\n" ); + +return ; +} + +void main_info (int argc,char **argv) +{ +int opt, verbose; + + verbose =0 ; +while ((opt =getopt (argc, argv,"h" )) !=-1 ) { +switch (opt) { +case 'h' : +help ("vcpu-list" ); +exit (0 ); +default : +fprintf (stderr,"option `%c' not supported.\n" , opt); +break ; + } + } + +info (verbose); +exit (0 ); +} +int main (int argc,char **argv) {if (argc <2 ) {
@@ -2696,6 +2808,8 @@ int main(int argc, char **argv)main_vcpupin (argc -1 , argv +1 ); }else if (!strcmp (argv[1 ],"vcpu-set" )) {main_vcpuset (argc -1 , argv +1 ); + }else if (!strcmp (argv[1 ],"info" )) { +main_info (argc -1 , argv +1 ); }else if (!strcmp (argv[1 ],"help" )) {if (argc >2 )help (argv[2 ]);
Signature · 1 line
1.6.4
Quoted 7 lines · Andre Przywara
The "info" subcommand is missing from the xl tool.
The attached patchset adds support for this, extending libxl on the way to provide the necessary info only by using own functions. On my system the output of xm info and xl info was identical, I omitted the recent NUMA additions from xl info for now and will provide the necessary patches later.
Quoted 7 lines
Reworked version due to comments from Ian and Vincent (thanks for the review!) Changes to version 1:
- use Xen public headers for constants instead of (re-)defining them
- comment the meaning of the return value ofget_sched_id()
- remove the masking feature forget_version_info
- make theversion_infostructure a member oflibxl_ctxand fill it on demand, omitting the need to free it manually
all patches:
Thanks for your contribution !
Signature · 1 line
Vincent