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

[Minios-devel] [UNIKRAFT PATCH v3 10/10] plat/xen: Add Xenbus device probing


  • To: minios-devel@xxxxxxxxxxxxx
  • From: Costin Lupu <costin.lupu@xxxxxxxxx>
  • Date: Mon, 10 Sep 2018 12:06:02 +0300
  • Cc: simon.kuenzer@xxxxxxxxx, yuri.volchkov@xxxxxxxxx
  • Delivery-date: Mon, 10 Sep 2018 09:06:22 +0000
  • Ironport-phdr: 9a23:Bqj4JBJ4fqKg8Iifr9mcpTZWNBhigK39O0sv0rFitYgeLPTxwZ3uMQTl6Ol3ixeRBMOHs60C07KempujcFRI2YyGvnEGfc4EfD4+ouJSoTYdBtWYA1bwNv/gYn9yNs1DUFh44yPzahANS47xaFLIv3K98yMZFAnhOgppPOT1HZPZg9iq2+yo9JDffwdFiCChbb9uMR67sRjfus4KjIV4N60/0AHJonxGe+RXwWNnO1eelAvi68mz4ZBu7T1et+ou+MBcX6r6eb84TaFDAzQ9L281/szrugLdQgaJ+3ART38ZkhtMAwjC8RH6QpL8uTb0u+ZhxCWXO9D9QLYpUjqg8qhrUgflhicZOTAk/m/Zict+g6BVoB+6uxBz35TZbJ2POfZiYq/Qe84RS2pbXsZWUixMGp2xb4wUD+odPOZYqZT2qV0TrRumGAmnGeTixSNPhn/twa060uIhHRvC3Aw9B9IOrW/Zo8nuNKsISeC10bLHwS/Zb/NRwDrw7pXDfBM5ofyUQL59ftfdxVMsGg7FlFmct5LpMjGP2ukDq2SX8uVtWf+1h2Mkqwx9uCajy8kih4XTm44YxU7I+CNky4gvP9K4UlR0Ydu8HZtVsCGVKpV5T9s5Q2FtpCY60roGuYOnfCQSyJQo2Rrfa/uffoiW5xLsTueRITNiiH15Y7KznQ6y8VW7xeHmTMm0105GritDktbSqnAAzwHf58eaRvdn/Uqs2SyD2x7N5uxGO0w5m7LXK5s7zb4xkpoTv17DHijzmEjukKCWcV4k+vSp6+TheLnmooKcN5dpigzlLqsugdazAfwlMgcVRWSb4+O82KX5/ULlWLVKkuE2kq7BvZDfJMQboK+5AwhO0oo69hmwESmm38ocnXQcKFJFeQmHj5TyO13UL/H3E/G/j06rkDdxyPDMJqfhDYnVLnjfjLfheq5w61VdyAo2ytBf4YhYCrIcIP3tXE/wtcLXDgUiPgyy3enoFNF92ZkFVm6VHKCZLbvYsUWU6eI3P+mMeIgVtS79Kvg4/f7ujGU1mUEafamtwZQXaHO4HvN4I0iCZ3rjnMsOEWMQsQUlVuDllkCCAnZvYCO3XqQ94Sp+BI+4AIPrQoG2nKfHzCq9WJpMaTNoEFeJRFzvbJmFXb8odTqPaptqlScYVL7nT5I5yDmlr0ni1rAhNO2CqX5Qjo7qyNUgv76brho17zEhV8k=
  • List-id: Mini-os development list <minios-devel.lists.xenproject.org>

Extend the Xenbus bus driver with support for probing Xenbus
devices.

Signed-off-by: Costin Lupu <costin.lupu@xxxxxxxxx>
Reviewed-by: Yuri Volchkov <yuri.volchkov@xxxxxxxxx>
---
 plat/xen/include/xenbus/xenbus.h |  17 ++++-
 plat/xen/xenbus/xenbus.c         | 131 ++++++++++++++++++++++++++++++++++++++-
 2 files changed, 146 insertions(+), 2 deletions(-)

diff --git a/plat/xen/include/xenbus/xenbus.h b/plat/xen/include/xenbus/xenbus.h
index 230dcd4..3d3b540 100644
--- a/plat/xen/include/xenbus/xenbus.h
+++ b/plat/xen/include/xenbus/xenbus.h
@@ -110,7 +110,22 @@ UK_TAILQ_HEAD(xenbus_watch_list, struct xenbus_watch);
  */
 
 struct xenbus_device {
-
+       /**< in use by Xenbus handler */
+       UK_TAILQ_ENTRY(struct xenbus_device) next;
+       /**< Device state */
+       XenbusState state;
+       /**< Device type */
+       enum xenbus_dev_type devtype;
+       /**< Xenstore path of the device */
+       char *nodename;
+       /**< Xenstore path of the device peer (e.g. backend for frontend) */
+       char *otherend;
+       /**< Domain id of the other end */
+       domid_t otherend_id;
+       /**< Watch for monitoring changes on other end */
+       struct xenbus_watch *otherend_watch;
+       /**< Xenbus driver */
+       struct xenbus_driver *drv;
 };
 UK_TAILQ_HEAD(xenbus_device_list, struct xenbus_device);
 
diff --git a/plat/xen/xenbus/xenbus.c b/plat/xen/xenbus/xenbus.c
index a20546b..28f0cfd 100644
--- a/plat/xen/xenbus/xenbus.c
+++ b/plat/xen/xenbus/xenbus.c
@@ -43,8 +43,12 @@
 #include <uk/errptr.h>
 #include <uk/assert.h>
 #include <xenbus/xenbus.h>
+#include <xenbus/xs.h>
+#include <xenbus/client.h>
 #include "xs_comms.h"
 
+#define XS_DEV_PATH "device"
+
 static struct xenbus_handler xbh;
 
 
@@ -67,13 +71,138 @@ void uk_xb_free(void *ptr)
        uk_free(xbh.a, ptr);
 }
 
+
+static struct xenbus_driver *xenbus_find_driver(xenbus_dev_type_t devtype)
+{
+       struct xenbus_driver *drv;
+       const xenbus_dev_type_t *pdevtype;
+
+       UK_TAILQ_FOREACH(drv, &xbh.drv_list, next) {
+               for (pdevtype = drv->device_types;
+                               *pdevtype != xenbus_dev_none; pdevtype++) {
+                       if (*pdevtype == devtype)
+                               return drv;
+               }
+       }
+
+       return NULL; /* no driver found */
+}
+
+static int xenbus_probe_device(struct xenbus_driver *drv,
+               xenbus_dev_type_t type, const char *name)
+{
+       int err;
+       struct xenbus_device *dev;
+       char *nodename = NULL;
+       XenbusState state;
+
+       /* device/type/name */
+       err = asprintf(&nodename, "%s/%s/%s",
+               XS_DEV_PATH, xenbus_devtype_to_str(type), name);
+       if (err < 0)
+               goto out;
+
+       state = xenbus_read_driver_state(nodename);
+       if (state != XenbusStateInitialising)
+               return 0;
+
+       uk_printd(DLVL_INFO, "Xenbus device: %s\n", nodename);
+
+       dev = uk_xb_calloc(1, sizeof(*dev) + strlen(nodename) + 1);
+       if (!dev) {
+               uk_printd(DLVL_ERR, "Failed to initialize: Out of memory!\n");
+               err = -ENOMEM;
+               goto out;
+       }
+
+       dev->state = XenbusStateInitialising;
+       dev->devtype = type;
+       dev->nodename = (char *) (dev + 1);
+       strcpy(dev->nodename, nodename);
+
+       err = drv->add_dev(dev);
+       if (err) {
+               uk_printd(DLVL_ERR, "Failed to add device.\n");
+               uk_xb_free(dev);
+       }
+
+out:
+       if (nodename)
+               free(nodename);
+
+       return err;
+}
+
+static int xenbus_probe_device_type(const char *devtype_str)
+{
+       struct xenbus_driver *drv;
+       xenbus_dev_type_t devtype;
+       char dirname[sizeof(XS_DEV_PATH) + strlen(devtype_str)];
+       char **devices = NULL;
+       int err = 0;
+
+       devtype = xenbus_str_to_devtype(devtype_str);
+       if (!devtype) {
+               uk_printd(DLVL_WARN,
+                       "Unsupported device type: %s\n", devtype_str);
+               goto out;
+       }
+
+       drv = xenbus_find_driver(devtype);
+       if (!drv) {
+               uk_printd(DLVL_WARN,
+                       "No driver for device type: %s\n", devtype_str);
+               goto out;
+       }
+
+       sprintf(dirname, "%s/%s", XS_DEV_PATH, devtype_str);
+
+       /* Get device list */
+       devices = xs_ls(XBT_NIL, dirname);
+       if (PTRISERR(devices)) {
+               err = PTR2ERR(devices);
+               uk_printd(DLVL_ERR,
+                       "Error reading %s devices: %d\n", devtype_str, err);
+               goto out;
+       }
+
+       for (int i = 0; devices[i] != NULL; i++) {
+               /* Probe only if no prior error */
+               if (err == 0)
+                       err = xenbus_probe_device(drv, devtype, devices[i]);
+       }
+
+out:
+       if (!PTRISERR(devices))
+               free(devices);
+
+       return err;
+}
+
 static int xenbus_probe(void)
 {
+       char **devtypes;
        int err = 0;
 
        uk_printd(DLVL_INFO, "Probe Xenbus\n");
 
-       /* TODO */
+       /* Get device types list */
+       devtypes = xs_ls(XBT_NIL, XS_DEV_PATH);
+       if (PTRISERR(devtypes)) {
+               err = PTR2ERR(devtypes);
+               uk_printd(DLVL_ERR, "Error reading device types: %d\n", err);
+               goto out;
+       }
+
+       for (int i = 0; devtypes[i] != NULL; i++) {
+               /* Probe only if no previous error */
+               if (err == 0)
+                       err = xenbus_probe_device_type(devtypes[i]);
+       }
+
+out:
+       if (!PTRISERR(devtypes))
+               free(devtypes);
 
        return err;
 }
-- 
2.11.0


_______________________________________________
Minios-devel mailing list
Minios-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/minios-devel

 


Rackspace

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