From nobody Mon Feb 9 23:58:02 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=1631622984; cv=none; d=zohomail.com; s=zohoarc; b=G83qKiM/Z3FbUmWuSsNVkW8Q0gErIYOT68uGVtvI/Ep6Hj/qL2GvOdnO8b6tm8kd8fuZl5i1yJo42aPTslyBvZ8WaPjyqUY3sRJfEBNbnnhH/km7Wuflpsr5ad1OMOP1GK3Vfxm3BgcRUW5Zl/htWSE/P2RL4Up5kdnotAsmMXM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1631622984; 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=EH+dU3e+z7VJuNtk1nknzKQyPzqsv/7YUiwjiyb6J/Y=; b=inb/UFT2FYo10lzNaiCGPycvUbfkmmtizeQryKn6VHRJox6aGhhR5qwDgWEBMxUG5G6cIb+lpBstAiq2qyhj6B53QDxjo79My6vnI/ITkBqZkLEciKajiPAUB9ieeci3+3cH7gInRkhwvvM6yQ+kPFS+DSRukK+6QMdXGCqoiQU= 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) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1631622984816377.286760631119; Tue, 14 Sep 2021 05:36:24 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.186542.335285 (Exim 4.92) (envelope-from ) id 1mQ7fU-0007HC-Cz; Tue, 14 Sep 2021 12:36:08 +0000 Received: by outflank-mailman (output) from mailman id 186542.335285; Tue, 14 Sep 2021 12:36:08 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mQ7fU-0007H1-99; Tue, 14 Sep 2021 12:36:08 +0000 Received: by outflank-mailman (input) for mailman id 186542; Tue, 14 Sep 2021 12:36:07 +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 1mQ7fT-0007Eq-4s for xen-devel@lists.xenproject.org; Tue, 14 Sep 2021 12:36:07 +0000 Received: from smtp-out1.suse.de (unknown [195.135.220.28]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 5388358e-1558-11ec-b421-12813bfff9fa; Tue, 14 Sep 2021 12:36:05 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 3AC06220EA; Tue, 14 Sep 2021 12:36:04 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id F3D8113F2C; Tue, 14 Sep 2021 12:36:03 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id KAwKOjOXQGE7MAAAMHmgww (envelope-from ); Tue, 14 Sep 2021 12:36:03 +0000 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: 5388358e-1558-11ec-b421-12813bfff9fa DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1631622964; 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=EH+dU3e+z7VJuNtk1nknzKQyPzqsv/7YUiwjiyb6J/Y=; b=TAlRcuSOmk3CTnhnWvKPvzACQ7Z/l+R/61XeosOOYScQ8OsPEoN/cJtEFpSfb2XQBsR1JQ Je4hMLDeXehqBLqwUo9bY4QCdnKRmkQ+VlSSeAL4HtSp1/tYGJF7hwGGkgcAEOWnFLOMor EI0btNofF2tB5b5ozK7zgzAIhlb/LsY= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Ian Jackson , Wei Liu , Julien Grall Subject: [PATCH RFC 4/4] tools/xenstore: use new stable interface instead of libxenctrl Date: Tue, 14 Sep 2021 14:36:00 +0200 Message-Id: <20210914123600.1626-5-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210914123600.1626-1-jgross@suse.com> References: <20210914123600.1626-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1631622985988100001 Content-Type: text/plain; charset="utf-8" Xenstore is using libxenctrl only for obtaining state information about domains. Use the new stable interface XEN_CONTROL_OP_get_state_changed_domain instead. Signed-off-by: Juergen Gross --- tools/xenstore/Makefile | 3 +- tools/xenstore/xenstored_control.c | 14 +- tools/xenstore/xenstored_domain.c | 219 ++++++++++++++++------------- 3 files changed, 130 insertions(+), 106 deletions(-) diff --git a/tools/xenstore/Makefile b/tools/xenstore/Makefile index 292b478fa1..b78e29470b 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_libxencall) CFLAGS +=3D $(CFLAGS_libxenguest) CFLAGS +=3D $(CFLAGS_libxentoolcore) CFLAGS +=3D -DXEN_LIB_STORED=3D"\"$(XEN_LIB_STORED)\"" @@ -70,7 +71,7 @@ endif $(XENSTORED_OBJS): CFLAGS +=3D $(CFLAGS_libxengnttab) =20 xenstored: $(XENSTORED_OBJS) - $(CC) $^ $(LDFLAGS) $(LDLIBS_libxenevtchn) $(LDLIBS_libxengnttab) $(LDLIB= S_libxenctrl) $(LDLIBS_xenstored) $(SOCKET_LIBS) -o $@ $(APPEND_LDFLAGS) + $(CC) $^ $(LDFLAGS) $(LDLIBS_libxenevtchn) $(LDLIBS_libxengnttab) $(LDLIB= S_libxencall) $(LDLIBS_xenstored) $(SOCKET_LIBS) -o $@ $(APPEND_LDFLAGS) =20 xenstored.a: $(XENSTORED_OBJS) $(AR) cr $@ $^ diff --git a/tools/xenstore/xenstored_control.c b/tools/xenstore/xenstored_= control.c index 7b4300ef77..d767aea0f9 100644 --- a/tools/xenstore/xenstored_control.c +++ b/tools/xenstore/xenstored_control.c @@ -594,6 +594,13 @@ void lu_read_state(void) void *ctx =3D talloc_new(NULL); /* Work context for subfunctions. */ struct xs_state_preamble *pre; =20 + /* + * 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. This will pre-initialize all domain structures. + */ + check_domains(); + syslog(LOG_INFO, "live-update: read state\n"); lu_get_dump_state(&state); if (state.size =3D=3D 0) @@ -634,13 +641,6 @@ 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(); } =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 47e9107c14..2801e4b24f 100644 --- a/tools/xenstore/xenstored_domain.c +++ b/tools/xenstore/xenstored_domain.c @@ -31,11 +31,12 @@ #include "xenstored_transaction.h" #include "xenstored_watch.h" =20 +#include #include -#include +#include #include =20 -static xc_interface **xc_handle; +static xencall_handle **xc_handle; xengnttab_handle **xgt_handle; static evtchn_port_t virq_port; =20 @@ -50,6 +51,7 @@ struct domain =20 /* The id of this domain */ unsigned int domid; + uint64_t unique_id; =20 /* Event channel port */ evtchn_port_t port; @@ -238,54 +240,114 @@ static int destroy_domain(void *_domain) return 0; } =20 -static bool get_domain_info(unsigned int domid, xc_dominfo_t *dominfo) +static bool get_domain_info(struct xen_control_changed_domain *dominfo) { - return xc_domain_getinfo(*xc_handle, domid, 1, dominfo) =3D=3D 1 && - dominfo->domid =3D=3D domid; + struct xen_control_changed_domain *buf; + int ret; + + buf =3D xencall_alloc_buffer(*xc_handle, sizeof(*buf)); + if (!buf) + return false; + ret =3D xencall2(*xc_handle, __HYPERVISOR_control_op, + XEN_CONTROL_OP_get_state_changed_domain, + (unsigned long)buf); + *dominfo =3D *buf; + xencall_free_buffer(*xc_handle, buf); + + return ret =3D=3D 0; } =20 -void check_domains(void) +static struct domain *find_domain_struct(unsigned int domid) +{ + struct domain *i; + + list_for_each_entry(i, &domains, list) { + if (i->domid =3D=3D domid) + return i; + } + return NULL; +} + +static struct domain *alloc_domain(unsigned int domid) { - xc_dominfo_t dominfo; struct domain *domain; + + domain =3D talloc_zero(talloc_autofree_context(), struct domain); + if (!domain) { + errno =3D ENOMEM; + return NULL; + } + + domain->domid =3D domid; + domain->generation =3D generation; + domain->introduced =3D false; + + talloc_set_destructor(domain, destroy_domain); + + list_add(&domain->list, &domains); + + return domain; +} + +static void domain_drop(struct domain *domain) +{ struct connection *conn; + + /* domain is a talloc child of domain->conn. */ + conn =3D domain->conn; + domain->conn =3D NULL; + talloc_unlink(talloc_autofree_context(), conn); +} + +void check_domains(void) +{ + struct xen_control_changed_domain dominfo; + struct domain *domain; int notify =3D 0; - bool dom_valid; =20 - again: - list_for_each_entry(domain, &domains, list) { - dom_valid =3D get_domain_info(domain->domid, &dominfo); - if (!domain->introduced) { - if (!dom_valid) { + while (get_domain_info(&dominfo)) { + domain =3D find_domain_struct(dominfo.domid); + + if (!dominfo.state) { + if (domain && !domain->introduced) talloc_free(domain); - goto again; - } continue; } - if (dom_valid) { - if ((dominfo.crashed || dominfo.shutdown) - && !domain->shutdown) { - domain->shutdown =3D true; - notify =3D 1; - } - /* - * 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) + + if (domain && domain->unique_id && + domain->unique_id !=3D dominfo.unique_id) { + if (domain->conn) + domain_drop(domain); + else + talloc_free(domain); + domain =3D NULL; + } + + if (!domain) { + domain =3D alloc_domain(dominfo.domid); + if (!domain) continue; + domain->unique_id =3D dominfo.unique_id; } - if (domain->conn) { - /* domain is a talloc child of domain->conn. */ - conn =3D domain->conn; - domain->conn =3D NULL; - talloc_unlink(talloc_autofree_context(), conn); - notify =3D 0; /* destroy_domain() fires the watch */ - goto again; + + if ((dominfo.state & XEN_CONTROL_CHANGEDDOM_STATE_SHUTDOWN) && + !domain->shutdown) { + domain->shutdown =3D true; + notify =3D 1; } + + /* + * 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.state & XEN_CONTROL_CHANGEDDOM_STATE_DYING) && + domain->port && domain->interface) + continue; + + if (domain->conn) + domain_drop(domain); } =20 if (notify) @@ -323,46 +385,6 @@ static char *talloc_domain_path(void *context, unsigne= d int domid) return talloc_asprintf(context, "/local/domain/%u", domid); } =20 -static struct domain *find_domain_struct(unsigned int domid) -{ - struct domain *i; - - list_for_each_entry(i, &domains, list) { - if (i->domid =3D=3D domid) - return i; - } - return NULL; -} - -static struct domain *alloc_domain(const void *context, unsigned int domid) -{ - struct domain *domain; - - domain =3D talloc(context, struct domain); - if (!domain) { - errno =3D ENOMEM; - return NULL; - } - - domain->domid =3D domid; - domain->generation =3D generation; - domain->introduced =3D false; - - talloc_set_destructor(domain, destroy_domain); - - list_add(&domain->list, &domains); - - return domain; -} - -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, bool restore) { int rc; @@ -443,9 +465,13 @@ static struct domain *introduce_domain(const void *ctx, struct xenstore_domain_interface *interface; bool is_master_domain =3D (domid =3D=3D xenbus_master_domid()); =20 - domain =3D find_or_alloc_domain(ctx, domid); - if (!domain) + check_domains(); + + domain =3D find_domain_struct(domid); + if (!domain) { + errno =3D ENOENT; return NULL; + } =20 if (!domain->introduced) { interface =3D is_master_domain ? xenbus_map() @@ -650,7 +676,7 @@ int do_reset_watches(struct connection *conn, struct bu= ffered_data *in) =20 static int close_xc_handle(void *_handle) { - xc_interface_close(*(xc_interface**)_handle); + xencall_close(*(xencall_handle **)_handle); return 0; } =20 @@ -741,11 +767,11 @@ void domain_init(int evtfd) { int rc; =20 - xc_handle =3D talloc(talloc_autofree_context(), xc_interface*); + xc_handle =3D talloc(talloc_autofree_context(), xencall_handle *); if (!xc_handle) barf_perror("Failed to allocate domain handle"); =20 - *xc_handle =3D xc_interface_open(0,0,0); + *xc_handle =3D xencall_open(NULL, 0); if (!*xc_handle) barf_perror("Failed to open connection to hypervisor"); =20 @@ -821,7 +847,6 @@ void domain_entry_inc(struct connection *conn, struct n= ode *node) * count (used for testing whether a node permission is older than a domai= n). * * Return values: - * -1: error * 0: domain has higher generation count (it is younger than a node with = the * given count), or domain isn't existing any longer * 1: domain is older than the node @@ -829,7 +854,6 @@ void domain_entry_inc(struct connection *conn, struct n= ode *node) static int chk_domain_generation(unsigned int domid, uint64_t gen) { struct domain *d; - xc_dominfo_t dominfo; =20 if (!xc_handle && domid =3D=3D 0) return 1; @@ -838,11 +862,9 @@ static int chk_domain_generation(unsigned int domid, u= int64_t gen) if (d) return (d->generation <=3D gen) ? 1 : 0; =20 - if (!get_domain_info(domid, &dominfo)) - return 0; - - d =3D alloc_domain(NULL, domid); - return d ? 1 : -1; + check_domains(); + d =3D find_domain_struct(domid); + return (d && d->generation <=3D gen) ? 1 : 0; } =20 /* @@ -855,8 +877,6 @@ int domain_adjust_node_perms(struct node *node) int ret; =20 ret =3D chk_domain_generation(node->perms.p[0].id, node->generation); - if (ret < 0) - return errno; =20 /* If the owner doesn't exist any longer give it to priv domain. */ if (!ret) @@ -867,8 +887,6 @@ int domain_adjust_node_perms(struct node *node) continue; ret =3D chk_domain_generation(node->perms.p[i].id, node->generation); - if (ret < 0) - return errno; if (!ret) node->perms.p[i].perms |=3D XS_PERM_IGNORE; } @@ -1300,16 +1318,21 @@ void read_state_connection(const void *ctx, const v= oid *state) } else { domain =3D introduce_domain(ctx, sc->spec.ring.domid, sc->spec.ring.evtchn, true); - if (!domain) + if (!domain) { + /* Domain vanished during LM? */ + if (errno =3D ENOENT) + return; barf("domain allocation error"); + } =20 if (sc->spec.ring.tdomid !=3D DOMID_INVALID) { - tdomain =3D find_or_alloc_domain(ctx, - sc->spec.ring.tdomid); - if (!tdomain) + tdomain =3D find_domain_struct(sc->spec.ring.tdomid); + if (!tdomain && errno !=3D ENOENT) barf("target domain allocation error"); - talloc_reference(domain->conn, tdomain->conn); - domain->conn->target =3D tdomain->conn; + if (tdomain) { + talloc_reference(domain->conn, tdomain->conn); + domain->conn->target =3D tdomain->conn; + } } conn =3D domain->conn; } --=20 2.26.2