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

[Xen-devel] [PATCH v3 05/11] libxl: add vdispl setting xen store configuration



From: Oleksandr Grytsov <oleksandr_grytsov@xxxxxxxx>

Implemet set_xenstore_config callback  for vdispl
device driver.

Signed-off-by: Oleksandr Grytsov <oleksandr_grytsov@xxxxxxxx>
---
 tools/libxl/libxl_device.c   |   2 +-
 tools/libxl/libxl_internal.h |   1 +
 tools/libxl/libxl_vdispl.c   | 117 ++++++++++++++++++++++++++++++++++++++++++-
 3 files changed, 118 insertions(+), 2 deletions(-)

diff --git a/tools/libxl/libxl_device.c b/tools/libxl/libxl_device.c
index e202503..5d7e189 100644
--- a/tools/libxl/libxl_device.c
+++ b/tools/libxl/libxl_device.c
@@ -18,7 +18,7 @@
 
 #include "libxl_internal.h"
 
-static char *libxl__device_frontend_path(libxl__gc *gc, libxl__device *device)
+char *libxl__device_frontend_path(libxl__gc *gc, libxl__device *device)
 {
     char *dom_path = libxl__xs_get_dompath(gc, device->domid);
 
diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h
index 3397655..c0dd17e 100644
--- a/tools/libxl/libxl_internal.h
+++ b/tools/libxl/libxl_internal.h
@@ -1209,6 +1209,7 @@ _hidden int libxl__device_exists(libxl__gc *gc, 
xs_transaction_t t,
                                  libxl__device *device);
 _hidden int libxl__device_generic_add(libxl__gc *gc, xs_transaction_t t,
         libxl__device *device, char **bents, char **fents, char **ro_fents);
+_hidden char *libxl__device_frontend_path(libxl__gc *gc, libxl__device 
*device);
 _hidden char *libxl__device_backend_path(libxl__gc *gc, libxl__device *device);
 _hidden char *libxl__device_libxl_path(libxl__gc *gc, libxl__device *device);
 _hidden int libxl__parse_backend_path(libxl__gc *gc, const char *path,
diff --git a/tools/libxl/libxl_vdispl.c b/tools/libxl/libxl_vdispl.c
index c79bcda..4eceb71 100644
--- a/tools/libxl/libxl_vdispl.c
+++ b/tools/libxl/libxl_vdispl.c
@@ -65,6 +65,119 @@ static void libxl__device_vdispl_add(libxl__egc *egc, 
uint32_t domid,
     libxl__device_add(egc, domid, &libxl__vdispl_devtype, vdispl, aodev);
 }
 
+static int libxl__set_xenstore_connectors(libxl__gc *gc, xs_transaction_t t,
+                                          libxl__device *device,
+                                          libxl_device_vdispl *vdispl)
+{
+    struct xs_permissions perms[2];
+    char *frontend_path = NULL;
+    flexarray_t *connector;
+    libxl_ctx *ctx = libxl__gc_owner(gc);
+    int i;
+    int rc;
+
+    frontend_path = libxl__device_frontend_path(gc, device);
+
+    perms[0].id = device->domid;
+    perms[0].perms = XS_PERM_NONE;
+    perms[1].id = device->backend_domid;
+    perms[1].perms = XS_PERM_READ;
+
+    connector = flexarray_make(gc, 2, 1);
+    flexarray_append(connector, "resolution");
+    flexarray_append(connector, "");
+    flexarray_append(connector, "id");
+    flexarray_append(connector, "");
+
+    for (i = 0; i < vdispl->num_connectors; i++) {
+        char *connector_path = GCSPRINTF("%s/%d", frontend_path, i);
+
+        if (!xs_mkdir(ctx->xsh, t, connector_path)) {
+            rc = ERROR_FAIL; goto out;
+        }
+
+        if (!xs_set_permissions(ctx->xsh, t, connector_path, perms,
+                                ARRAY_SIZE(perms))) {
+            rc = ERROR_FAIL; goto out;
+        }
+
+        flexarray_set(connector, 1,
+                      GCSPRINTF("%dx%d", vdispl->connectors[i].width,
+                                 vdispl->connectors[i].height));
+        flexarray_set(connector, 3, vdispl->connectors[i].id);
+
+        rc = libxl__xs_writev(gc, t, connector_path,
+                              libxl__xs_kvs_of_flexarray(gc, connector));
+        if (rc) goto out;
+    }
+
+    rc = 0;
+
+out:
+    return rc;
+}
+
+static int libxl__set_xenstore_vdispl(libxl__gc *gc, uint32_t domid,
+                                      libxl_device_vdispl *vdispl)
+{
+    flexarray_t *front;
+    flexarray_t *back;
+
+    front = flexarray_make(gc, 16, 1);
+    back = flexarray_make(gc, 16, 1);
+
+    flexarray_append(back, "frontend-id");
+    flexarray_append(back, GCSPRINTF("%d", domid));
+    flexarray_append(back, "online");
+    flexarray_append(back, "1");
+    flexarray_append(back, "state");
+    flexarray_append(back, GCSPRINTF("%d", XenbusStateInitialising));
+    flexarray_append(back, "handle");
+    flexarray_append(back, GCSPRINTF("%d", vdispl->devid));
+
+    flexarray_append(front, "backend-id");
+    flexarray_append(front, GCSPRINTF("%d", vdispl->backend_domid));
+    flexarray_append(front, "state");
+    flexarray_append(front, GCSPRINTF("%d", XenbusStateInitialising));
+    flexarray_append(front, "handle");
+    flexarray_append(front, GCSPRINTF("%d", vdispl->devid));
+    flexarray_append(front, "be_alloc");
+    flexarray_append(front, GCSPRINTF("%d", vdispl->be_alloc));
+
+    libxl__device *device;
+    xs_transaction_t t = XBT_NULL;
+    int rc;
+
+    GCNEW(device);
+
+    rc = libxl__device_from_vdispl(gc, domid, vdispl, device);
+    if (rc) goto out;
+
+    for (;;) {
+        rc = libxl__xs_transaction_start(gc, &t);
+        if (rc) goto out;
+
+        rc = libxl__device_generic_add(gc, t, device,
+                                       libxl__xs_kvs_of_flexarray(gc, back),
+                                       libxl__xs_kvs_of_flexarray(gc, front),
+                                       NULL);
+        if (rc) goto out;
+
+        rc = libxl__set_xenstore_connectors(gc, t, device, vdispl);
+        if (rc) goto out;
+
+        rc = libxl__xs_transaction_commit(gc, &t);
+        if (!rc) break;
+        if (rc < 0) goto out;
+    }
+
+    rc = 0;
+
+out:
+    libxl__xs_transaction_abort(gc, &t);
+    return rc;
+}
+
 libxl_device_vdispl *libxl_device_vdispl_list(libxl_ctx *ctx, uint32_t domid,
                                               int *num)
 {
@@ -91,7 +204,9 @@ DEFINE_DEVICE_TYPE_STRUCT(vdispl,
     .update_config = (void (*)(libxl__gc *, void *, void *))
                      libxl__update_config_vdispl,
     .from_xenstore = (int (*)(libxl__gc *, const char *, uint32_t, void *))
-                     libxl__from_xenstore_vdispl
+                     libxl__from_xenstore_vdispl,
+    .set_xenstore_config = (int (*)(libxl__gc *, uint32_t, void *))
+                           libxl__set_xenstore_vdispl
 );
 
 /*
-- 
2.7.4


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

 


Rackspace

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