From nobody Tue Feb 10 02:49:44 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=1688972448; cv=none; d=zohomail.com; s=zohoarc; b=GHq4RtvmGHP3WPASPu6YKu/8QX5GTYqEnDKfrUfaS11/dZaDOYvfgKuJLS+MDhHI8E0T9ivg4S44GSoepGoRFmXsS1/7+UYDLZ5IpLakk7yiKnNf7FtcNSKDF+41bahfJEEkjPL0f3y1QgufD/E1ocVB6T1Hd5/P44QXLoqUvoE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1688972448; 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=oOCZz1yrYGWpW3fZFR3xBPsNc3NZAwTDmSc4zNEaUAQ=; b=SvMNDszVuttu32hAI24/FWutRU0WDUuutOfpTIsPIqc3Q8yFwiWYT7LRPHUuQEzDmvyV+5uxrOb8ezq9q2NpLAI3wkTqyc2h846KdO2WyDvimjd6stANeT4mGOSbQ49sbFs61aqP/UekB4qWoUmi5NsERraTAybEwD4Vg2mgP5I= 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 1688972448488301.01884692169654; Mon, 10 Jul 2023 00:00:48 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.560953.877161 (Exim 4.92) (envelope-from ) id 1qIksg-0005Xp-Ow; Mon, 10 Jul 2023 07:00:22 +0000 Received: by outflank-mailman (output) from mailman id 560953.877161; Mon, 10 Jul 2023 07:00: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 1qIksg-0005XU-LE; Mon, 10 Jul 2023 07:00:22 +0000 Received: by outflank-mailman (input) for mailman id 560953; Mon, 10 Jul 2023 07:00:20 +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 1qIkse-0002bQ-SY for xen-devel@lists.xenproject.org; Mon, 10 Jul 2023 07:00:20 +0000 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 6e2136f2-1eef-11ee-8611-37d641c3527e; Mon, 10 Jul 2023 09:00: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 C53431F88C; Mon, 10 Jul 2023 07:00:18 +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 950D01361C; Mon, 10 Jul 2023 07:00:18 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id JnAbI4Ksq2TMYgAAMHmgww (envelope-from ); Mon, 10 Jul 2023 07:00:18 +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: 6e2136f2-1eef-11ee-8611-37d641c3527e DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1688972418; 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=oOCZz1yrYGWpW3fZFR3xBPsNc3NZAwTDmSc4zNEaUAQ=; b=e51PHjHle8yZ5gWMJUyng+zpG3SfaeLnvBX+EJ48AxLwpeO7NkHrM8sxoehieikpmLmI9d VgbdOrO8eKgrrzcPjEqtHmk2HE6fXI+dPj5QivZ/+Ycf5muS5obG7tuiwknZ5I6QUZw4BB i+ORwBahg+5D/YgYvSb6TUjM54ri20A= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Julien Grall , Anthony PERARD Subject: [PATCH v2 05/18] tools/xenstore: rename do_tdb_write() and change parameter type Date: Mon, 10 Jul 2023 08:59:34 +0200 Message-Id: <20230710065947.4201-6-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230710065947.4201-1-jgross@suse.com> References: <20230710065947.4201-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1688972448968100001 Content-Type: text/plain; charset="utf-8" Rename do_tdb_write() to db_write() and replace the key parameter with db_name specifying the name of the node in the data base, and the data parameter with a data pointer and a length. Do the same key parameter type change for write_node_raw(), too. This is in preparation to replace TDB with a more simple data storage. Signed-off-by: Juergen Gross Reviewed-by: Julien Grall --- V2: - keep ta_key in finalize_transaction() (Julien Grall) --- tools/xenstore/xenstored_core.c | 70 +++++++++++++------------- tools/xenstore/xenstored_core.h | 11 ++-- tools/xenstore/xenstored_domain.c | 4 +- tools/xenstore/xenstored_transaction.c | 10 ++-- 4 files changed, 46 insertions(+), 49 deletions(-) diff --git a/tools/xenstore/xenstored_core.c b/tools/xenstore/xenstored_cor= e.c index 5e83c412ad..9bcff43e21 100644 --- a/tools/xenstore/xenstored_core.c +++ b/tools/xenstore/xenstored_core.c @@ -600,23 +600,27 @@ static unsigned int get_acc_domid(struct connection *= conn, TDB_DATA *key, ? domid : conn->id; } =20 -int do_tdb_write(struct connection *conn, TDB_DATA *key, TDB_DATA *data, - struct node_account_data *acc, enum write_node_mode mode, - bool no_quota_check) +int db_write(struct connection *conn, const char *db_name, void *data, + size_t size, struct node_account_data *acc, + enum write_node_mode mode, bool no_quota_check) { - struct xs_tdb_record_hdr *hdr =3D (void *)data->dptr; + struct xs_tdb_record_hdr *hdr =3D data; struct node_account_data old_acc =3D {}; unsigned int old_domid, new_domid; int ret; + TDB_DATA key, dat; =20 + set_tdb_key(db_name, &key); + dat.dptr =3D data; + dat.dsize =3D size; if (!acc) old_acc.memory =3D -1; else old_acc =3D *acc; =20 - get_acc_data(key, &old_acc); - old_domid =3D get_acc_domid(conn, key, old_acc.domid); - new_domid =3D get_acc_domid(conn, key, hdr->perms[0].id); + get_acc_data(&key, &old_acc); + old_domid =3D get_acc_domid(conn, &key, old_acc.domid); + new_domid =3D get_acc_domid(conn, &key, hdr->perms[0].id); =20 /* * Don't check for ENOENT, as we want to be able to switch orphaned @@ -624,35 +628,34 @@ int do_tdb_write(struct connection *conn, TDB_DATA *k= ey, TDB_DATA *data, */ if (old_acc.memory) domain_memory_add_nochk(conn, old_domid, - -old_acc.memory - key->dsize); - ret =3D domain_memory_add(conn, new_domid, - data->dsize + key->dsize, no_quota_check); + -old_acc.memory - key.dsize); + ret =3D domain_memory_add(conn, new_domid, size + key.dsize, + no_quota_check); if (ret) { /* Error path, so no quota check. */ if (old_acc.memory) domain_memory_add_nochk(conn, old_domid, - old_acc.memory + key->dsize); + old_acc.memory + key.dsize); return ret; } =20 /* TDB should set errno, but doesn't even set ecode AFAICT. */ - if (tdb_store(tdb_ctx, *key, *data, + if (tdb_store(tdb_ctx, key, dat, (mode =3D=3D NODE_CREATE) ? TDB_INSERT : TDB_MODIFY) !=3D 0) { - domain_memory_add_nochk(conn, new_domid, - -data->dsize - key->dsize); + domain_memory_add_nochk(conn, new_domid, -size - key.dsize); /* Error path, so no quota check. */ if (old_acc.memory) domain_memory_add_nochk(conn, old_domid, - old_acc.memory + key->dsize); + old_acc.memory + key.dsize); errno =3D EIO; return errno; } - trace_tdb("store %s size %zu\n", key->dptr, data->dsize + key->dsize); + trace_tdb("store %s size %zu\n", db_name, size + key.dsize); =20 if (acc) { /* Don't use new_domid, as it might be a transaction node. */ acc->domid =3D hdr->perms[0].id; - acc->memory =3D data->dsize; + acc->memory =3D size; } =20 return 0; @@ -780,33 +783,35 @@ static bool read_node_can_propagate_errno(void) return errno =3D=3D ENOMEM || errno =3D=3D ENOSPC; } =20 -int write_node_raw(struct connection *conn, TDB_DATA *key, struct node *no= de, - enum write_node_mode mode, bool no_quota_check) +int write_node_raw(struct connection *conn, const char *db_name, + struct node *node, enum write_node_mode mode, + bool no_quota_check) { - TDB_DATA data; + void *data; + size_t size; void *p; struct xs_tdb_record_hdr *hdr; =20 if (domain_adjust_node_perms(node)) return errno; =20 - data.dsize =3D sizeof(*hdr) + size =3D sizeof(*hdr) + node->perms.num * sizeof(node->perms.p[0]) + node->datalen + node->childlen; =20 /* Call domain_max_chk() in any case in order to record max values. */ - if (domain_max_chk(conn, ACC_NODESZ, data.dsize) && !no_quota_check) { + if (domain_max_chk(conn, ACC_NODESZ, size) && !no_quota_check) { errno =3D ENOSPC; return errno; } =20 - data.dptr =3D talloc_size(node, data.dsize); - if (!data.dptr) { + data =3D talloc_size(node, size); + if (!data) { errno =3D ENOMEM; return errno; } =20 - hdr =3D (void *)data.dptr; + hdr =3D data; hdr->generation =3D node->generation; hdr->num_perms =3D node->perms.num; hdr->datalen =3D node->datalen; @@ -819,7 +824,8 @@ int write_node_raw(struct connection *conn, TDB_DATA *k= ey, struct node *node, p +=3D node->datalen; memcpy(p, node->children, node->childlen); =20 - if (do_tdb_write(conn, key, &data, &node->acc, mode, no_quota_check)) + if (db_write(conn, db_name, data, size, &node->acc, mode, + no_quota_check)) return EIO; =20 return 0; @@ -833,13 +839,11 @@ static int write_node(struct connection *conn, struct= node *node, enum write_node_mode mode, bool no_quota_check) { int ret; - TDB_DATA key; =20 if (access_node(conn, node, NODE_ACCESS_WRITE, &node->db_name)) return errno; =20 - set_tdb_key(node->db_name, &key); - ret =3D write_node_raw(conn, &key, node, mode, no_quota_check); + ret =3D write_node_raw(conn, node->db_name, node, mode, no_quota_check); if (ret && conn && conn->transaction) { /* * Reverting access_node() is hard, so just fail the @@ -3424,7 +3428,6 @@ void read_state_node(const void *ctx, const void *sta= te) { const struct xs_state_node *sn =3D state; struct node *node, *parent; - TDB_DATA key; char *name, *parentname; unsigned int i; struct connection conn =3D { .id =3D priv_domid }; @@ -3477,15 +3480,12 @@ void read_state_node(const void *ctx, const void *s= tate) if (add_child(node, parent, name)) barf("allocation error restoring node"); =20 - set_tdb_key(parentname, &key); - if (write_node_raw(NULL, &key, parent, NODE_MODIFY, true)) + if (write_node_raw(NULL, parentname, parent, NODE_MODIFY, true)) barf("write parent error restoring node"); } =20 - set_tdb_key(name, &key); - /* The "/" node is already existing, so it can only be modified here. */ - if (write_node_raw(NULL, &key, node, + if (write_node_raw(NULL, name, node, strcmp(name, "/") ? NODE_CREATE : NODE_MODIFY, true)) barf("write node error restoring node"); =20 diff --git a/tools/xenstore/xenstored_core.h b/tools/xenstore/xenstored_cor= e.h index 7bc1f68532..3074f14511 100644 --- a/tools/xenstore/xenstored_core.h +++ b/tools/xenstore/xenstored_core.h @@ -242,8 +242,9 @@ enum write_node_mode { NODE_MODIFY }; =20 -int write_node_raw(struct connection *conn, TDB_DATA *key, struct node *no= de, - enum write_node_mode mode, bool no_quota_check); +int write_node_raw(struct connection *conn, const char *db_name, + struct node *node, enum write_node_mode mode, + bool no_quota_check); =20 /* Get a node from the tdb data base. */ struct node *read_node(struct connection *conn, const void *ctx, @@ -363,9 +364,9 @@ int remember_string(struct hashtable *hash, const char = *str); =20 /* Data base access functions. */ void set_tdb_key(const char *name, TDB_DATA *key); -int do_tdb_write(struct connection *conn, TDB_DATA *key, TDB_DATA *data, - struct node_account_data *acc, enum write_node_mode mode, - bool no_quota_check); +int db_write(struct connection *conn, const char *db_name, void *data, + size_t size, struct node_account_data *acc, + enum write_node_mode mode, bool no_quota_check); int db_delete(struct connection *conn, const char *name, struct node_account_data *acc); =20 diff --git a/tools/xenstore/xenstored_domain.c b/tools/xenstore/xenstored_d= omain.c index ac0e109654..d8810fa353 100644 --- a/tools/xenstore/xenstored_domain.c +++ b/tools/xenstore/xenstored_domain.c @@ -511,19 +511,17 @@ static int domain_tree_remove_sub(const void *ctx, st= ruct connection *conn, struct node *node, void *arg) { struct domain *domain =3D arg; - TDB_DATA key; int ret =3D WALK_TREE_OK; =20 if (node->perms.p[0].id !=3D domain->domid) return WALK_TREE_OK; =20 if (keep_orphans) { - set_tdb_key(node->name, &key); domain_nbentry_dec(NULL, domain->domid); node->perms.p[0].id =3D priv_domid; node->acc.memory =3D 0; domain_nbentry_inc(NULL, priv_domid); - if (write_node_raw(NULL, &key, node, NODE_MODIFY, true)) { + if (write_node_raw(NULL, node->name, node, NODE_MODIFY, true)) { /* That's unfortunate. We only can try to continue. */ syslog(LOG_ERR, "error when moving orphaned node %s to dom0\n", diff --git a/tools/xenstore/xenstored_transaction.c b/tools/xenstore/xensto= red_transaction.c index a4f9d40e9a..6e06634807 100644 --- a/tools/xenstore/xenstored_transaction.c +++ b/tools/xenstore/xenstored_transaction.c @@ -228,7 +228,6 @@ int access_node(struct connection *conn, struct node *n= ode, { struct accessed_node *i =3D NULL; struct transaction *trans; - TDB_DATA local_key; int ret; bool introduce =3D false; =20 @@ -286,8 +285,7 @@ int access_node(struct connection *conn, struct node *n= ode, i->generation =3D node->generation; i->check_gen =3D true; if (node->generation !=3D NO_GENERATION) { - set_tdb_key(i->trans_name, &local_key); - ret =3D write_node_raw(conn, &local_key, node, + ret =3D write_node_raw(conn, i->trans_name, node, NODE_CREATE, true); if (ret) goto err; @@ -404,9 +402,9 @@ static int finalize_transaction(struct connection *conn, hdr->generation =3D ++generation; flag =3D (i->generation =3D=3D NO_GENERATION) ? NODE_CREATE : NODE_MODIFY; - set_tdb_key(i->node, &key); - *is_corrupt |=3D do_tdb_write(conn, &key, &data, - NULL, flag, true); + *is_corrupt |=3D db_write(conn, i->node, + data.dptr, data.dsize, + NULL, flag, true); talloc_free(data.dptr); if (db_delete(conn, i->trans_name, NULL)) *is_corrupt =3D true; --=20 2.35.3