From nobody Tue Feb 10 07:40:02 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=1610639377; cv=none; d=zohomail.com; s=zohoarc; b=YJTP94vPo92r8ipfT7r5Za2Bvnhv+QXT6HO6AOliYBv/sIEEMFANP8nYGzODfA9z41QONLUq43cH44x6jFH/cuAsU1ijvohAj7a2MZUvDL8UZfpjBoaoVaHiAXyRMVMoK7xEZqY9DLIrjlvfk8ZNG3CCYHBgZXyKnkJjXUaOSmM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610639377; 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=4kmuVlHOspaVKDt96etixwggFxvBVpVKxBmCa9TPUeo=; b=RrBHz3fOs4rUI82VsMSaK2XKjOQQSup6qLuPHwZG9W6weaOF2gos0R/b+1Ntsj62YPEvs2pGQbbmoIW11dpvLAkJcQExJlVJOIDqLcE2kC7ZGIi/bHjgBV9efjH9Mz08qNYUD5WxnO5CPivebjUVxJT1R1+BPsCx3JB6pQujCd0= 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) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1610639376992484.5490078002292; Thu, 14 Jan 2021 07:49:36 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.67262.119937 (Exim 4.92) (envelope-from ) id 1l04sE-0005dN-3h; Thu, 14 Jan 2021 15:49:22 +0000 Received: by outflank-mailman (output) from mailman id 67262.119937; Thu, 14 Jan 2021 15:49: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 1l04sE-0005dG-0O; Thu, 14 Jan 2021 15:49:22 +0000 Received: by outflank-mailman (input) for mailman id 67262; Thu, 14 Jan 2021 15:49:21 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l04ia-0002Sh-Kh for xen-devel@lists.xenproject.org; Thu, 14 Jan 2021 15:39:24 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id b6d48066-278a-4cf7-975e-da1af403dab1; Thu, 14 Jan 2021 15:38:13 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 991BCAF2C; Thu, 14 Jan 2021 15:38:11 +0000 (UTC) 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: b6d48066-278a-4cf7-975e-da1af403dab1 X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1610638691; 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=4kmuVlHOspaVKDt96etixwggFxvBVpVKxBmCa9TPUeo=; b=sfGsOR2FQoYyTPJqDQjwlZEn4BlIdg4SVietJnkw0a7ihFea+Fg2p9+ggWDbWAPiETXNha 5DFJnTNR46ISS7tus5oI1ImW3L0+NQS+ZVO0NojQepvqSCUO1VM0xPG6tXCJlgFT6OZplM oTwvWspjeUwRVWL0B3X1D7ZqPNSFWyc= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Ian Jackson , Wei Liu , Paul Durrant , Julien Grall Subject: [PATCH v11 24/27] tools/xenstore: add read node state for live update Date: Thu, 14 Jan 2021 16:38:00 +0100 Message-Id: <20210114153803.2591-25-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210114153803.2591-1-jgross@suse.com> References: <20210114153803.2591-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) Content-Type: text/plain; charset="utf-8" Add the needed functions for reading node state for live update. This requires some refactoring of current node handling in Xenstore in order to avoid repeating the same code patterns multiple times. Signed-off-by: Juergen Gross Reviewed-by: Paul Durrant Acked-by: Julien Grall --- V4: - drop local node handling (Julien Grall) V5: - use set_tdb_key (Paul Durrant) V6: - add permission flag handling (Julien Grall) --- tools/xenstore/xenstored_control.c | 1 + tools/xenstore/xenstored_core.c | 105 ++++++++++++++++++++++++++--- tools/xenstore/xenstored_core.h | 1 + 3 files changed, 96 insertions(+), 11 deletions(-) diff --git a/tools/xenstore/xenstored_control.c b/tools/xenstore/xenstored_= control.c index d6454d4e77..d73e1dca7e 100644 --- a/tools/xenstore/xenstored_control.c +++ b/tools/xenstore/xenstored_control.c @@ -547,6 +547,7 @@ void lu_read_state(void) 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", diff --git a/tools/xenstore/xenstored_core.c b/tools/xenstore/xenstored_cor= e.c index 4175b871ee..3e133b475c 100644 --- a/tools/xenstore/xenstored_core.c +++ b/tools/xenstore/xenstored_core.c @@ -972,13 +972,30 @@ static char *basename(const char *name) return strrchr(name, '/') + 1; } =20 -static struct node *construct_node(struct connection *conn, const void *ct= x, - const char *name) +static int add_child(const void *ctx, struct node *parent, const char *nam= e) { const char *base; unsigned int baselen; + char *children; + + base =3D basename(name); + baselen =3D strlen(base) + 1; + children =3D talloc_array(ctx, char, parent->childlen + baselen); + if (!children) + return ENOMEM; + memcpy(children, parent->children, parent->childlen); + memcpy(children + parent->childlen, base, baselen); + parent->children =3D children; + parent->childlen +=3D baselen; + + return 0; +} + +static struct node *construct_node(struct connection *conn, const void *ct= x, + const char *name) +{ struct node *parent, *node; - char *children, *parentname =3D get_parent(ctx, name); + char *parentname =3D get_parent(ctx, name); =20 if (!parentname) return NULL; @@ -991,15 +1008,8 @@ static struct node *construct_node(struct connection = *conn, const void *ctx, return NULL; =20 /* Add child to parent. */ - base =3D basename(name); - baselen =3D strlen(base) + 1; - children =3D talloc_array(ctx, char, parent->childlen + baselen); - if (!children) + if (add_child(ctx, parent, name)) goto nomem; - memcpy(children, parent->children, parent->childlen); - memcpy(children + parent->childlen, base, baselen); - parent->children =3D children; - parent->childlen +=3D baselen; =20 /* Allocate node */ node =3D talloc(ctx, struct node); @@ -2612,6 +2622,79 @@ void read_state_buffered_data(const void *ctx, struc= t connection *conn, } } =20 +void read_state_node(const void *ctx, const void *state) +{ + 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 }; + + name =3D (char *)(sn->perms + sn->perm_n); + node =3D talloc(ctx, struct node); + if (!node) + barf("allocation error restoring node"); + + node->name =3D name; + node->generation =3D ++generation; + node->datalen =3D sn->data_len; + node->data =3D name + sn->path_len; + node->childlen =3D 0; + node->children =3D NULL; + node->perms.num =3D sn->perm_n; + node->perms.p =3D talloc_array(node, struct xs_permissions, + node->perms.num); + if (!node->perms.p) + barf("allocation error restoring node"); + for (i =3D 0; i < node->perms.num; i++) { + switch (sn->perms[i].access) { + case 'r': + node->perms.p[i].perms =3D XS_PERM_READ; + break; + case 'w': + node->perms.p[i].perms =3D XS_PERM_WRITE; + break; + case 'b': + node->perms.p[i].perms =3D XS_PERM_READ | XS_PERM_WRITE; + break; + default: + node->perms.p[i].perms =3D XS_PERM_NONE; + break; + } + if (sn->perms[i].flags & XS_STATE_NODE_PERM_IGNORE) + node->perms.p[i].perms |=3D XS_PERM_IGNORE; + node->perms.p[i].id =3D sn->perms[i].domid; + } + + if (strstarts(name, "@")) { + set_perms_special(&conn, name, &node->perms); + talloc_free(node); + return; + } + + parentname =3D get_parent(node, name); + if (!parentname) + barf("allocation error restoring node"); + parent =3D read_node(NULL, node, parentname); + if (!parent) + barf("read parent error restoring node"); + + if (add_child(node, parent, name)) + barf("allocation error restoring node"); + + set_tdb_key(parentname, &key); + if (write_node_raw(NULL, &key, parent, true)) + barf("write parent error restoring node"); + + set_tdb_key(name, &key); + if (write_node_raw(NULL, &key, node, true)) + barf("write node error restoring node"); + domain_entry_inc(&conn, node); + + talloc_free(node); +} + /* * Local variables: * mode: C diff --git a/tools/xenstore/xenstored_core.h b/tools/xenstore/xenstored_cor= e.h index dcb3ad3e4b..6ac5a6fbfa 100644 --- a/tools/xenstore/xenstored_core.h +++ b/tools/xenstore/xenstored_core.h @@ -276,6 +276,7 @@ const char *dump_state_node_perms(FILE *fp, struct xs_s= tate_node *sn, void read_state_global(const void *ctx, const void *state); void read_state_buffered_data(const void *ctx, struct connection *conn, const struct xs_state_connection *sc); +void read_state_node(const void *ctx, const void *state); =20 #endif /* _XENSTORED_CORE_H */ =20 --=20 2.26.2