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

[Minios-devel] [UNIKRAFT PATCH v4 7/7] plat/xen: Add driver state functions to client API


  • To: minios-devel@xxxxxxxxxxxxx
  • From: Costin Lupu <costin.lupu@xxxxxxxxx>
  • Date: Mon, 17 Sep 2018 13:32:31 +0300
  • Cc: yuri.volchkov@xxxxxxxxx
  • Delivery-date: Mon, 17 Sep 2018 10:32:46 +0000
  • Ironport-phdr: 9a23:EcGLVROfw0L8v5VCvIUl6mtUPXoX/o7sNwtQ0KIMzox0Ivz9rarrMEGX3/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/GNKX7AprRNnjDjKvhfbFl5k9c1Qoz19Ff64hKCrEGJPL8Rk/xtN/fDh8nKAG0xfjoB8l51owEQm2DGLGWML6B+WOPs+cuJeiLf8oZtSjwL9Ah5uXyljkplFlberOmjrUNb3XtNfN9P0SfKV7xmspJRWwNpRY/SqrulUWfeTVIIW6vVeQm4WdoW8qdEY7fS9X10/S61yChE8gOaw==
  • List-id: Mini-os development list <minios-devel.lists.xenproject.org>

Extend the client API with functions for dealing with Xenbus driver
states.

Signed-off-by: Costin Lupu <costin.lupu@xxxxxxxxx>
---
 plat/xen/include/xenbus/client.h | 24 ++++++++++
 plat/xen/xenbus/client.c         | 95 ++++++++++++++++++++++++++++++++++++++++
 plat/xen/xenbus/exportsyms.uk    |  2 +
 3 files changed, 121 insertions(+)

diff --git a/plat/xen/include/xenbus/client.h b/plat/xen/include/xenbus/client.h
index 8b7e8c1..a9417a9 100644
--- a/plat/xen/include/xenbus/client.h
+++ b/plat/xen/include/xenbus/client.h
@@ -98,4 +98,28 @@ int xenbus_watch_notify_event(struct xenbus_watch *watch);
  */
 XenbusState xenbus_read_driver_state(const char *path);
 
+/*
+ * Changes the state of a Xen PV driver
+ *
+ * @param xbt Xenbus transaction id
+ * @param xendev Xenbus device
+ * @param state The new Xenbus state
+ * @return 0 on success, a negative errno value on error.
+ */
+int xenbus_switch_state(xenbus_transaction_t xbt,
+       struct xenbus_device *xendev, XenbusState state);
+
+/*
+ * Waits for the driver state found at the given Xenstore path to change by
+ * using watches.
+ *
+ * @param path Xenstore path
+ * @param state The returned Xenbus state
+ * @param watch Xenbus watch. It may be NULL, in which case a local watch
+ * will be created.
+ * @return 0 on success, a negative errno value on error.
+ */
+int xenbus_wait_for_state_change(const char *path, XenbusState *state,
+       struct xenbus_watch *watch);
+
 #endif /* __XENBUS_CLIENT_H__ */
diff --git a/plat/xen/xenbus/client.c b/plat/xen/xenbus/client.c
index 274e6e7..86725e3 100644
--- a/plat/xen/xenbus/client.c
+++ b/plat/xen/xenbus/client.c
@@ -142,3 +142,98 @@ XenbusState xenbus_read_driver_state(const char *path)
 
        return state;
 }
+
+int xenbus_switch_state(xenbus_transaction_t xbt,
+       struct xenbus_device *xendev, XenbusState state)
+{
+       char state_path[strlen(xendev->nodename) + sizeof("/state")];
+       char new_state_str[2];
+       XenbusState crnt_state;
+       int need_transaction_end = 0; /* non-zero if local transaction */
+       int abort;
+       int err;
+
+       if (xendev == NULL)
+               return -EINVAL;
+
+       sprintf(state_path, "%s/state", xendev->nodename);
+
+       do {
+               abort = 1;
+
+               if (xbt == XBT_NIL) {
+                       err = xs_transaction_start(&xbt);
+                       if (err)
+                               goto exit;
+                       need_transaction_end = 1;
+               }
+
+               /* check if state is already set */
+               err = xs_read_integer(xbt, xendev->nodename,
+                       (int *) &crnt_state);
+               if (err || crnt_state == state)
+                       goto exit;
+
+               /* set new state */
+               snprintf(new_state_str, sizeof(new_state_str), "%d", state);
+               err = xs_write(xbt, state_path, NULL, new_state_str);
+
+               abort = 0;
+exit:
+               if (need_transaction_end) {
+                       int _err;
+
+                       _err = xs_transaction_end(xbt, abort);
+                       if (!err)
+                               err = _err;
+                       xbt = XBT_NIL;
+               }
+       } while (err == -EAGAIN);
+
+       if (err)
+               uk_printd(DLVL_ERR, "Error switching state to %s: %d\n",
+                       xenbus_state_to_str(state), err);
+
+       return err;
+}
+
+int xenbus_wait_for_state_change(const char *path, XenbusState *state,
+       struct xenbus_watch *watch)
+{
+       XenbusState crnt_state;
+       int err = 0, watch_is_local = 0;
+
+       if (path == NULL || state == NULL) {
+               err = -EINVAL;
+               goto out;
+       }
+
+       if (watch == NULL) {
+               /* create a local watch */
+               watch = xs_watch_path(XBT_NIL, path);
+               if (PTRISERR(watch)) {
+                       err = PTR2ERR(watch);
+                       goto out;
+               }
+               watch_is_local = 1;
+       }
+
+       for (;;) {
+               err = xs_read_integer(XBT_NIL, path, (int *) &crnt_state);
+               if (err)
+                       break;
+
+               if (crnt_state != *state) {
+                       *state = crnt_state;
+                       break;
+               }
+
+               xenbus_watch_wait_event(watch);
+       }
+
+out:
+       if (watch_is_local)
+               xs_unwatch(XBT_NIL, watch);
+
+       return err;
+}
diff --git a/plat/xen/xenbus/exportsyms.uk b/plat/xen/xenbus/exportsyms.uk
index d57a2a5..a750ff2 100644
--- a/plat/xen/xenbus/exportsyms.uk
+++ b/plat/xen/xenbus/exportsyms.uk
@@ -28,3 +28,5 @@ xenbus_devtype_to_str
 xenbus_str_to_devtype
 xenbus_watch_wait_event
 xenbus_read_driver_state
+xenbus_switch_state
+xenbus_wait_for_state_change
-- 
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®.