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

[Minios-devel] [UNIKRAFT PATCH v3 09/10] plat/xen: Add driver state functions to client API


  • To: minios-devel@xxxxxxxxxxxxx
  • From: Costin Lupu <costin.lupu@xxxxxxxxx>
  • Date: Mon, 10 Sep 2018 12:06:01 +0300
  • Cc: simon.kuenzer@xxxxxxxxx, yuri.volchkov@xxxxxxxxx
  • Delivery-date: Mon, 10 Sep 2018 09:06:22 +0000
  • Ironport-phdr: 9a23:Y4/f7hDzGKpMdQcLqZ51UyQJP3N1i/DPJgcQr6AfoPdwSPT9r8bcNUDSrc9gkEXOFd2Cra4c1KyO6+jJYi8p2d65qncMcZhBBVcuqP49uEgeOvODElDxN/XwbiY3T4xoXV5h+GynYwAOQJ6tL1LdrWev4jEMBx7xKRR6JvjvGo7Vks+7y/2+94fcbglUhjexe69+IAmrpgjNq8cahpdvJLwswRXTuHtIfOpWxWJsJV2Nmhv3+9m98p1+/SlOovwt78FPX7n0cKQ+VrxYES8pM3sp683xtBnMVhWA630BWWgLiBVIAgzF7BbnXpfttybxq+Rw1DWGMcDwULs5Xymp4aV2Rx/ykCoJNyA3/nzZhMJzi6xUohyhqgdjz4LIeoyZKOBzcr/Bcd4cWGFPXtxRVytEAo6kcYYPCPEBPfpZr4n7ulAAqwa+BRGxBOjyzTJHmnj23bYm0+QgFwHKxgggH88WsHTJt9j6KLwSXfqtzKnV1jrPdelW2TDk5YXObxsvoumMUKptfcfe1EUjDQDIg1WKpYD7IT+Y1P4BvmaD4+Z9Wu+jlnQrpgJxrzS12MshhIfEipgIxl3L6yl0xps+K8eiR05he9GkFYNdtySdN4RrXMwvW3pouCMmyr0evp67YTQKxIwnxxHBb/yHdJCF4gzmVOmLIDd4gGhpd66khxqo6Uig1/bzWtOu0FZNtiZFk9/MuW4R1xHL98SKReZx8l2i1DuPzQzf9P9ILEIumafVM5Ihx6Q/lpsXsUTNBC/2n0D2gbeKeUUj4eio9+XnYrP8qp+YKo90khz+P78ylcykG+g4KhUOUHOB9eSm073v5Vf5T6lSjv0qjqnZt4jXJcEapq6/Ag9V1Z0j5w+iADi4ztQXg30HIUlBeBKGlIjpJ0rOLOr3DPihhVSgijBrx+rJPrf5GJXCMmDDkKv9fbZ680Nc0wszzdVY55JSEL0BI+/zVVH3tN3ZEBA5KRe5w+D5B9ph0oMRQ3mADrWHP6PPqVWI/P4gI/GQZI8JvzbwM/gk5+P0jX84g1MdY66p3Z8LZ3C4HfRmJFuZbGHqgtgfDWgKuhAxQ/fwhFKcTD4AL0q1Cqc94DA8E8eqAJnOQqipgaedx2GrE5sQYXpJWX6WFnK9XIKfR/YKIAaPOtIpxjcDTqSgTcklyAmznAThjaJ6JKzO/XtL5trYyNFp6riLxlkJ/jtuApHF3g==
  • 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 |  36 +++++++++++++
 plat/xen/xenbus/client.c         | 107 +++++++++++++++++++++++++++++++++++++++
 plat/xen/xenbus/exportsyms.uk    |   3 ++
 3 files changed, 146 insertions(+)

diff --git a/plat/xen/include/xenbus/client.h b/plat/xen/include/xenbus/client.h
index f3540b7..2add3be 100644
--- a/plat/xen/include/xenbus/client.h
+++ b/plat/xen/include/xenbus/client.h
@@ -86,4 +86,40 @@ int xenbus_watch_wait_event(struct xenbus_watch *watch);
  */
 int xenbus_watch_notify_event(struct xenbus_watch *watch);
 
+/*
+ * Driver states
+ */
+
+/*
+ * Returns the driver state found at the given Xenstore path.
+ *
+ * @param path Xenstore path
+ * @return The Xenbus driver state
+ */
+XenbusState xenbus_read_driver_state(const char *path);
+
+/*
+ * Changes the state of a Xen PV driver
+ *
+ * @param xendev Xenbus device
+ * @param state The new Xenbus state
+ * @param xbt Xenbus transaction id
+ * @return 0 on success, a negative errno value on error.
+ */
+int xenbus_switch_state(struct xenbus_device *xendev, XenbusState state,
+       xenbus_transaction_t xbt);
+
+/*
+ * 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 3dbca0f..d901222 100644
--- a/plat/xen/xenbus/client.c
+++ b/plat/xen/xenbus/client.c
@@ -44,6 +44,7 @@
 #include <string.h>
 #include <uk/errptr.h>
 #include <uk/wait.h>
+#include <xenbus/xs.h>
 #include <xenbus/client.h>
 
 
@@ -130,3 +131,109 @@ int xenbus_watch_notify_event(struct xenbus_watch *watch)
 
        return 0;
 }
+
+XenbusState xenbus_read_driver_state(const char *path)
+{
+       char state_path[strlen(path) + sizeof("/state")];
+       XenbusState state = XenbusStateUnknown;
+
+       sprintf(state_path, "%s/state", path);
+       xs_read_integer(XBT_NIL, state_path, (int *) &state);
+
+       return state;
+}
+
+int xenbus_switch_state(struct xenbus_device *xendev, XenbusState state,
+               xenbus_transaction_t xbt)
+{
+       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 695a01a..8436a7a 100644
--- a/plat/xen/xenbus/exportsyms.uk
+++ b/plat/xen/xenbus/exportsyms.uk
@@ -28,4 +28,7 @@ xenbus_devtype_to_str
 xenbus_str_to_devtype
 xenbus_watch_wait_event
 xenbus_watch_notify_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®.