XL API fixes and cleanup
cover XL API fixes and cleanup
this patchset contains API fixes and cleanup on the XL library. removing the number of exposed API to the client, and simplify the API where possible.
Vincent Hanquez (11):
change semantics of ctx_free and remove ctx_close coding styles cleanup
remove useless smac in the nic_info structure
remove structure init from the library and structure domid fixup
completly
hide internal logging from client
remove waitpid wrapper that's doesn't do anything
add useful xc flags in the xl_dominfo structure remove API for dominfolist and list that returns xc_dominfo. add a get_shutdown_reason
define errors as an enum instead of define random values. add a versioning number to ctx_init that permit to detect
incompatible client.
tools/libxl/libxl.c | 354 +++++++++-------------------------------- tools/libxl/libxl.h | 59 ++------ tools/libxl/libxl_device.c | 6 +- tools/libxl/libxl_dom.c | 60 ++++++-- tools/libxl/libxl_exec.c | 59 ++++---- tools/libxl/libxl_internal.h | 28 +++- tools/libxl/xl.c | 198 +++++++++++++++++++----- 7 files changed, 355 insertions(+), 409 deletions(-)
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
PATCH 1/11 change semantics of ctx_free and remove ctx_close
ctx_close isn't use anywhere, and free reallocate the GC array, which is quite surprising and lead to memory leaking in xl.c
--- tools/libxl/libxl.c | 10 ---------- tools/libxl/libxl.h | 1 - 2 files changed, 0 insertions(+), 11 deletions(-)
tools/libxl/libxl.c +0 -10
@@ -53,16 +53,6 @@ int libxl_ctx_free(struct libxl_ctx *ctx) {libxl_free_all (ctx);free (ctx->alloc_ptrs); - ctx->alloc_ptrs =calloc (ctx->alloc_maxsize,sizeof (void *)); -if (!ctx->alloc_ptrs) -return ERROR_NOMEM ; -return 0 ; -} - -int libxl_ctx_close (struct libxl_ctx *ctx) -{ -libxl_ctx_free (ctx); -free (ctx->alloc_ptrs);xc_interface_close (ctx->xch);xs_daemon_close (ctx->xsh);return 0 ;
tools/libxl/libxl.h +0 -1
@@ -253,7 +253,6 @@ void xl_log(struct libxl_ctx *ctx, int errnoval, int loglevel, const char *file,/* context functions */ int libxl_ctx_init (struct libxl_ctx *ctx);int libxl_ctx_free (struct libxl_ctx *ctx); -int libxl_ctx_close (struct libxl_ctx *ctx);int libxl_ctx_set_log (struct libxl_ctx *ctx,libxl_log_callback log_callback,void *log_data);/* domain related functions */
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
PATCH 2/11 coding styles cleanup
In reply to Vincent Hanquezsimplify some lines, and keep the xl style consistant with itself. use libxl_sprintf instead of snprintf/sprintf
--- tools/libxl/libxl.c | 94 +++++++++++++++++++----------------------- tools/libxl/libxl_device.c | 6 +- tools/libxl/libxl_dom.c | 25 ++++++++++- tools/libxl/libxl_exec.c | 47 +++++++++++---------- tools/libxl/libxl_internal.h | 2 +- 5 files changed, 95 insertions(+), 79 deletions(-)
tools/libxl/libxl.c +43 -51
@@ -45,7 +45,7 @@ int libxl_ctx_init(struct libxl_ctx *ctx) ctx->xch =xc_interface_open (); ctx->xsh =xs_daemon_open (); - ctx->waitpid_instead= libxl_waitpid_instead_default; + ctx->waitpid_instead = libxl_waitpid_instead_default;return 0 ; }
@@ -332,26 +332,6 @@ xc_dominfo_t * libxl_domain_infolist(struct libxl_ctx *ctx, int *nb_domain)return info; } -static int libxl_save_device_model (struct libxl_ctx *ctx,uint32_t domid,int fd) -{ -int fd2, c; -char buf[1024 ]; -char *filename =libxl_sprintf (ctx,"/var/lib/xen/qemu-save.%d" , domid); - -XL_LOG (ctx,XL_LOG_DEBUG ,"Saving device model state to %s" , filename); -libxl_xs_write (ctx,XBT_NULL ,libxl_sprintf (ctx,"/local/domain/0/device-model/%d/command" , domid),"save" ,strlen ("save" )); -libxl_wait_for_device_model (ctx, domid,"paused" ,NULL ,NULL ); - -write (fd,QEMU_SIGNATURE ,strlen (QEMU_SIGNATURE )); - fd2 =open (filename,O_RDONLY ); -while ((c =read (fd2, buf,sizeof (buf))) !=0 ) { -write (fd, buf, c); - } -close (fd2); -unlink (filename); -return 0 ; -} -xc_dominfo_t *libxl_domain_info (struct libxl_ctx *ctx,uint32_t domid) {xc_dominfo_t *info;
@@ -377,6 +357,7 @@ xc_dominfo_t *libxl_domain_info(struct libxl_ctx *ctx, uint32_t domid)return info; } +int libxl_domain_suspend (struct libxl_ctx *ctx,libxl_domain_suspend_info *info,uint32_t domid,int fd) {
@@ -384,11 +365,9 @@ int libxl_domain_suspend(struct libxl_ctx *ctx, libxl_domain_suspend_info *info,int live = info !=NULL && info->flags &XL_SUSPEND_LIVE ;int debug = info !=NULL && info->flags &XL_SUSPEND_LIVE ; -core_suspend (ctx, domid, fd, hvm, live, debug);if (hvm) -libxl_save_device_model (ctx, domid, fd); - +save_device_model (ctx, domid, fd);return 0 ; }
@@ -400,11 +379,11 @@ int libxl_domain_pause(struct libxl_ctx *ctx, uint32_t domid)int libxl_domain_unpause (struct libxl_ctx *ctx,uint32_t domid) { -char path[50 ]; +char *path;char *state;if (is_hvm (ctx, domid)) { -snprintf (path,sizeof (path),"/local/domain/0/device-model/%d/state" , domid); + path =libxl_sprintf (ctx,"/local/domain/0/device-model/%d/state" , domid); state =libxl_xs_read (ctx,XBT_NULL , path);if (state !=NULL && !strcmp (state,"paused" )) {libxl_xs_write (ctx,XBT_NULL ,libxl_sprintf (ctx,"/local/domain/0/device-model/%d/command" , domid),"continue" ,strlen ("continue" ));
@@ -607,7 +586,7 @@ static int libxl_destroy_device_model(struct libxl_ctx *ctx, uint32_t domid)int libxl_domain_destroy (struct libxl_ctx *ctx,uint32_t domid,int force) {char *dom_path, *uuid_str; -char vm_path[UUID_LEN_STR +5 ], vss_path[UUID_LEN_STR +6 ], xapi_path[20 ]; +char *vm_path, *vss_path, *xapi_path;xen_uuid_t *uuid;int rc, dm_present;
@@ -648,17 +627,21 @@ int libxl_domain_destroy(struct libxl_ctx *ctx, uint32_t domid, int force)XL_LOG (ctx,XL_LOG_ERROR ,"libxl_destroy_devices failed for %d" , domid);if (!xs_rm (ctx->xsh,XBT_NULL , dom_path))XL_LOG_ERRNO (ctx,XL_LOG_ERROR ,"xs_rm failed for %s" , dom_path); + uuid_str =libxl_uuid_to_string (ctx, uuid); -snprintf (vm_path,sizeof (vm_path),"/vm/%s" , uuid_str); + + vm_path =libxl_sprintf (ctx,"/vm/%s" , uuid_str);if (!xs_rm (ctx->xsh,XBT_NULL , vm_path))XL_LOG_ERRNO (ctx,XL_LOG_ERROR ,"xs_rm failed for %s" , vm_path); -snprintf (vss_path,sizeof (vss_path),"/vss/%s" , uuid_str); + + vss_path =libxl_sprintf (ctx,"/vss/%s" , uuid_str);if (!xs_rm (ctx->xsh,XBT_NULL , vss_path))XL_LOG_ERRNO (ctx,XL_LOG_ERROR ,"xs_rm failed for %s" , vss_path); -libxl_free (ctx, uuid_str); -snprintf (xapi_path,sizeof (xapi_path),"/xapi/%u" , domid); + + xapi_path =libxl_sprintf (ctx,"/xapi/%u" , domid);if (!xs_rm (ctx->xsh,XBT_NULL , xapi_path))XL_LOG_ERRNO (ctx,XL_LOG_ERROR ,"xs_rm failed for %s" , xapi_path); + rc =xc_domain_destroy (ctx->xch, domid);if (rc <0 ) {XL_LOG_ERRNOVAL (ctx,XL_LOG_ERROR , rc,"xc_domain_destroy failed for %d" , domid);
@@ -1068,7 +1051,8 @@ int libxl_create_device_model(struct libxl_ctx *ctx, }int libxl_detach_device_model (struct libxl_ctx *ctx, -libxl_device_model_starting *starting) { +libxl_device_model_starting *starting) +{int rc; rc =libxl_spawn_detach (ctx, starting->for_spawn);if (starting->for_spawn)libxl_free (ctx, starting->for_spawn);
@@ -1078,7 +1062,8 @@ int libxl_detach_device_model(struct libxl_ctx *ctx,int libxl_confirm_device_model_startup (struct libxl_ctx *ctx, -libxl_device_model_starting *starting) { +libxl_device_model_starting *starting) +{int problem =libxl_wait_for_device_model (ctx, starting->domid,"running" , libxl_spawn_check, starting->for_spawn);
@@ -1176,7 +1161,8 @@ int libxl_device_disk_add(struct libxl_ctx *ctx, uint32_t domid, libxl_device_diif (is_blktap2_supported ()) {int rc, c, p[2 ], tot;char buf[1024 ], *dev; -if ((dev =get_blktap2_device (ctx, disk->physpath,device_disk_string_of_phystype (disk->phystype))) ==NULL ) { + dev =get_blktap2_device (ctx, disk->physpath,device_disk_string_of_phystype (disk->phystype)); +if (dev ==NULL ) {if (pipe (p) <0 ) {XL_LOG (ctx,XL_LOG_ERROR ,"Failed to create a pipe" );return -1 ;
@@ -1959,7 +1945,7 @@ retry_transaction2:int libxl_device_pci_add (struct libxl_ctx *ctx,uint32_t domid,libxl_device_pci *pcidev) { -char path[50 ]; +char *path;char *state, *vdevfn;int rc, hvm;int stubdomid =0 ;
@@ -1968,7 +1954,8 @@ int libxl_device_pci_add(struct libxl_ctx *ctx, uint32_t domid, libxl_device_pcilibxl_device_pci_flr (ctx, pcidev->domain, pcidev->bus, pcidev->dev, pcidev->func); -if ((stubdomid =libxl_get_stubdom_id (ctx, domid)) !=0 ) { + stubdomid =libxl_get_stubdom_id (ctx, domid); +if (stubdomid !=0 ) {libxl_device_pci pcidev_s = *pcidev;libxl_device_pci_add (ctx, stubdomid, &pcidev_s); }
@@ -1978,23 +1965,23 @@ int libxl_device_pci_add(struct libxl_ctx *ctx, uint32_t domid, libxl_device_pciif (libxl_wait_for_device_model (ctx, domid,"running" ,0 ,0 ) <0 ) {return -1 ; } -snprintf (path,sizeof (path),"/local/domain/0/device-model/%d/state" , domid); + path =libxl_sprintf (ctx,"/local/domain/0/device-model/%d/state" , domid); state =libxl_xs_read (ctx,XBT_NULL , path); -snprintf (path,sizeof (path),"/local/domain/0/device-model/%d/parameter" , domid); + path =libxl_sprintf (ctx,"/local/domain/0/device-model/%d/parameter" , domid);if (pcidev->vdevfn)libxl_xs_write (ctx,XBT_NULL , path,PCI_BDF_VDEVFN , pcidev->domain, pcidev->bus, pcidev->dev, pcidev->func, pcidev->vdevfn);else libxl_xs_write (ctx,XBT_NULL , path,PCI_BDF , pcidev->domain, pcidev->bus, pcidev->dev, pcidev->func); -snprintf (path,sizeof (path),"/local/domain/0/device-model/%d/command" , domid); + path =libxl_sprintf (ctx,"/local/domain/0/device-model/%d/command" , domid);xs_write (ctx->xsh,XBT_NULL , path,"pci-ins" ,strlen ("pci-ins" ));if (libxl_wait_for_device_model (ctx, domid,"pci-inserted" ,0 ,0 ) <0 )XL_LOG (ctx,XL_LOG_ERROR ,"Device Model didn't respond in time" ); -snprintf (path,sizeof (path),"/local/domain/0/device-model/%d/parameter" , domid); + path =libxl_sprintf (ctx,"/local/domain/0/device-model/%d/parameter" , domid); vdevfn =libxl_xs_read (ctx,XBT_NULL , path);sscanf (vdevfn +2 ,"%x" , &pcidev->vdevfn); -snprintf (path,sizeof (path),"/local/domain/0/device-model/%d/state" , domid); + path =libxl_sprintf (ctx,"/local/domain/0/device-model/%d/state" , domid);xs_write (ctx->xsh,XBT_NULL , path, state,strlen (state)); }else { char *sysfs_path = libxl_sprintf(ctx, SYSFS_PCI_DEV"/"PCI_BDF"/resource", pcidev->domain,
@@ -2047,7 +2034,8 @@ int libxl_device_pci_add(struct libxl_ctx *ctx, uint32_t domid, libxl_device_pci } out:if (!libxl_is_stubdom (ctx, domid)) { -if ((rc =xc_assign_device (ctx->xch, domid, pcidev->value)) <0 ) + rc =xc_assign_device (ctx->xch, domid, pcidev->value); +if (rc <0 )XL_LOG_ERRNOVAL (ctx,XL_LOG_ERROR , rc,"xc_assign_device failed" ); }
@@ -2057,7 +2045,7 @@ out:int libxl_device_pci_remove (struct libxl_ctx *ctx,uint32_t domid,libxl_device_pci *pcidev) { -char path[50 ]; +char *path;char *state;int hvm, rc;int stubdomid =0 ;
@@ -2070,18 +2058,18 @@ int libxl_device_pci_remove(struct libxl_ctx *ctx, uint32_t domid, libxl_device_if (libxl_wait_for_device_model (ctx, domid,"running" ,0 ,0 ) <0 ) {return -1 ; } -snprintf (path,sizeof (path),"/local/domain/0/device-model/%d/state" , domid); + path =libxl_sprintf (ctx,"/local/domain/0/device-model/%d/state" , domid); state =libxl_xs_read (ctx,XBT_NULL , path); -snprintf (path,sizeof (path),"/local/domain/0/device-model/%d/parameter" , domid); + path =libxl_sprintf (ctx,"/local/domain/0/device-model/%d/parameter" , domid);libxl_xs_write (ctx,XBT_NULL , path,PCI_BDF , pcidev->domain, pcidev->bus, pcidev->dev, pcidev->func); -snprintf (path,sizeof (path),"/local/domain/0/device-model/%d/command" , domid); + path =libxl_sprintf (ctx,"/local/domain/0/device-model/%d/command" , domid);xs_write (ctx->xsh,XBT_NULL , path,"pci-rem" ,strlen ("pci-rem" ));if (libxl_wait_for_device_model (ctx, domid,"pci-removed" ,0 ,0 ) <0 ) {XL_LOG (ctx,XL_LOG_ERROR ,"Device Model didn't respond in time" );return -1 ; } -snprintf (path,sizeof (path),"/local/domain/0/device-model/%d/state" , domid); + path =libxl_sprintf (ctx,"/local/domain/0/device-model/%d/state" , domid);xs_write (ctx->xsh,XBT_NULL , path, state,strlen (state)); }else { char *sysfs_path = libxl_sprintf(ctx, SYSFS_PCI_DEV"/"PCI_BDF"/resource", pcidev->domain,
@@ -2137,11 +2125,13 @@ out:libxl_device_pci_flr (ctx, pcidev->domain, pcidev->bus, pcidev->dev, pcidev->func);if (!libxl_is_stubdom (ctx, domid)) { -if ((rc =xc_deassign_device (ctx->xch, domid, pcidev->value)) <0 ) + rc =xc_deassign_device (ctx->xch, domid, pcidev->value); +if (rc <0 )XL_LOG_ERRNOVAL (ctx,XL_LOG_ERROR , rc,"xc_deassign_device failed" ); } -if ((stubdomid =libxl_get_stubdom_id (ctx, domid)) !=0 ) { + stubdomid =libxl_get_stubdom_id (ctx, domid); +if (stubdomid !=0 ) {libxl_device_pci pcidev_s = *pcidev;libxl_device_pci_remove (ctx, stubdomid, &pcidev_s); }
@@ -2163,7 +2153,7 @@ libxl_device_pci *libxl_device_pci_list(struct libxl_ctx *ctx, uint32_t domid, ireturn NULL ; } n =atoi (num_devs); - pcidevs = (libxl_device_pci *)calloc (n,sizeof (libxl_device_pci)); + pcidevs =calloc (n,sizeof (libxl_device_pci)); *num = n;for (i =0 ; i < n; i++) {
@@ -2361,7 +2351,9 @@ int libxl_set_memory_target(struct libxl_ctx *ctx, uint32_t domid, uint32_t targ videoram =atoi (videoram_s);libxl_xs_write (ctx,XBT_NULL ,libxl_sprintf (ctx,"%s/memory/target" , dompath),"%lu" , target_memkb); -if ((rc =xc_domain_setmaxmem (ctx->xch, domid, target_memkb +LIBXL_MAXMEM_CONSTANT )) !=0 )return rc; + rc =xc_domain_setmaxmem (ctx->xch, domid, target_memkb +LIBXL_MAXMEM_CONSTANT ); +if (rc !=0 ) +return rc; rc =xc_domain_memory_set_pod_target (ctx->xch, domid, (target_memkb - videoram) /4 ,NULL ,NULL ,NULL );return rc; }
tools/libxl/libxl_device.c +3 -3
@@ -344,7 +344,7 @@ int libxl_device_del(struct libxl_ctx *ctx, libxl_device *dev, int wait)int libxl_device_pci_flr (struct libxl_ctx *ctx,unsigned int domain,unsigned int bus,unsigned int dev,unsigned int func) { -char *do_flr="/sys/bus/pci/drivers/pciback/do_flr" ; +char *do_flr ="/sys/bus/pci/drivers/pciback/do_flr" ;FILE *fd; fd =fopen (do_flr,"w" );
@@ -367,7 +367,7 @@ int libxl_wait_for_device_model(struct libxl_ctx *ctx, void *userdata), void *check_callback_userdata) { - char path[50]; + char *path;char *p;unsigned int len;int rc;
@@ -379,7 +379,7 @@ int libxl_wait_for_device_model(struct libxl_ctx *ctx,char **l =NULL ; xsh =xs_daemon_open (); -snprintf (path,sizeof (path),"/local/domain/0/device-model/%d/state" , domid); + path =libxl_sprintf (ctx,"/local/domain/0/device-model/%d/state" , domid);xs_watch (xsh, path, path); tv.tv_sec =LIBXL_DEVICE_MODEL_START_TIMEOUT ; tv.tv_usec =0 ;
tools/libxl/libxl_dom.c +23 -2
@@ -24,6 +24,7 @@#include <xenctrl.h> #include <xc_dom.h> #include <xenguest.h> +#include <fcntl.h> #include "libxl.h" #include "libxl_internal.h"
@@ -130,10 +131,11 @@ int build_pv(struct libxl_ctx *ctx, uint32_t domid,XL_LOG_ERRNO (ctx,XL_LOG_ERROR ,"xc_dom_allocate failed" );return -1 ; } -if ((ret =xc_dom_linux_build (ctx->xch, dom, domid, info->target_memkb /1024 , + ret =xc_dom_linux_build (ctx->xch, dom, domid, info->target_memkb /1024 , info->kernel, info->u.pv.ramdisk, flags, state->store_port, &state->store_mfn, - state->console_port, &state->console_mfn)) !=0 ) { + state->console_port, &state->console_mfn); +if (ret !=0 ) {xc_dom_release (dom);XL_LOG_ERRNOVAL (ctx,XL_LOG_ERROR , ret,"xc_dom_linux_build failed" );return -2 ;
@@ -317,3 +319,22 @@ int core_suspend(struct libxl_ctx *ctx, uint32_t domid, int fd,return 0 ; } +int save_device_model (struct libxl_ctx *ctx,uint32_t domid,int fd) +{ +int fd2, c; +char buf[1024 ]; +char *filename =libxl_sprintf (ctx,"/var/lib/xen/qemu-save.%d" , domid); + +XL_LOG (ctx,XL_LOG_DEBUG ,"Saving device model state to %s" , filename); +libxl_xs_write (ctx,XBT_NULL ,libxl_sprintf (ctx,"/local/domain/0/device-model/%d/command" , domid),"save" ,strlen ("save" )); +libxl_wait_for_device_model (ctx, domid,"paused" ,NULL ,NULL ); + +write (fd,QEMU_SIGNATURE ,strlen (QEMU_SIGNATURE )); + fd2 =open (filename,O_RDONLY ); +while ((c =read (fd2, buf,sizeof (buf))) !=0 ) { +write (fd, buf, c); + } +close (fd2); +unlink (filename); +return 0 ; +}
tools/libxl/libxl_exec.c +25 -22
140 lines not on this page · raw message
tools/libxl/libxl_internal.h +1 -1
@@ -116,6 +116,7 @@ int build_hvm(struct libxl_ctx *ctx, uint32_t domid,int restore_common (struct libxl_ctx *ctx,uint32_t domid,libxl_domain_build_info *info,libxl_domain_build_state *state,int fd);int core_suspend (struct libxl_ctx *ctx,uint32_t domid,int fd,int hvm,int live,int debug); +int save_device_model (struct libxl_ctx *ctx,uint32_t domid,int fd);/* from xl_device */ char *device_disk_backend_type_of_phystype (libxl_disk_phystype phystype);
@@ -186,7 +187,6 @@ int libxl_spawn_check(struct libxl_ctx *ctx,/* low-level stuff, for synchronous subprocesses etc. */ -pid_t libxl_fork (struct libxl_ctx *ctx);// logs errors void libxl_exec (struct libxl_ctx *ctx,int stdinfd,int stdoutfd,int stderrfd,char *arg0,char **args);// logs errors, never returns void libxl_log_child_exitstatus(struct libxl_ctx *ctx,
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
PATCH 3/11 remove useless smac in the nic_info structure
In reply to Vincent Hanquezthe string representing the mac is easily recomputed from the mac array
--- tools/libxl/libxl.c | 6 ++++-- tools/libxl/libxl.h | 1 - tools/libxl/xl.c | 3 --- 3 files changed, 4 insertions(+), 6 deletions(-)
tools/libxl/libxl.c +4 -2
@@ -748,9 +748,12 @@ static char ** libxl_build_device_model_args(struct libxl_ctx *ctx, }for (i =0 ; i < num_vifs; i++) {if (vifs[i].nictype ==NICTYPE_IOEMU ) { +char *smac =libxl_sprintf (ctx,"%02x:%02x:%02x:%02x:%02x:%02x" , + vifs[i].mac[0 ], vifs[i].mac[1 ], vifs[i].mac[2 ], + vifs[i].mac[3 ], vifs[i].mac[4 ], vifs[i].mac[5 ]);flexarray_set (dm_args, num++,"-net" );flexarray_set (dm_args, num++,libxl_sprintf (ctx,"nic,vlan=%d,macaddr=%s,model=%s" , - vifs[i].devid, vifs[i].smac, vifs[i].model)); + vifs[i].devid, smac, vifs[i].model));flexarray_set (dm_args, num++,"-net" );flexarray_set (dm_args, num++,libxl_sprintf (ctx,"tap,vlan=%d,ifname=%s,bridge=%s" , vifs[i].devid, vifs[i].ifname, vifs[i].bridge));
@@ -2303,7 +2306,6 @@ void init_nic_info(libxl_device_nic *nic_info, int devnum) nic_info->mac[3 ] =1 + (int ) (0x7f * (rand () / (RAND_MAX +1.0 ))); nic_info->mac[4 ] =1 + (int ) (0xff * (rand () / (RAND_MAX +1.0 ))); nic_info->mac[5 ] =1 + (int ) (0xff * (rand () / (RAND_MAX +1.0 ))); -asprintf (&(nic_info->smac),"%02x:%02x:%02x:%02x:%02x:%02x" , nic_info->mac[0 ], nic_info->mac[1 ], nic_info->mac[2 ], nic_info->mac[3 ], nic_info->mac[4 ], nic_info->mac[5 ]); nic_info->ifname =NULL ; nic_info->bridge ="xenbr0" ; nic_info->script ="/etc/xen/scripts/vif-bridge" ;
tools/libxl/libxl.h +0 -1
@@ -199,7 +199,6 @@ typedef struct {int mtu;char *model;uint8_t mac[6 ]; -char *smac;struct in_addr ip;char *bridge;char *ifname;
tools/libxl/xl.c +0 -3
@@ -122,7 +122,6 @@ static void printf_info(libxl_domain_create_info *c_info,printf ("mtu %d\n" , vifs[i].mtu);printf ("model %s\n" , vifs[i].model);printf ("mac %02x:%02x:%02x:%02x:%02x:%02x\n" , vifs[i].mac[0 ], vifs[i].mac[1 ], vifs[i].mac[2 ], vifs[i].mac[3 ], vifs[i].mac[4 ], vifs[i].mac[5 ]); -printf ("smac %s\n" , vifs[i].mac); }for (i =0 ; i < num_pcidevs; i++) {
@@ -399,7 +398,6 @@ static void parse_config_file(const char *filename, (*vifs)[*num_vifs].model =strdup (p2 +1 ); }else if (!strcmp (p,"mac" )) {char *p3 = p2 +1 ; - (*vifs)[*num_vifs].smac =strdup (p3); *(p3 +2 ) ='\0' ; (*vifs)[*num_vifs].mac[0 ] =strtol (p3,NULL ,16 ); p3 = p3 +3 ;
@@ -732,7 +730,6 @@ start:close (logfile);for (i =0 ; i < num_vifs; i++) { -free (vifs[i].smac);free (vifs[i].ifname); }free (disks);
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
PATCH 4/11 remove structure init from the library and structure domid fixup completly
In reply to Vincent Hanquezstructure init are more accurately done in the client of the library.
--- tools/libxl/libxl.c | 173 +++++---------------------------------------------- tools/libxl/libxl.h | 16 ----- tools/libxl/xl.c | 121 ++++++++++++++++++++++++++++++++++-- 3 files changed, 130 insertions(+), 180 deletions(-)
tools/libxl/libxl.c +15 -158
@@ -751,6 +751,8 @@ static char ** libxl_build_device_model_args(struct libxl_ctx *ctx,char *smac =libxl_sprintf (ctx,"%02x:%02x:%02x:%02x:%02x:%02x" , vifs[i].mac[0 ], vifs[i].mac[1 ], vifs[i].mac[2 ], vifs[i].mac[3 ], vifs[i].mac[4 ], vifs[i].mac[5 ]); +if (!vifs[i].ifname) + vifs[i].ifname =libxl_sprintf (ctx,"tap%d.%d" , info->domid, vifs[i].devid -1 );flexarray_set (dm_args, num++,"-net" );flexarray_set (dm_args, num++,libxl_sprintf (ctx,"nic,vlan=%d,macaddr=%s,model=%s" , vifs[i].devid, smac, vifs[i].model));
@@ -942,30 +944,27 @@ retry_transaction: goto retry_transaction;for (i =0 ; i < num_disks; i++) { -libxl_device_disk disk = disks[i]; -disk_info_domid_fixup (&disk, domid); -libxl_device_disk_add (ctx, domid, &disk); + disks[i].domid = domid; +libxl_device_disk_add (ctx, domid, &disks[i]); }for (i =0 ; i < num_vifs; i++) { -libxl_device_nic nic = vifs[i]; -nic_info_domid_fixup (&nic, domid); -libxl_device_nic_add (ctx, domid, &nic); + vifs[i].domid = domid; +libxl_device_nic_add (ctx, domid, &vifs[i]); } -vfb_info_domid_fixup (vfb, domid); + vfb->domid = domid;libxl_device_vfb_add (ctx, domid, vfb); -vkb_info_domid_fixup (vkb, domid); + vkb->domid = domid;libxl_device_vkb_add (ctx, domid, vkb);if (info->serial) num_console++; console =libxl_calloc (ctx, num_console,sizeof (libxl_device_console));for (i =0 ; i < num_console; i++) { -if (!i) -init_console_info (&console[i], i, &state); -else -init_console_info (&console[i], i,NULL ); -console_info_domid_fixup (&console[i], domid); + console[i].devid = i; console[i].constype =CONSTYPE_IOEMU ; + console[i].domid = domid; +if (!i) + console[i].build_state = &state;libxl_device_console_add (ctx, domid, &console[i]); }if (libxl_create_xenpv_qemu (ctx, vfb, num_console, console, &dm_starting) <0 ) {
@@ -1564,11 +1563,11 @@ int libxl_cdrom_insert(struct libxl_ctx *ctx, uint32_t domid, libxl_device_disklibxl_device_disk_add (ctx, domid, disk); stubdomid =libxl_get_stubdom_id (ctx, domid);if (stubdomid) { -disk_info_domid_fixup (disks + i, stubdomid); + disks[i].domid = stubdomid;libxl_device_disk_del (ctx, disks + i,1 ); -disk_info_domid_fixup (disk, stubdomid); + disk->domid = stubdomid;libxl_device_disk_add (ctx, stubdomid, disk); -disk_info_domid_fixup (disk, domid); + disk->domid = domid; }return 0 ; }
@@ -2200,146 +2199,6 @@ int libxl_device_pci_shutdown(struct libxl_ctx *ctx, uint32_t domid)return 0 ; } -void nic_info_domid_fixup (libxl_device_nic *nic_info,int domid) -{ - nic_info->domid = domid; -asprintf (&(nic_info->ifname),"tap%d.%d" , domid, nic_info->devid -1 ); -} - -void disk_info_domid_fixup (libxl_device_disk *disk_info,int domid) -{ - disk_info->domid = domid; -} - -void vfb_info_domid_fixup (libxl_device_vfb *vfb,int domid) -{ - vfb->domid = domid; -} - -void vkb_info_domid_fixup (libxl_device_vkb *vkb,int domid) -{ - vkb->domid = domid; -} - -void console_info_domid_fixup (libxl_device_console *console,int domid) -{ - console->domid = domid; -} - -void device_model_info_domid_fixup (libxl_device_model_info *dm_info,int domid) -{ - dm_info->domid = domid; -} - -void init_create_info (libxl_domain_create_info *c_info) -{ -memset (c_info,'\0' ,sizeof (*c_info)); - c_info->xsdata =NULL ; - c_info->platformdata =NULL ; - c_info->hvm =1 ; - c_info->ssidref =0 ; -} - -void init_build_info (libxl_domain_build_info *b_info,libxl_domain_create_info *c_info) -{ -memset (b_info,'\0' ,sizeof (*b_info)); - b_info->timer_mode =-1 ; - b_info->hpet =1 ; - b_info->vpt_align =-1 ; - b_info->max_vcpus =1 ; - b_info->max_memkb =32 *1024 ; - b_info->target_memkb = b_info->max_memkb; -if (c_info->hvm) { - b_info->shadow_memkb =libxl_get_required_shadow_memory (b_info->max_memkb, b_info->max_vcpus); - b_info->video_memkb =8 *1024 ; - b_info->kernel ="/usr/lib/xen/boot/hvmloader" ; - b_info->hvm =1 ; - b_info->u.hvm.pae =1 ; - b_info->u.hvm.apic =1 ; - b_info->u.hvm.acpi =1 ; - b_info->u.hvm.nx =1 ; - b_info->u.hvm.viridian =0 ; - }else { - b_info->u.pv.slack_memkb =8 *1024 ; - } -} - -void init_dm_info (libxl_device_model_info *dm_info, -libxl_domain_create_info *c_info,libxl_domain_build_info *b_info) -{ -memset (dm_info,'\0' ,sizeof (*dm_info)); - - dm_info->dom_name = c_info->name; - dm_info->device_model ="/usr/lib/xen/bin/qemu-dm" ; - dm_info->videoram = b_info->video_memkb /1024 ; - dm_info->apic = b_info->u.hvm.apic; - - dm_info->stdvga =0 ; - dm_info->vnc =1 ; - dm_info->vnclisten ="127.0.0.1" ; - dm_info->vncdisplay =0 ; - dm_info->vncunused =0 ; - dm_info->keymap =NULL ; - dm_info->sdl =0 ; - dm_info->opengl =0 ; - dm_info->nographic =0 ; - dm_info->serial =NULL ; - dm_info->boot ="cda" ; - dm_info->usb =0 ; - dm_info->usbdevice =NULL ; -} - -void init_nic_info (libxl_device_nic *nic_info,int devnum) -{ -memset (nic_info,'\0' ,sizeof (*nic_info)); - - - nic_info->backend_domid =0 ; - nic_info->domid =0 ; - nic_info->devid = devnum; - nic_info->mtu =1492 ; - nic_info->model ="e1000" ; -srand (time (0 )); - nic_info->mac[0 ] =0x00 ; - nic_info->mac[1 ] =0x16 ; - nic_info->mac[2 ] =0x3e ; - nic_info->mac[3 ] =1 + (int ) (0x7f * (rand () / (RAND_MAX +1.0 ))); - nic_info->mac[4 ] =1 + (int ) (0xff * (rand () / (RAND_MAX +1.0 ))); - nic_info->mac[5 ] =1 + (int ) (0xff * (rand () / (RAND_MAX +1.0 ))); - nic_info->ifname =NULL ; - nic_info->bridge ="xenbr0" ; - nic_info->script ="/etc/xen/scripts/vif-bridge" ; - nic_info->nictype =NICTYPE_IOEMU ; -} - -void init_vfb_info (libxl_device_vfb *vfb,int dev_num) -{ -memset (vfb,0x00 ,sizeof (libxl_device_vfb)); - vfb->devid = dev_num; - vfb->vnc =1 ; - vfb->vnclisten ="127.0.0.1" ; - vfb->vncdisplay =0 ; - vfb->vncunused =1 ; - vfb->keymap =NULL ; - vfb->sdl =0 ; - vfb->opengl =0 ; -} - -void init_vkb_info (libxl_device_vkb *vkb,int dev_num) -{ -memset (vkb,0x00 ,sizeof (libxl_device_vkb)); - vkb->devid = dev_num; -} - -void init_console_info (libxl_device_console *console,int dev_num,libxl_domain_build_state *state) -{ -memset (console,0x00 ,sizeof (libxl_device_console)); - console->devid = dev_num; - console->constype =CONSTYPE_XENCONSOLED ; -if (state) - console->build_state = state; -} -int libxl_set_memory_target (struct libxl_ctx *ctx,uint32_t domid,uint32_t target_memkb) {int rc =0 ;
@@ -2359,5 +2218,3 @@ int libxl_set_memory_target(struct libxl_ctx *ctx, uint32_t domid, uint32_t targ rc =xc_domain_memory_set_pod_target (ctx->xch, domid, (target_memkb - videoram) /4 ,NULL ,NULL ,NULL );return rc; } - -
tools/libxl/libxl.h +0 -16
@@ -358,20 +358,4 @@ int libxl_device_pci_init(libxl_device_pci *pcidev, unsigned int domain, unsigned int bus, unsigned int dev, unsigned int func, unsigned int vdevfn); -void nic_info_domid_fixup (libxl_device_nic *nic_info,int domid); -void disk_info_domid_fixup (libxl_device_disk *disk_info,int domid); -void vfb_info_domid_fixup (libxl_device_vfb *vfb,int domid); -void vkb_info_domid_fixup (libxl_device_vkb *vkb,int domid); -void console_info_domid_fixup (libxl_device_console *console,int domid); -void device_model_info_domid_fixup (libxl_device_model_info *dm_info,int domid); - -void init_create_info (libxl_domain_create_info *c_info); -void init_build_info (libxl_domain_build_info *b_info,libxl_domain_create_info *c_info); -void init_dm_info (libxl_device_model_info *dm_info, -libxl_domain_create_info *c_info,libxl_domain_build_info *b_info); -void init_nic_info (libxl_device_nic *nic_info,int devnum); -void init_vfb_info (libxl_device_vfb *vfb,int dev_num); -void init_vkb_info (libxl_device_vkb *vkb,int dev_num); -void init_console_info (libxl_device_console *console,int dev_num,libxl_domain_build_state *state); -#endif
tools/libxl/xl.c +115 -6
153 lines not on this page · raw message
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
PATCH 5/11 hide internal logging from client
In reply to Vincent Hanquezreimplement simple logging in xl, the XL_LOG facilities are a means for the library to communicate back to the client, not for a logging library that may be redundant with what the client use.
--- tools/libxl/libxl.h | 21 --------------------- tools/libxl/libxl_internal.h | 22 ++++++++++++++++++++++ tools/libxl/xl.c | 27 +++++++++++++++++++++------ 3 files changed, 43 insertions(+), 27 deletions(-)
tools/libxl/libxl.h +0 -21
@@ -23,8 +23,6 @@#include "xen_uuid.h" -#define XL_LOGGING_ENABLED -typedef void (*libxl_log_callback )(void *userdata,int loglevel,const char *file,int line,const char *func,char *s);struct libxl_dominfo {
@@ -230,25 +228,6 @@ typedef struct {#define ERROR_NOMEM (-1032)#define ERROR_INVAL (-1245) -/* logging */ -void xl_logv (struct libxl_ctx *ctx,int errnoval,int loglevel,const char *file,int line,const char *func,char *fmt,va_list al); -void xl_log (struct libxl_ctx *ctx,int errnoval,int loglevel,const char *file,int line,const char *func,char *fmt, ...); - -#ifdef XL_LOGGING_ENABLED -#define XL_LOG(ctx, loglevel, _f, _a...) xl_log(ctx, loglevel, -1, __FILE__, __LINE__, __func__, _f, ##_a) -#define XL_LOG_ERRNO(ctx, loglevel, _f, _a...) xl_log(ctx, loglevel, errno, __FILE__, __LINE__, __func__, _f, ##_a) -#define XL_LOG_ERRNOVAL(ctx, errnoval, loglevel, _f, _a...) xl_log(ctx, loglevel, errnoval, __FILE__, __LINE__, __func__, _f, ##_a) -#else -#define XL_LOG(ctx, loglevel, _f, _a...) -#define XL_LOG_ERRNO(ctx, loglevel, _f, _a...) -#define XL_LOG_ERRNOVAL(ctx, loglevel, errnoval, _f, _a...) -#endif - -#define XL_LOG_DEBUG 3 -#define XL_LOG_INFO 2 -#define XL_LOG_WARNING 1 -#define XL_LOG_ERROR 0 -/* context functions */ int libxl_ctx_init (struct libxl_ctx *ctx);int libxl_ctx_free (struct libxl_ctx *ctx);
tools/libxl/libxl_internal.h +22 -0
@@ -36,6 +36,28 @@#define ARRAY_SIZE (a) (sizeof(a) / sizeof(a[0])) +#define XL_LOGGING_ENABLED + +#ifdef XL_LOGGING_ENABLED +#define XL_LOG(ctx, loglevel, _f, _a...) xl_log(ctx, loglevel, -1, __FILE__, __LINE__, __func__, _f, ##_a) +#define XL_LOG_ERRNO(ctx, loglevel, _f, _a...) xl_log(ctx, loglevel, errno, __FILE__, __LINE__, __func__, _f, ##_a) +#define XL_LOG_ERRNOVAL(ctx, errnoval, loglevel, _f, _a...) xl_log(ctx, loglevel, errnoval, __FILE__, __LINE__, __func__, _f, ##_a) +#else +#define XL_LOG(ctx, loglevel, _f, _a...) +#define XL_LOG_ERRNO(ctx, loglevel, _f, _a...) +#define XL_LOG_ERRNOVAL(ctx, loglevel, errnoval, _f, _a...) +#endif + +#define XL_LOG_DEBUG 3 +#define XL_LOG_INFO 2 +#define XL_LOG_WARNING 1 +#define XL_LOG_ERROR 0 + +/* logging */ +void xl_logv (struct libxl_ctx *ctx,int errnoval,int loglevel,const char *file,int line,const char *func,char *fmt,va_list al); +void xl_log (struct libxl_ctx *ctx,int errnoval,int loglevel,const char *file,int line,const char *func,char *fmt, ...); + + typedef enum { DEVICE_VIF, DEVICE_VBD,
tools/libxl/xl.c +21 -6
@@ -46,6 +46,21 @@ void log_callback(void *userdata, int loglevel, const char *file, int line, conswrite (logfile, str,strlen (str)); } +#define LOG(_f, _a...) dolog(__FILE__, __LINE__, __func__, _f, ##_a) + +void dolog (const char *file,int line,const char *func,char *fmt, ...) +{ +va_list ap; +char *s; +int rc; + +va_start (ap, fmt); + rc =vasprintf (&s, fmt, ap); +va_end (ap); +if (rc >=0 ) +write (logfile, s, rc); +} +static void init_create_info (libxl_domain_create_info *c_info) {memset (c_info,'\0' ,sizeof (*c_info));
@@ -784,7 +799,7 @@ start:daemon (0 ,0 ); need_daemon =0 ; } -XL_LOG (&ctx,XL_LOG_DEBUG ,"Waiting for domain %s (domid %d) to die" , info1.name, domid); +LOG ("Waiting for domain %s (domid %d) to die" , info1.name, domid); w1 = (libxl_waiter *)malloc (sizeof (libxl_waiter) * num_disks); w2 = (libxl_waiter *)malloc (sizeof (libxl_waiter));libxl_wait_for_disk_ejects (&ctx, domid, disks, num_disks, w1);
@@ -808,9 +823,9 @@ start:switch (event.type) {case DOMAIN_DEATH :if (libxl_event_get_domain_death_info (&ctx, domid, &event, &info)) { -XL_LOG (&ctx,XL_LOG_DEBUG ,"Domain %d is dead" , domid); +LOG ("Domain %d is dead" , domid);if (info.crashed || info.dying || (info.shutdown && (info.shutdown_reason != SHUTDOWN_suspend))) { -XL_LOG (&ctx,XL_LOG_DEBUG ,"Domain %d needs to be clean: destroying the domain" , domid); +LOG ("Domain %d needs to be clean: destroying the domain" , domid);libxl_domain_destroy (&ctx, domid,0 );if (info.shutdown && (info.shutdown_reason == SHUTDOWN_reboot)) {libxl_free_waiter (w1);
@@ -818,12 +833,12 @@ start:free (w1);free (w2);libxl_ctx_free (&ctx); -XL_LOG (&ctx,XL_LOG_DEBUG ,"Done. Rebooting now" ); +LOG ("Done. Rebooting now" ); goto start; } -XL_LOG (&ctx,XL_LOG_DEBUG ,"Done. Exiting now" ); +LOG ("Done. Exiting now" ); } -XL_LOG (&ctx,XL_LOG_DEBUG ,"Domain %d does not need to be clean, exiting now" , domid); +LOG ("Domain %d does not need to be clean, exiting now" , domid);exit (0 ); }break ;
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
PATCH 6/11 remove waitpid wrapper that's doesn't do anything
In reply to Vincent Hanquezif the waitpid callback isn't defined just call normal waitpid
--- tools/libxl/libxl.c | 2 -- tools/libxl/libxl_exec.c | 16 ++++++++-------- tools/libxl/libxl_internal.h | 1 - 3 files changed, 8 insertions(+), 11 deletions(-)
tools/libxl/libxl.c +0 -2
@@ -44,8 +44,6 @@ int libxl_ctx_init(struct libxl_ctx *ctx) ctx->xch =xc_interface_open (); ctx->xsh =xs_daemon_open (); - - ctx->waitpid_instead = libxl_waitpid_instead_default;return 0 ; }
tools/libxl/libxl_exec.c +8 -8
@@ -43,6 +43,11 @@ static pid_t libxl_fork(struct libxl_ctx *ctx)return pid; } +static int call_waitpid (pid_t (*waitpid_cb)(pid_t ,int *,int ),pid_t pid,int *status,int options) +{ +return (waitpid_cb) ?waitpid_cb (pid, status,0 ) :waitpid (pid, status,0 ); +} +void libxl_exec (struct libxl_ctx *ctx,int stdinfd,int stdoutfd,int stderrfd,char *arg0,char **args)/* call this in the child */
@@ -94,11 +99,6 @@ void libxl_report_child_exitstatus(struct libxl_ctx *ctx, } } -pid_t libxl_waitpid_instead_default (pid_t pid,int *status,int flags) -{ -return waitpid (pid,status,flags); -} - int libxl_spawn_spawn(struct libxl_ctx *ctx, libxl_device_model_starting *starting, const char *what,
@@ -137,7 +137,7 @@ int libxl_spawn_spawn(struct libxl_ctx *ctx,if (!for_spawn)_exit (0 );/* just detach then */ - got = ctx->waitpid_instead (child, &status,0 ); + got =call_waitpid (ctx->waitpid_instead, child, &status,0 );assert (got == child);libxl_report_child_exitstatus (ctx, what, child, status);
@@ -178,7 +178,7 @@ int libxl_spawn_detach(struct libxl_ctx *ctx, (unsigned long)for_spawn->intermediate);abort ();/* things are very wrong */ } - got = ctx->waitpid_instead (for_spawn->intermediate, &status,0 ); + got =call_waitpid (ctx->waitpid_instead, for_spawn->intermediate, &status,0 );assert (got == for_spawn->intermediate);if (!(WIFSIGNALED (status) &&WTERMSIG (status) ==SIGKILL )) {report_spawn_intermediate_status (ctx, for_spawn, status);
@@ -202,7 +202,7 @@ int libxl_spawn_check(struct libxl_ctx *ctx, void *for_spawn_void)if (!for_spawn)return 0 ;assert (for_spawn->intermediate); - got = ctx->waitpid_instead (for_spawn->intermediate, &status,WNOHANG ); + got =call_waitpid (ctx->waitpid_instead, for_spawn->intermediate, &status,0 );if (!got)return 0 ;assert (got == for_spawn->intermediate);
tools/libxl/libxl_internal.h +0 -1
@@ -213,7 +213,6 @@ void libxl_exec(struct libxl_ctx *ctx, int stdinfd, int stdoutfd, int stderrfd, char *arg0, char **args); // logs errors, never returnsvoid libxl_log_child_exitstatus (struct libxl_ctx *ctx,const char *what,pid_t pid,int status); -pid_t libxl_waitpid_instead_default (pid_t pid,int *status,int flags);#endif
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
PATCH 7/11 add useful xc flags in the xl_dominfo structure
In reply to Vincent Hanquez--- tools/libxl/libxl.c | 8 ++++++++ tools/libxl/libxl.h | 3 +++ 2 files changed, 11 insertions(+), 0 deletions(-)
tools/libxl/libxl.c +8 -0
@@ -304,6 +304,14 @@ redo: }memcpy (&(ptr[index].uuid), info[i].handle,sizeof (xen_domain_handle_t)); ptr[index].domid = info[i].domain; + +if (info[i].flags & XEN_DOMINF_dying) + ptr[index].dying =1 ; +else if (info[i].flags & XEN_DOMINF_paused) + ptr[index].paused =1 ; +else if (info[i].flags & XEN_DOMINF_blocked || info[i].flags & XEN_DOMINF_running) + ptr[index].running =1 ; + first_domain = info[i].domain +1 ; index++; }
tools/libxl/libxl.h +3 -0
@@ -28,6 +28,9 @@ typedef void (*libxl_log_callback)(void *userdata, int loglevel, const char *filstruct libxl_dominfo {xen_uuid_t uuid;uint32_t domid; +uint8_t dying:1 ; +uint8_t paused:1 ; +uint8_t running:1 ; };struct libxl_ctx {
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
PATCH 8/11 remove API for dominfolist and list that returns xc_dominfo.
In reply to Vincent Hanquezfixup xl and part of libxl that use those API, to use simpler, faster and less wasteful API (doesn't need to get the info about all domains when looking for one specific domain).
--- tools/libxl/libxl.c | 61 +++++----------------------------------------- tools/libxl/libxl.h | 4 +-- tools/libxl/libxl_dom.c | 20 +++++++-------- tools/libxl/xl.c | 23 +++++++---------- 4 files changed, 26 insertions(+), 82 deletions(-)
tools/libxl/libxl.c +7 -54
@@ -321,49 +321,6 @@ redo:return ptr; } -xc_dominfo_t *libxl_domain_infolist (struct libxl_ctx *ctx,int *nb_domain) -{ -int index, first_domain; -xc_dominfo_t *info; -int size =1024 ; - - first_domain =0 ; - index =0 ; - info = (xc_dominfo_t *)calloc (size,sizeof (xc_dominfo_t)); -if (!info) { - *nb_domain =0 ; -return NULL ; - } - *nb_domain =xc_domain_getinfo (ctx->xch, first_domain,1024 , info); -return info; -} - -xc_dominfo_t *libxl_domain_info (struct libxl_ctx *ctx,uint32_t domid) -{ -xc_dominfo_t *info; -int rc; - - info = (xc_dominfo_t *)calloc (1 ,sizeof (xc_dominfo_t)); -if (!info) { -return NULL ; - } - rc =xc_domain_getinfo (ctx->xch, domid,1 , info); -if (rc !=1 ) { -free (info); -XL_LOG_ERRNO (ctx,XL_LOG_ERROR ,"Failed to get info for domain %u" , - domid); -return NULL ; - } -if (info->domid != domid) { -free (info); -XL_LOG (ctx,XL_LOG_ERROR ,"Failed to get info for domain %u" -", seems to not exist anymore" , domid); -return NULL ; - } - -return info; -} -int libxl_domain_suspend (struct libxl_ctx *ctx,libxl_domain_suspend_info *info,uint32_t domid,int fd) {
@@ -503,28 +460,24 @@ int libxl_free_waiter(libxl_waiter *waiter)return 0 ; } -int libxl_event_get_domain_death_info (struct libxl_ctx *ctx,uint32_t domid,libxl_event *event,xc_dominfo_t *info) +int libxl_event_get_domain_death_info (struct libxl_ctx *ctx,uint32_t domid,libxl_event *event,xc_domaininfo_t *info) { -int nb_domain, i, rc =0 ; -xc_dominfo_t *list =NULL ; +int rc =0 , ret;if (event && event->type ==DOMAIN_DEATH ) { - list =libxl_domain_infolist (ctx, &nb_domain); -for (i =0 ; i < nb_domain; i++) { -if (domid == list[i].domid) { -if (list[i].running || (!list[i].shutdown && !list[i].crashed && !list[i].dying)) + ret =xc_domain_getinfolist (ctx->xch, domid,1 , info); +if (ret ==1 && info->domain == domid) { +if (info->flags & XEN_DOMINF_running || + (!(info->flags & XEN_DOMINF_shutdown) && !(info->flags & XEN_DOMINF_dying))) goto out; - *info = list[i]; rc =1 ; goto out; - } } -memset (info,0x00 ,sizeof (xc_dominfo_t)); +memset (info,0 ,sizeof (xc_dominfo_t)); rc =1 ; goto out; } out: -free (list);return rc; }
tools/libxl/libxl.h +1 -3
@@ -279,7 +279,7 @@ int libxl_stop_waiting(struct libxl_ctx *ctx, libxl_waiter *waiter);int libxl_free_event (libxl_event *event);int libxl_free_waiter (libxl_waiter *waiter); -int libxl_event_get_domain_death_info (struct libxl_ctx *ctx,uint32_t domid,libxl_event *event,xc_dominfo_t *info); +int libxl_event_get_domain_death_info (struct libxl_ctx *ctx,uint32_t domid,libxl_event *event,xc_domaininfo_t *info);int libxl_event_get_disk_eject_info (struct libxl_ctx *ctx,uint32_t domid,libxl_event *event,libxl_device_disk *disk);
@@ -291,8 +291,6 @@ int libxl_set_memory_target(struct libxl_ctx *ctx, uint32_t domid, uint32_t targint libxl_console_attach (struct libxl_ctx *ctx,uint32_t domid,int cons_num);struct libxl_dominfo *libxl_domain_list (struct libxl_ctx *ctx,int *nb_domain); -xc_dominfo_t *libxl_domain_infolist (struct libxl_ctx *ctx,int *nb_domain); -xc_dominfo_t *libxl_domain_info (struct libxl_ctx *ctx,uint32_t domid);typedef struct libxl_device_model_starting libxl_device_model_starting ; int libxl_create_device_model(struct libxl_ctx *ctx,
tools/libxl/libxl_dom.c +9 -11
@@ -245,19 +245,17 @@ static int core_suspend_callback(void *data) }XL_LOG (si->ctx,XL_LOG_DEBUG ,"wait for the guest to suspend" );while (!strcmp (state,"suspend" ) && watchdog >0 ) { -int nb_domain, i; -xc_dominfo_t *list =NULL ; +xc_domaininfo_t info; +usleep (100000 ); - list =libxl_domain_infolist (si->ctx, &nb_domain); -for (i =0 ; i < nb_domain; i++) { -if (si->domid == list[i].domid) { -if (list[i].shutdown !=0 && list[i].shutdown_reason == SHUTDOWN_suspend) { -free (list); -return 1 ; - } - } + ret =xc_domain_getinfolist (si->ctx->xch, si->domid,1 , &info); +if (ret ==1 && info.domain == si->domid && info.flags & XEN_DOMINF_shutdown) { +int shutdown_reason; + + shutdown_reason = (info.flags >> XEN_DOMINF_shutdownshift) & XEN_DOMINF_shutdownmask; +if (shutdown_reason == SHUTDOWN_suspend) +return 1 ; } -free (list); state =libxl_xs_read (si->ctx,XBT_NULL , path); watchdog--; }
tools/libxl/xl.c +9 -14
@@ -808,7 +808,7 @@ start:while (1 ) {int ret;fd_set rfds; -xc_dominfo_t info; +xc_domaininfo_t info;libxl_event event;libxl_device_disk disk;memset (&info,0x00 ,sizeof (xc_dominfo_t));
@@ -824,10 +824,11 @@ start:case DOMAIN_DEATH :if (libxl_event_get_domain_death_info (&ctx, domid, &event, &info)) {LOG ("Domain %d is dead" , domid); -if (info.crashed || info.dying || (info.shutdown && (info.shutdown_reason != SHUTDOWN_suspend))) { +if (info.flags & XEN_DOMINF_dying || (info.flags & XEN_DOMINF_shutdown && (((info.flags >> XEN_DOMINF_shutdownshift) & XEN_DOMINF_shutdownmask) != SHUTDOWN_suspend))) {LOG ("Domain %d needs to be clean: destroying the domain" , domid);libxl_domain_destroy (&ctx, domid,0 ); -if (info.shutdown && (info.shutdown_reason == SHUTDOWN_reboot)) { +if (info.flags & XEN_DOMINF_shutdown && + (((info.flags >> XEN_DOMINF_shutdownshift) & XEN_DOMINF_shutdownmask) == SHUTDOWN_reboot)) {libxl_free_waiter (w1);libxl_free_waiter (w2);free (w1);
@@ -1320,32 +1321,26 @@ void destroy_domain(char *p)void list_domains (void ) {struct libxl_ctx ctx; -xc_dominfo_t *info; +struct libxl_dominfo *info;int nb_domain, i;libxl_ctx_init (&ctx);libxl_ctx_set_log (&ctx, log_callback,NULL ); - info =libxl_domain_infolist (&ctx, &nb_domain); + info =libxl_domain_list (&ctx, &nb_domain);if (info <0 ) {fprintf (stderr,"libxl_domain_infolist failed.\n" );exit (1 ); } -printf ("Name ID Mem VCPUs\tState\tTime(s)\n" ); +printf ("Name ID \tState\n" );for (i =0 ; i < nb_domain; i++) { -printf ("%-40s %5d %5lu %5d %c%c%c%c%c%c %8.1f\n" , +printf ("%-40s %5d %c%c%c\n" ,libxl_domid_to_name (&ctx, info[i].domid), info[i].domid, - info[i].nr_pages *XC_PAGE_SIZE /(1024 *1024 ), - info[i].nr_online_vcpus, info[i].running ?'r' :'-' , - info[i].blocked ?'b' :'-' , info[i].paused ?'p' :'-' , - info[i].shutdown ?'s' :'-' , - info[i].crashed ?'c' :'-' , - info[i].dying ?'d' :'-' , - ((float )info[i].cpu_time /1e9 )); + info[i].dying ?'d' :'-' ); }free (info); }
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
PATCH 9/11 add a get_shutdown_reason
In reply to Vincent Hanquez--- tools/libxl/libxl_dom.c | 15 +++++++++++++++ tools/libxl/libxl_internal.h | 3 +++ 2 files changed, 18 insertions(+), 0 deletions(-)
tools/libxl/libxl_dom.c +15 -0
@@ -42,6 +42,21 @@ int is_hvm(struct libxl_ctx *ctx, uint32_t domid)return !!(info.flags & XEN_DOMINF_hvm_guest); } +int get_shutdown_reason (struct libxl_ctx *ctx,uint32_t domid) +{ +xc_domaininfo_t info; +int ret; + + ret =xc_domain_getinfolist (ctx->xch, domid,1 , &info); +if (ret !=1 ) +return -1 ; +if (info.domain != domid) +return -1 ; +if (!(info.flags & XEN_DOMINF_shutdown)) +return -1 ; +return dominfo_get_shutdown_reason (&info); +} +int build_pre (struct libxl_ctx *ctx,uint32_t domid,libxl_domain_build_info *info,libxl_domain_build_state *state) {
tools/libxl/libxl_internal.h +3 -0
@@ -124,6 +124,9 @@ char **libxl_xs_directory(struct libxl_ctx *ctx, xs_transaction_t t, char *path,/* from xl_dom */ int is_hvm (struct libxl_ctx *ctx,uint32_t domid); +int get_shutdown_reason (struct libxl_ctx *ctx,uint32_t domid); +#define dominfo_get_shutdown_reason (info) (((info)->flags >> XEN_DOMINF_shutdownshift) & XEN_DOMINF_shutdownmask) +int build_pre (struct libxl_ctx *ctx,uint32_t domid,libxl_domain_build_info *info,libxl_domain_build_state *state); int build_post(struct libxl_ctx *ctx, uint32_t domid,
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
PATCH 10/11 define errors as an enum instead of define random values.
In reply to Vincent Hanquez--- tools/libxl/libxl.h | 11 +++++++---- 1 files changed, 7 insertions(+), 4 deletions(-)
tools/libxl/libxl.h +7 -4
@@ -226,10 +226,13 @@ typedef struct {bool power_mgmt; } libxl_device_pci; -#define ERROR_FAIL (-2) -#define ERROR_NI (-101) -#define ERROR_NOMEM (-1032) -#define ERROR_INVAL (-1245) +enum { +ERROR_VERSION =-1 , +ERROR_FAIL =-2 , +ERROR_NI =-3 , +ERROR_NOMEM =-4 , +ERROR_INVAL =-5 , +};/* context functions */ int libxl_ctx_init (struct libxl_ctx *ctx);
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
PATCH 11/11 add a versioning number to ctx_init that permit to detect incompatible client.
In reply to Vincent Hanquezat the moment if the versioning of the library is not exactly the same used in the client then the ctx_init return an ERROR_VERSION. however the same mechanism can be use in the future to be able to support older version and offer a compatibility layer.
--- tools/libxl/libxl.c | 4 +++- tools/libxl/libxl.h | 4 +++- tools/libxl/xl.c | 24 ++++++++++++------------ 3 files changed, 18 insertions(+), 14 deletions(-)
tools/libxl/libxl.c +3 -1
@@ -34,8 +34,10 @@#include "libxl_internal.h" #include "flexarray.h" -int libxl_ctx_init (struct libxl_ctx *ctx) +int libxl_ctx_init (struct libxl_ctx *ctx,int version) { +if (version !=LIBXL_VERSION ) +return ERROR_VERSION ;memset (ctx,0 ,sizeof (struct libxl_ctx )); ctx->alloc_maxsize =256 ; ctx->alloc_ptrs =calloc (ctx->alloc_maxsize,sizeof (void *));
tools/libxl/libxl.h +3 -1
@@ -234,8 +234,10 @@ enum { ERROR_INVAL = -5, }; +#define LIBXL_VERSION 0 +/* context functions */ -int libxl_ctx_init (struct libxl_ctx *ctx); +int libxl_ctx_init (struct libxl_ctx *ctx,int version);int libxl_ctx_free (struct libxl_ctx *ctx);int libxl_ctx_set_log (struct libxl_ctx *ctx,libxl_log_callback log_callback,void *log_data);
tools/libxl/xl.c +12 -12
@@ -730,7 +730,7 @@ static void create_domain(int debug, int daemonize, const char *config_file, con start: domid =0 ; -libxl_ctx_init (&ctx); +libxl_ctx_init (&ctx,LIBXL_VERSION );libxl_ctx_set_log (&ctx, log_callback,NULL );libxl_domain_make (&ctx, &info1, &domid);
@@ -942,7 +942,7 @@ void set_memory_target(char *p, char *mem)struct libxl_ctx ctx;uint32_t domid; -libxl_ctx_init (&ctx); +libxl_ctx_init (&ctx,LIBXL_VERSION );libxl_ctx_set_log (&ctx, log_callback,NULL );if (libxl_param_to_domid (&ctx, p, &domid) <0 ) {
@@ -984,7 +984,7 @@ void console(char *p, int cons_num)struct libxl_ctx ctx;uint32_t domid; -libxl_ctx_init (&ctx); +libxl_ctx_init (&ctx,LIBXL_VERSION );libxl_ctx_set_log (&ctx, log_callback,NULL );if (libxl_param_to_domid (&ctx, p, &domid) <0 ) {
@@ -1001,7 +1001,7 @@ void cd_insert(char *dom, char *virtdev, char *phys)libxl_device_disk disk;char *p; -libxl_ctx_init (&ctx); +libxl_ctx_init (&ctx,LIBXL_VERSION );libxl_ctx_set_log (&ctx, log_callback,NULL );if (libxl_param_to_domid (&ctx, dom, &domid) <0 ) {
@@ -1134,7 +1134,7 @@ void pcilist(char *dom)libxl_device_pci *pcidevs;int num, i; -libxl_ctx_init (&ctx); +libxl_ctx_init (&ctx,LIBXL_VERSION );libxl_ctx_set_log (&ctx, log_callback,NULL );if (libxl_param_to_domid (&ctx, dom, &domid) <0 ) {
@@ -1184,7 +1184,7 @@ void pcidetach(char *dom, char *bdf)libxl_device_pci pcidev;unsigned int domain, bus, dev, func; -libxl_ctx_init (&ctx); +libxl_ctx_init (&ctx,LIBXL_VERSION );libxl_ctx_set_log (&ctx, log_callback,NULL );if (libxl_param_to_domid (&ctx, dom, &domid) <0 ) {
@@ -1230,7 +1230,7 @@ void pciattach(char *dom, char *bdf, char *vs)libxl_device_pci pcidev;unsigned int domain, bus, dev, func; -libxl_ctx_init (&ctx); +libxl_ctx_init (&ctx,LIBXL_VERSION );libxl_ctx_set_log (&ctx, log_callback,NULL );if (libxl_param_to_domid (&ctx, dom, &domid) <0 ) {
@@ -1278,7 +1278,7 @@ void pause_domain(char *p)struct libxl_ctx ctx;uint32_t domid; -libxl_ctx_init (&ctx); +libxl_ctx_init (&ctx,LIBXL_VERSION );libxl_ctx_set_log (&ctx, log_callback,NULL );if (libxl_param_to_domid (&ctx, p, &domid) <0 ) {
@@ -1293,7 +1293,7 @@ void unpause_domain(char *p)struct libxl_ctx ctx;uint32_t domid; -libxl_ctx_init (&ctx); +libxl_ctx_init (&ctx,LIBXL_VERSION );libxl_ctx_set_log (&ctx, log_callback,NULL );if (libxl_param_to_domid (&ctx, p, &domid) <0 ) {
@@ -1308,7 +1308,7 @@ void destroy_domain(char *p)struct libxl_ctx ctx;uint32_t domid; -libxl_ctx_init (&ctx); +libxl_ctx_init (&ctx,LIBXL_VERSION );libxl_ctx_set_log (&ctx, log_callback,NULL );if (libxl_param_to_domid (&ctx, p, &domid) <0 ) {
@@ -1324,7 +1324,7 @@ void list_domains(void)struct libxl_dominfo *info;int nb_domain, i; -libxl_ctx_init (&ctx); +libxl_ctx_init (&ctx,LIBXL_VERSION );libxl_ctx_set_log (&ctx, log_callback,NULL ); info =libxl_domain_list (&ctx, &nb_domain);
@@ -1351,7 +1351,7 @@ int save_domain(char *p, char *filename, int checkpoint)uint32_t domid;int fd; -libxl_ctx_init (&ctx); +libxl_ctx_init (&ctx,LIBXL_VERSION );libxl_ctx_set_log (&ctx, log_callback,NULL );if (libxl_param_to_domid (&ctx, p, &domid) <0 ) {
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
Vincent Hanquez writes ("[Xen-devel] [PATCH 00/11] XL API fixes and cleanup"):
Quoted 3 lines
this patchset contains API fixes and cleanup on the XL library. removing the number of exposed API to the client, and simplify the API where possible.
Since this very large patchset was applied, a week and a half ago, libxenlight has been almost completely broken, at least as seen from its command line interface (and unit test), xl.
Evidently it wasn't properly tested; recent followup attempts to fix it haven't fixed it yet.
Perhaps it is time to revert this patch series and ask for a resubmission following proper testing ?
Ian.