From mboxrd@z Thu Jan 1 00:00:00 1970 From: Wei Liu Subject: [PATCH v2 07/18] libxl: separate device add/rm complete callbacks Date: Wed, 30 Jul 2014 19:23:48 +0100 Message-ID: <1406744639-28782-8-git-send-email-wei.liu2@citrix.com> References: <1406744639-28782-1-git-send-email-wei.liu2@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1406744639-28782-1-git-send-email-wei.liu2@citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel@lists.xen.org Cc: Wei Liu , ian.jackson@eu.citrix.com, ian.campbell@citrix.com List-Id: xen-devel@lists.xenproject.org This is in preparation for device hotplug / unplug configuration synchronisation. No functional change introduced. This change is necessary because rm is type specific, using a single callback cannot meet our need. Signed-off-by: Wei Liu --- tools/libxl/libxl.c | 54 +++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 42 insertions(+), 12 deletions(-) diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c index 9ac2c3d..01dffa0 100644 --- a/tools/libxl/libxl.c +++ b/tools/libxl/libxl.c @@ -1798,22 +1798,26 @@ out: } /******************************************************************************/ +#define DEVICE_AO_FAILED_MSG \ + do { \ + if (aodev->dev) { \ + LOG(ERROR, "unable to %s %s with id %u", \ + libxl__device_action_to_string(aodev->action), \ + libxl__device_kind_to_string(aodev->dev->kind), \ + aodev->dev->devid); \ + } else { \ + LOG(ERROR, "unable to %s device", \ + libxl__device_action_to_string(aodev->action)); \ + } \ + } while (0) /* generic callback for devices that only need to set ao_complete */ -static void device_addrm_aocomplete(libxl__egc *egc, libxl__ao_device *aodev) +static void device_add_aocomplete(libxl__egc *egc, libxl__ao_device *aodev) { STATE_AO_GC(aodev->ao); if (aodev->rc) { - if (aodev->dev) { - LOG(ERROR, "unable to %s %s with id %u", - libxl__device_action_to_string(aodev->action), - libxl__device_kind_to_string(aodev->dev->kind), - aodev->dev->devid); - } else { - LOG(ERROR, "unable to %s device", - libxl__device_action_to_string(aodev->action)); - } + DEVICE_AO_FAILED_MSG; goto out; } @@ -3537,6 +3541,32 @@ out: } /******************************************************************************/ +#define DEFINE_DEVICE_RM_AOCOMPLETE(type) \ + static void device_##type##_rm_aocomplete(libxl__egc *egc, \ + libxl__ao_device *aodev) \ + { \ + STATE_AO_GC(aodev->ao); \ + if (aodev->rc) { \ + DEVICE_AO_FAILED_MSG; \ + goto out; \ + } \ + \ + out: \ + libxl__ao_complete(egc, ao, aodev->rc); \ + } + +/* + * device_vtpm_rm_aocomplete + * device_nic_rm_aocomplete + * device_disk_rm_aocomplete + * device_vfb_rm_aocomplete + * device_vkb_rm_aocomplete + */ +DEFINE_DEVICE_RM_AOCOMPLETE(vtpm); +DEFINE_DEVICE_RM_AOCOMPLETE(nic); +DEFINE_DEVICE_RM_AOCOMPLETE(disk); +DEFINE_DEVICE_RM_AOCOMPLETE(vfb); +DEFINE_DEVICE_RM_AOCOMPLETE(vkb); /* Macro for defining device remove/destroy functions in a compact way */ /* The following functions are defined: @@ -3569,7 +3599,7 @@ out: libxl__prepare_ao_device(ao, aodev); \ aodev->action = LIBXL__DEVICE_ACTION_REMOVE; \ aodev->dev = device; \ - aodev->callback = device_addrm_aocomplete; \ + aodev->callback = device_##type##_rm_aocomplete; \ aodev->force = f; \ libxl__initiate_device_remove(egc, aodev); \ \ @@ -3622,7 +3652,7 @@ DEFINE_DEVICE_REMOVE(vtpm, destroy, 1) \ GCNEW(aodev); \ libxl__prepare_ao_device(ao, aodev); \ - aodev->callback = device_addrm_aocomplete; \ + aodev->callback = device_add_aocomplete; \ libxl__device_##type##_add(egc, domid, type, aodev); \ \ return AO_INPROGRESS; \ -- 1.7.10.4