From nobody Mon Apr 29 15:17:07 2024 Delivered-To: importer@patchew.org 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; 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; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1610699443; cv=none; d=zohomail.com; s=zohoarc; b=PxRIB3My25mDPB8CT4z7w1+FpPw5q0G/RHCiPDav/NEPD73YmYad5r5Lh34Wldfpbi3Twot/vawBetqoe+mWi2kaoac/6HzAbwDkejetHNNpCU4wNWPQ2JptE++a+2pS+P/PZSAronAaNqMLn7ciCw2drbNlnDDY/qaSS+H+JyU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610699443; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=nn9gMpfhe1E74/K4cM3t3wmRxzIvFt83elDpS8B51eA=; b=R9gujQkn5VIIPNX+3VZg8V4fK6MDJqLdiw1I36m7s3oUZstY8UwyzTMK8M3yUW9N5zZ8ZtzqXfXMOVlvj+XpHh2MwvQG3ivOKk+A6aQ2x/Ct3I21LRtDLpwFavUg6UtbLRjvPvyeNAB0DUsQP0Uziy8pHZnHcchU5r4qgHZ8Cis= ARC-Authentication-Results: i=1; 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; dmarc=pass header.from= (p=quarantine dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 161069944339116.028020545569575; Fri, 15 Jan 2021 00:30:43 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.67719.121059 (Exim 4.92) (envelope-from ) id 1l0KV2-0000Af-3a; Fri, 15 Jan 2021 08:30:28 +0000 Received: by outflank-mailman (output) from mailman id 67719.121059; Fri, 15 Jan 2021 08:30:28 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l0KV1-0000AR-UR; Fri, 15 Jan 2021 08:30:27 +0000 Received: by outflank-mailman (input) for mailman id 67719; Fri, 15 Jan 2021 08:30:26 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l0KV0-0008HA-NZ for xen-devel@lists.xenproject.org; Fri, 15 Jan 2021 08:30:26 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 0789dfb0-94f5-4c89-92bf-a458d21bdaad; Fri, 15 Jan 2021 08:30:08 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 7C985B93E; Fri, 15 Jan 2021 08:30:06 +0000 (UTC) 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: 0789dfb0-94f5-4c89-92bf-a458d21bdaad X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1610699407; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=nn9gMpfhe1E74/K4cM3t3wmRxzIvFt83elDpS8B51eA=; b=B5BKDWagh7zCJ7khiwDz8pvoE3kY4Cw+wOHBo2dCEP+Xj1CzmdivLP1bW7XLWU9XLqphvz C/WkCyIwPN+Wk9muBxbuSD3xWAkLOY33AsjFFQ1v/Z9R9DNdWAsyIvC+OZlJoXadkjshqU A1/gGoAAMsvb5/0f9W6RTiF300ZXuaU= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Ian Jackson , Wei Liu , Andrew Cooper Subject: [PATCH v12 01/27] tools/libxenevtchn: switch to standard xen coding style Date: Fri, 15 Jan 2021 09:29:34 +0100 Message-Id: <20210115083000.14186-2-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210115083000.14186-1-jgross@suse.com> References: <20210115083000.14186-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) Content-Type: text/plain; charset="utf-8" There is a mixture of different styles in libxenevtchn. Use the standard xen style only. No functional change. Signed-off-by: Juergen Gross Acked-by: Andrew Cooper --- V11: - new patch V12: - fixed two other style issues (Andrew Cooper) --- tools/libs/evtchn/core.c | 24 +++++---- tools/libs/evtchn/freebsd.c | 25 +++++++--- tools/libs/evtchn/linux.c | 4 ++ tools/libs/evtchn/minios.c | 98 +++++++++++++++++++++++++++---------- tools/libs/evtchn/netbsd.c | 22 ++++++--- tools/libs/evtchn/solaris.c | 12 +++-- 6 files changed, 131 insertions(+), 54 deletions(-) diff --git a/tools/libs/evtchn/core.c b/tools/libs/evtchn/core.c index aff6ecfaa0..8090d0ce87 100644 --- a/tools/libs/evtchn/core.c +++ b/tools/libs/evtchn/core.c @@ -18,10 +18,11 @@ =20 #include "private.h" =20 -static int all_restrict_cb(Xentoolcore__Active_Handle *ah, domid_t domid) { +static int all_restrict_cb(Xentoolcore__Active_Handle *ah, domid_t domid) +{ xenevtchn_handle *xce =3D CONTAINER_OF(ah, *xce, tc_ah); =20 - if (xce->fd < 0) + if ( xce->fd < 0 ) /* just in case */ return 0; =20 @@ -33,7 +34,8 @@ xenevtchn_handle *xenevtchn_open(xentoollog_logger *logge= r, unsigned open_flags) xenevtchn_handle *xce =3D malloc(sizeof(*xce)); int rc; =20 - if (!xce) return NULL; + if ( !xce ) + return NULL; =20 xce->fd =3D -1; xce->logger =3D logger; @@ -42,23 +44,26 @@ xenevtchn_handle *xenevtchn_open(xentoollog_logger *log= ger, unsigned open_flags) xce->tc_ah.restrict_callback =3D all_restrict_cb; xentoolcore__register_active_handle(&xce->tc_ah); =20 - if (!xce->logger) { - xce->logger =3D xce->logger_tofree =3D - (xentoollog_logger*) + if ( !xce->logger ) + { + xce->logger =3D xce->logger_tofree =3D (xentoollog_logger *) xtl_createlogger_stdiostream(stderr, XTL_PROGRESS, 0); - if (!xce->logger) goto err; + if ( !xce->logger ) + goto err; } =20 rc =3D osdep_evtchn_open(xce); - if ( rc < 0 ) goto err; + if ( rc < 0 ) + goto err; =20 return xce; =20 -err: + err: xentoolcore__deregister_active_handle(&xce->tc_ah); osdep_evtchn_close(xce); xtl_logger_destroy(xce->logger_tofree); free(xce); + return NULL; } =20 @@ -73,6 +78,7 @@ int xenevtchn_close(xenevtchn_handle *xce) rc =3D osdep_evtchn_close(xce); xtl_logger_destroy(xce->logger_tofree); free(xce); + return rc; } =20 diff --git a/tools/libs/evtchn/freebsd.c b/tools/libs/evtchn/freebsd.c index 6564ed4c44..554af122c8 100644 --- a/tools/libs/evtchn/freebsd.c +++ b/tools/libs/evtchn/freebsd.c @@ -34,9 +34,12 @@ int osdep_evtchn_open(xenevtchn_handle *xce) { int fd =3D open(EVTCHN_DEV, O_RDWR|O_CLOEXEC); + if ( fd =3D=3D -1 ) return -1; + xce->fd =3D fd; + return 0; } =20 @@ -51,6 +54,7 @@ int osdep_evtchn_close(xenevtchn_handle *xce) int osdep_evtchn_restrict(xenevtchn_handle *xce, domid_t domid) { errno =3D -EOPNOTSUPP; + return -1; } =20 @@ -69,7 +73,8 @@ int xenevtchn_notify(xenevtchn_handle *xce, evtchn_port_t= port) return ioctl(fd, IOCTL_EVTCHN_NOTIFY, ¬ify); } =20 -xenevtchn_port_or_error_t xenevtchn_bind_unbound_port(xenevtchn_handle *xc= e, uint32_t domid) +xenevtchn_port_or_error_t xenevtchn_bind_unbound_port(xenevtchn_handle *xc= e, + uint32_t domid) { int ret, fd =3D xce->fd; struct ioctl_evtchn_bind_unbound_port bind; @@ -77,11 +82,13 @@ xenevtchn_port_or_error_t xenevtchn_bind_unbound_port(x= enevtchn_handle *xce, uin bind.remote_domain =3D domid; =20 ret =3D ioctl(fd, IOCTL_EVTCHN_BIND_UNBOUND_PORT, &bind); - return ( ret =3D=3D 0 ) ? bind.port : ret; + + return ret ?: bind.port; } =20 -xenevtchn_port_or_error_t -xenevtchn_bind_interdomain(xenevtchn_handle *xce, uint32_t domid, evtchn_p= ort_t remote_port) +xenevtchn_port_or_error_t xenevtchn_bind_interdomain(xenevtchn_handle *xce, + uint32_t domid, + evtchn_port_t remote_= port) { int ret, fd =3D xce->fd; struct ioctl_evtchn_bind_interdomain bind; @@ -90,10 +97,12 @@ xenevtchn_bind_interdomain(xenevtchn_handle *xce, uint3= 2_t domid, evtchn_port_t bind.remote_port =3D remote_port; =20 ret =3D ioctl(fd, IOCTL_EVTCHN_BIND_INTERDOMAIN, &bind); - return ( ret =3D=3D 0 ) ? bind.port : ret; + + return ret ?: bind.port; } =20 -xenevtchn_port_or_error_t xenevtchn_bind_virq(xenevtchn_handle *xce, unsig= ned int virq) +xenevtchn_port_or_error_t xenevtchn_bind_virq(xenevtchn_handle *xce, + unsigned int virq) { int ret, fd =3D xce->fd; struct ioctl_evtchn_bind_virq bind; @@ -101,7 +110,8 @@ xenevtchn_port_or_error_t xenevtchn_bind_virq(xenevtchn= _handle *xce, unsigned in bind.virq =3D virq; =20 ret =3D ioctl(fd, IOCTL_EVTCHN_BIND_VIRQ, &bind); - return ( ret =3D=3D 0 ) ? bind.port : ret; + + return ret ?: bind.port; } =20 int xenevtchn_unbind(xenevtchn_handle *xce, evtchn_port_t port) @@ -131,6 +141,7 @@ int xenevtchn_unmask(xenevtchn_handle *xce, evtchn_port= _t port) =20 if ( write(fd, &port, sizeof(port)) !=3D sizeof(port) ) return -1; + return 0; } =20 diff --git a/tools/libs/evtchn/linux.c b/tools/libs/evtchn/linux.c index 17e64aea32..4582a58ec4 100644 --- a/tools/libs/evtchn/linux.c +++ b/tools/libs/evtchn/linux.c @@ -37,9 +37,12 @@ int osdep_evtchn_open(xenevtchn_handle *xce) { int fd =3D open("/dev/xen/evtchn", O_RDWR|O_CLOEXEC); + if ( fd =3D=3D -1 ) return -1; + xce->fd =3D fd; + return 0; } =20 @@ -135,6 +138,7 @@ int xenevtchn_unmask(xenevtchn_handle *xce, evtchn_port= _t port) =20 if ( write(fd, &port, sizeof(port)) !=3D sizeof(port) ) return -1; + return 0; } =20 diff --git a/tools/libs/evtchn/minios.c b/tools/libs/evtchn/minios.c index 9cd7636fc5..bbb313a521 100644 --- a/tools/libs/evtchn/minios.c +++ b/tools/libs/evtchn/minios.c @@ -43,22 +43,28 @@ extern void minios_evtchn_close_fd(int fd); extern struct wait_queue_head event_queue; =20 /* XXX Note: This is not threadsafe */ -static struct evtchn_port_info* port_alloc(int fd) { +static struct evtchn_port_info* port_alloc(int fd) +{ struct evtchn_port_info *port_info; + port_info =3D malloc(sizeof(struct evtchn_port_info)); - if (port_info =3D=3D NULL) + if ( port_info =3D=3D NULL ) return NULL; + port_info->pending =3D 0; port_info->port =3D -1; port_info->bound =3D 0; =20 LIST_INSERT_HEAD(&files[fd].evtchn.ports, port_info, list); + return port_info; } =20 -static void port_dealloc(struct evtchn_port_info *port_info) { - if (port_info->bound) +static void port_dealloc(struct evtchn_port_info *port_info) +{ + if ( port_info->bound ) unbind_evtchn(port_info->port); + LIST_REMOVE(port_info, list); free(port_info); } @@ -66,11 +72,14 @@ static void port_dealloc(struct evtchn_port_info *port_= info) { int osdep_evtchn_open(xenevtchn_handle *xce) { int fd =3D alloc_fd(FTYPE_EVTCHN); + if ( fd =3D=3D -1 ) return -1; + LIST_INIT(&files[fd].evtchn.ports); xce->fd =3D fd; printf("evtchn_open() -> %d\n", fd); + return 0; } =20 @@ -85,12 +94,14 @@ int osdep_evtchn_close(xenevtchn_handle *xce) int osdep_evtchn_restrict(xenevtchn_handle *xce, domid_t domid) { errno =3D -EOPNOTSUPP; + return -1; } =20 void minios_evtchn_close_fd(int fd) { struct evtchn_port_info *port_info, *tmp; + LIST_FOREACH_SAFE(port_info, &files[fd].evtchn.ports, list, tmp) port_dealloc(port_info); =20 @@ -108,10 +119,12 @@ int xenevtchn_notify(xenevtchn_handle *xce, evtchn_po= rt_t port) =20 ret =3D notify_remote_via_evtchn(port); =20 - if (ret < 0) { + if ( ret < 0 ) + { errno =3D -ret; ret =3D -1; } + return ret; } =20 @@ -119,12 +132,15 @@ static void evtchn_handler(evtchn_port_t port, struct= pt_regs *regs, void *data) { int fd =3D (int)(intptr_t)data; struct evtchn_port_info *port_info; + assert(files[fd].type =3D=3D FTYPE_EVTCHN); mask_evtchn(port); - LIST_FOREACH(port_info, &files[fd].evtchn.ports, list) { - if (port_info->port =3D=3D port) + LIST_FOREACH(port_info, &files[fd].evtchn.ports, list) + { + if ( port_info->port =3D=3D port ) goto found; } + printk("Unknown port for handle %d\n", fd); return; =20 @@ -134,7 +150,8 @@ static void evtchn_handler(evtchn_port_t port, struct p= t_regs *regs, void *data) wake_up(&event_queue); } =20 -xenevtchn_port_or_error_t xenevtchn_bind_unbound_port(xenevtchn_handle *xc= e, uint32_t domid) +xenevtchn_port_or_error_t xenevtchn_bind_unbound_port(xenevtchn_handle *xc= e, + uint32_t domid) { int fd =3D xce->fd; struct evtchn_port_info *port_info; @@ -143,26 +160,31 @@ xenevtchn_port_or_error_t xenevtchn_bind_unbound_port= (xenevtchn_handle *xce, uin =20 assert(get_current() =3D=3D main_thread); port_info =3D port_alloc(fd); - if (port_info =3D=3D NULL) + if ( port_info =3D=3D NULL ) return -1; =20 printf("xenevtchn_bind_unbound_port(%d)", domid); - ret =3D evtchn_alloc_unbound(domid, evtchn_handler, (void*)(intptr_t)f= d, &port); + ret =3D evtchn_alloc_unbound(domid, evtchn_handler, + (void *)(intptr_t)fd, &port); printf(" =3D %d\n", ret); =20 - if (ret < 0) { + if ( ret < 0 ) + { port_dealloc(port_info); errno =3D -ret; return -1; } + port_info->bound =3D 1; port_info->port =3D port; unmask_evtchn(port); + return port; } =20 -xenevtchn_port_or_error_t xenevtchn_bind_interdomain(xenevtchn_handle *xce= , uint32_t domid, - evtchn_port_t remote_por= t) +xenevtchn_port_or_error_t xenevtchn_bind_interdomain(xenevtchn_handle *xce, + uint32_t domid, + evtchn_port_t remote_= port) { int fd =3D xce->fd; struct evtchn_port_info *port_info; @@ -171,21 +193,25 @@ xenevtchn_port_or_error_t xenevtchn_bind_interdomain(= xenevtchn_handle *xce, uint =20 assert(get_current() =3D=3D main_thread); port_info =3D port_alloc(fd); - if (port_info =3D=3D NULL) + if ( port_info =3D=3D NULL ) return -1; =20 printf("xenevtchn_bind_interdomain(%d, %"PRId32")", domid, remote_port= ); - ret =3D evtchn_bind_interdomain(domid, remote_port, evtchn_handler, (v= oid*)(intptr_t)fd, &local_port); + ret =3D evtchn_bind_interdomain(domid, remote_port, evtchn_handler, + (void *)(intptr_t)fd, &local_port); printf(" =3D %d\n", ret); =20 - if (ret < 0) { + if ( ret < 0 ) + { port_dealloc(port_info); errno =3D -ret; return -1; } + port_info->bound =3D 1; port_info->port =3D local_port; unmask_evtchn(local_port); + return local_port; } =20 @@ -194,18 +220,24 @@ int xenevtchn_unbind(xenevtchn_handle *xce, evtchn_po= rt_t port) int fd =3D xce->fd; struct evtchn_port_info *port_info; =20 - LIST_FOREACH(port_info, &files[fd].evtchn.ports, list) { - if (port_info->port =3D=3D port) { + LIST_FOREACH(port_info, &files[fd].evtchn.ports, list) + { + if ( port_info->port =3D=3D port ) + { port_dealloc(port_info); return 0; } } - printf("Warning: couldn't find port %"PRId32" for xc handle %x\n", por= t, fd); + + printf("Warning: couldn't find port %"PRId32" for xc handle %x\n", + port, fd); errno =3D EINVAL; + return -1; } =20 -xenevtchn_port_or_error_t xenevtchn_bind_virq(xenevtchn_handle *xce, unsig= ned int virq) +xenevtchn_port_or_error_t xenevtchn_bind_virq(xenevtchn_handle *xce, + unsigned int virq) { int fd =3D xce->fd; struct evtchn_port_info *port_info; @@ -213,21 +245,24 @@ xenevtchn_port_or_error_t xenevtchn_bind_virq(xenevtc= hn_handle *xce, unsigned in =20 assert(get_current() =3D=3D main_thread); port_info =3D port_alloc(fd); - if (port_info =3D=3D NULL) + if ( port_info =3D=3D NULL ) return -1; =20 printf("xenevtchn_bind_virq(%d)", virq); - port =3D bind_virq(virq, evtchn_handler, (void*)(intptr_t)fd); + port =3D bind_virq(virq, evtchn_handler, (void *)(intptr_t)fd); printf(" =3D %d\n", port); =20 - if (port < 0) { + if ( port < 0 ) + { port_dealloc(port_info); errno =3D -port; return -1; } + port_info->bound =3D 1; port_info->port =3D port; unmask_evtchn(port); + return port; } =20 @@ -239,26 +274,35 @@ xenevtchn_port_or_error_t xenevtchn_pending(xenevtchn= _handle *xce) evtchn_port_t ret =3D -1; =20 local_irq_save(flags); + files[fd].read =3D 0; =20 - LIST_FOREACH(port_info, &files[fd].evtchn.ports, list) { - if (port_info->port !=3D -1 && port_info->pending) { - if (ret =3D=3D -1) { + LIST_FOREACH(port_info, &files[fd].evtchn.ports, list) + { + if ( port_info->port !=3D -1 && port_info->pending ) + { + if ( ret =3D=3D -1 ) + { ret =3D port_info->port; port_info->pending =3D 0; - } else { + } + else + { files[fd].read =3D 1; break; } } } + local_irq_restore(flags); + return ret; } =20 int xenevtchn_unmask(xenevtchn_handle *xce, evtchn_port_t port) { unmask_evtchn(port); + return 0; } =20 diff --git a/tools/libs/evtchn/netbsd.c b/tools/libs/evtchn/netbsd.c index 8b8545d2f9..53f9299ebb 100644 --- a/tools/libs/evtchn/netbsd.c +++ b/tools/libs/evtchn/netbsd.c @@ -34,9 +34,12 @@ int osdep_evtchn_open(xenevtchn_handle *xce) { int fd =3D open(EVTCHN_DEV_NAME, O_NONBLOCK|O_RDWR); + if ( fd =3D=3D -1 ) return -1; + xce->fd =3D fd; + return 0; } =20 @@ -51,6 +54,7 @@ int osdep_evtchn_close(xenevtchn_handle *xce) int osdep_evtchn_restrict(xenevtchn_handle *xce, domid_t domid) { errno =3D -EOPNOTSUPP; + return -1; } =20 @@ -69,7 +73,8 @@ int xenevtchn_notify(xenevtchn_handle *xce, evtchn_port_t= port) return ioctl(fd, IOCTL_EVTCHN_NOTIFY, ¬ify); } =20 -xenevtchn_port_or_error_t xenevtchn_bind_unbound_port(xenevtchn_handle * x= ce, uint32_t domid) +xenevtchn_port_or_error_t xenevtchn_bind_unbound_port(xenevtchn_handle *xc= e, + uint32_t domid) { int fd =3D xce->fd; struct ioctl_evtchn_bind_unbound_port bind; @@ -78,14 +83,15 @@ xenevtchn_port_or_error_t xenevtchn_bind_unbound_port(x= enevtchn_handle * xce, ui bind.remote_domain =3D domid; =20 ret =3D ioctl(fd, IOCTL_EVTCHN_BIND_UNBOUND_PORT, &bind); - if (ret =3D=3D 0) + if ( ret =3D=3D 0 ) return bind.port; else return -1; } =20 -xenevtchn_port_or_error_t xenevtchn_bind_interdomain(xenevtchn_handle *xce= , uint32_t domid, - evtchn_port_t remote_por= t) +xenevtchn_port_or_error_t xenevtchn_bind_interdomain(xenevtchn_handle *xce, + uint32_t domid, + evtchn_port_t remote_= port) { int fd =3D xce->fd; struct ioctl_evtchn_bind_interdomain bind; @@ -95,7 +101,7 @@ xenevtchn_port_or_error_t xenevtchn_bind_interdomain(xen= evtchn_handle *xce, uint bind.remote_port =3D remote_port; =20 ret =3D ioctl(fd, IOCTL_EVTCHN_BIND_INTERDOMAIN, &bind); - if (ret =3D=3D 0) + if ( ret =3D=3D 0 ) return bind.port; else return -1; @@ -111,7 +117,8 @@ int xenevtchn_unbind(xenevtchn_handle *xce, evtchn_port= _t port) return ioctl(fd, IOCTL_EVTCHN_UNBIND, &unbind); } =20 -xenevtchn_port_or_error_t xenevtchn_bind_virq(xenevtchn_handle *xce, unsig= ned int virq) +xenevtchn_port_or_error_t xenevtchn_bind_virq(xenevtchn_handle *xce, + unsigned int virq) { int fd =3D xce->fd; struct ioctl_evtchn_bind_virq bind; @@ -120,7 +127,7 @@ xenevtchn_port_or_error_t xenevtchn_bind_virq(xenevtchn= _handle *xce, unsigned in bind.virq =3D virq; =20 err =3D ioctl(fd, IOCTL_EVTCHN_BIND_VIRQ, &bind); - if (err) + if ( err ) return -1; else return bind.port; @@ -140,6 +147,7 @@ xenevtchn_port_or_error_t xenevtchn_pending(xenevtchn_h= andle *xce) int xenevtchn_unmask(xenevtchn_handle *xce, evtchn_port_t port) { int fd =3D xce->fd; + return write_exact(fd, (char *)&port, sizeof(port)); } =20 diff --git a/tools/libs/evtchn/solaris.c b/tools/libs/evtchn/solaris.c index dd41f62a24..d87abc553c 100644 --- a/tools/libs/evtchn/solaris.c +++ b/tools/libs/evtchn/solaris.c @@ -72,7 +72,8 @@ int xenevtchn_notify(xenevtchn_handle *xce, evtchn_port_t= port) return ioctl(fd, IOCTL_EVTCHN_NOTIFY, ¬ify); } =20 -xenevtchn_port_or_error_t xenevtchn_bind_unbound_port(xenevtchn_handle *xc= e, uint32_t domid) +xenevtchn_port_or_error_t xenevtchn_bind_unbound_port(xenevtchn_handle *xc= e, + uint32_t domid) { int fd =3D xce->fd; struct ioctl_evtchn_bind_unbound_port bind; @@ -82,8 +83,9 @@ xenevtchn_port_or_error_t xenevtchn_bind_unbound_port(xen= evtchn_handle *xce, uin return ioctl(fd, IOCTL_EVTCHN_BIND_UNBOUND_PORT, &bind); } =20 -xenevtchn_port_or_error_t xenevtchn_bind_interdomain(xenevtchn_handle *xce= , uint32_t domid, - evtchn_port_t remote_por= t) +xenevtchn_port_or_error_t xenevtchn_bind_interdomain(xenevtchn_handle *xce, + uint32_t domid, + evtchn_port_t remote_= port) { int fd =3D xce->fd; struct ioctl_evtchn_bind_interdomain bind; @@ -94,7 +96,8 @@ xenevtchn_port_or_error_t xenevtchn_bind_interdomain(xene= vtchn_handle *xce, uint return ioctl(fd, IOCTL_EVTCHN_BIND_INTERDOMAIN, &bind); } =20 -xenevtchn_port_or_error_t xenevtchn_bind_virq(xenevtchn_handle *xce, unsig= ned int virq) +xenevtchn_port_or_error_t xenevtchn_bind_virq(xenevtchn_handle *xce, + unsigned int virq) { int fd =3D xce->fd; struct ioctl_evtchn_bind_virq bind; @@ -128,6 +131,7 @@ xenevtchn_port_or_error_t xenevtchn_pending(xenevtchn_h= andle *xce) int xenevtchn_unmask(xenevtchn_handle *xce, evtchn_port_t port) { int fd =3D xce->fd; + return write_exact(fd, (char *)&port, sizeof(port)); } =20 --=20 2.26.2 From nobody Mon Apr 29 15:17:07 2024 Delivered-To: importer@patchew.org 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; 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; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1610699452; cv=none; d=zohomail.com; s=zohoarc; b=oBAIzOBEitz55seRQlCwH57HqPOlXJLrBg5NK293fN60LDX5/Rbb9+Tc0ZphDgdpOHRafLV1cpayH83Z8DqnoRzbkWd5XsZAwXus9itNOI4BBaAlgA1NOm9uf6+TEeyQKUfgnQhgHm9G19fPSX3dDzrkKfNRomXrh6Txk40tb0Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610699452; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=zcn+xkOoEdyR1SXn418KZH0aSy9L0cWXxWWj75I5evc=; b=GvO52Gqf9TC/2cXBJdZ7anrpKu5MFOB692IRxNHp6gOSSRY36Qkx7uGesJcbFSJKSj1XlR42H+hg+AeZctF8rHqtS0W4ANJbVU49ehR7LBcVQxFiZhBWg+jS1O+e2xnSVvTqRj9yNvE/noEE4mR6O677WP0wzcXdCySXVyZvsyU= ARC-Authentication-Results: i=1; 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; dmarc=pass header.from= (p=quarantine dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1610699452758899.0977947549737; Fri, 15 Jan 2021 00:30:52 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.67724.121106 (Exim 4.92) (envelope-from ) id 1l0KVC-0000V7-09; Fri, 15 Jan 2021 08:30:38 +0000 Received: by outflank-mailman (output) from mailman id 67724.121106; Fri, 15 Jan 2021 08:30:37 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l0KVB-0000Uu-Q3; Fri, 15 Jan 2021 08:30:37 +0000 Received: by outflank-mailman (input) for mailman id 67724; Fri, 15 Jan 2021 08:30:36 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l0KVA-0008HA-Nf for xen-devel@lists.xenproject.org; Fri, 15 Jan 2021 08:30:36 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id aedc45ed-65b0-445f-9921-eee7d386927b; Fri, 15 Jan 2021 08:30:11 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id DA962B987; Fri, 15 Jan 2021 08:30:06 +0000 (UTC) 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: aedc45ed-65b0-445f-9921-eee7d386927b X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1610699407; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=zcn+xkOoEdyR1SXn418KZH0aSy9L0cWXxWWj75I5evc=; b=qjG4F0py+5eHs8pbkghAZh01SrH7McaLgg/mhPT1bCI8JQVvIWtVuSUCBHnvD8dkGE4F/D IVg3cWCgPYUGjFarypEu+a6oUsVtcOIW4gnFdHEG81McVmOm0ogXLz4xwqR85L9LlAeJnT TkbVeMRHzGOhjL0eTeckJSdysR2zxeE= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Ian Jackson , Wei Liu , Andrew Cooper Subject: [PATCH v12 02/27] tools/libxenevtchn: rename open_flags to flags Date: Fri, 15 Jan 2021 09:29:35 +0100 Message-Id: <20210115083000.14186-3-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210115083000.14186-1-jgross@suse.com> References: <20210115083000.14186-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) Content-Type: text/plain; charset="utf-8" Rename the xenevtchn_open() parameter open_flags to flags as it might be used for things not passed on to open(). No functional change. No API/ABI changes. Suggested-by: Andrew Cooper Signed-off-by: Juergen Gross Reviewed-by: Andrew Cooper --- V11: - new patch (Andrew Cooper) V12: - added "No API/ABI changes" to commit message (Andrew Cooper) --- tools/include/xenevtchn.h | 2 +- tools/libs/evtchn/core.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/include/xenevtchn.h b/tools/include/xenevtchn.h index 91821ee56d..3e9b6e7323 100644 --- a/tools/include/xenevtchn.h +++ b/tools/include/xenevtchn.h @@ -67,7 +67,7 @@ struct xentoollog_logger; */ /* Currently no flags are defined */ xenevtchn_handle *xenevtchn_open(struct xentoollog_logger *logger, - unsigned open_flags); + unsigned int flags); =20 /* * Close a handle previously allocated with xenevtchn_open(). diff --git a/tools/libs/evtchn/core.c b/tools/libs/evtchn/core.c index 8090d0ce87..72d92e28bf 100644 --- a/tools/libs/evtchn/core.c +++ b/tools/libs/evtchn/core.c @@ -29,7 +29,7 @@ static int all_restrict_cb(Xentoolcore__Active_Handle *ah= , domid_t domid) return xenevtchn_restrict(xce, domid); } =20 -xenevtchn_handle *xenevtchn_open(xentoollog_logger *logger, unsigned open_= flags) +xenevtchn_handle *xenevtchn_open(xentoollog_logger *logger, unsigned int f= lags) { xenevtchn_handle *xce =3D malloc(sizeof(*xce)); int rc; --=20 2.26.2 From nobody Mon Apr 29 15:17:07 2024 Delivered-To: importer@patchew.org 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; 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; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1610699443; cv=none; d=zohomail.com; s=zohoarc; b=e71uKC72Ruz2sn5O015sj1yfY0ajQPcU7B4EmzylTsA9yA0qWebJo1Kwmmfi4rkGwlqp8yF67Uu2pBpBdrpRje/Vx2uHT41T7kv7KYtqrGWLZZf1OJ/sGD21qjJwaUcD4PJ3VOqTq7hnWLX3eO9hCNIfna11i0Dfzn3C22I9l44= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610699443; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=2ty1vNslOkhiniDqlzVqywbvjS91QpdBVLX1o3V8OmA=; b=PZXzl335XpeX1uH3qvJcU1xoBcaZxZ+atMk76oH4FROsX0R9P78VOmuJvaNBcGLpSKaF13xW3Ebos8GHHZel/62SYD2ZayF3MWtSTsgf4aYWA+BBFrjDzlvxRJb8LgNIpzfnzgMltk/rN6ItsWDLZ6mEKjvEdT/PQGAoQ2c9ioI= ARC-Authentication-Results: i=1; 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; dmarc=pass header.from= (p=quarantine dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1610699443678835.4571481565528; Fri, 15 Jan 2021 00:30:43 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.67717.121035 (Exim 4.92) (envelope-from ) id 1l0KUx-0008Sp-8v; Fri, 15 Jan 2021 08:30:23 +0000 Received: by outflank-mailman (output) from mailman id 67717.121035; Fri, 15 Jan 2021 08:30:23 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l0KUx-0008SY-5J; Fri, 15 Jan 2021 08:30:23 +0000 Received: by outflank-mailman (input) for mailman id 67717; Fri, 15 Jan 2021 08:30:21 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l0KUv-0008HA-N0 for xen-devel@lists.xenproject.org; Fri, 15 Jan 2021 08:30:21 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 6b4562b5-5eb4-442e-a23b-3cea9cb99d49; Fri, 15 Jan 2021 08:30:10 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id D73D9B96F; Fri, 15 Jan 2021 08:30:06 +0000 (UTC) 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: 6b4562b5-5eb4-442e-a23b-3cea9cb99d49 X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1610699407; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2ty1vNslOkhiniDqlzVqywbvjS91QpdBVLX1o3V8OmA=; b=It/kK8ZrfF8B6FYlDn45C5KHGRSqnhkURlJoc/X362NuwuzhgqeqsGVmat6L3CN9DY0GrV mYTUQGAnYqsY3zM6qjxgg9ZE0CE0wI5u+O41saHa4r1LGiGyMPMnSrflZngTp2B+8QU8Lr 6dSe1668SAu2BRJpFFRhRuYbAubbZa8= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Ian Jackson , Wei Liu , Andrew Cooper Subject: [PATCH v12 03/27] tools/libxenevtchn: check xenevtchn_open() flags for not supported bits Date: Fri, 15 Jan 2021 09:29:36 +0100 Message-Id: <20210115083000.14186-4-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210115083000.14186-1-jgross@suse.com> References: <20210115083000.14186-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) Content-Type: text/plain; charset="utf-8" Refuse a call of xenevtchn_open() with unsupported bits in flags being set. This will change behavior for callers passing junk in flags today, but those would otherwise get probably unwanted side effects when the flags they specify today get any meaning. So checking flags is the right thing to do. Suggested-by: Andrew Cooper Signed-off-by: Juergen Gross Reviewed-by: Andrew Cooper --- V11: - new patch (Andrew Cooper) V12: - expanded commit message (Andrew Cooper) --- tools/libs/evtchn/core.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/tools/libs/evtchn/core.c b/tools/libs/evtchn/core.c index 72d92e28bf..79990d0027 100644 --- a/tools/libs/evtchn/core.c +++ b/tools/libs/evtchn/core.c @@ -13,6 +13,7 @@ * License along with this library; If not, see . */ =20 +#include #include #include =20 @@ -31,9 +32,16 @@ static int all_restrict_cb(Xentoolcore__Active_Handle *a= h, domid_t domid) =20 xenevtchn_handle *xenevtchn_open(xentoollog_logger *logger, unsigned int f= lags) { - xenevtchn_handle *xce =3D malloc(sizeof(*xce)); + xenevtchn_handle *xce; int rc; =20 + if ( flags ) + { + errno =3D EINVAL; + return NULL; + } + + xce =3D malloc(sizeof(*xce)); if ( !xce ) return NULL; =20 --=20 2.26.2 From nobody Mon Apr 29 15:17:07 2024 Delivered-To: importer@patchew.org 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; 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; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1610699442; cv=none; d=zohomail.com; s=zohoarc; b=HBRO7/17DjCn5093LqdZPNbOEHD8uA9y+mbvxJAo6PDs5kxPMmEh5ddiQm45UgV89R1OjnOTcYpButFczof0+SPKfJuSHJppxGov/TBVfpxLHdNzxv1QDk7Gfd29QXvu+cd9p0YaqOTOeb8Ms5gMTENBn2DURi9XUjp+g1ezD7U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610699442; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=5tsWfbx6iMqKxvnR5GrO27JNZTi4P4HPe+MGlLpmMpw=; b=HhtY+cBI7aoOwc8NsDIQIf2uOmQV+3nV+WkYWfNVPYxwqWHg7A+yA/dd/8dArC6VYOtOY77uDD+y5kX+pOZKOa7Jf/1m8+vqFOt7RVlX16dXVtljOhFnlrPvQoJwn5l0Cj5Ivg+LMcCk3szpqh1j8KTAYAIHDMfOE3hnEzvFRdY= ARC-Authentication-Results: i=1; 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; dmarc=pass header.from= (p=quarantine dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1610699442373497.18213954835244; Fri, 15 Jan 2021 00:30:42 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.67715.121011 (Exim 4.92) (envelope-from ) id 1l0KUs-0008M7-Ck; Fri, 15 Jan 2021 08:30:18 +0000 Received: by outflank-mailman (output) from mailman id 67715.121011; Fri, 15 Jan 2021 08:30:18 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l0KUs-0008Ly-7w; Fri, 15 Jan 2021 08:30:18 +0000 Received: by outflank-mailman (input) for mailman id 67715; Fri, 15 Jan 2021 08:30:16 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l0KUq-0008HA-Mc for xen-devel@lists.xenproject.org; Fri, 15 Jan 2021 08:30:16 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id b0d71ecf-aa53-45e4-9446-6ffb6bf2811e; Fri, 15 Jan 2021 08:30:08 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id D7474B970; Fri, 15 Jan 2021 08:30:06 +0000 (UTC) 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: b0d71ecf-aa53-45e4-9446-6ffb6bf2811e X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1610699407; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5tsWfbx6iMqKxvnR5GrO27JNZTi4P4HPe+MGlLpmMpw=; b=ozius3sj14Z6CNa/AQRtDyLgIDs2LzM1oTDi5rZk5S5yQlA+EJAnSVEdvJ8ZHN+fpzwZNI AjtOp2HDbJWkHzr6A3oVxxTic+7W2HI4fzmANe0XjUOuO4mECM4JpAHSeMxWzxFi0V1x6e FLK5fM084dzMUiiw5trIPSM8eJcOlIo= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Ian Jackson , Wei Liu , Andrew Cooper Subject: [PATCH v12 04/27] tools/libxenevtchn: propagate xenevtchn_open() flags parameter Date: Fri, 15 Jan 2021 09:29:37 +0100 Message-Id: <20210115083000.14186-5-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210115083000.14186-1-jgross@suse.com> References: <20210115083000.14186-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) Content-Type: text/plain; charset="utf-8" Propagate the flags parameter of xenevtchn_open() to the OS-specific handlers in order to enable handling them there. Signed-off-by: Juergen Gross Acked-by: Andrew Cooper --- V11: - new patch (carved out from patch 4 of V10, Andrew Cooper) --- tools/libs/evtchn/core.c | 2 +- tools/libs/evtchn/freebsd.c | 2 +- tools/libs/evtchn/linux.c | 2 +- tools/libs/evtchn/minios.c | 2 +- tools/libs/evtchn/netbsd.c | 2 +- tools/libs/evtchn/private.h | 2 +- tools/libs/evtchn/solaris.c | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/tools/libs/evtchn/core.c b/tools/libs/evtchn/core.c index 79990d0027..d3cc93e98f 100644 --- a/tools/libs/evtchn/core.c +++ b/tools/libs/evtchn/core.c @@ -60,7 +60,7 @@ xenevtchn_handle *xenevtchn_open(xentoollog_logger *logge= r, unsigned int flags) goto err; } =20 - rc =3D osdep_evtchn_open(xce); + rc =3D osdep_evtchn_open(xce, flags); if ( rc < 0 ) goto err; =20 diff --git a/tools/libs/evtchn/freebsd.c b/tools/libs/evtchn/freebsd.c index 554af122c8..bb601f350f 100644 --- a/tools/libs/evtchn/freebsd.c +++ b/tools/libs/evtchn/freebsd.c @@ -31,7 +31,7 @@ =20 #define EVTCHN_DEV "/dev/xen/evtchn" =20 -int osdep_evtchn_open(xenevtchn_handle *xce) +int osdep_evtchn_open(xenevtchn_handle *xce, unsigned int flags) { int fd =3D open(EVTCHN_DEV, O_RDWR|O_CLOEXEC); =20 diff --git a/tools/libs/evtchn/linux.c b/tools/libs/evtchn/linux.c index 4582a58ec4..62adc0e574 100644 --- a/tools/libs/evtchn/linux.c +++ b/tools/libs/evtchn/linux.c @@ -34,7 +34,7 @@ #define O_CLOEXEC 0 #endif =20 -int osdep_evtchn_open(xenevtchn_handle *xce) +int osdep_evtchn_open(xenevtchn_handle *xce, unsigned int flags) { int fd =3D open("/dev/xen/evtchn", O_RDWR|O_CLOEXEC); =20 diff --git a/tools/libs/evtchn/minios.c b/tools/libs/evtchn/minios.c index bbb313a521..3afc8e2517 100644 --- a/tools/libs/evtchn/minios.c +++ b/tools/libs/evtchn/minios.c @@ -69,7 +69,7 @@ static void port_dealloc(struct evtchn_port_info *port_in= fo) free(port_info); } =20 -int osdep_evtchn_open(xenevtchn_handle *xce) +int osdep_evtchn_open(xenevtchn_handle *xce, unsigned int flags) { int fd =3D alloc_fd(FTYPE_EVTCHN); =20 diff --git a/tools/libs/evtchn/netbsd.c b/tools/libs/evtchn/netbsd.c index 53f9299ebb..60a9235978 100644 --- a/tools/libs/evtchn/netbsd.c +++ b/tools/libs/evtchn/netbsd.c @@ -31,7 +31,7 @@ =20 #define EVTCHN_DEV_NAME "/dev/xenevt" =20 -int osdep_evtchn_open(xenevtchn_handle *xce) +int osdep_evtchn_open(xenevtchn_handle *xce, unsigned int flags) { int fd =3D open(EVTCHN_DEV_NAME, O_NONBLOCK|O_RDWR); =20 diff --git a/tools/libs/evtchn/private.h b/tools/libs/evtchn/private.h index 31e595bea2..319d1996d7 100644 --- a/tools/libs/evtchn/private.h +++ b/tools/libs/evtchn/private.h @@ -14,7 +14,7 @@ struct xenevtchn_handle { Xentoolcore__Active_Handle tc_ah; }; =20 -int osdep_evtchn_open(xenevtchn_handle *xce); +int osdep_evtchn_open(xenevtchn_handle *xce, unsigned int flags); int osdep_evtchn_close(xenevtchn_handle *xce); int osdep_evtchn_restrict(xenevtchn_handle *xce, domid_t domid); =20 diff --git a/tools/libs/evtchn/solaris.c b/tools/libs/evtchn/solaris.c index d87abc553c..df9579df17 100644 --- a/tools/libs/evtchn/solaris.c +++ b/tools/libs/evtchn/solaris.c @@ -29,7 +29,7 @@ =20 #include "private.h" =20 -int osdep_evtchn_open(xenevtchn_handle *xce) +int osdep_evtchn_open(xenevtchn_handle *xce, unsigned int flags) { int fd; =20 --=20 2.26.2 From nobody Mon Apr 29 15:17:07 2024 Delivered-To: importer@patchew.org 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; 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; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1610699441; cv=none; d=zohomail.com; s=zohoarc; b=ITO7IUCVoXfCHXA4g8/nb20MamPVO/dHZa/UkVTXXeqVnhBJIA5+3TtYPXc3OkSD6VHYEIrWI4YxOsSBNIUvFxySWRnMYY9MfAQ83S6DJiSDaaKoQESa4ukhneOUUG8ug/Ro8l+dWWBDgUX/XTfA2K/3cDSn4RF8vfsw/1g40Nk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610699441; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=TDOKCm1PBekJ/I7OVe/tbhyex8V7rdSW9/SSHYEJKQE=; b=FTt4exJ3y3jGQMABjNJIS7sUUhu5g/oOLHbyk8RSDUEhNkZDFxoEpd7ujS+KeKnxAY/RP1hccMxJOQdIAaXrwJFldyK1qp/sB5N4A0kK0QCAVSYpJcFzaNK9WULGxdUPrTHH5mcNpZmK5ZT3oAk1mkVq5KMqvbL3QukhftEWvCM= ARC-Authentication-Results: i=1; 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; dmarc=pass header.from= (p=quarantine dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1610699441405508.4897910777588; Fri, 15 Jan 2021 00:30:41 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.67714.120998 (Exim 4.92) (envelope-from ) id 1l0KUq-0008JX-2s; Fri, 15 Jan 2021 08:30:16 +0000 Received: by outflank-mailman (output) from mailman id 67714.120998; Fri, 15 Jan 2021 08:30:16 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l0KUp-0008JQ-VD; Fri, 15 Jan 2021 08:30:15 +0000 Received: by outflank-mailman (input) for mailman id 67714; Fri, 15 Jan 2021 08:30:14 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l0KUo-0008Gh-Ee for xen-devel@lists.xenproject.org; Fri, 15 Jan 2021 08:30:14 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id f24ecc88-757a-4488-9397-2a88204bbb7f; Fri, 15 Jan 2021 08:30:08 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id D6F45B96C; Fri, 15 Jan 2021 08:30:06 +0000 (UTC) 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: f24ecc88-757a-4488-9397-2a88204bbb7f X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1610699407; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=TDOKCm1PBekJ/I7OVe/tbhyex8V7rdSW9/SSHYEJKQE=; b=R6NxtkjDSpZKiQOIQXgpnyRxDVwEyOd/MmrX3tCPvzeiogY82qn4AZFK3KMC+Ee6OCzEPR HGfNLtR+ltnGxrlFx+DmJxau6B4VkIRU231uNMp13Hx1apZ4oFtUtPMQOn6b6ihCY2Bwlv gbcIC5mMvGH/+3mNPhC3Dbw9k5qT8SM= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Ian Jackson , Wei Liu , Julien Grall Subject: [PATCH v12 05/27] tools/libxenevtchn: add possibility to not close file descriptor on exec Date: Fri, 15 Jan 2021 09:29:38 +0100 Message-Id: <20210115083000.14186-6-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210115083000.14186-1-jgross@suse.com> References: <20210115083000.14186-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) Content-Type: text/plain; charset="utf-8" Today the file descriptor for the access of the event channel driver is being closed in case of exec(2). For the support of live update of a daemon using libxenevtchn this can be problematic, so add a way to keep that file descriptor open. Add support of a flag XENEVTCHN_NO_CLOEXEC for xenevtchn_open() which will result in _not_ setting O_CLOEXEC when opening the event channel driver node. The caller can then obtain the file descriptor via xenevtchn_fd(). Add an alternative open function xenevtchn_fdopen() which takes that file descriptor as an additional parameter. This allows to allocate a xenevtchn_handle and to associate it with that file descriptor. Signed-off-by: Juergen Gross Reviewed-by: Wei Liu Reviewed-by: Julien Grall --- V7: - new patch V8: - some minor comments by Julien Grall addressed V11: - rename to xenevtchn_fdopen() (Andrew Cooper) V12: - better comments in header file (Andrew Cooper) - reject flags !=3D 0 if fdopen (Andrew Cooper) - style (Andrew Cooper) --- tools/include/xenevtchn.h | 50 +++++++++++++++--------- tools/libs/evtchn/Makefile | 2 +- tools/libs/evtchn/core.c | 62 ++++++++++++++++++++++-------- tools/libs/evtchn/freebsd.c | 7 +++- tools/libs/evtchn/libxenevtchn.map | 4 ++ tools/libs/evtchn/linux.c | 6 ++- tools/libs/evtchn/minios.c | 4 ++ 7 files changed, 97 insertions(+), 38 deletions(-) diff --git a/tools/include/xenevtchn.h b/tools/include/xenevtchn.h index 3e9b6e7323..10dbe1a06e 100644 --- a/tools/include/xenevtchn.h +++ b/tools/include/xenevtchn.h @@ -42,35 +42,47 @@ struct xentoollog_logger; */ =20 /* - * Return a handle to the event channel driver, or NULL on failure, in - * which case errno will be set appropriately. + * Opens the evtchn device node. Return a handle to the event channel + * driver, or NULL on failure, in which case errno will be set + * appropriately. * - * Note: After fork(2) a child process must not use any opened evtchn - * handle inherited from their parent, nor access any grant mapped - * areas associated with that handle. + * On fork(2): * - * The child must open a new handle if they want to interact with - * evtchn. + * After fork, a child process must not use any opened evtchn handle + * inherited from their parent. This includes operations such as + * poll() on the underlying file descriptor. Calling xenevtchn_close() + * is the only safe operation on a xenevtchn_handle which has been + * inherited. * - * Calling exec(2) in a child will safely (and reliably) reclaim any - * allocated resources via a xenevtchn_handle in the parent. + * The child must open a new handle if they want to interact with + * evtchn. * - * A child which does not call exec(2) may safely call - * xenevtchn_close() on a xenevtchn_handle inherited from their - * parent. This will attempt to reclaim any resources associated with - * that handle. Note that in some implementations this reclamation may - * not be completely effective, in this case any affected resources - * remain allocated. + * On exec(2): * - * Calling xenevtchn_close() is the only safe operation on a - * xenevtchn_handle which has been inherited. + * Wherever possible, the device node will be opened with O_CLOEXEC, + * so it is not inherited by the subsequent program. + * + * However the XENEVTCHN_NO_CLOEXEC flag may be used to avoid opening + * the device node with O_CLOEXEC. This is intended for use by + * daemons which support a self-reexec method of updating themselves. + * + * In this case, the updated daemon should pass the underlying file + * descriptor it inherited to xenevtchn_fdopen() to reconstruct the + * library handle. */ -/* Currently no flags are defined */ + +/* Don't set O_CLOEXEC when opening event channel driver node. */ +#define XENEVTCHN_NO_CLOEXEC (1U <<0) + xenevtchn_handle *xenevtchn_open(struct xentoollog_logger *logger, unsigned int flags); =20 +/* Flag XENEVTCHN_NO_CLOEXEC is rejected by xenevtchn_fdopen(). */ +xenevtchn_handle *xenevtchn_fdopen(struct xentoollog_logger *logger, + int fd, unsigned open_flags); + /* - * Close a handle previously allocated with xenevtchn_open(). + * Close a handle previously allocated with xenevtchn_{,fd}open(). */ int xenevtchn_close(xenevtchn_handle *xce); =20 diff --git a/tools/libs/evtchn/Makefile b/tools/libs/evtchn/Makefile index ad01a17b3d..b8c37b5b97 100644 --- a/tools/libs/evtchn/Makefile +++ b/tools/libs/evtchn/Makefile @@ -2,7 +2,7 @@ XEN_ROOT =3D $(CURDIR)/../../.. include $(XEN_ROOT)/tools/Rules.mk =20 MAJOR =3D 1 -MINOR =3D 1 +MINOR =3D 2 =20 SRCS-y +=3D core.c SRCS-$(CONFIG_Linux) +=3D linux.c diff --git a/tools/libs/evtchn/core.c b/tools/libs/evtchn/core.c index d3cc93e98f..abebf72559 100644 --- a/tools/libs/evtchn/core.c +++ b/tools/libs/evtchn/core.c @@ -30,18 +30,10 @@ static int all_restrict_cb(Xentoolcore__Active_Handle *= ah, domid_t domid) return xenevtchn_restrict(xce, domid); } =20 -xenevtchn_handle *xenevtchn_open(xentoollog_logger *logger, unsigned int f= lags) +static xenevtchn_handle *xenevtchn_alloc_handle(xentoollog_logger *logger) { - xenevtchn_handle *xce; - int rc; - - if ( flags ) - { - errno =3D EINVAL; - return NULL; - } + xenevtchn_handle *xce =3D malloc(sizeof(*xce)); =20 - xce =3D malloc(sizeof(*xce)); if ( !xce ) return NULL; =20 @@ -60,21 +52,59 @@ xenevtchn_handle *xenevtchn_open(xentoollog_logger *log= ger, unsigned int flags) goto err; } =20 + return xce; + +err: + xenevtchn_close(xce); + return NULL; +} + +xenevtchn_handle *xenevtchn_open(xentoollog_logger *logger, unsigned int f= lags) +{ + xenevtchn_handle *xce; + int rc; + + if ( flags & ~XENEVTCHN_NO_CLOEXEC ) + { + errno =3D EINVAL; + return NULL; + } + + xce =3D xenevtchn_alloc_handle(logger); + if ( !xce ) + return NULL; + rc =3D osdep_evtchn_open(xce, flags); if ( rc < 0 ) goto err; =20 return xce; =20 - err: - xentoolcore__deregister_active_handle(&xce->tc_ah); - osdep_evtchn_close(xce); - xtl_logger_destroy(xce->logger_tofree); - free(xce); - +err: + xenevtchn_close(xce); return NULL; } =20 +xenevtchn_handle *xenevtchn_fdopen(struct xentoollog_logger *logger, + int fd, unsigned int flags) +{ + xenevtchn_handle *xce; + + if ( flags ) + { + errno =3D EINVAL; + return NULL; + } + + xce =3D xenevtchn_alloc_handle(logger); + if ( !xce ) + return NULL; + + xce->fd =3D fd; + + return xce; +} + int xenevtchn_close(xenevtchn_handle *xce) { int rc; diff --git a/tools/libs/evtchn/freebsd.c b/tools/libs/evtchn/freebsd.c index bb601f350f..7427ab2408 100644 --- a/tools/libs/evtchn/freebsd.c +++ b/tools/libs/evtchn/freebsd.c @@ -33,8 +33,13 @@ =20 int osdep_evtchn_open(xenevtchn_handle *xce, unsigned int flags) { - int fd =3D open(EVTCHN_DEV, O_RDWR|O_CLOEXEC); + int open_flags =3D O_RDWR; + int fd; =20 + if ( !(flags & XENEVTCHN_NO_CLOEXEC) ) + open_flags |=3D O_CLOEXEC; + + fd =3D open(EVTCHN_DEV, open_flags); if ( fd =3D=3D -1 ) return -1; =20 diff --git a/tools/libs/evtchn/libxenevtchn.map b/tools/libs/evtchn/libxene= vtchn.map index 33a38f953a..4c180ea65d 100644 --- a/tools/libs/evtchn/libxenevtchn.map +++ b/tools/libs/evtchn/libxenevtchn.map @@ -21,3 +21,7 @@ VERS_1.1 { global: xenevtchn_restrict; } VERS_1.0; +VERS_1.2 { + global: + xenevtchn_fdopen; +} VERS_1.1; diff --git a/tools/libs/evtchn/linux.c b/tools/libs/evtchn/linux.c index 62adc0e574..60bb75a791 100644 --- a/tools/libs/evtchn/linux.c +++ b/tools/libs/evtchn/linux.c @@ -36,8 +36,12 @@ =20 int osdep_evtchn_open(xenevtchn_handle *xce, unsigned int flags) { - int fd =3D open("/dev/xen/evtchn", O_RDWR|O_CLOEXEC); + int open_flags =3D O_RDWR; + int fd; =20 + if ( !(flags & XENEVTCHN_NO_CLOEXEC) ) + open_flags |=3D O_CLOEXEC; + fd =3D open("/dev/xen/evtchn", open_flags); if ( fd =3D=3D -1 ) return -1; =20 diff --git a/tools/libs/evtchn/minios.c b/tools/libs/evtchn/minios.c index 3afc8e2517..57f712ade3 100644 --- a/tools/libs/evtchn/minios.c +++ b/tools/libs/evtchn/minios.c @@ -69,6 +69,10 @@ static void port_dealloc(struct evtchn_port_info *port_i= nfo) free(port_info); } =20 +/* + * XENEVTCHN_NO_CLOEXEC is being ignored, as there is no exec() call suppo= rted + * in Mini-OS. + */ int osdep_evtchn_open(xenevtchn_handle *xce, unsigned int flags) { int fd =3D alloc_fd(FTYPE_EVTCHN); --=20 2.26.2 From nobody Mon Apr 29 15:17:07 2024 Delivered-To: importer@patchew.org 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; 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; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1610699449; cv=none; d=zohomail.com; s=zohoarc; b=fb7sZ6srlhq1+L10BPYBUSRky/VqMUbf7eHUJlNpniR/ODqycgGRoVRcEplnvHtJT28cEoga4d9L1CW+AHni8eBFSuwPF4UI5oMXilpJjpSKwWPB29MnmFBZXXLw55TnkNqPhGdapnb78JCa/q/Yf8PYYrDQPdCujUIiuIfmij8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610699449; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=O/DEREX1kMq5zoH/CbxrwUSJ5+uKCnvjpzSN2JoigQo=; b=Q3Hs3Wf/wHkxhG6Yl7FR5ooNtLfa0iB0el8JZpkxzTuBSCIj+orcrHkgbESG7W4hzA3gfgUaycSCeNyD2i/YhhaQpX6gEf9chLC1gA9RxGLdjHMnJpwYHOkjEj+uTQnZ4UpL3tPLvW41Yjx3VfBxFnZNnQPSqae3B9xpIu9pKfw= ARC-Authentication-Results: i=1; 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; dmarc=pass header.from= (p=quarantine dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1610699449070385.60063318190964; Fri, 15 Jan 2021 00:30:49 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.67721.121083 (Exim 4.92) (envelope-from ) id 1l0KV8-0000MS-0Z; Fri, 15 Jan 2021 08:30:34 +0000 Received: by outflank-mailman (output) from mailman id 67721.121083; Fri, 15 Jan 2021 08:30:33 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l0KV7-0000ME-Qy; Fri, 15 Jan 2021 08:30:33 +0000 Received: by outflank-mailman (input) for mailman id 67721; Fri, 15 Jan 2021 08:30:31 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l0KV5-0008HA-NO for xen-devel@lists.xenproject.org; Fri, 15 Jan 2021 08:30:31 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 706bb988-6d4b-4e34-a634-1d3daf47b475; Fri, 15 Jan 2021 08:30:10 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id D6D2BB96A; Fri, 15 Jan 2021 08:30:06 +0000 (UTC) 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: 706bb988-6d4b-4e34-a634-1d3daf47b475 X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1610699407; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=O/DEREX1kMq5zoH/CbxrwUSJ5+uKCnvjpzSN2JoigQo=; b=Hq87GsTw5jUuS8YCiKWxuNTNUr2XJGn3eDsQTF2hh8LRfy99wO31DrsKUdlMzR/KCuhBjq kCc2TpQLn0VH+hk9aFKPXF1eEvWlpR3bUnbd8U/5MoZeQ7AaGidNhPJdoMcvIJt3KvTwc3 RFEYfFZ6raKoZiDrB3ztFtrLa5sTHt0= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Ian Jackson , Wei Liu , Julien Grall , Paul Durrant Subject: [PATCH v12 06/27] tools/xenstore: refactor XS_CONTROL handling Date: Fri, 15 Jan 2021 09:29:39 +0100 Message-Id: <20210115083000.14186-7-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210115083000.14186-1-jgross@suse.com> References: <20210115083000.14186-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) Content-Type: text/plain; charset="utf-8" In order to allow control commands with binary data refactor handling of XS_CONTROL: - get primary command first - add maximum number of additional parameters to pass to command handler Signed-off-by: Juergen Gross Reviewed-by: Julien Grall Reviewed-by: Paul Durrant --- V2: - add comment regarding max_pars (Pawel Wieczorkiewicz) V3: - addressed Paul's comments --- tools/xenstore/xenstored_control.c | 34 ++++++++++++++++++++---------- tools/xenstore/xenstored_core.c | 3 +-- tools/xenstore/xenstored_core.h | 1 + 3 files changed, 25 insertions(+), 13 deletions(-) diff --git a/tools/xenstore/xenstored_control.c b/tools/xenstore/xenstored_= control.c index 8d48ab4820..8d29db8270 100644 --- a/tools/xenstore/xenstored_control.c +++ b/tools/xenstore/xenstored_control.c @@ -30,6 +30,14 @@ struct cmd_s { char *cmd; int (*func)(void *, struct connection *, char **, int); char *pars; + /* + * max_pars can be used to limit the size of the parameter vector, + * e.g. in case of large binary parts in the parameters. + * The command is included in the count, so 1 means just the command + * without any parameter. + * 0 =3D=3D no limit (the default) + */ + unsigned int max_pars; }; =20 static int do_control_check(void *ctx, struct connection *conn, @@ -194,25 +202,29 @@ static int do_control_help(void *ctx, struct connecti= on *conn, =20 int do_control(struct connection *conn, struct buffered_data *in) { - int num; - int cmd; - char **vec; + unsigned int cmd, num, off; + char **vec =3D NULL; =20 if (conn->id !=3D 0) return EACCES; =20 - num =3D xs_count_strings(in->buffer, in->used); - if (num < 1) + off =3D get_string(in, 0); + if (!off) + return EINVAL; + for (cmd =3D 0; cmd < ARRAY_SIZE(cmds); cmd++) + if (streq(in->buffer, cmds[cmd].cmd)) + break; + if (cmd =3D=3D ARRAY_SIZE(cmds)) return EINVAL; + + num =3D xs_count_strings(in->buffer, in->used); + if (cmds[cmd].max_pars) + num =3D min(num, cmds[cmd].max_pars); vec =3D talloc_array(in, char *, num); if (!vec) return ENOMEM; - if (get_strings(in, vec, num) !=3D num) + if (get_strings(in, vec, num) < num) return EIO; =20 - for (cmd =3D 0; cmd < ARRAY_SIZE(cmds); cmd++) - if (streq(vec[0], cmds[cmd].cmd)) - return cmds[cmd].func(in, conn, vec + 1, num - 1); - - return EINVAL; + return cmds[cmd].func(in, conn, vec + 1, num - 1); } diff --git a/tools/xenstore/xenstored_core.c b/tools/xenstore/xenstored_cor= e.c index 50986f8b29..e1b92c3dc8 100644 --- a/tools/xenstore/xenstored_core.c +++ b/tools/xenstore/xenstored_core.c @@ -620,8 +620,7 @@ static struct buffered_data *new_buffer(void *ctx) /* Return length of string (including nul) at this offset. * If there is no nul, returns 0 for failure. */ -static unsigned int get_string(const struct buffered_data *data, - unsigned int offset) +unsigned int get_string(const struct buffered_data *data, unsigned int off= set) { const char *nul; =20 diff --git a/tools/xenstore/xenstored_core.h b/tools/xenstore/xenstored_cor= e.h index fb59d862a2..27826c125c 100644 --- a/tools/xenstore/xenstored_core.h +++ b/tools/xenstore/xenstored_core.h @@ -142,6 +142,7 @@ const char *onearg(struct buffered_data *in); /* Break input into vectors, return the number, fill in up to num of them.= */ unsigned int get_strings(struct buffered_data *data, char *vec[], unsigned int num); +unsigned int get_string(const struct buffered_data *data, unsigned int off= set); =20 void send_reply(struct connection *conn, enum xsd_sockmsg_type type, const void *data, unsigned int len); --=20 2.26.2 From nobody Mon Apr 29 15:17:07 2024 Delivered-To: importer@patchew.org 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; 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; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1610699958; cv=none; d=zohomail.com; s=zohoarc; b=Hbj7tBhGn6Ok+zXKl5w7dnyRnt8Clhj1k61lLBRQVy9lv0hLS2TRTbGWIStnZ3F8tMC2GYOz2RIn+yquqN1+uRxj+PklMndbrSNm3Y2s8fXQXgwpvAYRhmPDMVY4xfDVG1mdf8zFWEOTlvqXYuHF0CS3Em4sgQ/yO4+31I/zFFY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610699958; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=HsL6Mc3rID019qlX5MsNpyOqL+eLxMf7VkME+T0xvLY=; b=PJalXoH1AhY/j5E4S0B1ZETy9dMuc72RspYxPw3+2CN31L0opGRuZ9fWWfOemR8BcJXGGqCsw3T+mMEn/OSCx+5M/CNyu64lr2P5Oxb5jzDFX5A9s3B6qeT8FkPJhqiuAi0E101S20HwGvGUPZQGDRQys0JJd5xKfzsohz1ZIkU= ARC-Authentication-Results: i=1; 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; dmarc=pass header.from= (p=quarantine dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1610699958822925.7176864998326; Fri, 15 Jan 2021 00:39:18 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.67773.121215 (Exim 4.92) (envelope-from ) id 1l0KdE-0002F4-EL; Fri, 15 Jan 2021 08:38:56 +0000 Received: by outflank-mailman (output) from mailman id 67773.121215; Fri, 15 Jan 2021 08:38:56 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l0KdE-0002Ex-Ad; Fri, 15 Jan 2021 08:38:56 +0000 Received: by outflank-mailman (input) for mailman id 67773; Fri, 15 Jan 2021 08:38:55 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l0KVZ-0008HA-OY for xen-devel@lists.xenproject.org; Fri, 15 Jan 2021 08:31:01 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id f1689b74-caa3-485b-abda-2be48273fd9f; Fri, 15 Jan 2021 08:30:12 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id DA13BB976; Fri, 15 Jan 2021 08:30:06 +0000 (UTC) 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: f1689b74-caa3-485b-abda-2be48273fd9f X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1610699407; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=HsL6Mc3rID019qlX5MsNpyOqL+eLxMf7VkME+T0xvLY=; b=nN6Sdo6GoPhsMN+yZJuGZB2FgITdGoH6cNZSX16IisYjZkTZLHVnVQ6a0dsCUXWubTuW/T Ht6IWSul++usJWG7gGzUq5BekwprQqWKCeNoN8/D6PPdZ0eYVxOq+jVMP7h7VtfxBT+jnD YIbfFPCBLd92PjFOgViJbdKb8q5qRd4= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Andrew Cooper , George Dunlap , Ian Jackson , Jan Beulich , Julien Grall , Stefano Stabellini , Wei Liu , Paul Durrant , Julien Grall Subject: [PATCH v12 07/27] tools/xenstore: add live update command to xenstore-control Date: Fri, 15 Jan 2021 09:29:40 +0100 Message-Id: <20210115083000.14186-8-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210115083000.14186-1-jgross@suse.com> References: <20210115083000.14186-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) Content-Type: text/plain; charset="utf-8" Add the "live-update" command to xenstore-control enabling updating xenstored to a new version in a running Xen system. With -c it is possible to pass a different command line to the new instance of xenstored. This will replace the command line used for the invocation of the just running xenstored instance. The running xenstored (or xenstore-stubdom) needs to support live updating, of course. For now just add a small dummy handler to C xenstore denying any live update action. Signed-off-by: Juergen Gross Reviewed-by: Paul Durrant Reviewed-by: Julien Grall --- V2: - add 0 byte after kernel chunk - add comment regrading add_to_buf() semantics (Pawel Wieczorkiewicz) - use %u for unsigned in format (Pawel Wieczorkiewicz) - explain buffer size better (Pawel Wieczorkiewicz) - add loop around "-s" option for client side retry in case of timeout V3: - add live-update command to docs/misc/xenstore.txt (Paul Durrant) - fix indent (Paul Durrant) V4: - made several parameters const (Julien Grall) - added more details to xenstore.txt (Julien Grall) V5: - set old_binary to NULL initially (Paul Durrant) V6: - use strerror(errno) in error message (Julien Grall) V10: - make binary specification mandatory (Andrew Cooper) V11: - add sleep(1) in timeout loop (Edwin Torok) --- docs/misc/xenstore.txt | 21 ++ tools/xenstore/Makefile | 3 +- tools/xenstore/xenstore_control.c | 333 +++++++++++++++++++++++++++-- tools/xenstore/xenstored_control.c | 30 +++ 4 files changed, 370 insertions(+), 17 deletions(-) diff --git a/docs/misc/xenstore.txt b/docs/misc/xenstore.txt index 2081f20f55..1480742330 100644 --- a/docs/misc/xenstore.txt +++ b/docs/misc/xenstore.txt @@ -317,6 +317,27 @@ CONTROL |[|] Current commands are: check checks xenstored innards + live-update||+ + perform a live-update of the Xenstore daemon, only to + be used via xenstore-control command. + are implementation specific and are used for + different steps of the live-update processing. Currently + supported are: + -f specify new daemon binary + -b specify size of new stubdom binary + -d transfer chunk of new + stubdom binary + -c specify new command line to use + -s [-t ] [-F] start live update process (-t specifies + timeout in seconds to wait for active transactions + to finish, default is 60 seconds; -F will force + live update to happen even with running transactions + after timeout elapsed) + -a abort live update handling + All sub-options will return "OK" in case of success or an + error string in case of failure. -s can return "BUSY" in case + of an active transaction, a retry of -s can be done in that + case. log|on turn xenstore logging on log|off diff --git a/tools/xenstore/Makefile b/tools/xenstore/Makefile index 9a0f0d012d..ab89e22d3a 100644 --- a/tools/xenstore/Makefile +++ b/tools/xenstore/Makefile @@ -11,6 +11,7 @@ CFLAGS +=3D -include $(XEN_ROOT)/tools/config.h CFLAGS +=3D -I./include CFLAGS +=3D $(CFLAGS_libxenevtchn) CFLAGS +=3D $(CFLAGS_libxenctrl) +CFLAGS +=3D $(CFLAGS_libxenguest) CFLAGS +=3D $(CFLAGS_libxentoolcore) CFLAGS +=3D -DXEN_LIB_STORED=3D"\"$(XEN_LIB_STORED)\"" CFLAGS +=3D -DXEN_RUN_STORED=3D"\"$(XEN_RUN_STORED)\"" @@ -81,7 +82,7 @@ xenstore: xenstore_client.o $(CC) $< $(LDFLAGS) $(LDLIBS_libxenstore) $(LDLIBS_libxentoolcore) $(SOCK= ET_LIBS) -o $@ $(APPEND_LDFLAGS) =20 xenstore-control: xenstore_control.o - $(CC) $< $(LDFLAGS) $(LDLIBS_libxenstore) $(LDLIBS_libxentoolcore) $(SOCK= ET_LIBS) -o $@ $(APPEND_LDFLAGS) + $(CC) $< $(LDFLAGS) $(LDLIBS_libxenstore) $(LDLIBS_libxenctrl) $(LDLIBS_l= ibxenguest) $(LDLIBS_libxentoolcore) $(SOCKET_LIBS) -o $@ $(APPEND_LDFLAGS) =20 xs_tdb_dump: xs_tdb_dump.o utils.o tdb.o talloc.o $(CC) $^ $(LDFLAGS) -o $@ $(APPEND_LDFLAGS) diff --git a/tools/xenstore/xenstore_control.c b/tools/xenstore/xenstore_co= ntrol.c index afa04495a7..6031f216c7 100644 --- a/tools/xenstore/xenstore_control.c +++ b/tools/xenstore/xenstore_control.c @@ -1,9 +1,312 @@ +#define _GNU_SOURCE +#include #include #include #include +#include +#include +#include =20 #include "xenstore.h" =20 +/* Add a string plus terminating 0 byte to buf, returning new len. */ +static int add_to_buf(char **buf, const char *val, int len) +{ + int vallen =3D strlen(val) + 1; + + if (len < 0) + return -1; + + *buf =3D realloc(*buf, len + vallen); + if (!*buf) + return -1; + + strcpy(*buf + len, val); + + return len + vallen; +} + +static int live_update_start(struct xs_handle *xsh, bool force, unsigned i= nt to) +{ + int len =3D 0; + char *buf =3D NULL, *ret; + time_t time_start; + + if (asprintf(&ret, "%u", to) < 0) + return 1; + len =3D add_to_buf(&buf, "-s", len); + len =3D add_to_buf(&buf, "-t", len); + len =3D add_to_buf(&buf, ret, len); + free(ret); + if (force) + len =3D add_to_buf(&buf, "-F", len); + if (len < 0) + return 1; + + for (time_start =3D time(NULL); time(NULL) - time_start < to;) { + ret =3D xs_control_command(xsh, "live-update", buf, len); + if (!ret) + goto err; + if (strcmp(ret, "BUSY")) + break; + sleep(1); + } + + if (strcmp(ret, "OK")) + goto err; + + free(buf); + free(ret); + + return 0; + + err: + fprintf(stderr, "Starting live update failed:\n%s\n", + ret ? : strerror(errno)); + free(buf); + free(ret); + + return 3; +} + +static int live_update_cmdline(struct xs_handle *xsh, const char *cmdline) +{ + int len =3D 0, rc =3D 0; + char *buf =3D NULL, *ret; + + len =3D add_to_buf(&buf, "-c", len); + len =3D add_to_buf(&buf, cmdline, len); + if (len < 0) + return 1; + + ret =3D xs_control_command(xsh, "live-update", buf, len); + free(buf); + if (!ret || strcmp(ret, "OK")) { + fprintf(stderr, "Setting update binary failed:\n%s\n", + ret ? : strerror(errno)); + rc =3D 3; + } + free(ret); + + return rc; +} + +static int send_kernel_blob(struct xs_handle *xsh, const char *binary) +{ + int rc =3D 0, len =3D 0; + xc_interface *xch; + struct xc_dom_image *dom; + char *ret, *buf =3D NULL; + size_t off, sz; +#define BLOB_CHUNK_SZ 2048 + + xch =3D xc_interface_open(NULL, NULL, 0); + if (!xch) { + fprintf(stderr, "xc_interface_open() failed\n"); + return 1; + } + + dom =3D xc_dom_allocate(xch, NULL, NULL); + if (!dom) { + rc =3D 1; + goto out_close; + } + + rc =3D xc_dom_kernel_file(dom, binary); + if (rc) { + rc =3D 1; + goto out_rel; + } + + if (asprintf(&ret, "%zu", dom->kernel_size) < 0) { + rc =3D 1; + goto out_rel; + } + len =3D add_to_buf(&buf, "-b", len); + len =3D add_to_buf(&buf, ret, len); + free(ret); + if (len < 0) { + rc =3D 1; + goto out_rel; + } + ret =3D xs_control_command(xsh, "live-update", buf, len); + free(buf); + if (!ret || strcmp(ret, "OK")) { + fprintf(stderr, "Starting live update failed:\n%s\n", + ret ? : strerror(errno)); + rc =3D 3; + } + free(ret); + if (rc) + goto out_rel; + + /* buf capable to hold "-d" <1..2048> BLOB_CHUNK_SZ and a terminating = 0. */ + buf =3D malloc(3 + 5 + BLOB_CHUNK_SZ + 1); + if (!buf) { + rc =3D 1; + goto out_rel; + } + + strcpy(buf, "-d"); + sz =3D BLOB_CHUNK_SZ; + for (off =3D 0; off < dom->kernel_size; off +=3D BLOB_CHUNK_SZ) { + if (dom->kernel_size - off < BLOB_CHUNK_SZ) + sz =3D dom->kernel_size - off; + sprintf(buf + 3, "%zu", sz); + len =3D 3 + strlen(buf + 3) + 1; + memcpy(buf + len, dom->kernel_blob + off, sz); + buf[len + sz] =3D 0; + len +=3D sz + 1; + ret =3D xs_control_command(xsh, "live-update", buf, len); + if (!ret || strcmp(ret, "OK")) { + fprintf(stderr, "Transfer of new binary failed:\n%s\n", + ret ? : strerror(errno)); + rc =3D 3; + free(ret); + break; + } + free(ret); + } + + free(buf); + + out_rel: + xc_dom_release(dom); + + out_close: + xc_interface_close(xch); + + return rc; +} + +/* + * Live update of Xenstore stubdom + * + * Sequence of actions: + * 1. transfer new stubdom binary + * a) specify size + * b) transfer unpacked binary in chunks + * 2. transfer new cmdline (optional) + * 3. start update (includes flags) + */ +static int live_update_stubdom(struct xs_handle *xsh, const char *binary, + const char *cmdline, bool force, unsigned i= nt to) +{ + int rc; + + rc =3D send_kernel_blob(xsh, binary); + if (rc) + goto abort; + + if (cmdline) { + rc =3D live_update_cmdline(xsh, cmdline); + if (rc) + goto abort; + } + + rc =3D live_update_start(xsh, force, to); + if (rc) + goto abort; + + return 0; + + abort: + xs_control_command(xsh, "live-update", "-a", 3); + return rc; +} + +/* + * Live update of Xenstore daemon + * + * Sequence of actions: + * 1. transfer new binary filename + * 2. transfer new cmdline (optional) + * 3. start update (includes flags) + */ +static int live_update_daemon(struct xs_handle *xsh, const char *binary, + const char *cmdline, bool force, unsigned in= t to) +{ + int len =3D 0, rc; + char *buf =3D NULL, *ret; + + len =3D add_to_buf(&buf, "-f", len); + len =3D add_to_buf(&buf, binary, len); + if (len < 0) + return 1; + ret =3D xs_control_command(xsh, "live-update", buf, len); + free(buf); + if (!ret || strcmp(ret, "OK")) { + fprintf(stderr, "Setting update binary failed:\n%s\n", + ret ? : strerror(errno)); + free(ret); + return 3; + } + free(ret); + + if (cmdline) { + rc =3D live_update_cmdline(xsh, cmdline); + if (rc) + goto abort; + } + + rc =3D live_update_start(xsh, force, to); + if (rc) + goto abort; + + return 0; + + abort: + xs_control_command(xsh, "live-update", "-a", 3); + return rc; +} + +static int live_update(struct xs_handle *xsh, int argc, char **argv) +{ + int rc =3D 0; + unsigned int i, to =3D 60; + char *binary =3D NULL, *cmdline =3D NULL, *val; + bool force =3D false; + + for (i =3D 0; i < argc; i++) { + if (!strcmp(argv[i], "-c")) { + i++; + if (i =3D=3D argc) { + fprintf(stderr, "Missing command line value\n"); + rc =3D 2; + goto out; + } + cmdline =3D argv[i]; + } else if (!strcmp(argv[i], "-t")) { + i++; + if (i =3D=3D argc) { + fprintf(stderr, "Missing timeout value\n"); + rc =3D 2; + goto out; + } + to =3D atoi(argv[i]); + } else if (!strcmp(argv[i], "-F")) + force =3D true; + else + binary =3D argv[i]; + } + + if (!binary) { + fprintf(stderr, "Missing binary specification\n"); + rc =3D 2; + goto out; + } + + val =3D xs_read(xsh, XBT_NULL, "/tool/xenstored/domid", &i); + if (val) + rc =3D live_update_stubdom(xsh, binary, cmdline, force, to); + else + rc =3D live_update_daemon(xsh, binary, cmdline, force, to); + + free(val); + + out: + return rc; +} =20 int main(int argc, char **argv) { @@ -20,22 +323,6 @@ int main(int argc, char **argv) goto out; } =20 - for (p =3D 2; p < argc; p++) - len +=3D strlen(argv[p]) + 1; - if (len) { - par =3D malloc(len); - if (!par) { - fprintf(stderr, "Allocation error.\n"); - rc =3D 1; - goto out; - } - len =3D 0; - for (p =3D 2; p < argc; p++) { - memcpy(par + len, argv[p], strlen(argv[p]) + 1); - len +=3D strlen(argv[p]) + 1; - } - } - xsh =3D xs_open(0); if (xsh =3D=3D NULL) { fprintf(stderr, "Failed to contact Xenstored.\n"); @@ -43,6 +330,19 @@ int main(int argc, char **argv) goto out; } =20 + if (!strcmp(argv[1], "live-update")) { + rc =3D live_update(xsh, argc - 2, argv + 2); + goto out_close; + } + + for (p =3D 2; p < argc; p++) + len =3D add_to_buf(&par, argv[p], len); + if (len < 0) { + fprintf(stderr, "Allocation error.\n"); + rc =3D 1; + goto out_close; + } + ret =3D xs_control_command(xsh, argv[1], par, len); if (!ret) { rc =3D 3; @@ -59,6 +359,7 @@ int main(int argc, char **argv) } else if (strlen(ret) > 0) printf("%s\n", ret); =20 + out_close: xs_close(xsh); =20 out: diff --git a/tools/xenstore/xenstored_control.c b/tools/xenstore/xenstored_= control.c index 8d29db8270..00fda5acdb 100644 --- a/tools/xenstore/xenstored_control.c +++ b/tools/xenstore/xenstored_control.c @@ -149,11 +149,41 @@ static int do_control_print(void *ctx, struct connect= ion *conn, return 0; } =20 +static int do_control_lu(void *ctx, struct connection *conn, + char **vec, int num) +{ + const char *resp; + + resp =3D talloc_strdup(ctx, "NYI"); + send_reply(conn, XS_CONTROL, resp, strlen(resp) + 1); + return 0; +} + static int do_control_help(void *, struct connection *, char **, int); =20 static struct cmd_s cmds[] =3D { { "check", do_control_check, "" }, { "log", do_control_log, "on|off" }, + + /* + * The parameters are those of the xenstore-control utility! + * Depending on environment (Mini-OS or daemon) the live-update + * sequence is split into several sub-operations: + * 1. Specification of new binary + * daemon: -f + * Mini-OS: -b + * -d (multiple of those) + * 2. New command-line (optional): -c + * 3. Start of update: -s [-F] [-t ] + * Any sub-operation needs to respond with the string "OK" in case + * of success, any other response indicates failure. + * A started live-update sequence can be aborted via "-a" (not + * needed in case of failure for the first or last live-update + * sub-operation). + */ + { "live-update", do_control_lu, + "[-c ] [-F] [-t ] \n" + " Default timeout is 60 seconds.", 4 }, #ifdef __MINIOS__ { "memreport", do_control_memreport, "" }, #else --=20 2.26.2 From nobody Mon Apr 29 15:17:07 2024 Delivered-To: importer@patchew.org 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; 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; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1610699445; cv=none; d=zohomail.com; s=zohoarc; b=XzE/8mgVOxS/v/MmehHnzFinhLYcf4HLD2UuPBaZrMQG6TtVsQb5XASdi3wgAsRgZBUTWqD+1c/S93RACgXawtqY8LXBTFHuHecZE1n5xaWgd5JAIr5O2BybHfigepZj8ozoMTy7hYCIAloaaeIzPjnJmjVsdhhwvbBexQB5MgU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610699445; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=/nflSyskC2kS0M54iM8hYwK5qRRqM3a5TA3r174vCRE=; b=GDfZDPNAljDP4stbwhCWynZIHcrk3b2wmPPIo/Ob02x4U9LLakZpo66FZlUxXWPork93eySf2gdasfb5pCKWg2jqGuaXjrvhKgc3oHOMXyTP3/mXiJKVLUtQYy1isElQVwLDUuPjjVD+LhhvYxCvByj/o4ZsAQCLilu494HP4hM= ARC-Authentication-Results: i=1; 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; dmarc=pass header.from= (p=quarantine dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1610699445401875.2404945240485; Fri, 15 Jan 2021 00:30:45 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.67713.120987 (Exim 4.92) (envelope-from ) id 1l0KUm-0008Hq-QF; Fri, 15 Jan 2021 08:30:12 +0000 Received: by outflank-mailman (output) from mailman id 67713.120987; Fri, 15 Jan 2021 08:30:12 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l0KUm-0008Hj-Mb; Fri, 15 Jan 2021 08:30:12 +0000 Received: by outflank-mailman (input) for mailman id 67713; Fri, 15 Jan 2021 08:30:11 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l0KUl-0008HA-Rj for xen-devel@lists.xenproject.org; Fri, 15 Jan 2021 08:30:11 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 98fc18d7-2de7-4d0b-bcae-8b0f8b99af13; Fri, 15 Jan 2021 08:30:08 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id D69D7B969; Fri, 15 Jan 2021 08:30:06 +0000 (UTC) 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: 98fc18d7-2de7-4d0b-bcae-8b0f8b99af13 X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1610699407; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/nflSyskC2kS0M54iM8hYwK5qRRqM3a5TA3r174vCRE=; b=CS1UFCaNAo0drccJ1jYqTbKJqBwjmlj45Z1bKpDoKCE/wXjTMJ8kkUwYNK489ULfYKx/rl G0xiWBNfwX6m4ErmoBL2fkNNwOHl22vzOkzt5AbpSbySv3uG39Hp/YzpYSIU/SrpcspxaC SSu0SMAbHz6qDU3j6JMTB5Pu3aza+FQ= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Ian Jackson , Wei Liu , Paul Durrant , Julien Grall Subject: [PATCH v12 08/27] tools/xenstore: add basic live-update command parsing Date: Fri, 15 Jan 2021 09:29:41 +0100 Message-Id: <20210115083000.14186-9-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210115083000.14186-1-jgross@suse.com> References: <20210115083000.14186-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) Content-Type: text/plain; charset="utf-8" Add the basic parts for parsing the live-update control command. For now only add the parameter evaluation and calling appropriate functions. Those function only print a message for now and return success. Signed-off-by: Juergen Gross Reviewed-by: Paul Durrant Reviewed-by: Julien Grall --- V2: - keep consistent style in lu_arch() (Pawel Wieczorkiewicz) - fix handling of force flag (Pawel Wieczorkiewicz) - use xprintf() instead of trace() for better stubdom diag - add conn parameter to subfunctions V4: - make several parameters/variables const (Julien Grall) - don't reject an option specified multiple times (Julien Grall) - use syslog() for messages --- tools/xenstore/xenstored_control.c | 105 ++++++++++++++++++++++++++++- 1 file changed, 104 insertions(+), 1 deletion(-) diff --git a/tools/xenstore/xenstored_control.c b/tools/xenstore/xenstored_= control.c index 00fda5acdb..e3f0d34528 100644 --- a/tools/xenstore/xenstored_control.c +++ b/tools/xenstore/xenstored_control.c @@ -19,7 +19,9 @@ #include #include #include +#include #include +#include =20 #include "utils.h" #include "talloc.h" @@ -149,12 +151,113 @@ static int do_control_print(void *ctx, struct connec= tion *conn, return 0; } =20 +static const char *lu_abort(const void *ctx, struct connection *conn) +{ + syslog(LOG_INFO, "live-update: abort\n"); + return NULL; +} + +static const char *lu_cmdline(const void *ctx, struct connection *conn, + const char *cmdline) +{ + syslog(LOG_INFO, "live-update: cmdline %s\n", cmdline); + return NULL; +} + +#ifdef __MINIOS__ +static const char *lu_binary_alloc(const void *ctx, struct connection *con= n, + unsigned long size) +{ + syslog(LOG_INFO, "live-update: binary size %lu\n", size); + return NULL; +} + +static const char *lu_binary_save(const void *ctx, struct connection *conn, + unsigned int size, const char *data) +{ + return NULL; +} + +static const char *lu_arch(const void *ctx, struct connection *conn, + char **vec, int num) +{ + if (num =3D=3D 2 && !strcmp(vec[0], "-b")) + return lu_binary_alloc(ctx, conn, atol(vec[1])); + if (num > 2 && !strcmp(vec[0], "-d")) + return lu_binary_save(ctx, conn, atoi(vec[1]), vec[2]); + + errno =3D EINVAL; + return NULL; +} +#else +static const char *lu_binary(const void *ctx, struct connection *conn, + const char *filename) +{ + syslog(LOG_INFO, "live-update: binary %s\n", filename); + return NULL; +} + +static const char *lu_arch(const void *ctx, struct connection *conn, + char **vec, int num) +{ + if (num =3D=3D 2 && !strcmp(vec[0], "-f")) + return lu_binary(ctx, conn, vec[1]); + + errno =3D EINVAL; + return NULL; +} +#endif + +static const char *lu_start(const void *ctx, struct connection *conn, + bool force, unsigned int to) +{ + syslog(LOG_INFO, "live-update: start, force=3D%d, to=3D%u\n", force, to); + return NULL; +} + static int do_control_lu(void *ctx, struct connection *conn, char **vec, int num) { const char *resp; + const char *ret =3D NULL; + unsigned int i; + bool force =3D false; + unsigned int to =3D 0; + + if (num < 1) + return EINVAL; + + if (!strcmp(vec[0], "-a")) { + if (num =3D=3D 1) + ret =3D lu_abort(ctx, conn); + else + return EINVAL; + } else if (!strcmp(vec[0], "-c")) { + if (num =3D=3D 2) + ret =3D lu_cmdline(ctx, conn, vec[1]); + else + return EINVAL; + } else if (!strcmp(vec[0], "-s")) { + for (i =3D 1; i < num; i++) { + if (!strcmp(vec[i], "-F")) + force =3D true; + else if (!strcmp(vec[i], "-t") && i < num - 1) { + i++; + to =3D atoi(vec[i]); + } else + return EINVAL; + } + ret =3D lu_start(ctx, conn, force, to); + } else { + errno =3D 0; + ret =3D lu_arch(ctx, conn, vec, num); + if (errno) + return errno; + } =20 - resp =3D talloc_strdup(ctx, "NYI"); + if (!ret) + ret =3D "OK"; + resp =3D talloc_strdup(ctx, ret); send_reply(conn, XS_CONTROL, resp, strlen(resp) + 1); return 0; } --=20 2.26.2 From nobody Mon Apr 29 15:17:07 2024 Delivered-To: importer@patchew.org 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; 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; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1610699440; cv=none; d=zohomail.com; s=zohoarc; b=WsOoi1p7KAep3wNDXc7/YIMwaIUEtLppb0o96mex2IkDFTol2UEzg48ufH8/ldBSgzRnUWaeWBIOlj/Wo8lLUqRI4bRZD1PBkQ/5wenWYraOiTNjrHszv89WstEK7GpXc3knLMYq/BVC42UkMRhBn9m8iK23mBF2qiOuanPF8zQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610699440; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=owep/JxQmqtOU8OwJCv1cz7UUEHgQaXcLN5SkEV6rDc=; b=XAJSAC+3JhByrXNcU7xbaQjWJmGUoTZokwNN0sZhU6HCPf232LL3Llr81h7V3wYe1NI8KWEQZHQ8f0fwwv1kWpUBfEDNxrjSQ/x8qxofH93A0Zq6mHBvCjMhOqE9br2exdDVmD/VlmDCJol1dK5r35DnzcXrvTIqsSyYPyVaTHg= ARC-Authentication-Results: i=1; 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; dmarc=pass header.from= (p=quarantine dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1610699440934925.525568760104; Fri, 15 Jan 2021 00:30:40 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.67716.121023 (Exim 4.92) (envelope-from ) id 1l0KUv-0008QG-SC; Fri, 15 Jan 2021 08:30:21 +0000 Received: by outflank-mailman (output) from mailman id 67716.121023; Fri, 15 Jan 2021 08:30:21 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l0KUv-0008Q3-NT; Fri, 15 Jan 2021 08:30:21 +0000 Received: by outflank-mailman (input) for mailman id 67716; Fri, 15 Jan 2021 08:30:19 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l0KUt-0008Gh-F4 for xen-devel@lists.xenproject.org; Fri, 15 Jan 2021 08:30:19 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 578c276a-89fa-4578-8521-f7acf1eb81dc; Fri, 15 Jan 2021 08:30:12 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id DAF47B989; Fri, 15 Jan 2021 08:30:06 +0000 (UTC) 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: 578c276a-89fa-4578-8521-f7acf1eb81dc X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1610699407; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=owep/JxQmqtOU8OwJCv1cz7UUEHgQaXcLN5SkEV6rDc=; b=dJfo4ZOmh9lh/y1Mfx9IDhl1y7sBCRCzOdEZBHDYtQwPzit+bQKQGxIJdAHBobiO5u/UBF AUmFKT+gmhgUM6aMlnc+J58MJtP3Br70X+fsqailDUcG7W+n2p2Zeaytp/24luabMPLUaw o6eCoGMc20EU/Knj5IOLLQP1UoTIYTM= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Ian Jackson , Wei Liu , Paul Durrant , Julien Grall Subject: [PATCH v12 09/27] tools/xenstore: introduce live update status block Date: Fri, 15 Jan 2021 09:29:42 +0100 Message-Id: <20210115083000.14186-10-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210115083000.14186-1-jgross@suse.com> References: <20210115083000.14186-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) Content-Type: text/plain; charset="utf-8" Live update of Xenstore is done in multiple steps. It needs a status block holding the current state of live update and related data. It is allocated as child of the connection live update was started over in order to abort live update in case the connection is closed. Allocation of the block is done in lu_binary[_alloc](), freeing in lu_abort() (and for now in lu_start() as long as no real live-update is happening). Add tests in all live-update command handlers other than lu_abort() and lu_binary[_alloc]() for being started via the same connection as the begin of live-update. Signed-off-by: Juergen Gross Reviewed-by: Paul Durrant Reviewed-by: Julien Grall --- V2: - use talloc_zero() for allocating the status area (Julien Grall) V4: - const (Julien Grall) --- tools/xenstore/xenstored_control.c | 63 ++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/tools/xenstore/xenstored_control.c b/tools/xenstore/xenstored_= control.c index e3f0d34528..7854b7f46f 100644 --- a/tools/xenstore/xenstored_control.c +++ b/tools/xenstore/xenstored_control.c @@ -28,6 +28,34 @@ #include "xenstored_core.h" #include "xenstored_control.h" =20 +struct live_update { + /* For verification the correct connection is acting. */ + struct connection *conn; +}; + +static struct live_update *lu_status; + +static int lu_destroy(void *data) +{ + lu_status =3D NULL; + + return 0; +} + +static const char *lu_begin(struct connection *conn) +{ + if (lu_status) + return "live-update session already active."; + + lu_status =3D talloc_zero(conn, struct live_update); + if (!lu_status) + return "Allocation failure."; + lu_status->conn =3D conn; + talloc_set_destructor(lu_status, lu_destroy); + + return NULL; +} + struct cmd_s { char *cmd; int (*func)(void *, struct connection *, char **, int); @@ -154,6 +182,13 @@ static int do_control_print(void *ctx, struct connecti= on *conn, static const char *lu_abort(const void *ctx, struct connection *conn) { syslog(LOG_INFO, "live-update: abort\n"); + + if (!lu_status) + return "No live-update session active."; + + /* Destructor will do the real abort handling. */ + talloc_free(lu_status); + return NULL; } =20 @@ -161,6 +196,10 @@ static const char *lu_cmdline(const void *ctx, struct = connection *conn, const char *cmdline) { syslog(LOG_INFO, "live-update: cmdline %s\n", cmdline); + + if (!lu_status || lu_status->conn !=3D conn) + return "Not in live-update session."; + return NULL; } =20 @@ -168,13 +207,23 @@ static const char *lu_cmdline(const void *ctx, struct= connection *conn, static const char *lu_binary_alloc(const void *ctx, struct connection *con= n, unsigned long size) { + const char *ret; + syslog(LOG_INFO, "live-update: binary size %lu\n", size); + + ret =3D lu_begin(conn); + if (ret) + return ret; + return NULL; } =20 static const char *lu_binary_save(const void *ctx, struct connection *conn, unsigned int size, const char *data) { + if (!lu_status || lu_status->conn !=3D conn) + return "Not in live-update session."; + return NULL; } =20 @@ -193,7 +242,14 @@ static const char *lu_arch(const void *ctx, struct con= nection *conn, static const char *lu_binary(const void *ctx, struct connection *conn, const char *filename) { + const char *ret; + syslog(LOG_INFO, "live-update: binary %s\n", filename); + + ret =3D lu_begin(conn); + if (ret) + return ret; + return NULL; } =20 @@ -212,6 +268,13 @@ static const char *lu_start(const void *ctx, struct co= nnection *conn, bool force, unsigned int to) { syslog(LOG_INFO, "live-update: start, force=3D%d, to=3D%u\n", force, to); + + if (!lu_status || lu_status->conn !=3D conn) + return "Not in live-update session."; + + /* Will be replaced by real live-update later. */ + talloc_free(lu_status); + return NULL; } =20 --=20 2.26.2 From nobody Mon Apr 29 15:17:07 2024 Delivered-To: importer@patchew.org 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; 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; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1610699459; cv=none; d=zohomail.com; s=zohoarc; b=Fb5vm2QhMyzTF1JlNA8jcTVFKzQF8gc1SD/qmMFvQrDmKxDmIaWpV5X1d7168P4/Uq8jGobA+imGOcdBOkY1Cv6wEZyEqQLX4lItkcobxnL9EjKqlcQooN4bS9n9Oyq3l3LnJ9xliaYbd/c+ZveEk898/BFpJECfjBdGMcfM7Hs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610699459; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=aNFJAE4KqQnX5IjGOaMkCIzNeyfe1g2GU9xo9W5ZYdw=; b=PB5hhxqhRIpKju9twHjwALos1ZnFnlFwcRf26SfAVp961U2MjIO81+z7VuPe0hXArDs3z7D9LX+BQJBoj/9QsjilZT1V4BldBa3X2ne3dcVHzne7rYAH3TVgJY+lJNJOcXn7bDQ7Zza+5w3+zlY6XzzxODw78A6hFnbXksp0wG8= ARC-Authentication-Results: i=1; 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; dmarc=pass header.from= (p=quarantine dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 161069945954886.20792658287019; Fri, 15 Jan 2021 00:30:59 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.67727.121131 (Exim 4.92) (envelope-from ) id 1l0KVH-0000hR-Gv; Fri, 15 Jan 2021 08:30:43 +0000 Received: by outflank-mailman (output) from mailman id 67727.121131; Fri, 15 Jan 2021 08:30:43 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l0KVH-0000hG-6k; Fri, 15 Jan 2021 08:30:43 +0000 Received: by outflank-mailman (input) for mailman id 67727; Fri, 15 Jan 2021 08:30:41 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l0KVF-0008HA-Nf for xen-devel@lists.xenproject.org; Fri, 15 Jan 2021 08:30:41 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 17b8a2d1-207d-4fdc-8bba-7429192e95f2; Fri, 15 Jan 2021 08:30:11 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id D9DF0B953; Fri, 15 Jan 2021 08:30:06 +0000 (UTC) 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: 17b8a2d1-207d-4fdc-8bba-7429192e95f2 X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1610699407; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=aNFJAE4KqQnX5IjGOaMkCIzNeyfe1g2GU9xo9W5ZYdw=; b=O/tGH7W+fw0tfTY6Tw6iMpoiYgIuv6EHFlk+fgv+IuEniKhod22Txb1GlaQqGExf/hB3ar ixyj3utsuK7dAcOEQBBoqOacCoipBQNhZD/d1m1k29FNyJF5TYbJTJKb5RBMYye+mPFhYt wj7/ITktlk2whOQY6Wy8wEVckWyVhkU= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Ian Jackson , Wei Liu , Paul Durrant , Julien Grall Subject: [PATCH v12 10/27] tools/xenstore: save new binary for live update Date: Fri, 15 Jan 2021 09:29:43 +0100 Message-Id: <20210115083000.14186-11-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210115083000.14186-1-jgross@suse.com> References: <20210115083000.14186-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) Content-Type: text/plain; charset="utf-8" Save the new binary name for the daemon case and the new kernel for stubdom in order to support live update of Xenstore.. Signed-off-by: Juergen Gross Reviewed-by: Paul Durrant Reviewed-by: Julien Grall --- tools/xenstore/xenstored_control.c | 41 +++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/tools/xenstore/xenstored_control.c b/tools/xenstore/xenstored_= control.c index 7854b7f46f..95ac1a1648 100644 --- a/tools/xenstore/xenstored_control.c +++ b/tools/xenstore/xenstored_control.c @@ -1,5 +1,5 @@ /* - Interactive commands for Xen Store Daemon. +Interactive commands for Xen Store Daemon. Copyright (C) 2017 Juergen Gross, SUSE Linux GmbH =20 This program is free software; you can redistribute it and/or modify @@ -22,6 +22,9 @@ #include #include #include +#include +#include +#include =20 #include "utils.h" #include "talloc.h" @@ -31,6 +34,14 @@ struct live_update { /* For verification the correct connection is acting. */ struct connection *conn; + +#ifdef __MINIOS__ + void *kernel; + unsigned int kernel_size; + unsigned int kernel_off; +#else + char *filename; +#endif }; =20 static struct live_update *lu_status; @@ -215,6 +226,13 @@ static const char *lu_binary_alloc(const void *ctx, st= ruct connection *conn, if (ret) return ret; =20 + lu_status->kernel =3D talloc_size(lu_status, size); + if (!lu_status->kernel) + return "Allocation failure."; + + lu_status->kernel_size =3D size; + lu_status->kernel_off =3D 0; + return NULL; } =20 @@ -224,6 +242,12 @@ static const char *lu_binary_save(const void *ctx, str= uct connection *conn, if (!lu_status || lu_status->conn !=3D conn) return "Not in live-update session."; =20 + if (lu_status->kernel_off + size > lu_status->kernel_size) + return "Too much kernel data."; + + memcpy(lu_status->kernel + lu_status->kernel_off, data, size); + lu_status->kernel_off +=3D size; + return NULL; } =20 @@ -243,13 +267,23 @@ static const char *lu_binary(const void *ctx, struct = connection *conn, const char *filename) { const char *ret; + struct stat statbuf; =20 syslog(LOG_INFO, "live-update: binary %s\n", filename); =20 + if (stat(filename, &statbuf)) + return "File not accessible."; + if (!(statbuf.st_mode & (S_IXOTH | S_IXGRP | S_IXUSR))) + return "File not executable."; + ret =3D lu_begin(conn); if (ret) return ret; =20 + lu_status->filename =3D talloc_strdup(lu_status, filename); + if (!lu_status->filename) + return "Allocation failure."; + return NULL; } =20 @@ -272,6 +306,11 @@ static const char *lu_start(const void *ctx, struct co= nnection *conn, if (!lu_status || lu_status->conn !=3D conn) return "Not in live-update session."; =20 +#ifdef __MINIOS__ + if (lu_status->kernel_size !=3D lu_status->kernel_off) + return "Kernel not complete."; +#endif + /* Will be replaced by real live-update later. */ talloc_free(lu_status); =20 --=20 2.26.2 From nobody Mon Apr 29 15:17:07 2024 Delivered-To: importer@patchew.org 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; 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; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1610699468; cv=none; d=zohomail.com; s=zohoarc; b=TUORlaBDotElkuudGvE/2mlBk1s8/T74TuqYpszzKzi1huaXL0mpvLyjxI5Lywdd4dgsncwLtDA8S1KgebNhfeAKssNASgly+YNfjq1NjekoRPtjSqUvInaSXmsCgeOqAMDACzbjM1YrtEnWEzd88YdQLexxzn+Os5MvozvFMvA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610699468; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=oPsWgsu0Wo7yJeT1ib74W9U6E/lawBZhnW/z8jovZm8=; b=IUkOxUzmhS+2tManuqbmsVlzL9GF1ZbRA1hGi+GyrHvL42A3fnkxxAzRUDTEFfII22SvDHasF5n3evxnij2iiseGnI5ePFVCyGEK4hmwUDtDzs16PCnqR+15w/9ubrozA9VJLzZym+YzdXNGaOsD/cytwnjllAflIl3GH75nNM0= ARC-Authentication-Results: i=1; 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; dmarc=pass header.from= (p=quarantine dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1610699468526535.1006364103273; Fri, 15 Jan 2021 00:31:08 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.67730.121155 (Exim 4.92) (envelope-from ) id 1l0KVM-0000sT-Aj; Fri, 15 Jan 2021 08:30:48 +0000 Received: by outflank-mailman (output) from mailman id 67730.121155; Fri, 15 Jan 2021 08:30:48 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l0KVM-0000sC-5u; Fri, 15 Jan 2021 08:30:48 +0000 Received: by outflank-mailman (input) for mailman id 67730; Fri, 15 Jan 2021 08:30:46 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l0KVK-0008HA-Np for xen-devel@lists.xenproject.org; Fri, 15 Jan 2021 08:30:46 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 3590df4a-6796-4190-911e-7a3697e9c6f1; Fri, 15 Jan 2021 08:30:12 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 0296FB980; Fri, 15 Jan 2021 08:30:06 +0000 (UTC) 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: 3590df4a-6796-4190-911e-7a3697e9c6f1 X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1610699407; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=oPsWgsu0Wo7yJeT1ib74W9U6E/lawBZhnW/z8jovZm8=; b=EsCIwtmcFpDr275W1qpBeuO6jzfgrvlSKzoKiwUzijnk3+czz8xn3IdQQhGMPpZjqqRjFE s8iDL2dVZvvqq7CJk2/qWsbcpCqztDXClR1vd+5dzuOG1ndiIkutYA2+1Bw1N67zmBLdbV +iudpmj7xz+McdTIwJfELL4DY3yCslY= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Ian Jackson , Wei Liu , Julien Grall , Paul Durrant Subject: [PATCH v12 11/27] tools/xenstore: add command line handling for live update Date: Fri, 15 Jan 2021 09:29:44 +0100 Message-Id: <20210115083000.14186-12-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210115083000.14186-1-jgross@suse.com> References: <20210115083000.14186-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) Content-Type: text/plain; charset="utf-8" Updating an instance of Xenstore via live update needs to hand over the command line parameters to the updated instance. Those can be either the parameters used by the updated instance or new ones when supplied when starting the live update. So when supplied store the new command line parameters in lu_status. As it is related add a new option -U (or --live-update") to the command line of xenstored which will be added when starting the new instance. This enables to perform slightly different initializations when started as a result of live update. Signed-off-by: Juergen Gross Reviewed-by: Julien Grall Reviewed-by: Paul Durrant --- tools/xenstore/xenstored_control.c | 6 ++++++ tools/xenstore/xenstored_core.c | 7 ++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/tools/xenstore/xenstored_control.c b/tools/xenstore/xenstored_= control.c index 95ac1a1648..2e0827b9ef 100644 --- a/tools/xenstore/xenstored_control.c +++ b/tools/xenstore/xenstored_control.c @@ -42,6 +42,8 @@ struct live_update { #else char *filename; #endif + + char *cmdline; }; =20 static struct live_update *lu_status; @@ -211,6 +213,10 @@ static const char *lu_cmdline(const void *ctx, struct = connection *conn, if (!lu_status || lu_status->conn !=3D conn) return "Not in live-update session."; =20 + lu_status->cmdline =3D talloc_strdup(lu_status, cmdline); + if (!lu_status->cmdline) + return "Allocation failure."; + return NULL; } =20 diff --git a/tools/xenstore/xenstored_core.c b/tools/xenstore/xenstored_cor= e.c index e1b92c3dc8..0dddf24327 100644 --- a/tools/xenstore/xenstored_core.c +++ b/tools/xenstore/xenstored_core.c @@ -1969,6 +1969,7 @@ static struct option options[] =3D { { "internal-db", 0, NULL, 'I' }, { "verbose", 0, NULL, 'V' }, { "watch-nb", 1, NULL, 'W' }, + { "live-update", 0, NULL, 'U' }, { NULL, 0, NULL, 0 } }; =20 extern void dump_conn(struct connection *conn);=20 @@ -1983,11 +1984,12 @@ int main(int argc, char *argv[]) bool dofork =3D true; bool outputpid =3D false; bool no_domain_init =3D false; + bool live_update =3D false; const char *pidfile =3D NULL; int timeout; =20 =20 - while ((opt =3D getopt_long(argc, argv, "DE:F:HNPS:t:A:M:T:RVW:", options, + while ((opt =3D getopt_long(argc, argv, "DE:F:HNPS:t:A:M:T:RVW:U", option= s, NULL)) !=3D -1) { switch (opt) { case 'D': @@ -2045,6 +2047,9 @@ int main(int argc, char *argv[]) case 'p': priv_domid =3D strtol(optarg, NULL, 10); break; + case 'U': + live_update =3D true; + break; } } if (optind !=3D argc) --=20 2.26.2 From nobody Mon Apr 29 15:17:07 2024 Delivered-To: importer@patchew.org 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; 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; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1610699442; cv=none; d=zohomail.com; s=zohoarc; b=DnakpY0C11+ahl9V7fy77oFlVBXV+T9y8aYzG7QOj/Ddb/Aw4qZ04mqz+dG4sX6Bk3zOHebfFhF6j+UoV3qzy5rFABneTCVoJeDXdiuiCuv411st00lCBooPNlCvNMmIsSCNCLi97a2erSuynctqtxK1vEazE/m3mJrf/EPzZPs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610699442; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=nVUYv9vvkBAlWYhUlIHvlIvMtiQIrIzQ7in9vX0egqc=; b=O3HHV8HPlK6QU4HH9NsrsNkbyuA0y0OBUTn56v5MJJmY7/6o8NPIn4rX5aneLPBCbvcBC2wW2lU/XENCgE+87g82UWPCIgb+8B5/+NeOSaKihStjrT6BVN8xCHOfFG8xi8d4J2cIwBQJ2JjuTN0rSvT9I9ZLxGE2yioXT2cUghY= ARC-Authentication-Results: i=1; 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; dmarc=pass header.from= (p=quarantine dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1610699441997980.1430369173934; Fri, 15 Jan 2021 00:30:41 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.67718.121047 (Exim 4.92) (envelope-from ) id 1l0KUz-00005g-Ja; Fri, 15 Jan 2021 08:30:25 +0000 Received: by outflank-mailman (output) from mailman id 67718.121047; Fri, 15 Jan 2021 08:30:25 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l0KUz-00005U-Fo; Fri, 15 Jan 2021 08:30:25 +0000 Received: by outflank-mailman (input) for mailman id 67718; Fri, 15 Jan 2021 08:30:24 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l0KUy-0008Gh-FD for xen-devel@lists.xenproject.org; Fri, 15 Jan 2021 08:30:24 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 6d7d75af-e952-4608-b1ca-9ceed8959f2f; Fri, 15 Jan 2021 08:30:13 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 0A20AB957; Fri, 15 Jan 2021 08:30:07 +0000 (UTC) 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: 6d7d75af-e952-4608-b1ca-9ceed8959f2f X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1610699407; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=nVUYv9vvkBAlWYhUlIHvlIvMtiQIrIzQ7in9vX0egqc=; b=V0YleC+KGw2uoheouJeItfkvOavv22BajDA0QlTYrGh2C9vMTOPerDZYlK/+C2jPajgkUi /Kl96/h3w6wux+1RmiP+5OVipaDjXbRHWedkt1+nge3cA3QrDFzUCTBOdNXe4yRvABXjKP waX0rl/Ra57pHZTpuYDIuxV063MJ728= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Ian Jackson , Wei Liu Subject: [PATCH v12 12/27] tools/xenstore: add support for delaying execution of a xenstore request Date: Fri, 15 Jan 2021 09:29:45 +0100 Message-Id: <20210115083000.14186-13-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210115083000.14186-1-jgross@suse.com> References: <20210115083000.14186-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) Content-Type: text/plain; charset="utf-8" Today a Xenstore request is processed as soon as it is seen by xenstored. Add the framework for being able to delay processing of a request if the right conditions aren't met. Any delayed requests are executed at the end of the main processing loop in xenstored. They can either delay themselves again or just do their job. In order to enable the possibility of a timeout, the main loop will be paused for max one second if any requests are delayed. Signed-off-by: Juergen Gross --- V11: - new patch V12: - fix mangled patch --- tools/xenstore/xenstored_core.c | 62 ++++++++++++++++++++++++++++++++- tools/xenstore/xenstored_core.h | 21 +++++++++++ 2 files changed, 82 insertions(+), 1 deletion(-) diff --git a/tools/xenstore/xenstored_core.c b/tools/xenstore/xenstored_cor= e.c index 0dddf24327..6f556d49ef 100644 --- a/tools/xenstore/xenstored_core.c +++ b/tools/xenstore/xenstored_core.c @@ -69,6 +69,7 @@ static int xce_pollfd_idx =3D -1; static struct pollfd *fds; static unsigned int current_array_size; static unsigned int nr_fds; +static unsigned int delayed_requests; =20 static int sock =3D -1; =20 @@ -255,6 +256,53 @@ static bool write_messages(struct connection *conn) return true; } =20 +static int undelay_request(void *_req) +{ + struct delayed_request *req =3D _req; + + list_del(&req->list); + delayed_requests--; + + return 0; +} + +static void call_delayed(struct connection *conn, struct delayed_request *= req) +{ + assert(conn->in =3D=3D NULL); + conn->in =3D req->in; + + if (req->func(req)) { + undelay_request(req); + talloc_set_destructor(req, NULL); + } + + conn->in =3D NULL; +} + +int delay_request(struct connection *conn, struct buffered_data *in, + bool (*func)(struct delayed_request *), void *data) +{ + struct delayed_request *req; + + req =3D talloc(in, struct delayed_request); + if (!req) + return ENOMEM; + + /* For the case of connection being closed. */ + talloc_set_destructor(req, undelay_request); + + req->in =3D in; + req->func =3D func; + req->data =3D data; + + delayed_requests++; + list_add(&req->list, &conn->delayed); + + conn->in =3D NULL; + + return 0; +} + static int destroy_conn(void *_conn) { struct connection *conn =3D _conn; @@ -321,7 +369,8 @@ static void initialize_fds(int *p_sock_pollfd_idx, int = *ptimeout) memset(fds, 0, sizeof(struct pollfd) * current_array_size); nr_fds =3D 0; =20 - *ptimeout =3D -1; + /* In case of delayed requests pause for max 1 second. */ + *ptimeout =3D delayed_requests ? 1000 : -1; =20 if (sock !=3D -1) *p_sock_pollfd_idx =3D set_fd(sock, POLLIN|POLLPRI); @@ -1524,6 +1573,7 @@ struct connection *new_connection(connwritefn_t *writ= e, connreadfn_t *read) INIT_LIST_HEAD(&new->out_list); INIT_LIST_HEAD(&new->watches); INIT_LIST_HEAD(&new->transaction_list); + INIT_LIST_HEAD(&new->delayed); =20 list_add_tail(&new->list, &connections); talloc_set_destructor(new, destroy_conn); @@ -2215,6 +2265,16 @@ int main(int argc, char *argv[]) } } =20 + if (delayed_requests) { + list_for_each_entry(conn, &connections, list) { + struct delayed_request *req, *tmp; + + list_for_each_entry_safe(req, tmp, + &conn->delayed, list) + call_delayed(conn, req); + } + } + initialize_fds(&sock_pollfd_idx, &timeout); } } diff --git a/tools/xenstore/xenstored_core.h b/tools/xenstore/xenstored_cor= e.h index 27826c125c..d5cdf17160 100644 --- a/tools/xenstore/xenstored_core.h +++ b/tools/xenstore/xenstored_core.h @@ -61,6 +61,20 @@ struct buffered_data char default_buffer[DEFAULT_BUFFER_SIZE]; }; =20 +struct delayed_request { + /* Next delayed request. */ + struct list_head list; + + /* The delayed request. */ + struct buffered_data *in; + + /* Function to call. */ + bool (*func)(struct delayed_request *req); + + /* Further data. */ + void *data; +}; + struct connection; typedef int connwritefn_t(struct connection *, const void *, unsigned int); typedef int connreadfn_t(struct connection *, void *, unsigned int); @@ -94,6 +108,9 @@ struct connection uint32_t next_transaction_id; unsigned int transaction_started; =20 + /* List of delayed requests. */ + struct list_head delayed; + /* The domain I'm associated with, if any. */ struct domain *domain; =20 @@ -177,6 +194,10 @@ bool is_valid_nodename(const char *node); /* Get name of parent node. */ char *get_parent(const void *ctx, const char *node); =20 +/* Delay a request. */ +int delay_request(struct connection *conn, struct buffered_data *in, + bool (*func)(struct delayed_request *), void *data); + /* Tracing infrastructure. */ void trace_create(const void *data, const char *type); void trace_destroy(const void *data, const char *type); --=20 2.26.2 From nobody Mon Apr 29 15:17:07 2024 Delivered-To: importer@patchew.org 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; 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; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1610699474; cv=none; d=zohomail.com; s=zohoarc; b=BzBrSiwmw5HBATilXYIcy1onV8JbcZhsm76xutj43dJw8FtHbBFiQdg5IDaw8JspocYbTfkc6r3l3itqxpaPOjyX4+9TtU1WFhFLMC9AVA3HDn8Lim+q2RMB5cz58vuHrr2UBYSsqlAIyxmhMQ+nK6sqRc8WT3ebMquc32qfEL8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610699474; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=bNA7yQIV+PPc536mKzqlrDmeBTVpEgsNZ7LgNTDQBwY=; b=Ygpp+f09PdNSQ/9ZE/38T0/mYyC54EtjwLpQ2JOpY/iigFfH5GMmo90saNWzk7mJfEOWItiK4FOCtpp7zSJj66pMZgelIIV8iDbIjKTRbfmq2fgzAQB86V05IrL7MI3Tlse4bpdhYIvXlXi9JlmfgjT8b0aluhvKywB3GLaH544= ARC-Authentication-Results: i=1; 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; dmarc=pass header.from= (p=quarantine dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1610699474531110.52049250321147; Fri, 15 Jan 2021 00:31:14 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.67737.121179 (Exim 4.92) (envelope-from ) id 1l0KVR-000149-IW; Fri, 15 Jan 2021 08:30:53 +0000 Received: by outflank-mailman (output) from mailman id 67737.121179; Fri, 15 Jan 2021 08:30:53 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l0KVR-00013x-DC; Fri, 15 Jan 2021 08:30:53 +0000 Received: by outflank-mailman (input) for mailman id 67737; Fri, 15 Jan 2021 08:30:51 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l0KVP-0008HA-Nn for xen-devel@lists.xenproject.org; Fri, 15 Jan 2021 08:30:51 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 9a7677e3-ac82-400a-b15e-a8514fdffbee; Fri, 15 Jan 2021 08:30:13 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 12514B981; Fri, 15 Jan 2021 08:30:07 +0000 (UTC) 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: 9a7677e3-ac82-400a-b15e-a8514fdffbee X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1610699407; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=bNA7yQIV+PPc536mKzqlrDmeBTVpEgsNZ7LgNTDQBwY=; b=CyLjHnWmR3AHAlN03SApDLdrVRvZSAgl/5bsjGK0r7Fs+86r+NtMdlhkvWaIaw2XaE2/zS HcWB9ehgD1/z0YlOL9ka+7S9X4npVkPTe16Nyd64N/8jEe8eWUg8kBb1t88ypd7pqXl6qE mcCyxkcgf4cWE/xJMDC/lB+dt1AiryI= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Ian Jackson , Wei Liu Subject: [PATCH v12 13/27] tools/xenstore: add the basic framework for doing the live update Date: Fri, 15 Jan 2021 09:29:46 +0100 Message-Id: <20210115083000.14186-14-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210115083000.14186-1-jgross@suse.com> References: <20210115083000.14186-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) Content-Type: text/plain; charset="utf-8" Add the main framework for executing the live update. This for now only defines the basic execution steps with empty dummy functions. This final step returning means failure, as in case of success the new executable will have taken over. Signed-off-by: Juergen Gross --- V4: - const (Julien Grall) V11: - split lu_check_lu_allowed() - use delay_request() framework V12: - fix mangled patch --- tools/xenstore/xenstored_control.c | 69 +++++++++++++++++++++++++++++- 1 file changed, 67 insertions(+), 2 deletions(-) diff --git a/tools/xenstore/xenstored_control.c b/tools/xenstore/xenstored_= control.c index 2e0827b9ef..d3da6b8111 100644 --- a/tools/xenstore/xenstored_control.c +++ b/tools/xenstore/xenstored_control.c @@ -22,6 +22,7 @@ Interactive commands for Xen Store Daemon. #include #include #include +#include #include #include #include @@ -44,6 +45,11 @@ struct live_update { #endif =20 char *cmdline; + + /* Start parameters. */ + bool force; + unsigned int timeout; + time_t started_at; }; =20 static struct live_update *lu_status; @@ -304,6 +310,58 @@ static const char *lu_arch(const void *ctx, struct con= nection *conn, } #endif =20 +static bool lu_check_lu_allowed(void) +{ + return true; +} + +static const char *lu_reject_reason(const void *ctx) +{ + return "BUSY"; +} + +static const char *lu_dump_state(const void *ctx, struct connection *conn) +{ + return NULL; +} + +static const char *lu_activate_binary(const void *ctx) +{ + return "Not yet implemented."; +} + +static bool do_lu_start(struct delayed_request *req) +{ + time_t now =3D time(NULL); + const char *ret; + char *resp; + + if (!lu_check_lu_allowed()) { + if (now < lu_status->started_at + lu_status->timeout) + return false; + if (!lu_status->force) { + ret =3D lu_reject_reason(req); + goto out; + } + } + + /* Dump out internal state, including "OK" for live update. */ + ret =3D lu_dump_state(req->in, lu_status->conn); + if (!ret) { + /* Perform the activation of new binary. */ + ret =3D lu_activate_binary(req->in); + } + + /* We will reach this point only in case of failure. */ + out: + talloc_free(lu_status); + + resp =3D talloc_strdup(req->in, ret); + send_reply(lu_status->conn, XS_CONTROL, resp, strlen(resp) + 1); + + return true; +} + static const char *lu_start(const void *ctx, struct connection *conn, bool force, unsigned int to) { @@ -317,8 +375,11 @@ static const char *lu_start(const void *ctx, struct co= nnection *conn, return "Kernel not complete."; #endif =20 - /* Will be replaced by real live-update later. */ - talloc_free(lu_status); + lu_status->force =3D force; + lu_status->timeout =3D to; + lu_status->started_at =3D time(NULL); + + errno =3D delay_request(conn, conn->in, do_lu_start, NULL); =20 return NULL; } @@ -356,6 +417,10 @@ static int do_control_lu(void *ctx, struct connection = *conn, return EINVAL; } ret =3D lu_start(ctx, conn, force, to); + if (errno) + return errno; + if (!ret) + return 0; } else { errno =3D 0; ret =3D lu_arch(ctx, conn, vec, num); --=20 2.26.2 From nobody Mon Apr 29 15:17:07 2024 Delivered-To: importer@patchew.org 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; 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; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1610699476; cv=none; d=zohomail.com; s=zohoarc; b=HRph3SmoEDL1W1Xdd5f1R6J+6MMs46mu9brK5csaJkxeer/L4HMh+LHuRbF34PaMKhX+fJoeWjPrwwLCfopKzmDnNs4z9/EU2644eytEas+0tNwB4+wVof2xHnbAiSEMxlZ459jLjsSxidRRBgR69ufl+qYSnJ9Bd6JOvZHmEYQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610699476; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=o7E68E2skQt7ZQ6fewcb5Nlvjr3t4kMoxMxQJVoybz4=; b=Ek27U3PXyE3bktkpKGeZmKVlQQjd5+5HffSCP9DQagV3iFBxl/YwzulRQD+IbuhRZTiH6kVuAJGUxDc5LKlL51ULQu7l6gsTO/FU08nLaaLaf8N/FNTCqJu/8XzrhvZ4vDFpUunG1E/TgqG1FtkC58MWlo9hLjNBzwVkOEoGsfI= ARC-Authentication-Results: i=1; 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; dmarc=pass header.from= (p=quarantine dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1610699476827487.7272487634814; Fri, 15 Jan 2021 00:31:16 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.67742.121203 (Exim 4.92) (envelope-from ) id 1l0KVW-0001F0-Ie; Fri, 15 Jan 2021 08:30:58 +0000 Received: by outflank-mailman (output) from mailman id 67742.121203; Fri, 15 Jan 2021 08:30:58 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l0KVW-0001EX-AB; Fri, 15 Jan 2021 08:30:58 +0000 Received: by outflank-mailman (input) for mailman id 67742; Fri, 15 Jan 2021 08:30:56 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l0KVU-0008HA-O1 for xen-devel@lists.xenproject.org; Fri, 15 Jan 2021 08:30:56 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 70209202-40b6-475a-8c2c-f9e8a1e79505; Fri, 15 Jan 2021 08:30:12 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 20AFFB98B; Fri, 15 Jan 2021 08:30:07 +0000 (UTC) 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: 70209202-40b6-475a-8c2c-f9e8a1e79505 X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1610699407; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=o7E68E2skQt7ZQ6fewcb5Nlvjr3t4kMoxMxQJVoybz4=; b=GgXTlLDvG8xOlHqNKqeX70it5iMh298eHDUaJzMx7DrncSzYsDFy5jW7EAS6z7Rwmq4eFJ ACvX2ZxngJfVVZUPB9VGTTI8ltLwFf5N4dKyZs6ceGRj8YOhyVx2TMU1SjsZoyfqwlgXfV 2jDX9fC6hxUlkv/o30AQtvyZPTj/a3k= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Ian Jackson , Wei Liu Subject: [PATCH v12 14/27] tools/xenstore: allow live update only with no transaction active Date: Fri, 15 Jan 2021 09:29:47 +0100 Message-Id: <20210115083000.14186-15-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210115083000.14186-1-jgross@suse.com> References: <20210115083000.14186-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) Content-Type: text/plain; charset="utf-8" In order to simplify live update state dumping only allow live update to happen when no transaction is active. A timeout is used to detect guests which have a transaction active for longer periods of time. In case such a guest is detected when trying to do a live update it will be reported and the update will fail. The admin can then either use a longer timeout, or use the force flag to just ignore the transactions of such a guest, or kill the guest before retrying. Signed-off-by: Juergen Gross --- V11: - reworked timeout logic to be handled in daemon (Edwin Torok) --- tools/xenstore/xenstored_control.c | 29 ++++++++++++++++++++++++-- tools/xenstore/xenstored_core.h | 1 + tools/xenstore/xenstored_transaction.c | 5 +++++ 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/tools/xenstore/xenstored_control.c b/tools/xenstore/xenstored_= control.c index d3da6b8111..52fbf31367 100644 --- a/tools/xenstore/xenstored_control.c +++ b/tools/xenstore/xenstored_control.c @@ -312,12 +312,37 @@ static const char *lu_arch(const void *ctx, struct co= nnection *conn, =20 static bool lu_check_lu_allowed(void) { - return true; + struct connection *conn; + time_t now =3D time(NULL); + unsigned int ta_total =3D 0, ta_long =3D 0; + + list_for_each_entry(conn, &connections, list) { + if (conn->ta_start_time) { + ta_total++; + if (conn->ta_start_time - now >=3D lu_status->timeout) + ta_long++; + } + } + + return ta_total ? (lu_status->force && ta_long =3D=3D ta_total) : true; } =20 static const char *lu_reject_reason(const void *ctx) { - return "BUSY"; + char *ret =3D NULL; + struct connection *conn; + time_t now =3D time(NULL); + + list_for_each_entry(conn, &connections, list) { + if (conn->ta_start_time - now >=3D lu_status->timeout) { + ret =3D talloc_asprintf(ctx, "%s\nDomain %u: %ld s", + ret ? : "Domains with long running transactions:", + conn->id, + conn->ta_start_time - now); + } + } + + return ret ? (const char *)ret : "Overlapping transactions"; } =20 static const char *lu_dump_state(const void *ctx, struct connection *conn) diff --git a/tools/xenstore/xenstored_core.h b/tools/xenstore/xenstored_cor= e.h index d5cdf17160..db70f61f0d 100644 --- a/tools/xenstore/xenstored_core.h +++ b/tools/xenstore/xenstored_core.h @@ -107,6 +107,7 @@ struct connection struct list_head transaction_list; uint32_t next_transaction_id; unsigned int transaction_started; + time_t ta_start_time; =20 /* List of delayed requests. */ struct list_head delayed; diff --git a/tools/xenstore/xenstored_transaction.c b/tools/xenstore/xensto= red_transaction.c index 52355f4ed8..cd07fb0f21 100644 --- a/tools/xenstore/xenstored_transaction.c +++ b/tools/xenstore/xenstored_transaction.c @@ -473,6 +473,8 @@ int do_transaction_start(struct connection *conn, struc= t buffered_data *in) list_add_tail(&trans->list, &conn->transaction_list); talloc_steal(conn, trans); talloc_set_destructor(trans, destroy_transaction); + if (!conn->transaction_started) + conn->ta_start_time =3D time(NULL); conn->transaction_started++; wrl_ntransactions++; =20 @@ -511,6 +513,8 @@ int do_transaction_end(struct connection *conn, struct = buffered_data *in) conn->transaction =3D NULL; list_del(&trans->list); conn->transaction_started--; + if (!conn->transaction_started) + conn->ta_start_time =3D 0; =20 /* Attach transaction to in for auto-cleanup */ talloc_steal(in, trans); @@ -589,6 +593,7 @@ void conn_delete_all_transactions(struct connection *co= nn) assert(conn->transaction =3D=3D NULL); =20 conn->transaction_started =3D 0; + conn->ta_start_time =3D 0; } =20 int check_transactions(struct hashtable *hash) --=20 2.26.2 From nobody Mon Apr 29 15:17:07 2024 Delivered-To: importer@patchew.org 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; 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; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1610700071; cv=none; d=zohomail.com; s=zohoarc; b=VMyOatJR33AV6PwK84NXMu6ELsMHnjvNLWxye7rD9jiywkH4X7iOxl/JiLDF5hKntduY8BbkMY5lMz0glxFRbgvZmXrFdoFXTN2aAqQyAUv/ENzDA86OKaRYJ+oe6vBLYWKIMvExAzRqN7+dCwLbW3M6cjOcSKFOk4PTZRRpK0s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610700071; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=9hLKS3tqGavquprb3POoginKf8qVTOiNwihT9d+dpjc=; b=M3Ik3lCHfRVzmPaoaIUM3NEz4sA7Qo/1kmSEJhIjBW+3K1ytjh+rV0GP9LAhcc+IEYIC5QNSFCOao62dfGb2b8eebd5a/5oO8HM+6j/5t4v8zC+qfkPB/cY2H8jb7szQwPxFuZIdVY5FaLGF1BqMAgAP3TP031LOd+3YSUJrXzE= ARC-Authentication-Results: i=1; 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; dmarc=pass header.from= (p=quarantine dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1610700071152875.8683278300311; Fri, 15 Jan 2021 00:41:11 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.67822.121275 (Exim 4.92) (envelope-from ) id 1l0Keq-0003c4-65; Fri, 15 Jan 2021 08:40:36 +0000 Received: by outflank-mailman (output) from mailman id 67822.121275; Fri, 15 Jan 2021 08:40:36 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l0Keq-0003bu-1V; Fri, 15 Jan 2021 08:40:36 +0000 Received: by outflank-mailman (input) for mailman id 67822; Fri, 15 Jan 2021 08:40:35 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l0KVe-0008HA-OR for xen-devel@lists.xenproject.org; Fri, 15 Jan 2021 08:31:06 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id be665579-540d-4351-b7c0-854ce618ebc0; Fri, 15 Jan 2021 08:30:13 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 21C89B98D; Fri, 15 Jan 2021 08:30:07 +0000 (UTC) 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: be665579-540d-4351-b7c0-854ce618ebc0 X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1610699408; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9hLKS3tqGavquprb3POoginKf8qVTOiNwihT9d+dpjc=; b=csOG0wvPkcaYR/OnOv04ociOEy5DKGgtSVMnhfSHNbIgTydbM3UYRoe5yfyr7vwmKVXm/P IybJztmLLVuz59ofCp+d+f5DcQ4OGCtoIWoQo6Dm/iumemoOt/DIATVEmeSsCa4po+JfPP bM7H7h3+iK4kLbsUmFANfhgKwJ5RVv0= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Andrew Cooper , George Dunlap , Ian Jackson , Jan Beulich , Julien Grall , Stefano Stabellini , Wei Liu , Julien Grall Subject: [PATCH v12 15/27] docs: update the xenstore migration stream documentation Date: Fri, 15 Jan 2021 09:29:48 +0100 Message-Id: <20210115083000.14186-16-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210115083000.14186-1-jgross@suse.com> References: <20210115083000.14186-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) Content-Type: text/plain; charset="utf-8" For live update of Xenstore some records defined in the migration stream document need to be changed: - Support of the read-only socket has been dropped from all Xenstore implementations, so ro-socket-fd in the global record can be removed. - Some guests require the event channel to Xenstore to remain the same on Xenstore side, so Xenstore has to keep the event channel interface open across a live update. For this purpose an evtchn-fd needs to be added to the global record. - With no read-only support the flags field in the connection record can be dropped. - The evtchn field in the connection record needs to be switched to hold the port of the Xenstore side of the event channel. - A flags field needs to be added to permission specifiers in order to be able to mark a permission as stale (XSA-322). Signed-off-by: Juergen Gross Reviewed-by: Julien Grall --- V8: - split off from following patch (Julien Grall) --- docs/designs/xenstore-migration.md | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/docs/designs/xenstore-migration.md b/docs/designs/xenstore-mig= ration.md index 2ce2c836f5..1a5b94b31d 100644 --- a/docs/designs/xenstore-migration.md +++ b/docs/designs/xenstore-migration.md @@ -116,7 +116,7 @@ xenstored state that needs to be restored. +-------+-------+-------+-------+ | rw-socket-fd | +-------------------------------+ -| ro-socket-fd | +| evtchn-fd | +-------------------------------+ ``` =20 @@ -126,8 +126,8 @@ xenstored state that needs to be restored. | `rw-socket-fd` | The file descriptor of the socket accepting | | | read-write connections | | | | -| `ro-socket-fd` | The file descriptor of the socket accepting | -| | read-only connections | +| `evtchn-fd` | The file descriptor used to communicate with | +| | the event channel driver | =20 xenstored will resume in the original process context. Hence `rw-socket-fd= ` and `ro-socket-fd` simply specify the file descriptors of the sockets. Sockets @@ -147,7 +147,7 @@ the domain being migrated. ``` 0 1 2 3 4 5 6 7 octet +-------+-------+-------+-------+-------+-------+-------+-------+ -| conn-id | conn-type | flags | +| conn-id | conn-type | | +-------------------------------+---------------+---------------+ | conn-spec ... @@ -169,9 +169,6 @@ the domain being migrated. | | 0x0001: socket | | | 0x0002 - 0xFFFF: reserved for future use | | | | -| `flags` | A bit-wise OR of: | -| | 0001: read-only | -| | | | `conn-spec` | See below | | | | | `in-data-len` | The length (in octets) of any data read | @@ -216,7 +213,7 @@ For `shared ring` connections it is as follows: | | operation [2] or DOMID_INVALID [3] otherwise | | | | | `evtchn` | The port number of the interdomain channel used | -| | by `domid` to communicate with xenstored | +| | by xenstored to communicate with `domid` | | | | =20 Since the ABI guarantees that entry 1 in `domid`'s grant table will always @@ -386,7 +383,7 @@ A node permission specifier has the following format: ``` 0 1 2 3 octet +-------+-------+-------+-------+ -| perm | pad | domid | +| perm | flags | domid | +-------+-------+---------------+ ``` =20 @@ -395,6 +392,10 @@ A node permission specifier has the following format: | `perm` | One of the ASCII values `w`, `r`, `b` or `n` as | | | specified for the `SET_PERMS` operation [2] | | | | +| `flags` | A bit-wise OR of: | +| | 0x01: stale permission, ignore when checking | +| | permissions | +| | | | `domid` | The domain-id to which the permission relates | =20 Note that perm1 defines the domain owning the code. See [4] for more --=20 2.26.2 From nobody Mon Apr 29 15:17:07 2024 Delivered-To: importer@patchew.org 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; 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; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1610700074; cv=none; d=zohomail.com; s=zohoarc; b=nkxosGoRhcW5OfE0nYhImbQWemwtnazp2gEwkY4QXznE2OdrfhmGyrqWmTATHfYA3UT2tY0mL3mQoFVXMxrzQ/Tur3tzl4/L93Xhd/YieaeYeAiUPoNh5VH1zoq35jHtuxhogHNXiOu3NknNcyCMSSmR28VM2gVXBcVGy0AC/38= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610700074; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=TIt6mjfz4m4Lbw7qhygGZfW7PH1zNiUMYf4J84ykaIY=; b=Ruwn4/YBPoiIQfPabuu+EAMpPVm9HHu5CHqJeGhl/mrDwyAUSo0AQBxhOXT+YEh1zhYF2v9Mh8nzuNd4z3ban3mHHXITrv1HnEr6eOlAGceCSAjkbjE+Ehp5ZvjbXTeRoGfJXJCUmEcSbE6Tchwc8CPvPcjEI0jqSWsjlzhL8kA= ARC-Authentication-Results: i=1; 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; dmarc=pass header.from= (p=quarantine dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1610700074742353.2055086682075; Fri, 15 Jan 2021 00:41:14 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.67831.121293 (Exim 4.92) (envelope-from ) id 1l0KfD-0003oA-RR; Fri, 15 Jan 2021 08:40:59 +0000 Received: by outflank-mailman (output) from mailman id 67831.121293; Fri, 15 Jan 2021 08:40:59 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l0KfD-0003nx-Jy; Fri, 15 Jan 2021 08:40:59 +0000 Received: by outflank-mailman (input) for mailman id 67831; Fri, 15 Jan 2021 08:40:58 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l0KVj-0008HA-Ob for xen-devel@lists.xenproject.org; Fri, 15 Jan 2021 08:31:11 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 67322286-f7e5-43a5-8db9-52a62fac55a6; Fri, 15 Jan 2021 08:30:13 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 426B2B96E; Fri, 15 Jan 2021 08:30:07 +0000 (UTC) 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: 67322286-f7e5-43a5-8db9-52a62fac55a6 X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1610699407; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=TIt6mjfz4m4Lbw7qhygGZfW7PH1zNiUMYf4J84ykaIY=; b=B4qGmTquoINN3Rs5r+vl1B1aWKiK3RRbHp7UXwFXIpDBFkB4Y4B3qTCKY+TMzWyhulflKC nsOG4ujBSZql9pkySKjR4drSJpy4Xk9TsUSoi+DOK+hRzMl9aGff7c59NJwg2134+bwYrd N5CvgcyopksMIj8p4b0bCphlRNocWqg= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Ian Jackson , Wei Liu , Julien Grall Subject: [PATCH v12 16/27] tools/xenstore: add include file for state structure definitions Date: Fri, 15 Jan 2021 09:29:49 +0100 Message-Id: <20210115083000.14186-17-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210115083000.14186-1-jgross@suse.com> References: <20210115083000.14186-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) Content-Type: text/plain; charset="utf-8" Add an include file containing all structures and defines needed for dumping and restoring the internal Xenstore state. Signed-off-by: Juergen Gross Acked-by: Julien Grall --- V4: - drop mfn from connection record (rebase to V5 of state doc patch) - add #ifdef __MINIOS__ (Julien Grall) - correct comments (Julien Grall) - add data_in_len V5: - add data_resp_len V6: - add flag byte to node permissions (Julien Grall) - update migration document V7: - add evtchn_fd V8: - remove ro-socket and read-only connection flag - split off documentation part V9: - add htobe32() macro if needed (Wei Liu) --- tools/xenstore/include/xenstore_state.h | 131 ++++++++++++++++++++++++ 1 file changed, 131 insertions(+) create mode 100644 tools/xenstore/include/xenstore_state.h diff --git a/tools/xenstore/include/xenstore_state.h b/tools/xenstore/inclu= de/xenstore_state.h new file mode 100644 index 0000000000..d2a9307400 --- /dev/null +++ b/tools/xenstore/include/xenstore_state.h @@ -0,0 +1,131 @@ +/* + * Xenstore internal state dump definitions. + * Copyright (C) Juergen Gross, SUSE Software Solutions Germany GmbH + * + * Used for live-update and migration, possibly across Xenstore implementa= tions. + * + * This library 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; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; If not, see . + */ + +#ifndef XENSTORE_STATE_H +#define XENSTORE_STATE_H + +#include +#include + +#ifndef htobe32 +#if __BYTE_ORDER =3D=3D __LITTLE_ENDIAN +#define htobe32(x) __builtin_bswap32(x) +#else +#define htobe32(x) (x) +#endif +#endif + +struct xs_state_preamble { + char ident[8]; +#define XS_STATE_IDENT "xenstore" /* To be used without the NUL byte. = */ + uint32_t version; /* Version in big endian format. */ +#define XS_STATE_VERSION 0x00000001 + uint32_t flags; /* Endianess. */ +#if __BYTE_ORDER =3D=3D __LITTLE_ENDIAN +#define XS_STATE_FLAGS 0x00000000 /* Little endian. */ +#else +#define XS_STATE_FLAGS 0x00000001 /* Big endian. */ +#endif +}; + +/* + * Each record is starting with xs_state_record_header. + * All records have a length of a multiple of 8 bytes. + */ + +/* Common record layout: */ +struct xs_state_record_header { + uint32_t type; +#define XS_STATE_TYPE_END 0x00000000 +#define XS_STATE_TYPE_GLOBAL 0x00000001 +#define XS_STATE_TYPE_CONN 0x00000002 +#define XS_STATE_TYPE_WATCH 0x00000003 +#define XS_STATE_TYPE_TA 0x00000004 +#define XS_STATE_TYPE_NODE 0x00000005 + uint32_t length; /* Length of record in bytes. */ +}; + +/* Global state of Xenstore: */ +struct xs_state_global { + int32_t socket_fd; /* File descriptor for socket connections or -= 1. */ + int32_t evtchn_fd; /* File descriptor for event channel operation= s. */ +}; + +/* Connection to Xenstore: */ +struct xs_state_connection { + uint32_t conn_id; /* Used as reference in watch and TA records. = */ + uint16_t conn_type; +#define XS_STATE_CONN_TYPE_RING 0 +#define XS_STATE_CONN_TYPE_SOCKET 1 + uint16_t pad; + union { + struct { + uint16_t domid; /* Domain-Id. */ + uint16_t tdomid; /* Id of target domain or DOMID_INVALID. */ + uint32_t evtchn; /* Event channel port. */ + } ring; + int32_t socket_fd; /* File descriptor for socket connections. */ + } spec; + uint16_t data_in_len; /* Number of unprocessed bytes read from conn= . */ + uint16_t data_resp_len; /* Size of partial response pending for conn.= */ + uint32_t data_out_len; /* Number of bytes not yet written to conn. */ + uint8_t data[]; /* Pending data (read, written) + 0-7 pad byt= es. */ +}; + +/* Watch: */ +struct xs_state_watch { + uint32_t conn_id; /* Connection this watch is associated with. */ + uint16_t path_length; /* Number of bytes of path watched (incl. 0). = */ + uint16_t token_length; /* Number of bytes of watch token (incl. 0). */ + uint8_t data[]; /* Path bytes, token bytes, 0-7 pad bytes. */ +}; + +/* Transaction: */ +struct xs_state_transaction { + uint32_t conn_id; /* Connection this TA is associated with. */ + uint32_t ta_id; /* Transaction Id. */ +}; + +/* Node (either XS_STATE_TYPE_NODE or XS_STATE_TYPE_TANODE[_MOD]): */ +struct xs_state_node_perm { + uint8_t access; /* Access rights. */ +#define XS_STATE_NODE_PERM_NONE 'n' +#define XS_STATE_NODE_PERM_READ 'r' +#define XS_STATE_NODE_PERM_WRITE 'w' +#define XS_STATE_NODE_PERM_BOTH 'b' + uint8_t flags; +#define XS_STATE_NODE_PERM_IGNORE 0x01 /* Stale permission, ignore for che= ck. */ + uint16_t domid; /* Domain-Id. */ +}; +struct xs_state_node { + uint32_t conn_id; /* Connection in case of transaction or 0. */ + uint32_t ta_id; /* Transaction Id or 0. */ + uint16_t path_len; /* Length of path string including NUL byte. */ + uint16_t data_len; /* Length of node data. */ + uint16_t ta_access; +#define XS_STATE_NODE_TA_DELETED 0x0000 +#define XS_STATE_NODE_TA_READ 0x0001 +#define XS_STATE_NODE_TA_WRITTEN 0x0002 + uint16_t perm_n; /* Number of permissions (0 in TA: node delete= d). */ + /* Permissions (first is owner, has full access). */ + struct xs_state_node_perm perms[]; + /* Path and data follows, plus 0-7 pad bytes. */ +}; +#endif /* XENSTORE_STATE_H */ --=20 2.26.2 From nobody Mon Apr 29 15:17:07 2024 Delivered-To: importer@patchew.org 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; 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; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1610699463; cv=none; d=zohomail.com; s=zohoarc; b=Sj03R9mXZEMWpIzAQy0gfs3VF07o0HU4kMG/jvDWprsYQ79aKN8qy0zC81ePNGgER/vv3qMrcA0HV2GGSZ38JV9OTF2TV+0lm1RBocYT7I3O+wi4gcHi0KfxyVV+0TFiEdXROxmyDTnIhUwcGxpUe3/rimFXkFKfhtlJUHUlnYY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610699463; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=rWq2LDhxE/J88HdZm42cSDXebSU/T2ilWRxz9q5oE4I=; b=cnBK3c8PTSD4/evnVJYBwnboaT5mpOgingNMM3oU0Nb4VITS1dWi4FduPvsUzURdmYZp/yhvixUyEnZFUV2VzO0gaTtAUdokGf08idaz79piMM6artaLAHZFfMoM5v7jlA714r/CW9ZqfnKbbiaAnmOIUtGSC8p0JWn0LRZRzhU= ARC-Authentication-Results: i=1; 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; dmarc=pass header.from= (p=quarantine dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1610699463883789.3318928709866; Fri, 15 Jan 2021 00:31:03 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.67729.121143 (Exim 4.92) (envelope-from ) id 1l0KVJ-0000ms-Ry; Fri, 15 Jan 2021 08:30:45 +0000 Received: by outflank-mailman (output) from mailman id 67729.121143; Fri, 15 Jan 2021 08:30:45 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l0KVJ-0000me-KD; Fri, 15 Jan 2021 08:30:45 +0000 Received: by outflank-mailman (input) for mailman id 67729; Fri, 15 Jan 2021 08:30:44 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l0KVI-0008Gh-GF for xen-devel@lists.xenproject.org; Fri, 15 Jan 2021 08:30:44 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id e84e41e5-709d-4c90-a117-f9c0b643afb2; Fri, 15 Jan 2021 08:30:14 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 439B9B97D; Fri, 15 Jan 2021 08:30:07 +0000 (UTC) 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: e84e41e5-709d-4c90-a117-f9c0b643afb2 X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1610699408; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=rWq2LDhxE/J88HdZm42cSDXebSU/T2ilWRxz9q5oE4I=; b=ZTKK9h2qoibSAqf9gkqrjdMXM8qpwL9s6QFZCtpzhTVf68XwKnp/5q2klttK4iUIm6WZFV Hbc64vgPiK2NI9HrdEaJ0T0+wKbwIb+RvNmTY10XY+6XmXSgzFBqK8lkoK5Qb6F53w4Yhf Gxfks9ziBLGO1NlDJ4W3HhHTJ9mEBt8= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Ian Jackson , Wei Liu , Paul Durrant , Julien Grall Subject: [PATCH v12 17/27] tools/xenstore: dump the xenstore state for live update Date: Fri, 15 Jan 2021 09:29:50 +0100 Message-Id: <20210115083000.14186-18-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210115083000.14186-1-jgross@suse.com> References: <20210115083000.14186-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) Content-Type: text/plain; charset="utf-8" Dump the complete Xenstore status to a file (daemon case) or memory (stubdom case). As we don't know the exact length of the needed area in advance we are using an anonymous rather large mapping in stubdom case, which will use only virtual address space until accessed. And as we are writing the area in a sequential manner this is fine. As the initial size we are choosing the double size of the memory allocated via talloc(), which should be more than enough. Signed-off-by: Juergen Gross Reviewed-by: Paul Durrant Acked-by: Julien Grall --- V4: - directly write to state file in daemon case - add pending read data (Julien Grall) V5: - fix 0 length buffered data body (Julien Grall) - simplify dump_state_buffered_data() (Paul Durrant) - add data_resp_len field handling - add comments (Paul Durrant) - move dump_state_align() call out of dump_state_buffered_data() (Paul Durrant) - move constant assignments out of loops (Paul Durrant) - use set_tdb_key() (Paul Durrant) V6: - rename "first" to "Partial" (Paul Durrant) - make sure data_resp_len is written (Paul Durrant) - don't leak node memory in dump_state_nodes() - add permission flag byte handling (Julien Grall) - drop global state buffer (Julien Grall) - add and correct comments (Julien Grall) - add const (Julien Grall) - add path buffer overrun check (Julien Grall) - move get_watch_path() from later patch, correct dump_state_watches() to use it (Julien Grall) V7: - add glb.evtchn_fd, switch evtchn to local port - remove definition of ROUNDUP() from utils.h due to rebase - create state file with 0600 permissions --- tools/xenstore/utils.c | 17 +++ tools/xenstore/utils.h | 6 + tools/xenstore/xenstored_control.c | 102 +++++++++++++- tools/xenstore/xenstored_core.c | 213 +++++++++++++++++++++++++++++ tools/xenstore/xenstored_core.h | 12 ++ tools/xenstore/xenstored_domain.c | 105 ++++++++++++++ tools/xenstore/xenstored_domain.h | 3 + tools/xenstore/xenstored_watch.c | 57 +++++++- tools/xenstore/xenstored_watch.h | 3 + 9 files changed, 512 insertions(+), 6 deletions(-) diff --git a/tools/xenstore/utils.c b/tools/xenstore/utils.c index 633ce3b4fc..0d80cb6de8 100644 --- a/tools/xenstore/utils.c +++ b/tools/xenstore/utils.c @@ -62,3 +62,20 @@ void barf_perror(const char *fmt, ...) } exit(1); } + +const char *dump_state_align(FILE *fp) +{ + long len; + static char nul[8] =3D {}; + + len =3D ftell(fp); + if (len < 0) + return "Dump state align error"; + len &=3D 7; + if (!len) + return NULL; + + if (fwrite(nul, 8 - len, 1, fp) !=3D 1) + return "Dump state align error"; + return NULL; +} diff --git a/tools/xenstore/utils.h b/tools/xenstore/utils.h index 6a1b5de9bd..df1cb9a3ba 100644 --- a/tools/xenstore/utils.h +++ b/tools/xenstore/utils.h @@ -3,6 +3,7 @@ #include #include #include +#include =20 #include =20 @@ -21,6 +22,11 @@ static inline bool strends(const char *a, const char *b) return streq(a + strlen(a) - strlen(b), b); } =20 +/* + * Write NUL bytes for aligning state data to 8 bytes. + */ +const char *dump_state_align(FILE *fp); + void barf(const char *fmt, ...) __attribute__((noreturn)); void barf_perror(const char *fmt, ...) __attribute__((noreturn)); =20 diff --git a/tools/xenstore/xenstored_control.c b/tools/xenstore/xenstored_= control.c index 52fbf31367..72a03c99d4 100644 --- a/tools/xenstore/xenstored_control.c +++ b/tools/xenstore/xenstored_control.c @@ -25,12 +25,21 @@ Interactive commands for Xen Store Daemon. #include #include #include +#include +#include #include +#include =20 #include "utils.h" #include "talloc.h" #include "xenstored_core.h" #include "xenstored_control.h" +#include "xenstored_domain.h" + +/* Mini-OS only knows about MAP_ANON. */ +#ifndef MAP_ANONYMOUS +#define MAP_ANONYMOUS MAP_ANON +#endif =20 struct live_update { /* For verification the correct connection is acting. */ @@ -40,6 +49,9 @@ struct live_update { void *kernel; unsigned int kernel_size; unsigned int kernel_off; + + void *dump_state; + unsigned long dump_size; #else char *filename; #endif @@ -56,6 +68,10 @@ static struct live_update *lu_status; =20 static int lu_destroy(void *data) { +#ifdef __MINIOS__ + if (lu_status->dump_state) + munmap(lu_status->dump_state, lu_status->dump_size); +#endif lu_status =3D NULL; =20 return 0; @@ -274,6 +290,31 @@ static const char *lu_arch(const void *ctx, struct con= nection *conn, errno =3D EINVAL; return NULL; } + +static FILE *lu_dump_open(const void *ctx) +{ + lu_status->dump_size =3D ROUNDUP(talloc_total_size(NULL) * 2, + XC_PAGE_SHIFT); + lu_status->dump_state =3D mmap(NULL, lu_status->dump_size, + PROT_READ | PROT_WRITE, + MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); + if (lu_status->dump_state =3D=3D MAP_FAILED) + return NULL; + + return fmemopen(lu_status->dump_state, lu_status->dump_size, "w"); +} + +static void lu_dump_close(FILE *fp) +{ + size_t size; + + size =3D ftell(fp); + size =3D ROUNDUP(size, XC_PAGE_SHIFT); + munmap(lu_status->dump_state + size, lu_status->dump_size - size); + lu_status->dump_size =3D size; + + fclose(fp); +} #else static const char *lu_binary(const void *ctx, struct connection *conn, const char *filename) @@ -308,6 +349,27 @@ static const char *lu_arch(const void *ctx, struct con= nection *conn, errno =3D EINVAL; return NULL; } + +static FILE *lu_dump_open(const void *ctx) +{ + char *filename; + int fd; + + filename =3D talloc_asprintf(ctx, "%s/state_dump", xs_daemon_rootdir()); + if (!filename) + return NULL; + + fd =3D open(filename, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR); + if (fd < 0) + return NULL; + + return fdopen(fd, "w"); +} + +static void lu_dump_close(FILE *fp) +{ + fclose(fp); +} #endif =20 static bool lu_check_lu_allowed(void) @@ -347,7 +409,45 @@ static const char *lu_reject_reason(const void *ctx) =20 static const char *lu_dump_state(const void *ctx, struct connection *conn) { - return NULL; + FILE *fp; + const char *ret; + struct xs_state_record_header end; + struct xs_state_preamble pre; + + fp =3D lu_dump_open(ctx); + if (!fp) + return "Dump state open error"; + + memcpy(pre.ident, XS_STATE_IDENT, sizeof(pre.ident)); + pre.version =3D htobe32(XS_STATE_VERSION); + pre.flags =3D XS_STATE_FLAGS; + if (fwrite(&pre, sizeof(pre), 1, fp) !=3D 1) { + ret =3D "Dump write error"; + goto out; + } + + ret =3D dump_state_global(fp); + if (ret) + goto out; + ret =3D dump_state_connections(fp, conn); + if (ret) + goto out; + ret =3D dump_state_special_nodes(fp); + if (ret) + goto out; + ret =3D dump_state_nodes(fp, ctx); + if (ret) + goto out; + + end.type =3D XS_STATE_TYPE_END; + end.length =3D 0; + if (fwrite(&end, sizeof(end), 1, fp) !=3D 1) + ret =3D "Dump write error"; + + out: + lu_dump_close(fp); + + return ret; } =20 static const char *lu_activate_binary(const void *ctx) diff --git a/tools/xenstore/xenstored_core.c b/tools/xenstore/xenstored_cor= e.c index 6f556d49ef..97f9f0ffa9 100644 --- a/tools/xenstore/xenstored_core.c +++ b/tools/xenstore/xenstored_core.c @@ -2279,6 +2279,219 @@ int main(int argc, char *argv[]) } } =20 +const char *dump_state_global(FILE *fp) +{ + struct xs_state_record_header head; + struct xs_state_global glb; + + head.type =3D XS_STATE_TYPE_GLOBAL; + head.length =3D sizeof(glb); + if (fwrite(&head, sizeof(head), 1, fp) !=3D 1) + return "Dump global state error"; + glb.socket_fd =3D sock; + glb.evtchn_fd =3D xenevtchn_fd(xce_handle); + if (fwrite(&glb, sizeof(glb), 1, fp) !=3D 1) + return "Dump global state error"; + + return NULL; +} + +/* Called twice: first with fp =3D=3D NULL to get length, then for writing= data. */ +const char *dump_state_buffered_data(FILE *fp, const struct connection *c, + const struct connection *conn, + struct xs_state_connection *sc) +{ + unsigned int len =3D 0, used; + struct buffered_data *out, *in =3D c->in; + bool partial =3D true; + + if (in && c !=3D conn) { + len =3D in->inhdr ? in->used : sizeof(in->hdr); + if (fp && fwrite(&in->hdr, len, 1, fp) !=3D 1) + return "Dump read data error"; + if (!in->inhdr && in->used) { + len +=3D in->used; + if (fp && fwrite(in->buffer, in->used, 1, fp) !=3D 1) + return "Dump read data error"; + } + } + + if (sc) { + sc->data_in_len =3D len; + sc->data_resp_len =3D 0; + } + + len =3D 0; + + list_for_each_entry(out, &c->out_list, list) { + used =3D out->used; + if (out->inhdr) { + if (!used) + partial =3D false; + if (fp && fwrite(out->hdr.raw + out->used, + sizeof(out->hdr) - out->used, 1, fp) !=3D 1) + return "Dump buffered data error"; + len +=3D sizeof(out->hdr) - out->used; + used =3D 0; + } + if (fp && out->hdr.msg.len && + fwrite(out->buffer + used, out->hdr.msg.len - used, + 1, fp) !=3D 1) + return "Dump buffered data error"; + len +=3D out->hdr.msg.len - used; + if (partial && sc) + sc->data_resp_len =3D len; + partial =3D false; + } + + /* Add "OK" for live-update command. */ + if (c =3D=3D conn) { + struct xsd_sockmsg msg =3D conn->in->hdr.msg; + + msg.len =3D sizeof("OK"); + if (fp && fwrite(&msg, sizeof(msg), 1, fp) !=3D 1) + return "Dump buffered data error"; + len +=3D sizeof(msg); + if (fp && fwrite("OK", msg.len, 1, fp) !=3D 1) + + return "Dump buffered data error"; + len +=3D msg.len; + } + + if (sc) + sc->data_out_len =3D len; + + return NULL; +} + +const char *dump_state_node_perms(FILE *fp, struct xs_state_node *sn, + const struct xs_permissions *perms, + unsigned int n_perms) +{ + unsigned int p; + + for (p =3D 0; p < n_perms; p++) { + switch ((int)perms[p].perms & ~XS_PERM_IGNORE) { + case XS_PERM_READ: + sn->perms[p].access =3D XS_STATE_NODE_PERM_READ; + break; + case XS_PERM_WRITE: + sn->perms[p].access =3D XS_STATE_NODE_PERM_WRITE; + break; + case XS_PERM_READ | XS_PERM_WRITE: + sn->perms[p].access =3D XS_STATE_NODE_PERM_BOTH; + break; + default: + sn->perms[p].access =3D XS_STATE_NODE_PERM_NONE; + break; + } + sn->perms[p].flags =3D (perms[p].perms & XS_PERM_IGNORE) + ? XS_STATE_NODE_PERM_IGNORE : 0; + sn->perms[p].domid =3D perms[p].id; + } + + if (fwrite(sn->perms, sizeof(*sn->perms), n_perms, fp) !=3D n_perms) + return "Dump node permissions error"; + + return NULL; +} + +static const char *dump_state_node_tree(FILE *fp, char *path) +{ + unsigned int pathlen, childlen, p =3D 0; + struct xs_state_record_header head; + struct xs_state_node sn; + TDB_DATA key, data; + const struct xs_tdb_record_hdr *hdr; + const char *child; + const char *ret; + + pathlen =3D strlen(path) + 1; + + set_tdb_key(path, &key); + data =3D tdb_fetch(tdb_ctx, key); + if (data.dptr =3D=3D NULL) + return "Error reading node"; + + /* Clean up in case of failure. */ + talloc_steal(path, data.dptr); + + hdr =3D (void *)data.dptr; + + head.type =3D XS_STATE_TYPE_NODE; + head.length =3D sizeof(sn); + sn.conn_id =3D 0; + sn.ta_id =3D 0; + sn.ta_access =3D 0; + sn.perm_n =3D hdr->num_perms; + sn.path_len =3D pathlen; + sn.data_len =3D hdr->datalen; + head.length +=3D hdr->num_perms * sizeof(*sn.perms); + head.length +=3D pathlen; + head.length +=3D hdr->datalen; + head.length =3D ROUNDUP(head.length, 3); + + if (fwrite(&head, sizeof(head), 1, fp) !=3D 1) + return "Dump node state error"; + if (fwrite(&sn, sizeof(sn), 1, fp) !=3D 1) + return "Dump node state error"; + + ret =3D dump_state_node_perms(fp, &sn, hdr->perms, hdr->num_perms); + if (ret) + return ret; + + if (fwrite(path, pathlen, 1, fp) !=3D 1) + return "Dump node path error"; + if (hdr->datalen && + fwrite(hdr->perms + hdr->num_perms, hdr->datalen, 1, fp) !=3D 1) + return "Dump node data error"; + + ret =3D dump_state_align(fp); + if (ret) + return ret; + + child =3D (char *)(hdr->perms + hdr->num_perms) + hdr->datalen; + + /* + * Use path for constructing children paths. + * As we don't write out nodes without having written their parent + * already we will never clobber a part of the path we'll need later. + */ + pathlen--; + if (path[pathlen - 1] !=3D '/') { + path[pathlen] =3D '/'; + pathlen++; + } + while (p < hdr->childlen) { + childlen =3D strlen(child) + 1; + if (pathlen + childlen > XENSTORE_ABS_PATH_MAX) + return "Dump node path length error"; + strcpy(path + pathlen, child); + ret =3D dump_state_node_tree(fp, path); + if (ret) + return ret; + p +=3D childlen; + child +=3D childlen; + } + + talloc_free(data.dptr); + + return NULL; +} + +const char *dump_state_nodes(FILE *fp, const void *ctx) +{ + char *path; + + path =3D talloc_size(ctx, XENSTORE_ABS_PATH_MAX); + if (!path) + return "Path buffer allocation error"; + + strcpy(path, "/"); + + return dump_state_node_tree(fp, path); +} + /* * Local variables: * mode: C diff --git a/tools/xenstore/xenstored_core.h b/tools/xenstore/xenstored_cor= e.h index db70f61f0d..22287ddfe9 100644 --- a/tools/xenstore/xenstored_core.h +++ b/tools/xenstore/xenstored_core.h @@ -30,6 +30,7 @@ #include =20 #include "xenstore_lib.h" +#include "xenstore_state.h" #include "list.h" #include "tdb.h" #include "hashtable.h" @@ -41,6 +42,8 @@ typedef int32_t wrl_creditt; #define WRL_CREDIT_MAX (1000*1000*1000) /* ^ satisfies non-overflow condition for wrl_xfer_credit */ =20 +struct xs_state_connection; + struct buffered_data { struct list_head list; @@ -245,6 +248,15 @@ int remember_string(struct hashtable *hash, const char= *str); =20 void set_tdb_key(const char *name, TDB_DATA *key); =20 +const char *dump_state_global(FILE *fp); +const char *dump_state_buffered_data(FILE *fp, const struct connection *c, + const struct connection *conn, + struct xs_state_connection *sc); +const char *dump_state_nodes(FILE *fp, const void *ctx); +const char *dump_state_node_perms(FILE *fp, struct xs_state_node *sn, + const struct xs_permissions *perms, + unsigned int n_perms); + #endif /* _XENSTORED_CORE_H */ =20 /* diff --git a/tools/xenstore/xenstored_domain.c b/tools/xenstore/xenstored_d= omain.c index ed8e83b06b..919a4d98cf 100644 --- a/tools/xenstore/xenstored_domain.c +++ b/tools/xenstore/xenstored_domain.c @@ -1143,6 +1143,111 @@ void wrl_apply_debit_trans_commit(struct connection= *conn) wrl_apply_debit_actual(conn->domain); } =20 +const char *dump_state_connections(FILE *fp, struct connection *conn) +{ + const char *ret =3D NULL; + unsigned int conn_id =3D 1; + struct xs_state_connection sc; + struct xs_state_record_header head; + struct connection *c; + + list_for_each_entry(c, &connections, list) { + head.type =3D XS_STATE_TYPE_CONN; + head.length =3D sizeof(sc); + + sc.conn_id =3D conn_id++; + sc.pad =3D 0; + memset(&sc.spec, 0, sizeof(sc.spec)); + if (c->domain) { + sc.conn_type =3D XS_STATE_CONN_TYPE_RING; + sc.spec.ring.domid =3D c->id; + sc.spec.ring.tdomid =3D c->target ? c->target->id + : DOMID_INVALID; + sc.spec.ring.evtchn =3D c->domain->port; + } else { + sc.conn_type =3D XS_STATE_CONN_TYPE_SOCKET; + sc.spec.socket_fd =3D c->fd; + } + + ret =3D dump_state_buffered_data(NULL, c, conn, &sc); + if (ret) + return ret; + head.length +=3D sc.data_in_len + sc.data_out_len; + head.length =3D ROUNDUP(head.length, 3); + if (fwrite(&head, sizeof(head), 1, fp) !=3D 1) + return "Dump connection state error"; + if (fwrite(&sc, offsetof(struct xs_state_connection, data), + 1, fp) !=3D 1) + return "Dump connection state error"; + ret =3D dump_state_buffered_data(fp, c, conn, NULL); + if (ret) + return ret; + ret =3D dump_state_align(fp); + if (ret) + return ret; + + ret =3D dump_state_watches(fp, c, sc.conn_id); + if (ret) + return ret; + } + + return ret; +} + +static const char *dump_state_special_node(FILE *fp, const char *name, + const struct node_perms *perms) +{ + struct xs_state_record_header head; + struct xs_state_node sn; + unsigned int pathlen; + const char *ret; + + pathlen =3D strlen(name) + 1; + + head.type =3D XS_STATE_TYPE_NODE; + head.length =3D sizeof(sn); + + sn.conn_id =3D 0; + sn.ta_id =3D 0; + sn.ta_access =3D 0; + sn.perm_n =3D perms->num; + sn.path_len =3D pathlen; + sn.data_len =3D 0; + head.length +=3D perms->num * sizeof(*sn.perms); + head.length +=3D pathlen; + head.length =3D ROUNDUP(head.length, 3); + if (fwrite(&head, sizeof(head), 1, fp) !=3D 1) + return "Dump special node error"; + if (fwrite(&sn, sizeof(sn), 1, fp) !=3D 1) + return "Dump special node error"; + + ret =3D dump_state_node_perms(fp, &sn, perms->p, perms->num); + if (ret) + return ret; + + if (fwrite(name, pathlen, 1, fp) !=3D 1) + return "Dump special node path error"; + + ret =3D dump_state_align(fp); + + return ret; +} + +const char *dump_state_special_nodes(FILE *fp) +{ + const char *ret; + + ret =3D dump_state_special_node(fp, "@releaseDomain", + &dom_release_perms); + if (ret) + return ret; + + ret =3D dump_state_special_node(fp, "@introduceDomain", + &dom_introduce_perms); + + return ret; +} + /* * Local variables: * mode: C diff --git a/tools/xenstore/xenstored_domain.h b/tools/xenstore/xenstored_d= omain.h index 66e0a12654..413b974375 100644 --- a/tools/xenstore/xenstored_domain.h +++ b/tools/xenstore/xenstored_domain.h @@ -97,4 +97,7 @@ void wrl_log_periodic(struct wrl_timestampt now); void wrl_apply_debit_direct(struct connection *conn); void wrl_apply_debit_trans_commit(struct connection *conn); =20 +const char *dump_state_connections(FILE *fp, struct connection *conn); +const char *dump_state_special_nodes(FILE *fp); + #endif /* _XENSTORED_DOMAIN_H */ diff --git a/tools/xenstore/xenstored_watch.c b/tools/xenstore/xenstored_wa= tch.c index 9ff20690c0..9248f08bd9 100644 --- a/tools/xenstore/xenstored_watch.c +++ b/tools/xenstore/xenstored_watch.c @@ -72,6 +72,19 @@ static bool is_child(const char *child, const char *pare= nt) return child[len] =3D=3D '/' || child[len] =3D=3D '\0'; } =20 +static const char *get_watch_path(const struct watch *watch, const char *n= ame) +{ + const char *path =3D name; + + if (watch->relative_path) { + path +=3D strlen(watch->relative_path); + if (*path =3D=3D '/') /* Could be "" */ + path++; + } + + return path; +} + /* * Send a watch event. * Temporary memory allocations are done with ctx. @@ -85,11 +98,7 @@ static void add_event(struct connection *conn, unsigned int len; char *data; =20 - if (watch->relative_path) { - name +=3D strlen(watch->relative_path); - if (*name =3D=3D '/') /* Could be "" */ - name++; - } + name =3D get_watch_path(watch, name); =20 len =3D strlen(name) + 1 + strlen(watch->token) + 1; /* Don't try to send over-long events. */ @@ -291,6 +300,44 @@ void conn_delete_all_watches(struct connection *conn) } } =20 +const char *dump_state_watches(FILE *fp, struct connection *conn, + unsigned int conn_id) +{ + const char *ret =3D NULL; + struct watch *watch; + struct xs_state_watch sw; + struct xs_state_record_header head; + const char *path; + + head.type =3D XS_STATE_TYPE_WATCH; + + list_for_each_entry(watch, &conn->watches, list) { + head.length =3D sizeof(sw); + + sw.conn_id =3D conn_id; + path =3D get_watch_path(watch, watch->node); + sw.path_length =3D strlen(path) + 1; + sw.token_length =3D strlen(watch->token) + 1; + head.length +=3D sw.path_length + sw.token_length; + head.length =3D ROUNDUP(head.length, 3); + if (fwrite(&head, sizeof(head), 1, fp) !=3D 1) + return "Dump watch state error"; + if (fwrite(&sw, sizeof(sw), 1, fp) !=3D 1) + return "Dump watch state error"; + + if (fwrite(path, sw.path_length, 1, fp) !=3D 1) + return "Dump watch path error"; + if (fwrite(watch->token, sw.token_length, 1, fp) !=3D 1) + return "Dump watch token error"; + + ret =3D dump_state_align(fp); + if (ret) + return ret; + } + + return ret; +} + /* * Local variables: * mode: C diff --git a/tools/xenstore/xenstored_watch.h b/tools/xenstore/xenstored_wa= tch.h index 03094374f3..3d81645f45 100644 --- a/tools/xenstore/xenstored_watch.h +++ b/tools/xenstore/xenstored_watch.h @@ -30,4 +30,7 @@ void fire_watches(struct connection *conn, const void *tm= p, const char *name, =20 void conn_delete_all_watches(struct connection *conn); =20 +const char *dump_state_watches(FILE *fp, struct connection *conn, + unsigned int conn_id); + #endif /* _XENSTORED_WATCH_H */ --=20 2.26.2 From nobody Mon Apr 29 15:17:07 2024 Delivered-To: importer@patchew.org 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; 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; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1610700080; cv=none; d=zohomail.com; s=zohoarc; b=YsRBzkysW+AdYmYGY1aY6Cs8kSj4dn90Et88GIYmgfRDXngaCpZ/qs0AG1yU76ppzBOoSOxXflDdRwy4Kf03eswMgKOEK+5TcsZT+NpBObJ+6HzgWBlJ45uHXR9Ve9tU6OmzB+YQ4WMewmgE5yKxCZCh7nMa3EMzbT+yRBaWlGU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610700080; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=WDHzSzyoEaGlA3XU/qAkPBQ5kt8+f3mUpBIWytT+FZg=; b=Gm0j/opvJwuWlOlFIaJHSlA62c3McMFT+GlNPzgndW7BXU0MIh6Sg2tVbogcrBczTZ6WnjPL8HxCoEjm9oe+oyNIdDgVOjYoQymRf+vOfo/xT+bETGsGkxI0J/c54bowTOkmpXFlwoztFEPkiWEaaafR2+TbN4JWzn5ASwemgng= ARC-Authentication-Results: i=1; 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; dmarc=pass header.from= (p=quarantine dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1610700080450267.28720517219153; Fri, 15 Jan 2021 00:41:20 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.67829.121287 (Exim 4.92) (envelope-from ) id 1l0KfD-0003ne-FJ; Fri, 15 Jan 2021 08:40:59 +0000 Received: by outflank-mailman (output) from mailman id 67829.121287; Fri, 15 Jan 2021 08:40:59 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l0KfD-0003nW-C3; Fri, 15 Jan 2021 08:40:59 +0000 Received: by outflank-mailman (input) for mailman id 67829; Fri, 15 Jan 2021 08:40:57 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l0KVt-0008HA-Ot for xen-devel@lists.xenproject.org; Fri, 15 Jan 2021 08:31:21 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 48b65064-14a1-4bd3-a007-fdb2c88ccef0; Fri, 15 Jan 2021 08:30:13 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 4919CB99B; Fri, 15 Jan 2021 08:30:07 +0000 (UTC) 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: 48b65064-14a1-4bd3-a007-fdb2c88ccef0 X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1610699408; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=WDHzSzyoEaGlA3XU/qAkPBQ5kt8+f3mUpBIWytT+FZg=; b=PaxA6+NDCXF6Q5s0cgQL72bXQlijhGMwBW9+5LWSHvPoj6jgcvjvLnXm4piQbQI4lujeFt +kxECOsbR3io08dly8+DQIRAIVOzaKbsIbYzsEM28ba1pK5C1bmdMIuZLjA3ayW5CliSim ewTVbU4KwymgHa1ILUGMW7Crp781exs= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Ian Jackson , Wei Liu , Julien Grall Subject: [PATCH v12 18/27] tools/xenstore: handle CLOEXEC flag for local files and pipes Date: Fri, 15 Jan 2021 09:29:51 +0100 Message-Id: <20210115083000.14186-19-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210115083000.14186-1-jgross@suse.com> References: <20210115083000.14186-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) Content-Type: text/plain; charset="utf-8" For support of live update the locally used files need to have the "close on exec" flag set. Fortunately the used Xen libraries are already doing this, so only the logging and tdb related files and pipes are affected. openlog() has the close on exec attribute, too. In order to be able to keep the event channels open specify the XENEVTCHN_NO_CLOEXEC flag when calling xenevtchn_open(). Signed-off-by: Juergen Gross Acked-by: Julien Grall --- V4: - disable LU in case of O_CLOEXEC not supported (Julien Grall) V5: - add comment (Paul Durrant) V7: - set XENEVTCHN_NO_CLOEXEC --- tools/xenstore/xenstored_control.c | 6 ++++++ tools/xenstore/xenstored_core.c | 6 ++++-- tools/xenstore/xenstored_core.h | 8 ++++++++ tools/xenstore/xenstored_domain.c | 2 +- tools/xenstore/xenstored_posix.c | 12 ++++++++++++ 5 files changed, 31 insertions(+), 3 deletions(-) diff --git a/tools/xenstore/xenstored_control.c b/tools/xenstore/xenstored_= control.c index 72a03c99d4..63b1f9a8b7 100644 --- a/tools/xenstore/xenstored_control.c +++ b/tools/xenstore/xenstored_control.c @@ -41,6 +41,7 @@ Interactive commands for Xen Store Daemon. #define MAP_ANONYMOUS MAP_ANON #endif =20 +#ifndef NO_LIVE_UPDATE struct live_update { /* For verification the correct connection is acting. */ struct connection *conn; @@ -90,6 +91,7 @@ static const char *lu_begin(struct connection *conn) =20 return NULL; } +#endif =20 struct cmd_s { char *cmd; @@ -214,6 +216,7 @@ static int do_control_print(void *ctx, struct connectio= n *conn, return 0; } =20 +#ifndef NO_LIVE_UPDATE static const char *lu_abort(const void *ctx, struct connection *conn) { syslog(LOG_INFO, "live-update: abort\n"); @@ -559,6 +562,7 @@ static int do_control_lu(void *ctx, struct connection *= conn, send_reply(conn, XS_CONTROL, resp, strlen(resp) + 1); return 0; } +#endif =20 static int do_control_help(void *, struct connection *, char **, int); =20 @@ -566,6 +570,7 @@ static struct cmd_s cmds[] =3D { { "check", do_control_check, "" }, { "log", do_control_log, "on|off" }, =20 +#ifndef NO_LIVE_UPDATE /* * The parameters are those of the xenstore-control utility! * Depending on environment (Mini-OS or daemon) the live-update @@ -585,6 +590,7 @@ static struct cmd_s cmds[] =3D { { "live-update", do_control_lu, "[-c ] [-F] [-t ] \n" " Default timeout is 60 seconds.", 4 }, +#endif #ifdef __MINIOS__ { "memreport", do_control_memreport, "" }, #else diff --git a/tools/xenstore/xenstored_core.c b/tools/xenstore/xenstored_cor= e.c index 97f9f0ffa9..2ef4534de7 100644 --- a/tools/xenstore/xenstored_core.c +++ b/tools/xenstore/xenstored_core.c @@ -198,7 +198,8 @@ void reopen_log(void) if (tracefile) { close_log(); =20 - tracefd =3D open(tracefile, O_WRONLY|O_CREAT|O_APPEND, 0600); + tracefd =3D open(tracefile, + O_WRONLY | O_CREAT | O_APPEND | O_CLOEXEC, 0600); =20 if (tracefd < 0) perror("Could not open tracefile"); @@ -1696,7 +1697,8 @@ static void setup_structure(void) if (!(tdb_flags & TDB_INTERNAL)) unlink(tdbname); =20 - tdb_ctx =3D tdb_open_ex(tdbname, 7919, tdb_flags, O_RDWR|O_CREAT|O_EXCL, + tdb_ctx =3D tdb_open_ex(tdbname, 7919, tdb_flags, + O_RDWR | O_CREAT | O_EXCL | O_CLOEXEC, 0640, &tdb_logger, NULL); if (!tdb_ctx) barf_perror("Could not create tdb file %s", tdbname); diff --git a/tools/xenstore/xenstored_core.h b/tools/xenstore/xenstored_cor= e.h index 22287ddfe9..c7567eaf0b 100644 --- a/tools/xenstore/xenstored_core.h +++ b/tools/xenstore/xenstored_core.h @@ -35,6 +35,14 @@ #include "tdb.h" #include "hashtable.h" =20 +#ifndef O_CLOEXEC +#define O_CLOEXEC 0 +/* O_CLOEXEC support is needed for Live Update in the daemon case. */ +#ifndef __MINIOS__ +#define NO_LIVE_UPDATE +#endif +#endif + /* DEFAULT_BUFFER_SIZE should be large enough for each errno string. */ #define DEFAULT_BUFFER_SIZE 16 =20 diff --git a/tools/xenstore/xenstored_domain.c b/tools/xenstore/xenstored_d= omain.c index 919a4d98cf..38d250fbed 100644 --- a/tools/xenstore/xenstored_domain.c +++ b/tools/xenstore/xenstored_domain.c @@ -743,7 +743,7 @@ void domain_init(void) =20 talloc_set_destructor(xgt_handle, close_xgt_handle); =20 - xce_handle =3D xenevtchn_open(NULL, 0); + xce_handle =3D xenevtchn_open(NULL, XENEVTCHN_NO_CLOEXEC); =20 if (xce_handle =3D=3D NULL) barf_perror("Failed to open evtchn device"); diff --git a/tools/xenstore/xenstored_posix.c b/tools/xenstore/xenstored_po= six.c index 1f9603fea2..ae3e63e07f 100644 --- a/tools/xenstore/xenstored_posix.c +++ b/tools/xenstore/xenstored_posix.c @@ -90,9 +90,21 @@ void finish_daemonize(void) =20 void init_pipe(int reopen_log_pipe[2]) { + int flags; + unsigned int i; + if (pipe(reopen_log_pipe)) { barf_perror("pipe"); } + + for (i =3D 0; i < 2; i++) { + flags =3D fcntl(reopen_log_pipe[i], F_GETFD); + if (flags < 0) + barf_perror("pipe get flags"); + flags |=3D FD_CLOEXEC; + if (fcntl(reopen_log_pipe[i], F_SETFD, flags) < 0) + barf_perror("pipe set flags"); + } } =20 void unmap_xenbus(void *interface) --=20 2.26.2 From nobody Mon Apr 29 15:17:07 2024 Delivered-To: importer@patchew.org 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; 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; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1610700028; cv=none; d=zohomail.com; s=zohoarc; b=FShWTvgslR8CkmJHEI2HkbMWOEyDLU0BuR6re84oybJkydZvPSxSdGdPQJF5StTy9sPNh0ND3oVS+K6/wLo93fCfMJ95Zm62c3fiqaTg80/UeifdQI7kKp0gw5SWmIKZb2S4Eh53cMserunggWynm4EVKKvIF+jfSkBpxtV8e38= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610700028; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=/rmGIUwb7rQQbsNmDH/AGkcUN8zjvijT5247nfpjU8Q=; b=Fi1e5T+Jzjh7X1S/2h1r0E7MtzcENweQFqEeYc7xh8HB3szBAaBzs5c1tn4xriju0ZP387EBQwpXvotK7t7WiL5qlA5cg0KE/0piptUD1f7qkJsVAIS9/+l+LFE0X6P/lL7AzmnbZMHtMbffIGXMaAmSQpt0F379MoXwB9SdFUU= ARC-Authentication-Results: i=1; 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; dmarc=pass header.from= (p=quarantine dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1610700028329981.6479090856712; Fri, 15 Jan 2021 00:40:28 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.67813.121250 (Exim 4.92) (envelope-from ) id 1l0KeS-0003Pj-EA; Fri, 15 Jan 2021 08:40:12 +0000 Received: by outflank-mailman (output) from mailman id 67813.121250; Fri, 15 Jan 2021 08:40:12 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l0KeS-0003PU-Ap; Fri, 15 Jan 2021 08:40:12 +0000 Received: by outflank-mailman (input) for mailman id 67813; Fri, 15 Jan 2021 08:40:10 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l0KVo-0008HA-Op for xen-devel@lists.xenproject.org; Fri, 15 Jan 2021 08:31:16 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id a413e613-d01e-4c1d-ac5b-0033c2abfbf7; Fri, 15 Jan 2021 08:30:13 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 5C5FCB95B; Fri, 15 Jan 2021 08:30:07 +0000 (UTC) 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: a413e613-d01e-4c1d-ac5b-0033c2abfbf7 X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1610699408; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/rmGIUwb7rQQbsNmDH/AGkcUN8zjvijT5247nfpjU8Q=; b=sDZnKsN+Oo+HwEcF4lXkmwKBoVYX7m6vN167hC11zp7vh6kT8mNLfztmbuhkyVbj5hjKIw NidBM/F8vRZfMNiiU+8eTqfAcCFxkDzyOc34PIaD7uTKcRc9dD+Ss6cus2RRWo+yJXjxqZ C6N3a3FAJE8vuqoC6V5aKAz7nFrQYH0= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Ian Jackson , Wei Liu , Julien Grall Subject: [PATCH v12 19/27] tools/xenstore: split off domain introduction from do_introduce() Date: Fri, 15 Jan 2021 09:29:52 +0100 Message-Id: <20210115083000.14186-20-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210115083000.14186-1-jgross@suse.com> References: <20210115083000.14186-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) Content-Type: text/plain; charset="utf-8" For live update the functionality to introduce a new domain similar to the XS_INTRODUCE command is needed, so split that functionality off into a dedicated function introduce_domain(). Switch initial dom0 initialization to use this function, too. Signed-off-by: Juergen Gross Reviewed-by: Julien Grall --- V8: - new patch --- tools/xenstore/xenstored_domain.c | 95 ++++++++++++++++++------------- 1 file changed, 55 insertions(+), 40 deletions(-) diff --git a/tools/xenstore/xenstored_domain.c b/tools/xenstore/xenstored_d= omain.c index 38d250fbed..71b078caf3 100644 --- a/tools/xenstore/xenstored_domain.c +++ b/tools/xenstore/xenstored_domain.c @@ -326,7 +326,7 @@ static struct domain *find_domain_struct(unsigned int d= omid) return NULL; } =20 -static struct domain *alloc_domain(void *context, unsigned int domid) +static struct domain *alloc_domain(const void *context, unsigned int domid) { struct domain *domain; =20 @@ -347,6 +347,14 @@ static struct domain *alloc_domain(void *context, unsi= gned int domid) return domain; } =20 +static struct domain *find_or_alloc_domain(const void *ctx, unsigned int d= omid) +{ + struct domain *domain; + + domain =3D find_domain_struct(domid); + return domain ? : alloc_domain(ctx, domid); +} + static int new_domain(struct domain *domain, int port) { int rc; @@ -413,52 +421,41 @@ static void domain_conn_reset(struct domain *domain) domain->interface->rsp_cons =3D domain->interface->rsp_prod =3D 0; } =20 -/* domid, gfn, evtchn, path */ -int do_introduce(struct connection *conn, struct buffered_data *in) +static struct domain *introduce_domain(const void *ctx, + unsigned int domid, + evtchn_port_t port) { struct domain *domain; - char *vec[3]; - unsigned int domid; - evtchn_port_t port; int rc; struct xenstore_domain_interface *interface; + bool is_master_domain =3D (domid =3D=3D xenbus_master_domid()); =20 - if (get_strings(in, vec, ARRAY_SIZE(vec)) < ARRAY_SIZE(vec)) - return EINVAL; - - domid =3D atoi(vec[0]); - /* Ignore the gfn, we don't need it. */ - port =3D atoi(vec[2]); - - /* Sanity check args. */ - if (port <=3D 0) - return EINVAL; - - domain =3D find_domain_struct(domid); - - if (domain =3D=3D NULL) { - /* Hang domain off "in" until we're finished. */ - domain =3D alloc_domain(in, domid); - if (domain =3D=3D NULL) - return ENOMEM; - } + domain =3D find_or_alloc_domain(ctx, domid); + if (!domain) + return NULL; =20 if (!domain->introduced) { - interface =3D map_interface(domid); + interface =3D is_master_domain ? xenbus_map() + : map_interface(domid); if (!interface) - return errno; - /* Hang domain off "in" until we're finished. */ + return NULL; if (new_domain(domain, port)) { rc =3D errno; - unmap_interface(interface); - return rc; + if (is_master_domain) + unmap_xenbus(interface); + else + unmap_interface(interface); + errno =3D rc; + return NULL; } domain->interface =3D interface; =20 /* Now domain belongs to its connection. */ talloc_steal(domain->conn, domain); =20 - fire_watches(NULL, in, "@introduceDomain", NULL, false, NULL); + if (!is_master_domain) + fire_watches(NULL, ctx, "@introduceDomain", NULL, + false, NULL); } else { /* Use XS_INTRODUCE for recreating the xenbus event-channel. */ if (domain->port) @@ -467,6 +464,32 @@ int do_introduce(struct connection *conn, struct buffe= red_data *in) domain->port =3D (rc =3D=3D -1) ? 0 : rc; } =20 + return domain; +} + +/* domid, gfn, evtchn, path */ +int do_introduce(struct connection *conn, struct buffered_data *in) +{ + struct domain *domain; + char *vec[3]; + unsigned int domid; + evtchn_port_t port; + + if (get_strings(in, vec, ARRAY_SIZE(vec)) < ARRAY_SIZE(vec)) + return EINVAL; + + domid =3D atoi(vec[0]); + /* Ignore the gfn, we don't need it. */ + port =3D atoi(vec[2]); + + /* Sanity check args. */ + if (port <=3D 0) + return EINVAL; + + domain =3D introduce_domain(in, domid, port); + if (!domain) + return errno; + domain_conn_reset(domain); =20 send_ack(conn, XS_INTRODUCE); @@ -692,17 +715,9 @@ static int dom0_init(void) if (port =3D=3D -1) return -1; =20 - dom0 =3D alloc_domain(NULL, xenbus_master_domid()); + dom0 =3D introduce_domain(NULL, xenbus_master_domid(), port); if (!dom0) return -1; - if (new_domain(dom0, port)) - return -1; - - dom0->interface =3D xenbus_map(); - if (dom0->interface =3D=3D NULL) - return -1; - - talloc_steal(dom0->conn, dom0);=20 =20 xenevtchn_notify(xce_handle, dom0->port); =20 --=20 2.26.2 From nobody Mon Apr 29 15:17:07 2024 Delivered-To: importer@patchew.org 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; 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; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1610699450; cv=none; d=zohomail.com; s=zohoarc; b=XLWJTJsF/RabWccDzJLi3SSWGP4hu9ufbqCJQk0AeqGgbT8WRj21N8N5Asfhfjqlvl8/fWIHDGwffsI/NaWodN/JwKkKJOq2oYSBxNpCTgOf6Crw5HKOVJJLByb+76PJQlz8PGoNpBnD/9ilKUZRvjmy4rBKGlXDDCEkv93XPvA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610699450; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=FpjzbVCuzkXlVPcq4673SAaWIvU9rs1ug3Lwgronb5I=; b=Lav+JQ86bmdjy25CtssCKL4s/DZ+wb5lTdj+jjS3Fa4JoO0ERbNpw1/iRcgE0r00um/G8sclrauRJjaXWwnH3nIwGCLiMD68Y7tD3qXOb7LOQgsqu755AnDcDXEYvQ7fS1ssZ3SdRTC0kL0nhXKjEo56XtRUMk90w78Y+eKPxzo= ARC-Authentication-Results: i=1; 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; dmarc=pass header.from= (p=quarantine dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 161069945005266.58278412704806; Fri, 15 Jan 2021 00:30:50 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.67722.121095 (Exim 4.92) (envelope-from ) id 1l0KV9-0000Pp-Eg; Fri, 15 Jan 2021 08:30:35 +0000 Received: by outflank-mailman (output) from mailman id 67722.121095; Fri, 15 Jan 2021 08:30:35 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l0KV9-0000PV-9Y; Fri, 15 Jan 2021 08:30:35 +0000 Received: by outflank-mailman (input) for mailman id 67722; Fri, 15 Jan 2021 08:30:34 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l0KV8-0008Gh-Fe for xen-devel@lists.xenproject.org; Fri, 15 Jan 2021 08:30:34 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 825f997d-4020-4070-9318-28c754ee67cf; Fri, 15 Jan 2021 08:30:14 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 63B1CB949; Fri, 15 Jan 2021 08:30:07 +0000 (UTC) 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: 825f997d-4020-4070-9318-28c754ee67cf X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1610699408; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=FpjzbVCuzkXlVPcq4673SAaWIvU9rs1ug3Lwgronb5I=; b=S6I6Y+XcwGUyJ03kJ6Hnm3lKlIrBHZd63wbT0fkfEQdKbtIroo6z+Bj2JH+bEsMovyhdck baJdrd9r2lFj3T1Nv7evANo5WEpbspY1aylXsZIpRK/PNTvmizjRHufU50Jb7I+jz6Rwvu xCA7pk5r/hcTuvAWapaSmGo5ZJx4GjE= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Ian Jackson , Wei Liu , Julien Grall Subject: [PATCH v12 20/27] tools/xenstore: evaluate the live update flag when starting Date: Fri, 15 Jan 2021 09:29:53 +0100 Message-Id: <20210115083000.14186-21-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210115083000.14186-1-jgross@suse.com> References: <20210115083000.14186-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) Content-Type: text/plain; charset="utf-8" In the live update case several initialization steps of xenstore must be omitted or modified. Add the proper handling for that. Signed-off-by: Juergen Gross Reviewed-by: Julien Grall --- V4: - set xprintf =3D trace in daemon case (Julien Grall) - only update /tool/xenstored node contents V7: - some restructuring to enable keeping event channel fd V8: - pass evtfd to domain_init() as parameter (Julien Grall) - call dom0_init() from main() V10: - remove support for remembering binary name (Andrew Cooper) --- tools/xenstore/xenstored_control.c | 5 ++++ tools/xenstore/xenstored_control.h | 1 + tools/xenstore/xenstored_core.c | 44 +++++++++++++++++++++--------- tools/xenstore/xenstored_domain.c | 26 ++++++++---------- tools/xenstore/xenstored_domain.h | 3 +- tools/xenstore/xenstored_posix.c | 1 - 6 files changed, 51 insertions(+), 29 deletions(-) diff --git a/tools/xenstore/xenstored_control.c b/tools/xenstore/xenstored_= control.c index 63b1f9a8b7..5151c1448e 100644 --- a/tools/xenstore/xenstored_control.c +++ b/tools/xenstore/xenstored_control.c @@ -453,6 +453,11 @@ static const char *lu_dump_state(const void *ctx, stru= ct connection *conn) return ret; } =20 +void lu_read_state(void) +{ + xprintf("live-update: read state\n"); +} + static const char *lu_activate_binary(const void *ctx) { return "Not yet implemented."; diff --git a/tools/xenstore/xenstored_control.h b/tools/xenstore/xenstored_= control.h index 207e0a6fa3..aac61f0590 100644 --- a/tools/xenstore/xenstored_control.h +++ b/tools/xenstore/xenstored_control.h @@ -17,3 +17,4 @@ */ =20 int do_control(struct connection *conn, struct buffered_data *in); +void lu_read_state(void); diff --git a/tools/xenstore/xenstored_core.c b/tools/xenstore/xenstored_cor= e.c index 2ef4534de7..4d88aeba3d 100644 --- a/tools/xenstore/xenstored_core.c +++ b/tools/xenstore/xenstored_core.c @@ -1687,9 +1687,10 @@ static void tdb_logger(TDB_CONTEXT *tdb, int level, = const char * fmt, ...) } } =20 -static void setup_structure(void) +static void setup_structure(bool live_update) { char *tdbname; + tdbname =3D talloc_strdup(talloc_autofree_context(), xs_daemon_tdb()); if (!tdbname) barf_perror("Could not create tdbname"); @@ -1703,14 +1704,17 @@ static void setup_structure(void) if (!tdb_ctx) barf_perror("Could not create tdb file %s", tdbname); =20 - manual_node("/", "tool"); - manual_node("/tool", "xenstored"); - manual_node("/tool/xenstored", NULL); + if (live_update) + manual_node("/", NULL); + else { + manual_node("/", "tool"); + manual_node("/tool", "xenstored"); + manual_node("/tool/xenstored", NULL); + } =20 check_store(); } =20 - static unsigned int hash_from_key_fn(void *k) { char *str =3D k; @@ -2116,7 +2120,8 @@ int main(int argc, char *argv[]) =20 if (dofork) { openlog("xenstored", 0, LOG_DAEMON); - daemonize(); + if (!live_update) + daemonize(); } if (pidfile) write_pidfile(pidfile); @@ -2131,17 +2136,20 @@ int main(int argc, char *argv[]) talloc_enable_null_tracking(); =20 #ifndef NO_SOCKETS - init_sockets(); + if (!live_update) + init_sockets(); #endif =20 init_pipe(reopen_log_pipe); =20 /* Setup the database */ - setup_structure(); + setup_structure(live_update); =20 /* Listen to hypervisor. */ - if (!no_domain_init) - domain_init(); + if (!no_domain_init && !live_update) { + domain_init(-1); + dom0_init(); + } =20 if (outputpid) { printf("%ld\n", (long)getpid()); @@ -2149,13 +2157,21 @@ int main(int argc, char *argv[]) } =20 /* redirect to /dev/null now we're ready to accept connections */ - if (dofork) + if (dofork && !live_update) finish_daemonize(); +#ifndef __MINIOS__ + if (dofork) + xprintf =3D trace; +#endif =20 signal(SIGHUP, trigger_reopen_log); if (tracefile) tracefile =3D talloc_strdup(NULL, tracefile); =20 + /* Read state in case of live update. */ + if (live_update) + lu_read_state(); + /* Get ready to listen to the tools. */ initialize_fds(&sock_pollfd_idx, &timeout); =20 @@ -2163,8 +2179,10 @@ int main(int argc, char *argv[]) xenbus_notify_running(); =20 #if defined(XEN_SYSTEMD_ENABLED) - sd_notify(1, "READY=3D1"); - fprintf(stderr, SD_NOTICE "xenstored is ready\n"); + if (!live_update) { + sd_notify(1, "READY=3D1"); + fprintf(stderr, SD_NOTICE "xenstored is ready\n"); + } #endif =20 /* Main loop. */ diff --git a/tools/xenstore/xenstored_domain.c b/tools/xenstore/xenstored_d= omain.c index 71b078caf3..775546757b 100644 --- a/tools/xenstore/xenstored_domain.c +++ b/tools/xenstore/xenstored_domain.c @@ -706,29 +706,23 @@ bool check_perms_special(const char *name, struct con= nection *conn) return perm_for_conn(conn, p) & XS_PERM_READ; } =20 -static int dom0_init(void)=20 -{=20 +void dom0_init(void) +{ evtchn_port_t port; struct domain *dom0; =20 port =3D xenbus_evtchn(); if (port =3D=3D -1) - return -1; + barf_perror("Failed to initialize dom0 port"); =20 dom0 =3D introduce_domain(NULL, xenbus_master_domid(), port); if (!dom0) - return -1; + barf_perror("Failed to initialize dom0"); =20 xenevtchn_notify(xce_handle, dom0->port); - - if (set_dom_perms_default(&dom_release_perms) || - set_dom_perms_default(&dom_introduce_perms)) - return -1; - - return 0;=20 } =20 -void domain_init(void) +void domain_init(int evtfd) { int rc; =20 @@ -758,13 +752,17 @@ void domain_init(void) =20 talloc_set_destructor(xgt_handle, close_xgt_handle); =20 - xce_handle =3D xenevtchn_open(NULL, XENEVTCHN_NO_CLOEXEC); + if (evtfd < 0) + xce_handle =3D xenevtchn_open(NULL, XENEVTCHN_NO_CLOEXEC); + else + xce_handle =3D xenevtchn_fdopen(NULL, evtfd, 0); =20 if (xce_handle =3D=3D NULL) barf_perror("Failed to open evtchn device"); =20 - if (dom0_init() !=3D 0)=20 - barf_perror("Failed to initialize dom0 state");=20 + if (set_dom_perms_default(&dom_release_perms) || + set_dom_perms_default(&dom_introduce_perms)) + barf_perror("Failed to set special permissions"); =20 if ((rc =3D xenevtchn_bind_virq(xce_handle, VIRQ_DOM_EXC)) =3D=3D -1) barf_perror("Failed to bind to domain exception virq port"); diff --git a/tools/xenstore/xenstored_domain.h b/tools/xenstore/xenstored_d= omain.h index 413b974375..b20269b038 100644 --- a/tools/xenstore/xenstored_domain.h +++ b/tools/xenstore/xenstored_domain.h @@ -42,7 +42,8 @@ int do_get_domain_path(struct connection *conn, struct bu= ffered_data *in); /* Allow guest to reset all watches */ int do_reset_watches(struct connection *conn, struct buffered_data *in); =20 -void domain_init(void); +void domain_init(int evtfd); +void dom0_init(void); =20 /* Returns the implicit path of a connection (only domains have this) */ const char *get_implicit_path(const struct connection *conn); diff --git a/tools/xenstore/xenstored_posix.c b/tools/xenstore/xenstored_po= six.c index ae3e63e07f..48c37ffe3e 100644 --- a/tools/xenstore/xenstored_posix.c +++ b/tools/xenstore/xenstored_posix.c @@ -85,7 +85,6 @@ void finish_daemonize(void) dup2(devnull, STDOUT_FILENO); dup2(devnull, STDERR_FILENO); close(devnull); - xprintf =3D trace; } =20 void init_pipe(int reopen_log_pipe[2]) --=20 2.26.2 From nobody Mon Apr 29 15:17:07 2024 Delivered-To: importer@patchew.org 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; 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; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1610699445; cv=none; d=zohomail.com; s=zohoarc; b=CFD5yoRKLCZidvF26QDOuThNvjW1FENfsUAPPn5RBwEaDFYLituzeVVc2dUOG2XA+rB1AuF+u3ds546ddBTGGLbu/wsS+im26DmMwlIDK+QCn1oIOjuRRWHLsPwvqhnSM31hJbqoRZDBTsXzeWuPHi2TojgFDGXN+WV0FpxTyK8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610699445; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Dqtva9i5hOWwd+C/RFxrhHjBGyOaW9BmEt02J1LO82U=; b=ijc/XJg9TjXVtQL3xantA5YJ3l8wXRLRdc9BnqoXPJCQ1RMn9H3XsJShUeEt1USiOPhBO2OWgXKbYaTFINGIwhcIg6cQbGr5ec7glCxPpNyjuPTgFSSBopzt4GcUSQfMnDHIUUnhTVQVE+2Dr8CVPba040cN+Q86rUUlfCeEtAo= ARC-Authentication-Results: i=1; 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; dmarc=pass header.from= (p=quarantine dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1610699445300108.28647013508191; Fri, 15 Jan 2021 00:30:45 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.67720.121071 (Exim 4.92) (envelope-from ) id 1l0KV4-0000Fv-LP; Fri, 15 Jan 2021 08:30:30 +0000 Received: by outflank-mailman (output) from mailman id 67720.121071; Fri, 15 Jan 2021 08:30:30 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l0KV4-0000Fg-Es; Fri, 15 Jan 2021 08:30:30 +0000 Received: by outflank-mailman (input) for mailman id 67720; Fri, 15 Jan 2021 08:30:29 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l0KV3-0008Gh-FP for xen-devel@lists.xenproject.org; Fri, 15 Jan 2021 08:30:29 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 376dc9d4-0c26-4f59-9a6f-0a1f6df6d6ad; Fri, 15 Jan 2021 08:30:14 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 68486B95F; Fri, 15 Jan 2021 08:30:07 +0000 (UTC) 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: 376dc9d4-0c26-4f59-9a6f-0a1f6df6d6ad X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1610699408; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Dqtva9i5hOWwd+C/RFxrhHjBGyOaW9BmEt02J1LO82U=; b=nvyVrZGTnTv22kXzkMtZ4QopXiLwHKPd9l83UQBx0kogCA6BZ5PjVlGz/ZV2nOLUFZRZKv bX4IIGQSCnnc2R5qIyn5vZ9/JcZZQ8yitODd42QeLYajsLzprSfEzHl6qZlMLR8yv9ceTD xbjQcwwAEYstGN5cmZYWTg7gd02pthk= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Ian Jackson , Wei Liu , Paul Durrant , Julien Grall Subject: [PATCH v12 21/27] tools/xenstore: read internal state when doing live upgrade Date: Fri, 15 Jan 2021 09:29:54 +0100 Message-Id: <20210115083000.14186-22-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210115083000.14186-1-jgross@suse.com> References: <20210115083000.14186-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) Content-Type: text/plain; charset="utf-8" When started due to a live upgrade read the internal state and apply it to the data base and internal structures. Add the main control functions for that. For now only handle the daemon case. Signed-off-by: Juergen Gross Reviewed-by: Paul Durrant Acked-by: Julien Grall --- V4: - directly mmap dump state file (Julien Grall) - use syslog() instead of xprintf() (Julien Grall) V8: - remove state file after reading it (Julien Grall) --- tools/xenstore/xenstored_control.c | 102 ++++++++++++++++++++++++++++- 1 file changed, 101 insertions(+), 1 deletion(-) diff --git a/tools/xenstore/xenstored_control.c b/tools/xenstore/xenstored_= control.c index 5151c1448e..3bced9e39e 100644 --- a/tools/xenstore/xenstored_control.c +++ b/tools/xenstore/xenstored_control.c @@ -67,6 +67,14 @@ struct live_update { =20 static struct live_update *lu_status; =20 +struct lu_dump_state { + void *buf; + unsigned int size; +#ifndef __MINIOS__ + int fd; +#endif +}; + static int lu_destroy(void *data) { #ifdef __MINIOS__ @@ -318,6 +326,14 @@ static void lu_dump_close(FILE *fp) =20 fclose(fp); } + +static void lu_get_dump_state(struct lu_dump_state *state) +{ +} + +static void lu_close_dump_state(struct lu_dump_state *state) +{ +} #else static const char *lu_binary(const void *ctx, struct connection *conn, const char *filename) @@ -373,6 +389,50 @@ static void lu_dump_close(FILE *fp) { fclose(fp); } + +static void lu_get_dump_state(struct lu_dump_state *state) +{ + char *filename; + struct stat statbuf; + + state->size =3D 0; + + filename =3D talloc_asprintf(NULL, "%s/state_dump", xs_daemon_rootdir()); + if (!filename) + barf("Allocation failure"); + + state->fd =3D open(filename, O_RDONLY); + talloc_free(filename); + if (state->fd < 0) + return; + if (fstat(state->fd, &statbuf) !=3D 0) + goto out_close; + state->size =3D statbuf.st_size; + + state->buf =3D mmap(NULL, state->size, PROT_READ, MAP_PRIVATE, + state->fd, 0); + if (state->buf =3D=3D MAP_FAILED) { + state->size =3D 0; + goto out_close; + } + + return; + + out_close: + close(state->fd); +} + +static void lu_close_dump_state(struct lu_dump_state *state) +{ + char *filename; + + munmap(state->buf, state->size); + close(state->fd); + + filename =3D talloc_asprintf(NULL, "%s/state_dump", xs_daemon_rootdir()); + unlink(filename); + talloc_free(filename); +} #endif =20 static bool lu_check_lu_allowed(void) @@ -455,7 +515,47 @@ static const char *lu_dump_state(const void *ctx, stru= ct connection *conn) =20 void lu_read_state(void) { - xprintf("live-update: read state\n"); + struct lu_dump_state state; + struct xs_state_record_header *head; + void *ctx =3D talloc_new(NULL); /* Work context for subfunctions. */ + struct xs_state_preamble *pre; + + syslog(LOG_INFO, "live-update: read state\n"); + lu_get_dump_state(&state); + if (state.size =3D=3D 0) + barf_perror("No state found after live-update"); + + pre =3D state.buf; + if (memcmp(pre->ident, XS_STATE_IDENT, sizeof(pre->ident)) || + pre->version !=3D htobe32(XS_STATE_VERSION) || + pre->flags !=3D XS_STATE_FLAGS) + barf("Unknown record identifier"); + for (head =3D state.buf + sizeof(*pre); + head->type !=3D XS_STATE_TYPE_END && + (void *)head - state.buf < state.size; + head =3D (void *)head + sizeof(*head) + head->length) { + switch (head->type) { + case XS_STATE_TYPE_GLOBAL: + break; + case XS_STATE_TYPE_CONN: + break; + case XS_STATE_TYPE_WATCH: + break; + case XS_STATE_TYPE_TA: + xprintf("live-update: ignore transaction record\n"); + break; + case XS_STATE_TYPE_NODE: + break; + default: + xprintf("live-update: unknown state record %08x\n", + head->type); + break; + } + } + + lu_close_dump_state(&state); + + talloc_free(ctx); } =20 static const char *lu_activate_binary(const void *ctx) --=20 2.26.2 From nobody Mon Apr 29 15:17:07 2024 Delivered-To: importer@patchew.org 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; 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; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1610699464; cv=none; d=zohomail.com; s=zohoarc; b=VhXylDAfUSjyqa4LWEtg2T3lk6A1zit/F8iI5sljnPZUof6crKO24gEBmJ1rA+LjNNC16KCxa5ZKyiEPH6OgqMrmWNg7DKhewf2vgyIVIEeWRlRs6TdZWzrfsKKoSrIB4SntlX3RcHYws2DBLMBRj5LmSceLzYq3iqdIa14zmYU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610699464; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=MdMyp3DEAb+9Zw9HY9kn0zId5YKGUXIMBqIQPa1Gw/Q=; b=jq2xdl2kjBW9xfCnJUfYM6TI//hUx2BM4l8dZaAC+fLIROOPZZaxHj4lmjgX+PZK5+2Vn24BkHBTwtzzZcpLm71DNiBImIXbZ9K24P5MbBN8YvOAoVSv4ZDTdDg5H/s7HSJuQt5CRzS9xVKmOGPFe+CFxquvndhR/17Mq0u4yXg= ARC-Authentication-Results: i=1; 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; dmarc=pass header.from= (p=quarantine dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1610699464672170.04247235888056; Fri, 15 Jan 2021 00:31:04 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.67735.121167 (Exim 4.92) (envelope-from ) id 1l0KVP-0000z3-6B; Fri, 15 Jan 2021 08:30:51 +0000 Received: by outflank-mailman (output) from mailman id 67735.121167; Fri, 15 Jan 2021 08:30:51 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l0KVP-0000yt-1T; Fri, 15 Jan 2021 08:30:51 +0000 Received: by outflank-mailman (input) for mailman id 67735; Fri, 15 Jan 2021 08:30:49 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l0KVN-0008Gh-GM for xen-devel@lists.xenproject.org; Fri, 15 Jan 2021 08:30:49 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 9b0bcde9-4c77-4637-8514-e44ab0c2e90e; Fri, 15 Jan 2021 08:30:15 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 6B92AB96D; Fri, 15 Jan 2021 08:30:07 +0000 (UTC) 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: 9b0bcde9-4c77-4637-8514-e44ab0c2e90e X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1610699408; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=MdMyp3DEAb+9Zw9HY9kn0zId5YKGUXIMBqIQPa1Gw/Q=; b=W34zoFNpwNOQV0JXGHbonRNNclJ62EkYRqMPe8w2UZr1AnMJTJtMG2bEqS+lEHlCweRASF jYGzb/rr8KOdyJlrG/wQKc8vBwDzXduxrIQBcgn7uDII4Ma1CIjh1P/2EqsDyw7HyX0a+5 mmfIb98qrvCWIA/t16Us1XcXQsuQaOk= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Ian Jackson , Wei Liu , Julien Grall , Paul Durrant Subject: [PATCH v12 22/27] tools/xenstore: add reading global state for live update Date: Fri, 15 Jan 2021 09:29:55 +0100 Message-Id: <20210115083000.14186-23-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210115083000.14186-1-jgross@suse.com> References: <20210115083000.14186-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) Content-Type: text/plain; charset="utf-8" Add reading the global state for live update. Signed-off-by: Juergen Gross Acked-by: Julien Grall Reviewed-by: Paul Durrant --- tools/xenstore/xenstored_control.c | 1 + tools/xenstore/xenstored_core.c | 9 +++++++++ tools/xenstore/xenstored_core.h | 2 ++ 3 files changed, 12 insertions(+) diff --git a/tools/xenstore/xenstored_control.c b/tools/xenstore/xenstored_= control.c index 3bced9e39e..d94b558e99 100644 --- a/tools/xenstore/xenstored_control.c +++ b/tools/xenstore/xenstored_control.c @@ -536,6 +536,7 @@ void lu_read_state(void) head =3D (void *)head + sizeof(*head) + head->length) { switch (head->type) { case XS_STATE_TYPE_GLOBAL: + read_state_global(ctx, head + 1); break; case XS_STATE_TYPE_CONN: break; diff --git a/tools/xenstore/xenstored_core.c b/tools/xenstore/xenstored_cor= e.c index 4d88aeba3d..60e98104ad 100644 --- a/tools/xenstore/xenstored_core.c +++ b/tools/xenstore/xenstored_core.c @@ -2512,6 +2512,15 @@ const char *dump_state_nodes(FILE *fp, const void *c= tx) return dump_state_node_tree(fp, path); } =20 +void read_state_global(const void *ctx, const void *state) +{ + const struct xs_state_global *glb =3D state; + + sock =3D glb->socket_fd; + + domain_init(glb->evtchn_fd); +} + /* * Local variables: * mode: C diff --git a/tools/xenstore/xenstored_core.h b/tools/xenstore/xenstored_cor= e.h index c7567eaf0b..ac9fe1559e 100644 --- a/tools/xenstore/xenstored_core.h +++ b/tools/xenstore/xenstored_core.h @@ -265,6 +265,8 @@ const char *dump_state_node_perms(FILE *fp, struct xs_s= tate_node *sn, const struct xs_permissions *perms, unsigned int n_perms); =20 +void read_state_global(const void *ctx, const void *state); + #endif /* _XENSTORED_CORE_H */ =20 /* --=20 2.26.2 From nobody Mon Apr 29 15:17:07 2024 Delivered-To: importer@patchew.org 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; 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; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1610700042; cv=none; d=zohomail.com; s=zohoarc; b=NH/JLdiFyESa/PsTkpCBCWf4NVZKwpn2zn8+y5GMG4EQywpZfngbLt+SAm8yu/iOiQSfxYwWg7LpOzMwyFJDaebUZHfyMnWwC/LdaDQ17Qf+GOUKDKfsnAczxnBxT3aFD3NuVU36TASodHhXYWDJf9ifww3BscJUIwTsAoGi6Vk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610700042; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=DPiDfKORR274WTzYKQ9DOBvO587P9XpqEDkKKhCSltI=; b=Cibax4Xrpu0XGoMusGdsYdKwctyvheP0/bEIrkko5TvA+H4lXCJsA/j8HsRSxdny3HKpQ+s6+zfbtJx7NNbKZkb9ehJBjcVAPTse51/miNULsVuQqewceZwuqpyZ+wdv9Q8AhQKtieIMZNoY4dyGHa/Z+YhJRugaURVQHiIBuoo= ARC-Authentication-Results: i=1; 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; dmarc=pass header.from= (p=quarantine dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1610700042379587.3739238076463; Fri, 15 Jan 2021 00:40:42 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.67817.121262 (Exim 4.92) (envelope-from ) id 1l0Kef-0003Ve-No; Fri, 15 Jan 2021 08:40:25 +0000 Received: by outflank-mailman (output) from mailman id 67817.121262; Fri, 15 Jan 2021 08:40:25 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l0Kef-0003VW-JW; Fri, 15 Jan 2021 08:40:25 +0000 Received: by outflank-mailman (input) for mailman id 67817; Fri, 15 Jan 2021 08:40:24 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l0KVy-0008HA-P0 for xen-devel@lists.xenproject.org; Fri, 15 Jan 2021 08:31:26 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 2306d349-557f-47be-9e13-d6249dc05c68; Fri, 15 Jan 2021 08:30:15 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 7DF0FB95C; Fri, 15 Jan 2021 08:30:07 +0000 (UTC) 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: 2306d349-557f-47be-9e13-d6249dc05c68 X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1610699408; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=DPiDfKORR274WTzYKQ9DOBvO587P9XpqEDkKKhCSltI=; b=pnlQo4fWwha2kkFahPCbbMUOjy5FkXt6tAhWNAypd5vAsX1qmMyTndTgfzmYeqDL8POLiN LMlFzbHLEPuKHJSdhIa57yJ7gfa9X4oKUeorqxmbjmvakdI4URrThGZo3D4j6bQ85W1Vvf kJSfKmM1K1NG2TusBGAGJAuf1H4p84I= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Ian Jackson , Wei Liu , Julien Grall Subject: [PATCH v12 23/27] tools/xenstore: add read connection state for live update Date: Fri, 15 Jan 2021 09:29:56 +0100 Message-Id: <20210115083000.14186-24-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210115083000.14186-1-jgross@suse.com> References: <20210115083000.14186-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) Content-Type: text/plain; charset="utf-8" Add the needed functions for reading connection state for live update. As the connection is identified by a unique connection id in the state records we need to add this to struct connection. Add a new function to return the connection based on a connection id. Signed-off-by: Juergen Gross Reviewed-by: Julien Grall --- V2: - fixed condition in introduce_domain() (Julien Grall) V4: - set pending data msg type to XS_INVALID (Julien Grall) - add buffered read data (Julien Grall) V5: - really read buffered read data (Julien Grall) - drop conn parameter from introduce_domain() (Paul Durrant) - split pending write data into individual buffers V6: - rename "first" to "partial" (Paul Durrant) V7: - use local port from connection data V8: - remove dom0 special handling --- tools/xenstore/xenstored_control.c | 1 + tools/xenstore/xenstored_core.c | 102 ++++++++++++++++++++++++++++- tools/xenstore/xenstored_core.h | 10 +++ tools/xenstore/xenstored_domain.c | 60 +++++++++++++---- tools/xenstore/xenstored_domain.h | 2 + 5 files changed, 162 insertions(+), 13 deletions(-) diff --git a/tools/xenstore/xenstored_control.c b/tools/xenstore/xenstored_= control.c index d94b558e99..7428b836a5 100644 --- a/tools/xenstore/xenstored_control.c +++ b/tools/xenstore/xenstored_control.c @@ -539,6 +539,7 @@ void lu_read_state(void) read_state_global(ctx, head + 1); break; case XS_STATE_TYPE_CONN: + read_state_connection(ctx, head + 1); break; case XS_STATE_TYPE_WATCH: break; diff --git a/tools/xenstore/xenstored_core.c b/tools/xenstore/xenstored_cor= e.c index 60e98104ad..b2c544b165 100644 --- a/tools/xenstore/xenstored_core.c +++ b/tools/xenstore/xenstored_core.c @@ -1582,12 +1582,35 @@ struct connection *new_connection(connwritefn_t *wr= ite, connreadfn_t *read) return new; } =20 +struct connection *get_connection_by_id(unsigned int conn_id) +{ + struct connection *conn; + + list_for_each_entry(conn, &connections, list) + if (conn->conn_id =3D=3D conn_id) + return conn; + + return NULL; +} + #ifdef NO_SOCKETS static void accept_connection(int sock) { } + +int writefd(struct connection *conn, const void *data, unsigned int len) +{ + errno =3D EBADF; + return -1; +} + +int readfd(struct connection *conn, void *data, unsigned int len) +{ + errno =3D EBADF; + return -1; +} #else -static int writefd(struct connection *conn, const void *data, unsigned int= len) +int writefd(struct connection *conn, const void *data, unsigned int len) { int rc; =20 @@ -1603,7 +1626,7 @@ static int writefd(struct connection *conn, const voi= d *data, unsigned int len) return rc; } =20 -static int readfd(struct connection *conn, void *data, unsigned int len) +int readfd(struct connection *conn, void *data, unsigned int len) { int rc; =20 @@ -2521,6 +2544,81 @@ void read_state_global(const void *ctx, const void *= state) domain_init(glb->evtchn_fd); } =20 +static void add_buffered_data(struct buffered_data *bdata, + struct connection *conn, const uint8_t *data, + unsigned int len) +{ + bdata->hdr.msg.len =3D len; + if (len <=3D DEFAULT_BUFFER_SIZE) + bdata->buffer =3D bdata->default_buffer; + else + bdata->buffer =3D talloc_array(bdata, char, len); + if (!bdata->buffer) + barf("error restoring buffered data"); + + memcpy(bdata->buffer, data, len); + + /* Queue for later transmission. */ + list_add_tail(&bdata->list, &conn->out_list); +} + +void read_state_buffered_data(const void *ctx, struct connection *conn, + const struct xs_state_connection *sc) +{ + struct buffered_data *bdata; + const uint8_t *data; + unsigned int len; + bool partial =3D sc->data_resp_len; + + if (sc->data_in_len) { + bdata =3D new_buffer(conn); + if (!bdata) + barf("error restoring read data"); + if (sc->data_in_len < sizeof(bdata->hdr)) { + bdata->inhdr =3D true; + memcpy(&bdata->hdr, sc->data, sc->data_in_len); + bdata->used =3D sc->data_in_len; + } else { + bdata->inhdr =3D false; + memcpy(&bdata->hdr, sc->data, sizeof(bdata->hdr)); + if (bdata->hdr.msg.len <=3D DEFAULT_BUFFER_SIZE) + bdata->buffer =3D bdata->default_buffer; + else + bdata->buffer =3D talloc_array(bdata, char, + bdata->hdr.msg.len); + if (!bdata->buffer) + barf("Error allocating in buffer"); + bdata->used =3D sc->data_in_len - sizeof(bdata->hdr); + memcpy(bdata->buffer, sc->data + sizeof(bdata->hdr), + bdata->used); + } + + conn->in =3D bdata; + } + + for (data =3D sc->data + sc->data_in_len; + data < sc->data + sc->data_in_len + sc->data_out_len; + data +=3D len) { + bdata =3D new_buffer(conn); + if (!bdata) + barf("error restoring buffered data"); + if (partial) { + bdata->inhdr =3D false; + /* Make trace look nice. */ + bdata->hdr.msg.type =3D XS_INVALID; + len =3D sc->data_resp_len; + add_buffered_data(bdata, conn, data, len); + partial =3D false; + continue; + } + + memcpy(&bdata->hdr, data, sizeof(bdata->hdr)); + data +=3D sizeof(bdata->hdr); + len =3D bdata->hdr.msg.len; + add_buffered_data(bdata, conn, data, len); + } +} + /* * Local variables: * mode: C diff --git a/tools/xenstore/xenstored_core.h b/tools/xenstore/xenstored_cor= e.h index ac9fe1559e..dcb3ad3e4b 100644 --- a/tools/xenstore/xenstored_core.h +++ b/tools/xenstore/xenstored_core.h @@ -135,6 +135,9 @@ struct connection /* Methods for communicating over this connection: write can be NULL */ connwritefn_t *write; connreadfn_t *read; + + /* Support for live update: connection id. */ + unsigned int conn_id; }; extern struct list_head connections; =20 @@ -195,6 +198,7 @@ struct node *read_node(struct connection *conn, const v= oid *ctx, const char *name); =20 struct connection *new_connection(connwritefn_t *write, connreadfn_t *read= ); +struct connection *get_connection_by_id(unsigned int conn_id); void check_store(void); void corrupt(struct connection *conn, const char *fmt, ...); enum xs_perm_type perm_for_conn(struct connection *conn, @@ -250,6 +254,10 @@ void finish_daemonize(void); /* Open a pipe for signal handling */ void init_pipe(int reopen_log_pipe[2]); =20 +int writefd(struct connection *conn, const void *data, unsigned int len); +int readfd(struct connection *conn, void *data, unsigned int len); + +extern struct interface_funcs socket_funcs; extern xengnttab_handle **xgt_handle; =20 int remember_string(struct hashtable *hash, const char *str); @@ -266,6 +274,8 @@ const char *dump_state_node_perms(FILE *fp, struct xs_s= tate_node *sn, unsigned int n_perms); =20 void read_state_global(const void *ctx, const void *state); +void read_state_buffered_data(const void *ctx, struct connection *conn, + const struct xs_state_connection *sc); =20 #endif /* _XENSTORED_CORE_H */ =20 diff --git a/tools/xenstore/xenstored_domain.c b/tools/xenstore/xenstored_d= omain.c index 775546757b..6934f1bc89 100644 --- a/tools/xenstore/xenstored_domain.c +++ b/tools/xenstore/xenstored_domain.c @@ -355,7 +355,7 @@ static struct domain *find_or_alloc_domain(const void *= ctx, unsigned int domid) return domain ? : alloc_domain(ctx, domid); } =20 -static int new_domain(struct domain *domain, int port) +static int new_domain(struct domain *domain, int port, bool restore) { int rc; =20 @@ -369,11 +369,16 @@ static int new_domain(struct domain *domain, int port) =20 wrl_domain_new(domain); =20 - /* Tell kernel we're interested in this event. */ - rc =3D xenevtchn_bind_interdomain(xce_handle, domain->domid, port); - if (rc =3D=3D -1) - return errno; - domain->port =3D rc; + if (restore) + domain->port =3D port; + else { + /* Tell kernel we're interested in this event. */ + rc =3D xenevtchn_bind_interdomain(xce_handle, domain->domid, + port); + if (rc =3D=3D -1) + return errno; + domain->port =3D rc; + } =20 domain->introduced =3D true; =20 @@ -423,7 +428,7 @@ static void domain_conn_reset(struct domain *domain) =20 static struct domain *introduce_domain(const void *ctx, unsigned int domid, - evtchn_port_t port) + evtchn_port_t port, bool restore) { struct domain *domain; int rc; @@ -439,7 +444,7 @@ static struct domain *introduce_domain(const void *ctx, : map_interface(domid); if (!interface) return NULL; - if (new_domain(domain, port)) { + if (new_domain(domain, port, restore)) { rc =3D errno; if (is_master_domain) unmap_xenbus(interface); @@ -453,7 +458,7 @@ static struct domain *introduce_domain(const void *ctx, /* Now domain belongs to its connection. */ talloc_steal(domain->conn, domain); =20 - if (!is_master_domain) + if (!is_master_domain && !restore) fire_watches(NULL, ctx, "@introduceDomain", NULL, false, NULL); } else { @@ -486,7 +491,7 @@ int do_introduce(struct connection *conn, struct buffer= ed_data *in) if (port <=3D 0) return EINVAL; =20 - domain =3D introduce_domain(in, domid, port); + domain =3D introduce_domain(in, domid, port, false); if (!domain) return errno; =20 @@ -715,7 +720,7 @@ void dom0_init(void) if (port =3D=3D -1) barf_perror("Failed to initialize dom0 port"); =20 - dom0 =3D introduce_domain(NULL, xenbus_master_domid(), port); + dom0 =3D introduce_domain(NULL, xenbus_master_domid(), port, false); if (!dom0) barf_perror("Failed to initialize dom0"); =20 @@ -1261,6 +1266,39 @@ const char *dump_state_special_nodes(FILE *fp) return ret; } =20 +void read_state_connection(const void *ctx, const void *state) +{ + const struct xs_state_connection *sc =3D state; + struct connection *conn; + struct domain *domain, *tdomain; + + if (sc->conn_type =3D=3D XS_STATE_CONN_TYPE_SOCKET) { + conn =3D new_connection(writefd, readfd); + if (!conn) + barf("error restoring connection"); + conn->fd =3D sc->spec.socket_fd; + } else { + domain =3D introduce_domain(ctx, sc->spec.ring.domid, + sc->spec.ring.evtchn, true); + if (!domain) + barf("domain allocation error"); + + if (sc->spec.ring.tdomid !=3D DOMID_INVALID) { + tdomain =3D find_or_alloc_domain(ctx, + sc->spec.ring.tdomid); + if (!tdomain) + barf("target domain allocation error"); + talloc_reference(domain->conn, tdomain->conn); + domain->conn->target =3D tdomain->conn; + } + conn =3D domain->conn; + } + + conn->conn_id =3D sc->conn_id; + + read_state_buffered_data(ctx, conn, sc); +} + /* * Local variables: * mode: C diff --git a/tools/xenstore/xenstored_domain.h b/tools/xenstore/xenstored_d= omain.h index b20269b038..8f3b4e0f8b 100644 --- a/tools/xenstore/xenstored_domain.h +++ b/tools/xenstore/xenstored_domain.h @@ -101,4 +101,6 @@ void wrl_apply_debit_trans_commit(struct connection *co= nn); const char *dump_state_connections(FILE *fp, struct connection *conn); const char *dump_state_special_nodes(FILE *fp); =20 +void read_state_connection(const void *ctx, const void *state); + #endif /* _XENSTORED_DOMAIN_H */ --=20 2.26.2 From nobody Mon Apr 29 15:17:07 2024 Delivered-To: importer@patchew.org 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; 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; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1610699454; cv=none; d=zohomail.com; s=zohoarc; b=RyOZ2Ii5fUQGVnwaSRZs0YEHpiRtNJSmL0ETsacj+l3NKbnVN6jyTxAYPqhLGmVH/Lsi83tKPUG0F8LNzudsXEAZ+f3mcs32eH3Hox2gqOJ99V0SITIU2RCkMlFqZ4nHoyeWOMAOp0kfJKvh9MmtNHYfbrlhcWMtpWxA2tlpzhM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610699454; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=sSnAF7fRT0i6R+7d24NOVdIRMygQrGad5fUKdqzr1pY=; b=AV2rOfoliZRL8chfvKucRYkbfggy41vlD52yvk5rm1IjptEwkDj1/inhmuuArCYSKbz0MvWwJDyCfoglRjTPzKUMqizDEyiBc6N6POey03Zt9Q5q2mnh5KRNUI0ijfv0OOosfXpaZJzKOa29otnZebOY0hLYJklpOFv3RpmzIr0= ARC-Authentication-Results: i=1; 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; dmarc=pass header.from= (p=quarantine dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 161069945451416.97297997780231; Fri, 15 Jan 2021 00:30:54 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.67726.121119 (Exim 4.92) (envelope-from ) id 1l0KVE-0000b3-Nz; Fri, 15 Jan 2021 08:30:40 +0000 Received: by outflank-mailman (output) from mailman id 67726.121119; Fri, 15 Jan 2021 08:30:40 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l0KVE-0000aa-9p; Fri, 15 Jan 2021 08:30:40 +0000 Received: by outflank-mailman (input) for mailman id 67726; Fri, 15 Jan 2021 08:30:39 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l0KVD-0008Gh-Fs for xen-devel@lists.xenproject.org; Fri, 15 Jan 2021 08:30:39 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 9926760f-ac98-4180-9380-4be2dff450d1; Fri, 15 Jan 2021 08:30:14 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 7F23DB944; Fri, 15 Jan 2021 08:30:07 +0000 (UTC) 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: 9926760f-ac98-4180-9380-4be2dff450d1 X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1610699408; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=sSnAF7fRT0i6R+7d24NOVdIRMygQrGad5fUKdqzr1pY=; b=okxDcM8Ov0R+Y8piHkHPx2GuDHma6Z2tr7Lnns8sGJyPCsCv4+T0DVeCfFSIkJk8BJ1E2Q MR1zXDn4y7VaFrBKig+aZbv7b328GOEXWpsyiSJM+HZTkaGykvSWgmC+n93fE6eRArlrKA IQOEfuxM3oKZea5tFc+ti2fFB+9fTUw= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Ian Jackson , Wei Liu , Paul Durrant , Julien Grall Subject: [PATCH v12 24/27] tools/xenstore: add read node state for live update Date: Fri, 15 Jan 2021 09:29:57 +0100 Message-Id: <20210115083000.14186-25-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210115083000.14186-1-jgross@suse.com> References: <20210115083000.14186-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) Content-Type: text/plain; charset="utf-8" Add the needed functions for reading node state for live update. This requires some refactoring of current node handling in Xenstore in order to avoid repeating the same code patterns multiple times. Signed-off-by: Juergen Gross Reviewed-by: Paul Durrant Acked-by: Julien Grall --- V4: - drop local node handling (Julien Grall) V5: - use set_tdb_key (Paul Durrant) V6: - add permission flag handling (Julien Grall) --- tools/xenstore/xenstored_control.c | 1 + tools/xenstore/xenstored_core.c | 105 ++++++++++++++++++++++++++--- tools/xenstore/xenstored_core.h | 1 + 3 files changed, 96 insertions(+), 11 deletions(-) diff --git a/tools/xenstore/xenstored_control.c b/tools/xenstore/xenstored_= control.c index 7428b836a5..287417de6b 100644 --- a/tools/xenstore/xenstored_control.c +++ b/tools/xenstore/xenstored_control.c @@ -547,6 +547,7 @@ void lu_read_state(void) xprintf("live-update: ignore transaction record\n"); break; case XS_STATE_TYPE_NODE: + read_state_node(ctx, head + 1); break; default: xprintf("live-update: unknown state record %08x\n", diff --git a/tools/xenstore/xenstored_core.c b/tools/xenstore/xenstored_cor= e.c index b2c544b165..a5c1a56c6c 100644 --- a/tools/xenstore/xenstored_core.c +++ b/tools/xenstore/xenstored_core.c @@ -979,13 +979,30 @@ static char *basename(const char *name) return strrchr(name, '/') + 1; } =20 -static struct node *construct_node(struct connection *conn, const void *ct= x, - const char *name) +static int add_child(const void *ctx, struct node *parent, const char *nam= e) { const char *base; unsigned int baselen; + char *children; + + base =3D basename(name); + baselen =3D strlen(base) + 1; + children =3D talloc_array(ctx, char, parent->childlen + baselen); + if (!children) + return ENOMEM; + memcpy(children, parent->children, parent->childlen); + memcpy(children + parent->childlen, base, baselen); + parent->children =3D children; + parent->childlen +=3D baselen; + + return 0; +} + +static struct node *construct_node(struct connection *conn, const void *ct= x, + const char *name) +{ struct node *parent, *node; - char *children, *parentname =3D get_parent(ctx, name); + char *parentname =3D get_parent(ctx, name); =20 if (!parentname) return NULL; @@ -998,15 +1015,8 @@ static struct node *construct_node(struct connection = *conn, const void *ctx, return NULL; =20 /* Add child to parent. */ - base =3D basename(name); - baselen =3D strlen(base) + 1; - children =3D talloc_array(ctx, char, parent->childlen + baselen); - if (!children) + if (add_child(ctx, parent, name)) goto nomem; - memcpy(children, parent->children, parent->childlen); - memcpy(children + parent->childlen, base, baselen); - parent->children =3D children; - parent->childlen +=3D baselen; =20 /* Allocate node */ node =3D talloc(ctx, struct node); @@ -2619,6 +2629,79 @@ void read_state_buffered_data(const void *ctx, struc= t connection *conn, } } =20 +void read_state_node(const void *ctx, const void *state) +{ + const struct xs_state_node *sn =3D state; + struct node *node, *parent; + TDB_DATA key; + char *name, *parentname; + unsigned int i; + struct connection conn =3D { .id =3D priv_domid }; + + name =3D (char *)(sn->perms + sn->perm_n); + node =3D talloc(ctx, struct node); + if (!node) + barf("allocation error restoring node"); + + node->name =3D name; + node->generation =3D ++generation; + node->datalen =3D sn->data_len; + node->data =3D name + sn->path_len; + node->childlen =3D 0; + node->children =3D NULL; + node->perms.num =3D sn->perm_n; + node->perms.p =3D talloc_array(node, struct xs_permissions, + node->perms.num); + if (!node->perms.p) + barf("allocation error restoring node"); + for (i =3D 0; i < node->perms.num; i++) { + switch (sn->perms[i].access) { + case 'r': + node->perms.p[i].perms =3D XS_PERM_READ; + break; + case 'w': + node->perms.p[i].perms =3D XS_PERM_WRITE; + break; + case 'b': + node->perms.p[i].perms =3D XS_PERM_READ | XS_PERM_WRITE; + break; + default: + node->perms.p[i].perms =3D XS_PERM_NONE; + break; + } + if (sn->perms[i].flags & XS_STATE_NODE_PERM_IGNORE) + node->perms.p[i].perms |=3D XS_PERM_IGNORE; + node->perms.p[i].id =3D sn->perms[i].domid; + } + + if (strstarts(name, "@")) { + set_perms_special(&conn, name, &node->perms); + talloc_free(node); + return; + } + + parentname =3D get_parent(node, name); + if (!parentname) + barf("allocation error restoring node"); + parent =3D read_node(NULL, node, parentname); + if (!parent) + barf("read parent error restoring node"); + + if (add_child(node, parent, name)) + barf("allocation error restoring node"); + + set_tdb_key(parentname, &key); + if (write_node_raw(NULL, &key, parent, true)) + barf("write parent error restoring node"); + + set_tdb_key(name, &key); + if (write_node_raw(NULL, &key, node, true)) + barf("write node error restoring node"); + domain_entry_inc(&conn, node); + + talloc_free(node); +} + /* * Local variables: * mode: C diff --git a/tools/xenstore/xenstored_core.h b/tools/xenstore/xenstored_cor= e.h index dcb3ad3e4b..6ac5a6fbfa 100644 --- a/tools/xenstore/xenstored_core.h +++ b/tools/xenstore/xenstored_core.h @@ -276,6 +276,7 @@ const char *dump_state_node_perms(FILE *fp, struct xs_s= tate_node *sn, void read_state_global(const void *ctx, const void *state); void read_state_buffered_data(const void *ctx, struct connection *conn, const struct xs_state_connection *sc); +void read_state_node(const void *ctx, const void *state); =20 #endif /* _XENSTORED_CORE_H */ =20 --=20 2.26.2 From nobody Mon Apr 29 15:17:07 2024 Delivered-To: importer@patchew.org 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; 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; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1610700006; cv=none; d=zohomail.com; s=zohoarc; b=YBL2joP3wSV98b4RzhJpTF0wy7c9jv+hFDBJ1EHUe95lQb3v8To+VNmccqCgUGXvKuLkrGctnYdhbdKVRA3JsHZN9JeDtLtN8kRFmPcUEJir/2tAi9HEH94sf8EZ4HMMp3HQx7OFQFDAwL4HQjRPKxf3l1pArkhu0t58c7pDE8c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610700006; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=chZrRINMlN9NIz5hFmosn+ti87iJeN4zUTFjHuYKE7E=; b=aPD4p6GFM6bIbx6QX/itHtKqTUvKxUEDQpqZYmJew5httfiSR1vtnvcx3GUSG1/ctSvn9iFZ+VEVkuLtU5V34cvAFVsSXRVrBgzeFQgzzXsvXbbJkVptRPLFoTdLBiT1NvQViGow0XFRMMQJz4NhGxSeAiAjXkZMroUGwcw2pUk= ARC-Authentication-Results: i=1; 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; dmarc=pass header.from= (p=quarantine dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 161070000626563.86029671271751; Fri, 15 Jan 2021 00:40:06 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.67796.121239 (Exim 4.92) (envelope-from ) id 1l0Ke6-0002aT-63; Fri, 15 Jan 2021 08:39:50 +0000 Received: by outflank-mailman (output) from mailman id 67796.121239; Fri, 15 Jan 2021 08:39:50 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l0Ke6-0002aJ-2s; Fri, 15 Jan 2021 08:39:50 +0000 Received: by outflank-mailman (input) for mailman id 67796; Fri, 15 Jan 2021 08:39:48 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l0KW3-0008HA-PD for xen-devel@lists.xenproject.org; Fri, 15 Jan 2021 08:31:31 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id d03ffd5a-eac2-4136-824e-4a04e6eb56e6; Fri, 15 Jan 2021 08:30:16 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 97CA9B945; Fri, 15 Jan 2021 08:30:07 +0000 (UTC) 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: d03ffd5a-eac2-4136-824e-4a04e6eb56e6 X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1610699408; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=chZrRINMlN9NIz5hFmosn+ti87iJeN4zUTFjHuYKE7E=; b=KHQ1Q7M0X6qqMyqOHDUubODLDYskHcVgNa3DTwsCDen649F1ADI5PB6imY7EXeN+uPLWDm smP2slwNoMSrSDxcAdAp12WGvGTqz1AI49v+esVRxBuqpkI72fyu62u+SfQdRwJLyuoBze GM72Bk1t+4oDsbL0g2Offor/5GHLiWQ= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Ian Jackson , Wei Liu , Paul Durrant Subject: [PATCH v12 25/27] tools/xenstore: add read watch state for live update Date: Fri, 15 Jan 2021 09:29:58 +0100 Message-Id: <20210115083000.14186-26-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210115083000.14186-1-jgross@suse.com> References: <20210115083000.14186-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) Content-Type: text/plain; charset="utf-8" Add reading the watch state records for live update. This requires factoring out some of the add watch functionality into a dedicated function. Signed-off-by: Juergen Gross Reviewed-by: Paul Durrant --- V4: - add comment (Julien Grall) V6: - correct check_watch_path() (setting errno) --- tools/xenstore/xenstored_control.c | 2 + tools/xenstore/xenstored_watch.c | 114 +++++++++++++++++++++-------- tools/xenstore/xenstored_watch.h | 2 + 3 files changed, 88 insertions(+), 30 deletions(-) diff --git a/tools/xenstore/xenstored_control.c b/tools/xenstore/xenstored_= control.c index 287417de6b..b8195eed41 100644 --- a/tools/xenstore/xenstored_control.c +++ b/tools/xenstore/xenstored_control.c @@ -35,6 +35,7 @@ Interactive commands for Xen Store Daemon. #include "xenstored_core.h" #include "xenstored_control.h" #include "xenstored_domain.h" +#include "xenstored_watch.h" =20 /* Mini-OS only knows about MAP_ANON. */ #ifndef MAP_ANONYMOUS @@ -542,6 +543,7 @@ void lu_read_state(void) read_state_connection(ctx, head + 1); break; case XS_STATE_TYPE_WATCH: + read_state_watch(ctx, head + 1); break; case XS_STATE_TYPE_TA: xprintf("live-update: ignore transaction record\n"); diff --git a/tools/xenstore/xenstored_watch.c b/tools/xenstore/xenstored_wa= tch.c index 9248f08bd9..db89e0141f 100644 --- a/tools/xenstore/xenstored_watch.c +++ b/tools/xenstore/xenstored_watch.c @@ -205,6 +205,62 @@ static int destroy_watch(void *_watch) return 0; } =20 +static int check_watch_path(struct connection *conn, const void *ctx, + char **path, bool *relative) +{ + /* Check if valid event. */ + if (strstarts(*path, "@")) { + *relative =3D false; + if (strlen(*path) > XENSTORE_REL_PATH_MAX) + goto inval; + } else { + *relative =3D !strstarts(*path, "/"); + *path =3D canonicalize(conn, ctx, *path); + if (!*path) + return errno; + if (!is_valid_nodename(*path)) + goto inval; + } + + return 0; + + inval: + errno =3D EINVAL; + return errno; +} + +static struct watch *add_watch(struct connection *conn, char *path, char *= token, + bool relative) +{ + struct watch *watch; + + watch =3D talloc(conn, struct watch); + if (!watch) + goto nomem; + watch->node =3D talloc_strdup(watch, path); + watch->token =3D talloc_strdup(watch, token); + if (!watch->node || !watch->token) + goto nomem; + + if (relative) + watch->relative_path =3D get_implicit_path(conn); + else + watch->relative_path =3D NULL; + + INIT_LIST_HEAD(&watch->events); + + domain_watch_inc(conn); + list_add_tail(&watch->list, &conn->watches); + talloc_set_destructor(watch, destroy_watch); + + return watch; + + nomem: + talloc_free(watch); + errno =3D ENOMEM; + return NULL; +} + int do_watch(struct connection *conn, struct buffered_data *in) { struct watch *watch; @@ -214,19 +270,9 @@ int do_watch(struct connection *conn, struct buffered_= data *in) if (get_strings(in, vec, ARRAY_SIZE(vec)) !=3D ARRAY_SIZE(vec)) return EINVAL; =20 - if (strstarts(vec[0], "@")) { - relative =3D false; - if (strlen(vec[0]) > XENSTORE_REL_PATH_MAX) - return EINVAL; - /* check if valid event */ - } else { - relative =3D !strstarts(vec[0], "/"); - vec[0] =3D canonicalize(conn, in, vec[0]); - if (!vec[0]) - return ENOMEM; - if (!is_valid_nodename(vec[0])) - return EINVAL; - } + errno =3D check_watch_path(conn, in, &(vec[0]), &relative); + if (errno) + return errno; =20 /* Check for duplicates. */ list_for_each_entry(watch, &conn->watches, list) { @@ -238,26 +284,11 @@ int do_watch(struct connection *conn, struct buffered= _data *in) if (domain_watch(conn) > quota_nb_watch_per_domain) return E2BIG; =20 - watch =3D talloc(conn, struct watch); + watch =3D add_watch(conn, vec[0], vec[1], relative); if (!watch) - return ENOMEM; - watch->node =3D talloc_strdup(watch, vec[0]); - watch->token =3D talloc_strdup(watch, vec[1]); - if (!watch->node || !watch->token) { - talloc_free(watch); - return ENOMEM; - } - if (relative) - watch->relative_path =3D get_implicit_path(conn); - else - watch->relative_path =3D NULL; + return errno; =20 - INIT_LIST_HEAD(&watch->events); - - domain_watch_inc(conn); - list_add_tail(&watch->list, &conn->watches); trace_create(watch, "watch"); - talloc_set_destructor(watch, destroy_watch); send_ack(conn, XS_WATCH); =20 /* We fire once up front: simplifies clients and restart. */ @@ -338,6 +369,29 @@ const char *dump_state_watches(FILE *fp, struct connec= tion *conn, return ret; } =20 +void read_state_watch(const void *ctx, const void *state) +{ + const struct xs_state_watch *sw =3D state; + struct connection *conn; + char *path, *token; + bool relative; + + conn =3D get_connection_by_id(sw->conn_id); + if (!conn) + barf("connection not found for read watch"); + + path =3D (char *)sw->data; + token =3D path + sw->path_length; + + /* Don't check success, we want the relative information only. */ + check_watch_path(conn, ctx, &path, &relative); + if (!path) + barf("allocation error for read watch"); + + if (!add_watch(conn, path, token, relative)) + barf("error adding watch"); +} + /* * Local variables: * mode: C diff --git a/tools/xenstore/xenstored_watch.h b/tools/xenstore/xenstored_wa= tch.h index 3d81645f45..0e693f0839 100644 --- a/tools/xenstore/xenstored_watch.h +++ b/tools/xenstore/xenstored_watch.h @@ -33,4 +33,6 @@ void conn_delete_all_watches(struct connection *conn); const char *dump_state_watches(FILE *fp, struct connection *conn, unsigned int conn_id); =20 +void read_state_watch(const void *ctx, const void *state); + #endif /* _XENSTORED_WATCH_H */ --=20 2.26.2 From nobody Mon Apr 29 15:17:07 2024 Delivered-To: importer@patchew.org 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; 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; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1610699469; cv=none; d=zohomail.com; s=zohoarc; b=U9OSD/FK7GkJvcqOTbRdhjlG4+/Ilj6bQpyAsnu1TFEw/B79jWCl+nH2Z+Aq9ChJRK9XNpECAToScx2i81To01WCWdVeN+Duuuno4M0CO2X0Lv8DJnl2IUxSfbqiFur91rt2MKWzfqZAiTELEBfdyMzHihnt06sqvu8gde1HwKs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610699469; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=s87EsQNdAKvx1lyH1QYgj42flvmI+1JRarXqGbeqazE=; b=G9l9pUavXHPl1cTimNf9IXJf8fkrF6dyBEe3lubLwCkbVZf2XgQhdUDp/osybMVnkYJElczeEY79PqzEe+6NdNtIQaNF7UPp8veXLNtZVEU63w9tdnBCnAc+30xBIsOxIPB3Vy95+Fy8IS2xL4r9MNiegViBpEAJsc/tJJCkHQc= ARC-Authentication-Results: i=1; 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; dmarc=pass header.from= (p=quarantine dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1610699469100533.2064634226119; Fri, 15 Jan 2021 00:31:09 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.67740.121191 (Exim 4.92) (envelope-from ) id 1l0KVU-00019V-1W; Fri, 15 Jan 2021 08:30:56 +0000 Received: by outflank-mailman (output) from mailman id 67740.121191; Fri, 15 Jan 2021 08:30:56 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l0KVT-00019M-S7; Fri, 15 Jan 2021 08:30:55 +0000 Received: by outflank-mailman (input) for mailman id 67740; Fri, 15 Jan 2021 08:30:54 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l0KVS-0008Gh-GS for xen-devel@lists.xenproject.org; Fri, 15 Jan 2021 08:30:54 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id acfd7906-a0f8-44f6-9433-5f2cd337fc91; Fri, 15 Jan 2021 08:30:16 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id C920DB733; Fri, 15 Jan 2021 08:30:07 +0000 (UTC) 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: acfd7906-a0f8-44f6-9433-5f2cd337fc91 X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1610699408; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=s87EsQNdAKvx1lyH1QYgj42flvmI+1JRarXqGbeqazE=; b=h4Ueuj6ktVUvlU9OkLdiz7S6rQoAbig8eG+Le9/7fJVdo+GjKRNcAQTNKdVbpda48o7Kl8 pIhtaaE/f6FHNdD2RmMQ15Lj3Qyz5T8gPOowkawF63bIjM+lA5bBkdCUCVb1CdpodWZkxp 06Pnb9KYB32wqCFVs35GSK5drdwnR8U= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Julien Grall , Ian Jackson , Wei Liu , Juergen Gross , Paul Durrant Subject: [PATCH v12 26/27] tools/xenstore: handle dying domains in live update Date: Fri, 15 Jan 2021 09:29:59 +0100 Message-Id: <20210115083000.14186-27-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210115083000.14186-1-jgross@suse.com> References: <20210115083000.14186-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) Content-Type: text/plain; charset="utf-8" From: Julien Grall A domain could just be dying when live updating Xenstore, so the case of not being able to map the ring page or to connect to the event channel must be handled gracefully. Signed-off-by: Julien Grall Reviewed-by: Paul Durrant --- V4: - new patch (Julien, I hope adding the Sob: is okay?) V10: - removed "XXX..." comment (Julien Grall) --- tools/xenstore/xenstored_control.c | 7 +++++++ tools/xenstore/xenstored_domain.c | 25 +++++++++++++++++-------- tools/xenstore/xenstored_domain.h | 2 ++ 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/tools/xenstore/xenstored_control.c b/tools/xenstore/xenstored_= control.c index b8195eed41..3c212cc4d4 100644 --- a/tools/xenstore/xenstored_control.c +++ b/tools/xenstore/xenstored_control.c @@ -561,6 +561,13 @@ void lu_read_state(void) lu_close_dump_state(&state); =20 talloc_free(ctx); + + /* + * We may have missed the VIRQ_DOM_EXC notification and a domain may + * have died while we were live-updating. So check all the domains are + * still alive. + */ + check_domains(true); } =20 static const char *lu_activate_binary(const void *ctx) diff --git a/tools/xenstore/xenstored_domain.c b/tools/xenstore/xenstored_d= omain.c index 6934f1bc89..cbeb2a309c 100644 --- a/tools/xenstore/xenstored_domain.c +++ b/tools/xenstore/xenstored_domain.c @@ -220,7 +220,7 @@ static bool get_domain_info(unsigned int domid, xc_domi= nfo_t *dominfo) dominfo->domid =3D=3D domid; } =20 -static void domain_cleanup(void) +void check_domains(bool restore) { xc_dominfo_t dominfo; struct domain *domain; @@ -244,7 +244,14 @@ static void domain_cleanup(void) domain->shutdown =3D true; notify =3D 1; } - if (!dominfo.dying) + /* + * On Restore, we may have been unable to remap the + * interface and the port. As we don't know whether + * this was because of a dying domain, we need to + * check if the interface and port are still valid. + */ + if (!dominfo.dying && domain->port && + domain->interface) continue; } if (domain->conn) { @@ -270,7 +277,7 @@ void handle_event(void) barf_perror("Failed to read from event fd"); =20 if (port =3D=3D virq_port) - domain_cleanup(); + check_domains(false); =20 if (xenevtchn_unmask(xce_handle, port) =3D=3D -1) barf_perror("Failed to write to event fd"); @@ -442,14 +449,16 @@ static struct domain *introduce_domain(const void *ct= x, if (!domain->introduced) { interface =3D is_master_domain ? xenbus_map() : map_interface(domid); - if (!interface) + if (!interface && !restore) return NULL; if (new_domain(domain, port, restore)) { rc =3D errno; - if (is_master_domain) - unmap_xenbus(interface); - else - unmap_interface(interface); + if (interface) { + if (is_master_domain) + unmap_xenbus(interface); + else + unmap_interface(interface); + } errno =3D rc; return NULL; } diff --git a/tools/xenstore/xenstored_domain.h b/tools/xenstore/xenstored_d= omain.h index 8f3b4e0f8b..1cc1c03ed8 100644 --- a/tools/xenstore/xenstored_domain.h +++ b/tools/xenstore/xenstored_domain.h @@ -21,6 +21,8 @@ =20 void handle_event(void); =20 +void check_domains(bool restore); + /* domid, mfn, eventchn, path */ int do_introduce(struct connection *conn, struct buffered_data *in); =20 --=20 2.26.2 From nobody Mon Apr 29 15:17:07 2024 Delivered-To: importer@patchew.org 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; 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; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1610699974; cv=none; d=zohomail.com; s=zohoarc; b=kb7jHTkUDnGGdg6Ws5Ccw7a11H3/+WSbnF9YNeQjJNH+B9k9taiyx3pmuXwVEwm9dtoACLBGqG1Zds9aiqfQ0fRk2+Ft4MDgIl7VQek8txA/RXJCOTHhuhD/W4wekkdJRjX/gTTCBYuqG6EqYKvVP5M6fR9AKG9vxRT5rAsP4CA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610699974; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=XGzuxQnYzfc8rJK8syvxEKqLLXp0M6fORQPHnjkOtYc=; b=TbTLYJiHN6Ld0u/7+NJrgTzaZ4LNzWAkoBsNSoSWdk+7X41wXBN1rWa7pYVppaF+q/xgvFcOZhBfZAqDQEb6HCu9Oq5xMNFqJz9W6Nb0c2tmpg0LHZ28iexIv5rwZKLbPodOOmk18cv75DgX3bDBarSoFLC6B9FVAavkBKxvcDo= ARC-Authentication-Results: i=1; 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; dmarc=pass header.from= (p=quarantine dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1610699974793556.7585933064607; Fri, 15 Jan 2021 00:39:34 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.67782.121227 (Exim 4.92) (envelope-from ) id 1l0Kda-0002Pc-Rn; Fri, 15 Jan 2021 08:39:18 +0000 Received: by outflank-mailman (output) from mailman id 67782.121227; Fri, 15 Jan 2021 08:39:18 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l0Kda-0002PV-Oo; Fri, 15 Jan 2021 08:39:18 +0000 Received: by outflank-mailman (input) for mailman id 67782; Fri, 15 Jan 2021 08:39:17 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l0KVX-0008Gh-Gk for xen-devel@lists.xenproject.org; Fri, 15 Jan 2021 08:30:59 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id cfca8c9a-1c8e-4685-90d1-f5bd52a73124; Fri, 15 Jan 2021 08:30:16 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id EC288B92C; Fri, 15 Jan 2021 08:30:07 +0000 (UTC) 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: cfca8c9a-1c8e-4685-90d1-f5bd52a73124 X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1610699408; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=XGzuxQnYzfc8rJK8syvxEKqLLXp0M6fORQPHnjkOtYc=; b=LR+d8UFlv2UIVrBY1btxs0cNVe2HZDQ3e1uARlsjwrn766KER8RSRIffpO/qwERB4X0cz+ ONoCICkJMlJvJAi5icHi6G3v1cKbhvI6GUQReLZISGoXGvbqAeXxIf7z/piZQ+CgY3M8HP I0yI3gyy0AYazVykbK056MIiR5kQ0VM= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Ian Jackson , Wei Liu Subject: [PATCH v12 27/27] tools/xenstore: activate new binary for live update Date: Fri, 15 Jan 2021 09:30:00 +0100 Message-Id: <20210115083000.14186-28-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210115083000.14186-1-jgross@suse.com> References: <20210115083000.14186-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) Content-Type: text/plain; charset="utf-8" Add activation of the new binary for live update. The daemon case is handled completely, while for stubdom we only add stubs. Signed-off-by: Juergen Gross --- V7: - added unbinding dom0 and virq event channels V8: - no longer close dom0 evtchn (Julien Grall) V10: - remember original argc and argv (taken from deleted patch) --- tools/xenstore/xenstored_control.c | 61 +++++++++++++++++++++++++++++- tools/xenstore/xenstored_core.c | 5 +++ tools/xenstore/xenstored_core.h | 3 ++ tools/xenstore/xenstored_domain.c | 6 +++ tools/xenstore/xenstored_domain.h | 1 + 5 files changed, 75 insertions(+), 1 deletion(-) diff --git a/tools/xenstore/xenstored_control.c b/tools/xenstore/xenstored_= control.c index 3c212cc4d4..1f733e0a04 100644 --- a/tools/xenstore/xenstored_control.c +++ b/tools/xenstore/xenstored_control.c @@ -16,6 +16,7 @@ Interactive commands for Xen Store Daemon. along with this program; If not, see . */ =20 +#include #include #include #include @@ -335,6 +336,11 @@ static void lu_get_dump_state(struct lu_dump_state *st= ate) static void lu_close_dump_state(struct lu_dump_state *state) { } + +static char *lu_exec(const void *ctx, int argc, char **argv) +{ + return "NYI"; +} #else static const char *lu_binary(const void *ctx, struct connection *conn, const char *filename) @@ -434,6 +440,14 @@ static void lu_close_dump_state(struct lu_dump_state *= state) unlink(filename); talloc_free(filename); } + +static char *lu_exec(const void *ctx, int argc, char **argv) +{ + argv[0] =3D lu_status->filename; + execvp(argv[0], argv); + + return "Error activating new binary."; +} #endif =20 static bool lu_check_lu_allowed(void) @@ -572,7 +586,52 @@ void lu_read_state(void) =20 static const char *lu_activate_binary(const void *ctx) { - return "Not yet implemented."; + int argc; + char **argv; + unsigned int i; + + if (lu_status->cmdline) { + argc =3D 4; /* At least one arg + progname + "-U" + NULL. */ + for (i =3D 0; lu_status->cmdline[i]; i++) + if (isspace(lu_status->cmdline[i])) + argc++; + argv =3D talloc_array(ctx, char *, argc); + if (!argv) + return "Allocation failure."; + + i =3D 0; + argc =3D 1; + argv[1] =3D strtok(lu_status->cmdline, " \t"); + while (argv[argc]) { + if (!strcmp(argv[argc], "-U")) + i =3D 1; + argc++; + argv[argc] =3D strtok(NULL, " \t"); + } + + if (!i) { + argv[argc++] =3D "-U"; + argv[argc] =3D NULL; + } + } else { + for (i =3D 0; i < orig_argc; i++) + if (!strcmp(orig_argv[i], "-U")) + break; + + argc =3D orig_argc; + argv =3D talloc_array(ctx, char *, orig_argc + 2); + if (!argv) + return "Allocation failure."; + + memcpy(argv, orig_argv, orig_argc * sizeof(*argv)); + if (i =3D=3D orig_argc) + argv[argc++] =3D "-U"; + argv[argc] =3D NULL; + } + + domain_deinit(); + + return lu_exec(ctx, argc, argv); } =20 static bool do_lu_start(struct delayed_request *req) diff --git a/tools/xenstore/xenstored_core.c b/tools/xenstore/xenstored_cor= e.c index a5c1a56c6c..65ecdd0568 100644 --- a/tools/xenstore/xenstored_core.c +++ b/tools/xenstore/xenstored_core.c @@ -73,6 +73,9 @@ static unsigned int delayed_requests; =20 static int sock =3D -1; =20 +int orig_argc; +char **orig_argv; + static bool verbose =3D false; LIST_HEAD(connections); int tracefd =3D -1; @@ -2077,6 +2080,8 @@ int main(int argc, char *argv[]) const char *pidfile =3D NULL; int timeout; =20 + orig_argc =3D argc; + orig_argv =3D argv; =20 while ((opt =3D getopt_long(argc, argv, "DE:F:HNPS:t:A:M:T:RVW:U", option= s, NULL)) !=3D -1) { diff --git a/tools/xenstore/xenstored_core.h b/tools/xenstore/xenstored_cor= e.h index 6ac5a6fbfa..589699e833 100644 --- a/tools/xenstore/xenstored_core.h +++ b/tools/xenstore/xenstored_core.h @@ -222,6 +222,9 @@ void dtrace_io(const struct connection *conn, const str= uct buffered_data *data, void reopen_log(void); void close_log(void); =20 +extern int orig_argc; +extern char **orig_argv; + extern char *tracefile; extern int tracefd; =20 diff --git a/tools/xenstore/xenstored_domain.c b/tools/xenstore/xenstored_d= omain.c index cbeb2a309c..3d4d0649a2 100644 --- a/tools/xenstore/xenstored_domain.c +++ b/tools/xenstore/xenstored_domain.c @@ -783,6 +783,12 @@ void domain_init(int evtfd) virq_port =3D rc; } =20 +void domain_deinit(void) +{ + if (virq_port) + xenevtchn_unbind(xce_handle, virq_port); +} + void domain_entry_inc(struct connection *conn, struct node *node) { struct domain *d; diff --git a/tools/xenstore/xenstored_domain.h b/tools/xenstore/xenstored_d= omain.h index 1cc1c03ed8..dc97591713 100644 --- a/tools/xenstore/xenstored_domain.h +++ b/tools/xenstore/xenstored_domain.h @@ -46,6 +46,7 @@ int do_reset_watches(struct connection *conn, struct buff= ered_data *in); =20 void domain_init(int evtfd); void dom0_init(void); +void domain_deinit(void); =20 /* Returns the implicit path of a connection (only domains have this) */ const char *get_implicit_path(const struct connection *conn); --=20 2.26.2