[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [PATCH 11/11] libxl: -Wunused-parameter



*** 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.

Signed-off-by: Ian Jackson <ian.jackson@xxxxxxxxxxxxx>
Cc: Ian Campbell <Ian.Campbell@xxxxxxxxxx>
---
 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(-)

diff --git a/tools/libxl/Makefile b/tools/libxl/Makefile
index 424a7ee..7d1ebf9 100644
--- a/tools/libxl/Makefile
+++ b/tools/libxl/Makefile
@@ -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
diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c
index 00ddc0e..3ad83ea 100644
--- a/tools/libxl/libxl.c
+++ b/tools/libxl/libxl.c
@@ -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);
 }
diff --git a/tools/libxl/libxl_aoutils.c b/tools/libxl/libxl_aoutils.c
index 4bd5484..e91dc9c 100644
--- a/tools/libxl/libxl_aoutils.c
+++ b/tools/libxl/libxl_aoutils.c
@@ -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);
 
diff --git a/tools/libxl/libxl_blktap2.c b/tools/libxl/libxl_blktap2.c
index 2c40182..660a669 100644
--- a/tools/libxl/libxl_blktap2.c
+++ b/tools/libxl/libxl_blktap2.c
@@ -19,6 +19,7 @@
 
 int libxl__blktap_enabled(libxl__gc *gc)
 {
+    USE(gc);
     const char *msg;
     return !tap_ctl_check(&msg);
 }
diff --git a/tools/libxl/libxl_bootloader.c b/tools/libxl/libxl_bootloader.c
index 2e65383..bfae328 100644
--- a/tools/libxl/libxl_bootloader.c
+++ b/tools/libxl/libxl_bootloader.c
@@ -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;
 
diff --git a/tools/libxl/libxl_create.c b/tools/libxl/libxl_create.c
index 5f0d26f..5d56d67 100644
--- a/tools/libxl/libxl_create.c
+++ b/tools/libxl/libxl_create.c
@@ -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;
 
diff --git a/tools/libxl/libxl_device.c b/tools/libxl/libxl_device.c
index 84fa06c..85df199 100644
--- a/tools/libxl/libxl_device.c
+++ b/tools/libxl/libxl_device.c
@@ -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);
diff --git a/tools/libxl/libxl_dm.c b/tools/libxl/libxl_dm.c
index 0c0084f..6995306 100644
--- a/tools/libxl/libxl_dm.c
+++ b/tools/libxl/libxl_dm.c
@@ -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;
     }
diff --git a/tools/libxl/libxl_dom.c b/tools/libxl/libxl_dom.c
index 06d5e4f..4a36652 100644
--- a/tools/libxl/libxl_dom.c
+++ b/tools/libxl/libxl_dom.c
@@ -756,8 +756,8 @@ void libxl__domain_suspend_common_switch_qemu_logdirty
     switch_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);
diff --git a/tools/libxl/libxl_event.c b/tools/libxl/libxl_event.c
index 1af64c8..296303c 100644
--- a/tools/libxl/libxl_event.c
+++ b/tools/libxl/libxl_event.c
@@ -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) {
diff --git a/tools/libxl/libxl_exec.c b/tools/libxl/libxl_exec.c
index 0477386..ed6b44e 100644
--- a/tools/libxl/libxl_exec.c
+++ b/tools/libxl/libxl_exec.c
@@ -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;
diff --git a/tools/libxl/libxl_fork.c b/tools/libxl/libxl_fork.c
index 044ddad..0379604 100644
--- a/tools/libxl/libxl_fork.c
+++ b/tools/libxl/libxl_fork.c
@@ -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 */
 }
diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h
index 9315ae0..2687382 100644
--- a/tools/libxl/libxl_internal.h
+++ b/tools/libxl/libxl_internal.h
@@ -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: */
diff --git a/tools/libxl/libxl_pci.c b/tools/libxl/libxl_pci.c
index 9c92ae6..a094965 100644
--- a/tools/libxl/libxl_pci.c
+++ b/tools/libxl/libxl_pci.c
@@ -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, unsigned
 
 int libxl__device_pci_setdefault(libxl__gc *gc, libxl_device_pci *pci)
 {
+    USE(gc);
+    USE(pci);
     return 0;
 }
 
diff --git a/tools/libxl/libxl_qmp.c b/tools/libxl/libxl_qmp.c
index e33b130..c354c71 100644
--- a/tools/libxl/libxl_qmp.c
+++ b/tools/libxl/libxl_qmp.c
@@ -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;
diff --git a/tools/libxl/libxl_save_callout.c b/tools/libxl/libxl_save_callout.c
index 078b7ee..78bb67e 100644
--- a/tools/libxl/libxl_save_callout.c
+++ b/tools/libxl/libxl_save_callout.c
@@ -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);
diff --git a/tools/libxl/libxl_utils.c b/tools/libxl/libxl_utils.c
index f7b44a0..a7c34a9 100644
--- a/tools/libxl/libxl_utils.c
+++ b/tools/libxl/libxl_utils.c
@@ -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);
-- 
1.7.2.5


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.