From nobody Mon Feb 9 02:28:13 2026 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=1608050235; cv=none; d=zohomail.com; s=zohoarc; b=AFCQoy87tG7O63y5gG0KPoynbSbFM0s8TNRnS4qjfqi+aBpOTMusp9uU1Ir9qrEQPsfZitTTNUICg8qV+iWB/hStABYXSlERyz+WJg9Ov2MhXCXdoeU1JoPGXGvBGVvf+L0MpIIo3fNRjd6elM+KFpyen5L6TG0prfKZC+xdDGU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608050235; 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=R/YgePDHO2chAetPsjOi7ZWAx5SNUZ/vW9zQWAbOTdQ=; b=DH2jnzICV7Y9q+WTnqKuUtztm3rOVFAx1H2y1YSyt8F0Tv8xodxxSsfEP+x7tVJ5gAkCtnpKPtxPqdN8UV6+qp+0bVBNMEfXmeOTV/CqqNnI5YyoGL2fbsVSAlaYQrA9/u2y3e1rLquNxadqqCgK9bB3AWHqm2gIhgHvXjKPqIo= 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 1608050235574380.7586350695111; Tue, 15 Dec 2020 08:37:15 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.54576.95060 (Exim 4.92) (envelope-from ) id 1kpDJq-0007gT-Et; Tue, 15 Dec 2020 16:36:58 +0000 Received: by outflank-mailman (output) from mailman id 54576.95060; Tue, 15 Dec 2020 16:36: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 1kpDJp-0007f9-LE; Tue, 15 Dec 2020 16:36:57 +0000 Received: by outflank-mailman (input) for mailman id 54576; Tue, 15 Dec 2020 16:36: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 1kpDJo-00066M-IH for xen-devel@lists.xenproject.org; Tue, 15 Dec 2020 16:36:56 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 857a6ad4-b29c-4827-a73a-71328af6fe5c; Tue, 15 Dec 2020 16:36:13 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 6EE9DB27D; Tue, 15 Dec 2020 16:36:11 +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: 857a6ad4-b29c-4827-a73a-71328af6fe5c 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=1608050171; 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=R/YgePDHO2chAetPsjOi7ZWAx5SNUZ/vW9zQWAbOTdQ=; b=l6TmpsIfi+RAU/bRj31ztEcxBtN0mSauw50kqJj9NUxt1gBX8mrlwp1nsRe0tZpLgfxWah jLp2DbXnxoP7YyOe3xlSMaVZYM/AyME+1Mcvykid4KF9h7WPugbCSm9rBXbUBquMkEYTk+ n4jzfo1ruRxhLs+82NSiUw9KEaKqCNo= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Ian Jackson , Wei Liu , Julien Grall Subject: [PATCH v10 18/25] tools/xenstore: evaluate the live update flag when starting Date: Tue, 15 Dec 2020 17:35:56 +0100 Message-Id: <20201215163603.21700-19-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201215163603.21700-1-jgross@suse.com> References: <20201215163603.21700-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) Signed-off-by: Juergen Gross --- tools/xenstore/xenstored_control.c | 5 ++++ tools/xenstore/xenstored_control.h | 1 + tools/xenstore/xenstored_core.c | 43 +++++++++++++++++++++--------- tools/xenstore/xenstored_domain.c | 26 +++++++++--------- tools/xenstore/xenstored_domain.h | 3 ++- tools/xenstore/xenstored_posix.c | 1 - 6 files changed, 50 insertions(+), 29 deletions(-) diff --git a/tools/xenstore/xenstored_control.c b/tools/xenstore/xenstored_= control.c index 437276de8d..a539666410 100644 --- a/tools/xenstore/xenstored_control.c +++ b/tools/xenstore/xenstored_control.c @@ -436,6 +436,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 0f4e10815a..d6f8373ee0 100644 --- a/tools/xenstore/xenstored_core.c +++ b/tools/xenstore/xenstored_core.c @@ -1637,9 +1637,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"); @@ -1653,14 +1654,16 @@ 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"); + } =20 check_store(); } =20 - static unsigned int hash_from_key_fn(void *k) { char *str =3D k; @@ -2066,7 +2069,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); @@ -2081,17 +2085,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()); @@ -2099,13 +2106,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 @@ -2113,8 +2128,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..94dd501a3b 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_open_fd(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