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

[Xen-changelog] [xen master] libxl: add config update callback to device type framework



commit 9f3fbaff6cccdab9122e8c987fa5694f0930d7f4
Author:     Juergen Gross <jgross@xxxxxxxx>
AuthorDate: Tue Jul 12 17:30:43 2016 +0200
Commit:     Wei Liu <wei.liu2@xxxxxxxxxx>
CommitDate: Wed Jul 27 12:30:10 2016 +0100

    libxl: add config update callback to device type framework
    
    Some device types require a configuration update after resume of
    domain. Add a callback for this purpose.
    
    Signed-off-by: Juergen Gross <jgross@xxxxxxxx>
    Acked-by: Wei Liu <wei.liu2@xxxxxxxxxx>
---
 tools/libxl/libxl.c          | 17 ++++++++++++++++-
 tools/libxl/libxl_internal.c | 21 ++++++++++++++-------
 tools/libxl/libxl_internal.h | 17 +----------------
 tools/libxl/libxl_vtpm.c     | 16 +++++++++++++++-
 4 files changed, 46 insertions(+), 25 deletions(-)

diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c
index ecc0906..3ce8ec3 100644
--- a/tools/libxl/libxl.c
+++ b/tools/libxl/libxl.c
@@ -3147,6 +3147,14 @@ static int libxl__device_from_nic(libxl__gc *gc, 
uint32_t domid,
     return 0;
 }
 
+static void libxl__update_config_nic(libxl__gc *gc, libxl_device_nic *dst,
+                                     const libxl_device_nic *src)
+{
+    dst->devid = src->devid;
+    dst->nictype = src->nictype;
+    libxl_mac_copy(CTX, &dst->mac, &src->mac);
+}
+
 static void libxl__device_nic_add(libxl__egc *egc, uint32_t domid,
                                   libxl_device_nic *nic,
                                   libxl__ao_device *aodev)
@@ -7230,12 +7238,19 @@ static int libxl_device_nic_compare(libxl_device_nic 
*d1,
     return COMPARE_DEVID(d1, d2);
 }
 
+static void libxl_device_nic_update_config(libxl__gc *gc, void *d, void *s)
+{
+    libxl__update_config_nic(gc, d, s);
+}
+
 DEFINE_DEVICE_TYPE_STRUCT(disk,
     .merge       = libxl_device_disk_merge,
     .dm_needed   = libxl_device_disk_dm_needed,
     .skip_attach = 1
 );
-DEFINE_DEVICE_TYPE_STRUCT(nic);
+DEFINE_DEVICE_TYPE_STRUCT(nic,
+    .update_config = libxl_device_nic_update_config
+);
 
 /*
  * Local variables:
diff --git a/tools/libxl/libxl_internal.c b/tools/libxl/libxl_internal.c
index 3b30f8a..448dd61 100644
--- a/tools/libxl/libxl_internal.c
+++ b/tools/libxl/libxl_internal.c
@@ -537,15 +537,22 @@ void libxl__update_domain_configuration(libxl__gc *gc,
                                         libxl_domain_config *dst,
                                         const libxl_domain_config *src)
 {
-    int i;
+    int i, idx, num;
+    const struct libxl_device_type *dt;
+
+    for (idx = 0;; idx++) {
+        dt = device_type_tbl[idx];
+        if (!dt)
+            break;
 
-    /* update network interface information */
-    for (i = 0; i < src->num_nics; i++)
-        libxl__update_config_nic(gc, &dst->nics[i], &src->nics[i]);
+        num = *libxl__device_type_get_num(dt, src);
+        if (!dt->update_config || !num)
+            continue;
 
-    /* update vtpm information */
-    for (i = 0; i < src->num_vtpms; i++)
-        libxl__update_config_vtpm(gc, &dst->vtpms[i], &src->vtpms[i]);
+        for (i = 0; i < num; i++)
+            dt->update_config(gc, libxl__device_type_get_elem(dt, dst, i),
+                                  libxl__device_type_get_elem(dt, src, i));
+    }
 
     /* update guest UUID */
     libxl_uuid_copy(CTX, &dst->c_info.uuid, &src->c_info.uuid);
diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h
index 30b6e1e..cdc23e2 100644
--- a/tools/libxl/libxl_internal.h
+++ b/tools/libxl/libxl_internal.h
@@ -3451,6 +3451,7 @@ struct libxl_device_type {
     int (*compare)(void *, void *);
     void (*merge)(libxl_ctx *, void *, void *);
     int (*dm_needed)(void *, unsigned);
+    void (*update_config)(libxl__gc *, void *, void *);
 };
 
 #define DEFINE_DEVICE_TYPE_STRUCT_X(name, sname, ...)                          
\
@@ -4192,22 +4193,6 @@ int libxl__set_domain_configuration(libxl__gc *gc, 
uint32_t domid,
 void libxl__update_domain_configuration(libxl__gc *gc,
                                         libxl_domain_config *dst,
                                         const libxl_domain_config *src);
-static inline void libxl__update_config_nic(libxl__gc *gc,
-                                            libxl_device_nic *dst,
-                                            const libxl_device_nic *src)
-{
-    dst->devid = src->devid;
-    dst->nictype = src->nictype;
-    libxl_mac_copy(CTX, &dst->mac, &src->mac);
-}
-
-static inline void libxl__update_config_vtpm(libxl__gc *gc,
-                                             libxl_device_vtpm *dst,
-                                             libxl_device_vtpm *src)
-{
-    dst->devid = src->devid;
-    libxl_uuid_copy(CTX, &dst->uuid, &src->uuid);
-}
 
 /* Target memory in xenstore is different from what user has
  * asked for. The difference is video_memkb + (possible) fudge.
diff --git a/tools/libxl/libxl_vtpm.c b/tools/libxl/libxl_vtpm.c
index cbbeea7..29a0817 100644
--- a/tools/libxl/libxl_vtpm.c
+++ b/tools/libxl/libxl_vtpm.c
@@ -41,6 +41,13 @@ static int libxl__device_from_vtpm(libxl__gc *gc, uint32_t 
domid,
    return 0;
 }
 
+static void libxl__update_config_vtpm(libxl__gc *gc, libxl_device_vtpm *dst,
+                                      libxl_device_vtpm *src)
+{
+    dst->devid = src->devid;
+    libxl_uuid_copy(CTX, &dst->uuid, &src->uuid);
+}
+
 static void libxl__device_vtpm_add(libxl__egc *egc, uint32_t domid,
                                    libxl_device_vtpm *vtpm,
                                    libxl__ao_device *aodev)
@@ -350,11 +357,18 @@ void libxl_device_vtpm_list_free(libxl_device_vtpm* list, 
int nr)
    free(list);
 }
 
+static void libxl_device_vtpm_update_config(libxl__gc *gc, void *d, void *s)
+{
+    libxl__update_config_vtpm(gc, d, s);
+}
+
 LIBXL_DEFINE_DEVICE_ADD(vtpm)
 static LIBXL_DEFINE_DEVICES_ADD(vtpm)
 LIBXL_DEFINE_DEVICE_REMOVE(vtpm)
 
-DEFINE_DEVICE_TYPE_STRUCT(vtpm);
+DEFINE_DEVICE_TYPE_STRUCT(vtpm,
+    .update_config = libxl_device_vtpm_update_config
+);
 
 /*
  * Local variables:
--
generated by git-patchbot for /home/xen/git/xen.git#master

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxx
https://lists.xenproject.org/xen-changelog

 


Rackspace

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