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

[Xen-devel] [PATCH v2 12/18] libxl: synchronise configuration when we remove/destroy a device



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 <wei.liu2@xxxxxxxxxx>
---
 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


_______________________________________________
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®.