From mboxrd@z Thu Jan 1 00:00:00 1970 From: Wei Liu Subject: [PATCH v2 12/18] libxl: synchronise configuration when we remove/destroy a device Date: Wed, 30 Jul 2014 19:23:53 +0100 Message-ID: <1406744639-28782-13-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 Xenstore is updated first, JSON is updated later, so that we maintain the same invariant as previous commit: any device which is present in xenstore has an entry in JSON. Signed-off-by: Wei Liu --- tools/libxl/libxl.c | 28 ++++++++++++++++++++++------ tools/libxl/libxl_internal.h | 2 ++ tools/libxl/libxl_pci.c | 15 +++++++++++++++ 3 files changed, 39 insertions(+), 6 deletions(-) diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c index 184e126..430a45f 100644 --- a/tools/libxl/libxl.c +++ b/tools/libxl/libxl.c @@ -3654,7 +3654,7 @@ out: } /******************************************************************************/ -#define DEFINE_DEVICE_RM_AOCOMPLETE(type) \ +#define DEFINE_DEVICE_RM_AOCOMPLETE(type, compare) \ static void device_##type##_rm_aocomplete(libxl__egc *egc, \ libxl__ao_device *aodev) \ { \ @@ -3662,6 +3662,21 @@ out: if (aodev->rc) { \ DEVICE_AO_FAILED_MSG; \ goto out; \ + } else { \ + libxl__carefd *lock; \ + \ + lock = libxl__lock_domain_data(gc, aodev->dev->domid); \ + if (!lock) { \ + aodev->rc = ERROR_LOCK_FAIL; \ + goto out; \ + } \ + \ + aodev->rc = DEVICE_REMOVE_JSON(type, type##s, \ + num_##type##s, \ + aodev->dev->domid, \ + aodev->pdev, compare); \ + \ + libxl__unlock_domain_data(lock); \ } \ \ out: \ @@ -3675,11 +3690,11 @@ out: * 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); +DEFINE_DEVICE_RM_AOCOMPLETE(vtpm, COMPARE_DEVID); +DEFINE_DEVICE_RM_AOCOMPLETE(nic, COMPARE_DEVID); +DEFINE_DEVICE_RM_AOCOMPLETE(disk, COMPARE_DISK); +DEFINE_DEVICE_RM_AOCOMPLETE(vfb, COMPARE_DEVID); +DEFINE_DEVICE_RM_AOCOMPLETE(vkb, COMPARE_DEVID); /* Macro for defining device remove/destroy functions in a compact way */ /* The following functions are defined: @@ -3710,6 +3725,7 @@ DEFINE_DEVICE_RM_AOCOMPLETE(vkb); \ GCNEW(aodev); \ libxl__prepare_ao_device(ao, aodev); \ + aodev->pdev = type; \ aodev->action = LIBXL__DEVICE_ACTION_REMOVE; \ aodev->dev = device; \ aodev->callback = device_##type##_rm_aocomplete; \ diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h index a5eb7d4..eeeffdb 100644 --- a/tools/libxl/libxl_internal.h +++ b/tools/libxl/libxl_internal.h @@ -2146,6 +2146,8 @@ struct libxl__ao_device { libxl__async_exec_state aes; /* If we need to udpate JSON config */ bool update_json; + /* point to libxl_device_TYPE */ + void *pdev; }; /* diff --git a/tools/libxl/libxl_pci.c b/tools/libxl/libxl_pci.c index 357e274..9ad1f19 100644 --- a/tools/libxl/libxl_pci.c +++ b/tools/libxl/libxl_pci.c @@ -1372,6 +1372,21 @@ int libxl_device_pci_remove(libxl_ctx *ctx, uint32_t domid, rc = libxl__device_pci_remove_common(gc, domid, pcidev, 0); + if (!rc) { + libxl__carefd *lock; + + lock = libxl__lock_domain_data(gc, domid); + if (!lock) { + rc = ERROR_LOCK_FAIL; + goto out; + } + + rc = DEVICE_REMOVE_JSON(pci, pcidevs, num_pcidevs, domid, + pcidev, COMPARE_PCI); + + libxl__unlock_domain_data(lock); + } +out: libxl__ao_complete(egc, ao, rc); return AO_INPROGRESS; } -- 1.7.10.4