From nobody Mon Feb 9 16:19:06 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=1690196622; cv=none; d=zohomail.com; s=zohoarc; b=IDIDNLIMFaI7UZZ1zlKe9VycWVgJiVBfBhiAbarzvzZqvMdiAosl8pqvCeVawc7SjDvPOFueW87/30Gy7HOBj81kRiESQa7/LCYBANJ1dbOvIf8AJE4S7Y8MEzfQMzPC5N/DlUt3/9maEbPrOmGoDewFULIFCWTLidExvk04mxo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1690196622; 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=20QNajxZk743EX0aY+cQsL9LD9drTSx4TUjevmwUJ6E=; b=ZjVWjOF6/f243sx7VmPcwLFcHDrKJNWeAhMeT84HmcmbwxyGUo6WmB3cv8e0axgtv4QoX0K9XpCreTF2fgTXMpy8sMEvTpUdgI2sZXQ2gGUKAQKxve3K96d2ffnTbw/rdM/c5MwIbgo4k2aB167U9ekIxz72zHDF6sFja6rhJc0= 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 1690196622473200.497433720304; Mon, 24 Jul 2023 04:03:42 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.568736.888613 (Exim 4.92) (envelope-from ) id 1qNtLU-00026G-On; Mon, 24 Jul 2023 11:03:20 +0000 Received: by outflank-mailman (output) from mailman id 568736.888613; Mon, 24 Jul 2023 11:03:20 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qNtLU-000269-Lr; Mon, 24 Jul 2023 11:03:20 +0000 Received: by outflank-mailman (input) for mailman id 568736; Mon, 24 Jul 2023 11:03:19 +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 1qNtLT-0000KR-D9 for xen-devel@lists.xenproject.org; Mon, 24 Jul 2023 11:03:19 +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 b1fc07cb-2a11-11ee-b23a-6b7b168915f2; Mon, 24 Jul 2023 13:03:18 +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 51CCB20694; Mon, 24 Jul 2023 11:03: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 1EE3013476; Mon, 24 Jul 2023 11:03:18 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id RfohBnZavmRzYQAAMHmgww (envelope-from ); Mon, 24 Jul 2023 11:03: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: b1fc07cb-2a11-11ee-b23a-6b7b168915f2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1690196598; 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=20QNajxZk743EX0aY+cQsL9LD9drTSx4TUjevmwUJ6E=; b=rmXs4+NUDGQWf0svXnxtB3EadaPS11KNyaZosp6kxxLj/esZfXbqvx2jpHUx4XcrqTKSPV ji8hfHWzDijUmpItQ7xcB7XwqlhQPTkxAMZ1XtTIc9cVlV0zZqXPDWrlUNt+dMIe67CSHC HA7RiHrZin4P7ta/pMewAMLrNaB/HtY= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Julien Grall , Anthony PERARD , Julien Grall Subject: [PATCH v3 05/25] tools/xenstore: rename do_tdb_write() and change parameter type Date: Mon, 24 Jul 2023 13:02:27 +0200 Message-Id: <20230724110247.10520-6-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230724110247.10520-1-jgross@suse.com> References: <20230724110247.10520-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1690196623697100003 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 aa3885682d..2aa3d37c18 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 @@ -3429,7 +3433,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 }; @@ -3482,15 +3485,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 1aae324c77..875ee5192b 100644 --- a/tools/xenstore/xenstored_core.h +++ b/tools/xenstore/xenstored_core.h @@ -243,8 +243,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, @@ -364,9 +365,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 569c3bfbd0..10d2280f84 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 4a243369b0..1961aef0d7 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; @@ -405,9 +403,9 @@ static int finalize_transaction(struct connection *conn, hdr->generation =3D ++generation; mode =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, mode, true); + *is_corrupt |=3D db_write(conn, i->node, + data.dptr, data.dsize, + NULL, mode, true); talloc_free(data.dptr); if (db_delete(conn, i->trans_name, NULL)) *is_corrupt =3D true; --=20 2.35.3