From nobody Fri May 17 03:12:53 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=1667319324; cv=none; d=zohomail.com; s=zohoarc; b=FFTpk6g8Q8PWJHMGAK26dLhHEB5UnvWpZjQHE0UhbVkpVZfHzPd3FIdpxB+v4kPAJLGpC+sZuXRjac2vQ5KYZiszqmCt1eSGGnptVbAdizLmkklsgrho58RP+L0EqjN1C+Prgc8GUAjlXuiC6lg0ZVE5xOs61nwxOruq7yzG3mY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1667319324; 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=SRXNQDO4MhG9H32yh0qBaLPCvnVGtf7v3eYM21ANcnk=; b=KoRiBOTUpEv39OEqsGnC0riy5imz1eUdN+//1u2EjplkDbfV9c6NFT9h2EOLZdam8WGXt1Y57rIYzTdx29WqjtQER2lrBsgcE0P140MGtlGv6qK/Um22gkhqnoeFvMQxKmWyU8lLl+VbvnyYGS1jtY/fG+pJInd4BvpSPFVOzVA= 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 1667319324614852.3497605806007; Tue, 1 Nov 2022 09:15:24 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.435065.688108 (Exim 4.92) (envelope-from ) id 1optuv-0000zR-1F; Tue, 01 Nov 2022 16:15:09 +0000 Received: by outflank-mailman (output) from mailman id 435065.688108; Tue, 01 Nov 2022 16:15:08 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1optuu-0000zG-UD; Tue, 01 Nov 2022 16:15:08 +0000 Received: by outflank-mailman (input) for mailman id 435065; Tue, 01 Nov 2022 16:15:06 +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 1optus-0000yH-Ny for xen-devel@lists.xenproject.org; Tue, 01 Nov 2022 16:15:06 +0000 Received: from smtp-out2.suse.de (smtp-out2.suse.de [2001:67c:2178:6::1d]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 58e3f89c-5a00-11ed-91b5-6bf2151ebd3b; Tue, 01 Nov 2022 17:15:05 +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 871D51F90F; Tue, 1 Nov 2022 16:15:05 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 600101346F; Tue, 1 Nov 2022 16:15:05 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id mTP/FQlGYWMPdwAAMHmgww (envelope-from ); Tue, 01 Nov 2022 16:15: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: 58e3f89c-5a00-11ed-91b5-6bf2151ebd3b DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1667319305; 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=SRXNQDO4MhG9H32yh0qBaLPCvnVGtf7v3eYM21ANcnk=; b=uE2UvseLH5K44Hrqi7TWdLTAcE5uiNIIixn9OviwEQVluWQGHv5wkD7r7O20R4TuQjPElQ cCsFuXRC8LPqau/1IXWJsksgLf6VhHAFrywyThJsId+1dp5vL6DGo5vCz8R8pw2QitTiQB Zi1wM+hn6U2EbKVhn4G6iMPIIUSR19g= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Julien Grall , Anthony PERARD Subject: [PATCH 01/10] tools/xenstore: verify command line parameters better Date: Tue, 1 Nov 2022 17:14:48 +0100 Message-Id: <20221101161457.8470-2-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20221101161457.8470-1-jgross@suse.com> References: <20221101161457.8470-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1667319325256100001 Content-Type: text/plain; charset="utf-8" Add some more verification of command line parameters. Signed-off-by: Juergen Gross --- tools/xenstore/xenstored_core.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/tools/xenstore/xenstored_core.c b/tools/xenstore/xenstored_cor= e.c index ae1ea29b80..714841d9ca 100644 --- a/tools/xenstore/xenstored_core.c +++ b/tools/xenstore/xenstored_core.c @@ -2790,7 +2790,7 @@ int main(int argc, char *argv[]) no_domain_init =3D true; break; case 'E': - hard_quotas[ACC_NODES].val =3D strtoul(optarg, NULL, 10); + hard_quotas[ACC_NODES].val =3D get_optval_int(optarg); break; case 'F': pidfile =3D optarg; @@ -2808,10 +2808,10 @@ int main(int argc, char *argv[]) recovery =3D false; break; case 'S': - hard_quotas[ACC_NODESZ].val =3D strtoul(optarg, NULL, 10); + hard_quotas[ACC_NODESZ].val =3D get_optval_int(optarg); break; case 't': - hard_quotas[ACC_TRANS].val =3D strtoul(optarg, NULL, 10); + hard_quotas[ACC_TRANS].val =3D get_optval_int(optarg); break; case 'T': tracefile =3D optarg; @@ -2830,14 +2830,13 @@ int main(int argc, char *argv[]) verbose =3D true; break; case 'W': - hard_quotas[ACC_WATCH].val =3D strtoul(optarg, NULL, 10); + hard_quotas[ACC_WATCH].val =3D get_optval_int(optarg); break; case 'A': - hard_quotas[ACC_NPERM].val =3D strtoul(optarg, NULL, 10); + hard_quotas[ACC_NPERM].val =3D get_optval_int(optarg); break; case 'M': - hard_quotas[ACC_PATHLEN].val =3D - strtoul(optarg, NULL, 10); + hard_quotas[ACC_PATHLEN].val =3D get_optval_int(optarg); hard_quotas[ACC_PATHLEN].val =3D min((unsigned int)XENSTORE_REL_PATH_MAX, hard_quotas[ACC_PATHLEN].val); @@ -2852,13 +2851,13 @@ int main(int argc, char *argv[]) set_timeout(optarg); break; case 'e': - dom0_event =3D strtol(optarg, NULL, 10); + dom0_event =3D get_optval_int(optarg); break; case 'm': - dom0_domid =3D strtol(optarg, NULL, 10); + dom0_domid =3D get_optval_int(optarg); break; case 'p': - priv_domid =3D strtol(optarg, NULL, 10); + priv_domid =3D get_optval_int(optarg); break; #ifndef NO_LIVE_UPDATE case 'U': --=20 2.35.3 From nobody Fri May 17 03:12:53 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=1667319331; cv=none; d=zohomail.com; s=zohoarc; b=W8wsQh3NbK67mIpypCN87NAah62olUuHArKN1AZ4wa6+BSC7Th4tjW8h4/6diJYiJUprYi3xQAoutGvj/DmXPPMzcUIdYNbnfud8pWgRVcN/Xh3kFkjTD3QlYwGeslKu6GMfv66nyGJZf/MoNmjPedHwK830MKkVHFurTnmIkc4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1667319331; 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=pIb0/mYGQ+HwHEptI7zIsqWzXRU1CQBKgofF97fLAvs=; b=AxbR/g2KxTyvjkUfS6JnpniMvOXPPLPXXA/pEBogFZtssFj0mNdUQ35tWNOR05eCtCTSZntU1rUrXiYBNhpwpM1i4wzG1WkzaHLrYn1n7TF3pVisp6ezYgSsGaCv1/Z8PD6VMYq+qqCPoZme5BATQSJ/nWNTLmPm2D+PPBeeg/E= 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 1667319331779170.6055898831786; Tue, 1 Nov 2022 09:15:31 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.435076.688135 (Exim 4.92) (envelope-from ) id 1optv0-0001qA-6y; Tue, 01 Nov 2022 16:15:14 +0000 Received: by outflank-mailman (output) from mailman id 435076.688135; Tue, 01 Nov 2022 16: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 1optuz-0001pC-VV; Tue, 01 Nov 2022 16:15:13 +0000 Received: by outflank-mailman (input) for mailman id 435076; Tue, 01 Nov 2022 16: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 1optuy-0000i5-AU for xen-devel@lists.xenproject.org; Tue, 01 Nov 2022 16:15:12 +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 5c3528f9-5a00-11ed-8fd0-01056ac49cbb; Tue, 01 Nov 2022 17:15: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-out1.suse.de (Postfix) with ESMTPS id 202503382E; Tue, 1 Nov 2022 16:15: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 E69B71346F; Tue, 1 Nov 2022 16:15:10 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id QVjxNg5GYWMedwAAMHmgww (envelope-from ); Tue, 01 Nov 2022 16:15:10 +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: 5c3528f9-5a00-11ed-8fd0-01056ac49cbb DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1667319311; 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=pIb0/mYGQ+HwHEptI7zIsqWzXRU1CQBKgofF97fLAvs=; b=Mux+Oyeny1sk2ahF5isrQx7yM9meirOsLaQ2iXfYQm8Hn1AuqztnbpMJ8yiumFWQ9a70lW N1tKEZ/nKhEY9+oNc+JLe+Wm7x2xRa9yH4Zw8AGCvj7jQFA2ZRkGCY79FYlxIMS2upluMZ DsqP0sR1byMe9zu2wfI69MyLzeDBJwI= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Julien Grall , Anthony PERARD Subject: [PATCH 02/10] tools/xenstore: do some cleanup of hashtable.c Date: Tue, 1 Nov 2022 17:14:49 +0100 Message-Id: <20221101161457.8470-3-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20221101161457.8470-1-jgross@suse.com> References: <20221101161457.8470-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1667319333229100002 Content-Type: text/plain; charset="utf-8" Do the following cleanups: - hashtable_count() isn't used at all, so remove it - replace prime_table_length and max_load_factor with macros - make hash() static - add a loadlimit() helper function - remove the /***/ lines between functions - do some style corrections Signed-off-by: Juergen Gross --- tools/xenstore/hashtable.c | 74 ++++++++++++++------------------------ tools/xenstore/hashtable.h | 10 ------ 2 files changed, 27 insertions(+), 57 deletions(-) diff --git a/tools/xenstore/hashtable.c b/tools/xenstore/hashtable.c index 1c8656e016..d312004d70 100644 --- a/tools/xenstore/hashtable.c +++ b/tools/xenstore/hashtable.c @@ -40,22 +40,25 @@ static const unsigned int primes[] =3D { 50331653, 100663319, 201326611, 402653189, 805306457, 1610612741 }; -const unsigned int prime_table_length =3D sizeof(primes)/sizeof(primes[0]); -const unsigned int max_load_factor =3D 65; /* percentage */ =20 -/*************************************************************************= ****/ -/* indexFor */ -static inline unsigned int -indexFor(unsigned int tablelength, unsigned int hashvalue) { +#define PRIME_TABLE_LEN ARRAY_SIZE(primes) +#define MAX_LOAD_PERCENT 65 + +static inline unsigned int indexFor(unsigned int tablelength, + unsigned int hashvalue) +{ return (hashvalue % tablelength); } =20 -/*************************************************************************= ****/ -struct hashtable * -create_hashtable(const void *ctx, unsigned int minsize, - unsigned int (*hashf) (void*), - int (*eqf) (void*,void*), - unsigned int flags) +static unsigned int loadlimit(unsigned int pindex) +{ + return ((uint64_t)primes[pindex] * MAX_LOAD_PERCENT) / 100; +} + +struct hashtable *create_hashtable(const void *ctx, unsigned int minsize, + unsigned int (*hashf) (void *), + int (*eqf) (void *,void *), + unsigned int flags) { struct hashtable *h; unsigned int pindex, size =3D primes[0]; @@ -64,7 +67,7 @@ create_hashtable(const void *ctx, unsigned int minsize, if (minsize > (1u << 30)) return NULL; =20 /* Enforce size as prime */ - for (pindex=3D0; pindex < prime_table_length; pindex++) { + for (pindex=3D0; pindex < PRIME_TABLE_LEN; pindex++) { if (primes[pindex] > minsize) { size =3D primes[pindex]; break; } } =20 @@ -81,7 +84,7 @@ create_hashtable(const void *ctx, unsigned int minsize, h->entrycount =3D 0; h->hashfn =3D hashf; h->eqfn =3D eqf; - h->loadlimit =3D (unsigned int)(((uint64_t)size * max_load_factor) = / 100); + h->loadlimit =3D loadlimit(pindex); return h; =20 err1: @@ -90,9 +93,7 @@ err0: return NULL; } =20 -/*************************************************************************= ****/ -unsigned int -hash(struct hashtable *h, void *k) +static unsigned int hash(struct hashtable *h, void *k) { /* Aim to protect against poor hash functions by adding logic here * - logic taken from java 1.4 hashtable source */ @@ -104,9 +105,7 @@ hash(struct hashtable *h, void *k) return i; } =20 -/*************************************************************************= ****/ -static int -hashtable_expand(struct hashtable *h) +static int hashtable_expand(struct hashtable *h) { /* Double the size of the table to accomodate more entries */ struct entry **newtable; @@ -114,7 +113,7 @@ hashtable_expand(struct hashtable *h) struct entry **pE; unsigned int newsize, i, index; /* Check we're not hitting max capacity */ - if (h->primeindex =3D=3D (prime_table_length - 1)) return 0; + if (h->primeindex =3D=3D (PRIME_TABLE_LEN - 1)) return 0; newsize =3D primes[++(h->primeindex)]; =20 newtable =3D talloc_realloc(h, h->table, struct entry *, newsize); @@ -144,21 +143,11 @@ hashtable_expand(struct hashtable *h) } =20 h->tablelength =3D newsize; - h->loadlimit =3D (unsigned int) - (((uint64_t)newsize * max_load_factor) / 100); + h->loadlimit =3D loadlimit(h->primeindex); return -1; } =20 -/*************************************************************************= ****/ -unsigned int -hashtable_count(struct hashtable *h) -{ - return h->entrycount; -} - -/*************************************************************************= ****/ -int -hashtable_insert(struct hashtable *h, void *k, void *v) +int hashtable_insert(struct hashtable *h, void *k, void *v) { /* This method allows duplicate keys - but they shouldn't be used */ unsigned int index; @@ -182,9 +171,7 @@ hashtable_insert(struct hashtable *h, void *k, void *v) return -1; } =20 -/*************************************************************************= ****/ -void * /* returns value associated with key */ -hashtable_search(struct hashtable *h, void *k) +void *hashtable_search(struct hashtable *h, void *k) { struct entry *e; unsigned int hashvalue, index; @@ -200,9 +187,7 @@ hashtable_search(struct hashtable *h, void *k) return NULL; } =20 -/*************************************************************************= ****/ -void * /* returns value associated with key */ -hashtable_remove(struct hashtable *h, void *k) +void *hashtable_remove(struct hashtable *h, void *k) { /* TODO: consider compacting the table when the load factor drops enou= gh, * or provide a 'compact' method. */ @@ -235,10 +220,8 @@ hashtable_remove(struct hashtable *h, void *k) return NULL; } =20 -/*************************************************************************= ****/ -int -hashtable_iterate(struct hashtable *h, - int (*func)(void *k, void *v, void *arg), void *arg) +int hashtable_iterate(struct hashtable *h, + int (*func)(void *k, void *v, void *arg), void *arg) { int ret; unsigned int i; @@ -261,10 +244,7 @@ hashtable_iterate(struct hashtable *h, return 0; } =20 -/*************************************************************************= ****/ -/* destroy */ -void -hashtable_destroy(struct hashtable *h) +void hashtable_destroy(struct hashtable *h) { unsigned int i; struct entry *e; diff --git a/tools/xenstore/hashtable.h b/tools/xenstore/hashtable.h index 07fdc1a82b..f1caef0d4f 100644 --- a/tools/xenstore/hashtable.h +++ b/tools/xenstore/hashtable.h @@ -75,16 +75,6 @@ hashtable_search(struct hashtable *h, void *k); void * /* returns value */ hashtable_remove(struct hashtable *h, void *k); =20 -/*************************************************************************= **** - * hashtable_count - =20 - * @name hashtable_count - * @param h the hashtable - * @return the number of items stored in the hashtable - */ -unsigned int -hashtable_count(struct hashtable *h); - /*************************************************************************= **** * hashtable_iterate =20 --=20 2.35.3 From nobody Fri May 17 03:12:53 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=1667319336; cv=none; d=zohomail.com; s=zohoarc; b=ML0B1ynEqN9DsVS3ud82MwnHoBfynWAOfYpks0msglBreqr/uNedOI7zFGxzA569i0K1JhhYXm6vhxC8k54ZN29eCCtVugxY4R1BYEjXUC4JfBbRz0mwDQAvC9bryrEguKYCJnDAd15342AyBzlRcyGQmMIbvURdWpe4EFpaVis= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1667319336; 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=ePljyH5jlUhgLAg8XDkia2Vo0lFqj2Qpdrf2FB4EPzU=; b=K68MEYn/A6I8kushLWMX/A03TYBcHatXbYXrZUw8hVE5YusYtfr0seaoQ8mT1//rrxjoyblUwyf8uvXG7FM81t7OF/ra1u19INqYYGy0AA3VtZyl+238rP+oKkFEXwKxuIVV6kptwB5dO90VBqLkXtHW2eTnq+a80aGddALIRbk= 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 1667319336521634.9770777303514; Tue, 1 Nov 2022 09:15:36 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.435084.688163 (Exim 4.92) (envelope-from ) id 1optv5-0002vo-Uw; Tue, 01 Nov 2022 16:15:19 +0000 Received: by outflank-mailman (output) from mailman id 435084.688163; Tue, 01 Nov 2022 16: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 1optv5-0002vU-S0; Tue, 01 Nov 2022 16:15:19 +0000 Received: by outflank-mailman (input) for mailman id 435084; Tue, 01 Nov 2022 16:15:18 +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 1optv4-0000i5-0L for xen-devel@lists.xenproject.org; Tue, 01 Nov 2022 16:15:18 +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 5f893797-5a00-11ed-8fd0-01056ac49cbb; Tue, 01 Nov 2022 17:15: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-out2.suse.de (Postfix) with ESMTPS id AE73D1F90F; Tue, 1 Nov 2022 16:15:16 +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 7EDF41346F; Tue, 1 Nov 2022 16:15:16 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id PHilHRRGYWMtdwAAMHmgww (envelope-from ); Tue, 01 Nov 2022 16:15:16 +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: 5f893797-5a00-11ed-8fd0-01056ac49cbb DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1667319316; 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=ePljyH5jlUhgLAg8XDkia2Vo0lFqj2Qpdrf2FB4EPzU=; b=KGxM5llsacI35uOqsmNhcEZhS/uWRSdQhPmi6hi/EOUtXVNP6dTXi/+gv9A516MZo3uqat HDKcN7WyMEqmUvXEGFJyQPbC9oBIEvoRjKo+Cxix4Bd/ItrzMO7SsJqcqycf7FJx6TwsIS V4d+xVt278CTw05khGNw+C4W/BywrZg= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Julien Grall , Anthony PERARD Subject: [PATCH 03/10] tools/xenstore: modify interface of create_hashtable() Date: Tue, 1 Nov 2022 17:14:50 +0100 Message-Id: <20221101161457.8470-4-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20221101161457.8470-1-jgross@suse.com> References: <20221101161457.8470-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1667319337079100001 Content-Type: text/plain; charset="utf-8" The minsize parameter of create_hashtable() doesn't have any real use case for Xenstore, so drop it. For better talloc_report_full() diagnostic output add a name parameter to create_hashtable(). Signed-off-by: Juergen Gross --- tools/xenstore/hashtable.c | 24 ++++++++---------------- tools/xenstore/hashtable.h | 4 ++-- tools/xenstore/xenstored_core.c | 2 +- tools/xenstore/xenstored_domain.c | 4 ++-- 4 files changed, 13 insertions(+), 21 deletions(-) diff --git a/tools/xenstore/hashtable.c b/tools/xenstore/hashtable.c index d312004d70..43a8caab82 100644 --- a/tools/xenstore/hashtable.c +++ b/tools/xenstore/hashtable.c @@ -55,36 +55,28 @@ static unsigned int loadlimit(unsigned int pindex) return ((uint64_t)primes[pindex] * MAX_LOAD_PERCENT) / 100; } =20 -struct hashtable *create_hashtable(const void *ctx, unsigned int minsize, - unsigned int (*hashf) (void *), - int (*eqf) (void *,void *), +struct hashtable *create_hashtable(const void *ctx, const char *name, + unsigned int (*hashf) (void*), + int (*eqf) (void*,void*), unsigned int flags) { struct hashtable *h; - unsigned int pindex, size =3D primes[0]; - - /* Check requested hashtable isn't too large */ - if (minsize > (1u << 30)) return NULL; - - /* Enforce size as prime */ - for (pindex=3D0; pindex < PRIME_TABLE_LEN; pindex++) { - if (primes[pindex] > minsize) { size =3D primes[pindex]; break; } - } =20 h =3D talloc_zero(ctx, struct hashtable); if (NULL =3D=3D h) goto err0; - h->table =3D talloc_zero_array(h, struct entry *, size); + talloc_set_name_const(h, name); + h->table =3D talloc_zero_array(h, struct entry *, primes[0]); if (NULL =3D=3D h->table) goto err1; =20 - h->tablelength =3D size; + h->tablelength =3D primes[0]; h->flags =3D flags; - h->primeindex =3D pindex; + h->primeindex =3D 0; h->entrycount =3D 0; h->hashfn =3D hashf; h->eqfn =3D eqf; - h->loadlimit =3D loadlimit(pindex); + h->loadlimit =3D loadlimit(0); return h; =20 err1: diff --git a/tools/xenstore/hashtable.h b/tools/xenstore/hashtable.h index f1caef0d4f..5575f6c1dd 100644 --- a/tools/xenstore/hashtable.h +++ b/tools/xenstore/hashtable.h @@ -10,7 +10,7 @@ struct hashtable; =20 * @name create_hashtable * @param ctx talloc context to use for allocations - * @param minsize minimum initial size of hashtable + * @param name talloc name of the hashtable * @param hashfunction function for hashing keys * @param key_eq_fn function for determining key equality * @param flags flags HASHTABLE_* @@ -23,7 +23,7 @@ struct hashtable; #define HASHTABLE_FREE_KEY (1U << 1) =20 struct hashtable * -create_hashtable(const void *ctx, unsigned int minsize, +create_hashtable(const void *ctx, const char *name, 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 714841d9ca..c4d9d275be 100644 --- a/tools/xenstore/xenstored_core.c +++ b/tools/xenstore/xenstored_core.c @@ -2502,7 +2502,7 @@ void check_store(void) struct check_store_data data; =20 /* Don't free values (they are all void *1) */ - data.reachable =3D create_hashtable(NULL, 16, hash_from_key_fn, + data.reachable =3D create_hashtable(NULL, "checkstore", hash_from_key_fn, keys_equal_fn, HASHTABLE_FREE_KEY); if (!data.reachable) { log("check_store: ENOMEM"); diff --git a/tools/xenstore/xenstored_domain.c b/tools/xenstore/xenstored_d= omain.c index 1f746afd70..b3c288bf40 100644 --- a/tools/xenstore/xenstored_domain.c +++ b/tools/xenstore/xenstored_domain.c @@ -1020,7 +1020,7 @@ void domain_init(int evtfd) int rc; =20 /* Start with a random rather low domain count for the hashtable. */ - domhash =3D create_hashtable(NULL, 8, domhash_fn, domeq_fn, 0); + domhash =3D create_hashtable(NULL, "domains", domhash_fn, domeq_fn, 0); if (!domhash) barf_perror("Failed to allocate domain hashtable"); =20 @@ -1798,7 +1798,7 @@ struct hashtable *domain_check_acc_init(void) { struct hashtable *domains; =20 - domains =3D create_hashtable(NULL, 8, domhash_fn, domeq_fn, + domains =3D create_hashtable(NULL, "domain_check", domhash_fn, domeq_fn, HASHTABLE_FREE_VALUE); if (!domains) return NULL; --=20 2.35.3 From nobody Fri May 17 03:12:53 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=1667319340; cv=none; d=zohomail.com; s=zohoarc; b=kc76DwmMJRsYbA/Rpe9kbhNJf8NnWwhzOrflCoZlHMk3yUMBTXuBWvXfovUg5MyMovpahiw10RRH5K8MPlLEOyO4zMDzCnNS7J2aK8igXp/NJCHNFHOJ1TZR8u6BzbaVkkeelb5dPMP9XZkFH+WSOO4Dwt8wfihuSG5yN9UuT9k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1667319340; 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=wkI1F2q0wuo3k02I3w30xmcUIYPftf6mWJLCe27OacU=; b=JCukB4Yz3+6tJ/7u6vb2EQxIIr+zUYIiqSieuroP+srvnkMSTrvIeOjoFOBS2qLtDncu80wu4b1WdRO6eegGUrnB5oA7pOju+hefyV6yXuApPNatqeKJv71rrtpEwXjjG59Tx3g3z56cCmUd6sIJPvTbr6LaDCw0jh+N2JHdwRg= 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 1667319340805956.1380733483677; Tue, 1 Nov 2022 09:15:40 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.435090.688196 (Exim 4.92) (envelope-from ) id 1optvB-000467-5k; Tue, 01 Nov 2022 16:15:25 +0000 Received: by outflank-mailman (output) from mailman id 435090.688196; Tue, 01 Nov 2022 16:15:25 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1optvA-00044X-UX; Tue, 01 Nov 2022 16:15:24 +0000 Received: by outflank-mailman (input) for mailman id 435090; Tue, 01 Nov 2022 16:15:23 +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 1optv9-0000i5-AG for xen-devel@lists.xenproject.org; Tue, 01 Nov 2022 16:15:23 +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 62dddeb9-5a00-11ed-8fd0-01056ac49cbb; Tue, 01 Nov 2022 17:15:22 +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 4904E3382E; Tue, 1 Nov 2022 16:15: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 1CF4A1346F; Tue, 1 Nov 2022 16:15:22 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 30vABRpGYWNCdwAAMHmgww (envelope-from ); Tue, 01 Nov 2022 16:15: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: 62dddeb9-5a00-11ed-8fd0-01056ac49cbb DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1667319322; 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=wkI1F2q0wuo3k02I3w30xmcUIYPftf6mWJLCe27OacU=; b=UTcOeQTSFT9SOojEBqDhJP0nJ6RXmzODIkVf9DxuMqnQYqzAy2gWNtsAMPc0ocFA7GFAv2 1pxrKEuzJ6pKP6gjBHrYbetw/ISTcpdzr54LfJKeWsaz+ue4JAZRZcA52TgDMFsTpJHezh BgXJmzbhGPeEW8V4brzn7b4GSeC523I= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Julien Grall , Anthony PERARD Subject: [PATCH 04/10] tools/xenstore: let hashtable_insert() return 0 on success Date: Tue, 1 Nov 2022 17:14:51 +0100 Message-Id: <20221101161457.8470-5-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20221101161457.8470-1-jgross@suse.com> References: <20221101161457.8470-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1667319341211100001 Content-Type: text/plain; charset="utf-8" Today hashtable_insert() returns 0 in case of an error. Change that to let it return an errno value in the error case and 0 in case of success. Even if not used today, do the same switch for the return value of hashtable_expand(). Signed-off-by: Juergen Gross --- tools/xenstore/hashtable.c | 15 ++++++++++----- tools/xenstore/hashtable.h | 2 +- tools/xenstore/xenstored_core.c | 4 ++-- tools/xenstore/xenstored_domain.c | 4 ++-- tools/xenstore/xenstored_transaction.c | 4 ++-- 5 files changed, 17 insertions(+), 12 deletions(-) diff --git a/tools/xenstore/hashtable.c b/tools/xenstore/hashtable.c index 43a8caab82..1bed5ad384 100644 --- a/tools/xenstore/hashtable.c +++ b/tools/xenstore/hashtable.c @@ -105,14 +105,15 @@ static int hashtable_expand(struct hashtable *h) struct entry **pE; unsigned int newsize, i, index; /* Check we're not hitting max capacity */ - if (h->primeindex =3D=3D (PRIME_TABLE_LEN - 1)) return 0; + if (h->primeindex =3D=3D (PRIME_TABLE_LEN - 1)) + return ENOSPC; newsize =3D primes[++(h->primeindex)]; =20 newtable =3D talloc_realloc(h, h->table, struct entry *, newsize); if (!newtable) { h->primeindex--; - return 0; + return ENOMEM; } =20 h->table =3D newtable; @@ -136,7 +137,7 @@ static int hashtable_expand(struct hashtable *h) =20 h->tablelength =3D newsize; h->loadlimit =3D loadlimit(h->primeindex); - return -1; + return 0; } =20 int hashtable_insert(struct hashtable *h, void *k, void *v) @@ -153,14 +154,18 @@ int hashtable_insert(struct hashtable *h, void *k, vo= id *v) hashtable_expand(h); } e =3D talloc_zero(h, struct entry); - if (NULL =3D=3D e) { --(h->entrycount); return 0; } /*oom*/ + if (NULL =3D=3D e) + { + --h->entrycount; + return ENOMEM; + } e->h =3D hash(h,k); index =3D indexFor(h->tablelength,e->h); e->k =3D k; e->v =3D v; e->next =3D h->table[index]; h->table[index] =3D e; - return -1; + return 0; } =20 void *hashtable_search(struct hashtable *h, void *k) diff --git a/tools/xenstore/hashtable.h b/tools/xenstore/hashtable.h index 5575f6c1dd..99a8331bec 100644 --- a/tools/xenstore/hashtable.h +++ b/tools/xenstore/hashtable.h @@ -36,7 +36,7 @@ create_hashtable(const void *ctx, const char *name, * @param h the hashtable to insert into * @param k the key - hashtable claims ownership and will free on remo= val * @param v the value - does not claim ownership - * @return non-zero for successful insertion + * @return zero for successful insertion * * This function will cause the table to expand if the insertion would take * the ratio of entries to table size over the maximum load factor. diff --git a/tools/xenstore/xenstored_core.c b/tools/xenstore/xenstored_cor= e.c index c4d9d275be..5d35925ed8 100644 --- a/tools/xenstore/xenstored_core.c +++ b/tools/xenstore/xenstored_core.c @@ -2385,7 +2385,7 @@ int remember_string(struct hashtable *hash, const cha= r *str) char *k =3D talloc_strdup(NULL, str); =20 if (!k) - return 0; + return ENOMEM; return hashtable_insert(hash, k, (void *)1); } =20 @@ -2419,7 +2419,7 @@ static int check_store_step(const void *ctx, struct c= onnection *conn, : WALK_TREE_SKIP_CHILDREN; } =20 - if (!remember_string(data->reachable, node->name)) + if (remember_string(data->reachable, node->name)) return WALK_TREE_ERROR_STOP; =20 domain_check_acc_add(node, data->domains); diff --git a/tools/xenstore/xenstored_domain.c b/tools/xenstore/xenstored_d= omain.c index b3c288bf40..f871bdf04a 100644 --- a/tools/xenstore/xenstored_domain.c +++ b/tools/xenstore/xenstored_domain.c @@ -542,7 +542,7 @@ static struct domain *alloc_domain(const void *context,= unsigned int domid) domain->generation =3D generation; domain->introduced =3D false; =20 - if (!hashtable_insert(domhash, &domain->domid, domain)) { + if (hashtable_insert(domhash, &domain->domid, domain)) { talloc_free(domain); errno =3D ENOMEM; return NULL; @@ -1786,7 +1786,7 @@ static int domain_check_acc_init_sub(void *k, void *v= , void *arg) */ dom->nodes =3D -d->acc[ACC_NODES].val; =20 - if (!hashtable_insert(domains, &dom->domid, dom)) { + if (hashtable_insert(domains, &dom->domid, dom)) { talloc_free(dom); return -1; } diff --git a/tools/xenstore/xenstored_transaction.c b/tools/xenstore/xensto= red_transaction.c index 13fabe030d..7b2e78f104 100644 --- a/tools/xenstore/xenstored_transaction.c +++ b/tools/xenstore/xenstored_transaction.c @@ -588,13 +588,13 @@ int check_transactions(struct hashtable *hash) list_for_each_entry(trans, &conn->transaction_list, list) { tname =3D talloc_asprintf(trans, "%"PRIu64, trans->generation); - if (!tname || !remember_string(hash, tname)) + if (!tname || remember_string(hash, tname)) goto nomem; =20 list_for_each_entry(i, &trans->accessed, list) { if (!i->ta_node) continue; - if (!remember_string(hash, i->trans_name)) + if (remember_string(hash, i->trans_name)) goto nomem; } =20 --=20 2.35.3 From nobody Fri May 17 03:12:53 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=1667319350; cv=none; d=zohomail.com; s=zohoarc; b=RD7zSvNgpk471gmMGH6zScrL5EAz+jhx5Bzio9kVSFU1iQTWcjWNZv/l+sPxwWue751oWgea8d4vghqrYsPe3uYEplaJ/ctkBOA0SNbyLHer5OF6nCVaqnyup6IljBCKtPaRqVK1Ge1/xE+yVIKSgMbJvaYJQVbkXasa54s+FDQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1667319350; 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=R7SNA0TjbXqw84TAvx2L4UOdxld+IGgbLt1a5t0hQVU=; b=TArmnrWLvmKrPNopXeDI5zeGqCySyUlIp8lIEGvR1zJGWaaJna/5tAXCaT0ssvwlDdL3TH6UnCH9KLwIZCywPgNmmmA8OySazYDvMHfhKdTo6N01WICTo28XBy5+sDWvxZXGppH2V8aoMm74SM+EVM+epwGiNjJO7V446JC52Tc= 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 1667319350185598.1989144620726; Tue, 1 Nov 2022 09:15:50 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.435095.688207 (Exim 4.92) (envelope-from ) id 1optvH-0004z5-Fx; Tue, 01 Nov 2022 16:15:31 +0000 Received: by outflank-mailman (output) from mailman id 435095.688207; Tue, 01 Nov 2022 16:15:31 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1optvH-0004yq-CG; Tue, 01 Nov 2022 16:15:31 +0000 Received: by outflank-mailman (input) for mailman id 435095; Tue, 01 Nov 2022 16:15: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 1optvF-0000yH-8v for xen-devel@lists.xenproject.org; Tue, 01 Nov 2022 16:15:29 +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 662faff1-5a00-11ed-91b5-6bf2151ebd3b; Tue, 01 Nov 2022 17:15: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-out1.suse.de (Postfix) with ESMTPS id D3BAF3382E; Tue, 1 Nov 2022 16:15:27 +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 A031E1346F; Tue, 1 Nov 2022 16:15:27 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id mjLRJR9GYWNKdwAAMHmgww (envelope-from ); Tue, 01 Nov 2022 16:15:27 +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: 662faff1-5a00-11ed-91b5-6bf2151ebd3b DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1667319327; 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=R7SNA0TjbXqw84TAvx2L4UOdxld+IGgbLt1a5t0hQVU=; b=bZAuQg/e1wdVIjlcMwpvW7DNycqex9ZABU2aAOblEY9Ok1NLH22xsBs/viLsa/AJJs0XPg pSIAMNsSq/9B4+TJt2Agi4z80qkDLrh4zxXfKJlwPcdyk75MgZcUB581v7+i3Y3gxdfxAw Kymk2gDfWtQPKs8NjUNvy1hcrHvuhBg= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Julien Grall , Anthony PERARD Subject: [PATCH 05/10] tools/xenstore: make some write limit functions static Date: Tue, 1 Nov 2022 17:14:52 +0100 Message-Id: <20221101161457.8470-6-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20221101161457.8470-1-jgross@suse.com> References: <20221101161457.8470-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1667319351340100001 Content-Type: text/plain; charset="utf-8" Some wrl_*() functions are only used in xenstored_domain.c, so make them static. In order to avoid the need of forward declarations, move the whole function block to the start of the file. Signed-off-by: Juergen Gross --- tools/xenstore/xenstored_domain.c | 456 +++++++++++++++--------------- tools/xenstore/xenstored_domain.h | 3 - 2 files changed, 228 insertions(+), 231 deletions(-) diff --git a/tools/xenstore/xenstored_domain.c b/tools/xenstore/xenstored_d= omain.c index f871bdf04a..559687a9d9 100644 --- a/tools/xenstore/xenstored_domain.c +++ b/tools/xenstore/xenstored_domain.c @@ -157,6 +157,234 @@ struct changed_domain =20 static struct hashtable *domhash; =20 +static wrl_creditt wrl_config_writecost =3D WRL_FACTOR; +static wrl_creditt wrl_config_rate =3D WRL_RATE * WRL_FACTOR; +static wrl_creditt wrl_config_dburst =3D WRL_DBURST * WRL_FACTOR; +static wrl_creditt wrl_config_gburst =3D WRL_GBURST * WRL_FACTOR; +static wrl_creditt wrl_config_newdoms_dburst =3D + WRL_DBURST * WRL_NEWDOMS * WRL_FACTOR; + +long wrl_ntransactions; + +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 */ + +#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; + int r; + + r =3D clock_gettime(CLOCK_MONOTONIC, &now_ts); + if (r) + barf_perror("Could not find time (clock_gettime failed)"); + + now_wt->sec =3D now_ts.tv_sec; + now_wt->msec =3D now_ts.tv_nsec / 1000000; +} + +static void wrl_xfer_credit(wrl_creditt *debit, wrl_creditt debit_floor, + wrl_creditt *credit, wrl_creditt credit_ceil) + /* + * Transfers zero or more credit from "debit" to "credit". + * Transfers as much as possible while maintaining + * debit >=3D debit_floor and credit <=3D credit_ceil. + * (If that's violated already, does nothing.) + * + * Sufficient conditions to avoid overflow, either of: + * |every argument| <=3D 0x3fffffff + * |every argument| <=3D 1E9 + * |every argument| <=3D WRL_CREDIT_MAX + * (And this condition is preserved.) + */ +{ + wrl_creditt xfer =3D MIN( *debit - debit_floor, + credit_ceil - *credit ); + if (xfer > 0) { + *debit -=3D xfer; + *credit +=3D xfer; + } +} + +static void wrl_domain_new(struct domain *domain) +{ + domain->wrl_credit =3D 0; + wrl_gettime_now(&domain->wrl_timestamp); + wrl_ndomains++; + /* Steal up to DBURST from the reserve */ + wrl_xfer_credit(&wrl_reserve, -wrl_config_newdoms_dburst, + &domain->wrl_credit, wrl_config_dburst); +} + +static void wrl_domain_destroy(struct domain *domain) +{ + wrl_ndomains--; + /* + * Don't bother recalculating domain's credit - this just + * means we don't give the reserve the ending domain's credit + * for time elapsed since last update. + */ + wrl_xfer_credit(&domain->wrl_credit, 0, + &wrl_reserve, wrl_config_dburst); +} + +static void wrl_credit_update(struct domain *domain, struct wrl_timestampt= now) +{ + /* + * We want to calculate + * credit +=3D (now - timestamp) * RATE / ndoms; + * But we want it to saturate, and to avoid floating point. + * To avoid rounding errors from constantly adding small + * amounts of credit, we only add credit for whole milliseconds. + */ + long seconds =3D now.sec - domain->wrl_timestamp.sec; + long milliseconds =3D now.msec - domain->wrl_timestamp.msec; + long msec; + int64_t denom, num; + wrl_creditt surplus; + + seconds =3D MIN(seconds, 1000*1000); /* arbitrary, prevents overflow */ + msec =3D seconds * 1000 + milliseconds; + + if (msec < 0) + /* shouldn't happen with CLOCK_MONOTONIC */ + msec =3D 0; + + /* 32x32 -> 64 cannot overflow */ + denom =3D (int64_t)msec * wrl_config_rate; + num =3D (int64_t)wrl_ndomains * 1000; + /* denom / num <=3D 1E6 * wrl_config_rate, so with + reasonable wrl_config_rate, denom / num << 2^64 */ + + /* at last! */ + domain->wrl_credit =3D MIN( (int64_t)domain->wrl_credit + denom / num, + WRL_CREDIT_MAX ); + /* (maybe briefly violating the DBURST cap on wrl_credit) */ + + /* maybe take from the reserve to make us nonnegative */ + wrl_xfer_credit(&wrl_reserve, 0, + &domain->wrl_credit, 0); + + /* return any surplus (over DBURST) to the reserve */ + surplus =3D 0; + wrl_xfer_credit(&domain->wrl_credit, wrl_config_dburst, + &surplus, WRL_CREDIT_MAX); + wrl_xfer_credit(&surplus, 0, + &wrl_reserve, wrl_config_gburst); + /* surplus is now implicitly discarded */ + + domain->wrl_timestamp =3D now; + + 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); +} + +void wrl_check_timeout(struct domain *domain, + struct wrl_timestampt now, + int *ptimeout) +{ + uint64_t num, denom; + int wakeup; + + wrl_credit_update(domain, now); + + if (domain->wrl_credit >=3D 0) + /* not blocked */ + return; + + if (!*ptimeout) + /* already decided on immediate wakeup, + so no need to calculate our timeout */ + return; + + /* calculate wakeup =3D now + -credit / (RATE / ndoms); */ + + /* credit cannot go more -ve than one transaction, + * so the first multiplication cannot overflow even 32-bit */ + num =3D (uint64_t)(-domain->wrl_credit * 1000) * wrl_ndomains; + denom =3D wrl_config_rate; + + wakeup =3D MIN( num / denom /* uint64_t */, INT_MAX ); + if (*ptimeout=3D=3D-1 || wakeup < *ptimeout) + *ptimeout =3D 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); +} + +#define WRL_LOG(now, ...) \ + (syslog(LOG_WARNING, "write rate limit: " __VA_ARGS__)) + +void wrl_apply_debit_actual(struct domain *domain) +{ + struct wrl_timestampt now; + + if (!domain || !domain_is_unprivileged(domain->conn)) + /* sockets and privileged domain escape the write rate limit */ + return; + + wrl_gettime_now(&now); + wrl_credit_update(domain, now); + + 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); + + if (domain->wrl_credit < 0) { + if (!domain->wrl_delay_logged) { + domain->wrl_delay_logged =3D true; + WRL_LOG(now, "domain %ld is affected\n", + (long)domain->domid); + } else if (!wrl_log_last_warning) { + WRL_LOG(now, "rate limiting restarts\n"); + } + wrl_log_last_warning =3D now.sec; + } +} + +void wrl_log_periodic(struct wrl_timestampt now) +{ + if (wrl_log_last_warning && + (now.sec - wrl_log_last_warning) > WRL_LOGEVERY) { + WRL_LOG(now, "not in force recently\n"); + wrl_log_last_warning =3D 0; + } +} + +void wrl_apply_debit_direct(struct connection *conn) +{ + if (!conn) + /* some writes are generated internally */ + return; + + if (conn->transaction) + /* these are accounted for when the transaction ends */ + return; + + if (!wrl_ntransactions) + /* we don't conflict with anyone */ + return; + + wrl_apply_debit_actual(conn->domain); +} + +void wrl_apply_debit_trans_commit(struct connection *conn) +{ + if (wrl_ntransactions <=3D 1) + /* our own transaction appears in the counter */ + return; + + wrl_apply_debit_actual(conn->domain); +} + static bool check_indexes(XENSTORE_RING_IDX cons, XENSTORE_RING_IDX prod) { return ((prod - cons) <=3D XENSTORE_RING_SIZE); @@ -1437,234 +1665,6 @@ unsigned int domain_transaction_get(struct connecti= on *conn) : 0; } =20 -static wrl_creditt wrl_config_writecost =3D WRL_FACTOR; -static wrl_creditt wrl_config_rate =3D WRL_RATE * WRL_FACTOR; -static wrl_creditt wrl_config_dburst =3D WRL_DBURST * WRL_FACTOR; -static wrl_creditt wrl_config_gburst =3D WRL_GBURST * WRL_FACTOR; -static wrl_creditt wrl_config_newdoms_dburst =3D - WRL_DBURST * WRL_NEWDOMS * WRL_FACTOR; - -long wrl_ntransactions; - -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 */ - -#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; - int r; - - r =3D clock_gettime(CLOCK_MONOTONIC, &now_ts); - if (r) - barf_perror("Could not find time (clock_gettime failed)"); - - now_wt->sec =3D now_ts.tv_sec; - now_wt->msec =3D now_ts.tv_nsec / 1000000; -} - -static void wrl_xfer_credit(wrl_creditt *debit, wrl_creditt debit_floor, - wrl_creditt *credit, wrl_creditt credit_ceil) - /* - * Transfers zero or more credit from "debit" to "credit". - * Transfers as much as possible while maintaining - * debit >=3D debit_floor and credit <=3D credit_ceil. - * (If that's violated already, does nothing.) - * - * Sufficient conditions to avoid overflow, either of: - * |every argument| <=3D 0x3fffffff - * |every argument| <=3D 1E9 - * |every argument| <=3D WRL_CREDIT_MAX - * (And this condition is preserved.) - */ -{ - wrl_creditt xfer =3D MIN( *debit - debit_floor, - credit_ceil - *credit ); - if (xfer > 0) { - *debit -=3D xfer; - *credit +=3D xfer; - } -} - -void wrl_domain_new(struct domain *domain) -{ - domain->wrl_credit =3D 0; - wrl_gettime_now(&domain->wrl_timestamp); - wrl_ndomains++; - /* Steal up to DBURST from the reserve */ - wrl_xfer_credit(&wrl_reserve, -wrl_config_newdoms_dburst, - &domain->wrl_credit, wrl_config_dburst); -} - -void wrl_domain_destroy(struct domain *domain) -{ - wrl_ndomains--; - /* - * Don't bother recalculating domain's credit - this just - * means we don't give the reserve the ending domain's credit - * for time elapsed since last update. - */ - wrl_xfer_credit(&domain->wrl_credit, 0, - &wrl_reserve, wrl_config_dburst); -} - -void wrl_credit_update(struct domain *domain, struct wrl_timestampt now) -{ - /* - * We want to calculate - * credit +=3D (now - timestamp) * RATE / ndoms; - * But we want it to saturate, and to avoid floating point. - * To avoid rounding errors from constantly adding small - * amounts of credit, we only add credit for whole milliseconds. - */ - long seconds =3D now.sec - domain->wrl_timestamp.sec; - long milliseconds =3D now.msec - domain->wrl_timestamp.msec; - long msec; - int64_t denom, num; - wrl_creditt surplus; - - seconds =3D MIN(seconds, 1000*1000); /* arbitrary, prevents overflow */ - msec =3D seconds * 1000 + milliseconds; - - if (msec < 0) - /* shouldn't happen with CLOCK_MONOTONIC */ - msec =3D 0; - - /* 32x32 -> 64 cannot overflow */ - denom =3D (int64_t)msec * wrl_config_rate; - num =3D (int64_t)wrl_ndomains * 1000; - /* denom / num <=3D 1E6 * wrl_config_rate, so with - reasonable wrl_config_rate, denom / num << 2^64 */ - - /* at last! */ - domain->wrl_credit =3D MIN( (int64_t)domain->wrl_credit + denom / num, - WRL_CREDIT_MAX ); - /* (maybe briefly violating the DBURST cap on wrl_credit) */ - - /* maybe take from the reserve to make us nonnegative */ - wrl_xfer_credit(&wrl_reserve, 0, - &domain->wrl_credit, 0); - - /* return any surplus (over DBURST) to the reserve */ - surplus =3D 0; - wrl_xfer_credit(&domain->wrl_credit, wrl_config_dburst, - &surplus, WRL_CREDIT_MAX); - wrl_xfer_credit(&surplus, 0, - &wrl_reserve, wrl_config_gburst); - /* surplus is now implicitly discarded */ - - domain->wrl_timestamp =3D now; - - 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); -} - -void wrl_check_timeout(struct domain *domain, - struct wrl_timestampt now, - int *ptimeout) -{ - uint64_t num, denom; - int wakeup; - - wrl_credit_update(domain, now); - - if (domain->wrl_credit >=3D 0) - /* not blocked */ - return; - - if (!*ptimeout) - /* already decided on immediate wakeup, - so no need to calculate our timeout */ - return; - - /* calculate wakeup =3D now + -credit / (RATE / ndoms); */ - - /* credit cannot go more -ve than one transaction, - * so the first multiplication cannot overflow even 32-bit */ - num =3D (uint64_t)(-domain->wrl_credit * 1000) * wrl_ndomains; - denom =3D wrl_config_rate; - - wakeup =3D MIN( num / denom /* uint64_t */, INT_MAX ); - if (*ptimeout=3D=3D-1 || wakeup < *ptimeout) - *ptimeout =3D 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); -} - -#define WRL_LOG(now, ...) \ - (syslog(LOG_WARNING, "write rate limit: " __VA_ARGS__)) - -void wrl_apply_debit_actual(struct domain *domain) -{ - struct wrl_timestampt now; - - if (!domain || !domid_is_unprivileged(domain->domid)) - /* sockets and privileged domain escape the write rate limit */ - return; - - wrl_gettime_now(&now); - wrl_credit_update(domain, now); - - 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); - - if (domain->wrl_credit < 0) { - if (!domain->wrl_delay_logged) { - domain->wrl_delay_logged =3D true; - WRL_LOG(now, "domain %ld is affected\n", - (long)domain->domid); - } else if (!wrl_log_last_warning) { - WRL_LOG(now, "rate limiting restarts\n"); - } - wrl_log_last_warning =3D now.sec; - } -} - -void wrl_log_periodic(struct wrl_timestampt now) -{ - if (wrl_log_last_warning && - (now.sec - wrl_log_last_warning) > WRL_LOGEVERY) { - WRL_LOG(now, "not in force recently\n"); - wrl_log_last_warning =3D 0; - } -} - -void wrl_apply_debit_direct(struct connection *conn) -{ - if (!conn) - /* some writes are generated internally */ - return; - - if (conn->transaction) - /* these are accounted for when the transaction ends */ - return; - - if (!wrl_ntransactions) - /* we don't conflict with anyone */ - return; - - wrl_apply_debit_actual(conn->domain); -} - -void wrl_apply_debit_trans_commit(struct connection *conn) -{ - if (wrl_ntransactions <=3D 1) - /* our own transaction appears in the counter */ - return; - - wrl_apply_debit_actual(conn->domain); -} - const char *dump_state_connections(FILE *fp) { const char *ret =3D NULL; diff --git a/tools/xenstore/xenstored_domain.h b/tools/xenstore/xenstored_d= omain.h index 1d11085ebc..b691a28778 100644 --- a/tools/xenstore/xenstored_domain.h +++ b/tools/xenstore/xenstored_domain.h @@ -152,9 +152,6 @@ struct wrl_timestampt { extern long wrl_ntransactions; =20 void wrl_gettime_now(struct wrl_timestampt *now_ts); -void wrl_domain_new(struct domain *domain); -void wrl_domain_destroy(struct domain *domain); -void wrl_credit_update(struct domain *domain, struct wrl_timestampt now); void wrl_check_timeout(struct domain *domain, struct wrl_timestampt now, int *ptimeout); --=20 2.35.3 From nobody Fri May 17 03:12:53 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=1667319937; cv=none; d=zohomail.com; s=zohoarc; b=DgkWgAsS/FJLzTzODFL7yzY26JKAcCJyjxwkPFC2wqXLzoXF5TMhMMErVmPSSmP/8n+zJFXJEC8o7+x9W2Kj46WepMH1r5ZVfFreqieBJFvpnmNKSfgu5YdZg9dtO5ZDyNfjdFBA/+ueF6VYi7ZzmJG+OpUC+OMdouXICwVzBDM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1667319937; 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=rMRJEUOJ3aRwlNByoJe0UnjE1hGXLfxM7z6HnPQjpTg=; b=hPCI4ehpJ99S06CQva8Ku5dlvW9kqPwKQ5MDXRaJG792EaPyEKd0ro4NF4dVXgYMAGf2uES72K0C06SucvTc73LpGxhYiIhRUeYgxp4qW8zAmylqsW3s722XesRsLccP+nbpJuQEHRR7y2xscxcZXF+nGXWzjsylV7AtPEj+bRk= 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 1667319937211953.8534466816573; Tue, 1 Nov 2022 09:25:37 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.435122.688223 (Exim 4.92) (envelope-from ) id 1opu4d-0008QM-Rw; Tue, 01 Nov 2022 16:25:11 +0000 Received: by outflank-mailman (output) from mailman id 435122.688223; Tue, 01 Nov 2022 16:25:11 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1opu4d-0008Po-Mg; Tue, 01 Nov 2022 16:25:11 +0000 Received: by outflank-mailman (input) for mailman id 435122; Tue, 01 Nov 2022 16:25:10 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1optvM-0000i5-0k for xen-devel@lists.xenproject.org; Tue, 01 Nov 2022 16:15:36 +0000 Received: from smtp-out1.suse.de (smtp-out1.suse.de [2001:67c:2178:6::1c]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 698050f7-5a00-11ed-8fd0-01056ac49cbb; Tue, 01 Nov 2022 17:15:33 +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 68E353382E; Tue, 1 Nov 2022 16:15:33 +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 3D9D71346F; Tue, 1 Nov 2022 16:15:33 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id VJ3IDSVGYWNadwAAMHmgww (envelope-from ); Tue, 01 Nov 2022 16:15: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: 698050f7-5a00-11ed-8fd0-01056ac49cbb DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1667319333; 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=rMRJEUOJ3aRwlNByoJe0UnjE1hGXLfxM7z6HnPQjpTg=; b=LkklC2O/2gLEIwig1MTllAL6tTicHJ7NtHo8PBAN8jEL49AihkQQd7J+DP6H+blTCOKviS Hx3nLBbsoeYOS+g2NbyzWk9zUCt2mob6kgsEvL+/KGeotvPci/B2BUlkKIbuAtBDbsN9gm Dq3dhFT4k7NHl/pYyvaQDRpi4xZ7xdA= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Julien Grall , Anthony PERARD Subject: [PATCH 06/10] tools/xenstore: switch write limiting to use millisecond time base Date: Tue, 1 Nov 2022 17:14:53 +0100 Message-Id: <20221101161457.8470-7-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20221101161457.8470-1-jgross@suse.com> References: <20221101161457.8470-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1667319939342100003 Content-Type: text/plain; charset="utf-8" There is no need to keep struct wrl_timestampt, as it serves the same purpose as the more simple time base provided by get_now(). Move some more stuff from xenstored_domain.h into xenstored_domain.c as it is being used nowhere else. Signed-off-by: Juergen Gross --- tools/xenstore/xenstored_core.c | 8 ++--- tools/xenstore/xenstored_core.h | 7 ++-- tools/xenstore/xenstored_domain.c | 56 +++++++++++++------------------ tools/xenstore/xenstored_domain.h | 21 ++---------- 4 files changed, 32 insertions(+), 60 deletions(-) diff --git a/tools/xenstore/xenstored_core.c b/tools/xenstore/xenstored_cor= e.c index 5d35925ed8..5fcf96c77a 100644 --- a/tools/xenstore/xenstored_core.c +++ b/tools/xenstore/xenstored_core.c @@ -192,7 +192,7 @@ void reopen_log(void) } } =20 -static uint64_t get_now_msec(void) +uint64_t get_now_msec(void) { struct timespec now_ts; =20 @@ -510,7 +510,6 @@ fail: static void initialize_fds(int *p_sock_pollfd_idx, int *ptimeout) { struct connection *conn; - struct wrl_timestampt now; uint64_t msecs; =20 if (fds) @@ -530,13 +529,12 @@ static void initialize_fds(int *p_sock_pollfd_idx, in= t *ptimeout) xce_pollfd_idx =3D set_fd(xenevtchn_fd(xce_handle), POLLIN|POLLPRI); =20 - wrl_gettime_now(&now); - wrl_log_periodic(now); msecs =3D get_now_msec(); + wrl_log_periodic(msecs); =20 list_for_each_entry(conn, &connections, list) { if (conn->domain) { - wrl_check_timeout(conn->domain, now, ptimeout); + wrl_check_timeout(conn->domain, msecs, ptimeout); check_event_timeout(conn, msecs, ptimeout); if (conn_can_read(conn) || (conn_can_write(conn) && diff --git a/tools/xenstore/xenstored_core.h b/tools/xenstore/xenstored_cor= e.h index e3a987028a..ecfa987272 100644 --- a/tools/xenstore/xenstored_core.h +++ b/tools/xenstore/xenstored_core.h @@ -47,10 +47,6 @@ /* DEFAULT_BUFFER_SIZE should be large enough for each errno string. */ #define DEFAULT_BUFFER_SIZE 16 =20 -typedef int32_t wrl_creditt; -#define WRL_CREDIT_MAX (1000*1000*1000) -/* ^ satisfies non-overflow condition for wrl_xfer_credit */ - struct xs_state_connection; =20 struct buffered_data @@ -311,6 +307,9 @@ extern bool keep_orphans; =20 extern unsigned int timeout_watch_event_msec; =20 +/* Get internal time in milliseconds. */ +uint64_t get_now_msec(void); + /* Map the kernel's xenstore page. */ void *xenbus_map(void); void unmap_xenbus(void *interface); diff --git a/tools/xenstore/xenstored_domain.c b/tools/xenstore/xenstored_d= omain.c index 559687a9d9..329815ffc3 100644 --- a/tools/xenstore/xenstored_domain.c +++ b/tools/xenstore/xenstored_domain.c @@ -99,6 +99,8 @@ struct quota soft_quotas[ACC_N] =3D { }, }; =20 +typedef int32_t wrl_creditt; + struct domain { /* The id of this domain */ @@ -139,7 +141,7 @@ struct domain =20 /* write rate limit */ wrl_creditt wrl_credit; /* [ -wrl_config_writecost, +_dburst ] */ - struct wrl_timestampt wrl_timestamp; + uint64_t wrl_timestamp; bool wrl_delay_logged; }; =20 @@ -157,6 +159,17 @@ struct changed_domain =20 static struct hashtable *domhash; =20 +/* Write rate limiting */ + +/* Satisfies non-overflow condition for wrl_xfer_credit. */ +#define WRL_CREDIT_MAX (1000*1000*1000) +#define WRL_FACTOR 1000 /* for fixed-point arithmetic */ +#define WRL_RATE 200 +#define WRL_DBURST 10 +#define WRL_GBURST 1000 +#define WRL_NEWDOMS 5 +#define WRL_LOGEVERY 120 /* seconds */ + static wrl_creditt wrl_config_writecost =3D WRL_FACTOR; static wrl_creditt wrl_config_rate =3D WRL_RATE * WRL_FACTOR; static wrl_creditt wrl_config_dburst =3D WRL_DBURST * WRL_FACTOR; @@ -176,19 +189,6 @@ do { \ trace("wrl: " __VA_ARGS__); \ } while (0) =20 -void wrl_gettime_now(struct wrl_timestampt *now_wt) -{ - struct timespec now_ts; - int r; - - r =3D clock_gettime(CLOCK_MONOTONIC, &now_ts); - if (r) - barf_perror("Could not find time (clock_gettime failed)"); - - now_wt->sec =3D now_ts.tv_sec; - now_wt->msec =3D now_ts.tv_nsec / 1000000; -} - static void wrl_xfer_credit(wrl_creditt *debit, wrl_creditt debit_floor, wrl_creditt *credit, wrl_creditt credit_ceil) /* @@ -215,7 +215,7 @@ static void wrl_xfer_credit(wrl_creditt *debit, wrl_cr= editt debit_floor, static void wrl_domain_new(struct domain *domain) { domain->wrl_credit =3D 0; - wrl_gettime_now(&domain->wrl_timestamp); + domain->wrl_timestamp =3D get_now_msec(); wrl_ndomains++; /* Steal up to DBURST from the reserve */ wrl_xfer_credit(&wrl_reserve, -wrl_config_newdoms_dburst, @@ -234,7 +234,7 @@ static void wrl_domain_destroy(struct domain *domain) &wrl_reserve, wrl_config_dburst); } =20 -static void wrl_credit_update(struct domain *domain, struct wrl_timestampt= now) +static void wrl_credit_update(struct domain *domain, uint64_t now) { /* * We want to calculate @@ -243,18 +243,12 @@ static void wrl_credit_update(struct domain *domain, = struct wrl_timestampt now) * To avoid rounding errors from constantly adding small * amounts of credit, we only add credit for whole milliseconds. */ - long seconds =3D now.sec - domain->wrl_timestamp.sec; - long milliseconds =3D now.msec - domain->wrl_timestamp.msec; long msec; int64_t denom, num; wrl_creditt surplus; =20 - seconds =3D MIN(seconds, 1000*1000); /* arbitrary, prevents overflow */ - msec =3D seconds * 1000 + milliseconds; - - if (msec < 0) - /* shouldn't happen with CLOCK_MONOTONIC */ - msec =3D 0; + /* Prevent overflow by limiting to 32 bits. */ + msec =3D MIN(now - domain->wrl_timestamp, 1000 * 1000 * 1000); =20 /* 32x32 -> 64 cannot overflow */ denom =3D (int64_t)msec * wrl_config_rate; @@ -286,9 +280,7 @@ static void wrl_credit_update(struct domain *domain, st= ruct wrl_timestampt now) (long)wrl_reserve, (long)surplus); } =20 -void wrl_check_timeout(struct domain *domain, - struct wrl_timestampt now, - int *ptimeout) +void wrl_check_timeout(struct domain *domain, uint64_t now, int *ptimeout) { uint64_t num, denom; int wakeup; @@ -325,13 +317,13 @@ void wrl_check_timeout(struct domain *domain, =20 void wrl_apply_debit_actual(struct domain *domain) { - struct wrl_timestampt now; + uint64_t now; =20 if (!domain || !domain_is_unprivileged(domain->conn)) /* sockets and privileged domain escape the write rate limit */ return; =20 - wrl_gettime_now(&now); + now =3D get_now_msec(); wrl_credit_update(domain, now); =20 domain->wrl_credit -=3D wrl_config_writecost; @@ -346,14 +338,14 @@ void wrl_apply_debit_actual(struct domain *domain) } else if (!wrl_log_last_warning) { WRL_LOG(now, "rate limiting restarts\n"); } - wrl_log_last_warning =3D now.sec; + wrl_log_last_warning =3D now / 1000; } } =20 -void wrl_log_periodic(struct wrl_timestampt now) +void wrl_log_periodic(uint64_t now) { if (wrl_log_last_warning && - (now.sec - wrl_log_last_warning) > WRL_LOGEVERY) { + (now / 1000 - wrl_log_last_warning) > WRL_LOGEVERY) { WRL_LOG(now, "not in force recently\n"); wrl_log_last_warning =3D 0; } diff --git a/tools/xenstore/xenstored_domain.h b/tools/xenstore/xenstored_d= omain.h index b691a28778..1ab0a220f2 100644 --- a/tools/xenstore/xenstored_domain.h +++ b/tools/xenstore/xenstored_domain.h @@ -135,27 +135,10 @@ void domain_reset_global_acc(void); bool domain_max_chk(const struct connection *conn, unsigned int what, unsigned int val); =20 -/* Write rate limiting */ - -#define WRL_FACTOR 1000 /* for fixed-point arithmetic */ -#define WRL_RATE 200 -#define WRL_DBURST 10 -#define WRL_GBURST 1000 -#define WRL_NEWDOMS 5 -#define WRL_LOGEVERY 120 /* seconds */ - -struct wrl_timestampt { - time_t sec; - int msec; -}; - extern long wrl_ntransactions; =20 -void wrl_gettime_now(struct wrl_timestampt *now_ts); -void wrl_check_timeout(struct domain *domain, - struct wrl_timestampt now, - int *ptimeout); -void wrl_log_periodic(struct wrl_timestampt now); +void wrl_check_timeout(struct domain *domain, uint64_t now, int *ptimeout); +void wrl_log_periodic(uint64_t now); void wrl_apply_debit_direct(struct connection *conn); void wrl_apply_debit_trans_commit(struct connection *conn); =20 --=20 2.35.3 From nobody Fri May 17 03:12:53 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=1667319947; cv=none; d=zohomail.com; s=zohoarc; b=ctYwL+k9ZiKNgmTmzvSPXofWLvSBkaI/VtiLaePHa1Vj8QyOE/CbR0ivS4oy8zReXXFdPJfXri/fGsh7Ll2ZRdJrKJcWg/YbfDqMB92oNe2GAcf5z+U37DNNV6F2gO2nSWN6rKxUjH3JfG4mdkRv/+L4IV8PG1ajbQKv0pkMAxs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1667319947; 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=eAHb8+QFjd5pkkPNHRs46idZapdPvMHUccr3ff2r5Dk=; b=XhM7r/EA1gh5GicCvFNKlGSu4D+IDYTyndA5dj+bI9LxZLQMWCtR7t3Z6CcQE+Sd5AooaFALAYdjJYn6Eo+2TVd/KcqVoako7DksDANK2HoA0QPOPGAjSCCtOpRDZvolBB2FNxTLrUwS47BY7fdGUKWTxzRmqSeA/7BQvt4WtmE= 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 1667319947325820.0516497106678; Tue, 1 Nov 2022 09:25:47 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.435139.688262 (Exim 4.92) (envelope-from ) id 1opu4x-0001jM-0G; Tue, 01 Nov 2022 16:25:31 +0000 Received: by outflank-mailman (output) from mailman id 435139.688262; Tue, 01 Nov 2022 16:25:30 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1opu4w-0001j3-SR; Tue, 01 Nov 2022 16:25:30 +0000 Received: by outflank-mailman (input) for mailman id 435139; Tue, 01 Nov 2022 16:25:29 +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 1optvR-0000i5-19 for xen-devel@lists.xenproject.org; Tue, 01 Nov 2022 16:15:41 +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 6ccac263-5a00-11ed-8fd0-01056ac49cbb; Tue, 01 Nov 2022 17:15: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 E9ECD1F90F; Tue, 1 Nov 2022 16:15: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 BD6A51346F; Tue, 1 Nov 2022 16:15:38 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id aJTaLCpGYWN0dwAAMHmgww (envelope-from ); Tue, 01 Nov 2022 16:15:38 +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: 6ccac263-5a00-11ed-8fd0-01056ac49cbb DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1667319338; 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=eAHb8+QFjd5pkkPNHRs46idZapdPvMHUccr3ff2r5Dk=; b=FXS0hBgkIjRdmY+XZX/5I1lbxMmzyG9Z7+97+Rs1Qr1mN9bRIPa5kiPpwRZ61AT9PwWsh5 j4xCekkHPpCKyzn9DUUZGnp3gTlu1yjjIqZIIpLxcAG/vmCtZucKMk6umnOTHbDeGQk+b0 P71e/QkSBWeOsJnrDfdF+rB2HF4IYeM= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Julien Grall , Anthony PERARD Subject: [PATCH 07/10] tools/xenstore: remove stale TODO file Date: Tue, 1 Nov 2022 17:14:54 +0100 Message-Id: <20221101161457.8470-8-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20221101161457.8470-1-jgross@suse.com> References: <20221101161457.8470-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1667319949443100001 Content-Type: text/plain; charset="utf-8" The TODO file is not really helpful any longer. It contains only entries which no longer apply or it is unknown what they are meant for ("Dynamic/supply nodes", "Remove assumption that rename doesn't fail"). Signed-off-by: Juergen Gross --- tools/xenstore/TODO | 10 ---------- 1 file changed, 10 deletions(-) delete mode 100644 tools/xenstore/TODO diff --git a/tools/xenstore/TODO b/tools/xenstore/TODO deleted file mode 100644 index 71d5bbbf50..0000000000 --- a/tools/xenstore/TODO +++ /dev/null @@ -1,10 +0,0 @@ -TODO in no particular order. Some of these will never be done. There -are omissions of important but necessary things. It is up to the -reader to fill in the blanks. - -- Timeout failed watch responses -- Dynamic/supply nodes -- Persistant storage of introductions, watches and transactions, so daemon= can restart -- Remove assumption that rename doesn't fail -- Multi-root transactions, for setting up front and back ends at same time. - --=20 2.35.3 From nobody Fri May 17 03:12:53 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=1667319940; cv=none; d=zohomail.com; s=zohoarc; b=X/+wRu1Wu2ht90PWIVV2n8MuIJ9TtAsN6xvAmF9gwho4GUa9PpwCV/QsCmfYknBEDRMwW+rOuXm2wTDVg6ByKN2bAtxjTnExYQmn2B4rnCHmcMWhhFgsjhqDaSp4FtdDBV1dLKE9wsOqXRMRRXJlupYoqGsCQIoYv1y5HgTuYRQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1667319940; 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=IGeFv24ZPr/KZ3pFnNba31NdyHUcNMT973heFZoLWFU=; b=A66ilQvVXZNwOH3LBJktGbgOukC0bbBwuAQDBqql6stNnT9JLveo7Yob1ryRA1yao99iLr3k25yV/tl0LLHpt41V8gXDpwmeEWZ2R/bAYsCnle5Qx98uIHz/p3HSnn3wxAt1PMaZA8Pacol/TKKgy12ZeFv2W3ZV09T7xy7LG+8= 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 1667319940844456.4591424600487; Tue, 1 Nov 2022 09:25:40 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.435119.688218 (Exim 4.92) (envelope-from ) id 1opu4d-0008Oo-Jv; Tue, 01 Nov 2022 16:25:11 +0000 Received: by outflank-mailman (output) from mailman id 435119.688218; Tue, 01 Nov 2022 16:25:11 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1opu4d-0008Og-FF; Tue, 01 Nov 2022 16:25:11 +0000 Received: by outflank-mailman (input) for mailman id 435119; Tue, 01 Nov 2022 16:25:10 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1optvV-0000i5-CS for xen-devel@lists.xenproject.org; Tue, 01 Nov 2022 16:15:45 +0000 Received: from smtp-out1.suse.de (smtp-out1.suse.de [2001:67c:2178:6::1c]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 701c7b69-5a00-11ed-8fd0-01056ac49cbb; Tue, 01 Nov 2022 17:15:44 +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 80B543382E; Tue, 1 Nov 2022 16:15:44 +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 53A851346F; Tue, 1 Nov 2022 16:15:44 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id djYBEzBGYWOHdwAAMHmgww (envelope-from ); Tue, 01 Nov 2022 16:15:44 +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: 701c7b69-5a00-11ed-8fd0-01056ac49cbb DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1667319344; 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=IGeFv24ZPr/KZ3pFnNba31NdyHUcNMT973heFZoLWFU=; b=T7J3HDkC1l+3rUaVhUunMHYySpYRhVEQhxj6aYRXboYzG0eM5jAtqwPy+Y5ztLlixdE9Cp jFxZViANVTYtICCiE/OUOfbzUhZcQmhexZ7BjVWfAL+PNEY7kDBkLzOjAkIP3pP/IAlCJp MA5cjgldwEMICM5h6IrDvNF88tMcxWM= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Julien Grall , Anthony PERARD Subject: [PATCH 08/10] tools/xenstore: remove unused events list Date: Tue, 1 Nov 2022 17:14:55 +0100 Message-Id: <20221101161457.8470-9-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20221101161457.8470-1-jgross@suse.com> References: <20221101161457.8470-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1667319941313100007 Content-Type: text/plain; charset="utf-8" struct watch contains an used struct list_head events. Remove it. Signed-off-by: Juergen Gross --- tools/xenstore/xenstored_watch.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/tools/xenstore/xenstored_watch.c b/tools/xenstore/xenstored_wa= tch.c index ca0194966e..0078c60f32 100644 --- a/tools/xenstore/xenstored_watch.c +++ b/tools/xenstore/xenstored_watch.c @@ -36,9 +36,6 @@ struct watch /* Watches on this connection */ struct list_head list; =20 - /* Current outstanding events applying to this watch. */ - struct list_head events; - /* Offset into path for skipping prefix (used for relative paths). */ unsigned int prefix_len; =20 @@ -205,8 +202,6 @@ static struct watch *add_watch(struct connection *conn,= char *path, char *token, =20 watch->prefix_len =3D relative ? strlen(get_implicit_path(conn)) + 1 : 0; =20 - INIT_LIST_HEAD(&watch->events); - domain_watch_inc(conn); list_add_tail(&watch->list, &conn->watches); talloc_set_destructor(watch, destroy_watch); --=20 2.35.3 From nobody Fri May 17 03:12:53 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=1667319938; cv=none; d=zohomail.com; s=zohoarc; b=mmYu/VGiLxGx74CdYZulLcVAiXe5Ead73CZQe7QL2JvnPh1SZOjEmS8bqnAWGUI0cqP1jGMR1FPC+Agnxtfz+/dyQuPFsaKF2noKu4tval97EDKOSXcFCf0ldA3HoPSjQRwChTEkmoPkYnv4B9KY6kahu3+DIg20Rekq312dA04= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1667319938; 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=WhOM3PNzD9bJCGoKKo33Zgli+2MPQr6UTZsqeC1HgWI=; b=L9Zp1ZP0cPtQOq9FSR7c4s0rSkaNu7c9R6dVuBUJFcIPf3XANSAU25ZFGjf1Zm2HJVIlAYdnsZbxYKjRgNPnyYroAvmAMZTD9vO86lmcW8+a7FsBNCL7G5VyYFZgfkq+RXyQt6O2akRRJ9KsBhrfWuQHIcPkauU09vwcmzNGFNo= 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 1667319938709655.2330765207413; Tue, 1 Nov 2022 09:25:38 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.435130.688251 (Exim 4.92) (envelope-from ) id 1opu4n-0000t1-Hs; Tue, 01 Nov 2022 16:25:21 +0000 Received: by outflank-mailman (output) from mailman id 435130.688251; Tue, 01 Nov 2022 16:25:21 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1opu4n-0000sq-Dq; Tue, 01 Nov 2022 16:25:21 +0000 Received: by outflank-mailman (input) for mailman id 435130; Tue, 01 Nov 2022 16:25:20 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1optvc-0000yH-Ra for xen-devel@lists.xenproject.org; Tue, 01 Nov 2022 16:15:52 +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 736f26f5-5a00-11ed-91b5-6bf2151ebd3b; Tue, 01 Nov 2022 17:15:50 +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 182473382E; Tue, 1 Nov 2022 16:15:50 +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 DE1D51346F; Tue, 1 Nov 2022 16:15:49 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id YhHLNDVGYWOSdwAAMHmgww (envelope-from ); Tue, 01 Nov 2022 16:15: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: 736f26f5-5a00-11ed-91b5-6bf2151ebd3b DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1667319350; 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=WhOM3PNzD9bJCGoKKo33Zgli+2MPQr6UTZsqeC1HgWI=; b=eG9FjtjWP236isyPLSn4cWvJOdhSGJQKWtpUvyKcxBklDbp3krOAkwfa5IbKUi+K897HEq NNepjiSyG9K1qoT+RgBUA2kISTUQkelJ3RRROHcdfPxELrkLccd5pUgRlB+XO5+s+EQvf7 EICx5g3e1kMZM5aGTebMgKsDZ4ZM/do= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Julien Grall , Anthony PERARD Subject: [PATCH 09/10] tools/xenstore: remove support of file backed data base Date: Tue, 1 Nov 2022 17:14:56 +0100 Message-Id: <20221101161457.8470-10-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20221101161457.8470-1-jgross@suse.com> References: <20221101161457.8470-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1667319939381100005 Content-Type: text/plain; charset="utf-8" In order to prepare the replacement of TDB with direct accessible nodes in memory, remove the support for a file backed data base. This allows to remove xs_tdb_dump, too. Signed-off-by: Juergen Gross --- tools/xenstore/Makefile | 5 +- tools/xenstore/xenstored_core.c | 18 ++----- tools/xenstore/xs_tdb_dump.c | 86 --------------------------------- 3 files changed, 4 insertions(+), 105 deletions(-) delete mode 100644 tools/xenstore/xs_tdb_dump.c diff --git a/tools/xenstore/Makefile b/tools/xenstore/Makefile index ce7a68178f..56723139a1 100644 --- a/tools/xenstore/Makefile +++ b/tools/xenstore/Makefile @@ -29,7 +29,7 @@ CLIENTS +=3D xenstore-write xenstore-ls xenstore-watch =20 TARGETS :=3D xenstore $(CLIENTS) xenstore-control ifeq ($(XENSTORE_XENSTORED),y) -TARGETS +=3D xs_tdb_dump xenstored +TARGETS +=3D xenstored endif =20 .PHONY: all @@ -50,9 +50,6 @@ xenstore: xenstore_client.o xs_lib.o xenstore-control: xenstore_control.o $(CC) $(LDFLAGS) $^ $(LDLIBS) -o $@ $(APPEND_LDFLAGS) =20 -xs_tdb_dump: xs_tdb_dump.o utils.o tdb.o talloc.o - $(CC) $(LDFLAGS) $^ -o $@ $(APPEND_LDFLAGS) - .PHONY: clean clean:: $(RM) $(TARGETS) $(DEPS_RM) diff --git a/tools/xenstore/xenstored_core.c b/tools/xenstore/xenstored_cor= e.c index 5fcf96c77a..e11f796aaa 100644 --- a/tools/xenstore/xenstored_core.c +++ b/tools/xenstore/xenstored_core.c @@ -2282,8 +2282,6 @@ static void accept_connection(int sock) } #endif =20 -static int tdb_flags =3D TDB_INTERNAL | TDB_NOLOCK; - /* We create initial nodes manually. */ static void manual_node(const char *name, const char *child) { @@ -2335,14 +2333,11 @@ void setup_structure(bool live_update) { char *tdbname; =20 - tdbname =3D talloc_strdup(talloc_autofree_context(), xs_daemon_tdb()); + tdbname =3D talloc_strdup(talloc_autofree_context(), "/dev/mem"); if (!tdbname) barf_perror("Could not create tdbname"); =20 - if (!(tdb_flags & TDB_INTERNAL)) - unlink(tdbname); - - tdb_ctx =3D tdb_open_ex(tdbname, 7919, tdb_flags, + tdb_ctx =3D tdb_open_ex(tdbname, 7919, TDB_INTERNAL | TDB_NOLOCK, O_RDWR | O_CREAT | O_EXCL | O_CLOEXEC, 0640, &tdb_logger, NULL); if (!tdb_ctx) @@ -2640,8 +2635,6 @@ static void usage(void) " watch-event: time a watch-event is kept pending= \n" " -R, --no-recovery to request that no recovery should be attempted= when\n" " the store is corrupted (debug only),\n" -" -I, --internal-db [on|off] store database in memory, not on disk, defau= lt is\n" -" memory, with \"--internal-db off\" it is on dis= k\n" " -K, --keep-orphans don't delete nodes owned by a domain when the\n" " domain is deleted (this is a security risk!)\n" " -V, --verbose to request verbose execution.\n"); @@ -2668,7 +2661,6 @@ static struct option options[] =3D { { "quota-soft", 1, NULL, 'q' }, { "timeout", 1, NULL, 'w' }, { "no-recovery", 0, NULL, 'R' }, - { "internal-db", 2, NULL, 'I' }, { "keep-orphans", 0, NULL, 'K' }, { "verbose", 0, NULL, 'V' }, { "watch-nb", 1, NULL, 'W' }, @@ -2781,7 +2773,7 @@ int main(int argc, char *argv[]) orig_argv =3D argv; =20 while ((opt =3D getopt_long(argc, argv, - "DE:F:HI::KNPS:t:A:M:Q:q:T:RVW:w:U", + "DE:F:H::KNPS:t:A:M:Q:q:T:RVW:w:U", options, NULL)) !=3D -1) { switch (opt) { case 'D': @@ -2817,10 +2809,6 @@ int main(int argc, char *argv[]) case 1: set_trace_switch(optarg); break; - case 'I': - if (optarg && !strcmp(optarg, "off")) - tdb_flags =3D 0; - break; case 'K': keep_orphans =3D true; break; diff --git a/tools/xenstore/xs_tdb_dump.c b/tools/xenstore/xs_tdb_dump.c deleted file mode 100644 index 5d2db392b4..0000000000 --- a/tools/xenstore/xs_tdb_dump.c +++ /dev/null @@ -1,86 +0,0 @@ -/* Simple program to dump out all records of TDB */ -#include -#include -#include -#include -#include -#include -#include -#include "xenstore_lib.h" -#include "tdb.h" -#include "talloc.h" -#include "utils.h" - -static uint32_t total_size(struct xs_tdb_record_hdr *hdr) -{ - return sizeof(*hdr) + hdr->num_perms * sizeof(struct xs_permissions)=20 - + hdr->datalen + hdr->childlen; -} - -static char perm_to_char(unsigned int perm) -{ - return perm =3D=3D XS_PERM_READ ? 'r' : - perm =3D=3D XS_PERM_WRITE ? 'w' : - perm =3D=3D XS_PERM_NONE ? '-' : - perm =3D=3D (XS_PERM_READ|XS_PERM_WRITE) ? 'b' : - '?'; -} - -static void tdb_logger(TDB_CONTEXT *tdb, int level, const char * fmt, ...) -{ - va_list ap; - - va_start(ap, fmt); - vfprintf(stderr, fmt, ap); - va_end(ap); -} - -int main(int argc, char *argv[]) -{ - TDB_DATA key; - TDB_CONTEXT *tdb; - - if (argc !=3D 2) - barf("Usage: xs_tdb_dump "); - - tdb =3D tdb_open_ex(talloc_strdup(NULL, argv[1]), 0, 0, O_RDONLY, 0, - &tdb_logger, NULL); - if (!tdb) - barf_perror("Could not open %s", argv[1]); - - key =3D tdb_firstkey(tdb); - while (key.dptr) { - TDB_DATA data; - struct xs_tdb_record_hdr *hdr; - - data =3D tdb_fetch(tdb, key); - hdr =3D (void *)data.dptr; - if (data.dsize < sizeof(*hdr)) - fprintf(stderr, "%.*s: BAD truncated\n", - (int)key.dsize, key.dptr); - else if (data.dsize !=3D total_size(hdr)) - fprintf(stderr, "%.*s: BAD length %zu for %u/%u/%u (%u)\n", - (int)key.dsize, key.dptr, data.dsize, - hdr->num_perms, hdr->datalen, - hdr->childlen, total_size(hdr)); - else { - unsigned int i; - char *p; - - printf("%.*s: ", (int)key.dsize, key.dptr); - for (i =3D 0; i < hdr->num_perms; i++) - printf("%s%c%u", - i =3D=3D 0 ? "" : ",", - perm_to_char(hdr->perms[i].perms), - hdr->perms[i].id); - p =3D (void *)&hdr->perms[hdr->num_perms]; - printf(" %.*s\n", hdr->datalen, p); - p +=3D hdr->datalen; - for (i =3D 0; i < hdr->childlen; i +=3D strlen(p+i)+1) - printf("\t-> %s\n", p+i); - } - key =3D tdb_nextkey(tdb, key); - } - return 0; -} - --=20 2.35.3 From nobody Fri May 17 03:12:53 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=1667319937; cv=none; d=zohomail.com; s=zohoarc; b=kf06EDpP4+h3AJaG2Q3u9Q0HXXsOqzWeUKf65ehLNpA4AacXqWndErxL2eTa1UmalZbZiraHGJM51DQab9rGvGN23LMgy3m2v4XuW15wQUikr7Sf2pumajZOnKupdoiH3hrb/dDpqYV64pl369JuE8ZPKjZtPV3waQ/tbxpJbkE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1667319937; 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=NwUivDjaxbqaMaYd71PIDNVF/acd+ugyV6m7DW6bCCE=; b=iNgUH+BGAD971qo0C2x4qrCdCtWMbcs5b+7SMa+XwpcTMjVmvx3731ESY/MH6LKgXH1WzWQheZ2EpJwl3vdmFZn9WppDfo+g+Eww9jDk6nUU37fqeNdJRJkhogr+IISdAMB86SdbRUrY4jZQk5UQpCYwhPBE+0r2dbB8Cz9ikHA= 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 1667319937050554.6492439945242; Tue, 1 Nov 2022 09:25:37 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.435128.688240 (Exim 4.92) (envelope-from ) id 1opu4m-0000bV-7w; Tue, 01 Nov 2022 16:25:20 +0000 Received: by outflank-mailman (output) from mailman id 435128.688240; Tue, 01 Nov 2022 16:25:20 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1opu4m-0000bM-4q; Tue, 01 Nov 2022 16:25:20 +0000 Received: by outflank-mailman (input) for mailman id 435128; Tue, 01 Nov 2022 16:25:18 +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 1optvg-0000i5-TD for xen-devel@lists.xenproject.org; Tue, 01 Nov 2022 16:15:57 +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 76c72637-5a00-11ed-8fd0-01056ac49cbb; Tue, 01 Nov 2022 17:15: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 AC6F21F90F; Tue, 1 Nov 2022 16:15:55 +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 79BBE1346F; Tue, 1 Nov 2022 16:15:55 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id E81QHDtGYWOadwAAMHmgww (envelope-from ); Tue, 01 Nov 2022 16:15:55 +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: 76c72637-5a00-11ed-8fd0-01056ac49cbb DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1667319355; 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=NwUivDjaxbqaMaYd71PIDNVF/acd+ugyV6m7DW6bCCE=; b=LAfcGAD/f0G8jxFhOEnhq4NYiVUAVpLGaAo4xbrzDiB6caXDy1oqhMF8Dd6AU9uQG/oyzg bd/eGb3CVLzK7U/EmluFNP2j+3Vb1QHsTdZjLbMVGDWhfgwMLxbRKbSr7Sc+Vv+qM6SlCe zRgCuu6ioPH3VVqioqaAQm2PByqHRSs= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Anthony PERARD , Julien Grall Subject: [PATCH 10/10] tools/xenstore: remove no longer needed functions from xs_lib.c Date: Tue, 1 Nov 2022 17:14:57 +0100 Message-Id: <20221101161457.8470-11-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20221101161457.8470-1-jgross@suse.com> References: <20221101161457.8470-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1667319937450100001 Content-Type: text/plain; charset="utf-8" xs_daemon_tdb() in xs_lib.c is no longer used at all, so it can be removed. xs_domain_dev() is not used by xenstored, so it can be moved to tools/libs/store/xs.c. Move functions used by xenstore-client only to xenstore_client.c. Signed-off-by: Juergen Gross --- tools/libs/store/xs.c | 20 +++++ tools/xenstore/xenstore_client.c | 129 +++++++++++++++++++++++++++++ tools/xenstore/xs_lib.c | 138 ------------------------------- tools/xenstore/xs_lib.h | 17 ---- 4 files changed, 149 insertions(+), 155 deletions(-) diff --git a/tools/libs/store/xs.c b/tools/libs/store/xs.c index 7a9a8b1656..70e64fccb8 100644 --- a/tools/libs/store/xs.c +++ b/tools/libs/store/xs.c @@ -311,6 +311,26 @@ struct xs_handle *xs_domain_open(void) return xs_open(0); } =20 +static const char *xs_domain_dev(void) +{ + char *s =3D getenv("XENSTORED_PATH"); + if (s) + return s; +#if defined(__RUMPUSER_XEN__) || defined(__RUMPRUN__) + return "/dev/xen/xenbus"; +#elif defined(__linux__) + if (access("/dev/xen/xenbus", F_OK) =3D=3D 0) + return "/dev/xen/xenbus"; + return "/proc/xen/xenbus"; +#elif defined(__NetBSD__) + return "/kern/xen/xenbus"; +#elif defined(__FreeBSD__) + return "/dev/xen/xenstore"; +#else + return "/dev/xen/xenbus"; +#endif +} + struct xs_handle *xs_open(unsigned long flags) { struct xs_handle *xsh =3D NULL; diff --git a/tools/xenstore/xenstore_client.c b/tools/xenstore/xenstore_cli= ent.c index 0628ba275e..8ff8abf12a 100644 --- a/tools/xenstore/xenstore_client.c +++ b/tools/xenstore/xenstore_client.c @@ -8,6 +8,7 @@ * */ =20 +#include #include #include #include @@ -40,12 +41,140 @@ enum mode { MODE_watch, }; =20 +/* Sanitising (quoting) possibly-binary strings. */ +struct expanding_buffer { + char *buf; + int avail; +}; + static char *output_buf =3D NULL; static int output_pos =3D 0; static struct expanding_buffer ebuf; =20 static int output_size =3D 0; =20 +/* Ensure that given expanding buffer has at least min_avail characters. */ +static char *expanding_buffer_ensure(struct expanding_buffer *ebuf, + int min_avail) +{ + int want; + char *got; + + if ( ebuf->avail >=3D min_avail ) + return ebuf->buf; + + if ( min_avail >=3D INT_MAX/3 ) + return 0; + + want =3D ebuf->avail + min_avail + 10; + got =3D realloc(ebuf->buf, want); + if ( !got ) + return 0; + + ebuf->buf =3D got; + ebuf->avail =3D want; + return ebuf->buf; +} + +/* sanitise_value() may return NULL if malloc fails. */ +static char *sanitise_value(struct expanding_buffer *ebuf, + const char *val, unsigned len) +{ + int used, remain, c; + unsigned char *ip; + +#define ADD(c) (ebuf->buf[used++] =3D (c)) +#define ADDF(f,c) (used +=3D sprintf(ebuf->buf+used, (f), (c))) + + assert(len < INT_MAX/5); + + ip =3D (unsigned char *)val; + used =3D 0; + remain =3D len; + + if ( !expanding_buffer_ensure(ebuf, remain + 1) ) + return NULL; + + while ( remain-- > 0 ) + { + c=3D *ip++; + + if ( c >=3D ' ' && c <=3D '~' && c !=3D '\\' ) + { + ADD(c); + continue; + } + + if ( !expanding_buffer_ensure(ebuf, used + remain + 5) ) + /* for "\\nnn\0" */ + return 0; + + ADD('\\'); + switch (c) + { + case '\t': ADD('t'); break; + case '\n': ADD('n'); break; + case '\r': ADD('r'); break; + case '\\': ADD('\\'); break; + default: + if ( c < 010 ) ADDF("%03o", c); + else ADDF("x%02x", c); + } + } + + ADD(0); + assert(used <=3D ebuf->avail); + return ebuf->buf; + +#undef ADD +#undef ADDF +} + +/* *out_len_r on entry is ignored; out must be at least strlen(in)+1 bytes= . */ +static void unsanitise_value(char *out, unsigned *out_len_r, const char *i= n) +{ + const char *ip; + char *op; + unsigned c; + int n; + + for ( ip =3D in, op =3D out; (c =3D *ip++); *op++ =3D c ) + { + if ( c =3D=3D '\\' ) + { + c =3D *ip++; + +#define GETF(f) do \ +{ \ + n =3D 0; \ + sscanf(ip, f "%n", &c, &n); \ + ip +=3D n; \ +} while ( 0 ) + + switch ( c ) + { + case 't': c=3D '\t'; break; + case 'n': c=3D '\n'; break; + case 'r': c=3D '\r'; break; + case '\\': c=3D '\\'; break; + case 'x': GETF("%2x"); break; + case '0': case '4': + case '1': case '5': + case '2': case '6': + case '3': case '7': --ip; GETF("%3o"); break; + case 0: --ip; break; + default:; + } +#undef GETF + } + } + + *op =3D 0; + + if ( out_len_r ) + *out_len_r =3D op - out; +} + /* make sure there is at least 'len' more space in output_buf */ static void expand_buffer(size_t len) { diff --git a/tools/xenstore/xs_lib.c b/tools/xenstore/xs_lib.c index b9941c567c..1cfa9236bd 100644 --- a/tools/xenstore/xs_lib.c +++ b/tools/xenstore/xs_lib.c @@ -49,13 +49,6 @@ static const char *xs_daemon_path(void) return buf; } =20 -const char *xs_daemon_tdb(void) -{ - static char buf[PATH_MAX]; - snprintf(buf, sizeof(buf), "%s/tdb", xs_daemon_rootdir()); - return buf; -} - const char *xs_daemon_socket(void) { return xs_daemon_path(); @@ -66,26 +59,6 @@ const char *xs_daemon_socket_ro(void) return xs_daemon_path(); } =20 -const char *xs_domain_dev(void) -{ - char *s =3D getenv("XENSTORED_PATH"); - if (s) - return s; -#if defined(__RUMPUSER_XEN__) || defined(__RUMPRUN__) - return "/dev/xen/xenbus"; -#elif defined(__linux__) - if (access("/dev/xen/xenbus", F_OK) =3D=3D 0) - return "/dev/xen/xenbus"; - return "/proc/xen/xenbus"; -#elif defined(__NetBSD__) - return "/kern/xen/xenbus"; -#elif defined(__FreeBSD__) - return "/dev/xen/xenstore"; -#else - return "/dev/xen/xenbus"; -#endif -} - /* Simple routines for writing to sockets, etc. */ bool xs_write_all(int fd, const void *data, unsigned int len) { @@ -179,114 +152,3 @@ unsigned int xs_count_strings(const char *strings, un= signed int len) =20 return num; } - -char *expanding_buffer_ensure(struct expanding_buffer *ebuf, int min_avail) -{ - int want; - char *got; - - if (ebuf->avail >=3D min_avail) - return ebuf->buf; - - if (min_avail >=3D INT_MAX/3) - return 0; - - want =3D ebuf->avail + min_avail + 10; - got =3D realloc(ebuf->buf, want); - if (!got) - return 0; - - ebuf->buf =3D got; - ebuf->avail =3D want; - return ebuf->buf; -} - -char *sanitise_value(struct expanding_buffer *ebuf, - const char *val, unsigned len) -{ - int used, remain, c; - unsigned char *ip; - -#define ADD(c) (ebuf->buf[used++] =3D (c)) -#define ADDF(f,c) (used +=3D sprintf(ebuf->buf+used, (f), (c))) - - assert(len < INT_MAX/5); - - ip =3D (unsigned char *)val; - used =3D 0; - remain =3D len; - - if (!expanding_buffer_ensure(ebuf, remain + 1)) - return NULL; - - while (remain-- > 0) { - c=3D *ip++; - - if (c >=3D ' ' && c <=3D '~' && c !=3D '\\') { - ADD(c); - continue; - } - - if (!expanding_buffer_ensure(ebuf, used + remain + 5)) - /* for "\\nnn\0" */ - return 0; - - ADD('\\'); - switch (c) { - case '\t': ADD('t'); break; - case '\n': ADD('n'); break; - case '\r': ADD('r'); break; - case '\\': ADD('\\'); break; - default: - if (c < 010) ADDF("%03o", c); - else ADDF("x%02x", c); - } - } - - ADD(0); - assert(used <=3D ebuf->avail); - return ebuf->buf; - -#undef ADD -#undef ADDF -} - -void unsanitise_value(char *out, unsigned *out_len_r, const char *in) -{ - const char *ip; - char *op; - unsigned c; - int n; - - for (ip =3D in, op =3D out; (c =3D *ip++); *op++ =3D c) { - if (c =3D=3D '\\') { - c =3D *ip++; - -#define GETF(f) do { \ - n =3D 0; \ - sscanf(ip, f "%n", &c, &n); \ - ip +=3D n; \ - } while (0) - - switch (c) { - case 't': c=3D '\t'; break; - case 'n': c=3D '\n'; break; - case 'r': c=3D '\r'; break; - case '\\': c=3D '\\'; break; - case 'x': GETF("%2x"); break; - case '0': case '4': - case '1': case '5': - case '2': case '6': - case '3': case '7': --ip; GETF("%3o"); break; - case 0: --ip; break; - default:; - } -#undef GETF - } - } - - *op =3D 0; - - if (out_len_r) - *out_len_r =3D op - out; -} diff --git a/tools/xenstore/xs_lib.h b/tools/xenstore/xs_lib.h index efa05997d6..61229aa435 100644 --- a/tools/xenstore/xs_lib.h +++ b/tools/xenstore/xs_lib.h @@ -22,8 +22,6 @@ #include "xenstore_lib.h" =20 const char *xs_daemon_rootdir(void); -const char *xs_domain_dev(void); -const char *xs_daemon_tdb(void); =20 /* Convert permissions to a string (up to len MAX_STRLEN(unsigned int)+1).= */ bool xs_perm_to_string(const struct xs_permissions *perm, @@ -32,19 +30,4 @@ bool xs_perm_to_string(const struct xs_permissions *perm, /* Given a string and a length, count how many strings (nul terms). */ unsigned int xs_count_strings(const char *strings, unsigned int len); =20 -/* Sanitising (quoting) possibly-binary strings. */ -struct expanding_buffer { - char *buf; - int avail; -}; - -/* Ensure that given expanding buffer has at least min_avail characters. */ -char *expanding_buffer_ensure(struct expanding_buffer *, int min_avail); - -/* sanitise_value() may return NULL if malloc fails. */ -char *sanitise_value(struct expanding_buffer *, const char *val, unsigned = len); - -/* *out_len_r on entry is ignored; out must be at least strlen(in)+1 bytes= . */ -void unsanitise_value(char *out, unsigned *out_len_r, const char *in); - #endif /* XS_LIB_H */ --=20 2.35.3