libxl: Assorted bugfixes
v4 cover libxl: Assorted bugfixes
These are various bugfix and debugging patches. I have now tested this series up to 10/11. I haven't tested 11/11 because it doesn't build.
Bugfixes:
02/11 libxl: react correctly to bootloader pty master POLLHUP 03/11 libxl: fix device counting race in libxl__devices_destroy 04/11 libxl: fix formatting of DEFINE_DEVICES_ADD 07/11 libxl: do not blunder on if bootloader fails (again)
Cleanups:
01/11 libxl: unify libxl__device_destroy and device_hotplug_done 05/11 libxl: abolish useless `start' parameter to libxl__add_* 06/11 libxl: rename aodevs to multidev
09/11 libxl: remus: mark TODOs more clearly
10/11 libxl: remove an unused numainfo parameter
DO NOT APPLY:
08/11 Debugging machinery for synthesising POLLHUP 11/11 libxl: -Wunused-parameter
PATCH v4 1/11 libxl: unify libxl__device_destroy and device_hotplug_done
device_hotplug_done contains an open-coded but improved version of libxl__device_destroy. So move the contents of device_hotplug_done into libxl__device_destroy, deleting the old code, and replace it at its old location with a function call.
Also fix the error handling: the rc from the destroy should be propagated into the aodev.
--- tools/libxl/libxl_device.c | 35 ++++++++++++----------------------- 1 files changed, 12 insertions(+), 23 deletions(-)
tools/libxl/libxl_device.c +12 -23
@@ -513,17 +513,18 @@ int libxl__device_destroy(libxl__gc *gc, libxl__device *dev)char *be_path =libxl__device_backend_path (gc, dev);char *fe_path =libxl__device_frontend_path (gc, dev);xs_transaction_t t =0 ; -int rc =0 ; +int rc; + +for (;;) { + rc =libxl__xs_transaction_start (gc, &t); +if (rc) goto out; -do { - t =xs_transaction_start (CTX ->xsh);libxl__xs_path_cleanup (gc, t, fe_path);libxl__xs_path_cleanup (gc, t, be_path); - rc = !xs_transaction_end (CTX ->xsh, t,0 ); - }while (rc && errno ==EAGAIN ); -if (rc) { -LOGE (ERROR ,"unable to finish transaction" ); - goto out; + + rc =libxl__xs_transaction_commit (gc, &t); +if (!rc)break ; +if (rc <0 ) goto out; }libxl__device_destroy_tapdisk (gc, be_path);
@@ -993,29 +994,17 @@ error:static void device_hotplug_done (libxl__egc *egc,libxl__ao_device *aodev) {STATE_AO_GC (aodev->ao); -char *be_path =libxl__device_backend_path (gc, aodev->dev); -char *fe_path =libxl__device_frontend_path (gc, aodev->dev); -xs_transaction_t t =0 ;int rc;device_hotplug_clean (gc, aodev);/* Clean xenstore if it's a disconnection */ if (aodev->action ==DEVICE_DISCONNECT ) { -for (;;) { - rc =libxl__xs_transaction_start (gc, &t); -if (rc) goto out; - -libxl__xs_path_cleanup (gc, t, fe_path); -libxl__xs_path_cleanup (gc, t, be_path); - - rc =libxl__xs_transaction_commit (gc, &t); -if (!rc)break ; -if (rc <0 ) goto out; - } + rc =libxl__device_destroy (gc, aodev->dev); +if (!aodev->rc) + aodev->rc = rc; } -out: aodev->callback (egc, aodev);return ; }
Signature · 1 line
1.7.2.5
Re: [PATCH 01/11] libxl: unify libxl__device_destroy and device_hotplug_done
Quoted 10 lines · Ian Jackson
device_hotplug_donecontains an open-coded but improved version oflibxl__device_destroy. So move the contents ofdevice_hotplug_doneintolibxl__device_destroy, deleting the old code, and replace it at its old location with a function call.Also fix the error handling: the rc from the destroy should be propagated into the aodev.
Reported-by Ian Campbell <[email protected]>Signed-off-by Ian Jackson <[email protected]>
PATCH v4 2/11 libxl: react correctly to bootloader pty master POLLHUP
In reply to Ian JacksonReceive POLLHUP on the bootloader master pty is not an error. Hopefully it means that the bootloader has exited and therefore the pty slave side has no process group any more. (At least NetBSD indicates POLLHUP on the master in this case.)
So send the bootloader SIGTERM; if it has already exited then this has no effect (except that on some versions of NetBSD it erroneously returns ESRCH and we print a harmless warning) and we will then collect the bootloader's exit status and be satisfied.
However, we remember that we have done this so that if we got POLLHUP for some other reason than that the bootloader exited we report something resembling a useful message.
In order to implement this we need to provide a way for users of datacopier to handle POLLHUP rather than treating it as fatal.
We rename bootloader_abort to bootloader_stop since it now no longer only applies to error situations.
-
Changes in v4:
* Track whether we sent SIGTERM due to POLLHUP so we can report messages properly.
Changes in v3:
* datacopier provides new interface for handling POLLHUP
* Do not ignore errors on the xenconsole pty
* Rename bootloader_abort.
--- tools/libxl/libxl_aoutils.c | 23 +++++++++++++++++++++++ tools/libxl/libxl_bootloader.c | 39 +++++++++++++++++++++++++++++---------- tools/libxl/libxl_internal.h | 7 +++++-- 3 files changed, 57 insertions(+), 12 deletions(-)
tools/libxl/libxl_aoutils.c +23 -0
@@ -97,11 +97,31 @@ void libxl__datacopier_prefixdata(libxl__egc *egc, libxl__datacopier_state *dc,LIBXL_TAILQ_INSERT_TAIL (&dc->bufs, buf, entry); } +static int datacopier_pollhup_handled (libxl__egc *egc, +libxl__datacopier_state *dc, +short revents,int onwrite) +{ +STATE_AO_GC (dc->ao); + +if (dc->callback_pollhup && (revents &POLLHUP )) { +LOG (DEBUG ,"received POLLHUP on %s during copy of %s" , + onwrite ? dc->writewhat : dc->readwhat, + dc->copywhat); +libxl__datacopier_kill (dc); + dc->callback (egc, dc, onwrite,-1 ); +return 1 ; + } +return 0 ; +} +static void datacopier_readable (libxl__egc *egc,libxl__ev_fd *ev,int fd,short events,short revents) {libxl__datacopier_state *dc =CONTAINER_OF (ev, *dc, toread);STATE_AO_GC (dc->ao); +if (datacopier_pollhup_handled (egc, dc, revents,0 )) +return ; +if (revents & ~POLLIN ) {LOG (ERROR ,"unexpected poll event 0x%x (should be POLLIN)" " on %s during copy of %s" , revents, dc->readwhat, dc->copywhat);
@@ -163,6 +183,9 @@ static void datacopier_writable(libxl__egc *egc, libxl__ev_fd *ev,libxl__datacopier_state *dc =CONTAINER_OF (ev, *dc, towrite);STATE_AO_GC (dc->ao); +if (datacopier_pollhup_handled (egc, dc, revents,1 )) +return ; +if (revents & ~POLLOUT ) {LOG (ERROR ,"unexpected poll event 0x%x (should be POLLOUT)" " on %s during copy of %s" , revents, dc->writewhat, dc->copywhat);
tools/libxl/libxl_bootloader.c +29 -10
@@ -215,6 +215,7 @@ void libxl__bootloader_init(libxl__bootloader_state *bl)libxl__domaindeathcheck_init (&bl->deathcheck); bl->keystrokes.ao = bl->ao;libxl__datacopier_init (&bl->keystrokes); bl->display.ao = bl->ao;libxl__datacopier_init (&bl->display); + bl->got_pollhup =0 ; }static void bootloader_cleanup (libxl__egc *egc,libxl__bootloader_state *bl)
@@ -275,7 +276,7 @@ static void bootloader_local_detached_cb(libxl__egc *egc, }/* might be called at any time, provided it's init'd */ -static void bootloader_abort (libxl__egc *egc, +static void bootloader_stop (libxl__egc *egc,libxl__bootloader_state *bl,int rc) {STATE_AO_GC (bl->ao);
@@ -285,8 +286,8 @@ static void bootloader_abort(libxl__egc *egc,libxl__datacopier_kill (&bl->display);if (libxl__ev_child_inuse (&bl->child)) { r =kill (bl->child.pid,SIGTERM ); -if (r)LOGE (WARN ,"after failure, failed to kill bootloader [%lu]" , - (unsigned long )bl->child.pid); +if (r)LOGE (WARN ,"%sfailed to kill bootloader [%lu]" , + rc ?"after failure, " :"" , (unsigned long )bl->child.pid); } bl->rc = rc; }
@@ -508,7 +509,10 @@ static void bootloader_gotptys(libxl__egc *egc, libxl__openpty_state *op) bl->keystrokes.maxsz =BOOTLOADER_BUF_OUT ; bl->keystrokes.copywhat =GCSPRINTF ("bootloader input for domain %" PRIu32, bl->domid); - bl->keystrokes.callback = bootloader_keystrokes_copyfail; + bl->keystrokes.callback = bootloader_keystrokes_copyfail; + bl->keystrokes.callback_pollhup = bootloader_keystrokes_copyfail; +/* pollhup gets called with errnoval==-1 which is not otherwise +* possible since errnos are nonnegative, so it's unambiguous */ rc =libxl__datacopier_start (&bl->keystrokes);if (rc) goto out;
@@ -516,7 +520,8 @@ static void bootloader_gotptys(libxl__egc *egc, libxl__openpty_state *op) bl->display.maxsz =BOOTLOADER_BUF_IN ; bl->display.copywhat =GCSPRINTF ("bootloader output for domain %" PRIu32, bl->domid); - bl->display.callback = bootloader_display_copyfail; + bl->display.callback = bootloader_display_copyfail; + bl->display.callback_pollhup = bootloader_display_copyfail; rc =libxl__datacopier_start (&bl->display);if (rc) goto out;
@@ -562,30 +567,42 @@ static void bootloader_gotptys(libxl__egc *egc, libxl__openpty_state *op)/* perhaps one of these will be called, but perhaps not */ static void bootloader_copyfail (libxl__egc *egc,const char *which, -libxl__bootloader_state *bl,int onwrite,int errnoval) +libxl__bootloader_state *bl,int ondisplay,int onwrite,int errnoval) {STATE_AO_GC (bl->ao); +int rc =ERROR_FAIL ; + +if (errnoval==-1 ) { +/* POLLHUP */ +if (!!ondisplay != !!onwrite) { + rc =0 ; + bl->got_pollhup =1 ; + }else { +LOG (ERROR ,"unexpected POLLHUP on %s" , which); + } + }if (!onwrite && !errnoval)LOG (ERROR ,"unexpected eof copying %s" , which); -bootloader_abort (egc, bl,ERROR_FAIL ); + +bootloader_stop (egc, bl, rc); }static void bootloader_keystrokes_copyfail (libxl__egc *egc,libxl__datacopier_state *dc,int onwrite,int errnoval) {libxl__bootloader_state *bl =CONTAINER_OF (dc, *bl, keystrokes); -bootloader_copyfail (egc,"bootloader input" , bl, onwrite, errnoval); +bootloader_copyfail (egc,"bootloader input" , bl,0 , onwrite, errnoval); }static void bootloader_display_copyfail (libxl__egc *egc,libxl__datacopier_state *dc,int onwrite,int errnoval) {libxl__bootloader_state *bl =CONTAINER_OF (dc, *bl, display); -bootloader_copyfail (egc,"bootloader output" , bl, onwrite, errnoval); +bootloader_copyfail (egc,"bootloader output" , bl,1 , onwrite, errnoval); }static void bootloader_domaindeath (libxl__egc *egc,libxl__domaindeathcheck *dc) {libxl__bootloader_state *bl =CONTAINER_OF (dc, *bl, deathcheck); -bootloader_abort (egc, bl,ERROR_FAIL ); +bootloader_stop (egc, bl,ERROR_FAIL ); } static void bootloader_finished(libxl__egc *egc, libxl__ev_child *child,
@@ -599,6 +616,8 @@ static void bootloader_finished(libxl__egc *egc, libxl__ev_child *child,libxl__datacopier_kill (&bl->display);if (status) { +if (bl->got_pollhup &&WIFSIGNALED (status) &&WTERMSIG (status)==SIGTERM ) +LOG (ERROR ,"got POLLHUP, sent SIGTERM" );LOG (ERROR ,"bootloader failed - consult logfile %s" , bl->logfile);libxl_report_child_exitstatus (CTX ,XTL_ERROR ,"bootloader" , pid, status);
tools/libxl/libxl_internal.h +5 -2
@@ -2070,7 +2070,9 @@ typedef struct libxl__datacopier_buf libxl__datacopier_buf;* errnoval==0 means we got eof and all data was written * errnoval!=0 means we had a read error, logged * onwrite==-1 means some other internal failure, errnoval not valid, logged -* in all cases copier is killed before calling this callback */ +* If we get POLLHUP, we call callback_pollhup(..., onwrite, -1); +* or if callback_pollhup==0 this is an internal failure, as above. +* In all cases copier is killed before calling this callback */ typedef void libxl__datacopier_callback (libxl__egc *egc,libxl__datacopier_state *dc,int onwrite,int errnoval);
@@ -2089,6 +2091,7 @@ struct libxl__datacopier_state {const char *copywhat, *readwhat, *writewhat;/* for error msgs */ FILE *log;/* gets a copy of everything */ libxl__datacopier_callback *callback; +libxl__datacopier_callback *callback_pollhup;/* remaining fields are private to datacopier */ libxl__ev_fd toread, towrite;ssize_t used;
@@ -2273,7 +2276,7 @@ struct libxl__bootloader_state {int nargs, argsspace;const char **args;libxl__datacopier_state keystrokes, display; -int rc; +int rc, got_pollhup; }; _hidden void libxl__bootloader_init(libxl__bootloader_state *bl);
Signature · 1 line
1.7.2.5
Re: [PATCH 02/11] libxl: react correctly to bootloader pty master POLLHUP
Quoted 48 lines · Ian Jackson
Receive POLLHUP on the bootloader master pty is not an error. Hopefully it means that the bootloader has exited and therefore the pty slave side has no process group any more. (At least NetBSD indicates POLLHUP on the master in this case.)
So send the bootloader SIGTERM; if it has already exited then this has no effect (except that on some versions of NetBSD it erroneously returns ESRCH and we print a harmless warning) and we will then collect the bootloader's exit status and be satisfied.
However, we remember that we have done this so that if we got POLLHUP for some other reason than that the bootloader exited we report something resembling a useful message.
In order to implement this we need to provide a way for users of datacopier to handle POLLHUP rather than treating it as fatal.
We rename
bootloader_aborttobootloader_stopsince it now no longer only applies to error situations.Signed-off-by Roger Pau Monne <[email protected]>Signed-off-by Ian Jackson <[email protected]>-
Changes in v4:
* Track whether we sent SIGTERM due to POLLHUP so we can report messages properly.Changes in v3:
* datacopier provides new interface for handling POLLHUP
* Do not ignore errors on the xenconsole pty
* Renamebootloader_abort.--- tools/libxl/libxl_aoutils.c | 23 +++++++++++++++++++++++ tools/libxl/libxl_bootloader.c | 39 +++++++++++++++++++++++++++++---------- tools/libxl/libxl_internal.h | 7 +++++-- 3 files changed, 57 insertions(+), 12 deletions(-)tools/libxl/libxl_aoutils.c +2
-0@@ -97,11 +97,31 @@ void libxl__datacopier_prefixdata(libxl__egc *egc, libxl__datacopier_state *dc,LIBXL_TAILQ_INSERT_TAIL (&dc->bufs, buf, entry); } +static int datacopier_pollhup_handled(libxl__egc *egc, + libxl__datacopier_state *dc,
tools/libxl/libxl_aoutils.c void libxl__datacopier_prefixdata(libxl__egc *egc, libxl__datacopier_state *dc, · line 111
Quoted 10 lines
tools/libxl/libxl_aoutils.c +10
-0+ short revents, int onwrite) +{ +STATE_AO_GC (dc->ao); + +if (dc->callback_pollhup && (revents &POLLHUP )) { +LOG (DEBUG ,"received POLLHUP on %s during copy of %s" , + onwrite ? dc->writewhat : dc->readwhat, + dc->copywhat); +libxl__datacopier_kill (dc); + dc->callback (egc, dc, onwrite,-1 );
You've forgotten to make this ->callback_pollhup as discussed last time.
Re: [PATCH 02/11] libxl: react correctly to bootloader pty master POLLHUP
Ian Campbell writes ("Re: [Xen-devel] [PATCH 02/11] libxl: react correctly to bootloader pty master POLLHUP"):
Quoted 5 lines · Ian Jackson
Quoted 4 lines
Receive POLLHUP on the bootloader master pty is not an error. Hopefully it means that the bootloader has exited and therefore the pty slave side has no process group any more. (At least NetBSD indicates POLLHUP on the master in this case.)
...
Quoted 6 lines
Quoted 6 lines
tools/libxl/libxl_aoutils.c +6
-0+static int datacopier_pollhup_handled (libxl__egc *egc, +libxl__datacopier_state *dc, +short revents,int onwrite) +{ +STATE_AO_GC (dc->ao); +
Quoted 8 lines
tools/libxl/libxl_aoutils.c void libxl__datacopier_prefixdata(libxl__egc *egc, libxl__datacopier_state *dc, · line 111
Quoted 6 lines
tools/libxl/libxl_aoutils.c +6
-0+if (dc->callback_pollhup && (revents &POLLHUP )) { +LOG (DEBUG ,"received POLLHUP on %s during copy of %s" , + onwrite ? dc->writewhat : dc->readwhat, + dc->copywhat); +libxl__datacopier_kill (dc); + dc->callback (egc, dc, onwrite,-1 );You've forgotten to make this ->callback_pollhup as discussed last time.
So I have. And this didn't show up in my testing because the callers all either set ->callback_pollhup==0 or ==->callback.
I have fixed this in my tree.
Ian.
PATCH v4 3/11 libxl: fix device counting race in libxl__devices_destroy
In reply to Ian JacksonDon't have a fixed number of devices in the aodevs array, and instead size it depending on the devices present in xenstore. Somewhat formalise the multiple device addition/removal machinery to make this clearer and easier to do.
As a side-effect we fix a few "lost thread of control" bug which would occur if there were no devices of a particular kind. (Various if statements which checked for there being no devices have become redundant, but are retained to avoid making the patch bigger.)
Specifically:
* Users of libxl__ao_devices are no longer expected to know in advance how many device operations they are going to do. Instead they can initiate them one at a time, between bracketing calls to "begin" and "prepared".
* The array of aodevs used for this is dynamically sized; to support this it's an array of pointers rather than of structs.
* Users of libxl__ao_devices are presented with a more opaque interface. They are are no longer expected to, themselves,
- look into the array of aodevs (this is now private)
- know that the individual addition/removal completions are handled by libxl__ao_devices_callback (this callback function is now a private function for the multidev machinery)
- ever deal with populating the contents of an aodevs
* The doc comments relating to some of the members of libxl__ao_device are clarified. (And the member `aodevs' is moved to put it with the other members with the same status.)
* The multidev machinery allocates an aodev to represent the operation of preparing all of the other operations. See the comment in libxl__multidev_begin.
A wrinkle is that the functions are called "multidev" but the structs are called "libxl__ao_devices" and "aodevs". I have given these functions this name to distinguish them from "libxl__ao_device" and "aodev" and so forth by more than just the use of the plural "s" suffix.
In the next patch we will rename the structs.
-
Changes in v4:
* Actually honour errors in rc argument to libxl__multidev_prepared.
* Fix the doc comment for libxl__add_*.
* In comments, consistently use "multidev" not "multidevs".
Changes in v3:
* New multidev interfaces - extensive changes.
--- tools/libxl/libxl_create.c | 8 +- tools/libxl/libxl_device.c | 129 +++++++++++++++++++----------------------- tools/libxl/libxl_dm.c | 8 +- tools/libxl/libxl_internal.h | 75 +++++++++++++++---------- 4 files changed, 111 insertions(+), 109 deletions(-)
tools/libxl/libxl_create.c +4 -4
@@ -909,10 +909,10 @@ static void domcreate_rebuild_done(libxl__egc *egc,store_libxl_entry (gc, domid, &d_config->b_info); - dcs->aodevs.size = d_config->num_disks; +libxl__multidev_begin (ao, &dcs->aodevs); dcs->aodevs.callback = domcreate_launch_dm; -libxl__prepare_ao_devices (ao, &dcs->aodevs);libxl__add_disks (egc, ao, domid,0 , d_config, &dcs->aodevs); +libxl__multidev_prepared (egc, &dcs->aodevs,0 );return ;
@@ -1039,10 +1039,10 @@ static void domcreate_devmodel_started(libxl__egc *egc,/* Plug nic interfaces */ if (d_config->num_nics >0 ) {/* Attach nics */ - dcs->aodevs.size = d_config->num_nics; +libxl__multidev_begin (ao, &dcs->aodevs); dcs->aodevs.callback = domcreate_attach_pci; -libxl__prepare_ao_devices (ao, &dcs->aodevs);libxl__add_nics (egc, ao, domid,0 , d_config, &dcs->aodevs); +libxl__multidev_prepared (egc, &dcs->aodevs,0 );return ; }
tools/libxl/libxl_device.c +58 -71
198 lines not on this page · raw message
tools/libxl/libxl_dm.c +4 -4
@@ -856,10 +856,10 @@ retry_transaction:if (errno ==EAGAIN ) goto retry_transaction; - sdss->aodevs.size = dm_config->num_disks; +libxl__multidev_begin (ao, &sdss->aodevs); sdss->aodevs.callback = spawn_stub_launch_dm; -libxl__prepare_ao_devices (ao, &sdss->aodevs);libxl__add_disks (egc, ao, dm_domid,0 , dm_config, &sdss->aodevs); +libxl__multidev_prepared (egc, &sdss->aodevs,0 );free (args);return ;
@@ -982,10 +982,10 @@ static void spawn_stubdom_pvqemu_cb(libxl__egc *egc,if (rc) goto out;if (d_config->num_nics >0 ) { - sdss->aodevs.size = d_config->num_nics; +libxl__multidev_begin (ao, &sdss->aodevs); sdss->aodevs.callback = stubdom_pvqemu_cb; -libxl__prepare_ao_devices (ao, &sdss->aodevs);libxl__add_nics (egc, ao, dm_domid,0 , d_config, &sdss->aodevs); +libxl__multidev_prepared (egc, &sdss->aodevs,0 );return ; }
tools/libxl/libxl_internal.h +46 -31
108 lines not on this page · raw message
Signature · 1 line
1.7.2.5
Re: [PATCH 03/11] libxl: fix device counting race in libxl__devices_destroy
Quoted 2 lines · Ian Jackson
Signed-off-by Roger Pau Monne <[email protected]>Signed-off-by Ian Jackson <[email protected]>
PATCH v4 4/11 libxl: fix formatting of DEFINE_DEVICES_ADD
In reply to Ian JacksonThese lines were exactly 80 columns wide, which produces hideous wrap damage in an 80 column emacs. Reformat using emacs's C-c \, which puts the \ in column 72 (by default) where possible.
Whitespace change only.
--- tools/libxl/libxl_device.c | 26 +++++++++++++------------- 1 files changed, 13 insertions(+), 13 deletions(-)
tools/libxl/libxl_device.c +13 -13
@@ -483,19 +483,19 @@ void libxl__multidev_prepared(libxl__egc *egc, libxl__ao_devices *aodevs,* libxl__add_nics */ -#define DEFINE_DEVICES_ADD (type) \ - void libxl__add_##type##s(libxl__egc *egc, libxl__ao *ao, uint32_t domid, \ - int start, libxl_domain_config *d_config, \ - libxl__ao_devices *aodevs) \ - { \ - AO_GC; \ - int i; \ - int end = start + d_config->num_##type##s; \ - for (i = start; i < end; i++) { \ - libxl__ao_device *aodev = libxl__multidev_prepare(aodevs); \ - libxl__device_##type##_add(egc, domid, &d_config->type##s[i-start],\ - aodev); \ - } \ +#define DEFINE_DEVICES_ADD (type) \ + void libxl__add_##type##s(libxl__egc *egc, libxl__ao *ao, uint32_t domid, \ + int start, libxl_domain_config *d_config, \ + libxl__ao_devices *aodevs) \ + { \ + AO_GC; \ + int i; \ + int end = start + d_config->num_##type##s; \ + for (i = start; i < end; i++) { \ + libxl__ao_device *aodev = libxl__multidev_prepare(aodevs); \ + libxl__device_##type##_add(egc, domid, &d_config->type##s[i-start], \ + aodev); \ + } \ }DEFINE_DEVICES_ADD (disk)
Signature · 1 line
1.7.2.5
Re: [PATCH 04/11] libxl: fix formatting of DEFINE_DEVICES_ADD
Quoted 7 lines · Ian Jackson
These lines were exactly 80 columns wide, which produces hideous wrap damage in an 80 column emacs. Reformat using emacs's C-c \, which puts the \ in column 72 (by default) where possible.
Whitespace change only.
Signed-off-by Ian Jackson <[email protected]>
PATCH v4 5/11 libxl: abolish useless `start' parameter to libxl__add_*
In reply to Ian Jackson0 is always passed for this parameter and the code doesn't, actually, use it, now.
--- tools/libxl/libxl_create.c | 4 ++-- tools/libxl/libxl_device.c | 7 +++---- tools/libxl/libxl_dm.c | 4 ++-- tools/libxl/libxl_internal.h | 8 +++----- 4 files changed, 10 insertions(+), 13 deletions(-)
tools/libxl/libxl_create.c +2 -2
@@ -911,7 +911,7 @@ static void domcreate_rebuild_done(libxl__egc *egc,libxl__multidev_begin (ao, &dcs->aodevs); dcs->aodevs.callback = domcreate_launch_dm; -libxl__add_disks (egc, ao, domid,0 , d_config, &dcs->aodevs); +libxl__add_disks (egc, ao, domid, d_config, &dcs->aodevs);libxl__multidev_prepared (egc, &dcs->aodevs,0 );return ;
@@ -1041,7 +1041,7 @@ static void domcreate_devmodel_started(libxl__egc *egc,/* Attach nics */ libxl__multidev_begin (ao, &dcs->aodevs); dcs->aodevs.callback = domcreate_attach_pci; -libxl__add_nics (egc, ao, domid,0 , d_config, &dcs->aodevs); +libxl__add_nics (egc, ao, domid, d_config, &dcs->aodevs);libxl__multidev_prepared (egc, &dcs->aodevs,0 );return ; }
tools/libxl/libxl_device.c +3 -4
@@ -485,15 +485,14 @@ void libxl__multidev_prepared(libxl__egc *egc, libxl__ao_devices *aodevs,#define DEFINE_DEVICES_ADD (type) \ void libxl__add_##type##s(libxl__egc *egc, libxl__ao *ao, uint32_t domid, \ - int start, libxl_domain_config *d_config, \ + libxl_domain_config *d_config, \ libxl__ao_devices *aodevs) \ { \ AO_GC; \ int i; \ - int end = start + d_config->num_##type##s; \ - for (i = start; i < end; i++) { \ + for (i = 0; i < d_config->num_##type##s; i++) { \ libxl__ao_device *aodev = libxl__multidev_prepare(aodevs); \ - libxl__device_##type##_add(egc, domid, &d_config->type##s[i-start], \ + libxl__device_##type##_add(egc, domid, &d_config->type##s[i], \ aodev); \ } \ }
tools/libxl/libxl_dm.c +2 -2
@@ -858,7 +858,7 @@ retry_transaction:libxl__multidev_begin (ao, &sdss->aodevs); sdss->aodevs.callback = spawn_stub_launch_dm; -libxl__add_disks (egc, ao, dm_domid,0 , dm_config, &sdss->aodevs); +libxl__add_disks (egc, ao, dm_domid, dm_config, &sdss->aodevs);libxl__multidev_prepared (egc, &sdss->aodevs,0 );free (args);
@@ -984,7 +984,7 @@ static void spawn_stubdom_pvqemu_cb(libxl__egc *egc,if (d_config->num_nics >0 ) {libxl__multidev_begin (ao, &sdss->aodevs); sdss->aodevs.callback = stubdom_pvqemu_cb; -libxl__add_nics (egc, ao, dm_domid,0 , d_config, &sdss->aodevs); +libxl__add_nics (egc, ao, dm_domid, d_config, &sdss->aodevs);libxl__multidev_prepared (egc, &sdss->aodevs,0 );return ; }
tools/libxl/libxl_internal.h +3 -5
@@ -2382,19 +2382,17 @@ _hidden void libxl__devices_destroy(libxl__egc *egc,/* Helper function to add a bunch of disks. This should be used when * the caller is inside an async op. "devices" will NOT be prepared by * this function, so the caller must make sure to call -* libxl__multidev_begin before calling this function. The start -* parameter contains the position inside the aodevs array that should -* be used to store the state of this devices. +* libxl__multidev_begin before calling this function. * * The "callback" will be called for each device, and the user is responsible * for calling libxl__ao_device_check_last on the callback. */ _hidden void libxl__add_disks(libxl__egc *egc, libxl__ao *ao, uint32_t domid, -int start,libxl_domain_config *d_config, +libxl_domain_config *d_config,libxl__ao_devices *aodevs); _hidden void libxl__add_nics(libxl__egc *egc, libxl__ao *ao, uint32_t domid, -int start,libxl_domain_config *d_config, +libxl_domain_config *d_config,libxl__ao_devices *aodevs);/*----- device model creation -----*/
Signature · 1 line
1.7.2.5
Re: [PATCH 05/11] libxl: abolish useless `start' parameter to libxl__add_*
Quoted 4 lines · Ian Jackson
0 is always passed for this parameter and the code doesn't, actually, use it, now.
Signed-off-by Ian Jackson <[email protected]>
Quoted 4 lines
{ \
AO_GC; \
int i; \
- int end = start + d_config->num_##type##s; \This definition of end is pretty dodgy, glad to be rid of it.
tools/libxl/libxl_device.c void libxl__multidev_prepared(libxl__egc *egc, libxl__ao_devices *aodevs, · line 498
Quoted 8 lines
tools/libxl/libxl_device.c +2
-2-for (i = start; i < end; i++) { \ + for (i = 0; i < d_config->num_##type##s; i++) { \ libxl__ao_device *aodev = libxl__multidev_prepare(aodevs); \ - libxl__device_##type##_add(egc, domid, &d_config->type##s[i-start], \ + libxl__device_##type##_add(egc, domid, &d_config->type##s[i], \ aodev); \ } \ }
Ian.
PATCH v4 6/11 libxl: rename aodevs to multidev
In reply to Ian JacksonTo be consistent with the new function naming, rename libxl__ao_devices to libxl__multidev and all variables aodevs to multidev.
No functional change.
--- tools/libxl/libxl_create.c | 30 +++++++++--------- tools/libxl/libxl_device.c | 68 +++++++++++++++++++++--------------------- tools/libxl/libxl_dm.c | 30 +++++++++--------- tools/libxl/libxl_internal.h | 26 ++++++++-------- 4 files changed, 77 insertions(+), 77 deletions(-)
tools/libxl/libxl_create.c +15 -15
@@ -599,10 +599,10 @@ static void domcreate_bootloader_done(libxl__egc *egc,libxl__bootloader_state *bl, int rc); -static void domcreate_launch_dm (libxl__egc *egc,libxl__ao_devices *aodevs, +static void domcreate_launch_dm (libxl__egc *egc,libxl__multidev *aodevs,int ret); -static void domcreate_attach_pci (libxl__egc *egc,libxl__ao_devices *aodevs, +static void domcreate_attach_pci (libxl__egc *egc,libxl__multidev *aodevs,int ret); static void domcreate_console_available(libxl__egc *egc,
@@ -909,10 +909,10 @@ static void domcreate_rebuild_done(libxl__egc *egc,store_libxl_entry (gc, domid, &d_config->b_info); -libxl__multidev_begin (ao, &dcs->aodevs); - dcs->aodevs.callback = domcreate_launch_dm; -libxl__add_disks (egc, ao, domid, d_config, &dcs->aodevs); -libxl__multidev_prepared (egc, &dcs->aodevs,0 ); +libxl__multidev_begin (ao, &dcs->multidev); + dcs->multidev.callback = domcreate_launch_dm; +libxl__add_disks (egc, ao, domid, d_config, &dcs->multidev); +libxl__multidev_prepared (egc, &dcs->multidev,0 );return ;
@@ -921,10 +921,10 @@ static void domcreate_rebuild_done(libxl__egc *egc,domcreate_complete (egc, dcs, ret); } -static void domcreate_launch_dm (libxl__egc *egc,libxl__ao_devices *aodevs, +static void domcreate_launch_dm (libxl__egc *egc,libxl__multidev *multidev,int ret) { -libxl__domain_create_state *dcs =CONTAINER_OF (aodevs, *dcs, aodevs); +libxl__domain_create_state *dcs =CONTAINER_OF (multidev, *dcs, multidev);STATE_AO_GC (dcs->ao);int i;
@@ -1039,14 +1039,14 @@ static void domcreate_devmodel_started(libxl__egc *egc,/* Plug nic interfaces */ if (d_config->num_nics >0 ) {/* Attach nics */ -libxl__multidev_begin (ao, &dcs->aodevs); - dcs->aodevs.callback = domcreate_attach_pci; -libxl__add_nics (egc, ao, domid, d_config, &dcs->aodevs); -libxl__multidev_prepared (egc, &dcs->aodevs,0 ); +libxl__multidev_begin (ao, &dcs->multidev); + dcs->multidev.callback = domcreate_attach_pci; +libxl__add_nics (egc, ao, domid, d_config, &dcs->multidev); +libxl__multidev_prepared (egc, &dcs->multidev,0 );return ; } -domcreate_attach_pci (egc, &dcs->aodevs,0 ); +domcreate_attach_pci (egc, &dcs->multidev,0 );return ; error_out:
@@ -1054,10 +1054,10 @@ error_out:domcreate_complete (egc, dcs, ret); } -static void domcreate_attach_pci (libxl__egc *egc,libxl__ao_devices *aodevs, +static void domcreate_attach_pci (libxl__egc *egc,libxl__multidev *multidev,int ret) { -libxl__domain_create_state *dcs =CONTAINER_OF (aodevs, *dcs, aodevs); +libxl__domain_create_state *dcs =CONTAINER_OF (multidev, *dcs, multidev);STATE_AO_GC (dcs->ao);int i;libxl_ctx *ctx =CTX ;
tools/libxl/libxl_device.c +34 -34
156 lines not on this page · raw message
tools/libxl/libxl_dm.c +15 -15
@@ -714,10 +714,10 @@ static void spawn_stubdom_pvqemu_cb(libxl__egc *egc, int rc);static void spawn_stub_launch_dm (libxl__egc *egc, -libxl__ao_devices *aodevs,int ret); +libxl__multidev *aodevs,int ret);static void stubdom_pvqemu_cb (libxl__egc *egc, -libxl__ao_devices *aodevs, +libxl__multidev *aodevs,int rc); static void spaw_stubdom_pvqemu_destroy_cb(libxl__egc *egc,
@@ -856,10 +856,10 @@ retry_transaction:if (errno ==EAGAIN ) goto retry_transaction; -libxl__multidev_begin (ao, &sdss->aodevs); - sdss->aodevs.callback = spawn_stub_launch_dm; -libxl__add_disks (egc, ao, dm_domid, dm_config, &sdss->aodevs); -libxl__multidev_prepared (egc, &sdss->aodevs,0 ); +libxl__multidev_begin (ao, &sdss->multidev); + sdss->multidev.callback = spawn_stub_launch_dm; +libxl__add_disks (egc, ao, dm_domid, dm_config, &sdss->multidev); +libxl__multidev_prepared (egc, &sdss->multidev,0 );free (args);return ;
@@ -872,9 +872,9 @@ out: }static void spawn_stub_launch_dm (libxl__egc *egc, -libxl__ao_devices *aodevs,int ret) +libxl__multidev *multidev,int ret) { -libxl__stub_dm_spawn_state *sdss =CONTAINER_OF (aodevs, *sdss, aodevs); +libxl__stub_dm_spawn_state *sdss =CONTAINER_OF (multidev, *sdss, multidev);STATE_AO_GC (sdss->dm.spawn.ao);libxl_ctx *ctx =libxl__gc_owner (gc);int i, num_console =STUBDOM_SPECIAL_CONSOLES ;
@@ -982,22 +982,22 @@ static void spawn_stubdom_pvqemu_cb(libxl__egc *egc,if (rc) goto out;if (d_config->num_nics >0 ) { -libxl__multidev_begin (ao, &sdss->aodevs); - sdss->aodevs.callback = stubdom_pvqemu_cb; -libxl__add_nics (egc, ao, dm_domid, d_config, &sdss->aodevs); -libxl__multidev_prepared (egc, &sdss->aodevs,0 ); +libxl__multidev_begin (ao, &sdss->multidev); + sdss->multidev.callback = stubdom_pvqemu_cb; +libxl__add_nics (egc, ao, dm_domid, d_config, &sdss->multidev); +libxl__multidev_prepared (egc, &sdss->multidev,0 );return ; } out: -stubdom_pvqemu_cb (egc, &sdss->aodevs, rc); +stubdom_pvqemu_cb (egc, &sdss->multidev, rc); }static void stubdom_pvqemu_cb (libxl__egc *egc, -libxl__ao_devices *aodevs, +libxl__multidev *multidev,int rc) { -libxl__stub_dm_spawn_state *sdss =CONTAINER_OF (aodevs, *sdss, aodevs); +libxl__stub_dm_spawn_state *sdss =CONTAINER_OF (multidev, *sdss, multidev);STATE_AO_GC (sdss->dm.spawn.ao);uint32_t dm_domid = sdss->pvqemu.guest_domid;
tools/libxl/libxl_internal.h +13 -13
@@ -1791,7 +1791,7 @@ typedef enum { } libxl__device_action;typedef struct libxl__ao_device libxl__ao_device ; -typedef struct libxl__ao_devices libxl__ao_devices ; +typedef struct libxl__multidev libxl__multidev ;typedef void libxl__device_callback (libxl__egc *,libxl__ao_device *);/* This functions sets the necessary libxl__ao_device struct values to use
@@ -1821,7 +1821,7 @@ struct libxl__ao_device {int rc;/* private for multidev */ int active; -libxl__ao_devices *aodevs;/* reference to the containing multidev */ +libxl__multidev *multidev;/* reference to the containing multidev */ /* private for add/remove implementation */ libxl__ev_devstate backend_ds;/* Bodge for Qemu devices, also used for timeout of hotplug execution */
@@ -1847,12 +1847,12 @@ struct libxl__ao_device {*/ /* Starts preparing to add/remove a bunch of devices. */ -_hidden void libxl__multidev_begin(libxl__ao *ao, libxl__ao_devices*); +_hidden void libxl__multidev_begin(libxl__ao *ao, libxl__multidev*);/* Prepares to add/remove one of many devices. Returns a libxl__ao_device * which has had libxl__prepare_ao_device called, and which has also * had ->callback set. The user should not mess with aodev->callback. */ -_hidden libxl__ao_device *libxl__multidev_prepare(libxl__ao_devices*); +_hidden libxl__ao_device *libxl__multidev_prepare(libxl__multidev*);/* Notifies the multidev machinery that we have now finished preparing * and initiating devices. multidev->callback may then be called as
@@ -1860,10 +1860,10 @@ _hidden libxl__ao_device *libxl__multidev_prepare(libxl__ao_devices*);* outstanding, perhaps reentrantly. If rc!=0 (error should have been * logged) multidev->callback will get a non-zero rc. * callback may be set by the user at any point before prepared. */ -_hidden void libxl__multidev_prepared(libxl__egc*, libxl__ao_devices*, int rc); +_hidden void libxl__multidev_prepared(libxl__egc*, libxl__multidev*, int rc); -typedef void libxl__devices_callback (libxl__egc *,libxl__ao_devices *,int rc); -struct libxl__ao_devices { +typedef void libxl__devices_callback (libxl__egc *,libxl__multidev *,int rc); +struct libxl__multidev {/* set by user: */ libxl__devices_callback *callback;/* for private use by libxl__...ao_devices... machinery: */
@@ -2336,7 +2336,7 @@ struct libxl__devices_remove_state {libxl__devices_remove_callback *callback;int force;/* libxl_device_TYPE_destroy rather than _remove */ /* private */ -libxl__ao_devices aodevs; +libxl__multidev multidev;int num_devices; };
@@ -2380,7 +2380,7 @@ _hidden void libxl__devices_destroy(libxl__egc *egc, libxl__devices_remove_state *drs);/* Helper function to add a bunch of disks. This should be used when -* the caller is inside an async op. "devices" will NOT be prepared by +* the caller is inside an async op. "multidev" will NOT be prepared by * this function, so the caller must make sure to call * libxl__multidev_begin before calling this function. *
@@ -2389,11 +2389,11 @@ _hidden void libxl__devices_destroy(libxl__egc *egc,*/ _hidden void libxl__add_disks(libxl__egc *egc, libxl__ao *ao, uint32_t domid,libxl_domain_config *d_config, -libxl__ao_devices *aodevs); +libxl__multidev *multidev); _hidden void libxl__add_nics(libxl__egc *egc, libxl__ao *ao, uint32_t domid,libxl_domain_config *d_config, -libxl__ao_devices *aodevs); +libxl__multidev *multidev);/*----- device model creation -----*/
@@ -2429,7 +2429,7 @@ typedef struct {libxl__domain_build_state dm_state;libxl__dm_spawn_state pvqemu;libxl__destroy_domid_state dis; -libxl__ao_devices aodevs; +libxl__multidev multidev; } libxl__stub_dm_spawn_state; _hidden void libxl__spawn_stub_dm(libxl__egc *egc, libxl__stub_dm_spawn_state*);
@@ -2461,7 +2461,7 @@ struct libxl__domain_create_state {libxl__save_helper_state shs;/* necessary if the domain creation failed and we have to destroy it */ libxl__domain_destroy_state dds; -libxl__ao_devices aodevs; +libxl__multidev multidev; };/*----- Domain suspend (save) functions -----*/
Signature · 1 line
1.7.2.5
Re: [PATCH 06/11] libxl: rename aodevs to multidev
Quoted 7 lines · Ian Jackson
To be consistent with the new function naming, rename
libxl__ao_devicestolibxl__multidevand all variables aodevs to multidev.No functional change.
Signed-off-by Ian Jackson <[email protected]>
Didn't read closely but on the basis that it is mechanical:
PATCH v4 7/11 libxl: do not blunder on if bootloader fails (again)
In reply to Ian JacksonDo not lose the rc value passed to bootloader_callback. Do not lose the rc value from the bl when the local disk detach succeeds.
While we're here rationalise the use of bl->rc to make things clearer. Set it to zero at the start and always update it conditionally; copy it into bootloader_callback's argument each time.
--- tools/libxl/libxl_bootloader.c | 11 +++++++++-- 1 files changed, 9 insertions(+), 2 deletions(-)
tools/libxl/libxl_bootloader.c +9 -2
@@ -206,6 +206,7 @@ static int parse_bootloader_result(libxl__egc *egc,void libxl__bootloader_init (libxl__bootloader_state *bl) {assert (bl->ao); + bl->rc =0 ; bl->dls.diskpath =NULL ; bl->openpty.ao = bl->ao; bl->dls.ao = bl->ao;
@@ -255,6 +256,9 @@ static void bootloader_local_detached_cb(libxl__egc *egc,static void bootloader_callback (libxl__egc *egc,libxl__bootloader_state *bl,int rc) { +if (!bl->rc) + bl->rc = rc; +bootloader_cleanup (egc, bl); bl->dls.callback = bootloader_local_detached_cb;
@@ -270,9 +274,11 @@ static void bootloader_local_detached_cb(libxl__egc *egc,if (rc) {LOG (ERROR ,"unable to detach locally attached disk" ); +if (!bl->rc) + bl->rc = rc; } - bl->callback (egc, bl, rc); + bl->callback (egc, bl, bl->rc); }/* might be called at any time, provided it's init'd */
@@ -289,7 +295,8 @@ static void bootloader_stop(libxl__egc *egc,if (r)LOGE (WARN ,"%sfailed to kill bootloader [%lu]" , rc ?"after failure, " :"" , (unsigned long )bl->child.pid); } - bl->rc = rc; +if (!bl->rc) + bl->rc = rc; }/*----- main flow of control -----*/
Signature · 1 line
1.7.2.5
Re: [PATCH 07/11] libxl: do not blunder on if bootloader fails (again)
Quoted 8 lines · Ian Jackson
Do not lose the rc value passed to
bootloader_callback. Do not lose the rc value from the bl when the local disk detach succeeds.While we're here rationalise the use of
bl->rcto make things clearer. Set it to zero at the start and always update it conditionally; copy it into bootloader_callback's argument each time.Signed-off-by Ian Jackson <[email protected]>
Quoted 49 lines
--- tools/libxl/libxl_bootloader.c | 11 +++++++++-- 1 files changed, 9 insertions(+), 2 deletions(-)tools/libxl/libxl_bootloader.c +9
-2@@ -206,6 +206,7 @@ static int parse_bootloader_result(libxl__egc *egc,void libxl__bootloader_init (libxl__bootloader_state *bl) {assert (bl->ao); + bl->rc =0 ; bl->dls.diskpath =NULL ; bl->openpty.ao = bl->ao; bl->dls.ao = bl->ao;@@ -255,6 +256,9 @@ static void bootloader_local_detached_cb(libxl__egc *egc,static void bootloader_callback (libxl__egc *egc,libxl__bootloader_state *bl,int rc) { +if (!bl->rc) + bl->rc = rc; +bootloader_cleanup (egc, bl); bl->dls.callback = bootloader_local_detached_cb;@@ -270,9 +274,11 @@ static void bootloader_local_detached_cb(libxl__egc *egc,if (rc) {LOG (ERROR ,"unable to detach locally attached disk" ); +if (!bl->rc) + bl->rc = rc; } - bl->callback (egc, bl, rc); + bl->callback (egc, bl, bl->rc); }/* might be called at any time, provided it's init'd */ @@ -289,7 +295,8 @@ static void bootloader_stop(libxl__egc *egc,if (r)LOGE (WARN ,"%sfailed to kill bootloader [%lu]" , rc ?"after failure, " :"" , (unsigned long )bl->child.pid); } - bl->rc = rc; +if (!bl->rc) + bl->rc = rc; }/*----- main flow of control -----*/
PATCH v4 8/11 Debugging machinery for synthesising POLLHUP
In reply to Ian Jackson--- tools/libxl/libxl_bootloader.c | 16 ++++++++++++++++ 1 files changed, 16 insertions(+), 0 deletions(-)
tools/libxl/libxl_bootloader.c +16 -0
@@ -447,6 +447,19 @@ static void bootloader_disk_attached_cb(libxl__egc *egc,bootloader_callback (egc, bl, rc); } +static int tst_blfd; +static void tst_sigh (int dummy) { +int r, e = errno; +int p[2 ]; +write (2 ,"tst_sigh\n" ,9 ); + r =pipe (p);assert (!r); +close (p[1 ]); +if (getenv ("TST_EXTRADUP" ))dup (tst_blfd); +dup2 (p[0 ], tst_blfd); +close (p[0 ]); + errno = e; +} +static void bootloader_gotptys (libxl__egc *egc,libxl__openpty_state *op) {libxl__bootloader_state *bl =CONTAINER_OF (op, *bl, openpty);
@@ -503,6 +516,9 @@ static void bootloader_gotptys(libxl__egc *egc, libxl__openpty_state *op)int bootloader_master =libxl__carefd_fd (bl->ptys[0 ].master);int xenconsole_master =libxl__carefd_fd (bl->ptys[1 ].master); +tst_blfd = bootloader_master; +signal (SIGUSR2 ,tst_sigh); +libxl_fd_set_nonblock (CTX , bootloader_master,1 );libxl_fd_set_nonblock (CTX , xenconsole_master,1 );
Signature · 1 line
1.7.2.5
PATCH v4 9/11 libxl: remus: mark TODOs more clearly
In reply to Ian JacksonChange the TODOs in the remus code to "REMUS TODO" which will make them easier to grep for later. AIUI all of these are essential for use of remus in production.
Also add a new TODO and a new assert, to check rc on entry to remus_checkpoint_dm_saved.
--- tools/libxl/libxl_dom.c | 9 +++++---- 1 files changed, 5 insertions(+), 4 deletions(-)
tools/libxl/libxl_dom.c +5 -4
@@ -1110,7 +1110,7 @@ int libxl__toolstack_save(uint32_t domid, uint8_t **buf,static int libxl__remus_domain_suspend_callback (void *data) { -/* TODO: Issue disk and network checkpoint reqs. */ +/* REMUS TODO: Issue disk and network checkpoint reqs. */ return libxl__domain_suspend_common_callback (data); }
@@ -1124,7 +1124,7 @@ static int libxl__remus_domain_resume_callback(void *data)if (libxl_domain_resume (CTX , dss->domid,/* Fast Suspend */ 1 ))return 0 ; -/* TODO: Deal with disk. Start a new network output buffer */ +/* REMUS TODO: Deal with disk. Start a new network output buffer */ return 1 ; }
@@ -1151,8 +1151,9 @@ static void libxl__remus_domain_checkpoint_callback(void *data)static void remus_checkpoint_dm_saved (libxl__egc *egc,libxl__domain_suspend_state *dss,int rc) { -/* TODO: Wait for disk and memory ack, release network buffer */ -/* TODO: make this asynchronous */ +/* REMUS TODO: Wait for disk and memory ack, release network buffer */ +/* REMUS TODO: make this asynchronous */ +assert (!rc);/* REMUS TODO handle this error properly */ usleep (dss->interval *1000 );libxl__xc_domain_saverestore_async_callback_done (egc, &dss->shs,1 ); }
Signature · 1 line
1.7.2.5
Re: [PATCH 09/11] libxl: remus: mark TODOs more clearly
Quoted 6 lines · Ian Jackson
Change the TODOs in the remus code to "REMUS TODO" which will make them easier to grep for later. AIUI all of these are essential for use of remus in production.
Also add a new TODO and a new assert, to check rc on entry to
remus_checkpoint_dm_saved.
CCing Shriram in the hops of getting some actual code here (for 4.3 most likely).
Quoted 2 lines
Signed-off-by Ian Jackson <[email protected]>
Quoted 38 lines
--- tools/libxl/libxl_dom.c | 9 +++++---- 1 files changed, 5 insertions(+), 4 deletions(-)tools/libxl/libxl_dom.c +5
-4@@ -1110,7 +1110,7 @@ int libxl__toolstack_save(uint32_t domid, uint8_t **buf,static int libxl__remus_domain_suspend_callback (void *data) { -/* TODO: Issue disk and network checkpoint reqs. */ +/* REMUS TODO: Issue disk and network checkpoint reqs. */ return libxl__domain_suspend_common_callback (data); }@@ -1124,7 +1124,7 @@ static int libxl__remus_domain_resume_callback(void *data)if (libxl_domain_resume (CTX , dss->domid,/* Fast Suspend */ 1 ))return 0 ; -/* TODO: Deal with disk. Start a new network output buffer */ +/* REMUS TODO: Deal with disk. Start a new network output buffer */ return 1 ; }@@ -1151,8 +1151,9 @@ static void libxl__remus_domain_checkpoint_callback(void *data)static void remus_checkpoint_dm_saved (libxl__egc *egc,libxl__domain_suspend_state *dss,int rc) { -/* TODO: Wait for disk and memory ack, release network buffer */ -/* TODO: make this asynchronous */ +/* REMUS TODO: Wait for disk and memory ack, release network buffer */ +/* REMUS TODO: make this asynchronous */ +assert (!rc);/* REMUS TODO handle this error properly */ usleep (dss->interval *1000 );libxl__xc_domain_saverestore_async_callback_done (egc, &dss->shs,1 ); }
Re: [PATCH 09/11] libxl: remus: mark TODOs more clearly
Quoted 8 lines · Ian Campbell
Quoted 6 lines · Ian Jackson
Change the TODOs in the remus code to "REMUS TODO" which will make them easier to grep for later. AIUI all of these are essential for use of remus in production.
Also add a new TODO and a new assert, to check rc on entry to
remus_checkpoint_dm_saved.
Quoted 9 lines
CCing Shriram in the hops of getting some actual code here (for 4.3 most likely).
Quoted 2 lines
Signed-off-by Ian Jackson <[email protected]>Acked-by Ian Campbell <[email protected]>
Thanks I saw this yesterday.
shriram
Quoted 30 lines
tools/libxl/libxl_dom.c int libxl__toolstack_save(uint32_t domid, uint8_t
Quoted 9 lines
--- tools/libxl/libxl_dom.c | 9 +++++---- 1 files changed, 5 insertions(+), 4 deletions(-)tools/libxl/libxl_dom.c +0
-0@@ -1110,7 +1110,7 @@ int libxl__toolstack_save(uint32_t domid, uint8_t**buf,
tools/libxl/libxl_dom.c static int
Quoted 9 lines
tools/libxl/libxl_dom.c +1
-1static int libxl__remus_domain_suspend_callback (void *data) { -/* TODO: Issue disk and network checkpoint reqs. */ +/* REMUS TODO: Issue disk and network checkpoint reqs. */ return libxl__domain_suspend_common_callback (data); }@@ -1124,7 +1124,7 @@ static int
libxl__remus_domain_resume_callback(void *data)tools/libxl/libxl_dom.c static void
Quoted 9 lines
tools/libxl/libxl_dom.c +1
-1if (libxl_domain_resume (CTX , dss->domid,/* Fast Suspend */ 1 ))return 0 ; -/* TODO: Deal with disk. Start a new network output buffer */ +/* REMUS TODO: Deal with disk. Start a new network output buffer */ return 1 ; }@@ -1151,8 +1151,9 @@ static void
libxl__remus_domain_checkpoint_callback(void *data)
Quoted 16 lines
tools/libxl/libxl_dom.c static void · line 1152
Quoted 2 lines
tools/libxl/libxl_dom.c +0
-0static void remus_checkpoint_dm_saved(libxl__egc *egc, libxl__domain_suspend_state *dss,int rc)
tools/libxl/libxl_dom.c static void libxl__remus_domain_checkpoint_callback(void *data)
Quoted 4 lines
tools/libxl/libxl_dom.c +1
-2{ -/* TODO: Wait for disk and memory ack, release network buffer */ -/* TODO: make this asynchronous */ +/* REMUS TODO: Wait for disk and memory ack, release network buffer */
Quoted 5 lines
tools/libxl/libxl_dom.c +2
-0+/* REMUS TODO: make this asynchronous */ +assert (!rc);/* REMUS TODO handle this error properly */ usleep (dss->interval *1000 );libxl__xc_domain_saverestore_async_callback_done (egc, &dss->shs,1 ); }
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
PATCH v4 10/11 libxl: remove an unused numainfo parameter
In reply to Ian Jackson--- tools/libxl/libxl_numa.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
tools/libxl/libxl_numa.c +2 -2
@@ -231,7 +231,7 @@ static int nodemap_to_nr_vcpus(libxl__gc *gc, libxl_cputopology *tinfo,* candidates with just one node). */ static int count_cpus_per_node (libxl_cputopology *tinfo,int nr_cpus, -libxl_numainfo *ninfo,int nr_nodes) +int nr_nodes) {int cpus_per_node =0 ;int j, i;
@@ -340,7 +340,7 @@ int libxl__get_numa_candidate(libxl__gc *gc,if (!min_nodes) {int cpus_per_node; - cpus_per_node =count_cpus_per_node (tinfo, nr_cpus, ninfo, nr_nodes); + cpus_per_node =count_cpus_per_node (tinfo, nr_cpus, nr_nodes);if (cpus_per_node ==0 ) min_nodes =1 ;else
Signature · 1 line
1.7.2.5
Re: [PATCH 10/11] libxl: remove an unused numainfo parameter
Quoted 1 line · Ian Jackson
Signed-off-by Ian Jackson <[email protected]>
CCing Dario.
Quoted 26 lines
--- tools/libxl/libxl_numa.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)tools/libxl/libxl_numa.c +2
-2@@ -231,7 +231,7 @@ static int nodemap_to_nr_vcpus(libxl__gc *gc, libxl_cputopology *tinfo,* candidates with just one node). */ static int count_cpus_per_node (libxl_cputopology *tinfo,int nr_cpus, -libxl_numainfo *ninfo,int nr_nodes) +int nr_nodes) {int cpus_per_node =0 ;int j, i;@@ -340,7 +340,7 @@ int libxl__get_numa_candidate(libxl__gc *gc,if (!min_nodes) {int cpus_per_node; - cpus_per_node =count_cpus_per_node (tinfo, nr_cpus, ninfo, nr_nodes); + cpus_per_node =count_cpus_per_node (tinfo, nr_cpus, nr_nodes);if (cpus_per_node ==0 ) min_nodes =1 ;else
Dario Faggioli
Acked-byRe: [PATCH 10/11] libxl: remove an unused numainfo parameter
Quoted 7 lines · Ian Campbell
Quoted 1 line · Ian Jackson
Signed-off-by Ian Jackson <[email protected]>Acked-by Ian Campbell <[email protected]>CCing Dario.
Uups, sorry, I guess it was a stale from a previous version I forgot to kill. Thanks!
Signature · 4 lines
<<This happens because I choose it to happen!>> (Raistlin Majere) ----------------------------------------------------------------- Dario Faggioli, Ph.D, http://retis.sssup.it/people/faggioli Senior Software Engineer, Citrix Systems R&D Ltd., Cambridge (UK)
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
PATCH v4 11/11 libxl: -Wunused-parameter
In reply to Ian Jackson*** DO NOT APPLY ***
We have recently had a couple of bugs which basically involved ignoring the rc parameter to a callback function. I thought I would try -Wunused-parameter. Here are the results.
I found three further problems:
* libxl_wait_for_free_memory takes a domid parameter but its semantics don't seem to call for that. This function is going to have a big warning put on it for 4.2 and that should happen soon.
* qmp_synchronous_send has an `ask_timeout' parameter which is ignored.
* The autogenerated function libxl_event_init_type ignores the type parameter.
Things I needed to do to get the rest of the code to compile:
* Remove one harmless unused parameter from an internal function. (Earlier in this series.)
* Add an assert to make the error handling in the broken remus code slightly less broken. (Earlier in this series.)
* Provide machinery in the Makefile for passing different CFLAGS to libxl as opposed to xl and libxlu. The flex- and bison-generated files in libxlu can't be compiled with -Wunused-parameter.
* Define a new helper macro
#define USE(var) ((void)(var))
and use it 43 times. The pattern is something like
USE(egc);in a function which takes egc but doesn't need it. If the parameter is later used, this is harmless. In functions which are placeholders the USE statement should be placed in the middle of the function where the parameter would be used if the function is changed later, so that the USE gets deleted by the patch introducing the implementation.
* Define a new helper macro for use only in other macros
#define MAYBE_UNUSED __attribute__((unused))
and use it in 10 different places.
* Define new macros for helping declare common types of callback functions. For example:
#define EV_XSWATCH_CALLBACK_PARAMS(egc, watch, wpath, epath) \
libxl__egc *egc MAYBE_UNUSED, \
libxl__ev_xswatch *watch MAYBE_UNUSED, \
const char *wpath MAYBE_UNUSED, \ const char *epath MAYBE_UNUSED
which is used like this:
-static void some_callback(libxl__egc *egc, libxl__ev_xswatch *watch,
- const char *wpath, const char *epath)
+static void some_callback(EV_XSWATCH_CALLBACK_PARAMS
+ (egc, watch, wpath, epath))
{
... now we use (or not) egc, watch, wpath, etc. or not as we like
This somewhat resembles a Traditional K&R C typeless function definition. The types of the parameters are actually defined for the compiler of course, along with the information that the parameters might be unused.
There are 4 macros of this kind with 22 call sites.
IMO on the cost (65 places in ordinary code where we have to write something somewhat ugly) is worth the benefit (finding, if we had deployed this right away, around 6 bugs). But it's arguable.
*** DO NOT APPLY ***
Anyway, this patch must not be applied right now because it causes the build to fail.
--- tools/libxl/Makefile | 4 +++- tools/libxl/libxl.c | 29 +++++++++++++++++++++++++---- tools/libxl/libxl_aoutils.c | 8 ++++---- tools/libxl/libxl_blktap2.c | 1 + tools/libxl/libxl_bootloader.c | 6 ++++++ tools/libxl/libxl_create.c | 2 ++ tools/libxl/libxl_device.c | 9 +++++---- tools/libxl/libxl_dm.c | 4 ++++ tools/libxl/libxl_dom.c | 8 ++++---- tools/libxl/libxl_event.c | 22 +++++++++++++--------- tools/libxl/libxl_exec.c | 8 ++++---- tools/libxl/libxl_fork.c | 1 + tools/libxl/libxl_internal.h | 24 ++++++++++++++++++++++-- tools/libxl/libxl_pci.c | 6 ++++++ tools/libxl/libxl_qmp.c | 17 +++++++++-------- tools/libxl/libxl_save_callout.c | 4 ++-- tools/libxl/libxl_utils.c | 2 ++ 17 files changed, 113 insertions(+), 42 deletions(-)
tools/libxl/Makefile +3 -1
@@ -13,6 +13,8 @@ XLUMINOR = 0 CFLAGS += -Werror -Wno-format-zero-length -Wmissing-declarations \ -Wno-declaration-after-statement -Wformat-nonliteral +CFLAGS_FOR_LIBXL = -Wunused-parameter + CFLAGS += -I. -fPIC ifeq ($(CONFIG_Linux),y)
@@ -71,7 +73,7 @@ LIBXL_OBJS = flexarray.o libxl.o libxl_create.o libxl_dm.o libxl_pci.o \ libxl_qmp.o libxl_event.o libxl_fork.o $(LIBXL_OBJS-y) LIBXL_OBJS += _libxl_types.o libxl_flask.o _libxl_types_internal.o -$(LIBXL_OBJS): CFLAGS += $(CFLAGS_libxenctrl) $(CFLAGS_libxenguest) $(CFLAGS_libxenstore) $(CFLAGS_libblktapctl) -include $(XEN_ROOT)/tools/config.h +$(LIBXL_OBJS): CFLAGS += $(CFLAGS_FOR_LIBXL) $(CFLAGS_libxenctrl) $(CFLAGS_libxenguest) $(CFLAGS_libxenstore) $(CFLAGS_libblktapctl) -include $(XEN_ROOT)/tools/config.h AUTOINCS= libxlu_cfg_y.h libxlu_cfg_l.h _libxl_list.h _paths.h \ _libxl_save_msgs_callout.h _libxl_save_msgs_helper.h
tools/libxl/libxl.c +25 -4
@@ -28,6 +28,8 @@ int libxl_ctx_alloc(libxl_ctx **pctx, int version,struct stat stat_buf;int rc; +USE (flags); +if (version !=LIBXL_VERSION ) { rc =ERROR_VERSION ; goto out; } ctx =malloc (sizeof (*ctx));
@@ -700,6 +702,8 @@ int libxl_domain_remus_start(libxl_ctx *ctx, libxl_domain_remus_info *info,libxl__domain_suspend_state *dss;int rc; +USE (recv_fd);/* TODO get rid of this and actually use it! */ +libxl_domain_type type =libxl__domain_type (gc, domid);if (type ==LIBXL_DOMAIN_TYPE_INVALID ) { rc =ERROR_FAIL ;
@@ -979,8 +983,9 @@ static void domain_death_occurred(libxl__egc *egc,LIBXL_TAILQ_INSERT_HEAD (&CTX ->death_reported, evg, entry); } -static void domain_death_xswatch_callback (libxl__egc *egc,libxl__ev_xswatch *w, -const char *wpath,const char *epath) { +static void domain_death_xswatch_callback (EV_XSWATCH_CALLBACK_PARAMS + (egc ,watch ,wpath ,epath )) +{EGC_GC ;libxl_evgen_domain_death *evg;uint32_t domid;
@@ -1137,8 +1142,9 @@ void libxl_evdisable_domain_death(libxl_ctx *ctx,GC_FREE ; } -static void disk_eject_xswatch_callback (libxl__egc *egc,libxl__ev_xswatch *w, -const char *wpath,const char *epath) { +static void disk_eject_xswatch_callback (EV_XSWATCH_CALLBACK_PARAMS + (egc ,w ,wpath ,epath )) +{EGC_GC ;libxl_evgen_disk_eject *evg = (void *)w;char *backend;
@@ -2524,6 +2530,8 @@ static int libxl__device_from_nic(libxl__gc *gc, uint32_t domid, libxl_device_nic *nic, libxl__device *device) { +USE (gc); + device->backend_devid = nic->devid; device->backend_domid = nic->backend_domid; device->backend_kind =LIBXL__DEVICE_KIND_VIF ;
@@ -2902,6 +2910,9 @@ out:int libxl__device_vkb_setdefault (libxl__gc *gc,libxl_device_vkb *vkb) { +USE (gc); + +USE (vkb);return 0 ; }
@@ -2909,6 +2920,7 @@ static int libxl__device_from_vkb(libxl__gc *gc, uint32_t domid, libxl_device_vkb *vkb, libxl__device *device) { +USE (gc); device->backend_devid = vkb->devid; device->backend_domid = vkb->backend_domid; device->backend_kind =LIBXL__DEVICE_KIND_VKBD ;
@@ -2990,6 +3002,7 @@ out:int libxl__device_vfb_setdefault (libxl__gc *gc,libxl_device_vfb *vfb) { +USE (gc);libxl_defbool_setdefault (&vfb->vnc.enable, true);if (libxl_defbool_val (vfb->vnc.enable)) {if (!vfb->vnc.listen) {
@@ -3010,6 +3023,7 @@ static int libxl__device_from_vfb(libxl__gc *gc, uint32_t domid, libxl_device_vfb *vfb, libxl__device *device) { +USE (gc); device->backend_devid = vfb->devid; device->backend_domid = vfb->backend_domid; device->backend_kind =LIBXL__DEVICE_KIND_VFB ;
@@ -3936,8 +3950,13 @@ libxl_scheduler libxl_get_scheduler(libxl_ctx *ctx)static int sched_arinc653_domain_set (libxl__gc *gc,uint32_t domid,const libxl_domain_sched_params *scinfo) { +USE (gc); +/* Currently, the ARINC 653 scheduler does not take any domain-specific configuration, so we simply return success. */ +USE (domid); +USE (scinfo); +return 0 ; }
@@ -4385,6 +4404,8 @@ int libxl_xen_console_read_line(libxl_ctx *ctx,void libxl_xen_console_read_finish (libxl_ctx *ctx,libxl_xen_console_reader *cr) { +USE (ctx); +free (cr->buffer);free (cr); }
tools/libxl/libxl_aoutils.c +4 -4
@@ -114,8 +114,8 @@ static int datacopier_pollhup_handled(libxl__egc *egc,return 0 ; } -static void datacopier_readable (libxl__egc *egc,libxl__ev_fd *ev, -int fd,short events,short revents) { +static void datacopier_readable (EV_FD_CALLBACK_PARAMS + (egc ,ev ,fd ,events ,revents )) {libxl__datacopier_state *dc =CONTAINER_OF (ev, *dc, toread);STATE_AO_GC (dc->ao);
@@ -178,8 +178,8 @@ static void datacopier_readable(libxl__egc *egc, libxl__ev_fd *ev,datacopier_check_state (egc, dc); } -static void datacopier_writable (libxl__egc *egc,libxl__ev_fd *ev, -int fd,short events,short revents) { +static void datacopier_writable (EV_FD_CALLBACK_PARAMS ( +egc ,ev ,fd ,events ,revents )) {libxl__datacopier_state *dc =CONTAINER_OF (ev, *dc, towrite);STATE_AO_GC (dc->ao);
tools/libxl/libxl_blktap2.c +1 -0
@@ -19,6 +19,7 @@int libxl__blktap_enabled (libxl__gc *gc) { +USE (gc);const char *msg;return !tap_ctl_check (&msg); }
tools/libxl/libxl_bootloader.c +6 -0
@@ -88,6 +88,7 @@ static void make_bootloader_args(libxl__gc *gc, libxl__bootloader_state *bl,static int setup_xenconsoled_pty (libxl__egc *egc,libxl__bootloader_state *bl,char *slave_path,size_t slave_path_len) { +USE (egc);STATE_AO_GC (bl->ao);struct termios termattr;int r, rc;
@@ -141,6 +142,7 @@ static const char *bootloader_result_command(libxl__gc *gc, const char *buf,static int parse_bootloader_result (libxl__egc *egc,libxl__bootloader_state *bl) { +USE (egc);STATE_AO_GC (bl->ao);char buf[PATH_MAX *2 ];FILE *f =0 ;
@@ -221,6 +223,7 @@ void libxl__bootloader_init(libxl__bootloader_state *bl)static void bootloader_cleanup (libxl__egc *egc,libxl__bootloader_state *bl) { +USE (egc);STATE_AO_GC (bl->ao);int i;
@@ -256,6 +259,8 @@ static void bootloader_local_detached_cb(libxl__egc *egc,static void bootloader_callback (libxl__egc *egc,libxl__bootloader_state *bl,int rc) { +USE (egc); +if (!bl->rc) bl->rc = rc;
@@ -285,6 +290,7 @@ static void bootloader_local_detached_cb(libxl__egc *egc,static void bootloader_stop (libxl__egc *egc,libxl__bootloader_state *bl,int rc) { +USE (egc);STATE_AO_GC (bl->ao);int r;
tools/libxl/libxl_create.c +2 -0
@@ -62,6 +62,8 @@ void libxl_domain_config_dispose(libxl_domain_config *d_config)int libxl__domain_create_info_setdefault (libxl__gc *gc,libxl_domain_create_info *c_info) { +USE (gc); +if (!c_info->type)return ERROR_INVAL ;
tools/libxl/libxl_device.c +5 -4
@@ -44,6 +44,8 @@ int libxl__parse_backend_path(libxl__gc *gc,const char *path, libxl__device *dev) { +USE (gc ); +/* /local/domain/<domid>/backend/<kind>/<domid>/<devid> */ char strkind[16 ];/* Longest is actually "console" */ int rc = sscanf(path, "/local/domain/%d/backend/%15[^/]/%u/%d",
@@ -795,8 +797,7 @@ out:return ; } -static void device_qemu_timeout (libxl__egc *egc,libxl__ev_time *ev, -const struct timeval *requested_abs) +static void device_qemu_timeout (EV_TIME_CALLBACK_PARAMS (egc ,ev ,requested_abs )) {libxl__ao_device *aodev =CONTAINER_OF (ev, *aodev, timeout);STATE_AO_GC (aodev->ao);
@@ -918,8 +919,8 @@ out:return ; } -static void device_hotplug_timeout_cb (libxl__egc *egc,libxl__ev_time *ev, -const struct timeval *requested_abs) +static void device_hotplug_timeout_cb (EV_TIME_CALLBACK_PARAMS + (egc ,ev ,requested_abs )) {libxl__ao_device *aodev =CONTAINER_OF (ev, *aodev, timeout);STATE_AO_GC (aodev->ao);
tools/libxl/libxl_dm.c +4 -0
@@ -640,6 +640,7 @@ static int libxl__vfb_and_vkb_from_hvm_guest_config(libxl__gc *gc, libxl_device_vfb *vfb, libxl_device_vkb *vkb) { +USE (gc);const libxl_domain_build_info *b_info = &guest_config->b_info;if (b_info->type !=LIBXL_DOMAIN_TYPE_HVM )
@@ -1177,6 +1178,7 @@ static void device_model_confirm(libxl__egc *egc, libxl__spawn_state *spawn, {libxl__dm_spawn_state *dmss =CONTAINER_OF (spawn, *dmss, spawn);STATE_AO_GC (spawn->ao); +USE (egc);if (!xsdata)return ;
@@ -1262,6 +1264,7 @@ int libxl__need_xenpv_qemu(libxl__gc *gc, int nr_vfbs, libxl_device_vfb *vfbs, int nr_disks, libxl_device_disk *disks) { +USE (gc );int i, ret =0 ;/*
@@ -1283,6 +1286,7 @@ int libxl__need_xenpv_qemu(libxl__gc *gc, }if (nr_vfbs >0 ) { +USE (vfbs); ret =1 ; goto out; }
tools/libxl/libxl_dom.c +4 -4
@@ -756,8 +756,8 @@ void libxl__domain_suspend_common_switch_qemu_logdirtyswitch_logdirty_done (egc,dss,-1 ); } -static void switch_logdirty_timeout (libxl__egc *egc,libxl__ev_time *ev, -const struct timeval *requested_abs) +static void switch_logdirty_timeout (EV_TIME_CALLBACK_PARAMS + (egc ,ev ,requested_abs )) {libxl__domain_suspend_state *dss =CONTAINER_OF (ev, *dss, logdirty.timeout);STATE_AO_GC (dss->ao);
@@ -765,8 +765,8 @@ static void switch_logdirty_timeout(libxl__egc *egc, libxl__ev_time *ev,switch_logdirty_done (egc,dss,-1 ); } -static void switch_logdirty_xswatch (libxl__egc *egc,libxl__ev_xswatch *watch, -const char *watch_path,const char *event_path) +static void switch_logdirty_xswatch (EV_XSWATCH_CALLBACK_PARAMS + (egc ,watch ,wpath ,epath )) {libxl__domain_suspend_state *dss =CONTAINER_OF (watch, *dss, logdirty.watch);
tools/libxl/libxl_event.c +13 -9
@@ -197,6 +197,8 @@ static void time_done_debug(libxl__gc *gc, const char *func,"ev_time=%p done rc=%d .func=%p infinite=%d abs=%lu.%06lu" , ev, rc, ev->func, ev->infinite, (unsigned long)ev->abs.tv_sec, (unsigned long)ev->abs.tv_usec); +#else +USE (gc);USE (func);USE (ev);USE (rc);#endif }
@@ -381,8 +383,7 @@ static void libxl__set_watch_slot_contents(libxl__ev_watch_slot *slot, slot->empty.sle_next = (void *)w; } -static void watchfd_callback (libxl__egc *egc,libxl__ev_fd *ev, -int fd,short events,short revents) +static void watchfd_callback (EV_FD_CALLBACK_PARAMS (egc ,ev ,fd ,events ,revents )) {EGC_GC ;
@@ -571,8 +572,8 @@ void libxl__ev_xswatch_deregister(libxl__gc *gc, libxl__ev_xswatch *w)* waiting for device state */ -static void devstate_watch_callback (libxl__egc *egc,libxl__ev_xswatch *watch, -const char *watch_path,const char *event_path) +static void devstate_watch_callback (EV_XSWATCH_CALLBACK_PARAMS + (egc ,watch ,watch_path ,event_path )) {EGC_GC ;libxl__ev_devstate *ds =CONTAINER_OF (watch, *ds, watch);
@@ -605,8 +606,7 @@ static void devstate_watch_callback(libxl__egc *egc, libxl__ev_xswatch *watch, ds->callback (egc, ds, rc); } -static void devstate_timeout (libxl__egc *egc,libxl__ev_time *ev, -const struct timeval *requested_abs) +static void devstate_timeout (EV_TIME_CALLBACK_PARAMS (egc ,ev ,requested_abs )) {EGC_GC ;libxl__ev_devstate *ds =CONTAINER_OF (ev, *ds, timeout);
@@ -662,8 +662,8 @@ int libxl__ev_devstate_wait(libxl__gc *gc, libxl__ev_devstate *ds,* futile. */ -static void domaindeathcheck_callback (libxl__egc *egc,libxl__ev_xswatch *w, -const char *watch_path,const char *event_path) +static void domaindeathcheck_callback (EV_XSWATCH_CALLBACK_PARAMS + (egc ,w ,watch_path ,event_path )) {libxl__domaindeathcheck *dc =CONTAINER_OF (w, *dc, watch);EGC_GC ;
@@ -1019,6 +1019,7 @@ void libxl_osevent_occurred_fd(libxl_ctx *ctx, void *for_libxl,assert (fd == ev->fd); revents &= ev->events; +USE (events);/* we use our own idea of what we asked for */ if (revents) ev->func (egc, ev, fd, ev->events, revents);
@@ -1151,6 +1152,8 @@ void libxl__event_occurred(libxl__egc *egc, libxl_event *event)void libxl_event_free (libxl_ctx *ctx,libxl_event *event) { +USE (ctx); +/* Exceptionally, this function may be called from libxl, with ctx==0 */ libxl_event_dispose (event);free (event);
@@ -1645,7 +1648,8 @@ int libxl__ao_inprogress(libxl__ao *ao,* for how. But we want to copy *how. So we have this dummy function * whose address is stored in callback if the app passed how==NULL. */ static void dummy_asyncprogress_callback_ignore - (libxl_ctx *ctx,libxl_event *ev,void *for_callback) { } + (libxl_ctx *ctx,libxl_event *ev,void *for_callback) + {USE (ctx);USE (ev);USE (for_callback); }void libxl__ao_progress_gethow (libxl_asyncprogress_how *in_state,const libxl_asyncprogress_how *from_app) {
tools/libxl/libxl_exec.c +4 -4
@@ -280,6 +280,7 @@ void libxl__spawn_init(libxl__spawn_state *ss)int libxl__spawn_spawn (libxl__egc *egc,libxl__spawn_state *ss) { +USE (egc);STATE_AO_GC (ss->ao);int r;pid_t child;
@@ -387,8 +388,7 @@ static void spawn_fail(libxl__egc *egc, libxl__spawn_state *ss)spawn_detach (gc, ss); } -static void spawn_timeout (libxl__egc *egc,libxl__ev_time *ev, -const struct timeval *requested_abs) +static void spawn_timeout (EV_TIME_CALLBACK_PARAMS (egc ,ev ,requested_abs )) {/* Before event, was Attached. */ EGC_GC ;
@@ -397,8 +397,8 @@ static void spawn_timeout(libxl__egc *egc, libxl__ev_time *ev,spawn_fail (egc, ss);/* must be last */ } -static void spawn_watch_event (libxl__egc *egc,libxl__ev_xswatch *xsw, -const char *watch_path,const char *event_path) +static void spawn_watch_event (EV_XSWATCH_CALLBACK_PARAMS + (egc ,xsw ,wpath ,epath )) {/* On entry, is Attached. */ EGC_GC ;
tools/libxl/libxl_fork.c +1 -0
@@ -157,6 +157,7 @@ int libxl__carefd_fd(const libxl__carefd *cf)static void sigchld_handler (int signo) { +USE (signo);int e =libxl__self_pipe_wakeup (sigchld_owner->sigchld_selfpipe[1 ]);assert (!e);/* errors are probably EBADF, very bad */ }
tools/libxl/libxl_internal.h +22 -2
@@ -95,6 +95,8 @@#define DISABLE_UDEV_PATH "libxl/disable_udev"#define ARRAY_SIZE (a) (sizeof(a) / sizeof(a[0])) +#define USE (var) ((void)(var)) +#define MAYBE_UNUSED __attribute__((unused))#define LIBXL__LOGGING_ENABLED
@@ -147,6 +149,14 @@ typedef void libxl__ev_fd_callback(libxl__egc *egc, libxl__ev_fd *ev,* It is not permitted to listen for the same or overlapping events * on the same fd using multiple different libxl__ev_fd's. */ + +/* Declare your callback functions with this helper and you avoid unused +* parameter warnings (and don't have to list all the types either): */ +#define EV_FD_CALLBACK_PARAMS (egc, ev, fd, events, revents) \ + libxl__egc *egc MAYBE_UNUSED, libxl__ev_fd *ev MAYBE_UNUSED, \ + int fd MAYBE_UNUSED, \ + short events MAYBE_UNUSED, short revents MAYBE_UNUSED +struct libxl__ev_fd {/* caller should include this in their own struct */ /* read-only for caller, who may read only when registered: */
@@ -162,6 +172,11 @@ struct libxl__ev_fd {typedef struct libxl__ev_time libxl__ev_time ;typedef void libxl__ev_time_callback (libxl__egc *egc,libxl__ev_time *ev,const struct timeval *requested_abs); + +#define EV_TIME_CALLBACK_PARAMS (egc, ev, requested_abs) \ + libxl__egc *egc MAYBE_UNUSED, libxl__ev_time *ev MAYBE_UNUSED, \ + const struct timeval *requested_abs MAYBE_UNUSED +struct libxl__ev_time {/* caller should include this in their own struct */ /* read-only for caller, who may read only when registered: */
@@ -174,8 +189,13 @@ struct libxl__ev_time { };typedef struct libxl__ev_xswatch libxl__ev_xswatch ; -typedef void libxl__ev_xswatch_callback (libxl__egc *egc,libxl__ev_xswatch *, -const char *watch_path,const char *event_path); +typedef void libxl__ev_xswatch_callback (libxl__egc *egc, +libxl__ev_xswatch *watch,const char *watch_path,const char *event_path); + +#define EV_XSWATCH_CALLBACK_PARAMS (egc, watch, wpath, epath) \ + libxl__egc *egc MAYBE_UNUSED, libxl__ev_xswatch *watch MAYBE_UNUSED, \ + const char *wpath MAYBE_UNUSED, const char *epath MAYBE_UNUSED +struct libxl__ev_xswatch {/* caller should include this in their own struct */ /* read-only for caller, who may read only when registered: */
tools/libxl/libxl_pci.c +6 -0
@@ -800,6 +800,10 @@ static int pci_ins_check(libxl__gc *gc, uint32_t domid, const char *state, void {char *orig_state = priv; +USE (gc); +USE (domid); +USE (priv); +if ( !strcmp (state,"pci-insert-failed" ) )return -1 ;if ( !strcmp (state,"pci-inserted" ) )
@@ -1007,6 +1011,8 @@ static int libxl__device_pci_reset(libxl__gc *gc, unsigned int domain, unsignedint libxl__device_pci_setdefault (libxl__gc *gc,libxl_device_pci *pci) { +USE (gc); +USE (pci);return 0 ; }
tools/libxl/libxl_qmp.c +9 -8
@@ -46,6 +46,10 @@typedef int (*qmp_callback_t )(libxl__qmp_handler *qmp,const libxl__json_object *tree,void *opaque); +#define QMP_CALLBACK_PARAMS (qmp, tree, opaque) \ + libxl__qmp_handler *qmp MAYBE_UNUSED, \ + const libxl__json_object *tree MAYBE_UNUSED, \ + void *opaque MAYBE_UNUSED typedef struct qmp_request_context { int rc;
@@ -109,9 +113,7 @@ static int store_serial_port_info(libxl__qmp_handler *qmp,return ret; } -static int register_serials_chardev_callback (libxl__qmp_handler *qmp, -const libxl__json_object *o, -void *unused) +static int register_serials_chardev_callback (QMP_CALLBACK_PARAMS (qmp ,o ,unused )) {const libxl__json_object *obj =NULL ;const libxl__json_object *label =NULL ;
@@ -165,9 +167,7 @@ static int qmp_write_domain_console_item(libxl__gc *gc, int domid,return libxl__xs_write (gc,XBT_NULL , path,"%s" , value); } -static int qmp_register_vnc_callback (libxl__qmp_handler *qmp, -const libxl__json_object *o, -void *unused) +static int qmp_register_vnc_callback (QMP_CALLBACK_PARAMS (qmp ,o ,unused )) {GC_INIT (qmp->ctx);const libxl__json_object *obj;
@@ -203,8 +203,7 @@ out:return rc; } -static int qmp_capabilities_callback (libxl__qmp_handler *qmp, -const libxl__json_object *o,void *unused) +static int qmp_capabilities_callback (QMP_CALLBACK_PARAMS (qmp ,o ,unused )) { qmp->connected = true;
@@ -228,6 +227,8 @@ static int enable_qmp_capabilities(libxl__qmp_handler *qmp)static libxl__qmp_message_type qmp_response_type (libxl__qmp_handler *qmp,const libxl__json_object *o) { +USE (qmp); +libxl__qmp_message_type type;libxl__json_map_node *node =NULL ;int i =0 ;
tools/libxl/libxl_save_callout.c +2 -2
@@ -252,8 +252,8 @@ static void helper_failed(libxl__egc *egc, libxl__save_helper_state *shs, (unsigned long)shs->child.pid); } -static void helper_stdout_readable (libxl__egc *egc,libxl__ev_fd *ev, -int fd,short events,short revents) +static void helper_stdout_readable (EV_FD_CALLBACK_PARAMS + (egc ,ev ,fd ,events ,revents )) {libxl__save_helper_state *shs =CONTAINER_OF (ev, *shs, readable);STATE_AO_GC (shs->ao);
tools/libxl/libxl_utils.c +2 -0
@@ -230,6 +230,7 @@ out:int libxl_string_to_backend (libxl_ctx *ctx,char *s,libxl_disk_backend *backend) { +USE (ctx);char *p;int rc =0 ;
@@ -513,6 +514,7 @@ void libxl_bitmap_dispose(libxl_bitmap *map)void libxl_bitmap_copy (libxl_ctx *ctx,libxl_bitmap *dptr,const libxl_bitmap *sptr) { +USE (ctx);int sz;assert (dptr->size == sptr->size);
Signature · 1 line
1.7.2.5
Re: [PATCH 11/11] libxl: -Wunused-parameter
Quoted 3 lines · Ian Jackson
* The autogenerated function
libxl_event_init_typeignores the type parameter.
Your wish etc...
8<------------------------------------------
# HG changeset patch
# User Ian Campbell <[email protected]>
# Date 1343897835 -3600
# Node ID 5bbb555747204f9b1926741416f79ab6b8b02361
# Parent 5feb45a76581091bd267eecccb078afb91db0b8c
libxl: idl: always initialise the KeyedEnum keyvar in the member init function
Previously we only initialised it if an explicit keyvar_init_val was given but not if the default was implicitly 0.
In the generated code this only changes the unused libxl_event_init_type function:
void libxl_event_init_type(libxl_event *p, libxl_event_type type) {
+ assert(!p->type);
+ p->type = type;
switch (p->type) {
case LIBXL_EVENT_TYPE_DOMAIN_SHUTDOWN:
break;However I think it is wrong that this function is unused, this and libxl_event_init should be used by libxl__event_new. As it happens both are just memset to zero but for correctness we should use the init functions (in case the IDL changes).
In the generator we also need to properly handle init_var == 0 which the current if statements incorrectly treat as False. This doesn't actually have any impact on the generated code.
tools/libxl/gentypes.py +7 -4
@@ -162,17 +162,20 @@ def libxl_C_type_member_init(ty, field): ku.keyvar.type.make_arg(ku.keyvar.name)) s += "{\n" - if ku.keyvar.init_val: + if ku.keyvar.init_val is not None: init_val = ku.keyvar.init_val - elif ku.keyvar.type.init_val: + elif ku.keyvar.type.init_val is not None: init_val = ku.keyvar.type.init_val else: init_val = None + (nparent,fexpr) = ty.member(ty.pass_arg("p"), ku.keyvar, isref=True) if init_val is not None: - (nparent,fexpr) = ty.member(ty.pass_arg("p"), ku.keyvar, isref=True) s += " assert(%s == %s);\n" % (fexpr, init_val) - s += " %s = %s;\n" % (fexpr, ku.keyvar.name) + else: + s += " assert(!%s);\n" % (fexpr) + s += " %s = %s;\n" % (fexpr, ku.keyvar.name) + (nparent,fexpr) = ty.member(ty.pass_arg("p"), field, isref=True) s += _libxl_C_type_init(ku, fexpr, parent=nparent, subinit=True) s += "}\n"
tools/libxl/libxl_event.c +4 -1
@@ -1163,7 +1163,10 @@ libxl_event *libxl__event_new(libxl__egclibxl_event *ev; ev =libxl__zalloc (NOGC ,sizeof (*ev)); - ev->type = type; + +libxl_event_init (ev); +libxl_event_init_type (ev, type); + ev->domid = domid;return ev;
Ian Jackson
Acked-byRe: [PATCH 11/11] libxl: -Wunused-parameter
Ian Campbell writes ("Re: [PATCH 11/11] libxl: -Wunused-parameter"):
Quoted 1 line
libxl: idl: always initialise the KeyedEnum keyvar in the member init function
Thanks.
I have incorporated this into my series.
Ian.
Re: [PATCH 11/11] libxl: -Wunused-parameter
In reply to Ian JacksonQuoted 93 lines · Ian Jackson
*** DO NOT APPLY ***
We have recently had a couple of bugs which basically involved ignoring the rc parameter to a callback function. I thought I would try -Wunused-parameter. Here are the results.
I found three further problems:
*
libxl_wait_for_free_memorytakes a domid parameter but its semantics don't seem to call for that. This function is going to have a big warning put on it for 4.2 and that should happen soon.*
qmp_synchronous_sendhas an `ask_timeout' parameter which is ignored.* The autogenerated function
libxl_event_init_typeignores the type parameter.Things I needed to do to get the rest of the code to compile:
* Remove one harmless unused parameter from an internal function. (Earlier in this series.)
* Add an assert to make the error handling in the broken remus code slightly less broken. (Earlier in this series.)
* Provide machinery in the
Makefilefor passing different CFLAGS to libxl as opposed to xl and libxlu. The flex- and bison-generated files in libxlu can't be compiled with -Wunused-parameter.* Define a new helper macro
#define USE(var) ((void)(var)) and use it 43 times. The pattern is something like USE(egc);in a function which takes egc but doesn't need it. If the parameter is later used, this is harmless. In functions which are placeholders the USE statement should be placed in the middle of the function where the parameter would be used if the function is changed later, so that the USE gets deleted by the patch introducing the implementation.
* Define a new helper macro for use only in other macros
#define MAYBE_UNUSED __attribute__((unused))and use it in 10 different places.
* Define new macros for helping declare common types of callback functions. For example:
#define EV_XSWATCH_CALLBACK_PARAMS(egc, watch, wpath, epath) \ libxl__egc *egc MAYBE_UNUSED, \ libxl__ev_xswatch *watch MAYBE_UNUSED, \ const char *wpath MAYBE_UNUSED, \const char *epath
MAYBE_UNUSEDwhich is used like this:
-static void some_callback(libxl__egc *egc,
libxl__ev_xswatch*watch,
- const char *wpath, const char *epath)
+static void some_callback(EV_XSWATCH_CALLBACK_PARAMS
+ (egc, watch, wpath, epath))
{
... now we use (or not) egc, watch, wpath, etc. or not as we likeThis somewhat resembles a Traditional K&R C typeless function definition. The types of the parameters are actually defined for the compiler of course, along with the information that the parameters might be unused.
There are 4 macros of this kind with 22 call sites.
IMO on the cost (65 places in ordinary code where we have to write something somewhat ugly) is worth the benefit (finding, if we had deployed this right away, around 6 bugs). But it's arguable.
*** DO NOT APPLY ***
Anyway, this patch must not be applied right now because it causes the build to fail.
Signed-off-by Ian Jackson <[email protected]>Cc Ian Campbell <[email protected]>--- tools/libxl/Makefile | 4 +++- tools/libxl/libxl.c | 29 +++++++++++++++++++++++++---- tools/libxl/libxl_aoutils.c | 8 ++++---- tools/libxl/libxl_blktap2.c | 1 + tools/libxl/libxl_bootloader.c | 6 ++++++ tools/libxl/libxl_create.c | 2 ++ tools/libxl/libxl_device.c | 9 +++++---- tools/libxl/libxl_dm.c | 4 ++++ tools/libxl/libxl_dom.c | 8 ++++---- tools/libxl/libxl_event.c | 22 +++++++++++++---------
Quoted 8 lines
tools/libxl/libxl_exec.c | 8 ++++---- tools/libxl/libxl_fork.c | 1 + tools/libxl/libxl_internal.h | 24 ++++++++++++++++++++++-- tools/libxl/libxl_pci.c | 6 ++++++ tools/libxl/libxl_qmp.c | 17 +++++++++-------- tools/libxl/libxl_save_callout.c | 4 ++-- tools/libxl/libxl_utils.c | 2 ++ 17 files changed, 113 insertions(+), 42 deletions(-)
I'm not entirely sure how I feel about this patch generally (it's quite a bit of mess, but the bugs it would have found are real). It's also quite a lot of churn for 4.2.
On the other hand we are likely to want to backport lots of libxl fixes for 4.2.1 (I was actually considering an exception to the "no new features" rule for 4.2.1 for xm parity causing patches) and having this in 4.2 would make that cleaner.
I guess I come down (just) on the side of taking this, when it is baked.
tools/libxl/libxl.c int libxl_domain_remus_start(libxl_ctx *ctx, libxl_domain_remus_info *info, · line 705
Quoted 5 lines
tools/libxl/libxl.c +1
-0@@ -700,6 +702,8 @@ int libxl_domain_remus_start(libxl_ctx *ctx, libxl_domain_remus_info *info,libxl__domain_suspend_state *dss;int rc; +USE (recv_fd);/* TODO get rid of this and actually use it! */
You've only just introduced TODO REMUS...
tools/libxl/libxl_event.c void libxl_osevent_occurred_fd(libxl_ctx *ctx, void *for_libxl, · line 1022
Quoted 5 lines
tools/libxl/libxl_event.c +1
-0@@ -1019,6 +1019,7 @@ void libxl_osevent_occurred_fd(libxl_ctx *ctx, void *for_libxl,assert (fd == ev->fd); revents &= ev->events; +USE (events);/* we use our own idea of what we asked for */
What is the point of this argument then?
Is getting an event we weren't expecting a log-worthy occurrence?
tools/libxl/libxl_pci.c static int pci_ins_check(libxl__gc *gc, uint32_t domid, const char *state, void · line 805
Quoted 11 lines
tools/libxl/libxl_pci.c +3
-0@@ -800,6 +800,10 @@ static int pci_ins_check(libxl__gc *gc, uint32_t domid, const char *state, void {char *orig_state = priv; +USE (gc); +USE (domid); +USE (priv);
You actually use priv above.
Ian.
Re: [PATCH 11/11] libxl: -Wunused-parameter
Ian Campbell writes ("Re: [PATCH 11/11] libxl: -Wunused-parameter"):
Quoted 3 lines
I'm not entirely sure how I feel about this patch generally (it's quite a bit of mess, but the bugs it would have found are real). It's also quite a lot of churn for 4.2.
Yes.
Quoted 4 lines
On the other hand we are likely to want to backport lots of libxl fixes for 4.2.1 (I was actually considering an exception to the "no new features" rule for 4.2.1 for xm parity causing patches) and having this in 4.2 would make that cleaner.
Indeed.
Quoted 1 line
I guess I come down (just) on the side of taking this, when it is baked.
OK. Having slept on it I think overall this is an improvement and will help us in the future.
Quoted 7 lines
tools/libxl/libxl.c int libxl_domain_remus_start(libxl_ctx *ctx, libxl_domain_remus_info *info, · line 705
Quoted 5 lines
tools/libxl/libxl.c +1
-0@@ -700,6 +702,8 @@ int libxl_domain_remus_start(libxl_ctx *ctx, libxl_domain_remus_info *info,libxl__domain_suspend_state *dss;int rc; +USE (recv_fd);/* TODO get rid of this and actually use it! */ You've only just introduced TODO REMUS...
Point.
Quoted 7 lines
tools/libxl/libxl_event.c void libxl_osevent_occurred_fd(libxl_ctx *ctx, void *for_libxl, · line 1022
Quoted 5 lines
tools/libxl/libxl_event.c +1
-0@@ -1019,6 +1019,7 @@ void libxl_osevent_occurred_fd(libxl_ctx *ctx, void *for_libxl,assert (fd == ev->fd); revents &= ev->events; +USE (events);/* we use our own idea of what we asked for */ What is the point of this argument then?
It's there for consistency with poll(2)'s API.
Quoted 1 line
Is getting an event we weren't expecting a log-worthy occurrence?
events might be different from those we requested because events might be "in flight" from the application's call to poll, to us, while we register/deregister them. So this is not a logworthy event. I guess this property of the registration API is not documented and should be (although it amounts only to a relaxation from the point of view of the application).
Also I found a mistake in a related comment so I will fix these comments in another patch.
Quoted 8 lines
Quoted 8 lines
tools/libxl/libxl_pci.c +0
-0@@ -800,6 +800,10 @@ static int pci_ins_check(libxl__gc *gc, uint32_t domid, const char *state, void {char *orig_state = priv;
Quoted 5 lines
tools/libxl/libxl_pci.c static int pci_ins_check(libxl__gc *gc, uint32_t domid, const char *state, void · line 805
Quoted 3 lines
tools/libxl/libxl_pci.c +3
-0+USE (gc); +USE (domid); +USE (priv);You actually use priv above.
Fixed.
Ian.