From patchwork Tue Sep 12 13:48:08 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksandr Grytsov X-Patchwork-Id: 9949285 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 9232B603F3 for ; Tue, 12 Sep 2017 13:51:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 81C7E28F9C for ; Tue, 12 Sep 2017 13:51:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 76A9C28E2B; Tue, 12 Sep 2017 13:51:17 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 7C8C928F9C for ; Tue, 12 Sep 2017 13:51:16 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1drlYG-0005Tg-Hk; Tue, 12 Sep 2017 13:48:32 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1drlYF-0005Sj-Bp for xen-devel@lists.xenproject.org; Tue, 12 Sep 2017 13:48:31 +0000 Received: from [85.158.139.211] by server-11.bemta-5.messagelabs.com id 1B/E0-01760-EA5E7B95; Tue, 12 Sep 2017 13:48:30 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrGIsWRWlGSWpSXmKPExsVyMfS6s+7ap9s jDf6cUrH4vmUykwOjx+EPV1gCGKNYM/OS8isSWDOufJnBUrCijbFi8/6nLA2M65O6GLk4hARm MEpMmH2XDcRhEXjJInFj3zMwR0Kgn1XiyM0Gxi5GTiAnSeLU4yfMEHaaxNHX11gh7FKJeysug NlCAvISB1sus0OMncIk8bpjJxtIgk1AS+L+7RVgtoiAksS9VZOZQGxmgRSJvevawBYICxhJzD tzDsxmEVCV2D17CVg9r4CDxMwZj6EWy0ncPNcJZnMKOEq0/+5ihljsIHFlzR62CYyCCxgZVjF qFKcWlaUW6RoZ6SUVZaZnlOQmZuboGhqY6uWmFhcnpqfmJCYV6yXn525iBIZdPQMD4w7GPe1+ hxglOZiURHmV72+PFOJLyk+pzEgszogvKs1JLT7EqMHBIfDz6d8WRimWvPy8VCUJ3utPgOoEi 1LTUyvSMnOAkQFTKsHBoyTCawOS5i0uSMwtzkyHSJ1itOS4cOfSHyaOA3tuAcmOm3f/MAmBzZ MS580HaRAAacgozYMbB4veS4yyUsK8jAwMDEI8BalFuZklqPKvGMU5GJWEebeATOHJzCuB2/o K6CAmoIN4Lm0BOagkESEl1cA48erHRq6Lx71qp9zkiZFJLw32KboYX1y2r+HhrY/Z6z0YGPg7 HD6aV1Zp6SxfHhzis+eq/5/7W8XCraTDu2KnPPe/JGLgbKanGHnhqcam2wt35SUfaWj+VcheF cBynqEpZNOk+dncHLWliy9V3+pZE58+56T05re9enYzFf/cfBu6ouJbkqASS3FGoqEWc1FxIg ACoS/32QIAAA== X-Env-Sender: al1img@gmail.com X-Msg-Ref: server-8.tower-206.messagelabs.com!1505224109!111032119!1 X-Originating-IP: [209.85.215.67] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.4.45; banners=-,-,- X-VirusChecked: Checked Received: (qmail 61531 invoked from network); 12 Sep 2017 13:48:29 -0000 Received: from mail-lf0-f67.google.com (HELO mail-lf0-f67.google.com) (209.85.215.67) by server-8.tower-206.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 12 Sep 2017 13:48:29 -0000 Received: by mail-lf0-f67.google.com with SMTP id q132so5369506lfe.4 for ; Tue, 12 Sep 2017 06:48:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=ZHYUxNiapDqpK+ZGAWbQ7cNHOhBSUHTGY+bpaAjCLNk=; b=qUnoUOwPf+7pCpJYR4XLIzjkty+UoFzEO21AuJqGyatP7g52/O7mjXzyYU8M4VKX4P 1fQU9zR/05KAaJtBQO2lxfgDaI2+S7Ye5GTHujM/UG2uyB956zJt5A25Q8wKMLjRFZoZ oxfm0allX2GIsY5feLXanBUiQn14dpK/8XZ+4rSUUFk6SrIUZOFMFyiQC3+INhNpNcew mA/7HJej57CvhKo0s9Saz8hGUd95fDFcIM7smGUlod/gPAeKa2NxC4d88GGmFswK6Tee acix0iqcZZOEE4Xph06PXE7pmxQ2Tdkk/Msh9ycD5Smjif1hykADUZDuzDq/4/EoDWKw DQQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=ZHYUxNiapDqpK+ZGAWbQ7cNHOhBSUHTGY+bpaAjCLNk=; b=mYc+Vx+a5xruBIgjTOKntuEq6hOaZP1C24diyFa9ohGU8vFKLqQjivZQO6+AOI6/jU /X72a/unef9wdudAcrei9Ay3RgMxAKtiyjAWeOXmQGPyL+4SgnW9N7scQroWmh9EK6F7 6gdwyQGXwVwm0IY2Ejp7j7yNG3Np5s6c+iamrk2ayCywqsxHge3j+DnV9aBBvfTnPDtq b8P6zd+8Jn2ENhQvlLW6VOv9SQd3McC95R+IjYo6jZn+hEfFn/Rl3s8s1PzCX4F9MVEX 4T3rp3XCUcbDQChTgWt1Zu9C6EMVfXiR8s9xG1jo1iZugm42DG5nUbUYVYCRVaTvl1pb SDLg== X-Gm-Message-State: AHPjjUiX8HIjCTipslt6aMnGEJ8JGLh0HA3aozMHEgI5/+km3OBO1NFA kYlYneQjediyhTGEbC8= X-Google-Smtp-Source: AOwi7QCmfE+u02xNQ7nwMH3PqdgdBgpO5NYSVC9tev0cwdMZEJsE0cUK3dohu+btXGgR0M4QFhYlFQ== X-Received: by 10.25.27.7 with SMTP id b7mr4473664lfb.94.1505224108471; Tue, 12 Sep 2017 06:48:28 -0700 (PDT) Received: from al1-pc.kyiv.epam.com (ll-56.209.223.85.sovam.net.ua. [85.223.209.56]) by smtp.gmail.com with ESMTPSA id s5sm690074lfb.14.2017.09.12.06.48.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 12 Sep 2017 06:48:27 -0700 (PDT) From: Oleksandr Grytsov To: xen-devel@lists.xenproject.org Date: Tue, 12 Sep 2017 16:48:08 +0300 Message-Id: <1505224098-19330-4-git-send-email-al1img@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1505224098-19330-1-git-send-email-al1img@gmail.com> References: <1505224098-19330-1-git-send-email-al1img@gmail.com> Cc: ian.jackson@eu.citrix.com, wei.liu2@citrix.com, Oleksandr Grytsov Subject: [Xen-devel] [PATCH v6 03/13] libxl: add vdispl device X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Oleksandr Grytsov Signed-off-by: Oleksandr Grytsov Acked-by: Wei Liu --- tools/libxl/Makefile | 2 +- tools/libxl/libxl.h | 24 +++ tools/libxl/libxl_create.c | 1 + tools/libxl/libxl_internal.h | 1 + tools/libxl/libxl_types.idl | 36 +++++ tools/libxl/libxl_types_internal.idl | 1 + tools/libxl/libxl_utils.h | 4 + tools/libxl/libxl_vdispl.c | 284 +++++++++++++++++++++++++++++++++++ 8 files changed, 352 insertions(+), 1 deletion(-) create mode 100644 tools/libxl/libxl_vdispl.c diff --git a/tools/libxl/Makefile b/tools/libxl/Makefile index 082af8f..56f90e1 100644 --- a/tools/libxl/Makefile +++ b/tools/libxl/Makefile @@ -138,7 +138,7 @@ LIBXL_OBJS = flexarray.o libxl.o libxl_create.o libxl_dm.o libxl_pci.o \ libxl_dom_suspend.o libxl_dom_save.o libxl_usb.o \ libxl_vtpm.o libxl_nic.o libxl_disk.o libxl_console.o \ libxl_cpupool.o libxl_mem.o libxl_sched.o libxl_tmem.o \ - libxl_9pfs.o libxl_domain.o \ + libxl_9pfs.o libxl_domain.o libxl_vdispl.o \ $(LIBXL_OBJS-y) LIBXL_OBJS += libxl_genid.o LIBXL_OBJS += _libxl_types.o libxl_flask.o _libxl_types_internal.o diff --git a/tools/libxl/libxl.h b/tools/libxl/libxl.h index 812b7ea..e386357 100644 --- a/tools/libxl/libxl.h +++ b/tools/libxl/libxl.h @@ -1877,6 +1877,30 @@ libxl_device_vtpm *libxl_device_vtpm_list(libxl_ctx *ctx, uint32_t domid, int *n int libxl_device_vtpm_getinfo(libxl_ctx *ctx, uint32_t domid, libxl_device_vtpm *vtpm, libxl_vtpminfo *vtpminfo); +/* Virtual displays */ +int libxl_device_vdispl_add(libxl_ctx *ctx, uint32_t domid, + libxl_device_vdispl *displ, + const libxl_asyncop_how *ao_how) + LIBXL_EXTERNAL_CALLERS_ONLY; +int libxl_device_vdispl_remove(libxl_ctx *ctx, uint32_t domid, + libxl_device_vdispl *vdispl, + const libxl_asyncop_how *ao_how) + LIBXL_EXTERNAL_CALLERS_ONLY; +int libxl_device_vdispl_destroy(libxl_ctx *ctx, uint32_t domid, + libxl_device_vdispl *vdispl, + const libxl_asyncop_how *ao_how) + LIBXL_EXTERNAL_CALLERS_ONLY; + +libxl_device_vdispl *libxl_device_vdispl_list(libxl_ctx *ctx, + uint32_t domid, int *num) + LIBXL_EXTERNAL_CALLERS_ONLY; +void libxl_device_vdispl_list_free(libxl_device_vdispl* list, int num) + LIBXL_EXTERNAL_CALLERS_ONLY; +int libxl_device_vdispl_getinfo(libxl_ctx *ctx, uint32_t domid, + libxl_device_vdispl *vdispl, + libxl_vdisplinfo *vdisplinfo) + LIBXL_EXTERNAL_CALLERS_ONLY; + /* Keyboard */ int libxl_device_vkb_add(libxl_ctx *ctx, uint32_t domid, libxl_device_vkb *vkb, const libxl_asyncop_how *ao_how) diff --git a/tools/libxl/libxl_create.c b/tools/libxl/libxl_create.c index efd1459..f20bbf9 100644 --- a/tools/libxl/libxl_create.c +++ b/tools/libxl/libxl_create.c @@ -1446,6 +1446,7 @@ const struct libxl_device_type *device_type_tbl[] = { &libxl__usbdev_devtype, &libxl__pcidev_devtype, &libxl__dtdev_devtype, + &libxl__vdispl_devtype, NULL }; diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h index c94a117..c6f5868 100644 --- a/tools/libxl/libxl_internal.h +++ b/tools/libxl/libxl_internal.h @@ -3563,6 +3563,7 @@ extern const struct libxl_device_type libxl__vtpm_devtype; extern const struct libxl_device_type libxl__usbctrl_devtype; extern const struct libxl_device_type libxl__usbdev_devtype; extern const struct libxl_device_type libxl__pcidev_devtype; +extern const struct libxl_device_type libxl__vdispl_devtype; extern const struct libxl_device_type *device_type_tbl[]; diff --git a/tools/libxl/libxl_types.idl b/tools/libxl/libxl_types.idl index 173d70a..756e120 100644 --- a/tools/libxl/libxl_types.idl +++ b/tools/libxl/libxl_types.idl @@ -779,6 +779,20 @@ libxl_device_channel = Struct("device_channel", [ ])), ]) +libxl_connector_param = Struct("connector_param", [ + ("id", string), + ("width", uint32), + ("height", uint32) + ]) + +libxl_device_vdispl = Struct("device_vdispl", [ + ("backend_domid", libxl_domid), + ("backend_domname", string), + ("devid", libxl_devid), + ("be_alloc", bool), + ("connectors", Array(libxl_connector_param, "num_connectors")) + ]) + libxl_domain_config = Struct("domain_config", [ ("c_info", libxl_domain_create_info), ("b_info", libxl_domain_build_info), @@ -792,6 +806,7 @@ libxl_domain_config = Struct("domain_config", [ ("vkbs", Array(libxl_device_vkb, "num_vkbs")), ("vtpms", Array(libxl_device_vtpm, "num_vtpms")), ("p9s", Array(libxl_device_p9, "num_p9s")), + ("vdispls", Array(libxl_device_vdispl, "num_vdispls")), # a channel manifests as a console with a name, # see docs/misc/channels.txt ("channels", Array(libxl_device_channel, "num_channels")), @@ -888,6 +903,27 @@ libxl_physinfo = Struct("physinfo", [ ("cap_hvm_directio", bool), ], dir=DIR_OUT) +libxl_connectorinfo = Struct("connectorinfo", [ + ("id", string), + ("width", uint32), + ("height", uint32), + ("req_evtch", integer), + ("req_rref", integer), + ("evt_evtch", integer), + ("evt_rref", integer), + ], dir=DIR_OUT) + +libxl_vdisplinfo = Struct("vdisplinfo", [ + ("backend", string), + ("backend_id", uint32), + ("frontend", string), + ("frontend_id", uint32), + ("devid", libxl_devid), + ("state", integer), + ("be_alloc", bool), + ("connectors", Array(libxl_connectorinfo, "num_connectors")) + ], dir=DIR_OUT) + # NUMA node characteristics: size and free are how much memory it has, and how # much of it is free, respectively. dists is an array of distances from this # node to each other node. diff --git a/tools/libxl/libxl_types_internal.idl b/tools/libxl/libxl_types_internal.idl index 7dc4d0f..673a6d5 100644 --- a/tools/libxl/libxl_types_internal.idl +++ b/tools/libxl/libxl_types_internal.idl @@ -26,6 +26,7 @@ libxl__device_kind = Enumeration("device_kind", [ (9, "VUSB"), (10, "QUSB"), (11, "9PFS"), + (12, "VDISPL"), ]) libxl__console_backend = Enumeration("console_backend", [ diff --git a/tools/libxl/libxl_utils.h b/tools/libxl/libxl_utils.h index 25773d8..9e743dc 100644 --- a/tools/libxl/libxl_utils.h +++ b/tools/libxl/libxl_utils.h @@ -78,6 +78,10 @@ int libxl_devid_to_device_vtpm(libxl_ctx *ctx, uint32_t domid, int devid, libxl_device_vtpm *vtpm); int libxl_devid_to_device_usbctrl(libxl_ctx *ctx, uint32_t domid, int devid, libxl_device_usbctrl *usbctrl); + +int libxl_devid_to_device_vdispl(libxl_ctx *ctx, uint32_t domid, + int devid, libxl_device_vdispl *vdispl); + int libxl_ctrlport_to_device_usbdev(libxl_ctx *ctx, uint32_t domid, int ctrl, int port, libxl_device_usbdev *usbdev); diff --git a/tools/libxl/libxl_vdispl.c b/tools/libxl/libxl_vdispl.c new file mode 100644 index 0000000..5740c89 --- /dev/null +++ b/tools/libxl/libxl_vdispl.c @@ -0,0 +1,284 @@ +/* + * Copyright (C) 2016 EPAM Systems Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation; version 2.1 only. with the special + * exception on linking described in file LICENSE. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +#include "libxl_internal.h" + +static int libxl__device_vdispl_setdefault(libxl__gc *gc, uint32_t domid, + libxl_device_vdispl *vdispl, + bool hotplug) +{ + return libxl__resolve_domid(gc, vdispl->backend_domname, + &vdispl->backend_domid); +} + +static int libxl__device_from_vdispl(libxl__gc *gc, uint32_t domid, + libxl_device_vdispl *vdispl, + libxl__device *device) +{ + device->backend_devid = vdispl->devid; + device->backend_domid = vdispl->backend_domid; + device->backend_kind = LIBXL__DEVICE_KIND_VDISPL; + device->devid = vdispl->devid; + device->domid = domid; + device->kind = LIBXL__DEVICE_KIND_VDISPL; + + return 0; +} + +static int libxl__vdispl_from_xenstore(libxl__gc *gc, const char *libxl_path, + libxl_devid devid, + libxl_device_vdispl *vdispl) +{ + char *be_path; + + vdispl->devid = devid; + be_path = libxl__xs_read(gc, XBT_NULL, GCSPRINTF("%s/backend", libxl_path)); + + return libxl__backendpath_parse_domid(gc, be_path, &vdispl->backend_domid); +} + +static void libxl__update_config_vdispl(libxl__gc *gc, + libxl_device_vdispl *dst, + libxl_device_vdispl *src) +{ + dst->devid = src->devid; + dst->be_alloc = src->be_alloc; +} + +static int libxl_device_vdispl_compare(libxl_device_vdispl *d1, + libxl_device_vdispl *d2) +{ + return COMPARE_DEVID(d1, d2); +} + +static void libxl__device_vdispl_add(libxl__egc *egc, uint32_t domid, + libxl_device_vdispl *vdispl, + libxl__ao_device *aodev) +{ + libxl__device_add_async(egc, domid, &libxl__vdispl_devtype, vdispl, aodev); +} + +static int libxl__set_xenstore_vdispl(libxl__gc *gc, uint32_t domid, + libxl_device_vdispl *vdispl, + flexarray_t *back, flexarray_t *front, + flexarray_t *ro_front) +{ + int i; + + flexarray_append_pair(ro_front, "be-alloc", + GCSPRINTF("%d", vdispl->be_alloc)); + + for (i = 0; i < vdispl->num_connectors; i++) { + flexarray_append_pair(ro_front, GCSPRINTF("%d/resolution", i), + GCSPRINTF("%dx%d", vdispl->connectors[i].width, + vdispl->connectors[i].height)); + flexarray_append_pair(ro_front, GCSPRINTF("%d/id", i), + vdispl->connectors[i].id); + } + + return 0; +} + +libxl_device_vdispl *libxl_device_vdispl_list(libxl_ctx *ctx, uint32_t domid, + int *num) +{ + libxl_device_vdispl *r; + + GC_INIT(ctx); + + r = libxl__device_list(gc, &libxl__vdispl_devtype, domid, "vdispl", num); + + GC_FREE; + + return r; +} + +void libxl_device_vdispl_list_free(libxl_device_vdispl* list, int num) +{ + libxl__device_list_free(&libxl__vdispl_devtype, list, num); +} + +static int libxl__device_vdispl_getconnectors(libxl_ctx *ctx, + const char *path, + libxl_vdisplinfo *info) +{ + GC_INIT(ctx); + char *connector = NULL; + char *connector_path; + int i, rc; + + info->num_connectors = 0; + + connector_path = GCSPRINTF("%s/%d", path, info->num_connectors); + + while ((connector = xs_read(ctx->xsh, XBT_NULL, connector_path, NULL)) != + NULL) { + free(connector); + connector_path = GCSPRINTF("%s/%d", path, ++info->num_connectors); + } + + info->connectors = libxl__calloc(NOGC, info->num_connectors, + sizeof(*info->connectors)); + + for (i = 0; i < info->num_connectors; i++) { + char *value; + char *value_path; + + value_path = GCSPRINTF("%s/%d/id", path, i); + info->connectors[i].id = xs_read(ctx->xsh, XBT_NULL, value_path, NULL); + if (info->connectors[i].id == NULL) { rc = ERROR_FAIL; goto out; } + + value_path = GCSPRINTF("%s/%d/resolution", path, i); + value = xs_read(ctx->xsh, XBT_NULL, value_path, NULL); + if (value == NULL) { rc = ERROR_FAIL; goto out; } + + rc = sscanf(value, "%ux%u", &info->connectors[i].width, + &info->connectors[i].height); + free(value); + + if (rc != 2) { + rc = ERROR_FAIL; goto out; + } + + value_path = GCSPRINTF("%s/%d/req-ring-ref", path, i); + value = xs_read(ctx->xsh, XBT_NULL, value_path, NULL); + info->connectors[i].req_rref = value ? strtoul(value, NULL, 10) : -1; + free(value); + + value_path = GCSPRINTF("%s/%d/req-event-channel", path, i); + value = xs_read(ctx->xsh, XBT_NULL, value_path, NULL); + info->connectors[i].req_evtch = value ? strtoul(value, NULL, 10) : -1; + free(value); + + value_path = GCSPRINTF("%s/%d/evt-ring-ref", path, i); + value = xs_read(ctx->xsh, XBT_NULL, value_path, NULL); + info->connectors[i].evt_rref = value ? strtoul(value, NULL, 10) : -1; + free(value); + + value_path = GCSPRINTF("%s/%d/evt-event-channel", path, i); + value = xs_read(ctx->xsh, XBT_NULL, value_path, NULL); + info->connectors[i].evt_evtch = value ? strtoul(value, NULL, 10) : -1; + free(value); + } + + rc = 0; + +out: + return rc; +} + +int libxl_device_vdispl_getinfo(libxl_ctx *ctx, uint32_t domid, + libxl_device_vdispl *vdispl, + libxl_vdisplinfo *info) +{ + GC_INIT(ctx); + char *libxl_path, *dompath, *devpath; + char *val; + int rc; + + libxl_vdisplinfo_init(info); + dompath = libxl__xs_get_dompath(gc, domid); + info->devid = vdispl->devid; + + devpath = GCSPRINTF("%s/device/vdispl/%d", dompath, info->devid); + libxl_path = GCSPRINTF("%s/device/vdispl/%d", + libxl__xs_libxl_path(gc, domid), + info->devid); + info->backend = xs_read(ctx->xsh, XBT_NULL, + GCSPRINTF("%s/backend", libxl_path), + NULL); + if (!info->backend) { rc = ERROR_FAIL; goto out; } + + rc = libxl__backendpath_parse_domid(gc, info->backend, &info->backend_id); + if (rc) goto out; + + val = libxl__xs_read(gc, XBT_NULL, GCSPRINTF("%s/state", devpath)); + info->state = val ? strtoul(val, NULL, 10) : -1; + + info->frontend = xs_read(ctx->xsh, XBT_NULL, + GCSPRINTF("%s/frontend", libxl_path), + NULL); + info->frontend_id = domid; + + val = libxl__xs_read(gc, XBT_NULL, GCSPRINTF("%s/be-alloc", devpath)); + info->be_alloc = val ? strtoul(val, NULL, 10) : 0; + + rc = libxl__device_vdispl_getconnectors(ctx, devpath, info); + if (rc) goto out; + + rc = 0; + +out: + GC_FREE; + return rc; +} + +int libxl_devid_to_device_vdispl(libxl_ctx *ctx, uint32_t domid, + int devid, libxl_device_vdispl *vdispl) +{ + GC_INIT(ctx); + + libxl_device_vdispl *vdispls = NULL; + int n, i; + int rc; + + libxl_device_vdispl_init(vdispl); + + vdispls = libxl__device_list(gc, &libxl__vdispl_devtype, + domid, "vdispl", &n); + + if (!vdispls) { rc = ERROR_NOTFOUND; goto out; } + + for (i = 0; i < n; ++i) { + if (devid == vdispls[i].devid) { + libxl_device_vdispl_copy(ctx, vdispl, &vdispls[i]); + rc = 0; + goto out; + } + } + + rc = ERROR_NOTFOUND; + +out: + + if (vdispls) + libxl__device_list_free(&libxl__vdispl_devtype, vdispls, n); + + GC_FREE; + return rc; +} + +LIBXL_DEFINE_DEVICE_ADD(vdispl) +static LIBXL_DEFINE_DEVICES_ADD(vdispl) +LIBXL_DEFINE_DEVICE_REMOVE(vdispl) +static LIBXL_DEFINE_UPDATE_DEVID(vdispl, "vdispl") + +DEFINE_DEVICE_TYPE_STRUCT(vdispl, + .update_config = (void (*)(libxl__gc *, void *, void *)) + libxl__update_config_vdispl, + .from_xenstore = (int (*)(libxl__gc *, const char *, libxl_devid, void *)) + libxl__vdispl_from_xenstore, + .set_xenstore_config = (int (*)(libxl__gc *, uint32_t, void *, + flexarray_t *back, flexarray_t *front, + flexarray_t *ro_front)) + libxl__set_xenstore_vdispl +); + +/* + * Local variables: + * mode: C + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + */