From nobody Thu May 16 23:47:24 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=1680166248; cv=none; d=zohomail.com; s=zohoarc; b=WgtdXUuWIVkzpDtV3jybBRKc4nkYp+wg2/gV9DnQ+DDdFSrgeG9P63wDNupgwmBQ3JPEv9tyrXJ4iPN1W92L6Cn8km2i1wmNqsJFTDsPAoQyc2ZbVFGw4sQBqy3asPs++GHl3EgsYKvqXRl4HTG/wFKFnnKTydFolgVfElJZAoE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1680166248; 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=3pO10sPGTtdz9QC6xsd1+0esIC5/k5/zllx/QTVNu38=; b=ccrZ7msUVuVtKtopsyBt3wCxGzeLMBZtQ+rYeSlXR5bw67vVkAJbIth020J9MZYY+drOVYDzOXLwAHs+ohErBmxKlinz5wgzXzOSmKy1udhrS9CF4jSiqbV8zC2GmPVaj5oT1z/7YJnStxZhxBtyrEzi61135RUSLMJz8+1DlzI= 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 1680166248488748.2466221150893; Thu, 30 Mar 2023 01:50:48 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.516499.800692 (Exim 4.92) (envelope-from ) id 1phnzC-0005gn-LV; Thu, 30 Mar 2023 08:50:22 +0000 Received: by outflank-mailman (output) from mailman id 516499.800692; Thu, 30 Mar 2023 08:50:22 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1phnzC-0005gg-I7; Thu, 30 Mar 2023 08:50:22 +0000 Received: by outflank-mailman (input) for mailman id 516499; Thu, 30 Mar 2023 08:50: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 1phnzA-0005fr-Ov for xen-devel@lists.xenproject.org; Thu, 30 Mar 2023 08:50:20 +0000 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id e671c27c-ced7-11ed-85db-49a42c6b2330; Thu, 30 Mar 2023 10:50:19 +0200 (CEST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id AFFD51FEAC; Thu, 30 Mar 2023 08:50:19 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 8241F138FF; Thu, 30 Mar 2023 08:50:19 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id j1JwHktNJWTPIgAAMHmgww (envelope-from ); Thu, 30 Mar 2023 08:50:19 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: e671c27c-ced7-11ed-85db-49a42c6b2330 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1680166219; 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=3pO10sPGTtdz9QC6xsd1+0esIC5/k5/zllx/QTVNu38=; b=DmhuzkqIdzhODt2DGUTtmkrxBKyvhZmORveGHb5t49odyVkcBxg58Ldul7gle+17oGkE0y l9C4qHDpsceHqSHpg9zOdTqSo8Qtp6NnVmsRbhjdQtPbw5qtyXiYukkqxwjxnmDsDshn3P PiNT3392sf+M+hK/TwxuQhWgOJECEZM= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Julien Grall , Anthony PERARD Subject: [PATCH v2 01/13] tools/xenstore: verify command line parameters better Date: Thu, 30 Mar 2023 10:49:59 +0200 Message-Id: <20230330085011.9170-2-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230330085011.9170-1-jgross@suse.com> References: <20230330085011.9170-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1680166249536100001 Content-Type: text/plain; charset="utf-8" Add some more verification of command line parameters. Signed-off-by: Juergen Gross Acked-by: Julien Grall --- 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 6e2fc06840..7214b3df03 100644 --- a/tools/xenstore/xenstored_core.c +++ b/tools/xenstore/xenstored_core.c @@ -2809,7 +2809,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; @@ -2827,10 +2827,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; @@ -2850,14 +2850,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); @@ -2872,13 +2871,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 Thu May 16 23:47:25 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=1680166253; cv=none; d=zohomail.com; s=zohoarc; b=QfSsRKMNvvmupIa+O25CCRsMkTDogR/QINX6yvNBDt2TAniUGhn1yWqGngTLHA45LHZKj2AGtjVqv4bl4h67JTg4GeViU54OOnrden+0Ec4mFVS9yW+1RT7i1vqldG9Zan4B1kBqLgRjR+11fqLzVuAvZxAdkKdsgmwA+KUfINI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1680166253; 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=G7duMJqACu3XAMWpzr/xsKoLzajMYtvFv/QO5a4TpxA=; b=fadWVF0UYW2ED69KYuoER15mJb2ciUw8cFxGSkY4bSaMRcfrpcCWN238vCfyhpkGg/OKkDXv3CZ9Rs2YxJk7fCvwQoXQJMyvx3iwnuGgbm/TgdgWHf+UvarQ9wvOntUIhqFMSE0Jp+Todoj8ZAv6ZctYHGujIXBSOzQDyNd9u5I= 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 1680166253193221.28846546749492; Thu, 30 Mar 2023 01:50:53 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.516500.800703 (Exim 4.92) (envelope-from ) id 1phnzH-00060c-Sg; Thu, 30 Mar 2023 08:50:27 +0000 Received: by outflank-mailman (output) from mailman id 516500.800703; Thu, 30 Mar 2023 08:50:27 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1phnzH-00060R-PU; Thu, 30 Mar 2023 08:50:27 +0000 Received: by outflank-mailman (input) for mailman id 516500; Thu, 30 Mar 2023 08:50:26 +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 1phnzG-0005fr-4Q for xen-devel@lists.xenproject.org; Thu, 30 Mar 2023 08:50:26 +0000 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id e9c90f8d-ced7-11ed-85db-49a42c6b2330; Thu, 30 Mar 2023 10:50:25 +0200 (CEST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 4F4CD1FEA2; Thu, 30 Mar 2023 08:50:25 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 21817138FF; Thu, 30 Mar 2023 08:50:25 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id g2iSBlFNJWTyIgAAMHmgww (envelope-from ); Thu, 30 Mar 2023 08:50:25 +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: e9c90f8d-ced7-11ed-85db-49a42c6b2330 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1680166225; 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=G7duMJqACu3XAMWpzr/xsKoLzajMYtvFv/QO5a4TpxA=; b=DV9e35SW1ru5XIa+UoYin8gS3mqqq82qTij2asHRLDX9ANi1YwXGT64mYPh1b25eibveeG hY+jZVCAcW0jYnJU0fyBCOc3wpSOi5FmjZ+kde/teh3xRkuGasVHc5JkGvPI8qZUFoXz7E 2qC0vlO7JLFAhLbdtHdhtABhkG9zlFk= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Julien Grall , Anthony PERARD Subject: [PATCH v2 02/13] tools/xenstore: do some cleanup of hashtable.c Date: Thu, 30 Mar 2023 10:50:00 +0200 Message-Id: <20230330085011.9170-3-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230330085011.9170-1-jgross@suse.com> References: <20230330085011.9170-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1680166253431100005 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 Reviewed-by: Julien Grall --- tools/xenstore/hashtable.c | 71 ++++++++++++++------------------------ tools/xenstore/hashtable.h | 10 ------ 2 files changed, 26 insertions(+), 55 deletions(-) diff --git a/tools/xenstore/hashtable.c b/tools/xenstore/hashtable.c index 3d4466b597..c1b11743bb 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) (const void *), - int (*eqf) (const void *, const 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) (const void *), + int (*eqf) (const void *, const 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(const struct hashtable *h, const void *k) +static unsigned int hash(const struct hashtable *h, const 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(const struct hashtable *h, const 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(const 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; @@ -186,9 +175,7 @@ hashtable_insert(struct hashtable *h, void *k, void *v) return -1; } =20 -/*************************************************************************= ****/ -void * /* returns value associated with key */ -hashtable_search(const struct hashtable *h, const void *k) +void *hashtable_search(const struct hashtable *h, const void *k) { struct entry *e; unsigned int hashvalue, index; @@ -204,7 +191,6 @@ hashtable_search(const struct hashtable *h, const void = *k) return NULL; } =20 -/*************************************************************************= ****/ void hashtable_remove(struct hashtable *h, const void *k) { @@ -234,10 +220,8 @@ hashtable_remove(struct hashtable *h, const void *k) } } =20 -/*************************************************************************= ****/ -int -hashtable_iterate(struct hashtable *h, - int (*func)(const void *k, void *v, void *arg), void *ar= g) +int hashtable_iterate(struct hashtable *h, + int (*func)(const void *k, void *v, void *arg), void= *arg) { int ret; unsigned int i; @@ -260,10 +244,7 @@ hashtable_iterate(struct hashtable *h, return 0; } =20 -/*************************************************************************= ****/ -/* destroy */ -void -hashtable_destroy(struct hashtable *h) +void hashtable_destroy(struct hashtable *h) { talloc_free(h); } diff --git a/tools/xenstore/hashtable.h b/tools/xenstore/hashtable.h index cc0090f133..04310783b6 100644 --- a/tools/xenstore/hashtable.h +++ b/tools/xenstore/hashtable.h @@ -74,16 +74,6 @@ hashtable_search(const struct hashtable *h, const void *= k); void hashtable_remove(struct hashtable *h, const 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(const struct hashtable *h); - /*************************************************************************= **** * hashtable_iterate =20 --=20 2.35.3 From nobody Thu May 16 23:47:25 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=1680166262; cv=none; d=zohomail.com; s=zohoarc; b=gh9AGrBjMJiEmrXEzXWIkaGKmlny2DpD5iRy4OP2e07qldxf3SgQWKjFuII/bj6kdKXboh9iw71K+w6KPfLoST7kQjyr0WvByPERRGBw9RoGXBcRmnnZrfDXjqIYZn0GLRGuVZrKeB/IT5yGRhqG65bN2/dbeagX/O+5KSbuKHk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1680166262; 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=yNDHqsZeJimLNlZjd9q+WaVtry8TrNvKJye99WJK+MI=; b=al15RI9JVoqDVatNBdB4uq157SYnq+aBqCRrFMUDg+xxRdo4+Ie/R2Tfsc++ndHe6TiGjGq6lvITS5pY6+BVuw9liMtRo4hwD84+5TLOmXrzD+xkM4W2qtJaKhwndoWWP5bHt7QU6wfzS1fY2W+mX+LNZZA6mLmYi4qTA7BCw4Q= 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 1680166262514801.8629972541321; Thu, 30 Mar 2023 01:51:02 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.516501.800713 (Exim 4.92) (envelope-from ) id 1phnzO-0006Q3-9G; Thu, 30 Mar 2023 08:50:34 +0000 Received: by outflank-mailman (output) from mailman id 516501.800713; Thu, 30 Mar 2023 08:50:34 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1phnzO-0006Pt-5H; Thu, 30 Mar 2023 08:50:34 +0000 Received: by outflank-mailman (input) for mailman id 516501; Thu, 30 Mar 2023 08:50:33 +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 1phnzM-0005Qp-VM for xen-devel@lists.xenproject.org; Thu, 30 Mar 2023 08:50:33 +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 ed27b3ea-ced7-11ed-b464-930f4c7d94ae; Thu, 30 Mar 2023 10:50:31 +0200 (CEST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id E984321B0D; Thu, 30 Mar 2023 08:50:30 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id B0A51138FF; Thu, 30 Mar 2023 08:50:30 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id mcjKKVZNJWQTIwAAMHmgww (envelope-from ); Thu, 30 Mar 2023 08:50:30 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: ed27b3ea-ced7-11ed-b464-930f4c7d94ae DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1680166230; 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=yNDHqsZeJimLNlZjd9q+WaVtry8TrNvKJye99WJK+MI=; b=C1P36EdJ4nEFayaBwK+INqIbDnPYvVnIZdKRLJa/Xau0oQlOgrlxHSlNF70o4X8xOxMTop 6d2mE3Sy6PhCQAjxJds3y/H2e46l+9EoDshJndWSS3nh6twomzv7KsNQoY41bpRCwkyGO4 vLofgXJltNLvWUHy6jPVhdKS5CIwM7Q= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Julien Grall , Anthony PERARD Subject: [PATCH v2 03/13] tools/xenstore: modify interface of create_hashtable() Date: Thu, 30 Mar 2023 10:50:01 +0200 Message-Id: <20230330085011.9170-4-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230330085011.9170-1-jgross@suse.com> References: <20230330085011.9170-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1680166263653100001 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 | 20 ++++++-------------- tools/xenstore/hashtable.h | 4 ++-- tools/xenstore/xenstored_core.c | 2 +- tools/xenstore/xenstored_domain.c | 4 ++-- 4 files changed, 11 insertions(+), 19 deletions(-) diff --git a/tools/xenstore/hashtable.c b/tools/xenstore/hashtable.c index c1b11743bb..ab1e687d0b 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, +struct hashtable *create_hashtable(const void *ctx, const char *name, unsigned int (*hashf) (const void *), int (*eqf) (const void *, const 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 04310783b6..0e1a6f61c2 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) (const void *), int (*key_eq_fn) (const void *, const void *), unsigned int flags diff --git a/tools/xenstore/xenstored_core.c b/tools/xenstore/xenstored_cor= e.c index 7214b3df03..6ce7be3161 100644 --- a/tools/xenstore/xenstored_core.c +++ b/tools/xenstore/xenstored_core.c @@ -2511,7 +2511,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 df64c87efc..6d40aefc63 100644 --- a/tools/xenstore/xenstored_domain.c +++ b/tools/xenstore/xenstored_domain.c @@ -1017,7 +1017,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 @@ -1804,7 +1804,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 Thu May 16 23:47:25 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=1680166262; cv=none; d=zohomail.com; s=zohoarc; b=GJZk1OrstrZosYONmI4jLAj5aLeyxS132dsy/8pI2A3ST9uUmGGm5JmmuRWe0VQvY03mqDsX2WKpdfT2fmwFtnMyI0cIE2Umj2JAtSY1TkS02BJ4dqvMfiUIf9RQzoBYzftReXHiLObBBShsApd4WC/ygA8I5lKUqRVpnof3OMQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1680166262; 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=mh22UmQC/9EYE48tEsEFwbVqpQAAehAkZgB8F1H4+sY=; b=m0aeX3YbM6pO0vlk5+EPjkATDy5PHKfB8hhi67rY1v8dkbDxCtp2551n38uisSzc8lTj+4amzQ+nwvI0yzQeWQZV/H3dZA1y9S1ZofcHapZlTqdeRIZ8MdM+BHeoBYswUf1WgceEHIQMtE/khGYhf+Vjvh7+hu64Isws6i9DFU0= 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 1680166262758384.34310561619554; Thu, 30 Mar 2023 01:51:02 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.516502.800722 (Exim 4.92) (envelope-from ) id 1phnzS-0006mf-GA; Thu, 30 Mar 2023 08:50:38 +0000 Received: by outflank-mailman (output) from mailman id 516502.800722; Thu, 30 Mar 2023 08:50:38 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1phnzS-0006mU-D4; Thu, 30 Mar 2023 08:50:38 +0000 Received: by outflank-mailman (input) for mailman id 516502; Thu, 30 Mar 2023 08:50:37 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1phnzR-0005fr-BG for xen-devel@lists.xenproject.org; Thu, 30 Mar 2023 08:50:37 +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 f0775447-ced7-11ed-85db-49a42c6b2330; Thu, 30 Mar 2023 10:50:36 +0200 (CEST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 8147621B0D; Thu, 30 Mar 2023 08:50:36 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 56483138FF; Thu, 30 Mar 2023 08:50:36 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 78G6E1xNJWQbIwAAMHmgww (envelope-from ); Thu, 30 Mar 2023 08:50:36 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: f0775447-ced7-11ed-85db-49a42c6b2330 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1680166236; 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=mh22UmQC/9EYE48tEsEFwbVqpQAAehAkZgB8F1H4+sY=; b=EBcok8zLDq2vnVCOBh0/ulacFaGPeaJpsHEsURLa6cgq8a7CmCFJxU+OcVPLq1V5B1KA5X pVXbT7SwqDYmhxKWhmGhejdPV6jOy6vWeU3EqOr/VCxI0PFuQtDcaYjNM7JcXicUpmx9r0 /YngaGolj72p420Bm5x6Ecoxuzbj4bk= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Julien Grall , Anthony PERARD Subject: [PATCH v2 04/13] tools/xenstore: let hashtable_insert() return 0 on success Date: Thu, 30 Mar 2023 10:50:02 +0200 Message-Id: <20230330085011.9170-5-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230330085011.9170-1-jgross@suse.com> References: <20230330085011.9170-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1680166263657100002 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 ab1e687d0b..084d562b22 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,7 +154,11 @@ int hashtable_insert(struct hashtable *h, void *k, voi= d *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; @@ -164,7 +169,7 @@ int hashtable_insert(struct hashtable *h, void *k, void= *v) talloc_steal(e, v); e->next =3D h->table[index]; h->table[index] =3D e; - return -1; + return 0; } =20 void *hashtable_search(const struct hashtable *h, const void *k) diff --git a/tools/xenstore/hashtable.h b/tools/xenstore/hashtable.h index 0e1a6f61c2..ee4e25cbbf 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 6ce7be3161..c5433e5b3f 100644 --- a/tools/xenstore/xenstored_core.c +++ b/tools/xenstore/xenstored_core.c @@ -2394,7 +2394,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 @@ -2428,7 +2428,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 6d40aefc63..be9175a461 100644 --- a/tools/xenstore/xenstored_domain.c +++ b/tools/xenstore/xenstored_domain.c @@ -540,7 +540,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; @@ -1792,7 +1792,7 @@ static int domain_check_acc_init_sub(const void *k, v= oid *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 e8968d7a1d..c615c0de13 100644 --- a/tools/xenstore/xenstored_transaction.c +++ b/tools/xenstore/xenstored_transaction.c @@ -600,13 +600,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 Thu May 16 23:47:25 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=1680166270; cv=none; d=zohomail.com; s=zohoarc; b=XNn6WYRqy3irKdx6EJTcln+l1JsxzDfttdfeubMvZq9IWjusM25nTnjNZs5kMYYfI5HqdNrUUaeVjfj1b78QGBbglXQMGHjzZp2+oHC5NvvEcHi0dxMt9zLWdRYUS0cdsNVG2YR4MphUn4so3dVZ/6M92iYoKB+NzXGmB/GhQd0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1680166270; 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=lufIwgTGxJUqKBQ8/wNtAQ7gLQcAnt+JrVNaxGYXexI=; b=FFE08eYkmZbgrJ/62qQALo7tPFp52+lUtiG9vXd8AmRB7/rd0qfAK6BBPki9sbDNAFAX4rfYL3/MzCM5LtgY4+/zMTQLN5II2bHV5VsJuEp4uLyNaEULYIefC3U5xmEpRXOBQchFx9fVXWeSIaez0SI5de3rlUm1bucNHuObxfY= 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 1680166270000675.9762004018405; Thu, 30 Mar 2023 01:51:10 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.516507.800733 (Exim 4.92) (envelope-from ) id 1phnzY-0007JP-SA; Thu, 30 Mar 2023 08:50:44 +0000 Received: by outflank-mailman (output) from mailman id 516507.800733; Thu, 30 Mar 2023 08:50:44 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1phnzY-0007JF-Ok; Thu, 30 Mar 2023 08:50:44 +0000 Received: by outflank-mailman (input) for mailman id 516507; Thu, 30 Mar 2023 08:50:43 +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 1phnzX-0005fr-De for xen-devel@lists.xenproject.org; Thu, 30 Mar 2023 08:50:43 +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 f3e03993-ced7-11ed-85db-49a42c6b2330; Thu, 30 Mar 2023 10:50:42 +0200 (CEST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 3DD6C21B15; Thu, 30 Mar 2023 08:50:42 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 08202138FF; Thu, 30 Mar 2023 08:50:42 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id t/+mAGJNJWQqIwAAMHmgww (envelope-from ); Thu, 30 Mar 2023 08:50:42 +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: f3e03993-ced7-11ed-85db-49a42c6b2330 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1680166242; 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=lufIwgTGxJUqKBQ8/wNtAQ7gLQcAnt+JrVNaxGYXexI=; b=pAS5VjUqAM7IN1Hl4S/LnZ2k9KsBxSzHr6GYVldYjOCQt0VikQpyORtH3Mpay8TK+GVtOn D+i9f8fuM77bftCrrcBcwo/FUqxcka4QJf8Viey9UKwIwnirUCQNhpnJhh+3jZtmCd8JA+ 8LlVK6Z1fvaCH1HZxqaVJwXTkCvY0ok= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Julien Grall , Anthony PERARD Subject: [PATCH v2 05/13] tools/xenstore: make some write limit functions static Date: Thu, 30 Mar 2023 10:50:03 +0200 Message-Id: <20230330085011.9170-6-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230330085011.9170-1-jgross@suse.com> References: <20230330085011.9170-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1680166271519100001 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 be9175a461..0a8353dad5 100644 --- a/tools/xenstore/xenstored_domain.c +++ b/tools/xenstore/xenstored_domain.c @@ -159,6 +159,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); @@ -1443,234 +1671,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 b9e38abff5..8cd69d42ab 100644 --- a/tools/xenstore/xenstored_domain.h +++ b/tools/xenstore/xenstored_domain.h @@ -162,9 +162,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 Thu May 16 23:47:25 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=1680166278; cv=none; d=zohomail.com; s=zohoarc; b=K+621/+OXebWP1DOrf+q2hYn0ky26zwVRiFvaoT9seUg7nE2uh1R+ytPi2HT/GRMef4At+yzf+YpyYrMWf+uwOjT4fvJ1hxTDTmPbmXKBDuKkWZKbdpMrEKPwNqZOVoUMk/j8QaBptiJVVBcJcU1qbOG5Ml9SEfgye2jyyY/X1o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1680166278; 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=ZRzyXcBYIsQ+I9/0pFucQzlw0RZGeyj+n+0oBfMcYu8=; b=cvhKWzQQAtaPrPqyOOPm78XVSB/lAGumwRq6sHPzL5dCwgUgQAbw5fa/F6v63/P2iBevJxfDAZHU8uoKuzaaYNpQ7+O6hDy8aNHTLwGUGGHMb+gJ9bcFV5dQFbTJRMeMCEVXZAgnNSStOnFkiSHtTCDdP1QAvhT535Jzuga7Su0= 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 1680166278465539.0794584537657; Thu, 30 Mar 2023 01:51:18 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.516512.800743 (Exim 4.92) (envelope-from ) id 1phnzf-0007vt-CO; Thu, 30 Mar 2023 08:50:51 +0000 Received: by outflank-mailman (output) from mailman id 516512.800743; Thu, 30 Mar 2023 08:50:51 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1phnzf-0007vk-8i; Thu, 30 Mar 2023 08:50:51 +0000 Received: by outflank-mailman (input) for mailman id 516512; Thu, 30 Mar 2023 08:50:50 +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 1phnze-0005Qp-0q for xen-devel@lists.xenproject.org; Thu, 30 Mar 2023 08:50:50 +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 f73eadf9-ced7-11ed-b464-930f4c7d94ae; Thu, 30 Mar 2023 10:50:48 +0200 (CEST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id D977C1FEAA; Thu, 30 Mar 2023 08:50:47 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id A921A138FF; Thu, 30 Mar 2023 08:50:47 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 311oJ2dNJWQyIwAAMHmgww (envelope-from ); Thu, 30 Mar 2023 08:50:47 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: f73eadf9-ced7-11ed-b464-930f4c7d94ae DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1680166247; 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=ZRzyXcBYIsQ+I9/0pFucQzlw0RZGeyj+n+0oBfMcYu8=; b=uwJ0wMqxECH81+WhDgVDnotKmk4+W9GsPICIIaVOvf50oLbSUbloJd45kxpToZesOXFkex rxSTN/paBvGZpOPZC/8pVA2Qf8uKYBJM3AbsToTGAO6jLZNIS2rAxHWFiT7O41p8P8HLmZ LfLWrRUG6B9DQUXUoBCGGM0h31zRqXE= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Julien Grall , Anthony PERARD Subject: [PATCH v2 06/13] tools/xenstore: switch write limiting to use millisecond time base Date: Thu, 30 Mar 2023 10:50:04 +0200 Message-Id: <20230330085011.9170-7-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230330085011.9170-1-jgross@suse.com> References: <20230330085011.9170-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1680166279546100005 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 c5433e5b3f..6be2a3aa42 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 92d5b50f3c..84a611cbb5 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 @@ -320,6 +316,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 0a8353dad5..2fb142c5b3 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 @@ -159,6 +161,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; @@ -178,19 +191,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) /* @@ -217,7 +217,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, @@ -236,7 +236,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 @@ -245,18 +245,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; @@ -288,9 +282,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; @@ -327,13 +319,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; @@ -348,14 +340,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 8cd69d42ab..f9ee0bd141 100644 --- a/tools/xenstore/xenstored_domain.h +++ b/tools/xenstore/xenstored_domain.h @@ -145,27 +145,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 Thu May 16 23:47:25 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=1680166275; cv=none; d=zohomail.com; s=zohoarc; b=AaJgAYknHEgwFwR+Eb0icTG6Glkj9wBp5NAfHcJVtiEXXUuN47lZ6GFsFmiHcV5Vckj/hB8c4IAIVt5e3vUijAVvOt3xb5ybcf4hKGZZf5hR/3veEFkaIwK2aGEQYdEmzhRjXNv+Q6PWQ3iGoLQThReqyg5EC8NR68O+++ZdTe4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1680166275; 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=UGTCBEIv6a10+suniAj/4vO3f8KkouJn1kosoLixjPNlNhuoNl2sPakZzc/juQ4fAS7hUxexdPHwVEMKFZhBY50i3xb/DC/h9Oa5TwCaDdh/3P+O5zUuhtOwlNx5pmjGDKx6xgC6ICmwz8dA2aLXfzBiGoH0LsQV3gyB/Ei0CYk= 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 1680166275316423.6767278461697; Thu, 30 Mar 2023 01:51:15 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.516514.800753 (Exim 4.92) (envelope-from ) id 1phnzj-0008OA-OM; Thu, 30 Mar 2023 08:50:55 +0000 Received: by outflank-mailman (output) from mailman id 516514.800753; Thu, 30 Mar 2023 08:50:55 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1phnzj-0008Nt-KU; Thu, 30 Mar 2023 08:50:55 +0000 Received: by outflank-mailman (input) for mailman id 516514; Thu, 30 Mar 2023 08:50:54 +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 1phnzi-0005fr-2q for xen-devel@lists.xenproject.org; Thu, 30 Mar 2023 08:50:54 +0000 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id fa911ab0-ced7-11ed-85db-49a42c6b2330; Thu, 30 Mar 2023 10:50:53 +0200 (CEST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 75E2D1FEAA; Thu, 30 Mar 2023 08:50:53 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 4AA7B138FF; Thu, 30 Mar 2023 08:50:53 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id hlzcEG1NJWRDIwAAMHmgww (envelope-from ); Thu, 30 Mar 2023 08:50:53 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: fa911ab0-ced7-11ed-85db-49a42c6b2330 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1680166253; 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=VQiPEYFDNhYmB8OQVoK/9CWPHcjS0d4xwKwM+16jlaTU8Ajh+vamK3QFrQNB2VVhImis0D JKowpBqxphEuPUjezkyZD6HYyoRjGnklugh/8doRB3YnaoPC1jCBbHUsZSMp01bEt1v/Y2 c6jMzFgG2ur6XFO6AOt2INwgjCFy+OE= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Julien Grall , Anthony PERARD Subject: [PATCH v2 07/13] tools/xenstore: remove stale TODO file Date: Thu, 30 Mar 2023 10:50:05 +0200 Message-Id: <20230330085011.9170-8-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230330085011.9170-1-jgross@suse.com> References: <20230330085011.9170-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1680166275482100001 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 Acked-by: Julien Grall --- 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 Thu May 16 23:47:25 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=1680166275; cv=none; d=zohomail.com; s=zohoarc; b=CXAZGdzQOKdHbvry9g8Irc4MV8XNZSoJUUK+PCUodX6xqQvgtfQDhpvrR4zlJGa6f589HoAffJy8IGy+i1N579O+yY3/LDsnAdjp6MC0kWdLCtb478SP2F02Zqkg3xlrppZw9yfQQ4XIZ21ekQVUPs4klryeOFm5OwSLgMfftNM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1680166275; 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=T80cElhqLxq4rDBJa35Qe57b/vAHNK+lXXK39qwQ7f8=; b=NkH4GFkOf4fQ7SqVNeBZaQdL8Le72qQ+yecYkPYmfXMouvgPRuHMEEMq+bUv15gqo5NR8U/J94lcyT2n9CNEiurxCCw4wA8bFB8tT0o1hW0iRNlDqjKs32HTtT5Kxx4wrHWdzq1+jXn/nmW1PTi3Y0tbJHSMU5Gr5Xo6Z7Sk/c8= 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 1680166275655870.1071318738741; Thu, 30 Mar 2023 01:51:15 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.516517.800763 (Exim 4.92) (envelope-from ) id 1phnzp-0000Qp-1p; Thu, 30 Mar 2023 08:51:01 +0000 Received: by outflank-mailman (output) from mailman id 516517.800763; Thu, 30 Mar 2023 08:51:01 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1phnzo-0000Qc-UQ; Thu, 30 Mar 2023 08:51:00 +0000 Received: by outflank-mailman (input) for mailman id 516517; Thu, 30 Mar 2023 08:51:00 +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 1phnzn-0005fr-Vq for xen-devel@lists.xenproject.org; Thu, 30 Mar 2023 08:50:59 +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 fe16c54a-ced7-11ed-85db-49a42c6b2330; Thu, 30 Mar 2023 10:50:59 +0200 (CEST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 5F97221B0D; Thu, 30 Mar 2023 08:50:59 +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 2F3A1138FF; Thu, 30 Mar 2023 08:50:59 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id Vhn1CXNNJWRLIwAAMHmgww (envelope-from ); Thu, 30 Mar 2023 08:50:59 +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: fe16c54a-ced7-11ed-85db-49a42c6b2330 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1680166259; 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=T80cElhqLxq4rDBJa35Qe57b/vAHNK+lXXK39qwQ7f8=; b=AD2g/j7L31YdO58SaRadPox8D30vLPmjAsZ0YeTMmbSluay7kwuLjb4tFGySknN+kOpZ7D /SJHRn5jSeb1gIwuQ1ImYr8ejQS/rFcid7uXIeJtqhfX/DuF98jMuD5ejD3RzcnvOaB8P5 jiRDaZBkOFeHTpdBg8D1taVcdmLA22s= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Julien Grall , Anthony PERARD Subject: [PATCH v2 08/13] tools/xenstore: remove unused events list Date: Thu, 30 Mar 2023 10:50:06 +0200 Message-Id: <20230330085011.9170-9-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230330085011.9170-1-jgross@suse.com> References: <20230330085011.9170-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1680166277486100003 Content-Type: text/plain; charset="utf-8" struct watch contains an used struct list_head events. Remove it. Signed-off-by: Juergen Gross Acked-by: Julien Grall --- 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 e8eb35de02..4195c59e17 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 Thu May 16 23:47:25 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=1680166284; cv=none; d=zohomail.com; s=zohoarc; b=RvjEIPbcijotvIDp6QMJ8/9y36RjCWrG//9LgBkvPshFHTvdLZ6f8FeYGQ3fWys4d3XSvPP3TtpKZdZwot1j7RReSTLaN2d6asK4RwoPIYzNqueufRNJfCJaPNT3arDC/ITNEV7rBylL99wvWDSLJRuf668BA3az3DNGb6go8tc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1680166284; 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=IKAu+O48PLg3XO94zi8bHJvfv1O8cLs67CyWNbGEDfo=; b=DAybDI0+tndL0IfJy9JHJDbzDkdg2YB5ULLlb9EHSpFke8DavFpSIezZZk1u69o2h4hzCl7guOcKEwcO6KvvtIsmZDbYK27DUAuREGQUWRJ90B1kvOMVvSIj1N213SEpfSuhYdgCOqvotpZlZZHhwAFbPrj+z2jXZ1D16x/7z50= 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 1680166284940884.3375957574916; Thu, 30 Mar 2023 01:51:24 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.516521.800773 (Exim 4.92) (envelope-from ) id 1phnzx-000134-AW; Thu, 30 Mar 2023 08:51:09 +0000 Received: by outflank-mailman (output) from mailman id 516521.800773; Thu, 30 Mar 2023 08:51:09 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1phnzx-00012A-6b; Thu, 30 Mar 2023 08:51:09 +0000 Received: by outflank-mailman (input) for mailman id 516521; Thu, 30 Mar 2023 08:51:07 +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 1phnzv-0005Qp-90 for xen-devel@lists.xenproject.org; Thu, 30 Mar 2023 08:51:07 +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 018071f1-ced8-11ed-b464-930f4c7d94ae; Thu, 30 Mar 2023 10:51:05 +0200 (CEST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 15DDB21B0D; Thu, 30 Mar 2023 08:51: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 DC573138FF; Thu, 30 Mar 2023 08:51:04 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id poWMNHhNJWRcIwAAMHmgww (envelope-from ); Thu, 30 Mar 2023 08:51:04 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 018071f1-ced8-11ed-b464-930f4c7d94ae DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1680166265; 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=IKAu+O48PLg3XO94zi8bHJvfv1O8cLs67CyWNbGEDfo=; b=Xao28aq2UxzLXBiN89YmjAr9pmPSxuysP0GiDIwIqp44OEfCxR2+OtUB5Bd2YPYoZ8s4w4 3oPwxMZgGHNdHV9A4pFXFMP+gqewvXLX1jROt9JCqd9dKhfTJLSaB9BUR+Tbf1BbaxqaG8 04X7IJBFbzuCbK2uSVwxLWXNJyVsqQk= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Julien Grall , Anthony PERARD Subject: [PATCH v2 09/13] tools/xenstore: remove support of file backed data base Date: Thu, 30 Mar 2023 10:50:07 +0200 Message-Id: <20230330085011.9170-10-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230330085011.9170-1-jgross@suse.com> References: <20230330085011.9170-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1680166285736100001 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 6be2a3aa42..e16d0a6d53 100644 --- a/tools/xenstore/xenstored_core.c +++ b/tools/xenstore/xenstored_core.c @@ -2291,8 +2291,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) { @@ -2344,14 +2342,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) @@ -2649,8 +2644,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"); @@ -2677,7 +2670,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' }, @@ -2800,7 +2792,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': @@ -2837,10 +2829,6 @@ int main(int argc, char *argv[]) if (set_trace_switch(optarg)) barf("Illegal trace switch \"%s\"\n", 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 Thu May 16 23:47:25 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=1680166769; cv=none; d=zohomail.com; s=zohoarc; b=LLycoBdlXxlrIF60kk3lsQx4fJWzqUqZiryFNoCG4lot/DMErtqrxKhVlRYCycfOrMxzIDIJEZ8crcBs2DjLxB0dv2jqnvDpJUz3tpBjmIE+hBziv1C7XwDbmCZ8zbrqMWwJN6lUfr4yNAkVJIPdgOlJcg8uMu++BSCHxwMXn90= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1680166769; 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=n+LXWDKrHnNBBBh+eqFebI/xwup+/rnEIgqudl+aDTI=; b=HNNdOtZlfKglMNMbUwhggsTIBJrASpqjDHThijIA9A1gluyp2NzSwIMW8SL48gOzBHntJYGw+yDaaT9az1JHpYKbDkfLFwA4VtQL8ZJxCcRslIe3HYsb3oG0CuTp0AWrJWaW5SuWeeNkKVBgyDFh8Ke9Mo7OIDexNukKe6RlQTY= 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 1680166769226634.5340158852692; Thu, 30 Mar 2023 01:59:29 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.516535.800814 (Exim 4.92) (envelope-from ) id 1pho7e-00048C-2o; Thu, 30 Mar 2023 08:59:06 +0000 Received: by outflank-mailman (output) from mailman id 516535.800814; Thu, 30 Mar 2023 08:59:06 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pho7d-000485-UK; Thu, 30 Mar 2023 08:59:05 +0000 Received: by outflank-mailman (input) for mailman id 516535; Thu, 30 Mar 2023 08:59:03 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1phnzz-0005fr-S0 for xen-devel@lists.xenproject.org; Thu, 30 Mar 2023 08:51:12 +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 04dd9234-ced8-11ed-85db-49a42c6b2330; Thu, 30 Mar 2023 10:51:11 +0200 (CEST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id B79661FEAA; Thu, 30 Mar 2023 08:51:10 +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 80343138FF; Thu, 30 Mar 2023 08:51:10 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id LiHdHX5NJWRkIwAAMHmgww (envelope-from ); Thu, 30 Mar 2023 08:51: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: 04dd9234-ced8-11ed-85db-49a42c6b2330 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1680166270; 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=n+LXWDKrHnNBBBh+eqFebI/xwup+/rnEIgqudl+aDTI=; b=FW0lERnQI2c8NY81FGNYOqXsmd0iwh6gSC9Xv99qHsYMKX1vrftkz/gLbfOP75s3fXj+La +Z7iiketYiYQiDrAm11gEDmC2W15aRlTDCGylChbjMGu9nw0pxfWeloycFVJdzg+PBtSPx gKTFk+IxrZDZ6HNuweV9QfiemNzco2c= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Anthony PERARD , Julien Grall Subject: [PATCH v2 10/13] tools/xenstore: remove no longer needed functions from xs_lib.c Date: Thu, 30 Mar 2023 10:50:08 +0200 Message-Id: <20230330085011.9170-11-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230330085011.9170-1-jgross@suse.com> References: <20230330085011.9170-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1680166770182100003 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() and xs_write_all() are not used by xenstored, so they 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 --- V2: - move xs_write_all(), too --- tools/include/xenstore.h | 3 + tools/include/xenstore_lib.h | 3 - tools/libs/store/xs.c | 38 ++++++++ tools/xenstore/xenstore_client.c | 129 +++++++++++++++++++++++++ tools/xenstore/xs_lib.c | 156 ------------------------------- tools/xenstore/xs_lib.h | 17 ---- 6 files changed, 170 insertions(+), 176 deletions(-) diff --git a/tools/include/xenstore.h b/tools/include/xenstore.h index 2b3f69fb61..a442252849 100644 --- a/tools/include/xenstore.h +++ b/tools/include/xenstore.h @@ -113,6 +113,9 @@ void *xs_read(struct xs_handle *h, xs_transaction_t t, bool xs_write(struct xs_handle *h, xs_transaction_t t, const char *path, const void *data, unsigned int len); =20 +/* Simple write function: loops for you. */ +bool xs_write_all(int fd, const void *data, unsigned int len); + /* Create a new directory. * Returns false on failure, or success if it already exists. */ diff --git a/tools/include/xenstore_lib.h b/tools/include/xenstore_lib.h index 2266009ec1..43eec87379 100644 --- a/tools/include/xenstore_lib.h +++ b/tools/include/xenstore_lib.h @@ -47,9 +47,6 @@ const char *xs_daemon_rundir(void); const char *xs_daemon_socket(void); const char *xs_daemon_socket_ro(void); =20 -/* Simple write function: loops for you. */ -bool xs_write_all(int fd, const void *data, unsigned int len); - /* Convert strings to permissions. False if a problem. */ bool xs_strings_to_perms(struct xs_permissions *perms, unsigned int num, const char *strings); diff --git a/tools/libs/store/xs.c b/tools/libs/store/xs.c index 7a9a8b1656..48b0e917be 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; @@ -431,6 +451,24 @@ out_false: #ifdef XSTEST #define read_all read_all_choice #define xs_write_all write_all_choice +#else +/* Simple routine for writing to sockets, etc. */ +bool xs_write_all(int fd, const void *data, unsigned int len) +{ + while (len) { + int done; + + done =3D write(fd, data, len); + if (done < 0 && errno =3D=3D EINTR) + continue; + if (done <=3D 0) + return false; + data +=3D done; + len -=3D done; + } + + return true; +} #endif =20 static int get_error(const char *errorstring) 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..37e2a272ca 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,44 +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) -{ - while (len) { - int done; - - done =3D write(fd, data, len); - if (done < 0 && errno =3D=3D EINTR) - continue; - if (done <=3D 0) - return false; - data +=3D done; - len -=3D done; - } - - return true; -} - /* Convert strings to permissions. False if a problem. */ bool xs_strings_to_perms(struct xs_permissions *perms, unsigned int num, const char *strings) @@ -179,114 +134,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 From nobody Thu May 16 23:47:25 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=1680166767; cv=none; d=zohomail.com; s=zohoarc; b=c4xfioZEIEqqXqEgid9jGO36OOLhJ1AErfL9y1vrdccgr8u+kulWRLu8v+wj1gVfRzb4S4YFJAsiyCAaxEjinBlIBDSf6IYGaXG7GsIg/QX9aCJHHISDi+xtS26vv4943Oe+L9WIGcKgoDeQbWYsa3JFBAExH0bu3hRjoLJgQJA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1680166767; 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=zAR+D5IOBUizI647Da3RaQFwZvOMED7CwgvKNtyoeSU=; b=XwV0g6YhE6+FZKefAf9+eujEmI6YLwQ65Efth+60T8OIZ/ijQjrCqX6aSlNrswXv0D3BV7ML2YQm5Y93tZctnuS/h9z83XCZ8TWqPewOYy53zD8AhE+94ssZAi/8WP+gcwonmoUr+XZUP7TlvlJ5cOx1vuGA5iqW4Ic6m3dbEtw= 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 1680166767476762.5646981997097; Thu, 30 Mar 2023 01:59:27 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.516533.800803 (Exim 4.92) (envelope-from ) id 1pho7c-0003tN-R8; Thu, 30 Mar 2023 08:59:04 +0000 Received: by outflank-mailman (output) from mailman id 516533.800803; Thu, 30 Mar 2023 08:59:04 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pho7c-0003tG-Mz; Thu, 30 Mar 2023 08:59:04 +0000 Received: by outflank-mailman (input) for mailman id 516533; Thu, 30 Mar 2023 08:59:03 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pho05-0005fr-KE for xen-devel@lists.xenproject.org; Thu, 30 Mar 2023 08:51:17 +0000 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 083a5d76-ced8-11ed-85db-49a42c6b2330; Thu, 30 Mar 2023 10:51:16 +0200 (CEST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 623061FEAA; Thu, 30 Mar 2023 08:51: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 24403138FF; Thu, 30 Mar 2023 08:51:16 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id QGV/B4RNJWRuIwAAMHmgww (envelope-from ); Thu, 30 Mar 2023 08:51: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: 083a5d76-ced8-11ed-85db-49a42c6b2330 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1680166276; 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=zAR+D5IOBUizI647Da3RaQFwZvOMED7CwgvKNtyoeSU=; b=sf2j7Au+KNRhktSpIulbaSKhECES2Hr5Xvea+ykuaZAFq/W6WkHHiKkwi9Iqh3bo3Tsl/c BtvGku66ic9pZYB84M4rPk4vjSlsI5PlpeMHDa5snWbwYEXpTFtMTw9j1AJhPskM/NBR74 NV2wMjKiuf4LwBJ3u3+6qDC252SBTJI= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Julien Grall , Anthony PERARD Subject: [PATCH v2 11/13] tools/xenstore: split out environment specific live update code Date: Thu, 30 Mar 2023 10:50:09 +0200 Message-Id: <20230330085011.9170-12-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230330085011.9170-1-jgross@suse.com> References: <20230330085011.9170-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1680166768321100001 Content-Type: text/plain; charset="utf-8" Instead of using #ifdef in xenstored_control.c split out the code of environment specific functions (daemon or Mini-OS) to dedicated source files. Signed-off-by: Juergen Gross --- tools/xenstore/Makefile.common | 8 +- tools/xenstore/xenstored_control.c | 252 +-------------------------- tools/xenstore/xenstored_lu.h | 56 ++++++ tools/xenstore/xenstored_lu_daemon.c | 132 ++++++++++++++ tools/xenstore/xenstored_lu_minios.c | 121 +++++++++++++ 5 files changed, 316 insertions(+), 253 deletions(-) create mode 100644 tools/xenstore/xenstored_lu.h create mode 100644 tools/xenstore/xenstored_lu_daemon.c create mode 100644 tools/xenstore/xenstored_lu_minios.c diff --git a/tools/xenstore/Makefile.common b/tools/xenstore/Makefile.common index b18f95c103..dffab34603 100644 --- a/tools/xenstore/Makefile.common +++ b/tools/xenstore/Makefile.common @@ -4,10 +4,10 @@ XENSTORED_OBJS-y :=3D xenstored_core.o xenstored_watch.o = xenstored_domain.o XENSTORED_OBJS-y +=3D xenstored_transaction.o xenstored_control.o XENSTORED_OBJS-y +=3D xs_lib.o talloc.o utils.o tdb.o hashtable.o =20 -XENSTORED_OBJS-$(CONFIG_Linux) +=3D xenstored_posix.o -XENSTORED_OBJS-$(CONFIG_NetBSD) +=3D xenstored_posix.o -XENSTORED_OBJS-$(CONFIG_FreeBSD) +=3D xenstored_posix.o -XENSTORED_OBJS-$(CONFIG_MiniOS) +=3D xenstored_minios.o +XENSTORED_OBJS-$(CONFIG_Linux) +=3D xenstored_posix.o xenstored_lu_daemon.o +XENSTORED_OBJS-$(CONFIG_NetBSD) +=3D xenstored_posix.o xenstored_lu_daemon= .o +XENSTORED_OBJS-$(CONFIG_FreeBSD) +=3D xenstored_posix.o xenstored_lu_daemo= n.o +XENSTORED_OBJS-$(CONFIG_MiniOS) +=3D xenstored_minios.o xenstored_lu_minio= s.o =20 # Include configure output (config.h) CFLAGS +=3D -include $(XEN_ROOT)/tools/config.h diff --git a/tools/xenstore/xenstored_control.c b/tools/xenstore/xenstored_= control.c index 75f51a80db..c9e5766954 100644 --- a/tools/xenstore/xenstored_control.c +++ b/tools/xenstore/xenstored_control.c @@ -38,63 +38,13 @@ #include "xenstored_core.h" #include "xenstored_control.h" #include "xenstored_domain.h" +#include "xenstored_lu.h" #include "xenstored_watch.h" =20 -/* Mini-OS only knows about MAP_ANON. */ -#ifndef MAP_ANONYMOUS -#define MAP_ANONYMOUS MAP_ANON -#endif - #ifndef NO_LIVE_UPDATE -struct live_update { - /* For verification the correct connection is acting. */ - struct connection *conn; - - /* Pointer to the command used to request LU */ - struct buffered_data *in; +struct live_update *lu_status; =20 -#ifdef __MINIOS__ - void *kernel; - unsigned int kernel_size; - unsigned int kernel_off; - - void *dump_state; - unsigned long dump_size; -#else - char *filename; -#endif - - char *cmdline; - - /* Start parameters. */ - bool force; - unsigned int timeout; - time_t started_at; -}; - -static struct live_update *lu_status; - -struct lu_dump_state { - void *buf; - unsigned int size; -#ifndef __MINIOS__ - int fd; - char *filename; -#endif -}; - -static int lu_destroy(void *data) -{ -#ifdef __MINIOS__ - if (lu_status->dump_state) - munmap(lu_status->dump_state, lu_status->dump_size); -#endif - lu_status =3D NULL; - - return 0; -} - -static const char *lu_begin(struct connection *conn) +const char *lu_begin(struct connection *conn) { if (lu_status) return "live-update session already active."; @@ -431,202 +381,6 @@ static const char *lu_cmdline(const void *ctx, struct= connection *conn, return NULL; } =20 -#ifdef __MINIOS__ -static const char *lu_binary_alloc(const void *ctx, struct connection *con= n, - unsigned long size) -{ - const char *ret; - - syslog(LOG_INFO, "live-update: binary size %lu\n", size); - - ret =3D lu_begin(conn); - if (ret) - return ret; - - lu_status->kernel =3D talloc_size(lu_status, size); - if (!lu_status->kernel) - return "Allocation failure."; - - lu_status->kernel_size =3D size; - lu_status->kernel_off =3D 0; - - errno =3D 0; - return NULL; -} - -static const char *lu_binary_save(const void *ctx, struct connection *conn, - unsigned int size, const char *data) -{ - if (!lu_status || lu_status->conn !=3D conn) - return "Not in live-update session."; - - if (lu_status->kernel_off + size > lu_status->kernel_size) - return "Too much kernel data."; - - memcpy(lu_status->kernel + lu_status->kernel_off, data, size); - lu_status->kernel_off +=3D size; - - errno =3D 0; - return NULL; -} - -static const char *lu_arch(const void *ctx, struct connection *conn, - char **vec, int num) -{ - if (num =3D=3D 2 && !strcmp(vec[0], "-b")) - return lu_binary_alloc(ctx, conn, atol(vec[1])); - if (num > 2 && !strcmp(vec[0], "-d")) - return lu_binary_save(ctx, conn, atoi(vec[1]), vec[2]); - - errno =3D EINVAL; - return NULL; -} - -static FILE *lu_dump_open(const void *ctx) -{ - lu_status->dump_size =3D ROUNDUP(talloc_total_size(NULL) * 2, - XC_PAGE_SHIFT); - lu_status->dump_state =3D mmap(NULL, lu_status->dump_size, - PROT_READ | PROT_WRITE, - MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); - if (lu_status->dump_state =3D=3D MAP_FAILED) - return NULL; - - return fmemopen(lu_status->dump_state, lu_status->dump_size, "w"); -} - -static void lu_dump_close(FILE *fp) -{ - size_t size; - - size =3D ftell(fp); - size =3D ROUNDUP(size, XC_PAGE_SHIFT); - munmap(lu_status->dump_state + size, lu_status->dump_size - size); - lu_status->dump_size =3D size; - - fclose(fp); -} - -static void lu_get_dump_state(struct lu_dump_state *state) -{ -} - -static void lu_close_dump_state(struct lu_dump_state *state) -{ -} - -static char *lu_exec(const void *ctx, int argc, char **argv) -{ - return "NYI"; -} -#else -static const char *lu_binary(const void *ctx, struct connection *conn, - const char *filename) -{ - const char *ret; - struct stat statbuf; - - syslog(LOG_INFO, "live-update: binary %s\n", filename); - - if (stat(filename, &statbuf)) - return "File not accessible."; - if (!(statbuf.st_mode & (S_IXOTH | S_IXGRP | S_IXUSR))) - return "File not executable."; - - ret =3D lu_begin(conn); - if (ret) - return ret; - - lu_status->filename =3D talloc_strdup(lu_status, filename); - if (!lu_status->filename) - return "Allocation failure."; - - errno =3D 0; - return NULL; -} - -static const char *lu_arch(const void *ctx, struct connection *conn, - char **vec, int num) -{ - if (num =3D=3D 2 && !strcmp(vec[0], "-f")) - return lu_binary(ctx, conn, vec[1]); - - errno =3D EINVAL; - return NULL; -} - -static FILE *lu_dump_open(const void *ctx) -{ - char *filename; - int fd; - - filename =3D talloc_asprintf(ctx, "%s/state_dump", xs_daemon_rootdir()); - if (!filename) - return NULL; - - fd =3D open(filename, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR); - if (fd < 0) - return NULL; - - return fdopen(fd, "w"); -} - -static void lu_dump_close(FILE *fp) -{ - fclose(fp); -} - -static void lu_get_dump_state(struct lu_dump_state *state) -{ - struct stat statbuf; - - state->size =3D 0; - - state->filename =3D talloc_asprintf(NULL, "%s/state_dump", - xs_daemon_rootdir()); - if (!state->filename) - barf("Allocation failure"); - - state->fd =3D open(state->filename, O_RDONLY); - if (state->fd < 0) - return; - if (fstat(state->fd, &statbuf) !=3D 0) - goto out_close; - state->size =3D statbuf.st_size; - - state->buf =3D mmap(NULL, state->size, PROT_READ, MAP_PRIVATE, - state->fd, 0); - if (state->buf =3D=3D MAP_FAILED) { - state->size =3D 0; - goto out_close; - } - - return; - - out_close: - close(state->fd); -} - -static void lu_close_dump_state(struct lu_dump_state *state) -{ - assert(state->filename !=3D NULL); - - munmap(state->buf, state->size); - close(state->fd); - - unlink(state->filename); - talloc_free(state->filename); -} - -static char *lu_exec(const void *ctx, int argc, char **argv) -{ - argv[0] =3D lu_status->filename; - execvp(argv[0], argv); - - return "Error activating new binary."; -} -#endif - static bool lu_check_lu_allowed(void) { struct connection *conn; diff --git a/tools/xenstore/xenstored_lu.h b/tools/xenstore/xenstored_lu.h new file mode 100644 index 0000000000..d2f8e4e57c --- /dev/null +++ b/tools/xenstore/xenstored_lu.h @@ -0,0 +1,56 @@ +/* SPDX-License-Identifier: MIT */ + +/* + * Live Update interfaces for Xen Store Daemon. + * Copyright (C) 2022 Juergen Gross, SUSE LLC + */ + +#ifndef NO_LIVE_UPDATE +struct live_update { + /* For verification the correct connection is acting. */ + struct connection *conn; + + /* Pointer to the command used to request LU */ + struct buffered_data *in; + +#ifdef __MINIOS__ + void *kernel; + unsigned int kernel_size; + unsigned int kernel_off; + + void *dump_state; + unsigned long dump_size; +#else + char *filename; +#endif + + char *cmdline; + + /* Start parameters. */ + bool force; + unsigned int timeout; + time_t started_at; +}; + +struct lu_dump_state { + void *buf; + unsigned int size; +#ifndef __MINIOS__ + int fd; + char *filename; +#endif +}; + +extern struct live_update *lu_status; + +/* Live update private interfaces. */ +void lu_get_dump_state(struct lu_dump_state *state); +void lu_close_dump_state(struct lu_dump_state *state); +FILE *lu_dump_open(const void *ctx); +void lu_dump_close(FILE *fp); +char *lu_exec(const void *ctx, int argc, char **argv); +const char *lu_arch(const void *ctx, struct connection *conn, char **vec, + int num); +const char *lu_begin(struct connection *conn); +int lu_destroy(void *data); +#endif diff --git a/tools/xenstore/xenstored_lu_daemon.c b/tools/xenstore/xenstore= d_lu_daemon.c new file mode 100644 index 0000000000..bda543e492 --- /dev/null +++ b/tools/xenstore/xenstored_lu_daemon.c @@ -0,0 +1,132 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +/* + * Live Update for Xen Store Daemon. + * Copyright (C) 2022 Juergen Gross, SUSE LLC + */ + +#include +#include +#include +#include +#include + +#include "talloc.h" +#include "xs_lib.h" +#include "xenstored_core.h" +#include "xenstored_lu.h" + +#ifndef NO_LIVE_UPDATE +void lu_get_dump_state(struct lu_dump_state *state) +{ + struct stat statbuf; + + state->size =3D 0; + + state->filename =3D talloc_asprintf(NULL, "%s/state_dump", + xs_daemon_rootdir()); + if (!state->filename) + barf("Allocation failure"); + + state->fd =3D open(state->filename, O_RDONLY); + if (state->fd < 0) + return; + if (fstat(state->fd, &statbuf) !=3D 0) + goto out_close; + state->size =3D statbuf.st_size; + + state->buf =3D mmap(NULL, state->size, PROT_READ, MAP_PRIVATE, + state->fd, 0); + if (state->buf =3D=3D MAP_FAILED) { + state->size =3D 0; + goto out_close; + } + + return; + + out_close: + close(state->fd); +} + +void lu_close_dump_state(struct lu_dump_state *state) +{ + assert(state->filename !=3D NULL); + + munmap(state->buf, state->size); + close(state->fd); + + unlink(state->filename); + talloc_free(state->filename); +} + +FILE *lu_dump_open(const void *ctx) +{ + char *filename; + int fd; + + filename =3D talloc_asprintf(ctx, "%s/state_dump", xs_daemon_rootdir()); + if (!filename) + return NULL; + + fd =3D open(filename, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR); + if (fd < 0) + return NULL; + + return fdopen(fd, "w"); +} + +void lu_dump_close(FILE *fp) +{ + fclose(fp); +} + +char *lu_exec(const void *ctx, int argc, char **argv) +{ + argv[0] =3D lu_status->filename; + execvp(argv[0], argv); + + return "Error activating new binary."; +} + +int lu_destroy(void *data) +{ + lu_status =3D NULL; + + return 0; +} + +static const char *lu_binary(const void *ctx, struct connection *conn, + const char *filename) +{ + const char *ret; + struct stat statbuf; + + syslog(LOG_INFO, "live-update: binary %s\n", filename); + + if (stat(filename, &statbuf)) + return "File not accessible."; + if (!(statbuf.st_mode & (S_IXOTH | S_IXGRP | S_IXUSR))) + return "File not executable."; + + ret =3D lu_begin(conn); + if (ret) + return ret; + + lu_status->filename =3D talloc_strdup(lu_status, filename); + if (!lu_status->filename) + return "Allocation failure."; + + errno =3D 0; + return NULL; +} + +const char *lu_arch(const void *ctx, struct connection *conn, char **vec, + int num) +{ + if (num =3D=3D 2 && !strcmp(vec[0], "-f")) + return lu_binary(ctx, conn, vec[1]); + + errno =3D EINVAL; + return NULL; +} +#endif diff --git a/tools/xenstore/xenstored_lu_minios.c b/tools/xenstore/xenstore= d_lu_minios.c new file mode 100644 index 0000000000..0bec8a0037 --- /dev/null +++ b/tools/xenstore/xenstored_lu_minios.c @@ -0,0 +1,121 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +/* + * Live Update for Xen Store Daemon. + * Copyright (C) 2022 Juergen Gross, SUSE LLC + */ + +#include +#include +#include +#include +#include +#include +#include + +#include "talloc.h" +#include "xenstored_lu.h" + +/* Mini-OS only knows about MAP_ANON. */ +#ifndef MAP_ANONYMOUS +#define MAP_ANONYMOUS MAP_ANON +#endif + +#ifndef NO_LIVE_UPDATE +void lu_get_dump_state(struct lu_dump_state *state) +{ +} + +void lu_close_dump_state(struct lu_dump_state *state) +{ +} + +FILE *lu_dump_open(const void *ctx) +{ + lu_status->dump_size =3D ROUNDUP(talloc_total_size(NULL) * 2, + XC_PAGE_SHIFT); + lu_status->dump_state =3D mmap(NULL, lu_status->dump_size, + PROT_READ | PROT_WRITE, + MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); + if (lu_status->dump_state =3D=3D MAP_FAILED) + return NULL; + + return fmemopen(lu_status->dump_state, lu_status->dump_size, "w"); +} + +void lu_dump_close(FILE *fp) +{ + size_t size; + + size =3D ftell(fp); + size =3D ROUNDUP(size, XC_PAGE_SHIFT); + munmap(lu_status->dump_state + size, lu_status->dump_size - size); + lu_status->dump_size =3D size; + + fclose(fp); +} + +char *lu_exec(const void *ctx, int argc, char **argv) +{ + return "NYI"; +} + +int lu_destroy(void *data) +{ + if (lu_status->dump_state) + munmap(lu_status->dump_state, lu_status->dump_size); + lu_status =3D NULL; + + return 0; +} + +static const char *lu_binary_alloc(const void *ctx, struct connection *con= n, + unsigned long size) +{ + const char *ret; + + syslog(LOG_INFO, "live-update: binary size %lu\n", size); + + ret =3D lu_begin(conn); + if (ret) + return ret; + + lu_status->kernel =3D talloc_size(lu_status, size); + if (!lu_status->kernel) + return "Allocation failure."; + + lu_status->kernel_size =3D size; + lu_status->kernel_off =3D 0; + + errno =3D 0; + return NULL; +} + +static const char *lu_binary_save(const void *ctx, struct connection *conn, + unsigned int size, const char *data) +{ + if (!lu_status || lu_status->conn !=3D conn) + return "Not in live-update session."; + + if (lu_status->kernel_off + size > lu_status->kernel_size) + return "Too much kernel data."; + + memcpy(lu_status->kernel + lu_status->kernel_off, data, size); + lu_status->kernel_off +=3D size; + + errno =3D 0; + return NULL; +} + +const char *lu_arch(const void *ctx, struct connection *conn, char **vec, + int num) +{ + if (num =3D=3D 2 && !strcmp(vec[0], "-b")) + return lu_binary_alloc(ctx, conn, atol(vec[1])); + if (num > 2 && !strcmp(vec[0], "-d")) + return lu_binary_save(ctx, conn, atoi(vec[1]), vec[2]); + + errno =3D EINVAL; + return NULL; +} +#endif --=20 2.35.3 From nobody Thu May 16 23:47:25 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=1680166308; cv=none; d=zohomail.com; s=zohoarc; b=iQo8IQmuHcVWlixGvH9kz2X/xSO8q7jVTx+kJpmkFTfYNHMx8X6D6QaOPHmnbBO4WP2tPVcHjuAK979ulDiHYcEEJGe0EXts9St+v5y3IPsdNxthaPJzceHjVQ9FDrtdhKodw+uSQZoBoWS/E3r0/EjlgGvNYyTRr6WFWJuhwrU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1680166308; 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=HVRwBPRCNdBEJy67m+yudS9lbg/8d/q4E24a/0jlcgQ=; b=gY51ramWG8Sk0QzUbUlpIe7arpRglWSRCnferCb8Rlzm7UiwvZw1omiP9RarDXIl5Qix35vUj+TOUviLnroEf1YgkwGkgVE9zy7SoT63b69Ahw6L6fGlPB5YA2BOe9I2C3KuP0BBI8OpH1Mwi6X38iN/eq8fP8lWTvEiGZ70Gek= 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 1680166308234564.0704859205119; Thu, 30 Mar 2023 01:51:48 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.516527.800783 (Exim 4.92) (envelope-from ) id 1pho0D-00022c-LO; Thu, 30 Mar 2023 08:51:25 +0000 Received: by outflank-mailman (output) from mailman id 516527.800783; Thu, 30 Mar 2023 08:51: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 1pho0D-00021d-HT; Thu, 30 Mar 2023 08:51:25 +0000 Received: by outflank-mailman (input) for mailman id 516527; Thu, 30 Mar 2023 08:51:25 +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 1pho0C-0005Qp-Nk for xen-devel@lists.xenproject.org; Thu, 30 Mar 2023 08:51:25 +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 0b916d88-ced8-11ed-b464-930f4c7d94ae; Thu, 30 Mar 2023 10:51:22 +0200 (CEST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id EE52A1FEAA; Thu, 30 Mar 2023 08:51:21 +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 B9BB2138FF; Thu, 30 Mar 2023 08:51:21 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id NbzmK4lNJWR3IwAAMHmgww (envelope-from ); Thu, 30 Mar 2023 08:51:21 +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: 0b916d88-ced8-11ed-b464-930f4c7d94ae DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1680166281; 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=HVRwBPRCNdBEJy67m+yudS9lbg/8d/q4E24a/0jlcgQ=; b=TyxL24SGpH8Y0jnXq6r4e3ftuV/ZYXbGpu2e0D06cGazE/vZLBU7JEHWtGfe8BVSL1vO4e mGf7A3cteP8pPVuQoJlKgwEUSYa8jDpyn/TQdBvmUZqO/GGuBBpaJbwLJ8rvCAYFpq6y6G HUIwcBQSQ1Jl3NRrAMyGFJc63+sCqW4= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Julien Grall , Anthony PERARD Subject: [PATCH v2 12/13] tools/xenstore: split out rest of live update control code Date: Thu, 30 Mar 2023 10:50:10 +0200 Message-Id: <20230330085011.9170-13-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230330085011.9170-1-jgross@suse.com> References: <20230330085011.9170-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1680166309676100001 Content-Type: text/plain; charset="utf-8" Move the rest of live update related code from xenstored_control.c to a dedicated new source file. Signed-off-by: Juergen Gross --- tools/xenstore/Makefile.common | 2 +- tools/xenstore/xenstored_control.c | 409 ----------------------------- tools/xenstore/xenstored_control.h | 8 - tools/xenstore/xenstored_core.c | 1 + tools/xenstore/xenstored_lu.c | 401 ++++++++++++++++++++++++++++ tools/xenstore/xenstored_lu.h | 25 ++ 6 files changed, 428 insertions(+), 418 deletions(-) create mode 100644 tools/xenstore/xenstored_lu.c diff --git a/tools/xenstore/Makefile.common b/tools/xenstore/Makefile.common index dffab34603..2befede03d 100644 --- a/tools/xenstore/Makefile.common +++ b/tools/xenstore/Makefile.common @@ -1,7 +1,7 @@ # Makefile shared with stubdom =20 XENSTORED_OBJS-y :=3D xenstored_core.o xenstored_watch.o xenstored_domain.o -XENSTORED_OBJS-y +=3D xenstored_transaction.o xenstored_control.o +XENSTORED_OBJS-y +=3D xenstored_transaction.o xenstored_control.o xenstore= d_lu.o XENSTORED_OBJS-y +=3D xs_lib.o talloc.o utils.o tdb.o hashtable.o =20 XENSTORED_OBJS-$(CONFIG_Linux) +=3D xenstored_posix.o xenstored_lu_daemon.o diff --git a/tools/xenstore/xenstored_control.c b/tools/xenstore/xenstored_= control.c index c9e5766954..4d66e61b2c 100644 --- a/tools/xenstore/xenstored_control.c +++ b/tools/xenstore/xenstored_control.c @@ -16,21 +16,13 @@ along with this program; If not, see . */ =20 -#include -#include #include #include #include #include #include -#include -#include #include -#include -#include -#include #include -#include =20 #include "utils.h" #include "talloc.h" @@ -39,69 +31,6 @@ #include "xenstored_control.h" #include "xenstored_domain.h" #include "xenstored_lu.h" -#include "xenstored_watch.h" - -#ifndef NO_LIVE_UPDATE -struct live_update *lu_status; - -const char *lu_begin(struct connection *conn) -{ - if (lu_status) - return "live-update session already active."; - - lu_status =3D talloc_zero(conn, struct live_update); - if (!lu_status) - return "Allocation failure."; - lu_status->conn =3D conn; - talloc_set_destructor(lu_status, lu_destroy); - - return NULL; -} - -struct connection *lu_get_connection(void) -{ - return lu_status ? lu_status->conn : NULL; -} - -unsigned int lu_write_response(FILE *fp) -{ - struct xsd_sockmsg msg; - - assert(lu_status); - - msg =3D lu_status->in->hdr.msg; - - msg.len =3D sizeof("OK"); - if (fp && fwrite(&msg, sizeof(msg), 1, fp) !=3D 1) - return 0; - if (fp && fwrite("OK", msg.len, 1, fp) !=3D 1) - return 0; - - return sizeof(msg) + msg.len; -} - -bool lu_is_pending(void) -{ - return lu_status !=3D NULL; -} - -#else -struct connection *lu_get_connection(void) -{ - return NULL; -} - -unsigned int lu_write_response(FILE *fp) -{ - /* Unsupported */ - return 0; -} - -bool lu_is_pending(void) -{ - return false; -} -#endif =20 struct cmd_s { char *cmd; @@ -352,344 +281,6 @@ static int do_control_print(const void *ctx, struct c= onnection *conn, return 0; } =20 -#ifndef NO_LIVE_UPDATE -static const char *lu_abort(const void *ctx, struct connection *conn) -{ - syslog(LOG_INFO, "live-update: abort\n"); - - if (!lu_status) - return "No live-update session active."; - - /* Destructor will do the real abort handling. */ - talloc_free(lu_status); - - return NULL; -} - -static const char *lu_cmdline(const void *ctx, struct connection *conn, - const char *cmdline) -{ - syslog(LOG_INFO, "live-update: cmdline %s\n", cmdline); - - if (!lu_status || lu_status->conn !=3D conn) - return "Not in live-update session."; - - lu_status->cmdline =3D talloc_strdup(lu_status, cmdline); - if (!lu_status->cmdline) - return "Allocation failure."; - - return NULL; -} - -static bool lu_check_lu_allowed(void) -{ - struct connection *conn; - time_t now =3D time(NULL); - unsigned int ta_total =3D 0, ta_long =3D 0; - - list_for_each_entry(conn, &connections, list) { - if (conn->ta_start_time) { - ta_total++; - if (now - conn->ta_start_time >=3D lu_status->timeout) - ta_long++; - } - } - - /* - * Allow LiveUpdate if one of the following conditions is met: - * - There is no active transactions - * - All transactions are long running (e.g. they have been - * active for more than lu_status->timeout sec) and the admin as - * requested to force the operation. - */ - return ta_total ? (lu_status->force && ta_long =3D=3D ta_total) : true; -} - -static const char *lu_reject_reason(const void *ctx) -{ - char *ret =3D NULL; - struct connection *conn; - time_t now =3D time(NULL); - - list_for_each_entry(conn, &connections, list) { - if (conn->ta_start_time && - (now - conn->ta_start_time >=3D lu_status->timeout)) { - ret =3D talloc_asprintf(ctx, "%s\nDomain %u: %ld s", - ret ? : "Domains with long running transactions:", - conn->id, - now - conn->ta_start_time); - } - } - - return ret ? (const char *)ret : "Overlapping transactions"; -} - -static const char *lu_dump_state(const void *ctx, struct connection *conn) -{ - FILE *fp; - const char *ret; - struct xs_state_record_header end; - struct xs_state_preamble pre; - - fp =3D lu_dump_open(ctx); - if (!fp) - return "Dump state open error"; - - memcpy(pre.ident, XS_STATE_IDENT, sizeof(pre.ident)); - pre.version =3D htobe32(XS_STATE_VERSION); - pre.flags =3D XS_STATE_FLAGS; - if (fwrite(&pre, sizeof(pre), 1, fp) !=3D 1) { - ret =3D "Dump write error"; - goto out; - } - - ret =3D dump_state_global(fp); - if (ret) - goto out; - ret =3D dump_state_connections(fp); - if (ret) - goto out; - ret =3D dump_state_nodes(fp, ctx); - if (ret) - goto out; - - end.type =3D XS_STATE_TYPE_END; - end.length =3D 0; - if (fwrite(&end, sizeof(end), 1, fp) !=3D 1) - ret =3D "Dump write error"; - - out: - lu_dump_close(fp); - - return ret; -} - -void lu_read_state(void) -{ - struct lu_dump_state state =3D {}; - struct xs_state_record_header *head; - void *ctx =3D talloc_new(NULL); /* Work context for subfunctions. */ - struct xs_state_preamble *pre; - - syslog(LOG_INFO, "live-update: read state\n"); - lu_get_dump_state(&state); - if (state.size =3D=3D 0) - barf_perror("No state found after live-update"); - - pre =3D state.buf; - if (memcmp(pre->ident, XS_STATE_IDENT, sizeof(pre->ident)) || - pre->version !=3D htobe32(XS_STATE_VERSION) || - pre->flags !=3D XS_STATE_FLAGS) - barf("Unknown record identifier"); - for (head =3D state.buf + sizeof(*pre); - head->type !=3D XS_STATE_TYPE_END && - (void *)head - state.buf < state.size; - head =3D (void *)head + sizeof(*head) + head->length) { - switch (head->type) { - case XS_STATE_TYPE_GLOBAL: - read_state_global(ctx, head + 1); - break; - case XS_STATE_TYPE_CONN: - read_state_connection(ctx, head + 1); - break; - case XS_STATE_TYPE_WATCH: - read_state_watch(ctx, head + 1); - break; - case XS_STATE_TYPE_TA: - xprintf("live-update: ignore transaction record\n"); - break; - case XS_STATE_TYPE_NODE: - read_state_node(ctx, head + 1); - break; - default: - xprintf("live-update: unknown state record %08x\n", - head->type); - break; - } - } - - lu_close_dump_state(&state); - - talloc_free(ctx); - - /* - * We may have missed the VIRQ_DOM_EXC notification and a domain may - * have died while we were live-updating. So check all the domains are - * still alive. - */ - check_domains(); -} - -static const char *lu_activate_binary(const void *ctx) -{ - int argc; - char **argv; - unsigned int i; - - if (lu_status->cmdline) { - argc =3D 4; /* At least one arg + progname + "-U" + NULL. */ - for (i =3D 0; lu_status->cmdline[i]; i++) - if (isspace(lu_status->cmdline[i])) - argc++; - argv =3D talloc_array(ctx, char *, argc); - if (!argv) - return "Allocation failure."; - - i =3D 0; - argc =3D 1; - argv[1] =3D strtok(lu_status->cmdline, " \t"); - while (argv[argc]) { - if (!strcmp(argv[argc], "-U")) - i =3D 1; - argc++; - argv[argc] =3D strtok(NULL, " \t"); - } - - if (!i) { - argv[argc++] =3D "-U"; - argv[argc] =3D NULL; - } - } else { - for (i =3D 0; i < orig_argc; i++) - if (!strcmp(orig_argv[i], "-U")) - break; - - argc =3D orig_argc; - argv =3D talloc_array(ctx, char *, orig_argc + 2); - if (!argv) - return "Allocation failure."; - - memcpy(argv, orig_argv, orig_argc * sizeof(*argv)); - if (i =3D=3D orig_argc) - argv[argc++] =3D "-U"; - argv[argc] =3D NULL; - } - - domain_deinit(); - - return lu_exec(ctx, argc, argv); -} - -static bool do_lu_start(struct delayed_request *req) -{ - time_t now =3D time(NULL); - const char *ret; - struct buffered_data *saved_in; - struct connection *conn =3D req->data; - - /* - * Cancellation may have been requested asynchronously. In this - * case, lu_status will be NULL. - */ - if (!lu_status) { - ret =3D "Cancellation was requested"; - goto out; - } - - assert(lu_status->conn =3D=3D conn); - - if (!lu_check_lu_allowed()) { - if (now < lu_status->started_at + lu_status->timeout) - return false; - if (!lu_status->force) { - ret =3D lu_reject_reason(req); - goto out; - } - } - - assert(req->in =3D=3D lu_status->in); - /* Dump out internal state, including "OK" for live update. */ - ret =3D lu_dump_state(req->in, conn); - if (!ret) { - /* Perform the activation of new binary. */ - ret =3D lu_activate_binary(req->in); - } - - /* We will reach this point only in case of failure. */ - out: - /* - * send_reply() will send the response for conn->in. Save the current - * conn->in and restore it afterwards. - */ - saved_in =3D conn->in; - conn->in =3D req->in; - send_reply(conn, XS_CONTROL, ret, strlen(ret) + 1); - conn->in =3D saved_in; - talloc_free(lu_status); - - return true; -} - -static const char *lu_start(const void *ctx, struct connection *conn, - bool force, unsigned int to) -{ - syslog(LOG_INFO, "live-update: start, force=3D%d, to=3D%u\n", force, to); - - if (!lu_status || lu_status->conn !=3D conn) - return "Not in live-update session."; - -#ifdef __MINIOS__ - if (lu_status->kernel_size !=3D lu_status->kernel_off) - return "Kernel not complete."; -#endif - - lu_status->force =3D force; - lu_status->timeout =3D to; - lu_status->started_at =3D time(NULL); - lu_status->in =3D conn->in; - - errno =3D delay_request(conn, conn->in, do_lu_start, conn, false); - - return NULL; -} - -static int do_control_lu(const void *ctx, struct connection *conn, - char **vec, int num) -{ - const char *ret =3D NULL; - unsigned int i; - bool force =3D false; - unsigned int to =3D 0; - - if (num < 1) - return EINVAL; - - if (!strcmp(vec[0], "-a")) { - if (num =3D=3D 1) - ret =3D lu_abort(ctx, conn); - else - return EINVAL; - } else if (!strcmp(vec[0], "-c")) { - if (num =3D=3D 2) - ret =3D lu_cmdline(ctx, conn, vec[1]); - else - return EINVAL; - } else if (!strcmp(vec[0], "-s")) { - for (i =3D 1; i < num; i++) { - if (!strcmp(vec[i], "-F")) - force =3D true; - else if (!strcmp(vec[i], "-t") && i < num - 1) { - i++; - to =3D atoi(vec[i]); - } else - return EINVAL; - } - ret =3D lu_start(ctx, conn, force, to); - if (!ret) - return errno; - } else { - ret =3D lu_arch(ctx, conn, vec, num); - if (!ret && errno) - return errno; - } - - if (!ret) - ret =3D "OK"; - send_reply(conn, XS_CONTROL, ret, strlen(ret) + 1); - return 0; -} -#endif - static int do_control_help(const void *, struct connection *, char **, int= ); =20 static struct cmd_s cmds[] =3D { diff --git a/tools/xenstore/xenstored_control.h b/tools/xenstore/xenstored_= control.h index a8cb76559b..faa955968d 100644 --- a/tools/xenstore/xenstored_control.h +++ b/tools/xenstore/xenstored_control.h @@ -18,11 +18,3 @@ =20 int do_control(const void *ctx, struct connection *conn, struct buffered_data *in); -void lu_read_state(void); - -struct connection *lu_get_connection(void); - -/* Write the "OK" response for the live-update command */ -unsigned int lu_write_response(FILE *fp); - -bool lu_is_pending(void); diff --git a/tools/xenstore/xenstored_core.c b/tools/xenstore/xenstored_cor= e.c index e16d0a6d53..3842e122ce 100644 --- a/tools/xenstore/xenstored_core.c +++ b/tools/xenstore/xenstored_core.c @@ -52,6 +52,7 @@ #include "xenstored_transaction.h" #include "xenstored_domain.h" #include "xenstored_control.h" +#include "xenstored_lu.h" #include "tdb.h" =20 #ifndef NO_SOCKETS diff --git a/tools/xenstore/xenstored_lu.c b/tools/xenstore/xenstored_lu.c new file mode 100644 index 0000000000..cfd6d5cee2 --- /dev/null +++ b/tools/xenstore/xenstored_lu.c @@ -0,0 +1,401 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +/* + * Live Update interfaces for Xen Store Daemon. + * Copyright (C) 2022 Juergen Gross, SUSE LLC + */ + +#include +#include +#include +#include +#include +#include + +#include "talloc.h" +#include "xs_lib.h" +#include "xenstored_core.h" +#include "xenstored_domain.h" +#include "xenstored_lu.h" +#include "xenstored_watch.h" + +#ifndef NO_LIVE_UPDATE +struct live_update *lu_status; + +const char *lu_begin(struct connection *conn) +{ + if (lu_status) + return "live-update session already active."; + + lu_status =3D talloc_zero(conn, struct live_update); + if (!lu_status) + return "Allocation failure."; + lu_status->conn =3D conn; + talloc_set_destructor(lu_status, lu_destroy); + + return NULL; +} + +struct connection *lu_get_connection(void) +{ + return lu_status ? lu_status->conn : NULL; +} + +unsigned int lu_write_response(FILE *fp) +{ + struct xsd_sockmsg msg; + + assert(lu_status); + + msg =3D lu_status->in->hdr.msg; + + msg.len =3D sizeof("OK"); + if (fp && fwrite(&msg, sizeof(msg), 1, fp) !=3D 1) + return 0; + if (fp && fwrite("OK", msg.len, 1, fp) !=3D 1) + return 0; + + return sizeof(msg) + msg.len; +} + +bool lu_is_pending(void) +{ + return lu_status !=3D NULL; +} + +void lu_read_state(void) +{ + struct lu_dump_state state =3D {}; + struct xs_state_record_header *head; + void *ctx =3D talloc_new(NULL); /* Work context for subfunctions. */ + struct xs_state_preamble *pre; + + syslog(LOG_INFO, "live-update: read state\n"); + lu_get_dump_state(&state); + if (state.size =3D=3D 0) + barf_perror("No state found after live-update"); + + pre =3D state.buf; + if (memcmp(pre->ident, XS_STATE_IDENT, sizeof(pre->ident)) || + pre->version !=3D htobe32(XS_STATE_VERSION) || + pre->flags !=3D XS_STATE_FLAGS) + barf("Unknown record identifier"); + for (head =3D state.buf + sizeof(*pre); + head->type !=3D XS_STATE_TYPE_END && + (void *)head - state.buf < state.size; + head =3D (void *)head + sizeof(*head) + head->length) { + switch (head->type) { + case XS_STATE_TYPE_GLOBAL: + read_state_global(ctx, head + 1); + break; + case XS_STATE_TYPE_CONN: + read_state_connection(ctx, head + 1); + break; + case XS_STATE_TYPE_WATCH: + read_state_watch(ctx, head + 1); + break; + case XS_STATE_TYPE_TA: + xprintf("live-update: ignore transaction record\n"); + break; + case XS_STATE_TYPE_NODE: + read_state_node(ctx, head + 1); + break; + default: + xprintf("live-update: unknown state record %08x\n", + head->type); + break; + } + } + + lu_close_dump_state(&state); + + talloc_free(ctx); + + /* + * We may have missed the VIRQ_DOM_EXC notification and a domain may + * have died while we were live-updating. So check all the domains are + * still alive. + */ + check_domains(); +} + +static const char *lu_abort(const void *ctx, struct connection *conn) +{ + syslog(LOG_INFO, "live-update: abort\n"); + + if (!lu_status) + return "No live-update session active."; + + /* Destructor will do the real abort handling. */ + talloc_free(lu_status); + + return NULL; +} + +static const char *lu_cmdline(const void *ctx, struct connection *conn, + const char *cmdline) +{ + syslog(LOG_INFO, "live-update: cmdline %s\n", cmdline); + + if (!lu_status || lu_status->conn !=3D conn) + return "Not in live-update session."; + + lu_status->cmdline =3D talloc_strdup(lu_status, cmdline); + if (!lu_status->cmdline) + return "Allocation failure."; + + return NULL; +} + +static bool lu_check_lu_allowed(void) +{ + struct connection *conn; + time_t now =3D time(NULL); + unsigned int ta_total =3D 0, ta_long =3D 0; + + list_for_each_entry(conn, &connections, list) { + if (conn->ta_start_time) { + ta_total++; + if (now - conn->ta_start_time >=3D lu_status->timeout) + ta_long++; + } + } + + /* + * Allow LiveUpdate if one of the following conditions is met: + * - There is no active transactions + * - All transactions are long running (e.g. they have been + * active for more than lu_status->timeout sec) and the admin as + * requested to force the operation. + */ + return ta_total ? (lu_status->force && ta_long =3D=3D ta_total) : true; +} + +static const char *lu_reject_reason(const void *ctx) +{ + char *ret =3D NULL; + struct connection *conn; + time_t now =3D time(NULL); + + list_for_each_entry(conn, &connections, list) { + if (conn->ta_start_time && + (now - conn->ta_start_time >=3D lu_status->timeout)) { + ret =3D talloc_asprintf(ctx, "%s\nDomain %u: %ld s", + ret ? : "Domains with long running transactions:", + conn->id, + now - conn->ta_start_time); + } + } + + return ret ? (const char *)ret : "Overlapping transactions"; +} + +static const char *lu_dump_state(const void *ctx, struct connection *conn) +{ + FILE *fp; + const char *ret; + struct xs_state_record_header end; + struct xs_state_preamble pre; + + fp =3D lu_dump_open(ctx); + if (!fp) + return "Dump state open error"; + + memcpy(pre.ident, XS_STATE_IDENT, sizeof(pre.ident)); + pre.version =3D htobe32(XS_STATE_VERSION); + pre.flags =3D XS_STATE_FLAGS; + if (fwrite(&pre, sizeof(pre), 1, fp) !=3D 1) { + ret =3D "Dump write error"; + goto out; + } + + ret =3D dump_state_global(fp); + if (ret) + goto out; + ret =3D dump_state_connections(fp); + if (ret) + goto out; + ret =3D dump_state_nodes(fp, ctx); + if (ret) + goto out; + + end.type =3D XS_STATE_TYPE_END; + end.length =3D 0; + if (fwrite(&end, sizeof(end), 1, fp) !=3D 1) + ret =3D "Dump write error"; + + out: + lu_dump_close(fp); + + return ret; +} + +static const char *lu_activate_binary(const void *ctx) +{ + int argc; + char **argv; + unsigned int i; + + if (lu_status->cmdline) { + argc =3D 4; /* At least one arg + progname + "-U" + NULL. */ + for (i =3D 0; lu_status->cmdline[i]; i++) + if (isspace(lu_status->cmdline[i])) + argc++; + argv =3D talloc_array(ctx, char *, argc); + if (!argv) + return "Allocation failure."; + + i =3D 0; + argc =3D 1; + argv[1] =3D strtok(lu_status->cmdline, " \t"); + while (argv[argc]) { + if (!strcmp(argv[argc], "-U")) + i =3D 1; + argc++; + argv[argc] =3D strtok(NULL, " \t"); + } + + if (!i) { + argv[argc++] =3D "-U"; + argv[argc] =3D NULL; + } + } else { + for (i =3D 0; i < orig_argc; i++) + if (!strcmp(orig_argv[i], "-U")) + break; + + argc =3D orig_argc; + argv =3D talloc_array(ctx, char *, orig_argc + 2); + if (!argv) + return "Allocation failure."; + + memcpy(argv, orig_argv, orig_argc * sizeof(*argv)); + if (i =3D=3D orig_argc) + argv[argc++] =3D "-U"; + argv[argc] =3D NULL; + } + + domain_deinit(); + + return lu_exec(ctx, argc, argv); +} + +static bool do_lu_start(struct delayed_request *req) +{ + time_t now =3D time(NULL); + const char *ret; + struct buffered_data *saved_in; + struct connection *conn =3D req->data; + + /* + * Cancellation may have been requested asynchronously. In this + * case, lu_status will be NULL. + */ + if (!lu_status) { + ret =3D "Cancellation was requested"; + goto out; + } + + assert(lu_status->conn =3D=3D conn); + + if (!lu_check_lu_allowed()) { + if (now < lu_status->started_at + lu_status->timeout) + return false; + if (!lu_status->force) { + ret =3D lu_reject_reason(req); + goto out; + } + } + + assert(req->in =3D=3D lu_status->in); + /* Dump out internal state, including "OK" for live update. */ + ret =3D lu_dump_state(req->in, conn); + if (!ret) { + /* Perform the activation of new binary. */ + ret =3D lu_activate_binary(req->in); + } + + /* We will reach this point only in case of failure. */ + out: + /* + * send_reply() will send the response for conn->in. Save the current + * conn->in and restore it afterwards. + */ + saved_in =3D conn->in; + conn->in =3D req->in; + send_reply(conn, XS_CONTROL, ret, strlen(ret) + 1); + conn->in =3D saved_in; + talloc_free(lu_status); + + return true; +} + +static const char *lu_start(const void *ctx, struct connection *conn, + bool force, unsigned int to) +{ + syslog(LOG_INFO, "live-update: start, force=3D%d, to=3D%u\n", force, to); + + if (!lu_status || lu_status->conn !=3D conn) + return "Not in live-update session."; + +#ifdef __MINIOS__ + if (lu_status->kernel_size !=3D lu_status->kernel_off) + return "Kernel not complete."; +#endif + + lu_status->force =3D force; + lu_status->timeout =3D to; + lu_status->started_at =3D time(NULL); + lu_status->in =3D conn->in; + + errno =3D delay_request(conn, conn->in, do_lu_start, conn, false); + + return NULL; +} + +int do_control_lu(const void *ctx, struct connection *conn, char **vec, + int num) +{ + const char *ret =3D NULL; + unsigned int i; + bool force =3D false; + unsigned int to =3D 0; + + if (num < 1) + return EINVAL; + + if (!strcmp(vec[0], "-a")) { + if (num =3D=3D 1) + ret =3D lu_abort(ctx, conn); + else + return EINVAL; + } else if (!strcmp(vec[0], "-c")) { + if (num =3D=3D 2) + ret =3D lu_cmdline(ctx, conn, vec[1]); + else + return EINVAL; + } else if (!strcmp(vec[0], "-s")) { + for (i =3D 1; i < num; i++) { + if (!strcmp(vec[i], "-F")) + force =3D true; + else if (!strcmp(vec[i], "-t") && i < num - 1) { + i++; + to =3D atoi(vec[i]); + } else + return EINVAL; + } + ret =3D lu_start(ctx, conn, force, to); + if (!ret) + return errno; + } else { + ret =3D lu_arch(ctx, conn, vec, num); + if (!ret && errno) + return errno; + } + + if (!ret) + ret =3D "OK"; + send_reply(conn, XS_CONTROL, ret, strlen(ret) + 1); + return 0; +} +#endif diff --git a/tools/xenstore/xenstored_lu.h b/tools/xenstore/xenstored_lu.h index d2f8e4e57c..7aa524a07e 100644 --- a/tools/xenstore/xenstored_lu.h +++ b/tools/xenstore/xenstored_lu.h @@ -43,6 +43,16 @@ struct lu_dump_state { =20 extern struct live_update *lu_status; =20 +struct connection *lu_get_connection(void); +bool lu_is_pending(void); +void lu_read_state(void); + +/* Write the "OK" response for the live-update command */ +unsigned int lu_write_response(FILE *fp); + +int do_control_lu(const void *ctx, struct connection *conn, char **vec, + int num); + /* Live update private interfaces. */ void lu_get_dump_state(struct lu_dump_state *state); void lu_close_dump_state(struct lu_dump_state *state); @@ -53,4 +63,19 @@ const char *lu_arch(const void *ctx, struct connection *= conn, char **vec, int num); const char *lu_begin(struct connection *conn); int lu_destroy(void *data); +#else +static inline struct connection *lu_get_connection(void) +{ + return NULL; +} + +static inline unsigned int lu_write_response(FILE *fp) +{ + return 0; +} + +static inline bool lu_is_pending(void) +{ + return false; +} #endif --=20 2.35.3 From nobody Thu May 16 23:47:25 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=1680166769; cv=none; d=zohomail.com; s=zohoarc; b=RuSWbEzyV4Cx7fi57nvvSdu8k6TH3evOEh/MXnL2WfWHEaDF7Eb3lSUJn9t1rBu5t3gJtecHKbx99GZOkLllaY7w5OCJFaoMsDf7OlhJFPjPjyOez/gpOHMJMb5FAryxEN5EPpgFxz0SpD3mVt5IxsrOFT2iWesSH5e0B+C0244= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1680166769; 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=fx98eisytmRk+NNDmkl4p0Eqn//P5VGBs6rsYeEk9Xk=; b=JyBmgZeqRr9h0//L0btsClugN2jKVMt7msHuzGNyuoRakXlaXkXvSKf0xPAd5O4vYfvjnRNa9uvaKJpC5Jhehv1G+q4ey4Y/+eXxix5/SAQ/bYqhZ+suEJ1Calyr/YZdbe8vczFnAwv1ajtfPyTiAmnZLzambDa3h+jVlbG/Swg= 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 1680166769154992.7852405968109; Thu, 30 Mar 2023 01:59:29 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.516540.800823 (Exim 4.92) (envelope-from ) id 1pho7i-0004Qx-DA; Thu, 30 Mar 2023 08:59:10 +0000 Received: by outflank-mailman (output) from mailman id 516540.800823; Thu, 30 Mar 2023 08:59:10 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pho7i-0004Qo-A9; Thu, 30 Mar 2023 08:59:10 +0000 Received: by outflank-mailman (input) for mailman id 516540; Thu, 30 Mar 2023 08:59:09 +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 1pho0H-0005Qp-PP for xen-devel@lists.xenproject.org; Thu, 30 Mar 2023 08:51:29 +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 0eeb8b88-ced8-11ed-b464-930f4c7d94ae; Thu, 30 Mar 2023 10:51:27 +0200 (CEST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 949FE21B1B; Thu, 30 Mar 2023 08:51: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 623DE138FF; Thu, 30 Mar 2023 08:51:27 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id ow+nFo9NJWSMIwAAMHmgww (envelope-from ); Thu, 30 Mar 2023 08:51: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: 0eeb8b88-ced8-11ed-b464-930f4c7d94ae DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1680166287; 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=fx98eisytmRk+NNDmkl4p0Eqn//P5VGBs6rsYeEk9Xk=; b=ssDB9Qs3USwxA5Beb+gvk1chdy8+gctEL9x4W3AnsW04+KkBm5oLUpaQ6w49zbVznXVoGj ocH2bCmoIge09zeuobVwMfJfUSwv5HY70Uo5wGCo7lqeq0GAGGWYtkEaxN+PALPZezMaNZ pQZDlhvtS7X3Sq7Uyg6q+6Gia4EXYpY= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Julien Grall , Anthony PERARD Subject: [PATCH v2 13/13] tools/xenstore: remove unused stuff from list.h Date: Thu, 30 Mar 2023 10:50:11 +0200 Message-Id: <20230330085011.9170-14-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230330085011.9170-1-jgross@suse.com> References: <20230330085011.9170-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1680166770226100005 Content-Type: text/plain; charset="utf-8" Remove the hlist devines/functions and the rcu related functions from tools/xenstore/list.h, as they are not used. Signed-off-by: Juergen Gross --- tools/xenstore/list.h | 227 ------------------------------------------ 1 file changed, 227 deletions(-) diff --git a/tools/xenstore/list.h b/tools/xenstore/list.h index a464a38b61..d722a91220 100644 --- a/tools/xenstore/list.h +++ b/tools/xenstore/list.h @@ -88,48 +88,6 @@ static inline void list_add_tail(struct list_head *new, = struct list_head *head) __list_add(new, head->prev, head); } =20 -/* - * Insert a new entry between two known consecutive entries.=20 - * - * This is only for internal list manipulation where we know - * the prev/next entries already! - */ -static __inline__ void __list_add_rcu(struct list_head * new, - struct list_head * prev, - struct list_head * next) -{ - new->next =3D next; - new->prev =3D prev; - next->prev =3D new; - prev->next =3D new; -} - -/** - * list_add_rcu - add a new entry to rcu-protected list - * @new: new entry to be added - * @head: list head to add it after - * - * Insert a new entry after the specified head. - * This is good for implementing stacks. - */ -static __inline__ void list_add_rcu(struct list_head *new, struct list_hea= d *head) -{ - __list_add_rcu(new, head, head->next); -} - -/** - * list_add_tail_rcu - add a new entry to rcu-protected list - * @new: new entry to be added - * @head: list head to add it before - * - * Insert a new entry before the specified head. - * This is useful for implementing queues. - */ -static __inline__ void list_add_tail_rcu(struct list_head *new, struct lis= t_head *head) -{ - __list_add_rcu(new, head->prev, head); -} - /* * Delete a list entry by making the prev/next entries * point to each other. @@ -156,23 +114,6 @@ static inline void list_del(struct list_head *entry) entry->prev =3D LIST_POISON2; } =20 -/** - * list_del_rcu - deletes entry from list without re-initialization - * @entry: the element to delete from the list. - * - * Note: list_empty on entry does not return true after this,=20 - * the entry is in an undefined state. It is useful for RCU based - * lockfree traversal. - * - * In particular, it means that we can not poison the forward=20 - * pointers that may still be used for walking the list. - */ -static inline void list_del_rcu(struct list_head *entry) -{ - __list_del(entry->prev, entry->next); - entry->prev =3D LIST_POISON2; -} - /** * list_del_init - deletes entry from list and reinitialize it. * @entry: the element to delete from the list. @@ -339,172 +280,4 @@ static inline void list_splice_init(struct list_head = *list, &pos->member !=3D (head); \ pos =3D n, n =3D list_entry(n->member.next, typeof(*n), member)) =20 - -/*=20 - * Double linked lists with a single pointer list head.=20 - * Mostly useful for hash tables where the two pointer list head is=20 - * too wasteful. - * You lose the ability to access the tail in O(1). - */=20 - -struct hlist_head {=20 - struct hlist_node *first;=20 -};=20 - -struct hlist_node {=20 - struct hlist_node *next, **pprev;=20 -};=20 - -#define HLIST_HEAD_INIT { .first =3D NULL }=20 -#define HLIST_HEAD(name) struct hlist_head name =3D { .first =3D NULL } -#define INIT_HLIST_HEAD(ptr) ((ptr)->first =3D NULL)=20 -#define INIT_HLIST_NODE(ptr) ((ptr)->next =3D NULL, (ptr)->pprev =3D NULL) - -static __inline__ int hlist_unhashed(struct hlist_node *h)=20 -{=20 - return !h->pprev; -}=20 - -static __inline__ int hlist_empty(struct hlist_head *h)=20 -{=20 - return !h->first; -}=20 - -static __inline__ void __hlist_del(struct hlist_node *n)=20 -{ - struct hlist_node *next =3D n->next; - struct hlist_node **pprev =3D n->pprev; - *pprev =3D next; =20 - if (next)=20 - next->pprev =3D pprev; -} =20 - -static __inline__ void hlist_del(struct hlist_node *n) -{ - __hlist_del(n); - n->next =3D LIST_POISON1; - n->pprev =3D LIST_POISON2; -} - -/** - * hlist_del_rcu - deletes entry from hash list without re-initialization - * @entry: the element to delete from the hash list. - * - * Note: list_unhashed() on entry does not return true after this,=20 - * the entry is in an undefined state. It is useful for RCU based - * lockfree traversal. - * - * In particular, it means that we can not poison the forward - * pointers that may still be used for walking the hash list. - */ -static inline void hlist_del_rcu(struct hlist_node *n) -{ - __hlist_del(n); - n->pprev =3D LIST_POISON2; -} - -static __inline__ void hlist_del_init(struct hlist_node *n)=20 -{ - if (n->pprev) { - __hlist_del(n); - INIT_HLIST_NODE(n); - } -} =20 - -#define hlist_del_rcu_init hlist_del_init - -static __inline__ void hlist_add_head(struct hlist_node *n, struct hlist_h= ead *h)=20 -{=20 - struct hlist_node *first =3D h->first; - n->next =3D first;=20 - if (first)=20 - first->pprev =3D &n->next; - h->first =3D n;=20 - n->pprev =3D &h->first;=20 -}=20 - -static __inline__ void hlist_add_head_rcu(struct hlist_node *n, struct hli= st_head *h)=20 -{=20 - struct hlist_node *first =3D h->first; - n->next =3D first; - n->pprev =3D &h->first;=20 - if (first)=20 - first->pprev =3D &n->next; - h->first =3D n;=20 -}=20 - -/* next must be !=3D NULL */ -static __inline__ void hlist_add_before(struct hlist_node *n, struct hlist= _node *next) -{ - n->pprev =3D next->pprev; - n->next =3D next;=20 - next->pprev =3D &n->next;=20 - *(n->pprev) =3D n; -} - -static __inline__ void hlist_add_after(struct hlist_node *n, - struct hlist_node *next) -{ - next->next =3D n->next; - *(next->pprev) =3D n; - n->next =3D next; -} - -#define hlist_entry(ptr, type, member) container_of(ptr,type,member) - -/* Cannot easily do prefetch unfortunately */ -#define hlist_for_each(pos, head) \ - for (pos =3D (head)->first; pos; pos =3D pos->next)=20 - -#define hlist_for_each_safe(pos, n, head) \ - for (pos =3D (head)->first; n =3D pos ? pos->next : 0, pos; \ - pos =3D n) - -/** - * hlist_for_each_entry - iterate over list of given type - * @tpos: the type * to use as a loop counter. - * @pos: the &struct hlist_node to use as a loop counter. - * @head: the head for your list. - * @member: the name of the hlist_node within the struct. - */ -#define hlist_for_each_entry(tpos, pos, head, member) \ - for (pos =3D (head)->first; \ - pos && ({ tpos =3D hlist_entry(pos, typeof(*tpos), member); 1;}); \ - pos =3D pos->next) - -/** - * hlist_for_each_entry_continue - iterate over a hlist continuing after e= xisting point - * @tpos: the type * to use as a loop counter. - * @pos: the &struct hlist_node to use as a loop counter. - * @member: the name of the hlist_node within the struct. - */ -#define hlist_for_each_entry_continue(tpos, pos, member) \ - for (pos =3D (pos)->next; \ - pos && ({ tpos =3D hlist_entry(pos, typeof(*tpos), member); 1;}); \ - pos =3D pos->next) - -/** - * hlist_for_each_entry_from - iterate over a hlist continuing from existi= ng point - * @tpos: the type * to use as a loop counter. - * @pos: the &struct hlist_node to use as a loop counter. - * @member: the name of the hlist_node within the struct. - */ -#define hlist_for_each_entry_from(tpos, pos, member) \ - for (; pos && ({ tpos =3D hlist_entry(pos, typeof(*tpos), member); 1;}); \ - pos =3D pos->next) - -/** - * hlist_for_each_entry_safe - iterate over list of given type safe agains= t removal of list entry - * @tpos: the type * to use as a loop counter. - * @pos: the &struct hlist_node to use as a loop counter. - * @n: another &struct hlist_node to use as temporary storage - * @head: the head for your list. - * @member: the name of the hlist_node within the struct. - */ -#define hlist_for_each_entry_safe(tpos, pos, n, head, member) \ - for (pos =3D (head)->first; \ - pos && ({ n =3D pos->next; 1; }) && \ - ({ tpos =3D hlist_entry(pos, typeof(*tpos), member); 1;}); \ - pos =3D n) - #endif --=20 2.35.3