From nobody Mon Feb 9 16:01:52 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1692000169; cv=none; d=zohomail.com; s=zohoarc; b=eEDLv+McWs0wWVRUoQZJfRT3FMooGYuDD93Gs0HNruxNLFDfUJiSRv/AJi5SwXkLnZHwTH9ZoXXSrKBcHDQ21A7fqCo9qkDSBMujVYhB5BzUOTJI1IAxqVeCNU7myIyEezyehJonNb9pUXCBCT9cnRgQvhqz8UhkSQtckEU0FRM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1692000169; 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=TKsSCupJgCOy14CkP0dNJUmpxlUXvXGKgcCx2Ay0CRA=; b=kx7kUjcYplDYTXlu2XTvfxoGZL7LfWALXug7rdfp6L0qur9nBsdwMWtdsmhELk0KPmwgezDdnZsUkeIjimVdqe8fJqAMiBXB3RzaTikB91lWI9HxjeUL5zlHC4vcpMi+eTsW5K1sa8OJcA6rCV9JGdt1Iy07ZSH6ZmLtWjMzyZ4= 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 1692000169543524.0569148083321; Mon, 14 Aug 2023 01:02:49 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.583427.913658 (Exim 4.92) (envelope-from ) id 1qVSWz-0006jK-Rp; Mon, 14 Aug 2023 08:02:29 +0000 Received: by outflank-mailman (output) from mailman id 583427.913658; Mon, 14 Aug 2023 08:02:29 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qVSWz-0006fq-Kl; Mon, 14 Aug 2023 08:02:29 +0000 Received: by outflank-mailman (input) for mailman id 583427; Mon, 14 Aug 2023 08:02:28 +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 1qVSJi-0002SK-GQ for xen-devel@lists.xenproject.org; Mon, 14 Aug 2023 07:48:46 +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 ff2a92bc-3a76-11ee-b288-6b7b168915f2; Mon, 14 Aug 2023 09:48:45 +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 8D85C21984; Mon, 14 Aug 2023 07:48:45 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 616BE138EE; Mon, 14 Aug 2023 07:48:45 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id TH6NFl3c2WRRQgAAMHmgww (envelope-from ); Mon, 14 Aug 2023 07:48:45 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: ff2a92bc-3a76-11ee-b288-6b7b168915f2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1691999325; 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=TKsSCupJgCOy14CkP0dNJUmpxlUXvXGKgcCx2Ay0CRA=; b=oR81TxzpJQCiV64A1w0J54wH4uOELCDJMrJl8x3+xsqvN8oMwrqrKeP00IbGPTAH+M6Pnc j5a7f1qpIbENbuULGu5hiYljUNjP5/wALJpe051M8hwEukBAGP1e5+aUGiiMVWf1S+dl3q W8Hyl967DMV25sk+7egIae1TRYg7E9E= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Julien Grall , Anthony PERARD Subject: [PATCH v4 17/19] tools/xenstore: introduce get_node_const() Date: Mon, 14 Aug 2023 09:47:05 +0200 Message-Id: <20230814074707.27696-18-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230814074707.27696-1-jgross@suse.com> References: <20230814074707.27696-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1692000170664100001 Content-Type: text/plain; charset="utf-8" Add a variant of get_node() returning a const struct node pointer. Note that all callers of this new variant don't supply a pointer where to store the canonical node name, while all callers needing a non-const node do supply this pointer. This results in an asymmetric simplification of the two variants. Signed-off-by: Juergen Gross Reviewed-by: Julien Grall --- V3: - new approach (Julien Grall) --- tools/xenstore/xenstored_core.c | 35 ++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/tools/xenstore/xenstored_core.c b/tools/xenstore/xenstored_cor= e.c index 9098b7eee2..7de4df2f28 100644 --- a/tools/xenstore/xenstored_core.c +++ b/tools/xenstore/xenstored_core.c @@ -1301,11 +1301,8 @@ static struct node *get_node(struct connection *conn= , const void *ctx, const char *name, const char **canonical_name, unsigned int perm, bool allow_special) { - const char *tmp_name; struct node *node; =20 - if (!canonical_name) - canonical_name =3D &tmp_name; *canonical_name =3D canonicalize(conn, ctx, name, allow_special); if (!*canonical_name) return NULL; @@ -1316,12 +1313,28 @@ static struct node *get_node(struct connection *con= n, const void *ctx, ? node : NULL; } =20 +static const struct node *get_node_const(struct connection *conn, + const void *ctx, const char *name, + unsigned int perm, bool allow_special) +{ + const char *tmp_name; + const struct node *node; + + tmp_name =3D canonicalize(conn, ctx, name, allow_special); + if (!tmp_name) + return NULL; + + node =3D read_node_const(conn, ctx, tmp_name); + + return get_node_chk_perm(conn, ctx, node, tmp_name, perm) ? node : NULL; +} + static int send_directory(const void *ctx, struct connection *conn, struct buffered_data *in) { - struct node *node; + const struct node *node; =20 - node =3D get_node(conn, ctx, onearg(in), NULL, XS_PERM_READ, false); + node =3D get_node_const(conn, ctx, onearg(in), XS_PERM_READ, false); if (!node) return errno; =20 @@ -1335,14 +1348,14 @@ static int send_directory_part(const void *ctx, str= uct connection *conn, { unsigned int off, len, maxlen, genlen; char *child, *data; - struct node *node; + const struct node *node; char gen[24]; =20 if (xenstore_count_strings(in->buffer, in->used) !=3D 2) return EINVAL; =20 /* First arg is node name. */ - node =3D get_node(conn, ctx, in->buffer, NULL, XS_PERM_READ, false); + node =3D get_node_const(conn, ctx, in->buffer, XS_PERM_READ, false); if (!node) return errno; =20 @@ -1389,9 +1402,9 @@ static int send_directory_part(const void *ctx, struc= t connection *conn, static int do_read(const void *ctx, struct connection *conn, struct buffered_data *in) { - struct node *node; + const struct node *node; =20 - node =3D get_node(conn, ctx, onearg(in), NULL, XS_PERM_READ, false); + node =3D get_node_const(conn, ctx, onearg(in), XS_PERM_READ, false); if (!node) return errno; =20 @@ -1799,11 +1812,11 @@ static int do_rm(const void *ctx, struct connection= *conn, static int do_get_perms(const void *ctx, struct connection *conn, struct buffered_data *in) { - struct node *node; + const struct node *node; char *strings; unsigned int len; =20 - node =3D get_node(conn, ctx, onearg(in), NULL, XS_PERM_READ, true); + node =3D get_node_const(conn, ctx, onearg(in), XS_PERM_READ, true); if (!node) return errno; =20 --=20 2.35.3