xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Juergen Gross <jgross@suse.com>
To: xen-devel@lists.xen.org
Cc: Juergen Gross <jgross@suse.com>,
	wei.liu2@citrix.com, ian.jackson@eu.citrix.com
Subject: [PATCH 2/6] libxl: add "pv device mode needed" support to device type framework
Date: Tue, 12 Jul 2016 17:30:40 +0200	[thread overview]
Message-ID: <1468337444-24108-3-git-send-email-jgross@suse.com> (raw)
In-Reply-To: <1468337444-24108-1-git-send-email-jgross@suse.com>

Add another callback to the device type framework in order to aid
decision whether a pv domain needs a device model.

Signed-off-by: Juergen Gross <jgross@suse.com>
---
 tools/libxl/libxl.c          | 14 +++++++++++++-
 tools/libxl/libxl_create.c   |  8 ++------
 tools/libxl/libxl_dm.c       | 31 +++++++++++++++++--------------
 tools/libxl/libxl_internal.h |  2 ++
 tools/libxl/libxl_pvusb.c    | 12 +++++++++++-
 5 files changed, 45 insertions(+), 22 deletions(-)

diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c
index 07b96c7..12bc0e1 100644
--- a/tools/libxl/libxl.c
+++ b/tools/libxl/libxl.c
@@ -7478,6 +7478,14 @@ static void libxl_device_disk_merge(libxl_ctx *ctx, void *d1, void *d2)
     }
 }
 
+static int libxl_device_disk_dm_needed(void *e, unsigned domid)
+{
+    libxl_device_disk *elem = e;
+
+    return elem->backend == LIBXL_DISK_BACKEND_QDISK &&
+           elem->backend_domid == domid;
+}
+
 static int libxl_device_nic_compare(libxl_device_nic *d1,
                                     libxl_device_nic *d2)
 {
@@ -7490,7 +7498,11 @@ static int libxl_device_vtpm_compare(libxl_device_vtpm *d1,
     return COMPARE_DEVID(d1, d2);
 }
 
-DEFINE_DEVICE_TYPE_STRUCT(disk, .merge = libxl_device_disk_merge);
+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(vtpm);
 
diff --git a/tools/libxl/libxl_create.c b/tools/libxl/libxl_create.c
index 40dac1a..23b82e9 100644
--- a/tools/libxl/libxl_create.c
+++ b/tools/libxl/libxl_create.c
@@ -1454,7 +1454,7 @@ static void domcreate_attach_devices(libxl__egc *egc,
     dcs->device_type_idx++;
     dt = device_type_tbl[dcs->device_type_idx];
     if (dt) {
-        if (*libxl__device_type_get_num(dt, d_config) > 0) {
+        if (*libxl__device_type_get_num(dt, d_config) > 0 && !dt->skip_attach) {
             /* Attach devices */
             libxl__multidev_begin(ao, &dcs->multidev);
             dcs->multidev.callback = domcreate_attach_devices;
@@ -1501,11 +1501,7 @@ static void domcreate_devmodel_started(libxl__egc *egc,
         }
     }
 
-    /*
-     * Setting dcs->device_type_idx to 0 will skip disks, those have been
-     * already added.
-     */
-    dcs->device_type_idx = 0;
+    dcs->device_type_idx = -1;
     domcreate_attach_devices(egc, &dcs->multidev, 0);
     return;
 
diff --git a/tools/libxl/libxl_dm.c b/tools/libxl/libxl_dm.c
index de16a59..e3bf28f 100644
--- a/tools/libxl/libxl_dm.c
+++ b/tools/libxl/libxl_dm.c
@@ -2348,8 +2348,9 @@ int libxl__destroy_device_model(libxl__gc *gc, uint32_t domid)
 /* Return 0 if no dm needed, 1 if needed and <0 if error. */
 int libxl__need_xenpv_qemu(libxl__gc *gc, libxl_domain_config *d_config)
 {
-    int i, ret;
+    int idx, i, ret, num;
     uint32_t domid;
+    const struct libxl_device_type *dt;
 
     ret = libxl__get_domid(gc, &domid);
     if (ret) {
@@ -2362,11 +2363,21 @@ int libxl__need_xenpv_qemu(libxl__gc *gc, libxl_domain_config *d_config)
         goto out;
     }
 
-    for (i = 0; i < d_config->num_disks; i++) {
-        if (d_config->disks[i].backend == LIBXL_DISK_BACKEND_QDISK &&
-            d_config->disks[i].backend_domid == domid) {
-            ret = 1;
-            goto out;
+    for (idx = 0;; idx++) {
+        dt = device_type_tbl[idx];
+        if (!dt)
+            break;
+
+        num = *libxl__device_type_get_num(dt, d_config);
+        if (!dt->dm_needed || !num)
+            continue;
+
+        for (i = 0; i < num; i++) {
+            if (dt->dm_needed(libxl__device_type_get_elem(dt, d_config, i),
+                              domid)) {
+                ret = 1;
+                goto out;
+            }
         }
     }
 
@@ -2380,14 +2391,6 @@ int libxl__need_xenpv_qemu(libxl__gc *gc, libxl_domain_config *d_config)
         }
     }
 
-    for (i = 0; i < d_config->num_usbctrls; i++) {
-       if (d_config->usbctrls[i].type == LIBXL_USBCTRL_TYPE_QUSB &&
-           d_config->usbctrls[i].backend_domid == domid) {
-            ret = 1;
-            goto out;
-        }
-    }
-
 out:
     return ret;
 }
diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h
index 1a62d6f..aea14ea 100644
--- a/tools/libxl/libxl_internal.h
+++ b/tools/libxl/libxl_internal.h
@@ -3441,6 +3441,7 @@ _hidden void libxl__bootloader_run(libxl__egc*, libxl__bootloader_state *st);
 
 struct libxl_device_type {
     char *type;
+    int skip_attach;   /* Skip entry in domcreate_attach_devices() if 1 */
     int ptr_offset;    /* Offset of device array ptr in libxl_domain_config */
     int num_offset;    /* Offset of # of devices in libxl_domain_config */
     int dev_elem_size; /* Size of one device element in array */
@@ -3450,6 +3451,7 @@ struct libxl_device_type {
     void (*dispose)(void *);
     int (*compare)(void *, void *);
     void (*merge)(libxl_ctx *, void *, void *);
+    int (*dm_needed)(void *, unsigned);
 };
 
 #define DEFINE_DEVICE_TYPE_STRUCT_X(name, sname, ...)                          \
diff --git a/tools/libxl/libxl_pvusb.c b/tools/libxl/libxl_pvusb.c
index 48a4cec..c86d0b6 100644
--- a/tools/libxl/libxl_pvusb.c
+++ b/tools/libxl/libxl_pvusb.c
@@ -1681,13 +1681,23 @@ static int libxl_device_usbctrl_compare(libxl_device_usbctrl *d1,
     return COMPARE_USBCTRL(d1, d2);
 }
 
+static int libxl_device_usbctrl_dm_needed(void *e, unsigned domid)
+{
+    libxl_device_usbctrl *elem = e;
+
+    return elem->type == LIBXL_USBCTRL_TYPE_QUSB &&
+           elem->backend_domid == domid;
+}
+
 static int libxl_device_usbdev_compare(libxl_device_usbdev *d1,
                                        libxl_device_usbdev *d2)
 {
     return COMPARE_USB(d1, d2);
 }
 
-DEFINE_DEVICE_TYPE_STRUCT(usbctrl);
+DEFINE_DEVICE_TYPE_STRUCT(usbctrl,
+    .dm_needed = libxl_device_usbctrl_dm_needed
+);
 DEFINE_DEVICE_TYPE_STRUCT(usbdev);
 
 /*
-- 
2.6.6


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

  parent reply	other threads:[~2016-07-12 15:30 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-12 15:30 [PATCH 0/6] libxl: extend device type framework Juergen Gross
2016-07-12 15:30 ` [PATCH 1/6] libxl: add "merge" function to generic device type support Juergen Gross
2016-07-25 10:45   ` Wei Liu
2017-01-19 16:14   ` Olaf Hering
2017-01-19 16:19     ` Wei Liu
2017-01-19 16:51       ` Juergen Gross
2016-07-12 15:30 ` Juergen Gross [this message]
2016-07-25 10:46   ` [PATCH 2/6] libxl: add "pv device mode needed" support to device type framework Wei Liu
2016-07-12 15:30 ` [PATCH 3/6] libxl: move library pvusb specific code into libxl_pvusb.c Juergen Gross
2016-07-25 10:46   ` Wei Liu
2016-07-12 15:30 ` [PATCH 4/6] libxl: split libxl vtpm code into one source Juergen Gross
2016-07-25 10:46   ` Wei Liu
2016-07-12 15:30 ` [PATCH 5/6] libxl: add config update callback to device type framework Juergen Gross
2016-07-25 10:46   ` Wei Liu
2016-07-12 15:30 ` [PATCH 6/6] libxl: move common nic stuff into one source Juergen Gross
2016-07-25 10:46   ` Wei Liu
2016-07-21 13:12 ` [PATCH 0/6] libxl: extend device type framework Juergen Gross
2016-07-27 11:45 ` Wei Liu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1468337444-24108-3-git-send-email-jgross@suse.com \
    --to=jgross@suse.com \
    --cc=ian.jackson@eu.citrix.com \
    --cc=wei.liu2@citrix.com \
    --cc=xen-devel@lists.xen.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).