From nobody Fri May 17 03:00:56 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=1673946719; cv=none; d=zohomail.com; s=zohoarc; b=dhDaqXfLFrxIa5q/MD/5il7cu5rJztM73gwuaD+kIObO5MlnAFOSpv8WMUnWBbgvVYc/sk3FhyyeHcMom0tSj9i2kaFJZdrKSxxrVksn8WmEOxxohHVgGUUe604BX5XcLfmmENQd94psd54rwI9pP1JA7FchR7XatcK8z6NU1YE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1673946719; 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=zdMk1qkjmk7nTB2tDqSEvlsn0bUTpkOAiGi5WVrM4wM=; b=AdlnKJXNSs4x7RILUxNrIzEq9F/XkjTLzcA5ccIkfBQUM0J5DARhX0/SLL0VrchaQW4G3amoK33oj3y0dePd8TDqfIrhTaREjpVzocyjmMiZviyRhffNk3ZtHelb4CN65R4cIzPI0TrY1WiDt6KKIwVHrl2GGuHmHFeTq2dRqyE= 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 1673946719659820.7226862733289; Tue, 17 Jan 2023 01:11:59 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.479127.742764 (Exim 4.92) (envelope-from ) id 1pHi0E-0007IR-Gn; Tue, 17 Jan 2023 09:11:34 +0000 Received: by outflank-mailman (output) from mailman id 479127.742764; Tue, 17 Jan 2023 09:11: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 1pHi0E-0007IK-Dt; Tue, 17 Jan 2023 09:11:34 +0000 Received: by outflank-mailman (input) for mailman id 479127; Tue, 17 Jan 2023 09:11:33 +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 1pHi0D-000725-CL for xen-devel@lists.xenproject.org; Tue, 17 Jan 2023 09:11:33 +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 ef57441b-9646-11ed-91b6-6bf2151ebd3b; Tue, 17 Jan 2023 10:11:32 +0100 (CET) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 7822438216; Tue, 17 Jan 2023 09:11:32 +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 48F211390C; Tue, 17 Jan 2023 09:11:32 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id QoNqEERmxmPebwAAMHmgww (envelope-from ); Tue, 17 Jan 2023 09:11:32 +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: ef57441b-9646-11ed-91b6-6bf2151ebd3b DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1673946692; 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=zdMk1qkjmk7nTB2tDqSEvlsn0bUTpkOAiGi5WVrM4wM=; b=EvWYlOE4+ht6qUFPWnuAeTt227VV/Idv4qfIr3XFiGOaPnCQXkq9/HYHucdO+6u2aiihAf IcNRLuqjsVV818MOilkGf7X1iIiKzN0CNx9f2TjalW/c6txg61iHoKXabFrMTrZCsHm1G/ f7XGesvJs1k2N7UYrFfcH7WHF3jLrmM= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Julien Grall , Anthony PERARD Subject: [PATCH v3 01/17] tools/xenstore: let talloc_free() preserve errno Date: Tue, 17 Jan 2023 10:11:08 +0100 Message-Id: <20230117091124.22170-2-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230117091124.22170-1-jgross@suse.com> References: <20230117091124.22170-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1673946721894100001 Content-Type: text/plain; charset="utf-8" Today talloc_free() is not guaranteed to preserve errno, especially in case a custom destructor is being used. So preserve errno in talloc_free(). This allows to remove some errno saving outside of talloc.c. Signed-off-by: Juergen Gross Reviewed-by: Julien Grall --- V2: - drop wrapper (Julien Grall) --- tools/xenstore/talloc.c | 21 +++++++++++++-------- tools/xenstore/xenstored_core.c | 2 -- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/tools/xenstore/talloc.c b/tools/xenstore/talloc.c index d7edcf3a93..23c3a23b19 100644 --- a/tools/xenstore/talloc.c +++ b/tools/xenstore/talloc.c @@ -541,38 +541,39 @@ static void talloc_free_children(void *ptr) */ int talloc_free(void *ptr) { + int saved_errno =3D errno; struct talloc_chunk *tc; =20 if (ptr =3D=3D NULL) { - return -1; + goto err; } =20 tc =3D talloc_chunk_from_ptr(ptr); =20 if (tc->null_refs) { tc->null_refs--; - return -1; + goto err; } =20 if (tc->refs) { talloc_reference_destructor(tc->refs); - return -1; + goto err; } =20 if (tc->flags & TALLOC_FLAG_LOOP) { /* we have a free loop - stop looping */ - return 0; + goto success; } =20 if (tc->destructor) { talloc_destructor_t d =3D tc->destructor; if (d =3D=3D (talloc_destructor_t)-1) { - return -1; + goto err; } tc->destructor =3D (talloc_destructor_t)-1; if (d(ptr) =3D=3D -1) { tc->destructor =3D d; - return -1; + goto err; } tc->destructor =3D NULL; } @@ -594,10 +595,14 @@ int talloc_free(void *ptr) tc->flags |=3D TALLOC_FLAG_FREE; =20 free(tc); + success: + errno =3D saved_errno; return 0; -} - =20 + err: + errno =3D saved_errno; + return -1; +} =20 /* A talloc version of realloc. The context argument is only used if diff --git a/tools/xenstore/xenstored_core.c b/tools/xenstore/xenstored_cor= e.c index 78a3edaa4e..1650821922 100644 --- a/tools/xenstore/xenstored_core.c +++ b/tools/xenstore/xenstored_core.c @@ -771,9 +771,7 @@ struct node *read_node(struct connection *conn, const v= oid *ctx, return node; =20 error: - err =3D errno; talloc_free(node); - errno =3D err; return NULL; } =20 --=20 2.35.3 From nobody Fri May 17 03:00:56 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=1673946723; cv=none; d=zohomail.com; s=zohoarc; b=jBlcknyMyygIshYJPP9QHTpHL43bqwzEhLUT7MPkumqu5paHGjWOPsjSC9Oa58UvtiYUtplde5SbBTHgxFqnjkBO8VJva6bjQSk70GcunyMcMSAxgSIUJTco85VxPl9I9B3GwHTqhUdvE+rhvBlylen7KtQt23X4op+Mm/NRjHU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1673946723; 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=pX5UiTuGTkIWUb6YtyjDTQ7IukPWx9sxAlYTbqTbJs0=; b=FUU0CMAxyZuANodaq3VV4blSHUghkKIVvU+awtND5Uv2wvLYtervnQtV+BgoPnGwjkf/0QBP/u+H+aCiz11mL0olGoo/XGJQFFnnmmm3CigoRktqF32U8yoNRe7fX2CKtG9m37YC1vTxn5iN0YQ1afBnQgtuoYQbJIPhh5jKT8A= 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 1673946723140947.7651836874263; Tue, 17 Jan 2023 01:12:03 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.479128.742775 (Exim 4.92) (envelope-from ) id 1pHi0L-0007ek-Ro; Tue, 17 Jan 2023 09:11:41 +0000 Received: by outflank-mailman (output) from mailman id 479128.742775; Tue, 17 Jan 2023 09:11:41 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pHi0L-0007eJ-NP; Tue, 17 Jan 2023 09:11:41 +0000 Received: by outflank-mailman (input) for mailman id 479128; Tue, 17 Jan 2023 09:11:40 +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 1pHi0K-0007bs-8P for xen-devel@lists.xenproject.org; Tue, 17 Jan 2023 09:11:40 +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 f2ad1d0b-9646-11ed-b8d0-410ff93cb8f0; Tue, 17 Jan 2023 10:11:38 +0100 (CET) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 1399E38216; Tue, 17 Jan 2023 09:11:38 +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 D4A641390C; Tue, 17 Jan 2023 09:11:37 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 0wGCMklmxmPrbwAAMHmgww (envelope-from ); Tue, 17 Jan 2023 09:11:37 +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: f2ad1d0b-9646-11ed-b8d0-410ff93cb8f0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1673946698; 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=pX5UiTuGTkIWUb6YtyjDTQ7IukPWx9sxAlYTbqTbJs0=; b=kx+Wz/gVoOvbmptZE+o5NRjQpL0o8XEFpo0rhNTFM4XenVeTBueyxVmYeNO452JN4anBW6 PSaAVxieTZOABJCqPQ/TgEWzIvOYHswC4tzs3hMxHixMzjxaHy0lchG5RrEUfFsRsGiYnH JYtEgsnEow0RrybXY/9P1+o0+Ro53p0= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Julien Grall , Anthony PERARD , Julien Grall Subject: [PATCH v3 02/17] tools/xenstore: remove all watches when a domain has stopped Date: Tue, 17 Jan 2023 10:11:09 +0100 Message-Id: <20230117091124.22170-3-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230117091124.22170-1-jgross@suse.com> References: <20230117091124.22170-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1673946723784100005 Content-Type: text/plain; charset="utf-8" When a domain has been released by Xen tools, remove all its registered watches. This avoids sending watch events to the dead domain when all the nodes related to it are being removed by the Xen tools. Signed-off-by: Juergen Gross Reviewed-by: Julien Grall --- V2: - move call to do_release() (Julien Grall) --- tools/xenstore/xenstored_domain.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tools/xenstore/xenstored_domain.c b/tools/xenstore/xenstored_d= omain.c index aa86892fed..e669c89e94 100644 --- a/tools/xenstore/xenstored_domain.c +++ b/tools/xenstore/xenstored_domain.c @@ -740,6 +740,9 @@ int do_release(const void *ctx, struct connection *conn, if (IS_ERR(domain)) return -PTR_ERR(domain); =20 + /* Avoid triggering watch events when the domain's nodes are deleted. */ + conn_delete_all_watches(domain->conn); + talloc_free(domain->conn); =20 send_ack(conn, XS_RELEASE); --=20 2.35.3 From nobody Fri May 17 03:00:56 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=1673946732; cv=none; d=zohomail.com; s=zohoarc; b=fcY+7niEuPwyr84WBQbDb+t39TUaccY3CIJ2NbzteUMKPwYZgi/5Ti9XHFHgH66wSb2VXl5huTi5rDnhtmOO9SL++0IX5uD7mwU/cYJBApFnMZ7wZs5yPoYtUh+qRRBvAUd/dgyrM5teFlqIc9I8OFX0SpxfWK/CFWvKE/rbxNw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1673946732; 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=cvGa+mf9SlLa4egdJdNXtGqzGNV+vTmzoXzqW3HDEaE=; b=UuwUUzqxKBhWVeA5BsrPLQNpTRJh77py7wY+QfqKGwx5Ji8qxy4Jy0/YIMfyCkoJU2EOLtSVeXO1aidkuQYhhCLV+qIciWVbL0FvDC7eRmbFkdHt76tdyYvuNjjMLlzvmBi+eZZfLr5cexwrnHV2FRI6OYASNiaNNAdHrNVpCEg= 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 1673946732013402.14715762844105; Tue, 17 Jan 2023 01:12:12 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.479130.742786 (Exim 4.92) (envelope-from ) id 1pHi0R-00084t-3q; Tue, 17 Jan 2023 09:11:47 +0000 Received: by outflank-mailman (output) from mailman id 479130.742786; Tue, 17 Jan 2023 09:11:47 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pHi0Q-00084h-WC; Tue, 17 Jan 2023 09:11:47 +0000 Received: by outflank-mailman (input) for mailman id 479130; Tue, 17 Jan 2023 09:11:46 +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 1pHi0Q-0007bs-1f for xen-devel@lists.xenproject.org; Tue, 17 Jan 2023 09:11:46 +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 f6034998-9646-11ed-b8d0-410ff93cb8f0; Tue, 17 Jan 2023 10:11:43 +0100 (CET) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id A5A5F683D9; Tue, 17 Jan 2023 09:11:43 +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 73C0C1390C; Tue, 17 Jan 2023 09:11:43 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id b4ztGk9mxmP2bwAAMHmgww (envelope-from ); Tue, 17 Jan 2023 09:11:43 +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: f6034998-9646-11ed-b8d0-410ff93cb8f0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1673946703; 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=cvGa+mf9SlLa4egdJdNXtGqzGNV+vTmzoXzqW3HDEaE=; b=ZJqVTQF9/M2yeoK0fgFxi0Kx511cw1FZAJ5KlRDSqxvP+lWccFDpcP/DI8vMf5EKy6sYov vZWxly1zsgUIn53xmTABqvCJ7msKctBTmJqh4kyUuz9lCmD/LamMnspDB23DGmzkG3eBBh cT7RP33CBDKZbMYhxhWr0Y/lI6Tl+48= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Julien Grall , Anthony PERARD , Julien Grall Subject: [PATCH v3 03/17] tools/xenstore: add hashlist for finding struct domain by domid Date: Tue, 17 Jan 2023 10:11:10 +0100 Message-Id: <20230117091124.22170-4-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230117091124.22170-1-jgross@suse.com> References: <20230117091124.22170-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1673946733754100001 Content-Type: text/plain; charset="utf-8" Today finding a struct domain by its domain id requires to scan the list of domains until finding the correct domid. Add a hashlist for being able to speed this up. This allows to remove the linking of struct domain in a list. Note that the list of changed domains per transaction is kept as a list, as there are no known use cases with more than 4 domains being touched in a single transaction (this would be a device handled by a driver domain and being assigned to a HVM domain with device model in a stubdom, plus the control domain). Some simple performance tests comparing the scanning and hashlist have shown that the hashlist will win as soon as more than 6 entries need to be scanned. Signed-off-by: Juergen Gross Reviewed-by: Julien Grall --- V2: - add comment, fix return value of check_domain() (Julien Grall) --- tools/xenstore/xenstored_domain.c | 102 ++++++++++++++++++------------ 1 file changed, 60 insertions(+), 42 deletions(-) diff --git a/tools/xenstore/xenstored_domain.c b/tools/xenstore/xenstored_d= omain.c index e669c89e94..3ad1028edb 100644 --- a/tools/xenstore/xenstored_domain.c +++ b/tools/xenstore/xenstored_domain.c @@ -48,8 +48,6 @@ static struct node_perms dom_introduce_perms; =20 struct domain { - struct list_head list; - /* The id of this domain */ unsigned int domid; =20 @@ -96,7 +94,7 @@ struct domain bool wrl_delay_logged; }; =20 -static LIST_HEAD(domains); +static struct hashtable *domhash; =20 static bool check_indexes(XENSTORE_RING_IDX cons, XENSTORE_RING_IDX prod) { @@ -309,7 +307,7 @@ static int destroy_domain(void *_domain) =20 domain_tree_remove(domain); =20 - list_del(&domain->list); + hashtable_remove(domhash, &domain->domid); =20 if (!domain->introduced) return 0; @@ -341,43 +339,50 @@ static bool get_domain_info(unsigned int domid, xc_do= minfo_t *dominfo) dominfo->domid =3D=3D domid; } =20 -void check_domains(void) +static int check_domain(const void *k, void *v, void *arg) { xc_dominfo_t dominfo; - struct domain *domain; struct connection *conn; - int notify =3D 0; bool dom_valid; + struct domain *domain =3D v; + bool *notify =3D arg; =20 - again: - list_for_each_entry(domain, &domains, list) { - dom_valid =3D get_domain_info(domain->domid, &dominfo); - if (!domain->introduced) { - if (!dom_valid) { - talloc_free(domain); - goto again; - } - continue; - } - if (dom_valid) { - if ((dominfo.crashed || dominfo.shutdown) - && !domain->shutdown) { - domain->shutdown =3D true; - notify =3D 1; - } - if (!dominfo.dying) - continue; - } - if (domain->conn) { - /* domain is a talloc child of domain->conn. */ - conn =3D domain->conn; - domain->conn =3D NULL; - talloc_unlink(talloc_autofree_context(), conn); - notify =3D 0; /* destroy_domain() fires the watch */ - goto again; + dom_valid =3D get_domain_info(domain->domid, &dominfo); + if (!domain->introduced) { + if (!dom_valid) + talloc_free(domain); + return 0; + } + if (dom_valid) { + if ((dominfo.crashed || dominfo.shutdown) + && !domain->shutdown) { + domain->shutdown =3D true; + *notify =3D true; } + if (!dominfo.dying) + return 0; + } + if (domain->conn) { + /* domain is a talloc child of domain->conn. */ + conn =3D domain->conn; + domain->conn =3D NULL; + talloc_unlink(talloc_autofree_context(), conn); + *notify =3D false; /* destroy_domain() fires the watch */ + + /* Above unlink might result in 2 domains being freed! */ + return 1; } =20 + return 0; +} + +void check_domains(void) +{ + bool notify =3D false; + + while (hashtable_iterate(domhash, check_domain, ¬ify)) + ; + if (notify) fire_watches(NULL, NULL, "@releaseDomain", NULL, true, NULL); } @@ -415,13 +420,7 @@ static char *talloc_domain_path(const void *context, u= nsigned int domid) =20 static struct domain *find_domain_struct(unsigned int domid) { - struct domain *i; - - list_for_each_entry(i, &domains, list) { - if (i->domid =3D=3D domid) - return i; - } - return NULL; + return hashtable_search(domhash, &domid); } =20 int domain_get_quota(const void *ctx, struct connection *conn, @@ -470,9 +469,13 @@ static struct domain *alloc_domain(const void *context= , unsigned int domid) domain->generation =3D generation; domain->introduced =3D false; =20 - talloc_set_destructor(domain, destroy_domain); + if (!hashtable_insert(domhash, &domain->domid, domain)) { + talloc_free(domain); + errno =3D ENOMEM; + return NULL; + } =20 - list_add(&domain->list, &domains); + talloc_set_destructor(domain, destroy_domain); =20 return domain; } @@ -906,10 +909,25 @@ void dom0_init(void) xenevtchn_notify(xce_handle, dom0->port); } =20 +static unsigned int domhash_fn(void *k) +{ + return *(unsigned int *)k; +} + +static int domeq_fn(void *key1, void *key2) +{ + return *(unsigned int *)key1 =3D=3D *(unsigned int *)key2; +} + void domain_init(int evtfd) { int rc; =20 + /* Start with a random rather low domain count for the hashtable. */ + domhash =3D create_hashtable(8, domhash_fn, domeq_fn, 0); + if (!domhash) + barf_perror("Failed to allocate domain hashtable"); + xc_handle =3D talloc(talloc_autofree_context(), xc_interface*); if (!xc_handle) barf_perror("Failed to allocate domain handle"); --=20 2.35.3 From nobody Fri May 17 03:00:56 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=1673946735; cv=none; d=zohomail.com; s=zohoarc; b=QmI66H5mHVtJrCV8fv1Re/Sf9e7MG4w5LC8h8FujVyZXYSN13cut46xU2fS0fHIjNzH2d/CESpQZ3QZdt/fYNd5fqGpZ69hFmA/ykUbmN5D7+OMJCWBqhwrna0Bykqy0SiXqSbSoGocnh+MogV4UUzV4cK4fx70sAtl94Rp0MBY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1673946735; 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=AyZo7Qotz+0VbPqrO+ia/QPua4oxXsp64cB3hD04LW0=; b=FMm7ESlwIDVFEwH0egc0zz5A+B44DX+4g1jutgcDF7Q7OYMESsWjIMhNDu6i8SRMATyWTLeHoxALN5rrHJRko1DQj+kRhuAS/9mWtfZFJ5OdA2aAJYAb2iCYWgZimOvlu3HAFkfC/xjwoRx/tLr7KxjB4K0cElp4W8ps1dUIl7Y= 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 1673946735325715.318284885659; Tue, 17 Jan 2023 01:12:15 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.479133.742796 (Exim 4.92) (envelope-from ) id 1pHi0Y-00007s-Cm; Tue, 17 Jan 2023 09:11:54 +0000 Received: by outflank-mailman (output) from mailman id 479133.742796; Tue, 17 Jan 2023 09:11:54 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pHi0Y-00007l-9T; Tue, 17 Jan 2023 09:11:54 +0000 Received: by outflank-mailman (input) for mailman id 479133; Tue, 17 Jan 2023 09:11:52 +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 1pHi0W-0007bs-7N for xen-devel@lists.xenproject.org; Tue, 17 Jan 2023 09:11:52 +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 f95dd100-9646-11ed-b8d0-410ff93cb8f0; Tue, 17 Jan 2023 10:11:49 +0100 (CET) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 482C438217; Tue, 17 Jan 2023 09:11:49 +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 169281390C; Tue, 17 Jan 2023 09:11:49 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 8AA1BFVmxmMHcAAAMHmgww (envelope-from ); Tue, 17 Jan 2023 09:11:49 +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: f95dd100-9646-11ed-b8d0-410ff93cb8f0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1673946709; 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=AyZo7Qotz+0VbPqrO+ia/QPua4oxXsp64cB3hD04LW0=; b=gq5vdoBYRSWMyx1A/ckf9kkg+Vi4ppMU1t6kp11/YNCZSxJ1IB5d3ZSeFz9J0H5/Fw2ydx +ZLYzhVZ59guu/P2zRAFH/Z5mFEtPvYfp2gpO5HjZ6UpUwsIO5gRert45DLKcEnhuN6SQX 6AofNmZUCLy+nNaJpB76TyURSc8zJ9w= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Julien Grall , Anthony PERARD Subject: [PATCH v3 04/17] tools/xenstore: introduce dummy nodes for special watch paths Date: Tue, 17 Jan 2023 10:11:11 +0100 Message-Id: <20230117091124.22170-5-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230117091124.22170-1-jgross@suse.com> References: <20230117091124.22170-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1673946735815100003 Content-Type: text/plain; charset="utf-8" Instead of special casing the permission handling and watch event firing for the special watch paths "@introduceDomain" and "@releaseDomain", use static dummy nodes added to the data base when starting Xenstore. The node accounting needs to reflect that change by adding the special nodes in the domain_entry_fix() call in setup_structure(). Note that this requires to rework the calls of fire_watches() for the special events in order to avoid leaking memory. Move the check for a valid node name from get_node() to get_node_canonicalized(), as it allows to use get_node() for the special nodes, too. In order to avoid read and write accesses to the special nodes use a special variant for obtaining the current node data for the permission handling. This allows to simplify quite some code. In future sub-nodes of the special nodes will be possible due to this change, allowing more fine grained permission control of special events for specific domains. Signed-off-by: Juergen Gross Reviewed-by: Julien Grall --- V2: - add get_spec_node() - expand commit message (Julien Grall) V3: - modify get_acc_domid() comment (Julien Grall) - log error in fire_special_watches() (Julien Grall) --- tools/xenstore/xenstored_control.c | 3 - tools/xenstore/xenstored_core.c | 94 ++++++++++------- tools/xenstore/xenstored_domain.c | 164 ++++------------------------- tools/xenstore/xenstored_domain.h | 6 -- tools/xenstore/xenstored_watch.c | 17 +-- 5 files changed, 83 insertions(+), 201 deletions(-) diff --git a/tools/xenstore/xenstored_control.c b/tools/xenstore/xenstored_= control.c index d1aaa00bf4..41e6992591 100644 --- a/tools/xenstore/xenstored_control.c +++ b/tools/xenstore/xenstored_control.c @@ -676,9 +676,6 @@ static const char *lu_dump_state(const void *ctx, struc= t connection *conn) if (ret) goto out; ret =3D dump_state_connections(fp); - if (ret) - goto out; - ret =3D dump_state_special_nodes(fp); if (ret) goto out; ret =3D dump_state_nodes(fp, ctx); diff --git a/tools/xenstore/xenstored_core.c b/tools/xenstore/xenstored_cor= e.c index 1650821922..fb4379e67c 100644 --- a/tools/xenstore/xenstored_core.c +++ b/tools/xenstore/xenstored_core.c @@ -611,12 +611,13 @@ static void get_acc_data(TDB_DATA *key, struct node_a= ccount_data *acc) * Per-transaction nodes need to be accounted for the transaction owner. * Those nodes are stored in the data base with the transaction generation * count prepended (e.g. 123/local/domain/...). So testing for the node's - * key not to start with "/" is sufficient. + * key not to start with "/" or "@" is sufficient. */ static unsigned int get_acc_domid(struct connection *conn, TDB_DATA *key, unsigned int domid) { - return (!conn || key->dptr[0] =3D=3D '/') ? domid : conn->id; + return (!conn || key->dptr[0] =3D=3D '/' || key->dptr[0] =3D=3D '@') + ? domid : conn->id; } =20 int do_tdb_write(struct connection *conn, TDB_DATA *key, TDB_DATA *data, @@ -958,10 +959,6 @@ static struct node *get_node(struct connection *conn, { struct node *node; =20 - if (!name || !is_valid_nodename(name)) { - errno =3D EINVAL; - return NULL; - } node =3D read_node(conn, ctx, name); /* If we don't have permission, we don't have node. */ if (node) { @@ -1250,9 +1247,23 @@ static struct node *get_node_canonicalized(struct co= nnection *conn, *canonical_name =3D canonicalize(conn, ctx, name); if (!*canonical_name) return NULL; + if (!is_valid_nodename(*canonical_name)) { + errno =3D EINVAL; + return NULL; + } return get_node(conn, ctx, *canonical_name, perm); } =20 +static struct node *get_spec_node(struct connection *conn, const void *ctx, + const char *name, char **canonical_name, + unsigned int perm) +{ + if (name[0] =3D=3D '@') + return get_node(conn, ctx, name, perm); + + return get_node_canonicalized(conn, ctx, name, canonical_name, perm); +} + static int send_directory(const void *ctx, struct connection *conn, struct buffered_data *in) { @@ -1737,8 +1748,7 @@ static int do_get_perms(const void *ctx, struct conne= ction *conn, char *strings; unsigned int len; =20 - node =3D get_node_canonicalized(conn, ctx, onearg(in), NULL, - XS_PERM_READ); + node =3D get_spec_node(conn, ctx, onearg(in), NULL, XS_PERM_READ); if (!node) return errno; =20 @@ -1780,17 +1790,9 @@ static int do_set_perms(const void *ctx, struct conn= ection *conn, if (perms.p[0].perms & XS_PERM_IGNORE) return ENOENT; =20 - /* First arg is node name. */ - if (strstarts(in->buffer, "@")) { - if (set_perms_special(conn, in->buffer, &perms)) - return errno; - send_ack(conn, XS_SET_PERMS); - return 0; - } - /* We must own node to do this (tools can do this too). */ - node =3D get_node_canonicalized(conn, ctx, in->buffer, &name, - XS_PERM_WRITE | XS_PERM_OWNER); + node =3D get_spec_node(conn, ctx, in->buffer, &name, + XS_PERM_WRITE | XS_PERM_OWNER); if (!node) return errno; =20 @@ -2388,7 +2390,9 @@ void setup_structure(bool live_update) manual_node("/", "tool"); manual_node("/tool", "xenstored"); manual_node("/tool/xenstored", NULL); - domain_entry_fix(dom0_domid, 3, true); + manual_node("@releaseDomain", NULL); + manual_node("@introduceDomain", NULL); + domain_entry_fix(dom0_domid, 5, true); } =20 check_store(); @@ -3170,6 +3174,23 @@ static int dump_state_node(const void *ctx, struct c= onnection *conn, return WALK_TREE_OK; } =20 +static int dump_state_special_node(FILE *fp, const void *ctx, + struct dump_node_data *data, + const char *name) +{ + struct node *node; + int ret; + + node =3D read_node(NULL, ctx, name); + if (!node) + return dump_state_node_err(data, "Dump node read node error"); + + ret =3D dump_state_node(ctx, NULL, node, data); + talloc_free(node); + + return ret; +} + const char *dump_state_nodes(FILE *fp, const void *ctx) { struct dump_node_data data =3D { @@ -3181,6 +3202,11 @@ const char *dump_state_nodes(FILE *fp, const void *c= tx) if (walk_node_tree(ctx, NULL, "/", &walkfuncs, &data)) return data.err; =20 + if (dump_state_special_node(fp, ctx, &data, "@releaseDomain")) + return data.err; + if (dump_state_special_node(fp, ctx, &data, "@introduceDomain")) + return data.err; + return NULL; } =20 @@ -3354,25 +3380,21 @@ void read_state_node(const void *ctx, const void *s= tate) node->perms.p[i].id =3D sn->perms[i].domid; } =20 - if (strstarts(name, "@")) { - set_perms_special(&conn, name, &node->perms); - talloc_free(node); - return; - } - - parentname =3D get_parent(node, name); - if (!parentname) - barf("allocation error restoring node"); - parent =3D read_node(NULL, node, parentname); - if (!parent) - barf("read parent error restoring node"); + if (!strstarts(name, "@")) { + parentname =3D get_parent(node, name); + if (!parentname) + barf("allocation error restoring node"); + parent =3D read_node(NULL, node, parentname); + if (!parent) + barf("read parent error restoring node"); =20 - if (add_child(node, parent, name)) - barf("allocation error restoring node"); + if (add_child(node, parent, name)) + barf("allocation error restoring node"); =20 - set_tdb_key(parentname, &key); - if (write_node_raw(NULL, &key, parent, true)) - barf("write parent error restoring node"); + set_tdb_key(parentname, &key); + if (write_node_raw(NULL, &key, parent, true)) + barf("write parent error restoring node"); + } =20 set_tdb_key(name, &key); if (write_node_raw(NULL, &key, node, true)) diff --git a/tools/xenstore/xenstored_domain.c b/tools/xenstore/xenstored_d= omain.c index 3ad1028edb..99f0afcb1f 100644 --- a/tools/xenstore/xenstored_domain.c +++ b/tools/xenstore/xenstored_domain.c @@ -43,9 +43,6 @@ static evtchn_port_t virq_port; =20 xenevtchn_handle *xce_handle =3D NULL; =20 -static struct node_perms dom_release_perms; -static struct node_perms dom_introduce_perms; - struct domain { /* The id of this domain */ @@ -225,27 +222,6 @@ static void unmap_interface(void *interface) xengnttab_unmap(*xgt_handle, interface, 1); } =20 -static void remove_domid_from_perm(struct node_perms *perms, - struct domain *domain) -{ - unsigned int cur, new; - - if (perms->p[0].id =3D=3D domain->domid) - perms->p[0].id =3D priv_domid; - - for (cur =3D new =3D 1; cur < perms->num; cur++) { - if (perms->p[cur].id =3D=3D domain->domid) - continue; - - if (new !=3D cur) - perms->p[new] =3D perms->p[cur]; - - new++; - } - - perms->num =3D new; -} - static int domain_tree_remove_sub(const void *ctx, struct connection *conn, struct node *node, void *arg) { @@ -297,8 +273,26 @@ static void domain_tree_remove(struct domain *domain) "error when looking for orphaned nodes\n"); } =20 - remove_domid_from_perm(&dom_release_perms, domain); - remove_domid_from_perm(&dom_introduce_perms, domain); + walk_node_tree(domain, NULL, "@releaseDomain", &walkfuncs, domain); + walk_node_tree(domain, NULL, "@introduceDomain", &walkfuncs, domain); +} + +static void fire_special_watches(const char *name) +{ + void *ctx =3D talloc_new(NULL); + struct node *node; + + if (!ctx) + return; + + node =3D read_node(NULL, ctx, name); + + if (node) + fire_watches(NULL, ctx, name, node, true, NULL); + else + syslog(LOG_ERR, "special node %s not found\n", name); + + talloc_free(ctx); } =20 static int destroy_domain(void *_domain) @@ -326,7 +320,7 @@ static int destroy_domain(void *_domain) unmap_interface(domain->interface); } =20 - fire_watches(NULL, domain, "@releaseDomain", NULL, true, NULL); + fire_special_watches("@releaseDomain"); =20 wrl_domain_destroy(domain); =20 @@ -384,7 +378,7 @@ void check_domains(void) ; =20 if (notify) - fire_watches(NULL, NULL, "@releaseDomain", NULL, true, NULL); + fire_special_watches("@releaseDomain"); } =20 /* We scan all domains rather than use the information given here. */ @@ -633,8 +627,7 @@ static struct domain *introduce_domain(const void *ctx, } =20 if (!is_master_domain && !restore) - fire_watches(NULL, ctx, "@introduceDomain", NULL, - true, NULL); + fire_special_watches("@introduceDomain"); } else { /* Use XS_INTRODUCE for recreating the xenbus event-channel. */ if (domain->port) @@ -840,59 +833,6 @@ const char *get_implicit_path(const struct connection = *conn) return conn->domain->path; } =20 -static int set_dom_perms_default(struct node_perms *perms) -{ - perms->num =3D 1; - perms->p =3D talloc_array(NULL, struct xs_permissions, perms->num); - if (!perms->p) - return -1; - perms->p->id =3D 0; - perms->p->perms =3D XS_PERM_NONE; - - return 0; -} - -static struct node_perms *get_perms_special(const char *name) -{ - if (!strcmp(name, "@releaseDomain")) - return &dom_release_perms; - if (!strcmp(name, "@introduceDomain")) - return &dom_introduce_perms; - return NULL; -} - -int set_perms_special(struct connection *conn, const char *name, - struct node_perms *perms) -{ - struct node_perms *p; - - p =3D get_perms_special(name); - if (!p) - return EINVAL; - - if ((perm_for_conn(conn, p) & (XS_PERM_WRITE | XS_PERM_OWNER)) !=3D - (XS_PERM_WRITE | XS_PERM_OWNER)) - return EACCES; - - p->num =3D perms->num; - talloc_free(p->p); - p->p =3D perms->p; - talloc_steal(NULL, perms->p); - - return 0; -} - -bool check_perms_special(const char *name, struct connection *conn) -{ - struct node_perms *p; - - p =3D get_perms_special(name); - if (!p) - return false; - - return perm_for_conn(conn, p) & XS_PERM_READ; -} - void dom0_init(void) { evtchn_port_t port; @@ -962,10 +902,6 @@ void domain_init(int evtfd) if (xce_handle =3D=3D NULL) barf_perror("Failed to open evtchn device"); =20 - if (set_dom_perms_default(&dom_release_perms) || - set_dom_perms_default(&dom_introduce_perms)) - barf_perror("Failed to set special permissions"); - if ((rc =3D xenevtchn_bind_virq(xce_handle, VIRQ_DOM_EXC)) =3D=3D -1) barf_perror("Failed to bind to domain exception virq port"); virq_port =3D rc; @@ -1535,60 +1471,6 @@ const char *dump_state_connections(FILE *fp) return ret; } =20 -static const char *dump_state_special_node(FILE *fp, const char *name, - const struct node_perms *perms) -{ - struct xs_state_record_header head; - struct xs_state_node sn; - unsigned int pathlen; - const char *ret; - - pathlen =3D strlen(name) + 1; - - head.type =3D XS_STATE_TYPE_NODE; - head.length =3D sizeof(sn); - - sn.conn_id =3D 0; - sn.ta_id =3D 0; - sn.ta_access =3D 0; - sn.perm_n =3D perms->num; - sn.path_len =3D pathlen; - sn.data_len =3D 0; - head.length +=3D perms->num * sizeof(*sn.perms); - head.length +=3D pathlen; - head.length =3D ROUNDUP(head.length, 3); - if (fwrite(&head, sizeof(head), 1, fp) !=3D 1) - return "Dump special node error"; - if (fwrite(&sn, sizeof(sn), 1, fp) !=3D 1) - return "Dump special node error"; - - ret =3D dump_state_node_perms(fp, perms->p, perms->num); - if (ret) - return ret; - - if (fwrite(name, pathlen, 1, fp) !=3D 1) - return "Dump special node path error"; - - ret =3D dump_state_align(fp); - - return ret; -} - -const char *dump_state_special_nodes(FILE *fp) -{ - const char *ret; - - ret =3D dump_state_special_node(fp, "@releaseDomain", - &dom_release_perms); - if (ret) - return ret; - - ret =3D dump_state_special_node(fp, "@introduceDomain", - &dom_introduce_perms); - - return ret; -} - void read_state_connection(const void *ctx, const void *state) { const struct xs_state_connection *sc =3D state; diff --git a/tools/xenstore/xenstored_domain.h b/tools/xenstore/xenstored_d= omain.h index b38c82991d..630641d620 100644 --- a/tools/xenstore/xenstored_domain.h +++ b/tools/xenstore/xenstored_domain.h @@ -99,11 +99,6 @@ void domain_outstanding_domid_dec(unsigned int domid); int domain_get_quota(const void *ctx, struct connection *conn, unsigned int domid); =20 -/* Special node permission handling. */ -int set_perms_special(struct connection *conn, const char *name, - struct node_perms *perms); -bool check_perms_special(const char *name, struct connection *conn); - /* Write rate limiting */ =20 #define WRL_FACTOR 1000 /* for fixed-point arithmetic */ @@ -132,7 +127,6 @@ void wrl_apply_debit_direct(struct connection *conn); void wrl_apply_debit_trans_commit(struct connection *conn); =20 const char *dump_state_connections(FILE *fp); -const char *dump_state_special_nodes(FILE *fp); =20 void read_state_connection(const void *ctx, const void *state); =20 diff --git a/tools/xenstore/xenstored_watch.c b/tools/xenstore/xenstored_wa= tch.c index 316c08b7f7..75748ac109 100644 --- a/tools/xenstore/xenstored_watch.c +++ b/tools/xenstore/xenstored_watch.c @@ -46,13 +46,6 @@ struct watch char *node; }; =20 -static bool check_special_event(const char *name) -{ - assert(name); - - return strstarts(name, "@"); -} - /* Is child a subnode of parent, or equal? */ static bool is_child(const char *child, const char *parent) { @@ -153,14 +146,8 @@ void fire_watches(struct connection *conn, const void = *ctx, const char *name, =20 /* Create an event for each watch. */ list_for_each_entry(i, &connections, list) { - /* introduce/release domain watches */ - if (check_special_event(name)) { - if (!check_perms_special(name, i)) - continue; - } else { - if (!watch_permitted(i, ctx, name, node, perms)) - continue; - } + if (!watch_permitted(i, ctx, name, node, perms)) + continue; =20 list_for_each_entry(watch, &i->watches, list) { if (exact) { --=20 2.35.3 From nobody Fri May 17 03:00:56 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=1673946742; cv=none; d=zohomail.com; s=zohoarc; b=ZaPx+f/kjumtE9Bjw+vNQ/P/93NaMC0PcGXxnDKBAUxfNwuw5RBXsGvLAjq3QAHqVIhhmBQsq/dzU7zCjvsx1V1BNWq8fasd10qlXkjwP+aFYXBLXFW18F1dPD4Q/fJIJTjCWwsyz4PjljKZs6eUlzTxjhH/i3PKnyti058Q6Vw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1673946742; 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=yeWrscM88Vhy837N0J0RMcSEc0fQ7a4WxiqHlihRSgA=; b=XPklExd3qyHkeZCjomiT/uyfeX0Vk48VJR1u3X9NKKujLsVCeVWiKvStD2iDdbaYjez+f8asBQGqsPeoQnwQH5TEtQQJ9GL79HfwHMv25RchZRrPz5DE/u2y4flh2nZStqzkxLQN5lkeR6k+OqWhSEHaCbmQLYFX/tLPXfZklvg= 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 1673946742047871.8815271944918; Tue, 17 Jan 2023 01:12:22 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.479137.742808 (Exim 4.92) (envelope-from ) id 1pHi0c-0000aU-R3; Tue, 17 Jan 2023 09:11:58 +0000 Received: by outflank-mailman (output) from mailman id 479137.742808; Tue, 17 Jan 2023 09:11: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 1pHi0c-0000aK-NF; Tue, 17 Jan 2023 09:11:58 +0000 Received: by outflank-mailman (input) for mailman id 479137; Tue, 17 Jan 2023 09:11: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 1pHi0b-0007bs-O2 for xen-devel@lists.xenproject.org; Tue, 17 Jan 2023 09:11:57 +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 fcb3ffbe-9646-11ed-b8d0-410ff93cb8f0; Tue, 17 Jan 2023 10:11:55 +0100 (CET) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id DD6F3683DC; Tue, 17 Jan 2023 09:11:54 +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 B41E51390C; Tue, 17 Jan 2023 09:11:54 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id Du3CKlpmxmMVcAAAMHmgww (envelope-from ); Tue, 17 Jan 2023 09:11:54 +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: fcb3ffbe-9646-11ed-b8d0-410ff93cb8f0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1673946714; 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=yeWrscM88Vhy837N0J0RMcSEc0fQ7a4WxiqHlihRSgA=; b=exL1qlG/Vi6ciQUENU9ah6Tn7u9wBJfIjoGYMw9QdwkIc5+1+j6L/SfH9/cv3ZEZ2KIuEF +M7TuON7BgbHh1KSbtLE2wH3bGEOSOpN6K5XaHeYnB1rq8cbuyucJqYK2XnP86XU+jHlpd GQbzaDgaWLMskBTpvXlQQKpDBIo/v5s= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Julien Grall , Anthony PERARD Subject: [PATCH v3 05/17] tools/xenstore: replace watch->relative_path with a prefix length Date: Tue, 17 Jan 2023 10:11:12 +0100 Message-Id: <20230117091124.22170-6-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230117091124.22170-1-jgross@suse.com> References: <20230117091124.22170-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1673946743704100001 Content-Type: text/plain; charset="utf-8" Instead of storing a pointer to the path which is prepended to relative paths in struct watch, just use the length of the prepended path. It should be noted that the now removed special case of the relative path being "" in get_watch_path() can't happen at all. Signed-off-by: Juergen Gross Reviewed-by: Julien Grall --- V2: - don't open code get_watch_path() (Julien Grall) V3: - drop needless modification of dump_state_watches() (Julien Grall) --- tools/xenstore/xenstored_watch.c | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/tools/xenstore/xenstored_watch.c b/tools/xenstore/xenstored_wa= tch.c index 75748ac109..8ad0229df6 100644 --- a/tools/xenstore/xenstored_watch.c +++ b/tools/xenstore/xenstored_watch.c @@ -39,8 +39,8 @@ struct watch /* Current outstanding events applying to this watch. */ struct list_head events; =20 - /* Is this relative to connnection's implicit path? */ - const char *relative_path; + /* Offset into path for skipping prefix (used for relative paths). */ + unsigned int prefix_len; =20 char *token; char *node; @@ -66,15 +66,7 @@ static bool is_child(const char *child, const char *pare= nt) =20 static const char *get_watch_path(const struct watch *watch, const char *n= ame) { - const char *path =3D name; - - if (watch->relative_path) { - path +=3D strlen(watch->relative_path); - if (*path =3D=3D '/') /* Could be "" */ - path++; - } - - return path; + return name + watch->prefix_len; } =20 /* @@ -211,10 +203,7 @@ static struct watch *add_watch(struct connection *conn= , char *path, char *token, no_quota_check)) goto nomem; =20 - if (relative) - watch->relative_path =3D get_implicit_path(conn); - else - watch->relative_path =3D NULL; + watch->prefix_len =3D relative ? strlen(get_implicit_path(conn)) + 1 : 0; =20 INIT_LIST_HEAD(&watch->events); =20 --=20 2.35.3 From nobody Fri May 17 03:00:56 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=1673946745; cv=none; d=zohomail.com; s=zohoarc; b=WkdIfOf8hxk4QuU4ySt67L7j7fQTKKwNlYNhs2S8gA5k+MXXkFqpU4PX1MawEeSIRlX7WfBfdX8ArCfYoZ5N1lAsmnCqh/vLcrd1QyVoiC3fZfA8Y8H613mHvtP3+RtNVmKaAGtGcue5M5WwQhVqTfnhMd10yHBF7VTeWcQNxus= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1673946745; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=WUUgoNnUcKdU+i5lp6nHtOPfrpUDA9Id/qGOmHDQ6xg=; b=aY10uXdSO4SKDP18I0cXhC4gQt0rjLo2aISD/2RQE3HG2gprqgxzb0FqIw7lfPBszlLjQzjdeMSQLrDdjXAbN/O+1vknI6Dfp7xnii/ieNxDnoyugxR9WbgjIaQQdvTCdY35oGi08FJARsg4j0D5zH0n9MzR/vOW/N7biux/EpM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1673946745442784.3916352799811; Tue, 17 Jan 2023 01:12:25 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.479139.742819 (Exim 4.92) (envelope-from ) id 1pHi0h-000139-4c; Tue, 17 Jan 2023 09:12:03 +0000 Received: by outflank-mailman (output) from mailman id 479139.742819; Tue, 17 Jan 2023 09:12:03 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pHi0h-00012p-10; Tue, 17 Jan 2023 09:12:03 +0000 Received: by outflank-mailman (input) for mailman id 479139; Tue, 17 Jan 2023 09:12:02 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pHi0f-000725-Si for xen-devel@lists.xenproject.org; Tue, 17 Jan 2023 09:12:02 +0000 Received: from smtp-out1.suse.de (smtp-out1.suse.de [2001:67c:2178:6::1c]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 00088804-9647-11ed-91b6-6bf2151ebd3b; Tue, 17 Jan 2023 10:12:00 +0100 (CET) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 794743821D; Tue, 17 Jan 2023 09:12:00 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 4CE701390C; Tue, 17 Jan 2023 09:12:00 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id E285EWBmxmMgcAAAMHmgww (envelope-from ); Tue, 17 Jan 2023 09:12:00 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 00088804-9647-11ed-91b6-6bf2151ebd3b DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1673946720; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=WUUgoNnUcKdU+i5lp6nHtOPfrpUDA9Id/qGOmHDQ6xg=; b=bdNDsjhoni8zdIgcTpxGj63EYKHYy7l21RJT/4G+/f0ua8Tqp7sZIjk7Cd04SoqY56KTQA IdMXqZOZ//rB4H1kVe5mJKYZrJI3/v/cVyviW9UYPEsrXc8PFQ08yFUDhW2fRQLm35EmTd E61Gc4ALypqcBOIeLj/y3ZiOVxlfKuY= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Julien Grall , Anthony PERARD Subject: [PATCH v3 06/17] tools/xenstore: move changed domain handling Date: Tue, 17 Jan 2023 10:11:13 +0100 Message-Id: <20230117091124.22170-7-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230117091124.22170-1-jgross@suse.com> References: <20230117091124.22170-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1673946745775100003 Content-Type: text/plain; charset="utf-8" Move all code related to struct changed_domain from xenstored_transaction.c to xenstored_domain.c. This will be needed later in order to simplify the accounting data updates in cases of errors during a request. Split the code to have a more generic base framework. Signed-off-by: Juergen Gross Reviewed-by: Julien Grall --- V2: - remove unrelated change (Julien Grall) V3: - modify acc_add_dom_nbentry() interface (Julien Grall) --- tools/xenstore/xenstored_domain.c | 78 ++++++++++++++++++++++++++ tools/xenstore/xenstored_domain.h | 3 + tools/xenstore/xenstored_transaction.c | 64 ++------------------- 3 files changed, 85 insertions(+), 60 deletions(-) diff --git a/tools/xenstore/xenstored_domain.c b/tools/xenstore/xenstored_d= omain.c index 99f0afcb1f..3a2ab5d87e 100644 --- a/tools/xenstore/xenstored_domain.c +++ b/tools/xenstore/xenstored_domain.c @@ -91,6 +91,18 @@ struct domain bool wrl_delay_logged; }; =20 +struct changed_domain +{ + /* List of all changed domains. */ + struct list_head list; + + /* Identifier of the changed domain. */ + unsigned int domid; + + /* Amount by which this domain's nbentry field has changed. */ + int nbentry; +}; + static struct hashtable *domhash; =20 static bool check_indexes(XENSTORE_RING_IDX cons, XENSTORE_RING_IDX prod) @@ -543,6 +555,72 @@ static struct domain *find_domain_by_domid(unsigned in= t domid) return (d && d->introduced) ? d : NULL; } =20 +int acc_fix_domains(struct list_head *head, bool update) +{ + struct changed_domain *cd; + int cnt; + + list_for_each_entry(cd, head, list) { + cnt =3D domain_entry_fix(cd->domid, cd->nbentry, update); + if (!update) { + if (cnt >=3D quota_nb_entry_per_domain) + return ENOSPC; + if (cnt < 0) + return ENOMEM; + } + } + + return 0; +} + +static struct changed_domain *acc_find_changed_domain(struct list_head *he= ad, + unsigned int domid) +{ + struct changed_domain *cd; + + list_for_each_entry(cd, head, list) { + if (cd->domid =3D=3D domid) + return cd; + } + + return NULL; +} + +static struct changed_domain *acc_get_changed_domain(const void *ctx, + struct list_head *head, + unsigned int domid) +{ + struct changed_domain *cd; + + cd =3D acc_find_changed_domain(head, domid); + if (cd) + return cd; + + cd =3D talloc_zero(ctx, struct changed_domain); + if (!cd) + return NULL; + + cd->domid =3D domid; + list_add_tail(&cd->list, head); + + return cd; +} + +int acc_add_dom_nbentry(const void *ctx, struct list_head *head, int val, + unsigned int domid) +{ + struct changed_domain *cd; + + cd =3D acc_get_changed_domain(ctx, head, domid); + if (!cd) + return 0; + + errno =3D 0; + cd->nbentry +=3D val; + + return cd->nbentry; +} + static void domain_conn_reset(struct domain *domain) { struct connection *conn =3D domain->conn; diff --git a/tools/xenstore/xenstored_domain.h b/tools/xenstore/xenstored_d= omain.h index 630641d620..9e20d2b17d 100644 --- a/tools/xenstore/xenstored_domain.h +++ b/tools/xenstore/xenstored_domain.h @@ -98,6 +98,9 @@ void domain_outstanding_dec(struct connection *conn); void domain_outstanding_domid_dec(unsigned int domid); int domain_get_quota(const void *ctx, struct connection *conn, unsigned int domid); +int acc_fix_domains(struct list_head *head, bool update); +int acc_add_dom_nbentry(const void *ctx, struct list_head *head, int val, + unsigned int domid); =20 /* Write rate limiting */ =20 diff --git a/tools/xenstore/xenstored_transaction.c b/tools/xenstore/xensto= red_transaction.c index ac854197ca..c009c67989 100644 --- a/tools/xenstore/xenstored_transaction.c +++ b/tools/xenstore/xenstored_transaction.c @@ -137,18 +137,6 @@ struct accessed_node bool watch_exact; }; =20 -struct changed_domain -{ - /* List of all changed domains in the context of this transaction. */ - struct list_head list; - - /* Identifier of the changed domain. */ - unsigned int domid; - - /* Amount by which this domain's nbentry field has changed. */ - int nbentry; -}; - struct transaction { /* List of all transactions active on this connection. */ @@ -514,24 +502,6 @@ int do_transaction_start(const void *ctx, struct conne= ction *conn, return 0; } =20 -static int transaction_fix_domains(struct transaction *trans, bool update) -{ - struct changed_domain *d; - int cnt; - - list_for_each_entry(d, &trans->changed_domains, list) { - cnt =3D domain_entry_fix(d->domid, d->nbentry, update); - if (!update) { - if (cnt >=3D quota_nb_entry_per_domain) - return ENOSPC; - if (cnt < 0) - return ENOMEM; - } - } - - return 0; -} - int do_transaction_end(const void *ctx, struct connection *conn, struct buffered_data *in) { @@ -558,7 +528,7 @@ int do_transaction_end(const void *ctx, struct connecti= on *conn, if (streq(arg, "T")) { if (trans->fail) return ENOMEM; - ret =3D transaction_fix_domains(trans, false); + ret =3D acc_fix_domains(&trans->changed_domains, false); if (ret) return ret; ret =3D finalize_transaction(conn, trans, &is_corrupt); @@ -568,7 +538,7 @@ int do_transaction_end(const void *ctx, struct connecti= on *conn, wrl_apply_debit_trans_commit(conn); =20 /* fix domain entry for each changed domain */ - transaction_fix_domains(trans, true); + acc_fix_domains(&trans->changed_domains, true); =20 if (is_corrupt) corrupt(conn, "transaction inconsistency"); @@ -580,44 +550,18 @@ int do_transaction_end(const void *ctx, struct connec= tion *conn, =20 void transaction_entry_inc(struct transaction *trans, unsigned int domid) { - struct changed_domain *d; - - list_for_each_entry(d, &trans->changed_domains, list) - if (d->domid =3D=3D domid) { - d->nbentry++; - return; - } - - d =3D talloc(trans, struct changed_domain); - if (!d) { + if (!acc_add_dom_nbentry(trans, &trans->changed_domains, 1, domid)) { /* Let the transaction fail. */ trans->fail =3D true; - return; } - d->domid =3D domid; - d->nbentry =3D 1; - list_add_tail(&d->list, &trans->changed_domains); } =20 void transaction_entry_dec(struct transaction *trans, unsigned int domid) { - struct changed_domain *d; - - list_for_each_entry(d, &trans->changed_domains, list) - if (d->domid =3D=3D domid) { - d->nbentry--; - return; - } - - d =3D talloc(trans, struct changed_domain); - if (!d) { + if (!acc_add_dom_nbentry(trans, &trans->changed_domains, -1, domid)) { /* Let the transaction fail. */ trans->fail =3D true; - return; } - d->domid =3D domid; - d->nbentry =3D -1; - list_add_tail(&d->list, &trans->changed_domains); } =20 void fail_transaction(struct transaction *trans) --=20 2.35.3 From nobody Fri May 17 03:00:56 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=1673946750; cv=none; d=zohomail.com; s=zohoarc; b=k8kJOZhn8FaoLVF2C1W4+RItqh8Vx6ylc7tiE+kY8MV9h3Ta75jI4X1zcmuY9pRCKKe8QGk8++dzakc73PVo6iqkzGaPk86XMN53rReRCseKbfPVZ0P8W72xY9GYcCJDHy8wIx4qP98oOGy98tDTMUbl1oY7oFMZq1pqYJWTyuw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1673946750; 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=mfRRwxo4vvhdUuVMMBFhh02P5cIV8rdGRXpO+cxP6K8=; b=GQCLXvI8XI2wLAXftensUuA6TcMdGSYnKN1vBYtEc/jQfmkVfMVbEpwWVNuPuk+FAANkNg7vYhvbpfSds6eTApvvvg5uaWXW3masMYstHY52t/5X5ZnxmyIkG/6g/Boq8OyWWXPWgI5s3HMluIvYaxGamj2m4Pc2QbED17EXtdA= 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 1673946750858979.1498268543629; Tue, 17 Jan 2023 01:12:30 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.479148.742830 (Exim 4.92) (envelope-from ) id 1pHi0o-0001dq-CJ; Tue, 17 Jan 2023 09:12:10 +0000 Received: by outflank-mailman (output) from mailman id 479148.742830; Tue, 17 Jan 2023 09:12:10 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pHi0o-0001dd-9E; Tue, 17 Jan 2023 09:12:10 +0000 Received: by outflank-mailman (input) for mailman id 479148; Tue, 17 Jan 2023 09:12:08 +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 1pHi0m-0007bs-Rn for xen-devel@lists.xenproject.org; Tue, 17 Jan 2023 09:12:08 +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 0361ee14-9647-11ed-b8d0-410ff93cb8f0; Tue, 17 Jan 2023 10:12:06 +0100 (CET) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 1A2C6683D9; Tue, 17 Jan 2023 09:12:06 +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 DDD041390C; Tue, 17 Jan 2023 09:12:05 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id wxzXNGVmxmM1cAAAMHmgww (envelope-from ); Tue, 17 Jan 2023 09:12:05 +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: 0361ee14-9647-11ed-b8d0-410ff93cb8f0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1673946726; 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=mfRRwxo4vvhdUuVMMBFhh02P5cIV8rdGRXpO+cxP6K8=; b=ohgAaZeOSqPTPI1fLeNEHrMNpW+1xbO5vEcwt+6PNN6Qq42ZuN9+e5rp3kFdgqWbLSbEgW /kbrHxKhgPB4FMdSglTReJM6BEkAFISZ0YrlUj87y9QoMgOM3OXAZlUJNC/TNb7UEb0kMI 2OnxGeU95KSZtfhvR6NygCls3ksHYIQ= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Julien Grall , Anthony PERARD Subject: [PATCH v3 07/17] tools/xenstore: change per-domain node accounting interface Date: Tue, 17 Jan 2023 10:11:14 +0100 Message-Id: <20230117091124.22170-8-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230117091124.22170-1-jgross@suse.com> References: <20230117091124.22170-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1673946751790100001 Content-Type: text/plain; charset="utf-8" Rework the interface and the internals of the per-domain node accounting: - rename the functions to domain_nbentry_*() in order to better match the related counter name - switch from node pointer to domid as interface, as all nodes have the owner filled in - use a common internal function for adding a value to the counter For the transaction case add a helper function to get the list head of the per-transaction changed domains, enabling to eliminate the transaction_entry_*() functions. Signed-off-by: Juergen Gross --- V3: - add get_node_owner() (Julien Grall) - rename domain_nbentry_add() parameter (Julien Grall) - avoid negative entry count (Julien Grall) --- tools/xenstore/xenstored_core.c | 33 ++++--- tools/xenstore/xenstored_domain.c | 126 ++++++++++++------------- tools/xenstore/xenstored_domain.h | 10 +- tools/xenstore/xenstored_transaction.c | 15 +-- tools/xenstore/xenstored_transaction.h | 7 +- 5 files changed, 86 insertions(+), 105 deletions(-) diff --git a/tools/xenstore/xenstored_core.c b/tools/xenstore/xenstored_cor= e.c index fb4379e67c..561fb121d3 100644 --- a/tools/xenstore/xenstored_core.c +++ b/tools/xenstore/xenstored_core.c @@ -700,6 +700,11 @@ int do_tdb_delete(struct connection *conn, TDB_DATA *k= ey, return 0; } =20 +static unsigned int get_node_owner(const struct node *node) +{ + return node->perms.p[0].id; +} + /* * If it fails, returns NULL and sets errno. * Temporary memory allocations will be done with ctx. @@ -752,13 +757,13 @@ struct node *read_node(struct connection *conn, const= void *ctx, =20 /* Permissions are struct xs_permissions. */ node->perms.p =3D hdr->perms; - node->acc.domid =3D node->perms.p[0].id; + node->acc.domid =3D get_node_owner(node); node->acc.memory =3D data.dsize; if (domain_adjust_node_perms(node)) goto error; =20 /* If owner is gone reset currently accounted memory size. */ - if (node->acc.domid !=3D node->perms.p[0].id) + if (node->acc.domid !=3D get_node_owner(node)) node->acc.memory =3D 0; =20 /* Data is binary blob (usually ascii, no nul). */ @@ -1459,7 +1464,7 @@ 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_entry_dec(conn, node); + domain_nbentry_dec(conn, get_node_owner(node)); =20 /* * It is not possible to easily revert the changes in a transaction. @@ -1498,7 +1503,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_entry(conn) >=3D quota_nb_entry_per_domain) { + domain_nbentry(conn) >=3D quota_nb_entry_per_domain) { ret =3D ENOSPC; goto err; } @@ -1509,7 +1514,7 @@ static struct node *create_node(struct connection *co= nn, const void *ctx, =20 /* Account for new node */ if (i->parent) { - if (domain_entry_inc(conn, i)) { + if (domain_nbentry_inc(conn, get_node_owner(i))) { destroy_node_rm(conn, i); return NULL; } @@ -1662,7 +1667,7 @@ static int delnode_sub(const void *ctx, struct connec= tion *conn, watch_exact =3D strcmp(root, node->name); fire_watches(conn, ctx, node->name, node, watch_exact, NULL); =20 - domain_entry_dec(conn, node); + domain_nbentry_dec(conn, get_node_owner(node)); =20 return WALK_TREE_RM_CHILDENTRY; } @@ -1798,29 +1803,29 @@ static int do_set_perms(const void *ctx, struct con= nection *conn, =20 /* Unprivileged domains may not change the owner. */ if (domain_is_unprivileged(conn) && - perms.p[0].id !=3D node->perms.p[0].id) + perms.p[0].id !=3D get_node_owner(node)) return EPERM; =20 old_perms =3D node->perms; - domain_entry_dec(conn, node); + domain_nbentry_dec(conn, get_node_owner(node)); node->perms =3D perms; - if (domain_entry_inc(conn, node)) { + 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_entry_inc(conn, node); + domain_nbentry_inc(conn, get_node_owner(node)); return ENOMEM; } =20 if (write_node(conn, node, false)) { int saved_errno =3D errno; =20 - domain_entry_dec(conn, node); + domain_nbentry_dec(conn, get_node_owner(node)); node->perms =3D old_perms; /* No failure possible as above. */ - domain_entry_inc(conn, node); + domain_nbentry_inc(conn, get_node_owner(node)); =20 errno =3D saved_errno; return errno; @@ -2392,7 +2397,7 @@ void setup_structure(bool live_update) manual_node("/tool/xenstored", NULL); manual_node("@releaseDomain", NULL); manual_node("@introduceDomain", NULL); - domain_entry_fix(dom0_domid, 5, true); + domain_nbentry_fix(dom0_domid, 5, true); } =20 check_store(); @@ -3400,7 +3405,7 @@ void read_state_node(const void *ctx, const void *sta= te) if (write_node_raw(NULL, &key, node, true)) barf("write node error restoring node"); =20 - if (domain_entry_inc(&conn, node)) + if (domain_nbentry_inc(&conn, get_node_owner(node))) barf("node accounting error restoring node"); =20 talloc_free(node); diff --git a/tools/xenstore/xenstored_domain.c b/tools/xenstore/xenstored_d= omain.c index 3a2ab5d87e..edfe5809be 100644 --- a/tools/xenstore/xenstored_domain.c +++ b/tools/xenstore/xenstored_domain.c @@ -249,7 +249,7 @@ static int domain_tree_remove_sub(const void *ctx, stru= ct connection *conn, domain->nbentry--; node->perms.p[0].id =3D priv_domid; node->acc.memory =3D 0; - domain_entry_inc(NULL, node); + domain_nbentry_inc(NULL, priv_domid); if (write_node_raw(NULL, &key, node, true)) { /* That's unfortunate. We only can try to continue. */ syslog(LOG_ERR, @@ -561,7 +561,7 @@ int acc_fix_domains(struct list_head *head, bool update) int cnt; =20 list_for_each_entry(cd, head, list) { - cnt =3D domain_entry_fix(cd->domid, cd->nbentry, update); + cnt =3D domain_nbentry_fix(cd->domid, cd->nbentry, update); if (!update) { if (cnt >=3D quota_nb_entry_per_domain) return ENOSPC; @@ -606,8 +606,8 @@ static struct changed_domain *acc_get_changed_domain(co= nst void *ctx, return cd; } =20 -int acc_add_dom_nbentry(const void *ctx, struct list_head *head, int val, - unsigned int domid) +static int acc_add_dom_nbentry(const void *ctx, struct list_head *head, in= t val, + unsigned int domid) { struct changed_domain *cd; =20 @@ -991,30 +991,6 @@ void domain_deinit(void) xenevtchn_unbind(xce_handle, virq_port); } =20 -int domain_entry_inc(struct connection *conn, struct node *node) -{ - struct domain *d; - unsigned int domid; - - if (!node->perms.p) - return 0; - - domid =3D node->perms.p[0].id; - - if (conn && conn->transaction) { - transaction_entry_inc(conn->transaction, domid); - } else { - d =3D (conn && domid =3D=3D conn->id && conn->domain) ? conn->domain - : find_or_alloc_existing_domain(domid); - if (d) - d->nbentry++; - else - return ENOMEM; - } - - return 0; -} - /* * Check whether a domain was created before or after a specific generation * count (used for testing whether a node permission is older than a domai= n). @@ -1082,62 +1058,76 @@ int domain_adjust_node_perms(struct node *node) return 0; } =20 -void domain_entry_dec(struct connection *conn, struct node *node) +static int domain_nbentry_add(struct connection *conn, unsigned int domid, + int add, bool no_dom_alloc) { struct domain *d; - unsigned int domid; - - if (!node->perms.p) - return; + struct list_head *head; + int ret; =20 - domid =3D node->perms.p ? node->perms.p[0].id : conn->id; + if (conn && domid =3D=3D conn->id && conn->domain) + d =3D conn->domain; + else if (no_dom_alloc) { + d =3D find_domain_struct(domid); + if (!d) { + errno =3D ENOENT; + corrupt(conn, "Missing domain %u\n", domid); + return -1; + } + } else { + d =3D find_or_alloc_existing_domain(domid); + if (!d) { + errno =3D ENOMEM; + return -1; + } + } =20 if (conn && conn->transaction) { - transaction_entry_dec(conn->transaction, domid); - } else { - d =3D (conn && domid =3D=3D conn->id && conn->domain) ? conn->domain - : find_domain_struct(domid); - if (d) { - d->nbentry--; - } else { - errno =3D ENOENT; - corrupt(conn, - "Node \"%s\" owned by non-existing domain %u\n", - node->name, domid); + head =3D transaction_get_changed_domains(conn->transaction); + ret =3D acc_add_dom_nbentry(conn->transaction, head, 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); } + + d->nbentry +=3D add; + + return d->nbentry; } =20 -int domain_entry_fix(unsigned int domid, int num, bool update) +int domain_nbentry_inc(struct connection *conn, unsigned int domid) { - struct domain *d; - int cnt; + return (domain_nbentry_add(conn, domid, 1, false) < 0) ? errno : 0; +} =20 - if (update) { - d =3D find_domain_struct(domid); - assert(d); - } else { - /* - * We are called first with update =3D=3D false in order to catch - * any error. So do a possible allocation and check for error - * only in this case, as in the case of update =3D=3D true nothing - * can go wrong anymore as the allocation already happened. - */ - d =3D find_or_alloc_existing_domain(domid); - if (!d) - return -1; - } +int domain_nbentry_dec(struct connection *conn, unsigned int domid) +{ + return (domain_nbentry_add(conn, domid, -1, true) < 0) ? errno : 0; +} =20 - cnt =3D d->nbentry + num; - assert(cnt >=3D 0); +int domain_nbentry_fix(unsigned int domid, int num, bool update) +{ + int ret; =20 - if (update) - d->nbentry =3D cnt; + ret =3D domain_nbentry_add(NULL, domid, update ? num : 0, update); + if (ret < 0 || update) + return ret; =20 - return domid_is_unprivileged(domid) ? cnt : 0; + return domid_is_unprivileged(domid) ? ret + num : 0; } =20 -int domain_entry(struct connection *conn) +int domain_nbentry(struct connection *conn) { return (domain_is_unprivileged(conn)) ? conn->domain->nbentry diff --git a/tools/xenstore/xenstored_domain.h b/tools/xenstore/xenstored_d= omain.h index 9e20d2b17d..1e402f2609 100644 --- a/tools/xenstore/xenstored_domain.h +++ b/tools/xenstore/xenstored_domain.h @@ -66,10 +66,10 @@ int domain_adjust_node_perms(struct node *node); int domain_alloc_permrefs(struct node_perms *perms); =20 /* Quota manipulation */ -int domain_entry_inc(struct connection *conn, struct node *); -void domain_entry_dec(struct connection *conn, struct node *); -int domain_entry_fix(unsigned int domid, int num, bool update); -int domain_entry(struct connection *conn); +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); int domain_memory_add(unsigned int domid, int mem, bool no_quota_check); =20 /* @@ -99,8 +99,6 @@ void domain_outstanding_domid_dec(unsigned int domid); int domain_get_quota(const void *ctx, struct connection *conn, unsigned int domid); int acc_fix_domains(struct list_head *head, bool update); -int acc_add_dom_nbentry(const void *ctx, struct list_head *head, int val, - unsigned int domid); =20 /* Write rate limiting */ =20 diff --git a/tools/xenstore/xenstored_transaction.c b/tools/xenstore/xensto= red_transaction.c index c009c67989..82e5e66c18 100644 --- a/tools/xenstore/xenstored_transaction.c +++ b/tools/xenstore/xenstored_transaction.c @@ -548,20 +548,9 @@ int do_transaction_end(const void *ctx, struct connect= ion *conn, return 0; } =20 -void transaction_entry_inc(struct transaction *trans, unsigned int domid) +struct list_head *transaction_get_changed_domains(struct transaction *tran= s) { - if (!acc_add_dom_nbentry(trans, &trans->changed_domains, 1, domid)) { - /* Let the transaction fail. */ - trans->fail =3D true; - } -} - -void transaction_entry_dec(struct transaction *trans, unsigned int domid) -{ - if (!acc_add_dom_nbentry(trans, &trans->changed_domains, -1, domid)) { - /* Let the transaction fail. */ - trans->fail =3D true; - } + return &trans->changed_domains; } =20 void fail_transaction(struct transaction *trans) diff --git a/tools/xenstore/xenstored_transaction.h b/tools/xenstore/xensto= red_transaction.h index 3417303f94..b6f8cb7d0a 100644 --- a/tools/xenstore/xenstored_transaction.h +++ b/tools/xenstore/xenstored_transaction.h @@ -36,10 +36,6 @@ int do_transaction_end(const void *ctx, struct connectio= n *conn, =20 struct transaction *transaction_lookup(struct connection *conn, uint32_t i= d); =20 -/* inc/dec entry number local to trans while changing a node */ -void transaction_entry_inc(struct transaction *trans, unsigned int domid); -void transaction_entry_dec(struct transaction *trans, unsigned int domid); - /* This node was accessed. */ int __must_check access_node(struct connection *conn, struct node *node, enum node_access_type type, TDB_DATA *key); @@ -54,6 +50,9 @@ void transaction_prepend(struct connection *conn, const c= har *name, /* Mark the transaction as failed. This will prevent it to be committed. */ void fail_transaction(struct transaction *trans); =20 +/* Get the list head of the changed domains. */ +struct list_head *transaction_get_changed_domains(struct transaction *tran= s); + void conn_delete_all_transactions(struct connection *conn); int check_transactions(struct hashtable *hash); =20 --=20 2.35.3 From nobody Fri May 17 03:00:56 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=1673946936; cv=none; d=zohomail.com; s=zohoarc; b=DabFJtkJniEjHqCIqSQWOEWmCFx3cDsJMA+RbjnGL69Fta8Dfu7fzm8XJO/3vk8gnwWD0cEku/CMnl+hxn57j9/D3fwotdjceqeewzqSwLKk2x+BGl3IS3fwosP5YfY3iiUNh/lo621zbN0QRLM9D3aifXLvjiZSUcUciC7VRao= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1673946936; 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=alJygBFItsbWNBsKn2icTcjkRMNZAqhlfawwKm82T34=; b=S4mX3MiuvYsGbhimzaItObh/t9PKwzJsPAQZF5e6eDl8ami1exJ3NdGdFzTtLACcrLINz8JGiNPS1d00sHDyzgpRiNZFeVP+g6XTVCjrrpxd+R2j6isFuDM9sNWPHXjZKMxDt9arRDXJ+4VZnIqpy6QdWemJTCvv0VCSKuN5QQg= 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 1673946936580611.6092112914765; Tue, 17 Jan 2023 01:15:36 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.479195.742925 (Exim 4.92) (envelope-from ) id 1pHi3r-0005hN-Qx; Tue, 17 Jan 2023 09:15:19 +0000 Received: by outflank-mailman (output) from mailman id 479195.742925; Tue, 17 Jan 2023 09:15:19 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pHi3r-0005f4-HT; Tue, 17 Jan 2023 09:15:19 +0000 Received: by outflank-mailman (input) for mailman id 479195; Tue, 17 Jan 2023 09:15:17 +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 1pHi0s-0007bs-J3 for xen-devel@lists.xenproject.org; Tue, 17 Jan 2023 09:12:14 +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 06b4961d-9647-11ed-b8d0-410ff93cb8f0; Tue, 17 Jan 2023 10:12:11 +0100 (CET) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id A7F2B683D9; Tue, 17 Jan 2023 09:12:11 +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 7C4081390C; Tue, 17 Jan 2023 09:12:11 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id oiToHGtmxmM/cAAAMHmgww (envelope-from ); Tue, 17 Jan 2023 09:12:11 +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: 06b4961d-9647-11ed-b8d0-410ff93cb8f0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1673946731; 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=alJygBFItsbWNBsKn2icTcjkRMNZAqhlfawwKm82T34=; b=AccrtO3n03yFK+2uwjGahhIx0dLfSoO0c9GuG+PHyJ5ELSWcFm2Z05NOANvxFYQYEi0E9X F71imvHtPPvqBI5/2ElZ8Hp2LT5r+U9zljOfppd2Dk8Ybip0oy420zyvcowVXlx699Xo5X Ddyho+a9uwMTUYY79j5F3HVi0ltUBPw= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Julien Grall , Anthony PERARD Subject: [PATCH v3 08/17] tools/xenstore: don't allow creating too many nodes in a transaction Date: Tue, 17 Jan 2023 10:11:15 +0100 Message-Id: <20230117091124.22170-9-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230117091124.22170-1-jgross@suse.com> References: <20230117091124.22170-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1673946938631100001 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 allows to create arbitrary number of nodes. The transaction will finally fail due to exceeding the number of nodes quota, but before closing the transaction an unprivileged guest could cause Xenstore to use a lot of memory. Signed-off-by: Juergen Gross --- 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 edfe5809be..07d91eb50c 100644 --- a/tools/xenstore/xenstored_domain.c +++ b/tools/xenstore/xenstored_domain.c @@ -1129,9 +1129,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 Fri May 17 03:00:56 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=1673946928; cv=none; d=zohomail.com; s=zohoarc; b=G2jCbEgZjZVi03kGAApJ8TM0c8uY0ndkrOZRmIt5sQqAs195lH4WQbiJJxRUwSiKQ3MrMr4IU26wkJFgq+xfDiOs4lo/mOivqnRw77ntfRUKODNrIKPX+cdV3iNGvi32rw+zN32UNVmlXzGxn9B8vPIwjrGZGkzZ4sQi9q684lQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1673946928; 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=HhYKz+Oi7NXGdn9eIooP5S2YyA3D/bV21hS8CpK2wqk=; b=R4tmr5tjs/5lvKVZB199O1/3Ocl0HyDMCGPeiSAJQGcIYQ6Z+rIk5iEDDSSZj4gLciZUUmyoTOq8taXEhS8AIpgI2t4RTBSodaMFQOzQLeqYPA9mLj0TwT7tRSPoxrNxe4NE+YMLC9JS7mzaNaxyQLKFwZzpFzqqQ4ipqmedlhs= 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 1673946928206682.5062020098604; Tue, 17 Jan 2023 01:15:28 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.479175.742868 (Exim 4.92) (envelope-from ) id 1pHi3l-0004G5-QO; Tue, 17 Jan 2023 09:15:13 +0000 Received: by outflank-mailman (output) from mailman id 479175.742868; Tue, 17 Jan 2023 09:15:13 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pHi3l-0004FM-KR; Tue, 17 Jan 2023 09:15:13 +0000 Received: by outflank-mailman (input) for mailman id 479175; Tue, 17 Jan 2023 09:15:12 +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 1pHi0z-0007bs-AY for xen-devel@lists.xenproject.org; Tue, 17 Jan 2023 09:12:21 +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 0a0e5259-9647-11ed-b8d0-410ff93cb8f0; Tue, 17 Jan 2023 10:12:17 +0100 (CET) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 4A47B3821E; Tue, 17 Jan 2023 09:12:17 +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 1CFA91390C; Tue, 17 Jan 2023 09:12:17 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id P+7HBXFmxmNRcAAAMHmgww (envelope-from ); Tue, 17 Jan 2023 09:12:17 +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: 0a0e5259-9647-11ed-b8d0-410ff93cb8f0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1673946737; 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=HhYKz+Oi7NXGdn9eIooP5S2YyA3D/bV21hS8CpK2wqk=; b=ALO1TvRobgMJ1AorCZaEgQY0wUZ9fDndL3T46npH/zyLE7xIWsfMfSAI7C1J9oSg1upGnO YsOAXkz+ouc5mFTkW2ljb14Pz04Hou6Cgikuyn2qUmS3rwB+HUo9u+GdH6PUvtXMEmVZzw JYHY0y7DYI/BPxaF6k8Mra5td28tIjI= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Julien Grall , Anthony PERARD , Julien Grall Subject: [PATCH v3 09/17] tools/xenstore: replace literal domid 0 with dom0_domid Date: Tue, 17 Jan 2023 10:11:16 +0100 Message-Id: <20230117091124.22170-10-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230117091124.22170-1-jgross@suse.com> References: <20230117091124.22170-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1673946928619100001 Content-Type: text/plain; charset="utf-8" There are some places left where dom0 is associated with domid 0. Use dom0_domid instead. Signed-off-by: Juergen Gross Reviewed-by: Julien Grall --- tools/xenstore/xenstored_core.c | 5 +++-- tools/xenstore/xenstored_domain.c | 8 ++++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/tools/xenstore/xenstored_core.c b/tools/xenstore/xenstored_cor= e.c index 561fb121d3..3336e65c97 100644 --- a/tools/xenstore/xenstored_core.c +++ b/tools/xenstore/xenstored_core.c @@ -2316,9 +2316,10 @@ static void accept_connection(int sock) return; =20 conn =3D new_connection(&socket_funcs); - if (conn) + if (conn) { conn->fd =3D fd; - else + conn->id =3D dom0_domid; + } else close(fd); } #endif diff --git a/tools/xenstore/xenstored_domain.c b/tools/xenstore/xenstored_d= omain.c index 07d91eb50c..b7777b2afd 100644 --- a/tools/xenstore/xenstored_domain.c +++ b/tools/xenstore/xenstored_domain.c @@ -326,7 +326,7 @@ static int destroy_domain(void *_domain) if (domain->interface) { /* Domain 0 was mapped by dom0_init, so it must be unmapped using munmap() and not the grant unmap call. */ - if (domain->domid =3D=3D 0) + if (domain->domid =3D=3D dom0_domid) unmap_xenbus(domain->interface); else unmap_interface(domain->interface); @@ -410,7 +410,7 @@ void handle_event(void) =20 static bool domid_is_unprivileged(unsigned int domid) { - return domid !=3D 0 && domid !=3D priv_domid; + return domid !=3D dom0_domid && domid !=3D priv_domid; } =20 bool domain_is_unprivileged(struct connection *conn) @@ -798,7 +798,7 @@ static struct domain *onearg_domain(struct connection *= conn, return ERR_PTR(-EINVAL); =20 domid =3D atoi(domid_str); - if (!domid) + if (domid =3D=3D dom0_domid) return ERR_PTR(-EINVAL); =20 return find_connected_domain(domid); @@ -1004,7 +1004,7 @@ static int chk_domain_generation(unsigned int domid, = uint64_t gen) { struct domain *d; =20 - if (!xc_handle && domid =3D=3D 0) + if (!xc_handle && domid =3D=3D dom0_domid) return 1; =20 d =3D find_domain_struct(domid); --=20 2.35.3 From nobody Fri May 17 03:00:56 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=1673946928; cv=none; d=zohomail.com; s=zohoarc; b=HxPlR9/oSRxGap8AzHSD0wlngINrry+Subfsk7KqFPzUDKRf+TZY9dnpwkJp4i0GOVixlx7z2XIH3mIrJT1VjFLZF1r1vl7KwEpC4Yt/TWw0G8C0AY6QKjKRUviMjqPfqUR/5/KW6ah09mtVWPZHQGyTMQxiAgqMaSuLHeJDy/k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1673946928; 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=yXucUqowhnBeO9Jn8o0sdHo0YPTusLdpuVGmf+Cjy/o=; b=jOzoeAvxvDIBLqNv4JGbTyy0REDjNo9ZH06ZMSynnWubq89pJiGzyscJaRlE2HCtfMy1+MzjW0C/g15on6yADpMUPRKEcM1cRUmJiPT50K1YjVO6IFDvMg16iyNwOU/fk3fqVIyc1/m1Q7kh0+DFTnZLpFMdYdYmnwpMTmyqv7U= 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 1673946928607922.4146832953451; Tue, 17 Jan 2023 01:15:28 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.479178.742875 (Exim 4.92) (envelope-from ) id 1pHi3m-0004Nn-4x; Tue, 17 Jan 2023 09:15:14 +0000 Received: by outflank-mailman (output) from mailman id 479178.742875; Tue, 17 Jan 2023 09:15:14 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pHi3l-0004N3-Uq; Tue, 17 Jan 2023 09:15:13 +0000 Received: by outflank-mailman (input) for mailman id 479178; Tue, 17 Jan 2023 09:15:12 +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 1pHi12-0007bs-UW for xen-devel@lists.xenproject.org; Tue, 17 Jan 2023 09:12:25 +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 0d64c23f-9647-11ed-b8d0-410ff93cb8f0; Tue, 17 Jan 2023 10:12:23 +0100 (CET) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id DC45F38222; Tue, 17 Jan 2023 09:12:22 +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 AEEB21390C; Tue, 17 Jan 2023 09:12:22 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id U1Z4KXZmxmNmcAAAMHmgww (envelope-from ); Tue, 17 Jan 2023 09:12:22 +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: 0d64c23f-9647-11ed-b8d0-410ff93cb8f0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1673946742; 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=yXucUqowhnBeO9Jn8o0sdHo0YPTusLdpuVGmf+Cjy/o=; b=vPjfHsTvKEqoIJzRAJxJriG6q+gyHoY+FpIIl7mKaBHRGmcBmtQSiuW1j4FIahaVDp2Dpr PlKDky6dYGZyu9dgd4cOi7rOpeCCtD+RCLVAchXHIjwPoTKf4qhw9R5DHf46LoCJBGoPYj N6ivMdA3/11lyVBcoJWwulNI9RfLWks= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Julien Grall , Anthony PERARD , Julien Grall Subject: [PATCH v3 10/17] tools/xenstore: make domain_is_unprivileged() an inline function Date: Tue, 17 Jan 2023 10:11:17 +0100 Message-Id: <20230117091124.22170-11-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230117091124.22170-1-jgross@suse.com> References: <20230117091124.22170-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1673946930629100006 Content-Type: text/plain; charset="utf-8" clang 14 is complaining about a NULL dereference for constructs like: domain_is_unprivileged(conn) ? conn->in : NULL as it can't know that domain_is_unprivileged(conn) will return false if conn is NULL. Fix that by making domain_is_unprivileged() an inline function (and related to that domid_is_unprivileged(), too). In order not having to make struct domain public, use conn->id instead of conn->domain->domid for the test. Signed-off-by: Juergen Gross Acked-by: Julien Grall --- tools/xenstore/xenstored_core.h | 10 ++++++++++ tools/xenstore/xenstored_domain.c | 11 ----------- tools/xenstore/xenstored_domain.h | 2 -- 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/tools/xenstore/xenstored_core.h b/tools/xenstore/xenstored_cor= e.h index 37006d508d..3c4e27d0dd 100644 --- a/tools/xenstore/xenstored_core.h +++ b/tools/xenstore/xenstored_core.h @@ -297,6 +297,16 @@ void unmap_xenbus(void *interface); =20 static inline int xenbus_master_domid(void) { return dom0_domid; } =20 +static inline bool domid_is_unprivileged(unsigned int domid) +{ + return domid !=3D dom0_domid && domid !=3D priv_domid; +} + +static inline bool domain_is_unprivileged(const struct connection *conn) +{ + return conn && domid_is_unprivileged(conn->id); +} + /* Return the event channel used by xenbus. */ evtchn_port_t xenbus_evtchn(void); =20 diff --git a/tools/xenstore/xenstored_domain.c b/tools/xenstore/xenstored_d= omain.c index b7777b2afd..55a93eccdb 100644 --- a/tools/xenstore/xenstored_domain.c +++ b/tools/xenstore/xenstored_domain.c @@ -408,17 +408,6 @@ void handle_event(void) barf_perror("Failed to write to event fd"); } =20 -static bool domid_is_unprivileged(unsigned int domid) -{ - return domid !=3D dom0_domid && domid !=3D priv_domid; -} - -bool domain_is_unprivileged(struct connection *conn) -{ - return conn && conn->domain && - domid_is_unprivileged(conn->domain->domid); -} - static char *talloc_domain_path(const void *context, unsigned int domid) { return talloc_asprintf(context, "/local/domain/%u", domid); diff --git a/tools/xenstore/xenstored_domain.h b/tools/xenstore/xenstored_d= omain.h index 1e402f2609..22996e2576 100644 --- a/tools/xenstore/xenstored_domain.h +++ b/tools/xenstore/xenstored_domain.h @@ -59,8 +59,6 @@ void ignore_connection(struct connection *conn, unsigned = int err); /* Returns the implicit path of a connection (only domains have this) */ const char *get_implicit_path(const struct connection *conn); =20 -bool domain_is_unprivileged(struct connection *conn); - /* Remove node permissions for no longer existing domains. */ int domain_adjust_node_perms(struct node *node); int domain_alloc_permrefs(struct node_perms *perms); --=20 2.35.3 From nobody Fri May 17 03:00:56 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=1673946771; cv=none; d=zohomail.com; s=zohoarc; b=dmcaev8RCNDgDht+3j9fu79ZlrEWIszf3OE+Mq0PaLXpH286KHxXdC39G9s9yOCKGLDr9K0GwPZV4WbthQnHQSV7p87VZ4Sn3OtOxpRvfyxqtTAPRgKb8or2X9rkr7AHb0EdXOlLv8xmwrLN9SZjugNO0mDsWkuNyBs/AgReP3I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1673946771; 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=qxN+8k08vTt0nMXkeJr8ru9QvmOMBTZNPN5l16ahebE=; b=V2mf24dmj3pgrSmbjvR3+OH80OHCeTEFkfo5PS3bq3nm9qJaUJrBv8wBvB3cBXrkaUWSlLI5EOCTr5TIy1Oc2FRwb9hbEvwlYORLMui5Xe0bDHG1W6FekE7uHYXMIxOW4HriVlmvpUw+dJJFbcxS9GQcleBWwSQbXnHypCs86UE= 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 1673946771400148.73618248376147; Tue, 17 Jan 2023 01:12:51 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.479157.742841 (Exim 4.92) (envelope-from ) id 1pHi17-0002iZ-RB; Tue, 17 Jan 2023 09:12:29 +0000 Received: by outflank-mailman (output) from mailman id 479157.742841; Tue, 17 Jan 2023 09:12:29 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pHi17-0002iS-NB; Tue, 17 Jan 2023 09:12:29 +0000 Received: by outflank-mailman (input) for mailman id 479157; Tue, 17 Jan 2023 09:12:29 +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 1pHi17-000725-CK for xen-devel@lists.xenproject.org; Tue, 17 Jan 2023 09:12:29 +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 10b7f7da-9647-11ed-91b6-6bf2151ebd3b; Tue, 17 Jan 2023 10:12:28 +0100 (CET) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 79FA7683D9; Tue, 17 Jan 2023 09:12:28 +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 493381390C; Tue, 17 Jan 2023 09:12:28 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id B+WyEHxmxmNvcAAAMHmgww (envelope-from ); Tue, 17 Jan 2023 09:12:28 +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: 10b7f7da-9647-11ed-91b6-6bf2151ebd3b DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1673946748; 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=qxN+8k08vTt0nMXkeJr8ru9QvmOMBTZNPN5l16ahebE=; b=P/WKj3ov4+KtXochZB1lePMqmyq2VdvkXDHVrF7Ukb5Z8pdCVPkL5S78vRf479Q1V3/jPG nl2xTTR9/ookdhP4zN+OVj7VEYqdOlZWlAK2Dy6nz2vj+dHTdCQ85pP+cbWwd1whyOTDJE mYfSGxwCj6LxETmyoKoyBLaG7m9FiS0= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Julien Grall , Anthony PERARD , Julien Grall Subject: [PATCH v3 11/17] tools/xenstore: let chk_domain_generation() return a bool Date: Tue, 17 Jan 2023 10:11:18 +0100 Message-Id: <20230117091124.22170-12-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230117091124.22170-1-jgross@suse.com> References: <20230117091124.22170-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1673946771944100001 Content-Type: text/plain; charset="utf-8" Instead of returning 0 or 1 let chk_domain_generation() return a boolean value. Simplify the only caller by removing the ret variable. Signed-off-by: Juergen Gross Reviewed-by: Julien Grall --- tools/xenstore/xenstored_domain.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/tools/xenstore/xenstored_domain.c b/tools/xenstore/xenstored_d= omain.c index 55a93eccdb..1723c9804a 100644 --- a/tools/xenstore/xenstored_domain.c +++ b/tools/xenstore/xenstored_domain.c @@ -985,20 +985,20 @@ void domain_deinit(void) * count (used for testing whether a node permission is older than a domai= n). * * Return values: - * 0: domain has higher generation count (it is younger than a node with = the - * given count), or domain isn't existing any longer - * 1: domain is older than the node + * false: domain has higher generation count (it is younger than a node w= ith + * the given count), or domain isn't existing any longer + * true: domain is older than the node */ -static int chk_domain_generation(unsigned int domid, uint64_t gen) +static bool chk_domain_generation(unsigned int domid, uint64_t gen) { struct domain *d; =20 if (!xc_handle && domid =3D=3D dom0_domid) - return 1; + return true; =20 d =3D find_domain_struct(domid); =20 - return (d && d->generation <=3D gen) ? 1 : 0; + return d && d->generation <=3D gen; } =20 /* @@ -1033,14 +1033,12 @@ int domain_alloc_permrefs(struct node_perms *perms) int domain_adjust_node_perms(struct node *node) { unsigned int i; - int ret; =20 for (i =3D 1; i < node->perms.num; i++) { if (node->perms.p[i].perms & XS_PERM_IGNORE) continue; - ret =3D chk_domain_generation(node->perms.p[i].id, - node->generation); - if (!ret) + if (!chk_domain_generation(node->perms.p[i].id, + node->generation)) node->perms.p[i].perms |=3D XS_PERM_IGNORE; } =20 --=20 2.35.3 From nobody Fri May 17 03:00:56 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=1673946931; cv=none; d=zohomail.com; s=zohoarc; b=Syb7fis6lJvJC4SdteFlI0IZxDvJPA7y0iDYk0/cRUxGzEoAGOQ6IMl3EqIMiI9qfj4uUhPQil21zZ8mUsJB4qiCJtb6DlpBlKTMoYPqJ38QanfgaRcgVkkz5x2twY5bE/bdlmSIHy8kFl952ETq4/QjUgwMRatOQhcHObFHdJU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1673946931; 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=bQqweqSwYnhQCXgkJ+GuoRH/j2JjRdq9d6DeU3NphTE=; b=OtlIxk15eRyOsHWt+WX2A9YthC7278sFxY5HL9/CPLeciyZ8+fTGB48W/VoPma993zhpePHJPPP/ob7ig/7AQHMSU0HDgTtVSUexxIDjrhofBAcK6T2KXROxAFb+ZMdB0jP4AzSWJfaKLoqdfYWvyMgTui8h7+rJMlVk8Lisu0o= 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 1673946931811978.0363166089197; Tue, 17 Jan 2023 01:15:31 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.479190.742910 (Exim 4.92) (envelope-from ) id 1pHi3q-0005Mp-Dq; Tue, 17 Jan 2023 09:15:18 +0000 Received: by outflank-mailman (output) from mailman id 479190.742910; Tue, 17 Jan 2023 09:15:18 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pHi3q-0005MT-A1; Tue, 17 Jan 2023 09:15:18 +0000 Received: by outflank-mailman (input) for mailman id 479190; Tue, 17 Jan 2023 09:15:16 +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 1pHi1E-0007bs-5S for xen-devel@lists.xenproject.org; Tue, 17 Jan 2023 09:12:36 +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 140e5eab-9647-11ed-b8d0-410ff93cb8f0; Tue, 17 Jan 2023 10:12:34 +0100 (CET) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 1402138222; Tue, 17 Jan 2023 09:12:34 +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 DC1FB1390C; Tue, 17 Jan 2023 09:12:33 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id cIJtNIFmxmN3cAAAMHmgww (envelope-from ); Tue, 17 Jan 2023 09:12:33 +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: 140e5eab-9647-11ed-b8d0-410ff93cb8f0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1673946754; 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=bQqweqSwYnhQCXgkJ+GuoRH/j2JjRdq9d6DeU3NphTE=; b=pcb31h6yJWKzfEqmpCfESS8Z7el38BnEmqY9QrafiMwrSxiiVuPp1JFDx1K1yQO7bjbxqZ 6adNigUvH2LXZiE+t8buwGaWDmfyFJtfD1dWIJzNc4Kyg62/fqMVoCc2Q+Pc1MakRNCyii AzFh3Ec4pz3TQLPLCpgomVEJXW8HVoQ= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Julien Grall , Anthony PERARD Subject: [PATCH v3 12/17] tools/xenstore: don't let hashtable_remove() return the removed value Date: Tue, 17 Jan 2023 10:11:19 +0100 Message-Id: <20230117091124.22170-13-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230117091124.22170-1-jgross@suse.com> References: <20230117091124.22170-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1673946932623100009 Content-Type: text/plain; charset="utf-8" Letting hashtable_remove() return the value of the removed element is not used anywhere in Xenstore, and it conflicts with a hashtable created specifying the HASHTABLE_FREE_VALUE flag. So just drop returning the value. Signed-off-by: Juergen Gross --- V3: - new patch --- tools/xenstore/hashtable.c | 10 +++++----- tools/xenstore/hashtable.h | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/tools/xenstore/hashtable.c b/tools/xenstore/hashtable.c index 299549c51e..6738719e47 100644 --- a/tools/xenstore/hashtable.c +++ b/tools/xenstore/hashtable.c @@ -214,7 +214,7 @@ hashtable_search(struct hashtable *h, void *k) } =20 /*************************************************************************= ****/ -void * /* returns value associated with key */ +int hashtable_remove(struct hashtable *h, void *k) { /* TODO: consider compacting the table when the load factor drops enou= gh, @@ -222,7 +222,6 @@ hashtable_remove(struct hashtable *h, void *k) =20 struct entry *e; struct entry **pE; - void *v; unsigned int hashvalue, index; =20 hashvalue =3D hash(h,k); @@ -236,16 +235,17 @@ hashtable_remove(struct hashtable *h, void *k) { *pE =3D e->next; h->entrycount--; - v =3D e->v; if (h->flags & HASHTABLE_FREE_KEY) free(e->k); + if (h->flags & HASHTABLE_FREE_VALUE) + free(e->v); free(e); - return v; + return 1; } pE =3D &(e->next); e =3D e->next; } - return NULL; + return 0; } =20 /*************************************************************************= ****/ diff --git a/tools/xenstore/hashtable.h b/tools/xenstore/hashtable.h index 6d65431f96..d6feb1b038 100644 --- a/tools/xenstore/hashtable.h +++ b/tools/xenstore/hashtable.h @@ -68,10 +68,10 @@ hashtable_search(struct hashtable *h, void *k); * @name hashtable_remove * @param h the hashtable to remove the item from * @param k the key to search for - does not claim ownership - * @return the value associated with the key, or NULL if none found + * @return 0 if element not found */ =20 -void * /* returns value */ +int hashtable_remove(struct hashtable *h, void *k); =20 /*************************************************************************= **** --=20 2.35.3 From nobody Fri May 17 03:00:56 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=1673946933; cv=none; d=zohomail.com; s=zohoarc; b=FohN/5BqoRV8kvusgDv0QZu3qWprzKzOxF4HZwEY+M/Rwl6HESM+jn7gFhZpHF/Vkkq+jcMVMhNdkALY9U+og9Si9QsKIoFOeOcqR67+4YoAX/AfXYcmMKvwq04hQa32NS9Apxi9wFjOlQ8yaOtT+fU3T+oZAIiK/uNsfmmQ2XQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1673946933; 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=77xbwD9TcvGEPUJAkwJ1xcSALMKCwiZJKLxyV5lcyls=; b=FRDRZGOfmMLmkXHuOWrHgdbruL1SJ+pBoHNoJd++aaJL8ukqBtVLPgLAZQWeZGT3TBxcTiBswZjsRGfF3tMKlQtYIZAXn3KzTpg7z7ekAVYQQGMqUjO+hAscNETb/7f9PMWbP9Shr/sPxjgW8xOGL/viNlKIOxZJaKwu34cvKFc= 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 167394693332897.92532328902826; Tue, 17 Jan 2023 01:15:33 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.479188.742907 (Exim 4.92) (envelope-from ) id 1pHi3q-0005Ho-0Z; Tue, 17 Jan 2023 09:15:18 +0000 Received: by outflank-mailman (output) from mailman id 479188.742907; Tue, 17 Jan 2023 09:15:17 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pHi3p-0005HF-TH; Tue, 17 Jan 2023 09:15:17 +0000 Received: by outflank-mailman (input) for mailman id 479188; Tue, 17 Jan 2023 09:15:16 +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 1pHi1K-0007bs-2o for xen-devel@lists.xenproject.org; Tue, 17 Jan 2023 09:12:42 +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 1765f81e-9647-11ed-b8d0-410ff93cb8f0; Tue, 17 Jan 2023 10:12:39 +0100 (CET) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id A9227683DE; Tue, 17 Jan 2023 09:12:39 +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 7A5D11390C; Tue, 17 Jan 2023 09:12:39 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id xnOAHIdmxmOCcAAAMHmgww (envelope-from ); Tue, 17 Jan 2023 09:12:39 +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: 1765f81e-9647-11ed-b8d0-410ff93cb8f0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1673946759; 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=77xbwD9TcvGEPUJAkwJ1xcSALMKCwiZJKLxyV5lcyls=; b=Dis9zcsVRAnAKml091hEsYnEB8Uv6Zf9oF2QOkUE1nQ5GFR6iVrOA7busVh1OYBWCqhRKN Hin4CPV6UDFX4L/ULWqjcKxJFLcVxd+ru8N0uNKleetxwoT8pzaLDvPm/SD6uSiaykxype FxTXFdSoGoAOEy8ET/8MF46z1u6Da6U= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Julien Grall , Anthony PERARD Subject: [PATCH v3 13/17] tools/xenstore: switch hashtable to use the talloc framework Date: Tue, 17 Jan 2023 10:11:20 +0100 Message-Id: <20230117091124.22170-14-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230117091124.22170-1-jgross@suse.com> References: <20230117091124.22170-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1673946934670100001 Content-Type: text/plain; charset="utf-8" Instead of using malloc() and friends, let the hashtable implementation use the talloc framework. This is more consistent with the rest of xenstored and it allows to track memory usage via "xenstore-control memreport". Signed-off-by: Juergen Gross Reviewed-by: Julien Grall --- V3: - make key and value children of element (if flagged) --- tools/xenstore/hashtable.c | 98 +++++++++++-------------------- tools/xenstore/hashtable.h | 3 +- tools/xenstore/xenstored_core.c | 5 +- tools/xenstore/xenstored_domain.c | 2 +- 4 files changed, 38 insertions(+), 70 deletions(-) diff --git a/tools/xenstore/hashtable.c b/tools/xenstore/hashtable.c index 6738719e47..6c2a0efeea 100644 --- a/tools/xenstore/hashtable.c +++ b/tools/xenstore/hashtable.c @@ -6,6 +6,8 @@ #include #include #include +#include +#include "talloc.h" =20 struct entry { @@ -50,7 +52,7 @@ indexFor(unsigned int tablelength, unsigned int hashvalue= ) { =20 /*************************************************************************= ****/ struct hashtable * -create_hashtable(unsigned int minsize, +create_hashtable(const void *ctx, unsigned int minsize, unsigned int (*hashf) (void*), int (*eqf) (void*,void*), unsigned int flags) @@ -66,10 +68,10 @@ create_hashtable(unsigned int minsize, if (primes[pindex] > minsize) { size =3D primes[pindex]; break; } } =20 - h =3D (struct hashtable *)calloc(1, sizeof(struct hashtable)); + h =3D talloc_zero(ctx, struct hashtable); if (NULL =3D=3D h) goto err0; - h->table =3D (struct entry **)calloc(size, sizeof(struct entry *)); + h->table =3D talloc_zero_array(h, struct entry *, size); if (NULL =3D=3D h->table) goto err1; =20 @@ -83,7 +85,7 @@ create_hashtable(unsigned int minsize, return h; =20 err1: - free(h); + talloc_free(h); err0: return NULL; } @@ -115,47 +117,32 @@ hashtable_expand(struct hashtable *h) if (h->primeindex =3D=3D (prime_table_length - 1)) return 0; newsize =3D primes[++(h->primeindex)]; =20 - newtable =3D (struct entry **)calloc(newsize, sizeof(struct entry*)); - if (NULL !=3D newtable) + newtable =3D talloc_realloc(h, h->table, struct entry *, newsize); + if (!newtable) { - /* This algorithm is not 'stable'. ie. it reverses the list - * when it transfers entries between the tables */ - for (i =3D 0; i < h->tablelength; i++) { - while (NULL !=3D (e =3D h->table[i])) { - h->table[i] =3D e->next; - index =3D indexFor(newsize,e->h); + h->primeindex--; + return 0; + } + + h->table =3D newtable; + memset(newtable + h->tablelength, 0, + (newsize - h->tablelength) * sizeof(*newtable)); + for (i =3D 0; i < h->tablelength; i++) { + for (pE =3D &(newtable[i]), e =3D *pE; e !=3D NULL; e =3D *pE) { + index =3D indexFor(newsize, e->h); + if (index =3D=3D i) + { + pE =3D &(e->next); + } + else + { + *pE =3D e->next; e->next =3D newtable[index]; newtable[index] =3D e; } } - free(h->table); - h->table =3D newtable; - } - /* Plan B: realloc instead */ - else=20 - { - newtable =3D (struct entry **) - realloc(h->table, newsize * sizeof(struct entry *)); - if (NULL =3D=3D newtable) { (h->primeindex)--; return 0; } - h->table =3D newtable; - memset(newtable + h->tablelength, 0, - (newsize - h->tablelength) * sizeof(*newtable)); - for (i =3D 0; i < h->tablelength; i++) { - for (pE =3D &(newtable[i]), e =3D *pE; e !=3D NULL; e =3D *pE)= { - index =3D indexFor(newsize,e->h); - if (index =3D=3D i) - { - pE =3D &(e->next); - } - else - { - *pE =3D e->next; - e->next =3D newtable[index]; - newtable[index] =3D e; - } - } - } } + h->tablelength =3D newsize; h->loadlimit =3D (unsigned int) (((uint64_t)newsize * max_load_factor) / 100); @@ -184,12 +171,16 @@ hashtable_insert(struct hashtable *h, void *k, void *= v) * element may be ok. Next time we insert, we'll try expanding aga= in.*/ hashtable_expand(h); } - e =3D (struct entry *)calloc(1, sizeof(struct entry)); + e =3D talloc_zero(h, struct entry); if (NULL =3D=3D e) { --(h->entrycount); return 0; } /*oom*/ e->h =3D hash(h,k); index =3D indexFor(h->tablelength,e->h); e->k =3D k; + if (h->flags & HASHTABLE_FREE_KEY) + talloc_steal(e, k); e->v =3D v; + if (h->flags & HASHTABLE_FREE_VALUE) + talloc_steal(e, v); e->next =3D h->table[index]; h->table[index] =3D e; return -1; @@ -235,11 +226,7 @@ hashtable_remove(struct hashtable *h, void *k) { *pE =3D e->next; h->entrycount--; - if (h->flags & HASHTABLE_FREE_KEY) - free(e->k); - if (h->flags & HASHTABLE_FREE_VALUE) - free(e->v); - free(e); + talloc_free(e); return 1; } pE =3D &(e->next); @@ -279,26 +266,7 @@ hashtable_iterate(struct hashtable *h, void hashtable_destroy(struct hashtable *h) { - unsigned int i; - struct entry *e, *f; - struct entry **table =3D h->table; - - for (i =3D 0; i < h->tablelength; i++) - { - e =3D table[i]; - while (NULL !=3D e) - { - f =3D e; - e =3D e->next; - if (h->flags & HASHTABLE_FREE_KEY) - free(f->k); - if (h->flags & HASHTABLE_FREE_VALUE) - free(f->v); - free(f); - } - } - free(h->table); - free(h); + talloc_free(h); } =20 /* diff --git a/tools/xenstore/hashtable.h b/tools/xenstore/hashtable.h index d6feb1b038..5d39c4e3a0 100644 --- a/tools/xenstore/hashtable.h +++ b/tools/xenstore/hashtable.h @@ -9,6 +9,7 @@ struct hashtable; * create_hashtable =20 * @name create_hashtable + * @param ctx talloc context to use for allocations * @param minsize minimum initial size of hashtable * @param hashfunction function for hashing keys * @param key_eq_fn function for determining key equality @@ -22,7 +23,7 @@ struct hashtable; #define HASHTABLE_FREE_KEY (1U << 1) =20 struct hashtable * -create_hashtable(unsigned int minsize, +create_hashtable(const void *ctx, unsigned int minsize, unsigned int (*hashfunction) (void*), int (*key_eq_fn) (void*,void*), unsigned int flags diff --git a/tools/xenstore/xenstored_core.c b/tools/xenstore/xenstored_cor= e.c index 3336e65c97..f27209dec8 100644 --- a/tools/xenstore/xenstored_core.c +++ b/tools/xenstore/xenstored_core.c @@ -2424,11 +2424,10 @@ static int keys_equal_fn(void *key1, void *key2) =20 int remember_string(struct hashtable *hash, const char *str) { - char *k =3D malloc(strlen(str) + 1); + char *k =3D talloc_strdup(NULL, str); =20 if (!k) return 0; - strcpy(k, str); return hashtable_insert(hash, k, (void *)1); } =20 @@ -2523,7 +2522,7 @@ void check_store(void) }; =20 /* Don't free values (they are all void *1) */ - reachable =3D create_hashtable(16, hash_from_key_fn, keys_equal_fn, + reachable =3D create_hashtable(NULL, 16, hash_from_key_fn, keys_equal_fn, HASHTABLE_FREE_KEY); if (!reachable) { log("check_store: ENOMEM"); diff --git a/tools/xenstore/xenstored_domain.c b/tools/xenstore/xenstored_d= omain.c index 1723c9804a..3f20f03eb0 100644 --- a/tools/xenstore/xenstored_domain.c +++ b/tools/xenstore/xenstored_domain.c @@ -931,7 +931,7 @@ void domain_init(int evtfd) int rc; =20 /* Start with a random rather low domain count for the hashtable. */ - domhash =3D create_hashtable(8, domhash_fn, domeq_fn, 0); + domhash =3D create_hashtable(NULL, 8, domhash_fn, domeq_fn, 0); if (!domhash) barf_perror("Failed to allocate domain hashtable"); =20 --=20 2.35.3 From nobody Fri May 17 03:00:56 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=1673946787; cv=none; d=zohomail.com; s=zohoarc; b=cKdtF6AEesJ9REi2NR2fYzNVK0OMl0xM++PQ0BruWSOXUfaoRWwFt0Xa6ol7fOy5D2E6lp8QK80VDgB+R7LszY1ehMTCoAxZz2n+dDBfUmgrO+/qXxx8hPPNy29R96wLIC3QiPlpQ7UNZ/dqhaRb0iKgk+AW0Y2bTHzBJMKDg28= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1673946787; 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=Qhi92MnwPX7iSr8FlA4GN57x5a7k0yJyoHyO3b0J4k8=; b=LC82Ihya6r8l8OSsSPDfsJsQyOCCYNDhR9RtGHzhF90I/PXb/+1ODgSc+pANosm5vbRXiR+3a6KDlwqry08qLu5HMlmDg335zL9sgk/Gpj4XOfZLBlZxqBZzLUDXDquUFyY1LJ4qTtRBifdN08Enux7cbiirN+ENXWuVY2aYrQU= 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 1673946787574198.96073563858135; Tue, 17 Jan 2023 01:13:07 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.479162.742852 (Exim 4.92) (envelope-from ) id 1pHi1P-0003K0-4l; Tue, 17 Jan 2023 09:12:47 +0000 Received: by outflank-mailman (output) from mailman id 479162.742852; Tue, 17 Jan 2023 09:12:47 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pHi1P-0003Jr-0V; Tue, 17 Jan 2023 09:12:47 +0000 Received: by outflank-mailman (input) for mailman id 479162; Tue, 17 Jan 2023 09:12:46 +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 1pHi1O-000725-62 for xen-devel@lists.xenproject.org; Tue, 17 Jan 2023 09:12:46 +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 1abc3174-9647-11ed-91b6-6bf2151ebd3b; Tue, 17 Jan 2023 10:12:45 +0100 (CET) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 492A6683D9; Tue, 17 Jan 2023 09:12:45 +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 172B31390C; Tue, 17 Jan 2023 09:12:45 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id cThQBI1mxmOVcAAAMHmgww (envelope-from ); Tue, 17 Jan 2023 09:12:45 +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: 1abc3174-9647-11ed-91b6-6bf2151ebd3b DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1673946765; 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=Qhi92MnwPX7iSr8FlA4GN57x5a7k0yJyoHyO3b0J4k8=; b=ssmAxIkTO8DrjjidJyOflboV3TnbOo/57/H5yXzuG+jkF/NF0wzbLP/UCglJnQg+USYdB4 C7IYOp23Yi1Ri5Uskc6AzPWlxYqkmEneCYRmqe2JGtaDXJZaTEv0NtnWxTa+6YGGFAGBfE UklUgj8W8afevKKjnpjvN3NNkG6e9F8= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Julien Grall , Anthony PERARD , Julien Grall Subject: [PATCH v3 14/17] tools/xenstore: make log macro globally available Date: Tue, 17 Jan 2023 10:11:21 +0100 Message-Id: <20230117091124.22170-15-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230117091124.22170-1-jgross@suse.com> References: <20230117091124.22170-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1673946788035100001 Content-Type: text/plain; charset="utf-8" Move the definition of the log() macro to xenstored_core.h in order to make it usable from other source files, too. While at it preserve errno from being modified. Signed-off-by: Juergen Gross Reviewed-by: Julien Grall --- tools/xenstore/xenstored_core.c | 14 -------------- tools/xenstore/xenstored_core.h | 15 +++++++++++++++ 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/tools/xenstore/xenstored_core.c b/tools/xenstore/xenstored_cor= e.c index f27209dec8..d55ce632d8 100644 --- a/tools/xenstore/xenstored_core.c +++ b/tools/xenstore/xenstored_core.c @@ -88,20 +88,6 @@ TDB_CONTEXT *tdb_ctx =3D NULL; =20 static const char *sockmsg_string(enum xsd_sockmsg_type type); =20 -#define log(...) \ - do { \ - char *s =3D talloc_asprintf(NULL, __VA_ARGS__); \ - if (s) { \ - trace("%s\n", s); \ - syslog(LOG_ERR, "%s\n", s); \ - talloc_free(s); \ - } else { \ - trace("talloc failure during logging\n"); \ - syslog(LOG_ERR, "talloc failure during logging\n"); \ - } \ - } while (0) - - int quota_nb_entry_per_domain =3D 1000; int quota_nb_watch_per_domain =3D 128; int quota_max_entry_size =3D 2048; /* 2K */ diff --git a/tools/xenstore/xenstored_core.h b/tools/xenstore/xenstored_cor= e.h index 3c4e27d0dd..3b96ecd018 100644 --- a/tools/xenstore/xenstored_core.h +++ b/tools/xenstore/xenstored_core.h @@ -267,6 +267,21 @@ void trace(const char *fmt, ...) __attribute__ ((forma= t (printf, 1, 2))); void reopen_log(void); void close_log(void); =20 +#define log(...) \ + do { \ + int _saved_errno =3D errno; \ + char *s =3D talloc_asprintf(NULL, __VA_ARGS__); \ + if (s) { \ + trace("%s\n", s); \ + syslog(LOG_ERR, "%s\n", s); \ + talloc_free(s); \ + } else { \ + trace("talloc failure during logging\n"); \ + syslog(LOG_ERR, "talloc failure during logging\n"); \ + } \ + errno =3D _saved_errno; \ + } while (0) + extern int orig_argc; extern char **orig_argv; =20 --=20 2.35.3 From nobody Fri May 17 03:00:56 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=1673946932; cv=none; d=zohomail.com; s=zohoarc; b=byWbXouDQHQYH+a4Q+LExS5fSzIbezTcL6B+etO+C2zIs8rt02JU5C2fCws86qGttpKmh57fhvH06GoCxM2FGxFIYWeOPzxSE6xRYMYaBQgSlAuO0dJ/S9MKv7JmxYpOnybKw5txQZTwQdRCKvptXnI9D7YK2102a86XWHbOFd4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1673946932; 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=j/ffVP5VoVmPH0AcpkwhcaZe/NQTk5+HqyFL6Qt1ye4=; b=buW2MIyjOK3klACJG4g5tTyIrZZAy2K+LiCaa78EFT3OaH6Gs9ubY9UekhXYvhd9yi2Qp1ux6Nruw9nf+P1bcPJYlOK+35nI5ErpDDSvZdOmsiYDbtVI1CPEzBm7kdPDZFdP6wXPbIBTmA3OI5Z64Y5MX8zT61yhKzomKYxdGVw= 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 1673946932674516.432608837103; Tue, 17 Jan 2023 01:15:32 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.479192.742916 (Exim 4.92) (envelope-from ) id 1pHi3q-0005R8-U4; Tue, 17 Jan 2023 09:15:18 +0000 Received: by outflank-mailman (output) from mailman id 479192.742916; Tue, 17 Jan 2023 09:15:18 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pHi3q-0005Oa-KL; Tue, 17 Jan 2023 09:15:18 +0000 Received: by outflank-mailman (input) for mailman id 479192; Tue, 17 Jan 2023 09:15:16 +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 1pHi1U-000725-90 for xen-devel@lists.xenproject.org; Tue, 17 Jan 2023 09:12:52 +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 1e229a60-9647-11ed-91b6-6bf2151ebd3b; Tue, 17 Jan 2023 10:12:51 +0100 (CET) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 0064D38225; Tue, 17 Jan 2023 09:12:51 +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 B16DD1390C; Tue, 17 Jan 2023 09:12:50 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id HasWKpJmxmOdcAAAMHmgww (envelope-from ); Tue, 17 Jan 2023 09:12:50 +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: 1e229a60-9647-11ed-91b6-6bf2151ebd3b DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1673946771; 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=j/ffVP5VoVmPH0AcpkwhcaZe/NQTk5+HqyFL6Qt1ye4=; b=ugWkaeOZ4CtL7TkmcpuJcUEJlNRIveZz5zuZuz5W94yVmHYzlsrc+xN5F86k3Nn6mhbHOG P72vwH4m9w3ihBjdKu3qUZoC2dhReR2pGPpbAGb7LeesLUbS56qhzU4amEJDlC7FzjA1bZ +RPLJV1IT9CfAN8SIAjVcWL1DtzKvlg= 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 v3 15/17] tools/xenstore: introduce trace classes Date: Tue, 17 Jan 2023 10:11:22 +0100 Message-Id: <20230117091124.22170-16-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230117091124.22170-1-jgross@suse.com> References: <20230117091124.22170-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1673946934681100002 Content-Type: text/plain; charset="utf-8" Make the xenstored internal trace configurable by adding classes which can be switched on and off independently from each other. Define the following classes: - obj: Creation and deletion of interesting "objects" (watch, transaction, connection) - io: incoming requests and outgoing responses - wrl: write limiting Per default "obj" and "io" are switched on. Entries written via trace() will always be printed (if tracing is on at all). Add the capability to control the trace settings via the "log" command and via a new "--log-control" command line option. Add a missing trace_create() call for creating a transaction. Signed-off-by: Juergen Gross --- V2: - keep "log" and "logfile" command names (Julien Grall) --- docs/misc/xenstore.txt | 10 +++-- tools/xenstore/xenstored_control.c | 31 +++++++++++++-- tools/xenstore/xenstored_core.c | 55 ++++++++++++++++++++++++-- tools/xenstore/xenstored_core.h | 6 +++ tools/xenstore/xenstored_domain.c | 27 +++++++------ tools/xenstore/xenstored_transaction.c | 1 + 6 files changed, 106 insertions(+), 24 deletions(-) diff --git a/docs/misc/xenstore.txt b/docs/misc/xenstore.txt index 44428ae3a7..8887e7df88 100644 --- a/docs/misc/xenstore.txt +++ b/docs/misc/xenstore.txt @@ -409,10 +409,12 @@ CONTROL |[|] error string in case of failure. -s can return "BUSY" in case of an active transaction, a retry of -s can be done in that case. - log|on - turn xenstore logging on - log|off - turn xenstore logging off + log|[on|off|+|-] + without parameters: show possible log switches + on: turn xenstore logging on + off: turn xenstore logging off + +: activates log entries for , + -: deactivates log entries for logfile| log to specified file memreport|[] diff --git a/tools/xenstore/xenstored_control.c b/tools/xenstore/xenstored_= control.c index 41e6992591..000b2bb8c7 100644 --- a/tools/xenstore/xenstored_control.c +++ b/tools/xenstore/xenstored_control.c @@ -182,6 +182,28 @@ static int do_control_check(const void *ctx, struct co= nnection *conn, static int do_control_log(const void *ctx, struct connection *conn, char **vec, int num) { + int ret; + + if (num =3D=3D 0) { + char *resp =3D talloc_asprintf(ctx, "Log switch settings:\n"); + unsigned int idx; + bool on; + + if (!resp) + return ENOMEM; + for (idx =3D 0; trace_switches[idx]; idx++) { + on =3D trace_flags & (1u << idx); + resp =3D talloc_asprintf_append(resp, "%-8s: %s\n", + trace_switches[idx], + on ? "on" : "off"); + if (!resp) + return ENOMEM; + } + + send_reply(conn, XS_CONTROL, resp, strlen(resp) + 1); + return 0; + } + if (num !=3D 1) return EINVAL; =20 @@ -189,8 +211,11 @@ static int do_control_log(const void *ctx, struct conn= ection *conn, reopen_log(); else if (!strcmp(vec[0], "off")) close_log(); - else - return EINVAL; + else { + ret =3D set_trace_switch(vec[0]); + if (ret) + return ret; + } =20 send_ack(conn, XS_CONTROL); return 0; @@ -923,7 +948,7 @@ static int do_control_help(const void *, struct connect= ion *, char **, int); =20 static struct cmd_s cmds[] =3D { { "check", do_control_check, "" }, - { "log", do_control_log, "on|off" }, + { "log", do_control_log, "[on|off|+|-]" }, =20 #ifndef NO_LIVE_UPDATE /* diff --git a/tools/xenstore/xenstored_core.c b/tools/xenstore/xenstored_cor= e.c index d55ce632d8..3099077a86 100644 --- a/tools/xenstore/xenstored_core.c +++ b/tools/xenstore/xenstored_core.c @@ -85,6 +85,7 @@ static int reopen_log_pipe[2]; static int reopen_log_pipe0_pollfd_idx =3D -1; char *tracefile =3D NULL; TDB_CONTEXT *tdb_ctx =3D NULL; +unsigned int trace_flags =3D TRACE_OBJ | TRACE_IO; =20 static const char *sockmsg_string(enum xsd_sockmsg_type type); =20 @@ -139,13 +140,13 @@ static void trace_io(const struct connection *conn, time_t now; struct tm *tm; =20 - if (tracefd < 0) + if (tracefd < 0 || !(trace_flags & TRACE_IO)) return; =20 now =3D time(NULL); tm =3D localtime(&now); =20 - trace("%s %p %04d%02d%02d %02d:%02d:%02d %s (", + trace("io: %s %p %04d%02d%02d %02d:%02d:%02d %s (", out ? "OUT" : "IN", conn, tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec, @@ -158,12 +159,14 @@ static void trace_io(const struct connection *conn, =20 void trace_create(const void *data, const char *type) { - trace("CREATE %s %p\n", type, data); + if (trace_flags & TRACE_OBJ) + trace("obj: CREATE %s %p\n", type, data); } =20 void trace_destroy(const void *data, const char *type) { - trace("DESTROY %s %p\n", type, data); + if (trace_flags & TRACE_OBJ) + trace("obj: DESTROY %s %p\n", type, data); } =20 /** @@ -2604,6 +2607,8 @@ static void usage(void) " -N, --no-fork to request that the daemon does not fork,\n" " -P, --output-pid to request that the pid of the daemon is output= ,\n" " -T, --trace-file giving the file for logging, and\n" +" --trace-control=3D+ activate a specific \n" +" --trace-control=3D- deactivate a specific \n" " -E, --entry-nb limit the number of entries per domain,\n" " -S, --entry-size limit the size of entry per domain, and\n" " -W, --watch-nb limit the number of watches per domain,\n" @@ -2647,6 +2652,7 @@ static struct option options[] =3D { { "output-pid", 0, NULL, 'P' }, { "entry-size", 1, NULL, 'S' }, { "trace-file", 1, NULL, 'T' }, + { "trace-control", 1, NULL, 1 }, { "transaction", 1, NULL, 't' }, { "perm-nb", 1, NULL, 'A' }, { "path-max", 1, NULL, 'M' }, @@ -2721,6 +2727,43 @@ static void set_quota(const char *arg, bool soft) barf("unknown quota \"%s\"\n", arg); } =20 +/* Sorted by bit values of TRACE_* flags. Flag is (1u << index). */ +const char *trace_switches[] =3D { + "obj", "io", "wrl", + NULL +}; + +int set_trace_switch(const char *arg) +{ + bool remove =3D (arg[0] =3D=3D '-'); + unsigned int idx; + + switch (arg[0]) { + case '-': + remove =3D true; + break; + case '+': + remove =3D false; + break; + default: + return EINVAL; + } + + arg++; + + for (idx =3D 0; trace_switches[idx]; idx++) { + if (!strcmp(arg, trace_switches[idx])) { + if (remove) + trace_flags &=3D ~(1u << idx); + else + trace_flags |=3D 1u << idx; + return 0; + } + } + + return EINVAL; +} + int main(int argc, char *argv[]) { int opt; @@ -2769,6 +2812,10 @@ int main(int argc, char *argv[]) case 'T': tracefile =3D optarg; break; + case 1: + if (set_trace_switch(optarg)) + barf("Illegal trace switch \"%s\"\n", optarg); + break; case 'I': if (optarg && !strcmp(optarg, "off")) tdb_flags =3D 0; diff --git a/tools/xenstore/xenstored_core.h b/tools/xenstore/xenstored_cor= e.h index 3b96ecd018..c85b15515c 100644 --- a/tools/xenstore/xenstored_core.h +++ b/tools/xenstore/xenstored_core.h @@ -287,6 +287,12 @@ extern char **orig_argv; =20 extern char *tracefile; extern int tracefd; +extern unsigned int trace_flags; +#define TRACE_OBJ 0x00000001 +#define TRACE_IO 0x00000002 +#define TRACE_WRL 0x00000004 +extern const char *trace_switches[]; +int set_trace_switch(const char *arg); =20 extern TDB_CONTEXT *tdb_ctx; extern int dom0_domid; diff --git a/tools/xenstore/xenstored_domain.c b/tools/xenstore/xenstored_d= omain.c index 3f20f03eb0..cb1f09c297 100644 --- a/tools/xenstore/xenstored_domain.c +++ b/tools/xenstore/xenstored_domain.c @@ -1260,6 +1260,12 @@ static long wrl_ndomains; static wrl_creditt wrl_reserve; /* [-wrl_config_newdoms_dburst, +_gburst ]= */ static time_t wrl_log_last_warning; /* 0: no previous warning */ =20 +#define trace_wrl(...) \ +do { \ + if (trace_flags & TRACE_WRL) \ + trace("wrl: " __VA_ARGS__); \ +} while (0) + void wrl_gettime_now(struct wrl_timestampt *now_wt) { struct timespec now_ts; @@ -1365,12 +1371,9 @@ void wrl_credit_update(struct domain *domain, struct= wrl_timestampt now) =20 domain->wrl_timestamp =3D now; =20 - trace("wrl: dom %4d %6ld msec %9ld credit %9ld reserve" - " %9ld discard\n", - domain->domid, - msec, - (long)domain->wrl_credit, (long)wrl_reserve, - (long)surplus); + trace_wrl("dom %4d %6ld msec %9ld credit %9ld reserve %9ld discard\n", + domain->domid, msec, (long)domain->wrl_credit, + (long)wrl_reserve, (long)surplus); } =20 void wrl_check_timeout(struct domain *domain, @@ -1402,10 +1405,9 @@ void wrl_check_timeout(struct domain *domain, if (*ptimeout=3D=3D-1 || wakeup < *ptimeout) *ptimeout =3D wakeup; =20 - trace("wrl: domain %u credit=3D%ld (reserve=3D%ld) SLEEPING for %d\n", - domain->domid, - (long)domain->wrl_credit, (long)wrl_reserve, - wakeup); + trace_wrl("domain %u credit=3D%ld (reserve=3D%ld) SLEEPING for %d\n", + domain->domid, (long)domain->wrl_credit, (long)wrl_reserve, + wakeup); } =20 #define WRL_LOG(now, ...) \ @@ -1423,9 +1425,8 @@ void wrl_apply_debit_actual(struct domain *domain) wrl_credit_update(domain, now); =20 domain->wrl_credit -=3D wrl_config_writecost; - trace("wrl: domain %u credit=3D%ld (reserve=3D%ld)\n", - domain->domid, - (long)domain->wrl_credit, (long)wrl_reserve); + trace_wrl("domain %u credit=3D%ld (reserve=3D%ld)\n", domain->domid, + (long)domain->wrl_credit, (long)wrl_reserve); =20 if (domain->wrl_credit < 0) { if (!domain->wrl_delay_logged) { diff --git a/tools/xenstore/xenstored_transaction.c b/tools/xenstore/xensto= red_transaction.c index 82e5e66c18..1aa9d3cb3d 100644 --- a/tools/xenstore/xenstored_transaction.c +++ b/tools/xenstore/xenstored_transaction.c @@ -475,6 +475,7 @@ int do_transaction_start(const void *ctx, struct connec= tion *conn, if (!trans) return ENOMEM; =20 + trace_create(trans, "transaction"); INIT_LIST_HEAD(&trans->accessed); INIT_LIST_HEAD(&trans->changed_domains); trans->conn =3D conn; --=20 2.35.3 From nobody Fri May 17 03:00:56 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=1673946927; cv=none; d=zohomail.com; s=zohoarc; b=WVtXSsCqoN1OQAQIg009aF8wb8XPt71hjGJ1u5iSnRsxtXzZ2IpKAOojByxWxETeLHBQG2PhK8CSzLakEDsk+CRc7WhA1uhcvLEisjt8Axgad7SDOmBcObXVLnTc1N98AdUxIVU9l49d1RUxxQaHUcvgwYX8ycDz//v2JHRRlqc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1673946927; 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=JzTrJ5tQk513x3Ydn7diRgOfwUfJxvyb7EQt/DCJ5Fk=; b=h/KMtLSPqNsvM33jBQpnCr51LmJJIsyhkT/zEOdQ/ZefrofPH3zlWlGDgBjlerPt9LPSYMluBVrrnFkMsaTs/dAE30AK0akEoyxYhKiUquV4vroXBKWoHaVee5spZBn4caZiLFpJECnwqsYZ4IcKjBwCR/n7nbrk4TxBtdarINY= 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 1673946927518163.22556298570555; Tue, 17 Jan 2023 01:15:27 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.479172.742862 (Exim 4.92) (envelope-from ) id 1pHi3l-0004Di-Fl; Tue, 17 Jan 2023 09:15:13 +0000 Received: by outflank-mailman (output) from mailman id 479172.742862; Tue, 17 Jan 2023 09:15:13 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pHi3l-0004Db-DA; Tue, 17 Jan 2023 09:15:13 +0000 Received: by outflank-mailman (input) for mailman id 479172; Tue, 17 Jan 2023 09:15:11 +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 1pHi1Z-000725-Um for xen-devel@lists.xenproject.org; Tue, 17 Jan 2023 09:12:58 +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 218fd624-9647-11ed-91b6-6bf2151ebd3b; Tue, 17 Jan 2023 10:12:56 +0100 (CET) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id B3CF2683D9; Tue, 17 Jan 2023 09:12:56 +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 8707B1390C; Tue, 17 Jan 2023 09:12:56 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 0JqeH5hmxmOrcAAAMHmgww (envelope-from ); Tue, 17 Jan 2023 09:12: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: 218fd624-9647-11ed-91b6-6bf2151ebd3b DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1673946776; 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=JzTrJ5tQk513x3Ydn7diRgOfwUfJxvyb7EQt/DCJ5Fk=; b=XPPC+AyCftO64LZrJ2ieTvFPYdpTJTuwQjXtINIH0maH3Bp4b0qQ2Q3npVgYvByq1wzMH7 oRvo+mj85uCSH2Ed2jBaKmlF0heRQZMWox2/crDq7dZeR1qeDZhqH2dE5U9eX8GcSBMCMW a/JNsrwQZnc4y5ngJdBd0B7fhdDQu04= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Julien Grall , Anthony PERARD Subject: [PATCH v3 16/17] tools/xenstore: let check_store() check the accounting data Date: Tue, 17 Jan 2023 10:11:23 +0100 Message-Id: <20230117091124.22170-17-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230117091124.22170-1-jgross@suse.com> References: <20230117091124.22170-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1673946928646100002 Content-Type: text/plain; charset="utf-8" Today check_store() is only testing the correctness of the node tree. Add verification of the accounting data (number of nodes) and correct the data if it is wrong. Do the initial check_store() call only after Xenstore entries of a live update have been read. Signed-off-by: Juergen Gross --- tools/xenstore/xenstored_core.c | 62 ++++++++++++++++------ tools/xenstore/xenstored_domain.c | 86 +++++++++++++++++++++++++++++++ tools/xenstore/xenstored_domain.h | 4 ++ 3 files changed, 137 insertions(+), 15 deletions(-) diff --git a/tools/xenstore/xenstored_core.c b/tools/xenstore/xenstored_cor= e.c index 3099077a86..e201f14053 100644 --- a/tools/xenstore/xenstored_core.c +++ b/tools/xenstore/xenstored_core.c @@ -2389,8 +2389,6 @@ void setup_structure(bool live_update) manual_node("@introduceDomain", NULL); domain_nbentry_fix(dom0_domid, 5, true); } - - check_store(); } =20 static unsigned int hash_from_key_fn(void *k) @@ -2433,20 +2431,28 @@ int remember_string(struct hashtable *hash, const c= har *str) * As we go, we record each node in the given reachable hashtable. These * entries will be used later in clean_store. */ + +struct check_store_data { + struct hashtable *reachable; + struct hashtable *domains; +}; + static int check_store_step(const void *ctx, struct connection *conn, struct node *node, void *arg) { - struct hashtable *reachable =3D arg; + struct check_store_data *data =3D arg; =20 - if (hashtable_search(reachable, (void *)node->name)) { + if (hashtable_search(data->reachable, (void *)node->name)) { log("check_store: '%s' is duplicated!", node->name); return recovery ? WALK_TREE_RM_CHILDENTRY : WALK_TREE_SKIP_CHILDREN; } =20 - if (!remember_string(reachable, node->name)) + if (!remember_string(data->reachable, node->name)) return WALK_TREE_ERROR_STOP; =20 + domain_check_acc_add(node, data->domains); + return WALK_TREE_OK; } =20 @@ -2496,37 +2502,61 @@ static int clean_store_(TDB_CONTEXT *tdb, TDB_DATA = key, TDB_DATA val, * Given the list of reachable nodes, iterate over the whole store, and * remove any that were not reached. */ -static void clean_store(struct hashtable *reachable) +static void clean_store(struct check_store_data *data) { - tdb_traverse(tdb_ctx, &clean_store_, reachable); + tdb_traverse(tdb_ctx, &clean_store_, data->reachable); + domain_check_acc(data->domains); } =20 +int check_store_path(const char *name, struct check_store_data *data) +{ + struct node *node; + + node =3D read_node(NULL, NULL, name); + if (!node) { + log("check_store: error %d reading special node '%s'", errno, + name); + return errno; + } + + return check_store_step(NULL, NULL, node, data); +} =20 void check_store(void) { - struct hashtable *reachable; struct walk_funcs walkfuncs =3D { .enter =3D check_store_step, .enoent =3D check_store_enoent, }; + struct check_store_data data; =20 /* Don't free values (they are all void *1) */ - reachable =3D create_hashtable(NULL, 16, hash_from_key_fn, keys_equal_fn, - HASHTABLE_FREE_KEY); - if (!reachable) { + data.reachable =3D create_hashtable(NULL, 16, hash_from_key_fn, + keys_equal_fn, HASHTABLE_FREE_KEY); + if (!data.reachable) { log("check_store: ENOMEM"); return; } =20 + data.domains =3D domain_check_acc_init(); + if (!data.domains) { + log("check_store: ENOMEM"); + goto out_hash; + } + log("Checking store ..."); - if (walk_node_tree(NULL, NULL, "/", &walkfuncs, reachable)) { + if (walk_node_tree(NULL, NULL, "/", &walkfuncs, &data)) { if (errno =3D=3D ENOMEM) log("check_store: ENOMEM"); - } else if (!check_transactions(reachable)) - clean_store(reachable); + } else if (!check_store_path("@introduceDomain", &data) && + !check_store_path("@releaseDomain", &data) && + !check_transactions(data.reachable)) + clean_store(&data); log("Checking store complete."); =20 - hashtable_destroy(reachable); + hashtable_destroy(data.domains); + out_hash: + hashtable_destroy(data.reachable); } =20 =20 @@ -2925,6 +2955,8 @@ int main(int argc, char *argv[]) lu_read_state(); #endif =20 + check_store(); + /* Get ready to listen to the tools. */ initialize_fds(&sock_pollfd_idx, &timeout); =20 diff --git a/tools/xenstore/xenstored_domain.c b/tools/xenstore/xenstored_d= omain.c index cb1f09c297..a3c4fb7f93 100644 --- a/tools/xenstore/xenstored_domain.c +++ b/tools/xenstore/xenstored_domain.c @@ -1573,6 +1573,92 @@ void read_state_connection(const void *ctx, const vo= id *state) read_state_buffered_data(ctx, conn, sc); } =20 +struct domain_acc { + unsigned int domid; + int nodes; +}; + +static int domain_check_acc_init_sub(const void *k, void *v, void *arg) +{ + struct hashtable *domains =3D arg; + struct domain *d =3D v; + struct domain_acc *dom; + + dom =3D talloc_zero(NULL, struct domain_acc); + if (!dom) + return -1; + + dom->domid =3D d->domid; + /* + * Set the initial value to the negative one of the current domain. + * 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; + + if (!hashtable_insert(domains, &dom->domid, dom)) { + talloc_free(dom); + return -1; + } + + return 0; +} + +struct hashtable *domain_check_acc_init(void) +{ + struct hashtable *domains; + + domains =3D create_hashtable(NULL, 8, domhash_fn, domeq_fn, + HASHTABLE_FREE_VALUE); + if (!domains) + return NULL; + + if (hashtable_iterate(domhash, domain_check_acc_init_sub, domains)) { + hashtable_destroy(domains); + return NULL; + } + + return domains; +} + +void domain_check_acc_add(const struct node *node, struct hashtable *domai= ns) +{ + struct domain_acc *dom; + unsigned int domid; + + domid =3D node->perms.p[0].id; + dom =3D hashtable_search(domains, &domid); + if (!dom) + log("Node %s owned by unknown domain %u", node->name, domid); + else + dom->nodes++; +} + +static int domain_check_acc_sub(const void *k, void *v, void *arg) +{ + struct domain_acc *dom =3D v; + struct domain *d; + + if (!dom->nodes) + return 0; + + log("Correct accounting data for domain %u: nodes are %d off", + dom->domid, dom->nodes); + + d =3D find_domain_struct(dom->domid); + if (!d) + return 0; + + d->nbentry +=3D dom->nodes; + + return 0; +} + +void domain_check_acc(struct hashtable *domains) +{ + hashtable_iterate(domains, domain_check_acc_sub, NULL); +} + /* * Local variables: * mode: C diff --git a/tools/xenstore/xenstored_domain.h b/tools/xenstore/xenstored_d= omain.h index 22996e2576..dc4660861e 100644 --- a/tools/xenstore/xenstored_domain.h +++ b/tools/xenstore/xenstored_domain.h @@ -129,4 +129,8 @@ const char *dump_state_connections(FILE *fp); =20 void read_state_connection(const void *ctx, const void *state); =20 +struct hashtable *domain_check_acc_init(void); +void domain_check_acc_add(const struct node *node, struct hashtable *domai= ns); +void domain_check_acc(struct hashtable *domains); + #endif /* _XENSTORED_DOMAIN_H */ --=20 2.35.3 From nobody Fri May 17 03:00:56 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=1673946929; cv=none; d=zohomail.com; s=zohoarc; b=ieTCPTtDorvoMQ4Vo0NEsZcrgaUnMiYxQLVkfOSaQHZ7l7iqMTLyC9OIBO+Nz5lrMuhxyjv4F7ixw+/bc2mzTeVQzZFJzIn+cA8ArFMSi9CFbibx2uXT1T7hybZOKKQmm6gAxRMBLf7jflCaxLigr+Likys0jghLBbAJmpcq8t0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1673946929; 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=hbeYM9pX9rme/MidcA7zKLWfF87qgsmjrN7bSznT5S0=; b=b18cUzhjpNkU+ucACk5ZFMo+uIPAEvm6kXcqjXFZBEnBQYorYLLHAzriXerZtpTMUlKuRznQALZHXOwICC4WtkwgmPZd+7cjEEP+6OHpI9skXuzZ1oJ9XMazjG+ps1+N/u7g1nFuffMgdRA8TubDj9Wpjnk0P2XT96b2jPUzHVg= 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 1673946929199487.83503549994543; Tue, 17 Jan 2023 01:15:29 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.479186.742896 (Exim 4.92) (envelope-from ) id 1pHi3o-000518-Lo; Tue, 17 Jan 2023 09:15:16 +0000 Received: by outflank-mailman (output) from mailman id 479186.742896; Tue, 17 Jan 2023 09:15: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 1pHi3o-00050i-HE; Tue, 17 Jan 2023 09:15:16 +0000 Received: by outflank-mailman (input) for mailman id 479186; Tue, 17 Jan 2023 09:15: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 1pHi1f-000725-Kx for xen-devel@lists.xenproject.org; Tue, 17 Jan 2023 09:13: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 24ded8bb-9647-11ed-91b6-6bf2151ebd3b; Tue, 17 Jan 2023 10:13:02 +0100 (CET) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 4BC90683DD; Tue, 17 Jan 2023 09:13: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 214A41390C; Tue, 17 Jan 2023 09:13:02 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id oZ3bBp5mxmO0cAAAMHmgww (envelope-from ); Tue, 17 Jan 2023 09:13: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: 24ded8bb-9647-11ed-91b6-6bf2151ebd3b DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1673946782; 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=hbeYM9pX9rme/MidcA7zKLWfF87qgsmjrN7bSznT5S0=; b=kXgUN8Ck+aE1WJGaEnno2laahxi4dCDB/JMqBUyD08sCYdIhcJsWaxnegCAVEbp7CTTRYS IURXKnaDnuwt6qALRzIeNJpq6z2NexoDgITvx2wrtOfrdw+lut8EFrDfE+fQmJMKFT6i92 nBzhs9fT9mkSR2AAoazrVHoiqnoXuxw= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Julien Grall , Anthony PERARD Subject: [PATCH v3 17/17] tools/xenstore: make output of "xenstore-control help" more pretty Date: Tue, 17 Jan 2023 10:11:24 +0100 Message-Id: <20230117091124.22170-18-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230117091124.22170-1-jgross@suse.com> References: <20230117091124.22170-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1673946930617100005 Content-Type: text/plain; charset="utf-8" Using a tab for separating the command from the options in the output of "xenstore-control help" results in a rather ugly list. Use a fixed size for the command instead. Signed-off-by: Juergen Gross --- V2: - new patch --- tools/xenstore/xenstored_control.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/xenstore/xenstored_control.c b/tools/xenstore/xenstored_= control.c index 000b2bb8c7..cbd62556c3 100644 --- a/tools/xenstore/xenstored_control.c +++ b/tools/xenstore/xenstored_control.c @@ -996,7 +996,7 @@ static int do_control_help(const void *ctx, struct conn= ection *conn, if (!resp) return ENOMEM; for (cmd =3D 0; cmd < ARRAY_SIZE(cmds); cmd++) { - resp =3D talloc_asprintf_append(resp, "%s\t%s\n", + resp =3D talloc_asprintf_append(resp, "%-15s %s\n", cmds[cmd].cmd, cmds[cmd].pars); if (!resp) return ENOMEM; --=20 2.35.3