From nobody Wed May 15 14:38:27 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=1680678265; cv=none; d=zohomail.com; s=zohoarc; b=Cf1fNgAvl+9Esv7UUVI8u6WJ3I7vggMy7+EKa6HN8vfQJCasuQCP+Lluihr4KynylJMgmmLhUVdwqGEo8DMEUCKryIYpg5eCDq5PAeAd6XvS3Vl70sBQyTFpCywOn0KC8VlmqKwRO4JQ/PltJRcrSOfpDZjTfHASMeG7gJW29tk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1680678265; 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=jR2CaVJDZ2qBizxTmbgLfYMIkR5bcQwiTfYf2yndaVw=; b=L3b6ioygJNGwslXptSoHnRWwCEdRoeECUD3XFMdGXXstPzY8keSa2Wfux7uOmnklO2Zofi1BUR/4CVb4v0ud5i6JU8XMYwUYb1i+xkwGdh9rgCxDUau1CmQpm5EfNSxJCiNkWU9YaEXS6wEbfHiiVZUXYclPfHH8ekTFExASy0o= 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 1680678265654540.6255531469362; Wed, 5 Apr 2023 00:04:25 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.518229.804537 (Exim 4.92) (envelope-from ) id 1pjxBY-0002Uy-AS; Wed, 05 Apr 2023 07:04:00 +0000 Received: by outflank-mailman (output) from mailman id 518229.804537; Wed, 05 Apr 2023 07:04:00 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pjxBY-0002Un-7C; Wed, 05 Apr 2023 07:04:00 +0000 Received: by outflank-mailman (input) for mailman id 518229; Wed, 05 Apr 2023 07:03:59 +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 1pjxBX-0002UC-4m for xen-devel@lists.xenproject.org; Wed, 05 Apr 2023 07:03:59 +0000 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 08a76ca9-d380-11ed-85db-49a42c6b2330; Wed, 05 Apr 2023 09:03:57 +0200 (CEST) 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 35663229E9; Wed, 5 Apr 2023 07:03:57 +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 0655A13A31; Wed, 5 Apr 2023 07:03:56 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id ZzxgO1wdLWRUEwAAMHmgww (envelope-from ); Wed, 05 Apr 2023 07:03:56 +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: 08a76ca9-d380-11ed-85db-49a42c6b2330 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1680678237; 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=jR2CaVJDZ2qBizxTmbgLfYMIkR5bcQwiTfYf2yndaVw=; b=PNm3qfd93Y9Gavr2aSfwatm6iAcArvUAkI79Ec4Tyz5JmZRSAEqnX+J++bZAENfZdrmhrV c0EkT/oJCwY1tWWec5KmRLnWNFn+p233Vqh67Dit3FLRkxAE9kWF+lGf+1CSX4WsBiX6gG WFxSSwcrukx/2dldNX1uTN9jlLZrpUY= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Julien Grall , Anthony PERARD , Julien Grall Subject: [PATCH v4 01/13] tools/xenstore: take transaction internal nodes into account for quota Date: Wed, 5 Apr 2023 09:03:37 +0200 Message-Id: <20230405070349.25293-2-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230405070349.25293-1-jgross@suse.com> References: <20230405070349.25293-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1680678267983100001 Content-Type: text/plain; charset="utf-8" The accounting for the number of nodes of a domain in an active transaction is not working correctly, as it is checking the node quota only against the number of nodes outside the transaction. This can result in the transaction finally failing, as node quota is checked at the end of the transaction again. On the other hand even in a transaction deleting many nodes, new nodes might not be creatable, in case the node quota was already reached at the start of the transaction. Signed-off-by: Juergen Gross Acked-by: Julien Grall --- V3: - rewrite of commit message (Julien Grall) --- tools/xenstore/xenstored_domain.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tools/xenstore/xenstored_domain.c b/tools/xenstore/xenstored_d= omain.c index f62be2245c..dbbf97accc 100644 --- a/tools/xenstore/xenstored_domain.c +++ b/tools/xenstore/xenstored_domain.c @@ -1116,9 +1116,8 @@ int domain_nbentry_fix(unsigned int domid, int num, b= ool update) =20 int domain_nbentry(struct connection *conn) { - return (domain_is_unprivileged(conn)) - ? conn->domain->nbentry - : 0; + return domain_is_unprivileged(conn) + ? domain_nbentry_add(conn, conn->id, 0, true) : 0; } =20 static bool domain_chk_quota(struct domain *domain, int mem) --=20 2.35.3 From nobody Wed May 15 14:38:27 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=1680678267; cv=none; d=zohomail.com; s=zohoarc; b=U9Jie1Bkjcn4XgncE0LylQhq8pWNJbhuVWNjtlzhEiZlrH33kdXmc62yVNqP7dhNFCcax9ThlqwoMazh/j5rvdEpLtSkzYi0E7R6imDQ2BAUCe75TjmOsKZ7A/ksArVTObrh3Mvxz54dGlK6wERvud2f5t358NnuEYw8lnmD5eM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1680678267; 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=JlFoqnoU3I4JMyJapnFZtevlraEzWmolnTL1zQ4kqcs=; b=ed5kfwVAXViAvlJ+NEvCgRwYGLcQ9tWpKppvKVjODq/AMdeEIqm1ZbDW5ZmkkgBkxWuMl9LC7dCtZPysHDDhZnbtyce1ba05V52Odvm4Zxcu6D24fPn/iCRymz7lEVFYQzeth2Q322hvyfgAvbbBi2f3jTN8ddg6BqFRRywTKRo= 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 1680678267207351.6013386196106; Wed, 5 Apr 2023 00:04:27 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.518230.804547 (Exim 4.92) (envelope-from ) id 1pjxBd-0002nk-Jj; Wed, 05 Apr 2023 07:04:05 +0000 Received: by outflank-mailman (output) from mailman id 518230.804547; Wed, 05 Apr 2023 07:04:05 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pjxBd-0002nZ-Ga; Wed, 05 Apr 2023 07:04:05 +0000 Received: by outflank-mailman (input) for mailman id 518230; Wed, 05 Apr 2023 07:04:03 +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 1pjxBb-0002UC-L1 for xen-devel@lists.xenproject.org; Wed, 05 Apr 2023 07:04:03 +0000 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 0bfdcdaa-d380-11ed-85db-49a42c6b2330; Wed, 05 Apr 2023 09:04:03 +0200 (CEST) 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-out2.suse.de (Postfix) with ESMTPS id C870B205F9; Wed, 5 Apr 2023 07:04:02 +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 95F1F13A31; Wed, 5 Apr 2023 07:04:02 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id NXw7I2IdLWRfEwAAMHmgww (envelope-from ); Wed, 05 Apr 2023 07:04:02 +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: 0bfdcdaa-d380-11ed-85db-49a42c6b2330 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1680678242; 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=JlFoqnoU3I4JMyJapnFZtevlraEzWmolnTL1zQ4kqcs=; b=DDAP5/NyAduIWDEb6ICBx4jdNEjhte34fHoXhVU634jNXxaIfwnKOrqGKNI6jeg6ph566v KkAXwau9ss9pN8JmnivV8yWp18Ak6MDK0OfL+QBwKc0N0CJhcN/LNEJ3kRN5lboJWw0jU+ I9r22p9nwPylJiSigy3yVyLqeuejJZA= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Julien Grall , Anthony PERARD , Julien Grall Subject: [PATCH v4 02/13] tools/xenstore: manage per-transaction domain accounting data in an array Date: Wed, 5 Apr 2023 09:03:38 +0200 Message-Id: <20230405070349.25293-3-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230405070349.25293-1-jgross@suse.com> References: <20230405070349.25293-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1680678268965100003 Content-Type: text/plain; charset="utf-8" In order to prepare keeping accounting data in an array instead of using independent fields, switch the struct changed_domain accounting data to that scheme, for now only using an array with one element. In order to be able to extend this scheme add the needed indexing enum to xenstored_domain.h. Signed-off-by: Juergen Gross Reviewed-by: Julien Grall --- V2: - make "what" parameter of acc_add_changed_dom() an enum type, and assert() that it won't exceed the accounting array (Julien Grall) --- tools/xenstore/xenstored_domain.c | 19 +++++++++++-------- tools/xenstore/xenstored_domain.h | 10 ++++++++++ 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/tools/xenstore/xenstored_domain.c b/tools/xenstore/xenstored_d= omain.c index dbbf97accc..609a9a13ab 100644 --- a/tools/xenstore/xenstored_domain.c +++ b/tools/xenstore/xenstored_domain.c @@ -99,8 +99,8 @@ struct changed_domain /* Identifier of the changed domain. */ unsigned int domid; =20 - /* Amount by which this domain's nbentry field has changed. */ - int nbentry; + /* Accounting data. */ + int acc[ACC_TR_N]; }; =20 static struct hashtable *domhash; @@ -550,7 +550,7 @@ int acc_fix_domains(struct list_head *head, bool chk_qu= ota, bool update) int cnt; =20 list_for_each_entry(cd, head, list) { - cnt =3D domain_nbentry_fix(cd->domid, cd->nbentry, update); + cnt =3D domain_nbentry_fix(cd->domid, cd->acc[ACC_NODES], update); if (!update) { if (chk_quota && cnt >=3D quota_nb_entry_per_domain) return ENOSPC; @@ -595,19 +595,21 @@ static struct changed_domain *acc_get_changed_domain(= const void *ctx, return cd; } =20 -static int acc_add_dom_nbentry(const void *ctx, struct list_head *head, in= t val, - unsigned int domid) +static int acc_add_changed_dom(const void *ctx, struct list_head *head, + enum accitem what, int val, unsigned int domid) { struct changed_domain *cd; =20 + assert(what < ARRAY_SIZE(cd->acc)); + cd =3D acc_get_changed_domain(ctx, head, domid); if (!cd) return 0; =20 errno =3D 0; - cd->nbentry +=3D val; + cd->acc[what] +=3D val; =20 - return cd->nbentry; + return cd->acc[what]; } =20 static void domain_conn_reset(struct domain *domain) @@ -1071,7 +1073,8 @@ static int domain_nbentry_add(struct connection *conn= , unsigned int domid, =20 if (conn && conn->transaction) { head =3D transaction_get_changed_domains(conn->transaction); - ret =3D acc_add_dom_nbentry(conn->transaction, head, add, domid); + ret =3D acc_add_changed_dom(conn->transaction, head, ACC_NODES, + add, domid); if (errno) { fail_transaction(conn->transaction); return -1; diff --git a/tools/xenstore/xenstored_domain.h b/tools/xenstore/xenstored_d= omain.h index 279cccb3ad..40803574f6 100644 --- a/tools/xenstore/xenstored_domain.h +++ b/tools/xenstore/xenstored_domain.h @@ -19,6 +19,16 @@ #ifndef _XENSTORED_DOMAIN_H #define _XENSTORED_DOMAIN_H =20 +/* + * All accounting data is stored in a per-domain array. + * Depending on the account item there might be other scopes as well, like= e.g. + * a per transaction array. + */ +enum accitem { + ACC_NODES, + ACC_TR_N, /* Number of elements per transaction. */ +}; + void handle_event(void); =20 void check_domains(void); --=20 2.35.3 From nobody Wed May 15 14:38:27 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=1680678273; cv=none; d=zohomail.com; s=zohoarc; b=fn+7gJmteIFzNqQyl84o0lqDqB7IBOboj7uTXOFSXXapubVH1ZlyTc5gXM4Xj4yfs56PZqzLIh+mMcT/Wg9LbCH2R6ZJIqPborn+4PYWVkbZJwovhwcc67oKRqL5QmJbDaObI/ypahQlgxcgw1HxZrNYwdzNKlcwopRN8Eq2n/k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1680678273; 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=XGeyzFUz5tXMQxwcHUnMlsPDW6IPPfsMHnMCy5JL5Tc=; b=ZHhuTJp8xEU3F5/yL8tdE2SBAAbAzKayoyV+I6itOFskZh54LhztJEV4ahFYY5dp8PGrnjDailREtvUOzdjhnDiWiW2GDsGEM1p/il5yXccA9KDC0KbcMBk4ra2pGhnvNTVx0BjkGOm9ENHUy+3CccNAlLswOGuGoU0GTfEML0w= 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 1680678273045969.5978097862309; Wed, 5 Apr 2023 00:04:33 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.518232.804558 (Exim 4.92) (envelope-from ) id 1pjxBk-0003C5-T7; Wed, 05 Apr 2023 07:04:12 +0000 Received: by outflank-mailman (output) from mailman id 518232.804558; Wed, 05 Apr 2023 07:04: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 1pjxBk-0003By-Q8; Wed, 05 Apr 2023 07:04:12 +0000 Received: by outflank-mailman (input) for mailman id 518232; Wed, 05 Apr 2023 07:04:10 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pjxBi-0002Et-Ga for xen-devel@lists.xenproject.org; Wed, 05 Apr 2023 07:04:10 +0000 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 0f586cb1-d380-11ed-b464-930f4c7d94ae; Wed, 05 Apr 2023 09:04:08 +0200 (CEST) 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 67D92229E5; Wed, 5 Apr 2023 07:04:08 +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 3834213A31; Wed, 5 Apr 2023 07:04:08 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id NaRUDGgdLWSUEwAAMHmgww (envelope-from ); Wed, 05 Apr 2023 07:04:08 +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: 0f586cb1-d380-11ed-b464-930f4c7d94ae DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1680678248; 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=XGeyzFUz5tXMQxwcHUnMlsPDW6IPPfsMHnMCy5JL5Tc=; b=hz+PU6USwBStzOH8qIlujgCh7UZln1zWU3HxdKKBJcFUaj1pIdwd6spHFZdSJpaFSJqT5R wikn4kZb07OYCFVKm2y78r1ZqeS1PweDdHmGtfO1ZKjw0Q2jYT3LkErSnWa52fsf7XAqYc GQ/ohUuVYPPMu6oEmN4BIBfLILN8bbY= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Julien Grall , Anthony PERARD Subject: [PATCH v4 03/13] tools/xenstore: introduce accounting data array for per-domain values Date: Wed, 5 Apr 2023 09:03:39 +0200 Message-Id: <20230405070349.25293-4-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230405070349.25293-1-jgross@suse.com> References: <20230405070349.25293-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1680678274556100001 Content-Type: text/plain; charset="utf-8" Introduce the scheme of an accounting data array for per-domain accounting data and use it initially for the number of nodes owned by a domain. Make the accounting data type to be unsigned int, as no data is allowed to be negative at any time. Signed-off-by: Juergen Gross Reviewed-by: Julien Grall --- V3: - remove domid parameter from domain_acc_add_chk() (Julien Grall) - rename domain_acc_add_chk() (Julien Grall) - modify overflow check (Julien Grall) V4: - fix overflow check --- tools/xenstore/xenstored_domain.c | 70 ++++++++++++++++++------------- tools/xenstore/xenstored_domain.h | 3 +- 2 files changed, 43 insertions(+), 30 deletions(-) diff --git a/tools/xenstore/xenstored_domain.c b/tools/xenstore/xenstored_d= omain.c index 609a9a13ab..30fb9acec6 100644 --- a/tools/xenstore/xenstored_domain.c +++ b/tools/xenstore/xenstored_domain.c @@ -69,8 +69,8 @@ struct domain /* Has domain been officially introduced? */ bool introduced; =20 - /* number of entry from this domain in the store */ - int nbentry; + /* Accounting data for this domain. */ + unsigned int acc[ACC_N]; =20 /* Amount of memory allocated for this domain. */ int memory; @@ -246,7 +246,7 @@ static int domain_tree_remove_sub(const void *ctx, stru= ct connection *conn, =20 if (keep_orphans) { set_tdb_key(node->name, &key); - domain->nbentry--; + domain_nbentry_dec(NULL, domain->domid); node->perms.p[0].id =3D priv_domid; node->acc.memory =3D 0; domain_nbentry_inc(NULL, priv_domid); @@ -270,7 +270,7 @@ static int domain_tree_remove_sub(const void *ctx, stru= ct connection *conn, ret =3D WALK_TREE_SKIP_CHILDREN; } =20 - return domain->nbentry > 0 ? ret : WALK_TREE_SUCCESS_STOP; + return domain->acc[ACC_NODES] ? ret : WALK_TREE_SUCCESS_STOP; } =20 static void domain_tree_remove(struct domain *domain) @@ -278,7 +278,7 @@ static void domain_tree_remove(struct domain *domain) int ret; struct walk_funcs walkfuncs =3D { .enter =3D domain_tree_remove_sub }; =20 - if (domain->nbentry > 0) { + if (domain->acc[ACC_NODES]) { ret =3D walk_node_tree(domain, NULL, "/", &walkfuncs, domain); if (ret =3D=3D WALK_TREE_ERROR_STOP) syslog(LOG_ERR, @@ -437,7 +437,7 @@ int domain_get_quota(const void *ctx, struct connection= *conn, resp =3D talloc_asprintf_append(resp, "%-16s: %8d\n", #t, e); \ if (!resp) return ENOMEM =20 - ent(nodes, d->nbentry); + ent(nodes, d->acc[ACC_NODES]); ent(watches, d->nbwatch); ent(transactions, ta); ent(outstanding, d->nboutstanding); @@ -1047,8 +1047,27 @@ int domain_adjust_node_perms(struct node *node) return 0; } =20 -static int domain_nbentry_add(struct connection *conn, unsigned int domid, - int add, bool no_dom_alloc) +static int domain_acc_add_valid(struct domain *d, enum accitem what, int a= dd) +{ + assert(what < ARRAY_SIZE(d->acc)); + + if ((add < 0 && -add > d->acc[what]) || + (add > 0 && (INT_MAX - d->acc[what]) < add)) { + /* + * In a transaction when a node is being added/removed AND the + * same node has been added/removed outside the transaction in + * parallel, the resulting value will be wrong. This is no + * problem, as the transaction will fail due to the resulting + * conflict. + */ + return (add < 0) ? 0 : INT_MAX; + } + + return d->acc[what] + add; +} + +static int domain_acc_add(struct connection *conn, unsigned int domid, + enum accitem what, int add, bool no_dom_alloc) { struct domain *d; struct list_head *head; @@ -1071,56 +1090,49 @@ static int domain_nbentry_add(struct connection *co= nn, unsigned int domid, } } =20 - if (conn && conn->transaction) { + if (conn && conn->transaction && what < ACC_TR_N) { head =3D transaction_get_changed_domains(conn->transaction); - ret =3D acc_add_changed_dom(conn->transaction, head, ACC_NODES, + ret =3D acc_add_changed_dom(conn->transaction, head, what, add, domid); if (errno) { fail_transaction(conn->transaction); return -1; } - /* - * In a transaction when a node is being added/removed AND the - * same node has been added/removed outside the transaction in - * parallel, the resulting number of nodes will be wrong. This - * is no problem, as the transaction will fail due to the - * resulting conflict. - * In the node remove case the resulting number can be even - * negative, which should be avoided. - */ - return max(d->nbentry + ret, 0); + return domain_acc_add_valid(d, what, ret); } =20 - d->nbentry +=3D add; + d->acc[what] =3D domain_acc_add_valid(d, what, add); =20 - return d->nbentry; + return d->acc[what]; } =20 int domain_nbentry_inc(struct connection *conn, unsigned int domid) { - return (domain_nbentry_add(conn, domid, 1, false) < 0) ? errno : 0; + return (domain_acc_add(conn, domid, ACC_NODES, 1, false) < 0) + ? errno : 0; } =20 int domain_nbentry_dec(struct connection *conn, unsigned int domid) { - return (domain_nbentry_add(conn, domid, -1, true) < 0) ? errno : 0; + return (domain_acc_add(conn, domid, ACC_NODES, -1, true) < 0) + ? errno : 0; } =20 int domain_nbentry_fix(unsigned int domid, int num, bool update) { int ret; =20 - ret =3D domain_nbentry_add(NULL, domid, update ? num : 0, update); + ret =3D domain_acc_add(NULL, domid, ACC_NODES, update ? num : 0, update); if (ret < 0 || update) return ret; =20 return domid_is_unprivileged(domid) ? ret + num : 0; } =20 -int domain_nbentry(struct connection *conn) +unsigned int domain_nbentry(struct connection *conn) { return domain_is_unprivileged(conn) - ? domain_nbentry_add(conn, conn->id, 0, true) : 0; + ? domain_acc_add(conn, conn->id, ACC_NODES, 0, true) : 0; } =20 static bool domain_chk_quota(struct domain *domain, int mem) @@ -1597,7 +1609,7 @@ static int domain_check_acc_init_sub(const void *k, v= oid *v, void *arg) * If everything is correct incrementing the value for each node will * result in dom->nodes being 0 at the end. */ - dom->nodes =3D -d->nbentry; + dom->nodes =3D -d->acc[ACC_NODES]; =20 if (!hashtable_insert(domains, &dom->domid, dom)) { talloc_free(dom); @@ -1652,7 +1664,7 @@ static int domain_check_acc_cb(const void *k, void *v= , void *arg) if (!d) return 0; =20 - d->nbentry +=3D dom->nodes; + d->acc[ACC_NODES] +=3D dom->nodes; =20 return 0; } diff --git a/tools/xenstore/xenstored_domain.h b/tools/xenstore/xenstored_d= omain.h index 40803574f6..9d05eb01da 100644 --- a/tools/xenstore/xenstored_domain.h +++ b/tools/xenstore/xenstored_domain.h @@ -27,6 +27,7 @@ enum accitem { ACC_NODES, ACC_TR_N, /* Number of elements per transaction. */ + ACC_N =3D ACC_TR_N, /* Number of elements per domain. */ }; =20 void handle_event(void); @@ -77,7 +78,7 @@ int domain_alloc_permrefs(struct node_perms *perms); int domain_nbentry_inc(struct connection *conn, unsigned int domid); int domain_nbentry_dec(struct connection *conn, unsigned int domid); int domain_nbentry_fix(unsigned int domid, int num, bool update); -int domain_nbentry(struct connection *conn); +unsigned int domain_nbentry(struct connection *conn); int domain_memory_add(unsigned int domid, int mem, bool no_quota_check); =20 /* --=20 2.35.3 From nobody Wed May 15 14:38:27 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=1680678276; cv=none; d=zohomail.com; s=zohoarc; b=G42YdSEZtHIgtgUznu1302/QMj81KPO7kignwQH/21QbqVF0rQoouyIYUjQeCOPm6q3r5VMkm/OJuhe8szD9npL4GHk8bxJxOvOsRaytz2Lg5Y7+pD5ojLLfG41RYn0nv68SbJg9zp+cHwSx4NNwlCCgRLtp/cKRbWisPkAtrsk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1680678276; 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=PmKRxa2YuBmHM00MgxuyH9GXZoeQCdBxFLkVz4Hk1ys=; b=gp6mqHLe9CBQK/WWikYk//giSCwOat7HOMzCojvKuaKZiEiOD8S35gKGRIZb8UVRZH/TY+pGCKTyID+fPSMmZl2cKsTB3+BHvWd5MtLgFJW4FSOjzg0d/QgXKFlElS4e/uWChraG4GZZs3hduvh92medctbiXE5Hvn4zXOzxREY= 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 168067827674127.578848207313627; Wed, 5 Apr 2023 00:04:36 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.518234.804568 (Exim 4.92) (envelope-from ) id 1pjxBo-0003Xm-54; Wed, 05 Apr 2023 07:04:16 +0000 Received: by outflank-mailman (output) from mailman id 518234.804568; Wed, 05 Apr 2023 07:04: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 1pjxBo-0003XU-1p; Wed, 05 Apr 2023 07:04:16 +0000 Received: by outflank-mailman (input) for mailman id 518234; Wed, 05 Apr 2023 07:04:15 +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 1pjxBn-0002UC-09 for xen-devel@lists.xenproject.org; Wed, 05 Apr 2023 07:04:15 +0000 Received: from smtp-out2.suse.de (smtp-out2.suse.de [2001:67c:2178:6::1d]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 12a74feb-d380-11ed-85db-49a42c6b2330; Wed, 05 Apr 2023 09:04:14 +0200 (CEST) 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-out2.suse.de (Postfix) with ESMTPS id 013E520258; Wed, 5 Apr 2023 07:04:14 +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 C962013A31; Wed, 5 Apr 2023 07:04:13 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id Ac+pL20dLWSiEwAAMHmgww (envelope-from ); Wed, 05 Apr 2023 07:04:13 +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: 12a74feb-d380-11ed-85db-49a42c6b2330 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1680678254; 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=PmKRxa2YuBmHM00MgxuyH9GXZoeQCdBxFLkVz4Hk1ys=; b=W+adN7dxvkw5e9v+LkLSUx0dG3FvIDFTdGoBe9KhCde/ai3BrSwTIYgCAj8J7s7tF8uXkS p98RJu10dza9JeLqj2N3J+HuYsat3qpyE2/okY2BJAT3AOxZZ818/HCwRF4nLZvFPKvWie BvgAhmbL7B8wqZFtw7FrbTN2Ct6q1kY= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Julien Grall , Anthony PERARD Subject: [PATCH v4 04/13] tools/xenstore: add framework to commit accounting data on success only Date: Wed, 5 Apr 2023 09:03:40 +0200 Message-Id: <20230405070349.25293-5-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230405070349.25293-1-jgross@suse.com> References: <20230405070349.25293-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1680678278786100001 Content-Type: text/plain; charset="utf-8" Instead of modifying accounting data and undo those modifications in case of an error during further processing, add a framework for collecting the needed changes and commit them only when the whole operation has succeeded. This scheme can reuse large parts of the per transaction accounting. The changed_domain handling can be reused, but the array size of the accounting data should be possible to be different for both use cases. Signed-off-by: Juergen Gross --- V3: - call acc_commit() earlier (Julien Grall) - add assert() to acc_commit() - use fixed sized acc array in struct changed_domain (Julien Grall) --- tools/xenstore/xenstored_core.c | 9 ++++-- tools/xenstore/xenstored_core.h | 3 ++ tools/xenstore/xenstored_domain.c | 53 ++++++++++++++++++++++++++++++- tools/xenstore/xenstored_domain.h | 5 ++- 4 files changed, 66 insertions(+), 4 deletions(-) diff --git a/tools/xenstore/xenstored_core.c b/tools/xenstore/xenstored_cor= e.c index 3ca68681e3..84335f5f3d 100644 --- a/tools/xenstore/xenstored_core.c +++ b/tools/xenstore/xenstored_core.c @@ -1023,6 +1023,9 @@ static void send_error(struct connection *conn, int e= rror) break; } } + + acc_drop(conn); + send_reply(conn, XS_ERROR, xsd_errors[i].errstring, strlen(xsd_errors[i].errstring) + 1); } @@ -1034,6 +1037,9 @@ void send_reply(struct connection *conn, enum xsd_soc= kmsg_type type, =20 assert(type !=3D XS_WATCH_EVENT); =20 + conn->in =3D NULL; + acc_commit(conn); + if ( len > XENSTORE_PAYLOAD_MAX ) { send_error(conn, E2BIG); return; @@ -1059,8 +1065,6 @@ void send_reply(struct connection *conn, enum xsd_soc= kmsg_type type, } } =20 - conn->in =3D NULL; - /* Update relevant header fields and fill in the message body. */ bdata->hdr.msg.type =3D type; bdata->hdr.msg.len =3D len; @@ -2195,6 +2199,7 @@ struct connection *new_connection(const struct interf= ace_funcs *funcs) new->is_stalled =3D false; new->transaction_started =3D 0; INIT_LIST_HEAD(&new->out_list); + INIT_LIST_HEAD(&new->acc_list); INIT_LIST_HEAD(&new->ref_list); INIT_LIST_HEAD(&new->watches); INIT_LIST_HEAD(&new->transaction_list); diff --git a/tools/xenstore/xenstored_core.h b/tools/xenstore/xenstored_cor= e.h index c59b06551f..1f811f38cb 100644 --- a/tools/xenstore/xenstored_core.h +++ b/tools/xenstore/xenstored_core.h @@ -139,6 +139,9 @@ struct connection struct list_head out_list; uint64_t timeout_msec; =20 + /* Not yet committed accounting data (valid if in !=3D NULL). */ + struct list_head acc_list; + /* Referenced requests no longer pending. */ struct list_head ref_list; =20 diff --git a/tools/xenstore/xenstored_domain.c b/tools/xenstore/xenstored_d= omain.c index 30fb9acec6..144cbafb73 100644 --- a/tools/xenstore/xenstored_domain.c +++ b/tools/xenstore/xenstored_domain.c @@ -91,6 +91,8 @@ struct domain bool wrl_delay_logged; }; =20 +#define ACC_CHD_N (ACC_TR_N < ACC_REQ_N ? ACC_REQ_N : ACC_TR_N) + struct changed_domain { /* List of all changed domains. */ @@ -100,7 +102,7 @@ struct changed_domain unsigned int domid; =20 /* Accounting data. */ - int acc[ACC_TR_N]; + int acc[ACC_CHD_N]; }; =20 static struct hashtable *domhash; @@ -1070,6 +1072,7 @@ static int domain_acc_add(struct connection *conn, un= signed int domid, enum accitem what, int add, bool no_dom_alloc) { struct domain *d; + struct changed_domain *cd; struct list_head *head; int ret; =20 @@ -1090,6 +1093,22 @@ static int domain_acc_add(struct connection *conn, u= nsigned int domid, } } =20 + /* Temporary accounting data until final commit? */ + if (conn && conn->in && what < ACC_REQ_N) { + /* Consider transaction local data. */ + ret =3D 0; + if (conn->transaction && what < ACC_TR_N) { + head =3D transaction_get_changed_domains( + conn->transaction); + cd =3D acc_find_changed_domain(head, domid); + if (cd) + ret =3D cd->acc[what]; + } + ret +=3D acc_add_changed_dom(conn->in, &conn->acc_list, what, + add, domid); + return errno ? -1 : domain_acc_add_valid(d, what, ret); + } + if (conn && conn->transaction && what < ACC_TR_N) { head =3D transaction_get_changed_domains(conn->transaction); ret =3D acc_add_changed_dom(conn->transaction, head, what, @@ -1106,6 +1125,38 @@ static int domain_acc_add(struct connection *conn, u= nsigned int domid, return d->acc[what]; } =20 +void acc_drop(struct connection *conn) +{ + struct changed_domain *cd; + + while ((cd =3D list_top(&conn->acc_list, struct changed_domain, list))) { + list_del(&cd->list); + talloc_free(cd); + } +} + +void acc_commit(struct connection *conn) +{ + struct changed_domain *cd; + enum accitem what; + + /* + * Make sure domain_acc_add() below can't add additional data to + * to be committed accounting records. + */ + assert(!conn->in); + + while ((cd =3D list_top(&conn->acc_list, struct changed_domain, list))) { + list_del(&cd->list); + for (what =3D 0; what < ACC_REQ_N; what++) + if (cd->acc[what]) + domain_acc_add(conn, cd->domid, what, + cd->acc[what], true); + + talloc_free(cd); + } +} + int domain_nbentry_inc(struct connection *conn, unsigned int domid) { return (domain_acc_add(conn, domid, ACC_NODES, 1, false) < 0) diff --git a/tools/xenstore/xenstored_domain.h b/tools/xenstore/xenstored_d= omain.h index 9d05eb01da..6355ad4f37 100644 --- a/tools/xenstore/xenstored_domain.h +++ b/tools/xenstore/xenstored_domain.h @@ -25,7 +25,8 @@ * a per transaction array. */ enum accitem { - ACC_NODES, + ACC_REQ_N, /* Number of elements per request. */ + ACC_NODES =3D ACC_REQ_N, ACC_TR_N, /* Number of elements per transaction. */ ACC_N =3D ACC_TR_N, /* Number of elements per domain. */ }; @@ -113,6 +114,8 @@ int domain_get_quota(const void *ctx, struct connection= *conn, * If "update" is true, "chk_quota" is ignored. */ int acc_fix_domains(struct list_head *head, bool chk_quota, bool update); +void acc_drop(struct connection *conn); +void acc_commit(struct connection *conn); =20 /* Write rate limiting */ =20 --=20 2.35.3 From nobody Wed May 15 14:38:27 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=1680678279; cv=none; d=zohomail.com; s=zohoarc; b=ameIv+mnRr30z+7V9fEcQbibdNZVfpFlC+9pggS5uUBrsGMBPhbsGHzZXIs/FepDhfcw8zgPlkv4nB+zGz+MWFu7Emx3qQSO/p25bv9EhEmd1OOxKBxqHOyYvW5GMFT/BhQZkMIl+phoI1ytSMKSGU3rh+BcJ2aLhcrhSDMpsnM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1680678279; 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=zpWITZM/jycFaeqzkIbP5IXI6C0MvtvZCqGsXHa9q9E=; b=X2Z9qQEIveSv47Lma6NCm9T+C3UDmYAGxw9phtpsyXKYrcfCZr2hS03XhL0KIsrn9auJXH+OE9oOHNMgKpuUQoCkhf2Ct28ret/1fY1dpNItG7pJ5MEllaLg3PpJ/lXEvHhAVmNuv+h7lEmrtK59A8P5kL70VXmXTy21PrC7IAo= 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 1680678279410849.3729422592102; Wed, 5 Apr 2023 00:04:39 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.518237.804578 (Exim 4.92) (envelope-from ) id 1pjxBt-0004Ar-HX; Wed, 05 Apr 2023 07:04:21 +0000 Received: by outflank-mailman (output) from mailman id 518237.804578; Wed, 05 Apr 2023 07:04: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 1pjxBt-0004Ak-Em; Wed, 05 Apr 2023 07:04:21 +0000 Received: by outflank-mailman (input) for mailman id 518237; Wed, 05 Apr 2023 07:04:20 +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 1pjxBs-0002UC-Dn for xen-devel@lists.xenproject.org; Wed, 05 Apr 2023 07:04:20 +0000 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 15fee7ff-d380-11ed-85db-49a42c6b2330; Wed, 05 Apr 2023 09:04:19 +0200 (CEST) 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 943DD229D0; Wed, 5 Apr 2023 07:04:19 +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 6637513A31; Wed, 5 Apr 2023 07:04:19 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id qRGQF3MdLWSuEwAAMHmgww (envelope-from ); Wed, 05 Apr 2023 07:04:19 +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: 15fee7ff-d380-11ed-85db-49a42c6b2330 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1680678259; 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=zpWITZM/jycFaeqzkIbP5IXI6C0MvtvZCqGsXHa9q9E=; b=kTpVk4DwUfgPK7n3BwU0oPzleMoDtWJ447NcVfWzVjgXB+gyyHKQnZFa0k/Vr2vrOq9/LD HF4LHvHcGRpZHl9AJDKHA0UZmHI75Hu6Rn8600M4F1KRoyM3hM4yAivBTD1QMT3z8+BXXv 8+7tdsP+1izd8Xl53RPN1wneBPWYAXY= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Julien Grall , Anthony PERARD Subject: [PATCH v4 05/13] tools/xenstore: use accounting buffering for node accounting Date: Wed, 5 Apr 2023 09:03:41 +0200 Message-Id: <20230405070349.25293-6-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230405070349.25293-1-jgross@suse.com> References: <20230405070349.25293-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1680678280121100003 Content-Type: text/plain; charset="utf-8" Add the node accounting to the accounting information buffering in order to avoid having to undo it in case of failure. Signed-off-by: Juergen Gross --- tools/xenstore/xenstored_core.c | 21 ++------------------- tools/xenstore/xenstored_domain.h | 4 ++-- 2 files changed, 4 insertions(+), 21 deletions(-) diff --git a/tools/xenstore/xenstored_core.c b/tools/xenstore/xenstored_cor= e.c index 84335f5f3d..92a40ccf3f 100644 --- a/tools/xenstore/xenstored_core.c +++ b/tools/xenstore/xenstored_core.c @@ -1452,7 +1452,6 @@ static void destroy_node_rm(struct connection *conn, = struct node *node) static int destroy_node(struct connection *conn, struct node *node) { destroy_node_rm(conn, node); - domain_nbentry_dec(conn, get_node_owner(node)); =20 /* * It is not possible to easily revert the changes in a transaction. @@ -1797,27 +1796,11 @@ static int do_set_perms(const void *ctx, struct con= nection *conn, old_perms =3D node->perms; domain_nbentry_dec(conn, get_node_owner(node)); node->perms =3D perms; - if (domain_nbentry_inc(conn, get_node_owner(node))) { - node->perms =3D old_perms; - /* - * This should never fail because we had a reference on the - * domain before and Xenstored is single-threaded. - */ - domain_nbentry_inc(conn, get_node_owner(node)); + if (domain_nbentry_inc(conn, get_node_owner(node))) return ENOMEM; - } =20 - if (write_node(conn, node, false)) { - int saved_errno =3D errno; - - domain_nbentry_dec(conn, get_node_owner(node)); - node->perms =3D old_perms; - /* No failure possible as above. */ - domain_nbentry_inc(conn, get_node_owner(node)); - - errno =3D saved_errno; + if (write_node(conn, node, false)) return errno; - } =20 fire_watches(conn, ctx, name, node, false, &old_perms); send_ack(conn, XS_SET_PERMS); diff --git a/tools/xenstore/xenstored_domain.h b/tools/xenstore/xenstored_d= omain.h index 6355ad4f37..e669f57b80 100644 --- a/tools/xenstore/xenstored_domain.h +++ b/tools/xenstore/xenstored_domain.h @@ -25,9 +25,9 @@ * a per transaction array. */ enum accitem { + ACC_NODES, ACC_REQ_N, /* Number of elements per request. */ - ACC_NODES =3D ACC_REQ_N, - ACC_TR_N, /* Number of elements per transaction. */ + ACC_TR_N =3D ACC_REQ_N, /* Number of elements per transaction. */ ACC_N =3D ACC_TR_N, /* Number of elements per domain. */ }; =20 --=20 2.35.3 From nobody Wed May 15 14:38:27 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=1680678286; cv=none; d=zohomail.com; s=zohoarc; b=KhC7bOfwZzTYrs1ubcyewh4B3mkV/LKd54kN9SdAJwgl/L2V+lSN1RPcB6Meo7PZkAzfxnXpqkdOs+hrVhfmdmsGB14WtjJxo3him1Mel81xhcn5m2C9I8Yhi4Mc89LOx7BYp8Vsk0qAumczacQj3Lw7UJ8mg+yyG/7dMbGbaSc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1680678286; 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=KyUsGkw8xvAHU6kBBf8lvAgf5AlXfalzLddBzhYP/rg=; b=TQ0Mf8J1LbJBgkK+T+WUllwAdb7pPLtINAIvJKWBpH3KbJ3TdPWAA+hB0VYaUNXd3YfNgfKVTGYiuf3zjIr//WxaXBAevawpnX2xSVrOGMXVyOXnu78pMPK7zVPtiIj2DMvxZ45x/GqWnIeFsP9LHZfjiqFIJfkgbbXvcwMhR1I= 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 1680678286602269.82741654379777; Wed, 5 Apr 2023 00:04:46 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.518241.804588 (Exim 4.92) (envelope-from ) id 1pjxC0-0004lL-QS; Wed, 05 Apr 2023 07:04:28 +0000 Received: by outflank-mailman (output) from mailman id 518241.804588; Wed, 05 Apr 2023 07:04: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 1pjxC0-0004l9-NG; Wed, 05 Apr 2023 07:04:28 +0000 Received: by outflank-mailman (input) for mailman id 518241; Wed, 05 Apr 2023 07:04:27 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pjxBz-0002Et-6Z for xen-devel@lists.xenproject.org; Wed, 05 Apr 2023 07:04:27 +0000 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 195505f4-d380-11ed-b464-930f4c7d94ae; Wed, 05 Apr 2023 09:04:25 +0200 (CEST) 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 2D16D229ED; Wed, 5 Apr 2023 07:04:25 +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 0042613A31; Wed, 5 Apr 2023 07:04:24 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id rYEsOngdLWS3EwAAMHmgww (envelope-from ); Wed, 05 Apr 2023 07:04:24 +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: 195505f4-d380-11ed-b464-930f4c7d94ae DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1680678265; 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=KyUsGkw8xvAHU6kBBf8lvAgf5AlXfalzLddBzhYP/rg=; b=hS7Q1J2iA2PuHiGjs8dolF9hQLFzMKmnotf6iaAmoucNaCMbjfrmJqVN10kvlHLumpgt/M ncomGyud1nlnq0qh91uVHCijkS+y45dNDfUPzKrtysap+3mypWr4/sKPFJyz/WwzMvg+RY 6XxHAUO7n0xo+N+DCuNtj6ZUlhAq89M= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Julien Grall , Anthony PERARD Subject: [PATCH v4 06/13] tools/xenstore: add current connection to domain_memory_add() parameters Date: Wed, 5 Apr 2023 09:03:42 +0200 Message-Id: <20230405070349.25293-7-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230405070349.25293-1-jgross@suse.com> References: <20230405070349.25293-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1680678288407100001 Content-Type: text/plain; charset="utf-8" In order to enable switching memory accounting to the generic array based accounting, add the current connection to the parameters of domain_memory_add(). This requires to add the connection to some other functions, too. Signed-off-by: Juergen Gross Acked-by: Julien Grall --- tools/xenstore/xenstored_core.c | 28 ++++++++++++++++------------ tools/xenstore/xenstored_domain.c | 3 ++- tools/xenstore/xenstored_domain.h | 14 +++++++++----- tools/xenstore/xenstored_watch.c | 11 ++++++----- 4 files changed, 33 insertions(+), 23 deletions(-) diff --git a/tools/xenstore/xenstored_core.c b/tools/xenstore/xenstored_cor= e.c index 92a40ccf3f..88ae674523 100644 --- a/tools/xenstore/xenstored_core.c +++ b/tools/xenstore/xenstored_core.c @@ -246,7 +246,8 @@ static void free_buffered_data(struct buffered_data *ou= t, } } =20 - domain_memory_add_nochk(conn->id, -out->hdr.msg.len - sizeof(out->hdr)); + domain_memory_add_nochk(conn, conn->id, + -out->hdr.msg.len - sizeof(out->hdr)); =20 if (out->hdr.msg.type =3D=3D XS_WATCH_EVENT) { req =3D out->pend.req; @@ -631,24 +632,25 @@ int do_tdb_write(struct connection *conn, TDB_DATA *k= ey, TDB_DATA *data, * nodes to new owners. */ if (old_acc.memory) - domain_memory_add_nochk(old_domid, + domain_memory_add_nochk(conn, old_domid, -old_acc.memory - key->dsize); - ret =3D domain_memory_add(new_domid, data->dsize + key->dsize, - no_quota_check); + ret =3D domain_memory_add(conn, new_domid, + data->dsize + key->dsize, no_quota_check); if (ret) { /* Error path, so no quota check. */ if (old_acc.memory) - domain_memory_add_nochk(old_domid, + domain_memory_add_nochk(conn, old_domid, old_acc.memory + key->dsize); return ret; } =20 /* TDB should set errno, but doesn't even set ecode AFAICT. */ if (tdb_store(tdb_ctx, *key, *data, TDB_REPLACE) !=3D 0) { - domain_memory_add_nochk(new_domid, -data->dsize - key->dsize); + domain_memory_add_nochk(conn, new_domid, + -data->dsize - key->dsize); /* Error path, so no quota check. */ if (old_acc.memory) - domain_memory_add_nochk(old_domid, + domain_memory_add_nochk(conn, old_domid, old_acc.memory + key->dsize); errno =3D EIO; return errno; @@ -683,7 +685,7 @@ int do_tdb_delete(struct connection *conn, TDB_DATA *ke= y, =20 if (acc->memory) { domid =3D get_acc_domid(conn, key, acc->domid); - domain_memory_add_nochk(domid, -acc->memory - key->dsize); + domain_memory_add_nochk(conn, domid, -acc->memory - key->dsize); } =20 return 0; @@ -1055,11 +1057,13 @@ void send_reply(struct connection *conn, enum xsd_s= ockmsg_type type, if (len <=3D DEFAULT_BUFFER_SIZE) { bdata->buffer =3D bdata->default_buffer; /* Don't check quota, path might be used for returning error. */ - domain_memory_add_nochk(conn->id, len + sizeof(bdata->hdr)); + domain_memory_add_nochk(conn, conn->id, + len + sizeof(bdata->hdr)); } else { bdata->buffer =3D talloc_array(bdata, char, len); if (!bdata->buffer || - domain_memory_add_chk(conn->id, len + sizeof(bdata->hdr))) { + domain_memory_add_chk(conn, conn->id, + len + sizeof(bdata->hdr))) { send_error(conn, ENOMEM); return; } @@ -1122,7 +1126,7 @@ void send_event(struct buffered_data *req, struct con= nection *conn, } } =20 - if (domain_memory_add_chk(conn->id, len + sizeof(bdata->hdr))) { + if (domain_memory_add_chk(conn, conn->id, len + sizeof(bdata->hdr))) { talloc_free(bdata); return; } @@ -3322,7 +3326,7 @@ static void add_buffered_data(struct buffered_data *b= data, * be smaller. So ignore it. The limit will be applied for any resource * after the state has been fully restored. */ - domain_memory_add_nochk(conn->id, len + sizeof(bdata->hdr)); + domain_memory_add_nochk(conn, conn->id, len + sizeof(bdata->hdr)); } =20 void read_state_buffered_data(const void *ctx, struct connection *conn, diff --git a/tools/xenstore/xenstored_domain.c b/tools/xenstore/xenstored_d= omain.c index 144cbafb73..f94812610a 100644 --- a/tools/xenstore/xenstored_domain.c +++ b/tools/xenstore/xenstored_domain.c @@ -1235,7 +1235,8 @@ static bool domain_chk_quota(struct domain *domain, i= nt mem) return false; } =20 -int domain_memory_add(unsigned int domid, int mem, bool no_quota_check) +int domain_memory_add(struct connection *conn, unsigned int domid, int mem, + bool no_quota_check) { struct domain *domain; =20 diff --git a/tools/xenstore/xenstored_domain.h b/tools/xenstore/xenstored_d= omain.h index e669f57b80..5cfd730cf6 100644 --- a/tools/xenstore/xenstored_domain.h +++ b/tools/xenstore/xenstored_domain.h @@ -80,25 +80,29 @@ int domain_nbentry_inc(struct connection *conn, unsigne= d int domid); int domain_nbentry_dec(struct connection *conn, unsigned int domid); int domain_nbentry_fix(unsigned int domid, int num, bool update); unsigned int domain_nbentry(struct connection *conn); -int domain_memory_add(unsigned int domid, int mem, bool no_quota_check); +int domain_memory_add(struct connection *conn, unsigned int domid, int mem, + bool no_quota_check); =20 /* * domain_memory_add_chk(): to be used when memory quota should be checked. * Not to be used when specifying a negative mem value, as lowering the us= ed * memory should always be allowed. */ -static inline int domain_memory_add_chk(unsigned int domid, int mem) +static inline int domain_memory_add_chk(struct connection *conn, + unsigned int domid, int mem) { - return domain_memory_add(domid, mem, false); + return domain_memory_add(conn, domid, mem, false); } + /* * domain_memory_add_nochk(): to be used when memory quota should not be * checked, e.g. when lowering memory usage, or in an error case for undoi= ng * a previous memory adjustment. */ -static inline void domain_memory_add_nochk(unsigned int domid, int mem) +static inline void domain_memory_add_nochk(struct connection *conn, + unsigned int domid, int mem) { - domain_memory_add(domid, mem, true); + domain_memory_add(conn, domid, mem, true); } void domain_watch_inc(struct connection *conn); void domain_watch_dec(struct connection *conn); diff --git a/tools/xenstore/xenstored_watch.c b/tools/xenstore/xenstored_wa= tch.c index 8ad0229df6..e30cd89be3 100644 --- a/tools/xenstore/xenstored_watch.c +++ b/tools/xenstore/xenstored_watch.c @@ -199,7 +199,7 @@ static struct watch *add_watch(struct connection *conn,= char *path, char *token, watch->token =3D talloc_strdup(watch, token); if (!watch->node || !watch->token) goto nomem; - if (domain_memory_add(conn->id, strlen(path) + strlen(token), + if (domain_memory_add(conn, conn->id, strlen(path) + strlen(token), no_quota_check)) goto nomem; =20 @@ -274,8 +274,9 @@ int do_unwatch(const void *ctx, struct connection *conn, list_for_each_entry(watch, &conn->watches, list) { if (streq(watch->node, node) && streq(watch->token, vec[1])) { list_del(&watch->list); - domain_memory_add_nochk(conn->id, -strlen(watch->node) - - strlen(watch->token)); + domain_memory_add_nochk(conn, conn->id, + -strlen(watch->node) - + strlen(watch->token)); talloc_free(watch); domain_watch_dec(conn); send_ack(conn, XS_UNWATCH); @@ -291,8 +292,8 @@ void conn_delete_all_watches(struct connection *conn) =20 while ((watch =3D list_top(&conn->watches, struct watch, list))) { list_del(&watch->list); - domain_memory_add_nochk(conn->id, -strlen(watch->node) - - strlen(watch->token)); + domain_memory_add_nochk(conn, conn->id, -strlen(watch->node) - + strlen(watch->token)); talloc_free(watch); domain_watch_dec(conn); } --=20 2.35.3 From nobody Wed May 15 14:38:27 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=1680678299; cv=none; d=zohomail.com; s=zohoarc; b=NMrg75P7g1kAz/pYmal7hi4/XmDRTvL2mcMcwQcF4Ic8ujyhtZSOMkFrUX1be4BjDj/YhVcsUGpzjutI/2JxOFxoQQTJL2lMqLeTh+0c9cSe38AvvRraZjwqUkQembpDGUEe3yQThzp4+PKGxhk/6gC6HV5UMjHXrxsVSqYVxVc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1680678299; 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=yXnL6y0xe3ujnGIrpffgz9CI+U2tC4w1dZmiNxkMXsw=; b=hYaDaNatgzD7xsQgqDVgdnUnDE3MSXUQylHu7nIPPqMwMXMB0kbiNupWrYb2nvRLjYFQCwdj5wrtTFzl8xOSx5F00B0L33OwwY1nPTrUlTmc6AsUfmkpQHPQuU9UiF8PkgXyn442syhOjXZnJE9VzyLSJrmPQjbBxDv8vP3ZJ5I= 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 1680678299636461.6187975697968; Wed, 5 Apr 2023 00:04:59 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.518244.804598 (Exim 4.92) (envelope-from ) id 1pjxC6-0005Fx-1l; Wed, 05 Apr 2023 07:04:34 +0000 Received: by outflank-mailman (output) from mailman id 518244.804598; Wed, 05 Apr 2023 07:04:34 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pjxC5-0005F8-U0; Wed, 05 Apr 2023 07:04:33 +0000 Received: by outflank-mailman (input) for mailman id 518244; Wed, 05 Apr 2023 07:04:32 +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 1pjxC3-0002UC-Rz for xen-devel@lists.xenproject.org; Wed, 05 Apr 2023 07:04:31 +0000 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 1cacb26e-d380-11ed-85db-49a42c6b2330; Wed, 05 Apr 2023 09:04:31 +0200 (CEST) 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 BCE9D229FF; Wed, 5 Apr 2023 07:04:30 +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 8F10E13A31; Wed, 5 Apr 2023 07:04:30 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id whOiIX4dLWTHEwAAMHmgww (envelope-from ); Wed, 05 Apr 2023 07:04:30 +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: 1cacb26e-d380-11ed-85db-49a42c6b2330 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1680678270; 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=yXnL6y0xe3ujnGIrpffgz9CI+U2tC4w1dZmiNxkMXsw=; b=W7D+JLybanPWNvnVDx6eoSXB/U3WJR6A7WZ9HEE3UUKI5O26jvf9gW0MfxlUvBkM7mydAw llKH5a7EwZZXjTgpPQxN7NF4APfwC9TjembZO5rkzqIuoTkLjxb6ghyYN2iBRTzH/hlIyU os3novb/1onmO6ME64axrSDcIZqN0po= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Julien Grall , Anthony PERARD Subject: [PATCH v4 07/13] tools/xenstore: use accounting data array for per-domain values Date: Wed, 5 Apr 2023 09:03:43 +0200 Message-Id: <20230405070349.25293-8-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230405070349.25293-1-jgross@suse.com> References: <20230405070349.25293-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1680678301834100003 Content-Type: text/plain; charset="utf-8" Add the accounting of per-domain usage of Xenstore memory, watches, and outstanding requests to the array based mechanism. Signed-off-by: Juergen Gross --- tools/xenstore/xenstored_core.c | 8 +-- tools/xenstore/xenstored_domain.c | 111 +++++++++++------------------- tools/xenstore/xenstored_domain.h | 10 +-- 3 files changed, 52 insertions(+), 77 deletions(-) diff --git a/tools/xenstore/xenstored_core.c b/tools/xenstore/xenstored_cor= e.c index 88ae674523..67aa7c1578 100644 --- a/tools/xenstore/xenstored_core.c +++ b/tools/xenstore/xenstored_core.c @@ -255,7 +255,7 @@ static void free_buffered_data(struct buffered_data *ou= t, req->pend.ref.event_cnt--; if (!req->pend.ref.event_cnt && !req->on_out_list) { if (req->on_ref_list) { - domain_outstanding_domid_dec( + domain_outstanding_dec(conn, req->pend.ref.domid); list_del(&req->list); } @@ -271,7 +271,7 @@ static void free_buffered_data(struct buffered_data *ou= t, out->on_ref_list =3D true; return; } else - domain_outstanding_dec(conn); + domain_outstanding_dec(conn, conn->id); =20 talloc_free(out); } @@ -1077,7 +1077,7 @@ void send_reply(struct connection *conn, enum xsd_soc= kmsg_type type, /* Queue for later transmission. */ list_add_tail(&bdata->list, &conn->out_list); bdata->on_out_list =3D true; - domain_outstanding_inc(conn); + domain_outstanding_inc(conn, conn->id); } =20 /* @@ -3320,7 +3320,7 @@ static void add_buffered_data(struct buffered_data *b= data, * request have been delivered. */ if (bdata->hdr.msg.type !=3D XS_WATCH_EVENT) - domain_outstanding_inc(conn); + domain_outstanding_inc(conn, conn->id); /* * We are restoring the state after Live-Update and the new quota may * be smaller. So ignore it. The limit will be applied for any resource diff --git a/tools/xenstore/xenstored_domain.c b/tools/xenstore/xenstored_d= omain.c index f94812610a..22836ae881 100644 --- a/tools/xenstore/xenstored_domain.c +++ b/tools/xenstore/xenstored_domain.c @@ -72,19 +72,12 @@ struct domain /* Accounting data for this domain. */ unsigned int acc[ACC_N]; =20 - /* Amount of memory allocated for this domain. */ - int memory; + /* Memory quota data for this domain. */ bool soft_quota_reported; bool hard_quota_reported; time_t mem_last_msg; #define MEM_WARN_MINTIME_SEC 10 =20 - /* number of watch for this domain */ - int nbwatch; - - /* Number of outstanding requests. */ - int nboutstanding; - /* write rate limit */ wrl_creditt wrl_credit; /* [ -wrl_config_writecost, +_dburst ] */ struct wrl_timestampt wrl_timestamp; @@ -202,14 +195,15 @@ static bool domain_can_write(struct connection *conn) =20 static bool domain_can_read(struct connection *conn) { - struct xenstore_domain_interface *intf =3D conn->domain->interface; + struct domain *domain =3D conn->domain; + struct xenstore_domain_interface *intf =3D domain->interface; =20 if (domain_is_unprivileged(conn)) { - if (conn->domain->wrl_credit < 0) + if (domain->wrl_credit < 0) return false; - if (conn->domain->nboutstanding >=3D quota_req_outstanding) + if (domain->acc[ACC_OUTST] >=3D quota_req_outstanding) return false; - if (conn->domain->memory >=3D quota_memory_per_domain_hard && + if (domain->acc[ACC_MEM] >=3D quota_memory_per_domain_hard && quota_memory_per_domain_hard) return false; } @@ -440,10 +434,10 @@ int domain_get_quota(const void *ctx, struct connecti= on *conn, if (!resp) return ENOMEM =20 ent(nodes, d->acc[ACC_NODES]); - ent(watches, d->nbwatch); + ent(watches, d->acc[ACC_WATCH]); ent(transactions, ta); - ent(outstanding, d->nboutstanding); - ent(memory, d->memory); + ent(outstanding, d->acc[ACC_OUTST]); + ent(memory, d->acc[ACC_MEM]); =20 #undef ent =20 @@ -1186,14 +1180,16 @@ unsigned int domain_nbentry(struct connection *conn) ? domain_acc_add(conn, conn->id, ACC_NODES, 0, true) : 0; } =20 -static bool domain_chk_quota(struct domain *domain, int mem) +static bool domain_chk_quota(struct connection *conn, unsigned int mem) { time_t now; + struct domain *domain; =20 - if (!domain || !domid_is_unprivileged(domain->domid) || - (domain->conn && domain->conn->is_ignored)) + if (!conn || !domid_is_unprivileged(conn->id) || + conn->is_ignored) return false; =20 + domain =3D conn->domain; now =3D time(NULL); =20 if (mem >=3D quota_memory_per_domain_hard && @@ -1238,80 +1234,57 @@ static bool domain_chk_quota(struct domain *domain,= int mem) int domain_memory_add(struct connection *conn, unsigned int domid, int mem, bool no_quota_check) { - struct domain *domain; + int ret; =20 - domain =3D find_domain_struct(domid); - if (domain) { - /* - * domain_chk_quota() will print warning and also store whether - * the soft/hard quota has been hit. So check no_quota_check - * *after*. - */ - if (domain_chk_quota(domain, domain->memory + mem) && - !no_quota_check) - return ENOMEM; - domain->memory +=3D mem; - } else { - /* - * The domain the memory is to be accounted for should always - * exist, as accounting is done either for a domain related to - * the current connection, or for the domain owning a node - * (which is always existing, as the owner of the node is - * tested to exist and deleted or replaced by domid 0 if not). - * So not finding the related domain MUST be an error in the - * data base. - */ - errno =3D ENOENT; - corrupt(NULL, "Accounting called for non-existing domain %u\n", - domid); - return ENOENT; - } + ret =3D domain_acc_add(conn, domid, ACC_MEM, 0, true); + if (ret < 0) + return -ret; + + /* + * domain_chk_quota() will print warning and also store whether the + * soft/hard quota has been hit. So check no_quota_check *after*. + */ + if (domain_chk_quota(conn, ret + mem) && !no_quota_check) + return ENOMEM; + + /* + * The domain the memory is to be accounted for should always exist, + * as accounting is done either for a domain related to the current + * connection, or for the domain owning a node (which is always + * existing, as the owner of the node is tested to exist and deleted + * or replaced by domid 0 if not). + * So not finding the related domain MUST be an error in the data base. + */ + domain_acc_add(conn, domid, ACC_MEM, mem, true); =20 return 0; } =20 void domain_watch_inc(struct connection *conn) { - if (!conn || !conn->domain) - return; - conn->domain->nbwatch++; + domain_acc_add(conn, conn->id, ACC_WATCH, 1, true); } =20 void domain_watch_dec(struct connection *conn) { - if (!conn || !conn->domain) - return; - if (conn->domain->nbwatch) - conn->domain->nbwatch--; + domain_acc_add(conn, conn->id, ACC_WATCH, -1, true); } =20 int domain_watch(struct connection *conn) { return (domain_is_unprivileged(conn)) - ? conn->domain->nbwatch + ? domain_acc_add(conn, conn->id, ACC_WATCH, 0, true) : 0; } =20 -void domain_outstanding_inc(struct connection *conn) +void domain_outstanding_inc(struct connection *conn, unsigned int domid) { - if (!conn || !conn->domain) - return; - conn->domain->nboutstanding++; + domain_acc_add(conn, domid, ACC_OUTST, 1, true); } =20 -void domain_outstanding_dec(struct connection *conn) +void domain_outstanding_dec(struct connection *conn, unsigned int domid) { - if (!conn || !conn->domain) - return; - conn->domain->nboutstanding--; -} - -void domain_outstanding_domid_dec(unsigned int domid) -{ - struct domain *d =3D find_domain_by_domid(domid); - - if (d) - d->nboutstanding--; + domain_acc_add(conn, domid, ACC_OUTST, -1, true); } =20 static wrl_creditt wrl_config_writecost =3D WRL_FACTOR; diff --git a/tools/xenstore/xenstored_domain.h b/tools/xenstore/xenstored_d= omain.h index 5cfd730cf6..0d61bf4344 100644 --- a/tools/xenstore/xenstored_domain.h +++ b/tools/xenstore/xenstored_domain.h @@ -28,7 +28,10 @@ enum accitem { ACC_NODES, ACC_REQ_N, /* Number of elements per request. */ ACC_TR_N =3D ACC_REQ_N, /* Number of elements per transaction. */ - ACC_N =3D ACC_TR_N, /* Number of elements per domain. */ + ACC_WATCH =3D ACC_TR_N, + ACC_OUTST, + ACC_MEM, + ACC_N, /* Number of elements per domain. */ }; =20 void handle_event(void); @@ -107,9 +110,8 @@ static inline void domain_memory_add_nochk(struct conne= ction *conn, void domain_watch_inc(struct connection *conn); void domain_watch_dec(struct connection *conn); int domain_watch(struct connection *conn); -void domain_outstanding_inc(struct connection *conn); -void domain_outstanding_dec(struct connection *conn); -void domain_outstanding_domid_dec(unsigned int domid); +void domain_outstanding_inc(struct connection *conn, unsigned int domid); +void domain_outstanding_dec(struct connection *conn, unsigned int domid); int domain_get_quota(const void *ctx, struct connection *conn, unsigned int domid); =20 --=20 2.35.3 From nobody Wed May 15 14:38:27 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=1680678299; cv=none; d=zohomail.com; s=zohoarc; b=d4m4hDinQgioWvaL2y506nJlkT5LtcdPQE6d3rFZKmbAVTt49Ucny+bE4ozJQHh8r2VPur9f4VIKMIz+gz+fA4N13cY7OixNKS5knQTGohor8yc52Pdf+k+2b4VmEZuGuc9cSEyc2KkoguWJVpHREH0WEZwcV2T5zA9NQaNMibU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1680678299; 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=0FVX/N0LxAMOywC2jlDscHABd/v4BQEj8zV+MLHaj68=; b=g56wEf5cfwInszZyUL1KpCLd6mvp+lTgdl40Quyl1pOL6h+DdleITSV1otN4cUhXN4uzBVvj/oGPW08vS9sxlxN6p7rGPEZ59YdS64rPHiT/jnjCFpe47bFzyExOd093XUDI7iasdB+3CSHViVv9r0ZY0hq1TxrTXlHFaF6b2u0= 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 1680678299727716.2264029209799; Wed, 5 Apr 2023 00:04:59 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.518248.804607 (Exim 4.92) (envelope-from ) id 1pjxCA-0005jl-AN; Wed, 05 Apr 2023 07:04:38 +0000 Received: by outflank-mailman (output) from mailman id 518248.804607; Wed, 05 Apr 2023 07:04:38 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pjxCA-0005jc-6c; Wed, 05 Apr 2023 07:04:38 +0000 Received: by outflank-mailman (input) for mailman id 518248; Wed, 05 Apr 2023 07:04:37 +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 1pjxC9-0002UC-5c for xen-devel@lists.xenproject.org; Wed, 05 Apr 2023 07:04:37 +0000 Received: from smtp-out2.suse.de (smtp-out2.suse.de [2001:67c:2178:6::1d]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 200ce63f-d380-11ed-85db-49a42c6b2330; Wed, 05 Apr 2023 09:04:36 +0200 (CEST) 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-out2.suse.de (Postfix) with ESMTPS id 7340C20592; Wed, 5 Apr 2023 07:04:36 +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 3D6E213A31; Wed, 5 Apr 2023 07:04:36 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id TNk3DYQdLWTWEwAAMHmgww (envelope-from ); Wed, 05 Apr 2023 07:04:36 +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: 200ce63f-d380-11ed-85db-49a42c6b2330 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1680678276; 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=0FVX/N0LxAMOywC2jlDscHABd/v4BQEj8zV+MLHaj68=; b=kkFJhyYeVvEhEobwXdCyZzLJpbdI1PB+Q0ceqAJQc3IV+ScoJrBQheTkPhfSOhU8j3Zi3j 3ilgCE1AnCRHhreOXN4+uAJwR+yzepxIshlSbqaD/7DaYRvHBtTmzKm2pa5Bk8NRtaU9Sq BdXYeOhCOuCgRFvcGQSoWQSQhTyy5rs= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Julien Grall , Anthony PERARD , Julien Grall Subject: [PATCH v4 08/13] tools/xenstore: add accounting trace support Date: Wed, 5 Apr 2023 09:03:44 +0200 Message-Id: <20230405070349.25293-9-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230405070349.25293-1-jgross@suse.com> References: <20230405070349.25293-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1680678300298100001 Content-Type: text/plain; charset="utf-8" Add a new trace switch "acc" and the related trace calls. The "acc" switch is off per default. Signed-off-by: Juergen Gross Reviewed-by: Julien Grall --- tools/xenstore/xenstored_core.c | 2 +- tools/xenstore/xenstored_core.h | 1 + tools/xenstore/xenstored_domain.c | 10 ++++++++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/tools/xenstore/xenstored_core.c b/tools/xenstore/xenstored_cor= e.c index 67aa7c1578..bd816ce709 100644 --- a/tools/xenstore/xenstored_core.c +++ b/tools/xenstore/xenstored_core.c @@ -2746,7 +2746,7 @@ static void set_quota(const char *arg, bool soft) =20 /* Sorted by bit values of TRACE_* flags. Flag is (1u << index). */ const char *const trace_switches[] =3D { - "obj", "io", "wrl", + "obj", "io", "wrl", "acc", NULL }; =20 diff --git a/tools/xenstore/xenstored_core.h b/tools/xenstore/xenstored_cor= e.h index 1f811f38cb..3e0734a6c6 100644 --- a/tools/xenstore/xenstored_core.h +++ b/tools/xenstore/xenstored_core.h @@ -302,6 +302,7 @@ extern unsigned int trace_flags; #define TRACE_OBJ 0x00000001 #define TRACE_IO 0x00000002 #define TRACE_WRL 0x00000004 +#define TRACE_ACC 0x00000008 extern const char *const trace_switches[]; int set_trace_switch(const char *arg); =20 diff --git a/tools/xenstore/xenstored_domain.c b/tools/xenstore/xenstored_d= omain.c index 22836ae881..1caa60bb14 100644 --- a/tools/xenstore/xenstored_domain.c +++ b/tools/xenstore/xenstored_domain.c @@ -540,6 +540,12 @@ static struct domain *find_domain_by_domid(unsigned in= t domid) return (d && d->introduced) ? d : NULL; } =20 +#define trace_acc(...) \ +do { \ + if (trace_flags & TRACE_ACC) \ + trace("acc: " __VA_ARGS__); \ +} while (0) + int acc_fix_domains(struct list_head *head, bool chk_quota, bool update) { struct changed_domain *cd; @@ -603,6 +609,8 @@ static int acc_add_changed_dom(const void *ctx, struct = list_head *head, return 0; =20 errno =3D 0; + trace_acc("local change domid %u: what=3D%u %d add %d\n", domid, what, + cd->acc[what], val); cd->acc[what] +=3D val; =20 return cd->acc[what]; @@ -1114,6 +1122,8 @@ static int domain_acc_add(struct connection *conn, un= signed int domid, return domain_acc_add_valid(d, what, ret); } =20 + trace_acc("global change domid %u: what=3D%u %u add %d\n", domid, what, + d->acc[what], add); d->acc[what] =3D domain_acc_add_valid(d, what, add); =20 return d->acc[what]; --=20 2.35.3 From nobody Wed May 15 14:38:27 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=1680678568; cv=none; d=zohomail.com; s=zohoarc; b=Utk2SlkZInft1PQMO/GVIux6sy+dneVxIwq8GCqGZ5lmMUAPefMkgK7KBsQufN4hiQpOyrykbb0u1VVkWvGXj6jx/BILsb+IEboPjG4EKL5bPkPpkOu7tw01OEfybdtg0DHAOg17l4wfrlHrqgpihjfrs3xDHmv44QXozaNIgGM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1680678568; 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=GIdwVYCAKepkDxThtVUfw/37sAa1oGJdz4Nx6ZA+2lg=; b=gQghvSpV8Rsuma35lK+lgO+aevkTlcFr4J4/q0ax1v5b8zhFbis/yFXoSHnH4ye/xhrixvU07MClGwA5csZMSRK0REtm3g9A7qMOwLTd6ieRL0SRn3pOtMEImaZ8JCQ6mbMXWVZmdVZIJ+fo42kuWhJ6WmW5Jzlk/35MYk3prxA= 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 1680678568134891.8989746171814; Wed, 5 Apr 2023 00:09:28 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.518263.804648 (Exim 4.92) (envelope-from ) id 1pjxGP-0008Co-8m; Wed, 05 Apr 2023 07:09:01 +0000 Received: by outflank-mailman (output) from mailman id 518263.804648; Wed, 05 Apr 2023 07:09:01 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pjxGP-0008Cf-2H; Wed, 05 Apr 2023 07:09:01 +0000 Received: by outflank-mailman (input) for mailman id 518263; Wed, 05 Apr 2023 07:08:57 +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 1pjxCE-0002UC-Sd for xen-devel@lists.xenproject.org; Wed, 05 Apr 2023 07:04:42 +0000 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 2367f272-d380-11ed-85db-49a42c6b2330; Wed, 05 Apr 2023 09:04:42 +0200 (CEST) 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-out2.suse.de (Postfix) with ESMTPS id 1AC7020298; Wed, 5 Apr 2023 07:04:42 +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 DFDB813A31; Wed, 5 Apr 2023 07:04:41 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id dLRaNYkdLWTnEwAAMHmgww (envelope-from ); Wed, 05 Apr 2023 07:04:41 +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: 2367f272-d380-11ed-85db-49a42c6b2330 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1680678282; 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=GIdwVYCAKepkDxThtVUfw/37sAa1oGJdz4Nx6ZA+2lg=; b=JYSdSrraO6+/ewSBe4ComCaeaEt6LaIqm7GpPwvvBB2/50c3lKRhEfexZ/M1PYtUNuOAdp cAXPwMDtyPaVr6zj4HebZEt9t+7eJ9G9ICvXqsD4QgpVereucdcAxnztUHXU0/E9EcKMvt WCuHsq6yasY6PYD4cdSaJ4rMhd+r4JQ= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Julien Grall , Anthony PERARD , Julien Grall Subject: [PATCH v4 09/13] tools/xenstore: add TDB access trace support Date: Wed, 5 Apr 2023 09:03:45 +0200 Message-Id: <20230405070349.25293-10-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230405070349.25293-1-jgross@suse.com> References: <20230405070349.25293-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1680678569694100007 Content-Type: text/plain; charset="utf-8" Add a new trace switch "tdb" and the related trace calls. The "tdb" switch is off per default. Signed-off-by: Juergen Gross Reviewed-by: Julien Grall --- tools/xenstore/xenstored_core.c | 8 +++++++- tools/xenstore/xenstored_core.h | 7 +++++++ tools/xenstore/xenstored_transaction.c | 7 ++++++- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/tools/xenstore/xenstored_core.c b/tools/xenstore/xenstored_cor= e.c index bd816ce709..2d481fcad9 100644 --- a/tools/xenstore/xenstored_core.c +++ b/tools/xenstore/xenstored_core.c @@ -589,6 +589,8 @@ static void get_acc_data(TDB_DATA *key, struct node_acc= ount_data *acc) if (old_data.dptr =3D=3D NULL) { acc->memory =3D 0; } else { + trace_tdb("read %s size %zu\n", key->dptr, + old_data.dsize + key->dsize); hdr =3D (void *)old_data.dptr; acc->memory =3D old_data.dsize; acc->domid =3D hdr->perms[0].id; @@ -655,6 +657,7 @@ int do_tdb_write(struct connection *conn, TDB_DATA *key= , TDB_DATA *data, errno =3D EIO; return errno; } + trace_tdb("store %s size %zu\n", key->dptr, data->dsize + key->dsize); =20 if (acc) { /* Don't use new_domid, as it might be a transaction node. */ @@ -682,6 +685,7 @@ int do_tdb_delete(struct connection *conn, TDB_DATA *ke= y, errno =3D EIO; return errno; } + trace_tdb("delete %s\n", key->dptr); =20 if (acc->memory) { domid =3D get_acc_domid(conn, key, acc->domid); @@ -731,6 +735,8 @@ struct node *read_node(struct connection *conn, const v= oid *ctx, goto error; } =20 + trace_tdb("read %s size %zu\n", key.dptr, data.dsize + key.dsize); + node->parent =3D NULL; talloc_steal(node, data.dptr); =20 @@ -2746,7 +2752,7 @@ static void set_quota(const char *arg, bool soft) =20 /* Sorted by bit values of TRACE_* flags. Flag is (1u << index). */ const char *const trace_switches[] =3D { - "obj", "io", "wrl", "acc", + "obj", "io", "wrl", "acc", "tdb", NULL }; =20 diff --git a/tools/xenstore/xenstored_core.h b/tools/xenstore/xenstored_cor= e.h index 3e0734a6c6..5a11dc1231 100644 --- a/tools/xenstore/xenstored_core.h +++ b/tools/xenstore/xenstored_core.h @@ -303,9 +303,16 @@ extern unsigned int trace_flags; #define TRACE_IO 0x00000002 #define TRACE_WRL 0x00000004 #define TRACE_ACC 0x00000008 +#define TRACE_TDB 0x00000010 extern const char *const trace_switches[]; int set_trace_switch(const char *arg); =20 +#define trace_tdb(...) \ +do { \ + if (trace_flags & TRACE_TDB) \ + trace("tdb: " __VA_ARGS__); \ +} while (0) + extern TDB_CONTEXT *tdb_ctx; extern int dom0_domid; extern int dom0_event; diff --git a/tools/xenstore/xenstored_transaction.c b/tools/xenstore/xensto= red_transaction.c index 2b15506953..11c8bcec84 100644 --- a/tools/xenstore/xenstored_transaction.c +++ b/tools/xenstore/xenstored_transaction.c @@ -374,8 +374,11 @@ static int finalize_transaction(struct connection *con= n, if (tdb_error(tdb_ctx) !=3D TDB_ERR_NOEXIST) return EIO; gen =3D NO_GENERATION; - } else + } else { + trace_tdb("read %s size %zu\n", key.dptr, + key.dsize + data.dsize); gen =3D hdr->generation; + } talloc_free(data.dptr); if (i->generation !=3D gen) return EAGAIN; @@ -399,6 +402,8 @@ static int finalize_transaction(struct connection *conn, set_tdb_key(i->trans_name, &ta_key); data =3D tdb_fetch(tdb_ctx, ta_key); if (data.dptr) { + trace_tdb("read %s size %zu\n", ta_key.dptr, + ta_key.dsize + data.dsize); hdr =3D (void *)data.dptr; hdr->generation =3D ++generation; *is_corrupt |=3D do_tdb_write(conn, &key, &data, --=20 2.35.3 From nobody Wed May 15 14:38:27 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=1680678567; cv=none; d=zohomail.com; s=zohoarc; b=YGZtiFtKk3lopttn/VgPmCAmcLoo/0A/+2CMO1CgpZi8gAfasGVom9d9q/mmgIC1qKzm9xTaJZpuaaAaPh5DqXjn+Jzl8pNopCAR9ZR7p8Am+xSq9C0wspCLrebWOQwFetW0bBjvo/Cq8dvdFcHpr+XA5DbSfmL22YYXcAi1pL4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1680678567; 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=9+svNodvtqEzi347VmDVhAeqbmPB+a6CEyNMcH7A/78=; b=bYh4ah0U9bjibvNSEjUiW7es5wOLDyiblPHIAhckTM3WpvAiYu2K9Etjst7rLNn5/EhBYjyY/V2INTqmVFISthfCr4hSvv3hWHpTyWVudS+rt+GZdtRTP+9UwQ0vYO50kjZVeJlFXNGe/BwjX5s7HT0MYmejkjqC5TNtnaQJ/Rk= 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 1680678567836621.8963901733057; Wed, 5 Apr 2023 00:09:27 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.518260.804622 (Exim 4.92) (envelope-from ) id 1pjxGM-0007T6-9d; Wed, 05 Apr 2023 07:08:58 +0000 Received: by outflank-mailman (output) from mailman id 518260.804622; Wed, 05 Apr 2023 07:08: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 1pjxGM-0007ST-6U; Wed, 05 Apr 2023 07:08:58 +0000 Received: by outflank-mailman (input) for mailman id 518260; Wed, 05 Apr 2023 07:08:57 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pjxCL-0002Et-ML for xen-devel@lists.xenproject.org; Wed, 05 Apr 2023 07:04:49 +0000 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 26c01ddb-d380-11ed-b464-930f4c7d94ae; Wed, 05 Apr 2023 09:04:47 +0200 (CEST) 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-out2.suse.de (Postfix) with ESMTPS id AA1E22058E; Wed, 5 Apr 2023 07:04:47 +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 7B8FD13A31; Wed, 5 Apr 2023 07:04:47 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id aC3eHI8dLWTyEwAAMHmgww (envelope-from ); Wed, 05 Apr 2023 07:04:47 +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: 26c01ddb-d380-11ed-b464-930f4c7d94ae DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1680678287; 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=9+svNodvtqEzi347VmDVhAeqbmPB+a6CEyNMcH7A/78=; b=tnoiNvEK7wVRD3t0XP4Hb9wj9DRqF9BbSyC6DqYylJERvPZPE+SKEm+XT2wW86hDrWy8xB /v4wAUytR0s5QLSPDUknaFsDXTnPllXZP5H+DTDJbjKcl4L5+PBWKVbQU4+YHfxlPv2odP WPjJIR4tQYibRtvRn3i3I3iBFXgM4ig= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Julien Grall , Anthony PERARD Subject: [PATCH v4 10/13] tools/xenstore: switch transaction accounting to generic accounting Date: Wed, 5 Apr 2023 09:03:46 +0200 Message-Id: <20230405070349.25293-11-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230405070349.25293-1-jgross@suse.com> References: <20230405070349.25293-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1680678569359100005 Content-Type: text/plain; charset="utf-8" As transaction accounting is active for unprivileged domains only, it can easily be added to the generic per-domain accounting. Signed-off-by: Juergen Gross --- tools/xenstore/xenstored_core.c | 3 +-- tools/xenstore/xenstored_core.h | 1 - tools/xenstore/xenstored_domain.c | 21 ++++++++++++++++++--- tools/xenstore/xenstored_domain.h | 4 ++++ tools/xenstore/xenstored_transaction.c | 12 +++++------- 5 files changed, 28 insertions(+), 13 deletions(-) diff --git a/tools/xenstore/xenstored_core.c b/tools/xenstore/xenstored_cor= e.c index 2d481fcad9..88c569b7d5 100644 --- a/tools/xenstore/xenstored_core.c +++ b/tools/xenstore/xenstored_core.c @@ -2083,7 +2083,7 @@ static void consider_message(struct connection *conn) * stalled. This will ignore new requests until Live-Update happened * or it was aborted. */ - if (lu_is_pending() && conn->transaction_started =3D=3D 0 && + if (lu_is_pending() && conn->ta_start_time =3D=3D 0 && conn->in->hdr.msg.type =3D=3D XS_TRANSACTION_START) { trace("Delaying transaction start for connection %p req_id %u\n", conn, conn->in->hdr.msg.req_id); @@ -2190,7 +2190,6 @@ struct connection *new_connection(const struct interf= ace_funcs *funcs) new->funcs =3D funcs; new->is_ignored =3D false; new->is_stalled =3D false; - new->transaction_started =3D 0; INIT_LIST_HEAD(&new->out_list); INIT_LIST_HEAD(&new->acc_list); INIT_LIST_HEAD(&new->ref_list); diff --git a/tools/xenstore/xenstored_core.h b/tools/xenstore/xenstored_cor= e.h index 5a11dc1231..3564d85d7d 100644 --- a/tools/xenstore/xenstored_core.h +++ b/tools/xenstore/xenstored_core.h @@ -151,7 +151,6 @@ struct connection /* List of in-progress transactions. */ struct list_head transaction_list; uint32_t next_transaction_id; - unsigned int transaction_started; time_t ta_start_time; =20 /* List of delayed requests. */ diff --git a/tools/xenstore/xenstored_domain.c b/tools/xenstore/xenstored_d= omain.c index 1caa60bb14..40bcc1dbfa 100644 --- a/tools/xenstore/xenstored_domain.c +++ b/tools/xenstore/xenstored_domain.c @@ -419,12 +419,10 @@ int domain_get_quota(const void *ctx, struct connecti= on *conn, { struct domain *d =3D find_domain_struct(domid); char *resp; - int ta; =20 if (!d) return ENOENT; =20 - ta =3D d->conn ? d->conn->transaction_started : 0; resp =3D talloc_asprintf(ctx, "Domain %u:\n", domid); if (!resp) return ENOMEM; @@ -435,7 +433,7 @@ int domain_get_quota(const void *ctx, struct connection= *conn, =20 ent(nodes, d->acc[ACC_NODES]); ent(watches, d->acc[ACC_WATCH]); - ent(transactions, ta); + ent(transactions, d->acc[ACC_TRANS]); ent(outstanding, d->acc[ACC_OUTST]); ent(memory, d->acc[ACC_MEM]); =20 @@ -1297,6 +1295,23 @@ void domain_outstanding_dec(struct connection *conn,= unsigned int domid) domain_acc_add(conn, domid, ACC_OUTST, -1, true); } =20 +void domain_transaction_inc(struct connection *conn) +{ + domain_acc_add(conn, conn->id, ACC_TRANS, 1, true); +} + +void domain_transaction_dec(struct connection *conn) +{ + domain_acc_add(conn, conn->id, ACC_TRANS, -1, true); +} + +unsigned int domain_transaction_get(struct connection *conn) +{ + return (domain_is_unprivileged(conn)) + ? domain_acc_add(conn, conn->id, ACC_TRANS, 0, true) + : 0; +} + static wrl_creditt wrl_config_writecost =3D WRL_FACTOR; static wrl_creditt wrl_config_rate =3D WRL_RATE * WRL_FACTOR; static wrl_creditt wrl_config_dburst =3D WRL_DBURST * WRL_FACTOR; diff --git a/tools/xenstore/xenstored_domain.h b/tools/xenstore/xenstored_d= omain.h index 0d61bf4344..abc766f343 100644 --- a/tools/xenstore/xenstored_domain.h +++ b/tools/xenstore/xenstored_domain.h @@ -31,6 +31,7 @@ enum accitem { ACC_WATCH =3D ACC_TR_N, ACC_OUTST, ACC_MEM, + ACC_TRANS, ACC_N, /* Number of elements per domain. */ }; =20 @@ -112,6 +113,9 @@ void domain_watch_dec(struct connection *conn); int domain_watch(struct connection *conn); void domain_outstanding_inc(struct connection *conn, unsigned int domid); void domain_outstanding_dec(struct connection *conn, unsigned int domid); +void domain_transaction_inc(struct connection *conn); +void domain_transaction_dec(struct connection *conn); +unsigned int domain_transaction_get(struct connection *conn); int domain_get_quota(const void *ctx, struct connection *conn, unsigned int domid); =20 diff --git a/tools/xenstore/xenstored_transaction.c b/tools/xenstore/xensto= red_transaction.c index 11c8bcec84..1c14b8579a 100644 --- a/tools/xenstore/xenstored_transaction.c +++ b/tools/xenstore/xenstored_transaction.c @@ -479,8 +479,7 @@ int do_transaction_start(const void *ctx, struct connec= tion *conn, if (conn->transaction) return EBUSY; =20 - if (domain_is_unprivileged(conn) && - conn->transaction_started > quota_max_transaction) + if (domain_transaction_get(conn) > quota_max_transaction) return ENOSPC; =20 /* Attach transaction to ctx for autofree until it's complete */ @@ -505,9 +504,9 @@ int do_transaction_start(const void *ctx, struct connec= tion *conn, list_add_tail(&trans->list, &conn->transaction_list); talloc_steal(conn, trans); talloc_set_destructor(trans, destroy_transaction); - if (!conn->transaction_started) + if (!conn->ta_start_time) conn->ta_start_time =3D time(NULL); - conn->transaction_started++; + domain_transaction_inc(conn); wrl_ntransactions++; =20 snprintf(id_str, sizeof(id_str), "%u", trans->id); @@ -533,8 +532,8 @@ int do_transaction_end(const void *ctx, struct connecti= on *conn, =20 conn->transaction =3D NULL; list_del(&trans->list); - conn->transaction_started--; - if (!conn->transaction_started) + domain_transaction_dec(conn); + if (list_empty(&conn->transaction_list)) conn->ta_start_time =3D 0; =20 chk_quota =3D trans->node_created && domain_is_unprivileged(conn); @@ -588,7 +587,6 @@ void conn_delete_all_transactions(struct connection *co= nn) =20 assert(conn->transaction =3D=3D NULL); =20 - conn->transaction_started =3D 0; conn->ta_start_time =3D 0; } =20 --=20 2.35.3 From nobody Wed May 15 14:38:27 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=1680678567; cv=none; d=zohomail.com; s=zohoarc; b=l3X5P77Ka3ilTLIpLVfmpQtDB/aE9grP0w8MCmEYqQi2bC1AP/kvw0jMCvCmkChKkSjD3xT44xNnOHEausf/AlrKSZQPq+JecH9MAKbicpSz4W+DDwQhmeUfZXdDwbtFHs3/pYZO048UcgASz1mWkDEPcGRYJrelp5UO5Dl0rV0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1680678567; 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=2ZcKfGTywyhrwZZUE2CTmIRIHQZRyLmi1TNVZ6l6MAw=; b=L/lw7qey7RRaICodsxL1Jkxz+tw7YxD6Uw7zLVCqZC1p8znRS0vKMsUGXT5/GXSowA2Wd2s4ytuVO3Ds+ouKV7W6uoj6SLy59kGmAusyuRqUHsPA2YS1edEhi9myVvkRGjycgHRwnpc6rVv3zyirVdsGy/AaYN1GPrIJyUiWNbI= 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 1680678567557874.5368291606654; Wed, 5 Apr 2023 00:09:27 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.518261.804629 (Exim 4.92) (envelope-from ) id 1pjxGM-0007Z9-Lm; Wed, 05 Apr 2023 07:08:58 +0000 Received: by outflank-mailman (output) from mailman id 518261.804629; Wed, 05 Apr 2023 07:08: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 1pjxGM-0007Xk-FN; Wed, 05 Apr 2023 07:08:58 +0000 Received: by outflank-mailman (input) for mailman id 518261; Wed, 05 Apr 2023 07:08:57 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pjxCR-0002Et-GC for xen-devel@lists.xenproject.org; Wed, 05 Apr 2023 07:04:55 +0000 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 2a24292f-d380-11ed-b464-930f4c7d94ae; Wed, 05 Apr 2023 09:04:53 +0200 (CEST) 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 5B43C229D0; Wed, 5 Apr 2023 07:04:53 +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 183F713A31; Wed, 5 Apr 2023 07:04:53 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id y9STBJUdLWT9EwAAMHmgww (envelope-from ); Wed, 05 Apr 2023 07:04:53 +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: 2a24292f-d380-11ed-b464-930f4c7d94ae DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1680678293; 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=2ZcKfGTywyhrwZZUE2CTmIRIHQZRyLmi1TNVZ6l6MAw=; b=J85PbfdL8z3iCw2B4Q1bk3oMnyCK50oEidaoR42ZPYCoHHWj/yqLNNp6LOgrjYls97N18/ HkhQHaOPux3ZgThOWGXZFOewgIISa3eegqDDkkgUuomSi7g5tmcBvk97MQJ7ZTrK/9OCsv JTZWK5b6oNvQifldTqW7itnzi5IUMd8= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Andrew Cooper , George Dunlap , Jan Beulich , Julien Grall , Stefano Stabellini , Wei Liu , Anthony PERARD Subject: [PATCH v4 11/13] tools/xenstore: remember global and per domain max accounting values Date: Wed, 5 Apr 2023 09:03:47 +0200 Message-Id: <20230405070349.25293-12-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230405070349.25293-1-jgross@suse.com> References: <20230405070349.25293-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1680678567988100003 Content-Type: text/plain; charset="utf-8" Add saving the maximum values of the different accounting data seen per domain and (for unprivileged domains) globally, and print those values via the xenstore-control quota command. Add a sub-command for resetting the global maximum values seen. This should help for a decision how to set the related quotas. Signed-off-by: Juergen Gross Reviewed-by: Julien Grall --- docs/misc/xenstore.txt | 5 +- tools/xenstore/xenstored_control.c | 22 ++++++- tools/xenstore/xenstored_domain.c | 100 +++++++++++++++++++++++------ tools/xenstore/xenstored_domain.h | 2 + 4 files changed, 108 insertions(+), 21 deletions(-) diff --git a/docs/misc/xenstore.txt b/docs/misc/xenstore.txt index d807ef0709..38015835b1 100644 --- a/docs/misc/xenstore.txt +++ b/docs/misc/xenstore.txt @@ -426,7 +426,7 @@ CONTROL |[|] print| print to syslog (xenstore runs as daemon) or to console (xenstore runs as stubdom) - quota|[set |] + quota|[set ||max [-r]] without parameters: print the current quota settings with "set ": set the quota to new value (The admin should make sure all the domain usage is @@ -435,6 +435,9 @@ CONTROL |[|] violating the new quota setting isn't increased further) with "": print quota related accounting data for the domain + with "max [-r]": show global per-domain maximum values of all + unprivileged domains, optionally reset the values by adding + "-r" quota-soft|[set ] like the "quota" command, but for soft-quota. help diff --git a/tools/xenstore/xenstored_control.c b/tools/xenstore/xenstored_= control.c index cbd62556c3..a2ba64a15c 100644 --- a/tools/xenstore/xenstored_control.c +++ b/tools/xenstore/xenstored_control.c @@ -306,6 +306,22 @@ static int quota_get(const void *ctx, struct connectio= n *conn, return domain_get_quota(ctx, conn, atoi(vec[0])); } =20 +static int quota_max(const void *ctx, struct connection *conn, + char **vec, int num) +{ + if (num > 1) + return EINVAL; + + if (num =3D=3D 1) { + if (!strcmp(vec[0], "-r")) + domain_reset_global_acc(); + else + return EINVAL; + } + + return domain_max_global_acc(ctx, conn); +} + static int do_control_quota(const void *ctx, struct connection *conn, char **vec, int num) { @@ -315,6 +331,9 @@ static int do_control_quota(const void *ctx, struct con= nection *conn, if (!strcmp(vec[0], "set")) return quota_set(ctx, conn, vec + 1, num - 1, hard_quotas); =20 + if (!strcmp(vec[0], "max")) + return quota_max(ctx, conn, vec + 1, num - 1); + return quota_get(ctx, conn, vec, num); } =20 @@ -978,7 +997,8 @@ static struct cmd_s cmds[] =3D { { "memreport", do_control_memreport, "[]" }, #endif { "print", do_control_print, "" }, - { "quota", do_control_quota, "[set |]" }, + { "quota", do_control_quota, + "[set ||max [-r]]" }, { "quota-soft", do_control_quota_s, "[set ]" }, { "help", do_control_help, "" }, }; diff --git a/tools/xenstore/xenstored_domain.c b/tools/xenstore/xenstored_d= omain.c index 40bcc1dbfa..d21f31da92 100644 --- a/tools/xenstore/xenstored_domain.c +++ b/tools/xenstore/xenstored_domain.c @@ -43,6 +43,8 @@ static evtchn_port_t virq_port; =20 xenevtchn_handle *xce_handle =3D NULL; =20 +static unsigned int acc_global_max[ACC_N]; + struct domain { /* The id of this domain */ @@ -70,7 +72,10 @@ struct domain bool introduced; =20 /* Accounting data for this domain. */ - unsigned int acc[ACC_N]; + struct acc { + unsigned int val; + unsigned int max; + } acc[ACC_N]; =20 /* Memory quota data for this domain. */ bool soft_quota_reported; @@ -201,9 +206,9 @@ static bool domain_can_read(struct connection *conn) if (domain_is_unprivileged(conn)) { if (domain->wrl_credit < 0) return false; - if (domain->acc[ACC_OUTST] >=3D quota_req_outstanding) + if (domain->acc[ACC_OUTST].val >=3D quota_req_outstanding) return false; - if (domain->acc[ACC_MEM] >=3D quota_memory_per_domain_hard && + if (domain->acc[ACC_MEM].val >=3D quota_memory_per_domain_hard && quota_memory_per_domain_hard) return false; } @@ -266,7 +271,7 @@ static int domain_tree_remove_sub(const void *ctx, stru= ct connection *conn, ret =3D WALK_TREE_SKIP_CHILDREN; } =20 - return domain->acc[ACC_NODES] ? ret : WALK_TREE_SUCCESS_STOP; + return domain->acc[ACC_NODES].val ? ret : WALK_TREE_SUCCESS_STOP; } =20 static void domain_tree_remove(struct domain *domain) @@ -274,7 +279,7 @@ static void domain_tree_remove(struct domain *domain) int ret; struct walk_funcs walkfuncs =3D { .enter =3D domain_tree_remove_sub }; =20 - if (domain->acc[ACC_NODES]) { + if (domain->acc[ACC_NODES].val) { ret =3D walk_node_tree(domain, NULL, "/", &walkfuncs, domain); if (ret =3D=3D WALK_TREE_ERROR_STOP) syslog(LOG_ERR, @@ -428,14 +433,41 @@ int domain_get_quota(const void *ctx, struct connecti= on *conn, return ENOMEM; =20 #define ent(t, e) \ - resp =3D talloc_asprintf_append(resp, "%-16s: %8d\n", #t, e); \ + resp =3D talloc_asprintf_append(resp, "%-16s: %8u (max: %8u\n", #t, \ + d->acc[e].val, d->acc[e].max); \ + if (!resp) return ENOMEM + + ent(nodes, ACC_NODES); + ent(watches, ACC_WATCH); + ent(transactions, ACC_TRANS); + ent(outstanding, ACC_OUTST); + ent(memory, ACC_MEM); + +#undef ent + + send_reply(conn, XS_CONTROL, resp, strlen(resp) + 1); + + return 0; +} + +int domain_max_global_acc(const void *ctx, struct connection *conn) +{ + char *resp; + + resp =3D talloc_asprintf(ctx, "Max. seen accounting values:\n"); + if (!resp) + return ENOMEM; + +#define ent(t, e) \ + resp =3D talloc_asprintf_append(resp, "%-16s: %8u\n", #t, \ + acc_global_max[e]); \ if (!resp) return ENOMEM =20 - ent(nodes, d->acc[ACC_NODES]); - ent(watches, d->acc[ACC_WATCH]); - ent(transactions, d->acc[ACC_TRANS]); - ent(outstanding, d->acc[ACC_OUTST]); - ent(memory, d->acc[ACC_MEM]); + ent(nodes, ACC_NODES); + ent(watches, ACC_WATCH); + ent(transactions, ACC_TRANS); + ent(outstanding, ACC_OUTST); + ent(memory, ACC_MEM); =20 #undef ent =20 @@ -1051,10 +1083,12 @@ int domain_adjust_node_perms(struct node *node) =20 static int domain_acc_add_valid(struct domain *d, enum accitem what, int a= dd) { + unsigned int val; + assert(what < ARRAY_SIZE(d->acc)); =20 - if ((add < 0 && -add > d->acc[what]) || - (add > 0 && (INT_MAX - d->acc[what]) < add)) { + if ((add < 0 && -add > d->acc[what].val) || + (add > 0 && (INT_MAX - d->acc[what].val) < add)) { /* * In a transaction when a node is being added/removed AND the * same node has been added/removed outside the transaction in @@ -1065,7 +1099,13 @@ static int domain_acc_add_valid(struct domain *d, en= um accitem what, int add) return (add < 0) ? 0 : INT_MAX; } =20 - return d->acc[what] + add; + val =3D d->acc[what].val + add; + if (val > d->acc[what].max) + d->acc[what].max =3D val; + if (val > acc_global_max[what] && domid_is_unprivileged(d->domid)) + acc_global_max[what] =3D val; + + return val; } =20 static int domain_acc_add(struct connection *conn, unsigned int domid, @@ -1121,10 +1161,10 @@ static int domain_acc_add(struct connection *conn, = unsigned int domid, } =20 trace_acc("global change domid %u: what=3D%u %u add %d\n", domid, what, - d->acc[what], add); - d->acc[what] =3D domain_acc_add_valid(d, what, add); + d->acc[what].val, add); + d->acc[what].val =3D domain_acc_add_valid(d, what, add); =20 - return d->acc[what]; + return d->acc[what].val; } =20 void acc_drop(struct connection *conn) @@ -1159,6 +1199,28 @@ void acc_commit(struct connection *conn) } } =20 +static int domain_reset_global_acc_sub(const void *k, void *v, void *arg) +{ + struct domain *d =3D v; + unsigned int i; + + for (i =3D 0; i < ACC_N; i++) + d->acc[i].max =3D d->acc[i].val; + + return 0; +} + +void domain_reset_global_acc(void) +{ + unsigned int i; + + for (i =3D 0; i < ACC_N; i++) + acc_global_max[i] =3D 0; + + /* Set current max values seen. */ + hashtable_iterate(domhash, domain_reset_global_acc_sub, NULL); +} + int domain_nbentry_inc(struct connection *conn, unsigned int domid) { return (domain_acc_add(conn, domid, ACC_NODES, 1, false) < 0) @@ -1659,7 +1721,7 @@ static int domain_check_acc_init_sub(const void *k, v= oid *v, void *arg) * If everything is correct incrementing the value for each node will * result in dom->nodes being 0 at the end. */ - dom->nodes =3D -d->acc[ACC_NODES]; + dom->nodes =3D -d->acc[ACC_NODES].val; =20 if (!hashtable_insert(domains, &dom->domid, dom)) { talloc_free(dom); @@ -1714,7 +1776,7 @@ static int domain_check_acc_cb(const void *k, void *v= , void *arg) if (!d) return 0; =20 - d->acc[ACC_NODES] +=3D dom->nodes; + d->acc[ACC_NODES].val +=3D dom->nodes; =20 return 0; } diff --git a/tools/xenstore/xenstored_domain.h b/tools/xenstore/xenstored_d= omain.h index abc766f343..b55c9bcc2d 100644 --- a/tools/xenstore/xenstored_domain.h +++ b/tools/xenstore/xenstored_domain.h @@ -126,6 +126,8 @@ int domain_get_quota(const void *ctx, struct connection= *conn, int acc_fix_domains(struct list_head *head, bool chk_quota, bool update); void acc_drop(struct connection *conn); void acc_commit(struct connection *conn); +int domain_max_global_acc(const void *ctx, struct connection *conn); +void domain_reset_global_acc(void); =20 /* Write rate limiting */ =20 --=20 2.35.3 From nobody Wed May 15 14:38:27 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=1680678566; cv=none; d=zohomail.com; s=zohoarc; b=W2vLd0+xGy2iWZM8cpXF0jtHb4FQhwDLKKRlkTLc30IaWCyV53QtQij6Dm2iMENoHQml1SU7DqT7r+kc+FoEGXz6ljHYuAcMHwii9mbky6fMLzXEQg3CCRc8bd4twLi+n11tUXHOTzZGgD5KL9TmX0ZJOnoPDwjnnFubyFaSGh0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1680678566; 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=aCyLt0zxkjWxud2x9uGxTV8f0obgprf3/tY/K8k0jbw=; b=F1HBbNFHXSjHLGoc7YQpVJOKGHLlK+62x4VDMiN5mr+ADH+vxnm4gsYiwv6qulRi6ZqspeX3fpL9rQL1idwMS/vI0dZnjVTNOf1KOrfgNwR7+QNRuhpIG/MFX6mu38DVLV5do1INnl9yWwgWuw9EoLD+T+WyHzRtqx2jDPyBLgo= 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 1680678566927791.7694644419171; Wed, 5 Apr 2023 00:09:26 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.518257.804618 (Exim 4.92) (envelope-from ) id 1pjxGM-0007Qe-2V; Wed, 05 Apr 2023 07:08:58 +0000 Received: by outflank-mailman (output) from mailman id 518257.804618; Wed, 05 Apr 2023 07:08: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 1pjxGL-0007QS-W0; Wed, 05 Apr 2023 07:08:57 +0000 Received: by outflank-mailman (input) for mailman id 518257; Wed, 05 Apr 2023 07:08:56 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pjxCX-0002Et-31 for xen-devel@lists.xenproject.org; Wed, 05 Apr 2023 07:05:01 +0000 Received: from smtp-out2.suse.de (smtp-out2.suse.de [2001:67c:2178:6::1d]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 2d7be2a9-d380-11ed-b464-930f4c7d94ae; Wed, 05 Apr 2023 09:04:59 +0200 (CEST) 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-out2.suse.de (Postfix) with ESMTPS id F139B203F7; Wed, 5 Apr 2023 07:04:58 +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 C72B113A31; Wed, 5 Apr 2023 07:04:58 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id cxhLL5odLWQKFAAAMHmgww (envelope-from ); Wed, 05 Apr 2023 07:04:58 +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: 2d7be2a9-d380-11ed-b464-930f4c7d94ae DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1680678298; 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=aCyLt0zxkjWxud2x9uGxTV8f0obgprf3/tY/K8k0jbw=; b=JMkSCFp31r0fIZPNH2AkMftQJA+mpIcj9jvbs5ufb0Ar0XBybtUowBEtZDvBcP2LTjksJF fqxANAkevAZlQI+gakDpVPD8TisCAKrF0fcbvK1C5jjSE/LCDkdGF8CT6w2ukbn0+ujGx6 xNfbNEucYtgjqwKlr68nrI4H020r5Bo= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Julien Grall , Anthony PERARD Subject: [PATCH v4 12/13] tools/xenstore: use generic accounting for remaining quotas Date: Wed, 5 Apr 2023 09:03:48 +0200 Message-Id: <20230405070349.25293-13-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230405070349.25293-1-jgross@suse.com> References: <20230405070349.25293-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1680678567329100001 Content-Type: text/plain; charset="utf-8" The maxrequests, node size, number of node permissions, and path length quota are a little bit special, as they are either active in transactions only (maxrequests), or they are just per item instead of count values. Nevertheless being able to know the maximum number of those quota related values per domain would be beneficial, so add them to the generic accounting. The per domain value will never show current numbers other than zero, but the maximum number seen can be gathered the same way as the number of nodes during a transaction. To be able to use the const qualifier for a new function switch domain_is_unprivileged() to take a const pointer, too. Signed-off-by: Juergen Gross --- tools/xenstore/xenstored_core.c | 14 ++++----- tools/xenstore/xenstored_core.h | 2 +- tools/xenstore/xenstored_domain.c | 39 ++++++++++++++++++++------ tools/xenstore/xenstored_domain.h | 6 ++++ tools/xenstore/xenstored_transaction.c | 4 +-- tools/xenstore/xenstored_watch.c | 2 +- 6 files changed, 48 insertions(+), 19 deletions(-) diff --git a/tools/xenstore/xenstored_core.c b/tools/xenstore/xenstored_cor= e.c index 88c569b7d5..65df2866bf 100644 --- a/tools/xenstore/xenstored_core.c +++ b/tools/xenstore/xenstored_core.c @@ -799,8 +799,8 @@ int write_node_raw(struct connection *conn, TDB_DATA *k= ey, struct node *node, + node->perms.num * sizeof(node->perms.p[0]) + node->datalen + node->childlen; =20 - if (!no_quota_check && domain_is_unprivileged(conn) && - data.dsize >=3D quota_max_entry_size) { + if (domain_max_chk(conn, ACC_NODESZ, data.dsize, quota_max_entry_size) + && !no_quota_check) { errno =3D ENOSPC; return errno; } @@ -1168,7 +1168,7 @@ static bool valid_chars(const char *node) "0123456789-/_@") =3D=3D strlen(node)); } =20 -bool is_valid_nodename(const char *node) +bool is_valid_nodename(const struct connection *conn, const char *node) { int local_off =3D 0; unsigned int domid; @@ -1188,7 +1188,8 @@ bool is_valid_nodename(const char *node) if (sscanf(node, "/local/domain/%5u/%n", &domid, &local_off) !=3D 1) local_off =3D 0; =20 - if (strlen(node) > local_off + quota_max_path_len) + if (domain_max_chk(conn, ACC_PATHLEN, strlen(node) - local_off, + quota_max_path_len)) return false; =20 return valid_chars(node); @@ -1250,7 +1251,7 @@ static struct node *get_node_canonicalized(struct con= nection *conn, *canonical_name =3D canonicalize(conn, ctx, name); if (!*canonical_name) return NULL; - if (!is_valid_nodename(*canonical_name)) { + if (!is_valid_nodename(conn, *canonical_name)) { errno =3D EINVAL; return NULL; } @@ -1775,8 +1776,7 @@ static int do_set_perms(const void *ctx, struct conne= ction *conn, return EINVAL; =20 perms.num--; - if (domain_is_unprivileged(conn) && - perms.num > quota_nb_perms_per_node) + if (domain_max_chk(conn, ACC_NPERM, perms.num, quota_nb_perms_per_node)) return ENOSPC; =20 permstr =3D in->buffer + strlen(in->buffer) + 1; diff --git a/tools/xenstore/xenstored_core.h b/tools/xenstore/xenstored_cor= e.h index 3564d85d7d..9339820156 100644 --- a/tools/xenstore/xenstored_core.h +++ b/tools/xenstore/xenstored_core.h @@ -258,7 +258,7 @@ void check_store(void); void corrupt(struct connection *conn, const char *fmt, ...); =20 /* Is this a valid node name? */ -bool is_valid_nodename(const char *node); +bool is_valid_nodename(const struct connection *conn, const char *node); =20 /* Get name of parent node. */ char *get_parent(const void *ctx, const char *node); diff --git a/tools/xenstore/xenstored_domain.c b/tools/xenstore/xenstored_d= omain.c index d21f31da92..49e2c5c82a 100644 --- a/tools/xenstore/xenstored_domain.c +++ b/tools/xenstore/xenstored_domain.c @@ -433,7 +433,7 @@ int domain_get_quota(const void *ctx, struct connection= *conn, return ENOMEM; =20 #define ent(t, e) \ - resp =3D talloc_asprintf_append(resp, "%-16s: %8u (max: %8u\n", #t, \ + resp =3D talloc_asprintf_append(resp, "%-17s: %8u (max: %8u\n", #t, \ d->acc[e].val, d->acc[e].max); \ if (!resp) return ENOMEM =20 @@ -442,6 +442,7 @@ int domain_get_quota(const void *ctx, struct connection= *conn, ent(transactions, ACC_TRANS); ent(outstanding, ACC_OUTST); ent(memory, ACC_MEM); + ent(transaction-nodes, ACC_TRANSNODES); =20 #undef ent =20 @@ -459,7 +460,7 @@ int domain_max_global_acc(const void *ctx, struct conne= ction *conn) return ENOMEM; =20 #define ent(t, e) \ - resp =3D talloc_asprintf_append(resp, "%-16s: %8u\n", #t, \ + resp =3D talloc_asprintf_append(resp, "%-17s: %8u\n", #t, \ acc_global_max[e]); \ if (!resp) return ENOMEM =20 @@ -468,6 +469,7 @@ int domain_max_global_acc(const void *ctx, struct conne= ction *conn) ent(transactions, ACC_TRANS); ent(outstanding, ACC_OUTST); ent(memory, ACC_MEM); + ent(transaction-nodes, ACC_TRANSNODES); =20 #undef ent =20 @@ -1081,12 +1083,22 @@ int domain_adjust_node_perms(struct node *node) return 0; } =20 +static void domain_acc_valid_max(struct domain *d, enum accitem what, + unsigned int val) +{ + assert(what < ARRAY_SIZE(d->acc)); + assert(what < ARRAY_SIZE(acc_global_max)); + + if (val > d->acc[what].max) + d->acc[what].max =3D val; + if (val > acc_global_max[what] && domid_is_unprivileged(d->domid)) + acc_global_max[what] =3D val; +} + static int domain_acc_add_valid(struct domain *d, enum accitem what, int a= dd) { unsigned int val; =20 - assert(what < ARRAY_SIZE(d->acc)); - if ((add < 0 && -add > d->acc[what].val) || (add > 0 && (INT_MAX - d->acc[what].val) < add)) { /* @@ -1100,10 +1112,7 @@ static int domain_acc_add_valid(struct domain *d, en= um accitem what, int add) } =20 val =3D d->acc[what].val + add; - if (val > d->acc[what].max) - d->acc[what].max =3D val; - if (val > acc_global_max[what] && domid_is_unprivileged(d->domid)) - acc_global_max[what] =3D val; + domain_acc_valid_max(d, what, val); =20 return val; } @@ -1221,6 +1230,20 @@ void domain_reset_global_acc(void) hashtable_iterate(domhash, domain_reset_global_acc_sub, NULL); } =20 +bool domain_max_chk(const struct connection *conn, enum accitem what, + unsigned int val, unsigned int quota) +{ + if (!conn || !conn->domain) + return false; + + if (domain_is_unprivileged(conn) && val > quota) + return true; + + domain_acc_valid_max(conn->domain, what, val); + + return false; +} + int domain_nbentry_inc(struct connection *conn, unsigned int domid) { return (domain_acc_add(conn, domid, ACC_NODES, 1, false) < 0) diff --git a/tools/xenstore/xenstored_domain.h b/tools/xenstore/xenstored_d= omain.h index b55c9bcc2d..3e17b63659 100644 --- a/tools/xenstore/xenstored_domain.h +++ b/tools/xenstore/xenstored_domain.h @@ -32,6 +32,10 @@ enum accitem { ACC_OUTST, ACC_MEM, ACC_TRANS, + ACC_TRANSNODES, + ACC_NPERM, + ACC_PATHLEN, + ACC_NODESZ, ACC_N, /* Number of elements per domain. */ }; =20 @@ -128,6 +132,8 @@ void acc_drop(struct connection *conn); void acc_commit(struct connection *conn); int domain_max_global_acc(const void *ctx, struct connection *conn); void domain_reset_global_acc(void); +bool domain_max_chk(const struct connection *conn, unsigned int what, + unsigned int val, unsigned int quota); =20 /* Write rate limiting */ =20 diff --git a/tools/xenstore/xenstored_transaction.c b/tools/xenstore/xensto= red_transaction.c index 1c14b8579a..0b256f9b18 100644 --- a/tools/xenstore/xenstored_transaction.c +++ b/tools/xenstore/xenstored_transaction.c @@ -252,8 +252,8 @@ int access_node(struct connection *conn, struct node *n= ode, =20 i =3D find_accessed_node(trans, node->name); if (!i) { - if (trans->nodes >=3D quota_trans_nodes && - domain_is_unprivileged(conn)) { + if (domain_max_chk(conn, ACC_TRANSNODES, trans->nodes + 1, + quota_trans_nodes)) { ret =3D ENOSPC; goto err; } diff --git a/tools/xenstore/xenstored_watch.c b/tools/xenstore/xenstored_wa= tch.c index e30cd89be3..61b1e3421e 100644 --- a/tools/xenstore/xenstored_watch.c +++ b/tools/xenstore/xenstored_watch.c @@ -176,7 +176,7 @@ static int check_watch_path(struct connection *conn, co= nst void *ctx, *path =3D canonicalize(conn, ctx, *path); if (!*path) return errno; - if (!is_valid_nodename(*path)) + if (!is_valid_nodename(conn, *path)) goto inval; } =20 --=20 2.35.3 From nobody Wed May 15 14:38:27 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=1680678570; cv=none; d=zohomail.com; s=zohoarc; b=G7NaAVcuGw9EUNOhm8c7BBB21dm9xUrflSGs5xpIYeCpBWC8XwmBP+b4p6TPnztyLnJSfCqyK+I1/sxgvg6g/fCMV2qOcK7csKja7EBbXIOrFRnnSF464u1bg6sv3K8LU9bnjLchUF8HMmc/jSsd9dB+aSeH3k9W2iOcrQ0rco0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1680678570; 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=WlsEUwLyrbuDwUKcPe0rdVJuR+fsh5G5MKrTkqmSsAU=; b=LfWulynIzTZNArZmAne4rPX7Fs1yaPG9Om9TdRnJHI+K12s6h4qAPd7KueR45QvaC2UDgBy7pO+WFI1AZAj2KY/XlqyMwUutxdSIey4NMxxtfsYcm4Q1uKhuOaFIPIaoMYxekSqEfsE1utlbI425W0Lk5EyQvcSJNNLHTf+Curs= 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 1680678570120751.4344375089825; Wed, 5 Apr 2023 00:09:30 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.518268.804653 (Exim 4.92) (envelope-from ) id 1pjxGP-0008EO-Ic; Wed, 05 Apr 2023 07:09:01 +0000 Received: by outflank-mailman (output) from mailman id 518268.804653; Wed, 05 Apr 2023 07:09:01 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pjxGP-0008Dn-BL; Wed, 05 Apr 2023 07:09:01 +0000 Received: by outflank-mailman (input) for mailman id 518268; Wed, 05 Apr 2023 07:09:00 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pjxCd-0002Et-6Z for xen-devel@lists.xenproject.org; Wed, 05 Apr 2023 07:05:07 +0000 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 30dd4850-d380-11ed-b464-930f4c7d94ae; Wed, 05 Apr 2023 09:05:04 +0200 (CEST) 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-out2.suse.de (Postfix) with ESMTPS id 9FAA1201AE; Wed, 5 Apr 2023 07:05: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 6FFED13A31; Wed, 5 Apr 2023 07:05:04 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id sUUcGqAdLWQYFAAAMHmgww (envelope-from ); Wed, 05 Apr 2023 07:05:04 +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: 30dd4850-d380-11ed-b464-930f4c7d94ae DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1680678304; 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=WlsEUwLyrbuDwUKcPe0rdVJuR+fsh5G5MKrTkqmSsAU=; b=nuCyErAeaJms2nibOGMxAA1WYVt61sEpsQAOH+dBoxFDz3+jeklDHw4Wp+bbUxdmDyiZmk H4Qi8RYtT+TRz6nGLb0OcbywNqGLor5XSv80LKOmzU/0XzzhiNw6JI52TaFas4p+uqF8EU bpKKxSVcybscwIDkiW4DzfawgVwEszo= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Julien Grall , Anthony PERARD Subject: [PATCH v4 13/13] tools/xenstore: switch quota management to be table based Date: Wed, 5 Apr 2023 09:03:49 +0200 Message-Id: <20230405070349.25293-14-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230405070349.25293-1-jgross@suse.com> References: <20230405070349.25293-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1680678571769100001 Content-Type: text/plain; charset="utf-8" Instead of having individual quota variables switch to a table based approach like the generic accounting. Include all the related data in the same table and add accessor functions. This enables to use the command line --quota parameter for setting all possible quota values, keeping the previous parameters for compatibility. Signed-off-by: Juergen Gross --- V2: - new patch One further remark: it would be rather easy to add soft-quota for all the other quotas (similar to the memory one). This could be used as an early warning for the need to raise global quota. --- tools/xenstore/xenstored_control.c | 43 ++------ tools/xenstore/xenstored_core.c | 85 ++++++++-------- tools/xenstore/xenstored_core.h | 10 -- tools/xenstore/xenstored_domain.c | 132 +++++++++++++++++-------- tools/xenstore/xenstored_domain.h | 12 ++- tools/xenstore/xenstored_transaction.c | 5 +- tools/xenstore/xenstored_watch.c | 2 +- 7 files changed, 155 insertions(+), 134 deletions(-) diff --git a/tools/xenstore/xenstored_control.c b/tools/xenstore/xenstored_= control.c index a2ba64a15c..75f51a80db 100644 --- a/tools/xenstore/xenstored_control.c +++ b/tools/xenstore/xenstored_control.c @@ -221,35 +221,6 @@ static int do_control_log(const void *ctx, struct conn= ection *conn, return 0; } =20 -struct quota { - const char *name; - int *quota; - const char *descr; -}; - -static const struct quota hard_quotas[] =3D { - { "nodes", "a_nb_entry_per_domain, "Nodes per domain" }, - { "watches", "a_nb_watch_per_domain, "Watches per domain" }, - { "transactions", "a_max_transaction, "Transactions per domain" }, - { "outstanding", "a_req_outstanding, - "Outstanding requests per domain" }, - { "transaction-nodes", "a_trans_nodes, - "Max. number of accessed nodes per transaction" }, - { "memory", "a_memory_per_domain_hard, - "Total Xenstore memory per domain (error level)" }, - { "node-size", "a_max_entry_size, "Max. size of a node" }, - { "path-max", "a_max_path_len, "Max. length of a node path" }, - { "permissions", "a_nb_perms_per_node, - "Max. number of permissions per node" }, - { NULL, NULL, NULL } -}; - -static const struct quota soft_quotas[] =3D { - { "memory", "a_memory_per_domain_soft, - "Total Xenstore memory per domain (warning level)" }, - { NULL, NULL, NULL } -}; - static int quota_show_current(const void *ctx, struct connection *conn, const struct quota *quotas) { @@ -260,9 +231,11 @@ static int quota_show_current(const void *ctx, struct = connection *conn, if (!resp) return ENOMEM; =20 - for (i =3D 0; quotas[i].quota; i++) { + for (i =3D 0; i < ACC_N; i++) { + if (!quotas[i].name) + continue; resp =3D talloc_asprintf_append(resp, "%-17s: %8d %s\n", - quotas[i].name, *quotas[i].quota, + quotas[i].name, quotas[i].val, quotas[i].descr); if (!resp) return ENOMEM; @@ -274,7 +247,7 @@ static int quota_show_current(const void *ctx, struct c= onnection *conn, } =20 static int quota_set(const void *ctx, struct connection *conn, - char **vec, int num, const struct quota *quotas) + char **vec, int num, struct quota *quotas) { unsigned int i; int val; @@ -286,9 +259,9 @@ static int quota_set(const void *ctx, struct connection= *conn, if (val < 1) return EINVAL; =20 - for (i =3D 0; quotas[i].quota; i++) { - if (!strcmp(vec[0], quotas[i].name)) { - *quotas[i].quota =3D val; + for (i =3D 0; i < ACC_N; i++) { + if (quotas[i].name && !strcmp(vec[0], quotas[i].name)) { + quotas[i].val =3D val; send_ack(conn, XS_CONTROL); return 0; } diff --git a/tools/xenstore/xenstored_core.c b/tools/xenstore/xenstored_cor= e.c index 65df2866bf..6e2fc06840 100644 --- a/tools/xenstore/xenstored_core.c +++ b/tools/xenstore/xenstored_core.c @@ -89,17 +89,6 @@ unsigned int trace_flags =3D TRACE_OBJ | TRACE_IO; =20 static const char *sockmsg_string(enum xsd_sockmsg_type type); =20 -int quota_nb_entry_per_domain =3D 1000; -int quota_nb_watch_per_domain =3D 128; -int quota_max_entry_size =3D 2048; /* 2K */ -int quota_max_transaction =3D 10; -int quota_nb_perms_per_node =3D 5; -int quota_trans_nodes =3D 1024; -int quota_max_path_len =3D XENSTORE_REL_PATH_MAX; -int quota_req_outstanding =3D 20; -int quota_memory_per_domain_soft =3D 2 * 1024 * 1024; /* 2 MB */ -int quota_memory_per_domain_hard =3D 2 * 1024 * 1024 + 512 * 1024; /* 2.5 = MB */ - unsigned int timeout_watch_event_msec =3D 20000; =20 void trace(const char *fmt, ...) @@ -799,7 +788,7 @@ int write_node_raw(struct connection *conn, TDB_DATA *k= ey, struct node *node, + node->perms.num * sizeof(node->perms.p[0]) + node->datalen + node->childlen; =20 - if (domain_max_chk(conn, ACC_NODESZ, data.dsize, quota_max_entry_size) + if (domain_max_chk(conn, ACC_NODESZ, data.dsize) && !no_quota_check) { errno =3D ENOSPC; return errno; @@ -1188,8 +1177,7 @@ bool is_valid_nodename(const struct connection *conn,= const char *node) if (sscanf(node, "/local/domain/%5u/%n", &domid, &local_off) !=3D 1) local_off =3D 0; =20 - if (domain_max_chk(conn, ACC_PATHLEN, strlen(node) - local_off, - quota_max_path_len)) + if (domain_max_chk(conn, ACC_PATHLEN, strlen(node) - local_off)) return false; =20 return valid_chars(node); @@ -1501,7 +1489,7 @@ static struct node *create_node(struct connection *co= nn, const void *ctx, for (i =3D node; i; i =3D i->parent) { /* i->parent is set for each new node, so check quota. */ if (i->parent && - domain_nbentry(conn) >=3D quota_nb_entry_per_domain) { + domain_nbentry(conn) >=3D hard_quotas[ACC_NODES].val) { ret =3D ENOSPC; goto err; } @@ -1776,7 +1764,7 @@ static int do_set_perms(const void *ctx, struct conne= ction *conn, return EINVAL; =20 perms.num--; - if (domain_max_chk(conn, ACC_NPERM, perms.num, quota_nb_perms_per_node)) + if (domain_max_chk(conn, ACC_NPERM, perms.num)) return ENOSPC; =20 permstr =3D in->buffer + strlen(in->buffer) + 1; @@ -2644,7 +2632,16 @@ static void usage(void) " memory: total used memory per domain for nodes,= \n" " transactions, watches and requests, abo= ve\n" " which Xenstore will stop talking to dom= ain\n" +" nodes: number nodes owned by a domain\n" +" node-permissions: number of access permissions = per\n" +" node\n" +" node-size: total size of a node (permissions +\= n" +" children names + content)\n" " outstanding: number of outstanding requests\n" +" path-length: length of a node path\n" +" transactions: number of concurrent transactions= \n" +" per domain\n" +" watches: number of watches per domain" " -q, --quota-soft =3D set a soft quota to the value ,\n" " causing a warning to be issued via syslog() if = the\n" " limit is violated, allowed quotas are:\n" @@ -2695,12 +2692,12 @@ int dom0_domid =3D 0; int dom0_event =3D 0; int priv_domid =3D 0; =20 -static int get_optval_int(const char *arg) +static unsigned int get_optval_int(const char *arg) { char *end; - long val; + unsigned long val; =20 - val =3D strtol(arg, &end, 10); + val =3D strtoul(arg, &end, 10); if (!*arg || *end || val < 0 || val > INT_MAX) barf("invalid parameter value \"%s\"\n", arg); =20 @@ -2709,15 +2706,19 @@ static int get_optval_int(const char *arg) =20 static bool what_matches(const char *arg, const char *what) { - unsigned int what_len =3D strlen(what); + unsigned int what_len; + + if (!what) + false; =20 + what_len =3D strlen(what); return !strncmp(arg, what, what_len) && arg[what_len] =3D=3D '=3D'; } =20 static void set_timeout(const char *arg) { const char *eq =3D strchr(arg, '=3D'); - int val; + unsigned int val; =20 if (!eq) barf("quotas must be specified via =3D\n"); @@ -2731,22 +2732,22 @@ static void set_timeout(const char *arg) static void set_quota(const char *arg, bool soft) { const char *eq =3D strchr(arg, '=3D'); - int val; + struct quota *q =3D soft ? soft_quotas : hard_quotas; + unsigned int val; + unsigned int i; =20 if (!eq) barf("quotas must be specified via =3D\n"); val =3D get_optval_int(eq + 1); - if (what_matches(arg, "outstanding") && !soft) - quota_req_outstanding =3D val; - else if (what_matches(arg, "transaction-nodes") && !soft) - quota_trans_nodes =3D val; - else if (what_matches(arg, "memory")) { - if (soft) - quota_memory_per_domain_soft =3D val; - else - quota_memory_per_domain_hard =3D val; - } else - barf("unknown quota \"%s\"\n", arg); + + for (i =3D 0; i < ACC_N; i++) { + if (what_matches(arg, q[i].name)) { + q[i].val =3D val; + return; + } + } + + barf("unknown quota \"%s\"\n", arg); } =20 /* Sorted by bit values of TRACE_* flags. Flag is (1u << index). */ @@ -2808,7 +2809,7 @@ int main(int argc, char *argv[]) no_domain_init =3D true; break; case 'E': - quota_nb_entry_per_domain =3D strtol(optarg, NULL, 10); + hard_quotas[ACC_NODES].val =3D strtoul(optarg, NULL, 10); break; case 'F': pidfile =3D optarg; @@ -2826,10 +2827,10 @@ int main(int argc, char *argv[]) recovery =3D false; break; case 'S': - quota_max_entry_size =3D strtol(optarg, NULL, 10); + hard_quotas[ACC_NODESZ].val =3D strtoul(optarg, NULL, 10); break; case 't': - quota_max_transaction =3D strtol(optarg, NULL, 10); + hard_quotas[ACC_TRANS].val =3D strtoul(optarg, NULL, 10); break; case 'T': tracefile =3D optarg; @@ -2849,15 +2850,17 @@ int main(int argc, char *argv[]) verbose =3D true; break; case 'W': - quota_nb_watch_per_domain =3D strtol(optarg, NULL, 10); + hard_quotas[ACC_WATCH].val =3D strtoul(optarg, NULL, 10); break; case 'A': - quota_nb_perms_per_node =3D strtol(optarg, NULL, 10); + hard_quotas[ACC_NPERM].val =3D strtoul(optarg, NULL, 10); break; case 'M': - quota_max_path_len =3D strtol(optarg, NULL, 10); - quota_max_path_len =3D min(XENSTORE_REL_PATH_MAX, - quota_max_path_len); + hard_quotas[ACC_PATHLEN].val =3D + strtoul(optarg, NULL, 10); + hard_quotas[ACC_PATHLEN].val =3D + min((unsigned int)XENSTORE_REL_PATH_MAX, + hard_quotas[ACC_PATHLEN].val); break; case 'Q': set_quota(optarg, false); diff --git a/tools/xenstore/xenstored_core.h b/tools/xenstore/xenstored_cor= e.h index 9339820156..92d5b50f3c 100644 --- a/tools/xenstore/xenstored_core.h +++ b/tools/xenstore/xenstored_core.h @@ -316,16 +316,6 @@ extern TDB_CONTEXT *tdb_ctx; extern int dom0_domid; extern int dom0_event; extern int priv_domid; -extern int quota_nb_watch_per_domain; -extern int quota_max_transaction; -extern int quota_max_entry_size; -extern int quota_nb_perms_per_node; -extern int quota_max_path_len; -extern int quota_nb_entry_per_domain; -extern int quota_req_outstanding; -extern int quota_trans_nodes; -extern int quota_memory_per_domain_soft; -extern int quota_memory_per_domain_hard; extern bool keep_orphans; =20 extern unsigned int timeout_watch_event_msec; diff --git a/tools/xenstore/xenstored_domain.c b/tools/xenstore/xenstored_d= omain.c index 49e2c5c82a..9f6b17cca3 100644 --- a/tools/xenstore/xenstored_domain.c +++ b/tools/xenstore/xenstored_domain.c @@ -43,7 +43,61 @@ static evtchn_port_t virq_port; =20 xenevtchn_handle *xce_handle =3D NULL; =20 -static unsigned int acc_global_max[ACC_N]; +struct quota hard_quotas[ACC_N] =3D { + [ACC_NODES] =3D { + .name =3D "nodes", + .descr =3D "Nodes per domain", + .val =3D 1000, + }, + [ACC_WATCH] =3D { + .name =3D "watches", + .descr =3D "Watches per domain", + .val =3D 128, + }, + [ACC_OUTST] =3D { + .name =3D "outstanding", + .descr =3D "Outstanding requests per domain", + .val =3D 20, + }, + [ACC_MEM] =3D { + .name =3D "memory", + .descr =3D "Total Xenstore memory per domain (error level)", + .val =3D 2 * 1024 * 1024 + 512 * 1024, /* 2.5 MB */ + }, + [ACC_TRANS] =3D { + .name =3D "transactions", + .descr =3D "Active transactions per domain", + .val =3D 10, + }, + [ACC_TRANSNODES] =3D { + .name =3D "transaction-nodes", + .descr =3D "Max. number of accessed nodes per transaction", + .val =3D 1024, + }, + [ACC_NPERM] =3D { + .name =3D "node-permissions", + .descr =3D "Max. number of permissions per node", + .val =3D 5, + }, + [ACC_PATHLEN] =3D { + .name =3D "path-max", + .descr =3D "Max. length of a node path", + .val =3D XENSTORE_REL_PATH_MAX, + }, + [ACC_NODESZ] =3D { + .name =3D "node-size", + .descr =3D "Max. size of a node", + .val =3D 2048, + }, +}; + +struct quota soft_quotas[ACC_N] =3D { + [ACC_MEM] =3D { + .name =3D "memory", + .descr =3D "Total Xenstore memory per domain (warning level)", + .val =3D 2 * 1024 * 1024, /* 2.0 MB */ + }, +}; =20 struct domain { @@ -206,10 +260,10 @@ static bool domain_can_read(struct connection *conn) if (domain_is_unprivileged(conn)) { if (domain->wrl_credit < 0) return false; - if (domain->acc[ACC_OUTST].val >=3D quota_req_outstanding) + if (domain->acc[ACC_OUTST].val >=3D hard_quotas[ACC_OUTST].val) return false; - if (domain->acc[ACC_MEM].val >=3D quota_memory_per_domain_hard && - quota_memory_per_domain_hard) + if (domain->acc[ACC_MEM].val >=3D hard_quotas[ACC_MEM].val && + hard_quotas[ACC_MEM].val) return false; } =20 @@ -424,6 +478,7 @@ int domain_get_quota(const void *ctx, struct connection= *conn, { struct domain *d =3D find_domain_struct(domid); char *resp; + unsigned int i; =20 if (!d) return ENOENT; @@ -432,19 +487,15 @@ int domain_get_quota(const void *ctx, struct connecti= on *conn, if (!resp) return ENOMEM; =20 -#define ent(t, e) \ - resp =3D talloc_asprintf_append(resp, "%-17s: %8u (max: %8u\n", #t, \ - d->acc[e].val, d->acc[e].max); \ - if (!resp) return ENOMEM - - ent(nodes, ACC_NODES); - ent(watches, ACC_WATCH); - ent(transactions, ACC_TRANS); - ent(outstanding, ACC_OUTST); - ent(memory, ACC_MEM); - ent(transaction-nodes, ACC_TRANSNODES); - -#undef ent + for (i =3D 0; i < ACC_N; i++) { + if (!hard_quotas[i].name) + continue; + resp =3D talloc_asprintf_append(resp, "%-17s: %8u (max %8u)\n", + hard_quotas[i].name, + d->acc[i].val, d->acc[i].max); + if (!resp) + return ENOMEM; + } =20 send_reply(conn, XS_CONTROL, resp, strlen(resp) + 1); =20 @@ -454,24 +505,21 @@ int domain_get_quota(const void *ctx, struct connecti= on *conn, int domain_max_global_acc(const void *ctx, struct connection *conn) { char *resp; + unsigned int i; =20 resp =3D talloc_asprintf(ctx, "Max. seen accounting values:\n"); if (!resp) return ENOMEM; =20 -#define ent(t, e) \ - resp =3D talloc_asprintf_append(resp, "%-17s: %8u\n", #t, \ - acc_global_max[e]); \ - if (!resp) return ENOMEM - - ent(nodes, ACC_NODES); - ent(watches, ACC_WATCH); - ent(transactions, ACC_TRANS); - ent(outstanding, ACC_OUTST); - ent(memory, ACC_MEM); - ent(transaction-nodes, ACC_TRANSNODES); - -#undef ent + for (i =3D 0; i < ACC_N; i++) { + if (!hard_quotas[i].name) + continue; + resp =3D talloc_asprintf_append(resp, "%-17s: %8u\n", + hard_quotas[i].name, + hard_quotas[i].max); + if (!resp) + return ENOMEM; + } =20 send_reply(conn, XS_CONTROL, resp, strlen(resp) + 1); =20 @@ -586,7 +634,7 @@ int acc_fix_domains(struct list_head *head, bool chk_qu= ota, bool update) list_for_each_entry(cd, head, list) { cnt =3D domain_nbentry_fix(cd->domid, cd->acc[ACC_NODES], update); if (!update) { - if (chk_quota && cnt >=3D quota_nb_entry_per_domain) + if (chk_quota && cnt >=3D hard_quotas[ACC_NODES].val) return ENOSPC; if (cnt < 0) return ENOMEM; @@ -1087,12 +1135,12 @@ static void domain_acc_valid_max(struct domain *d, = enum accitem what, unsigned int val) { assert(what < ARRAY_SIZE(d->acc)); - assert(what < ARRAY_SIZE(acc_global_max)); + assert(what < ARRAY_SIZE(hard_quotas)); =20 if (val > d->acc[what].max) d->acc[what].max =3D val; - if (val > acc_global_max[what] && domid_is_unprivileged(d->domid)) - acc_global_max[what] =3D val; + if (val > hard_quotas[what].max && domid_is_unprivileged(d->domid)) + hard_quotas[what].max =3D val; } =20 static int domain_acc_add_valid(struct domain *d, enum accitem what, int a= dd) @@ -1224,19 +1272,19 @@ void domain_reset_global_acc(void) unsigned int i; =20 for (i =3D 0; i < ACC_N; i++) - acc_global_max[i] =3D 0; + hard_quotas[i].max =3D 0; =20 /* Set current max values seen. */ hashtable_iterate(domhash, domain_reset_global_acc_sub, NULL); } =20 bool domain_max_chk(const struct connection *conn, enum accitem what, - unsigned int val, unsigned int quota) + unsigned int val) { if (!conn || !conn->domain) return false; =20 - if (domain_is_unprivileged(conn) && val > quota) + if (domain_is_unprivileged(conn) && val > hard_quotas[what].val) return true; =20 domain_acc_valid_max(conn->domain, what, val); @@ -1285,8 +1333,7 @@ static bool domain_chk_quota(struct connection *conn,= unsigned int mem) domain =3D conn->domain; now =3D time(NULL); =20 - if (mem >=3D quota_memory_per_domain_hard && - quota_memory_per_domain_hard) { + if (mem >=3D hard_quotas[ACC_MEM].val && hard_quotas[ACC_MEM].val) { if (domain->hard_quota_reported) return true; syslog(LOG_ERR, "Domain %u exceeds hard memory quota, Xenstore interface= to domain stalled\n", @@ -1303,15 +1350,14 @@ static bool domain_chk_quota(struct connection *con= n, unsigned int mem) syslog(LOG_INFO, "Domain %u below hard memory quota again\n", domain->domid); } - if (mem >=3D quota_memory_per_domain_soft && - quota_memory_per_domain_soft && - !domain->soft_quota_reported) { + if (mem >=3D soft_quotas[ACC_MEM].val && + soft_quotas[ACC_MEM].val && !domain->soft_quota_reported) { domain->mem_last_msg =3D now; domain->soft_quota_reported =3D true; syslog(LOG_WARNING, "Domain %u exceeds soft memory quota\n", domain->domid); } - if (mem < quota_memory_per_domain_soft && + if (mem < soft_quotas[ACC_MEM].val && domain->soft_quota_reported) { domain->mem_last_msg =3D now; domain->soft_quota_reported =3D false; diff --git a/tools/xenstore/xenstored_domain.h b/tools/xenstore/xenstored_d= omain.h index 3e17b63659..b9e38abff5 100644 --- a/tools/xenstore/xenstored_domain.h +++ b/tools/xenstore/xenstored_domain.h @@ -39,6 +39,16 @@ enum accitem { ACC_N, /* Number of elements per domain. */ }; =20 +struct quota { + const char *name; + const char *descr; + unsigned int val; + unsigned int max; +}; + +extern struct quota hard_quotas[ACC_N]; +extern struct quota soft_quotas[ACC_N]; + void handle_event(void); =20 void check_domains(void); @@ -133,7 +143,7 @@ void acc_commit(struct connection *conn); int domain_max_global_acc(const void *ctx, struct connection *conn); void domain_reset_global_acc(void); bool domain_max_chk(const struct connection *conn, unsigned int what, - unsigned int val, unsigned int quota); + unsigned int val); =20 /* Write rate limiting */ =20 diff --git a/tools/xenstore/xenstored_transaction.c b/tools/xenstore/xensto= red_transaction.c index 0b256f9b18..e8968d7a1d 100644 --- a/tools/xenstore/xenstored_transaction.c +++ b/tools/xenstore/xenstored_transaction.c @@ -252,8 +252,7 @@ int access_node(struct connection *conn, struct node *n= ode, =20 i =3D find_accessed_node(trans, node->name); if (!i) { - if (domain_max_chk(conn, ACC_TRANSNODES, trans->nodes + 1, - quota_trans_nodes)) { + if (domain_max_chk(conn, ACC_TRANSNODES, trans->nodes + 1)) { ret =3D ENOSPC; goto err; } @@ -479,7 +478,7 @@ int do_transaction_start(const void *ctx, struct connec= tion *conn, if (conn->transaction) return EBUSY; =20 - if (domain_transaction_get(conn) > quota_max_transaction) + if (domain_transaction_get(conn) > hard_quotas[ACC_TRANS].val) return ENOSPC; =20 /* Attach transaction to ctx for autofree until it's complete */ diff --git a/tools/xenstore/xenstored_watch.c b/tools/xenstore/xenstored_wa= tch.c index 61b1e3421e..e8eb35de02 100644 --- a/tools/xenstore/xenstored_watch.c +++ b/tools/xenstore/xenstored_watch.c @@ -239,7 +239,7 @@ int do_watch(const void *ctx, struct connection *conn, = struct buffered_data *in) return EEXIST; } =20 - if (domain_watch(conn) > quota_nb_watch_per_domain) + if (domain_watch(conn) > hard_quotas[ACC_WATCH].val) return E2BIG; =20 watch =3D add_watch(conn, vec[0], vec[1], relative, false); --=20 2.35.3