From nobody Tue Feb 10 01:16:33 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1 dmarc=pass fromdomain=amd.com); dmarc=pass(p=quarantine dis=none) header.from=amd.com ARC-Seal: i=2; a=rsa-sha256; t=1713929793; cv=pass; d=zohomail.com; s=zohoarc; b=l/3IRrOC6TlDpz+U2qZqQ244K7MNaiYFWe7TTQWJ6borrSc5loFPCTVTBKmf3KJ+k1+dmk30j8CAZ6RHrYsUyywoMwzTvf2tfedNKd+FKl3XxSsWSbquEpTeouhoUz6CgNxN0XaM1UqT9u/STr0nKOzQhcVyc/C6o5iWQ8QwnSM= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1713929793; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=zlEz8Qbz/UMaWUU/jaiTmBDD/wiyD0++iaf2udSkHFg=; b=YncUHBGe/ETCOXkKDZzG7N7XIVt0MGt3UHiIqXmcID6C9wJpY0ZnlxBLFpIBqBX+GY5P6snkntrorVzQpj2D0Q+L4XYXyJ9wiQ+ntwVIiWCfZ49T60M5cA6Xu0dmVfl4yPwF7VFIWgNSeYsrNVW3usrLAhu78QHceHTatK3KCZ4= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1 dmarc=pass fromdomain=amd.com); dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1713929793286566.0810643486686; Tue, 23 Apr 2024 20:36:33 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.711032.1110705 (Exim 4.92) (envelope-from ) id 1rzTQc-0005tR-Dm; Wed, 24 Apr 2024 03:36:14 +0000 Received: by outflank-mailman (output) from mailman id 711032.1110705; Wed, 24 Apr 2024 03:36:14 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rzTQc-0005tI-AI; Wed, 24 Apr 2024 03:36:14 +0000 Received: by outflank-mailman (input) for mailman id 711032; Wed, 24 Apr 2024 03:36:12 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rzTQa-0002In-K5 for xen-devel@lists.xenproject.org; Wed, 24 Apr 2024 03:36:12 +0000 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on20600.outbound.protection.outlook.com [2a01:111:f403:2415::600]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id cb071d83-01eb-11ef-b4bb-af5377834399; Wed, 24 Apr 2024 05:36:10 +0200 (CEST) Received: from MN2PR12CA0008.namprd12.prod.outlook.com (2603:10b6:208:a8::21) by MN0PR12MB6054.namprd12.prod.outlook.com (2603:10b6:208:3ce::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7472.44; Wed, 24 Apr 2024 03:36:05 +0000 Received: from MN1PEPF0000ECD9.namprd02.prod.outlook.com (2603:10b6:208:a8:cafe::5a) by MN2PR12CA0008.outlook.office365.com (2603:10b6:208:a8::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7495.33 via Frontend Transport; Wed, 24 Apr 2024 03:36:05 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by MN1PEPF0000ECD9.mail.protection.outlook.com (10.167.242.138) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7519.19 via Frontend Transport; Wed, 24 Apr 2024 03:36:05 +0000 Received: from SATLEXMB08.amd.com (10.181.40.132) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Tue, 23 Apr 2024 22:36:04 -0500 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB08.amd.com (10.181.40.132) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Tue, 23 Apr 2024 20:36:04 -0700 Received: from henry-MS-7D54.amd.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2507.35 via Frontend Transport; Tue, 23 Apr 2024 22:36:02 -0500 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: cb071d83-01eb-11ef-b4bb-af5377834399 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=j8nhVp3kknyf4echTk6sdYRC0gg6JdtjV5ydZsD+Pop2qIUQeXpBUH2baBogEOBVA3Dfbl5leTceRmzP+7k0Cfng6vA7hRPJqSS+0JWzXlrWjGd6dHH9JaxXLfMqQINM3XwcA4JZ8BqYhonvDj1lFXqamG8I5jmQyvnh4iywSIhsG+L0m5VTcbiOEjWPfIffROvQfa7FRsTB2NYGWZqJEXWMJh8jxztGVRqzU26iDtCDskJN34gpUVLdaiPDtz0OMkq6vNrqQANa7U0qQj/Y1f21JmAUq55R5XwZcaoRZMcoGL0qgWbY1st3lsyayZUHyfIWOvynA/Y2twGK7lkEaw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=zlEz8Qbz/UMaWUU/jaiTmBDD/wiyD0++iaf2udSkHFg=; b=WOnZvSv3PaiiQpwUiupW94vZJKTvUqD/eDO5UjBddeWMCo/zv2x+ACpNqXg0+0qxP6Q4bWtlKeBzWqhORvfiY1D4q36CvqLQ9Q6OyVWkPHx9mXBeGsjVDJtQt7l+1ijAcUy8n5i3KUKn3FSuMTcNJ16qACctIpdARoHzCCFy+A2YbQbcDnNdJG381EkOdWUkQG/UPm37y4HG2qhfFqGdbzaba6aztn/dkf/y66b1yorn1Yp7PEAnDZKT5Sv/UQbNxLq1aAwtHwigRvG4w0kUKqTjtN1Dipn39wPLuA9A4qj7nMjiBpAtjru9kbTza/0uNPt+UeVIr2Gt5Glfp2ACog== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=zlEz8Qbz/UMaWUU/jaiTmBDD/wiyD0++iaf2udSkHFg=; b=IbHyBjeH1aG91WhymMQQHPWlhiAzsbyNeAfoA94TaRzXFSdUnzErh8nw6hb29YzHivz7QdWw5jzSvpAzKwP4jcIBZW2V8FrNSAMvb17CDTbkNtjF83n6rh2bHupfOLCGWKIM/YWdIjWZOv8Me5RqIgN50o9d0B351Y/v/OTEedE= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C From: Henry Wang To: CC: Vikram Garhwal , Anthony PERARD , Stewart Hildebrand , Stefano Stabellini , Henry Wang Subject: [PATCH 10/15] tools/xl: Share overlay with domU Date: Wed, 24 Apr 2024 11:34:44 +0800 Message-ID: <20240424033449.168398-11-xin.wang2@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240424033449.168398-1-xin.wang2@amd.com> References: <20240424033449.168398-1-xin.wang2@amd.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MN1PEPF0000ECD9:EE_|MN0PR12MB6054:EE_ X-MS-Office365-Filtering-Correlation-Id: 651dd3f1-484e-409f-7b9d-08dc640fac09 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?TGA3dNGoVRuoqr2bB74CDMTC3H/FjOKwXAdM0KjLpp3TYK2bBucumLoW4/rf?= =?us-ascii?Q?coAQkIjx33fA540XV0REnp8zF3kyxHq8qU5doepJtONQM8KMy780enBwZt13?= =?us-ascii?Q?Wi+iDpB7iim1m3Vky1IuLbnewzWzP4bwcTlPM3bE6ortjH2ddoRXPu3WUIIt?= =?us-ascii?Q?hoKdo6GPFypcaYOkYLnOOcTX72V0CiSrE9u6v31U34W1clqSHOFpYd4RD7Xi?= =?us-ascii?Q?899Td5TNKNra0nGgblbr1S7ymY4gzuar+zaFtgZuxOGKU3UVompkOObADegc?= =?us-ascii?Q?q+yAA8G1mWwr9lvZAIt9hHpBuXT5VfwInpG5TnllEhGIG9E0fG29QQdPi8Ld?= =?us-ascii?Q?azdGLP7s5ONnqJqm81c3fTAWVQhc8mbNAjXfU9ML7WMSaPn8YUawihltw3Da?= =?us-ascii?Q?UayPEpoFaCgMYvMA26aOl0I+Sd8Ha/8APUc+ZqK8JdWknFCj6uvraAXow0gM?= =?us-ascii?Q?bS2nyHbVEAKQOvk2lY7HDJHZUj15GJjCPpZow7U7uLLMV/vkzrGPs9JuW9AD?= =?us-ascii?Q?flx4iJ3+yR95+5JOUbs52nORPIq0fwvrXoJbNLJ1r64EVN5IoM+MU6hL+14a?= =?us-ascii?Q?VP7aLSYCjvjFKGBblkS2X4SOjcPV4bZstzlDuF+iRjV154AucXTgoyheeXHM?= =?us-ascii?Q?roTFMmFLztUAeAZWtV8yQAuHq5uemL0ZJHIlXMlNvq+xmnBmpJUzO9XU1skv?= =?us-ascii?Q?4Cg7rofTjssxy78eowUmMkCHqBhg+5syrutgGtG3IJShiMnzgyszgp4kmWXm?= =?us-ascii?Q?e9EU/Q2dNxwVeTB3gbGGnsd9ndhO8FO2vwf2NVM37uxnwCSgSuFkGZ87RybH?= =?us-ascii?Q?UjFXjuqqc963H7gob6lRYmdpxKRAC5akcYwkAV3li1FbpsZs8Bw9OyfQNft1?= =?us-ascii?Q?jx+o/FTEdAXNpVnLcoRoWrPw0OT8caPVtLu6m7rbgLXkJU3tWSGRKSQECoHL?= =?us-ascii?Q?QjA7t+wHtzTxfga7yq9qbaAugbvaCR49XQWzgmuMPJ+ktpy5DEls3x6dJyh9?= =?us-ascii?Q?y4xbCFnJr5XDHobweE6DL51yM0mABjpblshQ/q/CRP31DOlEo49kvv6rSsgW?= =?us-ascii?Q?pqsdWZjhPS4Yv+9Ux0GXc2uUUQ4/uHWtFb0BdoP2Ikpnqa3SlHI158X3BRrJ?= =?us-ascii?Q?x7200IaNY9P5b5CXhOvJj56BateJobmnKT+IxF6Nw5xVW5MRlr+RaO5ziz1m?= =?us-ascii?Q?onDlXM/rqWDu7Ixm1gwVsUjAhGEBd5Z7tKJ3eVZhFm6gGRkPV6c3YVT69oq7?= =?us-ascii?Q?GLXJ5RTLCm0KKDsBhwpIFMlz12KHHbgsIAKBhNQu+F5+Yacw0jYKxnQ4yp0t?= =?us-ascii?Q?NjMkVAcS6s8+rge63mYFN+iSUcsfKLwTFSLQgZB5I1uptKMzIc5aXC8/IcGb?= =?us-ascii?Q?DYl3wZdrCGFCqWQTio7vb5qOoQ+T?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(82310400014)(36860700004)(1800799015)(376005);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Apr 2024 03:36:05.2888 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 651dd3f1-484e-409f-7b9d-08dc640fac09 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: MN1PEPF0000ECD9.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN0PR12MB6054 X-ZohoMail-DKIM: pass (identity @amd.com) X-ZM-MESSAGEID: 1713929793722100001 Content-Type: text/plain; charset="utf-8" From: Vikram Garhwal Add domid to enable assigning the node to a running VMs. Add expert mode option to share the overlay dtbo with domU. In this mode do= m0 communicates with domid domain to share the overlay dtbo. This is done via xenstore. Signed-off-by: Vikram Garhwal Signed-off-by: Stewart Hildebrand Signed-off-by: Stefano Stabellini Signed-off-by: Henry Wang --- tools/xl/Makefile | 2 +- tools/xl/xl_cmdtable.c | 2 +- tools/xl/xl_vmcontrol.c | 343 +++++++++++++++++++++++++++++++++++++++- 3 files changed, 342 insertions(+), 5 deletions(-) diff --git a/tools/xl/Makefile b/tools/xl/Makefile index d742e96a5b..122dfb9346 100644 --- a/tools/xl/Makefile +++ b/tools/xl/Makefile @@ -32,7 +32,7 @@ $(XL_OBJS): CFLAGS +=3D -include $(XEN_ROOT)/tools/config= .h # libxl_json.h needs i all: xl =20 xl: $(XL_OBJS) - $(CC) $(LDFLAGS) -o $@ $(XL_OBJS) $(LDLIBS_libxenutil) $(LDLIBS_libxenlig= ht) $(LDLIBS_libxentoollog) -lyajl $(APPEND_LDFLAGS) + $(CC) $(LDFLAGS) -o $@ $(XL_OBJS) $(LDLIBS_libxenutil) $(LDLIBS_libxenlig= ht) $(LDLIBS_libxentoollog) $(LDLIBS_libxenstore) $(LDLIBS_libxengnttab) -l= yajl $(APPEND_LDFLAGS) =20 .PHONY: install install: all diff --git a/tools/xl/xl_cmdtable.c b/tools/xl/xl_cmdtable.c index 62bdb2aeaa..2531e8517b 100644 --- a/tools/xl/xl_cmdtable.c +++ b/tools/xl/xl_cmdtable.c @@ -635,7 +635,7 @@ const struct cmd_spec cmd_table[] =3D { { "dt-overlay", &main_dt_overlay, 0, 1, "Add/Remove a device tree overlay", - "add/remove <.dtbo>" + "add/remove <.dtbo> domain_id -e[expert_mode]", "-h print this help\n" }, #endif diff --git a/tools/xl/xl_vmcontrol.c b/tools/xl/xl_vmcontrol.c index 9674383ec3..2bf76dd389 100644 --- a/tools/xl/xl_vmcontrol.c +++ b/tools/xl/xl_vmcontrol.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -29,6 +30,8 @@ #include "xl.h" #include "xl_utils.h" #include "xl_parse.h" +#include +#include =20 static int fd_lock =3D -1; =20 @@ -1266,6 +1269,335 @@ int main_create(int argc, char **argv) } =20 #ifdef LIBXL_HAVE_DT_OVERLAY +static int copy_overlay_to_domU(uint32_t domain_id, void *overlay_dt_domU, + uint32_t overlay_dt_size, uint32_t *grant_= ref, + uint32_t num_pages) +{ + void *buffer =3D NULL; + xengnttab_handle *gnttab =3D xengnttab_open(NULL, 0); + + if (!gnttab) { + fprintf(stderr,"opening gnttab failed for domain %d\n", domain_id); + return -1; + } + + buffer =3D xengnttab_map_domain_grant_refs(gnttab, num_pages, domain_i= d, + grant_ref, PROT_READ|PROT_WRI= TE); + + if (buffer =3D=3D NULL) { + fprintf(stderr, "Getting the buffer failed for grant_refs\n"); + + return -1; + } + + /* buffer is contiguous allocated. */ + memcpy(buffer, overlay_dt_domU, overlay_dt_size); + + xengnttab_unmap(gnttab, buffer, num_pages); + + return 0; +} + +static bool wait_for_status(struct xs_handle *xs, int fd, char *status_pat= h, + const char *status) +{ + unsigned int num_strings; + char *buf =3D NULL; + char **vec =3D NULL; + bool ret =3D false; + unsigned int len; + int rc =3D 0; + fd_set set; + + while (1) + { + FD_ZERO(&set); + FD_SET(fd, &set); + + rc =3D select(fd + 1, &set, NULL, NULL, NULL); + /* Poll for data: Blocking. */ + if (rc <=3D 0) + break; + + if (FD_ISSET(fd, &set)) { + /* + * num_strings will be set to the number of elements in vec + * (2 - the watched path and the overlay_watch) + */ + vec =3D xs_read_watch(xs, &num_strings); + if (!vec) { + break; + } + + /* do a read. */ + buf =3D xs_read(xs, XBT_NULL, status_path, &len); + if (buf) { + if (!strcmp(buf, status)) { + ret =3D true; + break; + } + } + } + } + + free(vec); + free(buf); + + return ret; +} + +static bool write_overlay_size(struct xs_handle *xs, uint32_t overlay_size, + char *path) +{ + xs_transaction_t xs_trans =3D XBT_NULL; + char buf[128]; + char ref[16]; + +retry_transaction: + xs_trans =3D xs_transaction_start(xs); + if (!xs_trans) + return false; + + snprintf(ref, sizeof(ref), "%u", overlay_size); + snprintf(buf, sizeof(buf), "%s/overlay-size", path); + + if (!xs_write(xs, xs_trans, buf, ref, strlen(ref))) + return false; + + if (!xs_transaction_end(xs, xs_trans, 0)) { + if (errno =3D=3D EAGAIN) + goto retry_transaction; + else + return false; + } + + return true; +} + +static bool write_status(struct xs_handle *xs, char *status, char *status_= path) +{ + xs_transaction_t xs_trans =3D XBT_NULL; + +retry_transaction: + xs_trans =3D xs_transaction_start(xs); + if (!xs_trans) + return false; + + if (!xs_write(xs, xs_trans, status_path, status, strlen(status))) + return false; + + if (!xs_transaction_end(xs, xs_trans, 0)) { + if (errno =3D=3D EAGAIN) + goto retry_transaction; + else + return false; + } + + return true; +} + +static uint32_t *get_page_ref(struct xs_handle *xs, const char *xs_path, + uint32_t num_pages) +{ + char buf[128]; + uint32_t *ref =3D NULL; + char *data; + char temp[16] =3D { }; + unsigned int len; + int i =3D 0; + int j =3D 0; + int start_ind =3D 0; + + snprintf(buf, sizeof(buf), "%s/page-ref", xs_path); + + /* do a read. */ + data =3D xs_read(xs, XBT_NULL, buf, &len); + + if (data) { + /* Caller will free this. */ + ref =3D (uint32_t *)calloc(num_pages, sizeof(uint32_t)); + + for (i =3D 0; data[i] !=3D '\0'; i++) { + if (data[i] =3D=3D ',') { + /* Next page_ref data. */ + memset(temp, '\0', sizeof(temp)); + + /* Copy the data between previous ',' to current. */ + memcpy(temp, &data[start_ind], i - start_ind); + + /* Convert to int. */ + ref[j] =3D atoi(temp); + start_ind =3D i + 1; + j++; + } + + if (j =3D=3D num_pages) + break; + } + } + + if (j !=3D num_pages) { + fprintf(stderr, "Number of page_refs are not equal to num_pages\n"= ); + free(ref); + ref =3D NULL; + } + + free(data); + return ref; +} + +static uint32_t get_num_pages(struct xs_handle *xs, const char *xs_path) +{ + char buf[128]; + char *ref; + unsigned int len; + uint32_t num_pages =3D 0; + + snprintf(buf, sizeof(buf), "%s/num-pages", xs_path); + + /* do a read. */ + ref =3D xs_read(xs, XBT_NULL, buf, &len); + + if (ref) + num_pages =3D atoi(ref); + + free(ref); + + return num_pages; +} + +static int share_overlay_with_domu(void *overlay_dt_domU, int overlay_dt_s= ize, + int domain_id) +{ + struct xs_handle *xs =3D NULL; + char *path =3D NULL; + char receiver_status_path[64] =3D { }; + char sender_status_path[64] =3D { }; + int fd =3D 0; + int err; + uint32_t num_pages=3D 1; + uint32_t *page_ref =3D NULL; + + /* XS_watch part. */ + /* Open a connection to the xenstore. */ + xs =3D xs_open(0); + if (xs =3D=3D NULL) { + fprintf(stderr, "Deamon open for domain%d failed\n", domain_id); + err =3D ERROR_FAIL; + goto out; + } + + /* Get the local domain path */ + path =3D xs_get_domain_path(xs, domain_id); + if (path =3D=3D NULL) { + fprintf(stderr, "Getting domain%d path failed\n", domain_id); + err =3D ERROR_FAIL; + goto out; + } + + /* Make space for our node on the path */ + path =3D realloc(path, strlen(path) + strlen("/data/overlay") + 1); + if (path =3D=3D NULL) { + fprintf(stderr, "Path allocation failed\n"); + err =3D ERROR_NOMEM; + goto out; + } + + strcat(path, "/data/overlay"); + strcpy(receiver_status_path, path); + strcat(receiver_status_path, "/receiver-status"); + + /* + * Watch a node for changes (poll on fd to detect). + * When the node (or any child) changes, fd will become readable. + */ + err =3D xs_watch(xs, receiver_status_path, "overlay_watch"); + if (!err) { + fprintf(stderr, "Creating watch failed\n"); + err =3D ERROR_FAIL; + goto out; + } + + /* + * We are notified of read availability on the watch via the + * file descriptor. + */ + fd =3D xs_fileno(xs); + + /* Wait for "waiting" status from other domain. */ + if (!wait_for_status(xs, fd, receiver_status_path, "waiting")) { + err =3D ERROR_NOT_READY; + goto out; + } + + /* Share the dtb size with domain. */ + if (!write_overlay_size(xs, overlay_dt_size, path)) { + err =3D ERROR_FAIL; + fprintf(stderr,"Writing page ref failed\n"); + goto out; + } + + strcpy(sender_status_path, path); + strcat(sender_status_path, "/sender-status"); + + /* Write the status "ready". */ + if (!write_status(xs, "ready", sender_status_path)) { + err =3D ERROR_FAIL; + fprintf(stderr,"Writing status ready failed\n"); + goto out; + } + + /* Wait for "page_ref" status from other domain. */ + if (!wait_for_status(xs, fd, receiver_status_path, "page_ref")) { + err =3D ERROR_NOT_READY; + goto out; + } + + num_pages =3D get_num_pages(xs, path); + if (num_pages =3D=3D 0) { + fprintf(stderr, "no pages allocated\n"); + err =3D ERROR_FAIL; + goto out; + } + + page_ref =3D get_page_ref(xs, path, num_pages); + if (page_ref =3D=3D NULL) { + fprintf(stderr,"page ref is null.\n"); + err =3D ERROR_FAIL; + goto out; + } + + if (copy_overlay_to_domU(domain_id, overlay_dt_domU, overlay_dt_size, + page_ref, num_pages)) { + fprintf(stderr,"Copy overlay failed\n"); + err =3D ERROR_FAIL; + goto out; + } + + /* Write the status "done". */ + if (!write_status(xs, "done", sender_status_path)) { + fprintf(stderr,"Writing status DONE failed\n"); + err =3D ERROR_FAIL; + goto out; + } + +/* Cleanup */ +out: + if (xs) { + close(fd); + xs_unwatch(xs, path, "overlay_watch"); + xs_close(xs); + } + + if (path) + free(path); + + if (page_ref) + free(page_ref); + + return err; +} + int main_dt_overlay(int argc, char **argv) { const char *overlay_ops =3D NULL; @@ -1339,11 +1671,16 @@ int main_dt_overlay(int argc, char **argv) rc =3D libxl_dt_overlay(ctx, domain_id, overlay_dtb, overlay_dtb_size,= op, auto_mode, domain_mapping); =20 - free(overlay_dtb); - - if (rc) + if (rc) { + free(overlay_dtb); return EXIT_FAILURE; + } + + if (domain_id && auto_mode && (op =3D=3D LIBXL_DT_OVERLAY_ADD)) + rc =3D share_overlay_with_domu(overlay_dtb, overlay_dtb_size, + domain_id); =20 + free(overlay_dtb); return rc; } #endif --=20 2.34.1