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

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


  • To: minios-devel@xxxxxxxxxxxxx
  • From: Costin Lupu <costin.lupu@xxxxxxxxx>
  • Date: Thu, 23 Aug 2018 13:59:38 +0300
  • Cc: simon.kuenzer@xxxxxxxxx, yuri.volchkov@xxxxxxxxx, sharan.santhanam@xxxxxxxxx
  • Delivery-date: Thu, 23 Aug 2018 10:59:52 +0000
  • Ironport-phdr: 9a23:BylsGhM+WSlXnbX6H1wl6mtUPXoX/o7sNwtQ0KIMzox0I//9rarrMEGX3/hxlliBBdydt6obzbKO+4nbGkU4qa6bt34DdJEeHzQksu4x2zIaPcieFEfgJ+TrZSFpVO5LVVti4m3peRMNQJW2aFLduGC94iAPERvjKwV1Ov71GonPhMiryuy+4ZLebxlKiTanfb9+MAi9oBnMuMURnYZsMLs6xAHTontPdeRWxGdoKkyWkh3h+Mq+/4Nt/jpJtf45+MFOTav1f6IjTbxFFzsmKHw65NfqtRbYUwSC4GYXX3gMnRpJBwjF6wz6Xov0vyDnuOdxxDWWMMvrRr0yRD+s7bpkSAXwhSkHKTA37W/ZhM93gq1ZrhKsvABzz5LObY2JLvdyYr/RcNUHTmRBRMZRUClBD5uiYosIFOoBIedYr4/grFUIsBu+HRSsD/7oxzBUgX/2xrE60+UnEQ3c2AwgAsoOsGnPodrpL6ceS/i1zLTTwjnZdfNW3i7w5Y7VeR4iufGBRa98fMXMxUU1FA7Ijk+cpZL7Mz6XzOgAvXCX4/dvWO6ykWIqqAF8riKxysoihITFnJ8Zx1/a+Sh/3Y07P8e3SFRhbt6hCJZQsiaaOJZoTc46WGFovTo6yqUBuZ6mYCgG0JQnyADba/yAa4WI/BfjW/yQITd8nn5qZKm/iwyq8Ui90eLwTNO00FFSoipElNnDqGwN2gTO5sWIV/dx5ESs1DaV2wzN9O1JI1o4mKTDJ54k2LEwl54TsUrZHi/xnUX7lLOZdkI/+ui06uTnZK/qppuBN49slwHzKbghmtelDeQgLwgBRHKX+f671LH75032XK1KjuEqkqneqJ3aIMUbpqi4Aw9SyYYv8guwACm40NsGmXkKN1ZFeBOcj4j1IFHCOv/5Aum5g1i2lzdr3f/GNKX7AprRNnjDjKvhfbFl5k5HyAo818pf6IhSCr0bO/L8QEnxtMDYDhAjNQy72ePnBc571owARW2PBrWWP7jIvVCW++IlO/OMa5MNuDbhN/gl4ObjjWQ4mV8Yeqmp24EbaHOlHvt4JUWYYGTjgs0aHGcMoAUxUOjqh0eZXjJJeXmyQro25isnB4K+EYfDWoetjaSB3SemBJ1WZ3pKCk6LEXfsa4qEW/QMaCWMIsJ6lDwLS6SuS4s72h61rgP11adnfaLo/XgdtJTi08Mw6+DNmBUa8T1vE9/bw2yLCWZukTAmXTgziYt4ulB8zB+nzLBly6hTEsdP5vUPVhoiKLbX1KpiFtq0QAWXLYTBc0qvXtjzWWJ5ddk22dJbO0s=
  • 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>
---
 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®.