From mboxrd@z Thu Jan 1 00:00:00 1970 From: Wei Liu Subject: [PATCH v1 06/10] libxl: synchronise configuration when we remove/destroy a device Date: Thu, 10 Jul 2014 15:32:21 +0100 Message-ID: <1405002745-5034-7-git-send-email-wei.liu2@citrix.com> References: <1405002745-5034-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: <1405002745-5034-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 | 25 +++++++++++++++++++------ tools/libxl/libxl_internal.h | 2 ++ tools/libxl/libxl_pci.c | 13 +++++++++++++ 3 files changed, 34 insertions(+), 6 deletions(-) diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c index 5f9f94a..58f07d2 100644 --- a/tools/libxl/libxl.c +++ b/tools/libxl/libxl.c @@ -1822,7 +1822,7 @@ out: return; } -#define DEFINE_DEVICE_RM_AOCOMPLETE(type) \ +#define DEFINE_DEVICE_RM_AOCOMPLETE(type, ptr, cnt, compare) \ static void device_##type##_rm_aocomplete(libxl__egc *egc, \ libxl__ao_device *aodev) \ { \ @@ -1830,17 +1830,29 @@ out: if (aodev->rc) { \ DEVICE_AO_FAILED_MSG; \ goto out; \ + } else { \ + int lock = -1; \ + \ + LOCK_DOMAIN_JSON_CONFIG(gc, aodev->dev->domid, \ + lock, aodev->rc); \ + if (aodev->rc) \ + goto out; \ + \ + DEVICE_REMOVE_JSON(type, ptr, cnt, aodev->dev->domid, \ + aodev->pdev, compare, aodev->rc); \ + \ + UNLOCK_DOMAIN_JSON_CONFIG(gc, aodev->dev->domid, lock); \ } \ \ out: \ libxl__ao_complete(egc, ao, aodev->rc); \ } -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, vtpms, num_vtpms, COMPARE_DEVID); +DEFINE_DEVICE_RM_AOCOMPLETE(nic, nics, num_nics, COMPARE_DEVID); +DEFINE_DEVICE_RM_AOCOMPLETE(disk, disks, num_disks, COMPARE_DISK); +DEFINE_DEVICE_RM_AOCOMPLETE(vfb, vfbs, num_vfbs, COMPARE_DEVID); +DEFINE_DEVICE_RM_AOCOMPLETE(vkb, vkbs, num_vkbs, COMPARE_DEVID); /* common function to get next device id */ static int libxl__device_nextid(libxl__gc *gc, uint32_t domid, char *device) @@ -3677,6 +3689,7 @@ out: \ 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 f27a6e98..b4f518a 100644 --- a/tools/libxl/libxl_internal.h +++ b/tools/libxl/libxl_internal.h @@ -2131,6 +2131,8 @@ struct libxl__ao_device { int num_exec; /* for calling hotplug scripts */ libxl__async_exec_state aes; + /* point to libxl_device_TYPE */ + void *pdev; }; /* diff --git a/tools/libxl/libxl_pci.c b/tools/libxl/libxl_pci.c index d0d8f90..cab3a1b 100644 --- a/tools/libxl/libxl_pci.c +++ b/tools/libxl/libxl_pci.c @@ -1349,6 +1349,19 @@ int libxl_device_pci_remove(libxl_ctx *ctx, uint32_t domid, rc = libxl__device_pci_remove_common(gc, domid, pcidev, 0); + if (!rc) { + int lock = -1; + + LOCK_DOMAIN_JSON_CONFIG(gc, domid, lock, rc); + if (rc) + goto out; + + DEVICE_REMOVE_JSON(pci, pcidevs, num_pcidevs, domid, + pcidev, COMPARE_PCI, rc); + + UNLOCK_DOMAIN_JSON_CONFIG(gc, domid, lock); + } +out: libxl__ao_complete(egc, ao, rc); return AO_INPROGRESS; } -- 1.7.10.4