From nobody Mon Feb 9 08:57:23 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=1673946745; cv=none; d=zohomail.com; s=zohoarc; b=WkdIfOf8hxk4QuU4ySt67L7j7fQTKKwNlYNhs2S8gA5k+MXXkFqpU4PX1MawEeSIRlX7WfBfdX8ArCfYoZ5N1lAsmnCqh/vLcrd1QyVoiC3fZfA8Y8H613mHvtP3+RtNVmKaAGtGcue5M5WwQhVqTfnhMd10yHBF7VTeWcQNxus= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1673946745; 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=WUUgoNnUcKdU+i5lp6nHtOPfrpUDA9Id/qGOmHDQ6xg=; b=aY10uXdSO4SKDP18I0cXhC4gQt0rjLo2aISD/2RQE3HG2gprqgxzb0FqIw7lfPBszlLjQzjdeMSQLrDdjXAbN/O+1vknI6Dfp7xnii/ieNxDnoyugxR9WbgjIaQQdvTCdY35oGi08FJARsg4j0D5zH0n9MzR/vOW/N7biux/EpM= 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 1673946745442784.3916352799811; Tue, 17 Jan 2023 01:12:25 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.479139.742819 (Exim 4.92) (envelope-from ) id 1pHi0h-000139-4c; Tue, 17 Jan 2023 09:12:03 +0000 Received: by outflank-mailman (output) from mailman id 479139.742819; Tue, 17 Jan 2023 09:12:03 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pHi0h-00012p-10; Tue, 17 Jan 2023 09:12:03 +0000 Received: by outflank-mailman (input) for mailman id 479139; Tue, 17 Jan 2023 09:12:02 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pHi0f-000725-Si for xen-devel@lists.xenproject.org; Tue, 17 Jan 2023 09:12:02 +0000 Received: from smtp-out1.suse.de (smtp-out1.suse.de [2001:67c:2178:6::1c]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 00088804-9647-11ed-91b6-6bf2151ebd3b; Tue, 17 Jan 2023 10:12:00 +0100 (CET) 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 794743821D; Tue, 17 Jan 2023 09:12:00 +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 4CE701390C; Tue, 17 Jan 2023 09:12:00 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id E285EWBmxmMgcAAAMHmgww (envelope-from ); Tue, 17 Jan 2023 09:12:00 +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: 00088804-9647-11ed-91b6-6bf2151ebd3b DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1673946720; 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=WUUgoNnUcKdU+i5lp6nHtOPfrpUDA9Id/qGOmHDQ6xg=; b=bdNDsjhoni8zdIgcTpxGj63EYKHYy7l21RJT/4G+/f0ua8Tqp7sZIjk7Cd04SoqY56KTQA IdMXqZOZ//rB4H1kVe5mJKYZrJI3/v/cVyviW9UYPEsrXc8PFQ08yFUDhW2fRQLm35EmTd E61Gc4ALypqcBOIeLj/y3ZiOVxlfKuY= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Julien Grall , Anthony PERARD Subject: [PATCH v3 06/17] tools/xenstore: move changed domain handling Date: Tue, 17 Jan 2023 10:11:13 +0100 Message-Id: <20230117091124.22170-7-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230117091124.22170-1-jgross@suse.com> References: <20230117091124.22170-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1673946745775100003 Content-Type: text/plain; charset="utf-8" Move all code related to struct changed_domain from xenstored_transaction.c to xenstored_domain.c. This will be needed later in order to simplify the accounting data updates in cases of errors during a request. Split the code to have a more generic base framework. Signed-off-by: Juergen Gross Reviewed-by: Julien Grall --- V2: - remove unrelated change (Julien Grall) V3: - modify acc_add_dom_nbentry() interface (Julien Grall) --- tools/xenstore/xenstored_domain.c | 78 ++++++++++++++++++++++++++ tools/xenstore/xenstored_domain.h | 3 + tools/xenstore/xenstored_transaction.c | 64 ++------------------- 3 files changed, 85 insertions(+), 60 deletions(-) diff --git a/tools/xenstore/xenstored_domain.c b/tools/xenstore/xenstored_d= omain.c index 99f0afcb1f..3a2ab5d87e 100644 --- a/tools/xenstore/xenstored_domain.c +++ b/tools/xenstore/xenstored_domain.c @@ -91,6 +91,18 @@ struct domain bool wrl_delay_logged; }; =20 +struct changed_domain +{ + /* List of all changed domains. */ + struct list_head list; + + /* Identifier of the changed domain. */ + unsigned int domid; + + /* Amount by which this domain's nbentry field has changed. */ + int nbentry; +}; + static struct hashtable *domhash; =20 static bool check_indexes(XENSTORE_RING_IDX cons, XENSTORE_RING_IDX prod) @@ -543,6 +555,72 @@ static struct domain *find_domain_by_domid(unsigned in= t domid) return (d && d->introduced) ? d : NULL; } =20 +int acc_fix_domains(struct list_head *head, bool update) +{ + struct changed_domain *cd; + int cnt; + + list_for_each_entry(cd, head, list) { + cnt =3D domain_entry_fix(cd->domid, cd->nbentry, update); + if (!update) { + if (cnt >=3D quota_nb_entry_per_domain) + return ENOSPC; + if (cnt < 0) + return ENOMEM; + } + } + + return 0; +} + +static struct changed_domain *acc_find_changed_domain(struct list_head *he= ad, + unsigned int domid) +{ + struct changed_domain *cd; + + list_for_each_entry(cd, head, list) { + if (cd->domid =3D=3D domid) + return cd; + } + + return NULL; +} + +static struct changed_domain *acc_get_changed_domain(const void *ctx, + struct list_head *head, + unsigned int domid) +{ + struct changed_domain *cd; + + cd =3D acc_find_changed_domain(head, domid); + if (cd) + return cd; + + cd =3D talloc_zero(ctx, struct changed_domain); + if (!cd) + return NULL; + + cd->domid =3D domid; + list_add_tail(&cd->list, head); + + return cd; +} + +int acc_add_dom_nbentry(const void *ctx, struct list_head *head, int val, + unsigned int domid) +{ + struct changed_domain *cd; + + cd =3D acc_get_changed_domain(ctx, head, domid); + if (!cd) + return 0; + + errno =3D 0; + cd->nbentry +=3D val; + + return cd->nbentry; +} + static void domain_conn_reset(struct domain *domain) { struct connection *conn =3D domain->conn; diff --git a/tools/xenstore/xenstored_domain.h b/tools/xenstore/xenstored_d= omain.h index 630641d620..9e20d2b17d 100644 --- a/tools/xenstore/xenstored_domain.h +++ b/tools/xenstore/xenstored_domain.h @@ -98,6 +98,9 @@ void domain_outstanding_dec(struct connection *conn); void domain_outstanding_domid_dec(unsigned int domid); int domain_get_quota(const void *ctx, struct connection *conn, unsigned int domid); +int acc_fix_domains(struct list_head *head, bool update); +int acc_add_dom_nbentry(const void *ctx, struct list_head *head, int val, + unsigned int domid); =20 /* Write rate limiting */ =20 diff --git a/tools/xenstore/xenstored_transaction.c b/tools/xenstore/xensto= red_transaction.c index ac854197ca..c009c67989 100644 --- a/tools/xenstore/xenstored_transaction.c +++ b/tools/xenstore/xenstored_transaction.c @@ -137,18 +137,6 @@ struct accessed_node bool watch_exact; }; =20 -struct changed_domain -{ - /* List of all changed domains in the context of this transaction. */ - struct list_head list; - - /* Identifier of the changed domain. */ - unsigned int domid; - - /* Amount by which this domain's nbentry field has changed. */ - int nbentry; -}; - struct transaction { /* List of all transactions active on this connection. */ @@ -514,24 +502,6 @@ int do_transaction_start(const void *ctx, struct conne= ction *conn, return 0; } =20 -static int transaction_fix_domains(struct transaction *trans, bool update) -{ - struct changed_domain *d; - int cnt; - - list_for_each_entry(d, &trans->changed_domains, list) { - cnt =3D domain_entry_fix(d->domid, d->nbentry, update); - if (!update) { - if (cnt >=3D quota_nb_entry_per_domain) - return ENOSPC; - if (cnt < 0) - return ENOMEM; - } - } - - return 0; -} - int do_transaction_end(const void *ctx, struct connection *conn, struct buffered_data *in) { @@ -558,7 +528,7 @@ int do_transaction_end(const void *ctx, struct connecti= on *conn, if (streq(arg, "T")) { if (trans->fail) return ENOMEM; - ret =3D transaction_fix_domains(trans, false); + ret =3D acc_fix_domains(&trans->changed_domains, false); if (ret) return ret; ret =3D finalize_transaction(conn, trans, &is_corrupt); @@ -568,7 +538,7 @@ int do_transaction_end(const void *ctx, struct connecti= on *conn, wrl_apply_debit_trans_commit(conn); =20 /* fix domain entry for each changed domain */ - transaction_fix_domains(trans, true); + acc_fix_domains(&trans->changed_domains, true); =20 if (is_corrupt) corrupt(conn, "transaction inconsistency"); @@ -580,44 +550,18 @@ int do_transaction_end(const void *ctx, struct connec= tion *conn, =20 void transaction_entry_inc(struct transaction *trans, unsigned int domid) { - struct changed_domain *d; - - list_for_each_entry(d, &trans->changed_domains, list) - if (d->domid =3D=3D domid) { - d->nbentry++; - return; - } - - d =3D talloc(trans, struct changed_domain); - if (!d) { + if (!acc_add_dom_nbentry(trans, &trans->changed_domains, 1, domid)) { /* Let the transaction fail. */ trans->fail =3D true; - return; } - d->domid =3D domid; - d->nbentry =3D 1; - list_add_tail(&d->list, &trans->changed_domains); } =20 void transaction_entry_dec(struct transaction *trans, unsigned int domid) { - struct changed_domain *d; - - list_for_each_entry(d, &trans->changed_domains, list) - if (d->domid =3D=3D domid) { - d->nbentry--; - return; - } - - d =3D talloc(trans, struct changed_domain); - if (!d) { + if (!acc_add_dom_nbentry(trans, &trans->changed_domains, -1, domid)) { /* Let the transaction fail. */ trans->fail =3D true; - return; } - d->domid =3D domid; - d->nbentry =3D -1; - list_add_tail(&d->list, &trans->changed_domains); } =20 void fail_transaction(struct transaction *trans) --=20 2.35.3