From nobody Mon Feb 9 22:39:14 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=1610639514; cv=none; d=zohomail.com; s=zohoarc; b=MVwcIvKtqyP9oRytPaux/t6QUeiLLVKPsbrxVO+G4rG9qEmlWxTuCsmrXr4KUBr81cG17/862cKN74rI2LEm0dY5TUxccEVe719UnVO0vGuIi/HPGqdWRepze9FT/Om3Y+bhEv0wW/alhTrL3T1OcehAc07Ybe80gwr0lC6KgLw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610639514; 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=8fzisLFHra+8irPIn/ZYbpu+ZVxDRPBpXZRvcHrNvww=; b=ZmW0c+PRLODg6V4jv28IRROXCgWa7j/PEykF1DKAPiwyOJe+SG2OTGJyRYBUiRqrNJQM/VS9YhsTq0phUuSjNbHcUP/Fz6Wj4QyiJZfZyPUHaDIzWGUzaVfDfR2MyYSHvJ1Q6OAtNoSLp1k3F4RxXXP+6anDVxBcmOuYnrgczYI= 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 1610639514334491.0178414278995; Thu, 14 Jan 2021 07:51:54 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.67322.120045 (Exim 4.92) (envelope-from ) id 1l04uO-0007IR-4U; Thu, 14 Jan 2021 15:51:36 +0000 Received: by outflank-mailman (output) from mailman id 67322.120045; Thu, 14 Jan 2021 15:51:36 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l04uO-0007IG-0Y; Thu, 14 Jan 2021 15:51:36 +0000 Received: by outflank-mailman (input) for mailman id 67322; Thu, 14 Jan 2021 15:51:35 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l04iA-0002SV-Nj for xen-devel@lists.xenproject.org; Thu, 14 Jan 2021 15:38:58 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 11f01b16-e4ab-40dd-ad32-d34a03110e68; Thu, 14 Jan 2021 15:38:14 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id C606CAF31; 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: 11f01b16-e4ab-40dd-ad32-d34a03110e68 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=8fzisLFHra+8irPIn/ZYbpu+ZVxDRPBpXZRvcHrNvww=; b=ZK7rg2EF7pui5cHKjCSm70j+6qVc4zBC7xUvTUaV+o5PvHgjgle9BUpHYKUxlotAxUFXln hCEHt6SI1zzQe1pNofpaU4pr/vgW0FZPGb/oE+y9hIgPvLBMMUjTJFmWWlFMkeLwJLVtX0 387kbBwRHbxaCWoqngkOZZyTymGpKTk= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Ian Jackson , Wei Liu , Paul Durrant Subject: [PATCH v11 25/27] tools/xenstore: add read watch state for live update Date: Thu, 14 Jan 2021 16:38:01 +0100 Message-Id: <20210114153803.2591-26-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 reading the watch state records for live update. This requires factoring out some of the add watch functionality into a dedicated function. Signed-off-by: Juergen Gross Reviewed-by: Paul Durrant --- V4: - add comment (Julien Grall) V6: - correct check_watch_path() (setting errno) --- tools/xenstore/xenstored_control.c | 2 + tools/xenstore/xenstored_watch.c | 114 +++++++++++++++++++++-------- tools/xenstore/xenstored_watch.h | 2 + 3 files changed, 88 insertions(+), 30 deletions(-) diff --git a/tools/xenstore/xenstored_control.c b/tools/xenstore/xenstored_= control.c index d73e1dca7e..ba48358c31 100644 --- a/tools/xenstore/xenstored_control.c +++ b/tools/xenstore/xenstored_control.c @@ -35,6 +35,7 @@ Interactive commands for Xen Store Daemon. #include "xenstored_core.h" #include "xenstored_control.h" #include "xenstored_domain.h" +#include "xenstored_watch.h" =20 /* Mini-OS only knows about MAP_ANON. */ #ifndef MAP_ANONYMOUS @@ -542,6 +543,7 @@ void lu_read_state(void) 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"); diff --git a/tools/xenstore/xenstored_watch.c b/tools/xenstore/xenstored_wa= tch.c index 9248f08bd9..db89e0141f 100644 --- a/tools/xenstore/xenstored_watch.c +++ b/tools/xenstore/xenstored_watch.c @@ -205,6 +205,62 @@ static int destroy_watch(void *_watch) return 0; } =20 +static int check_watch_path(struct connection *conn, const void *ctx, + char **path, bool *relative) +{ + /* Check if valid event. */ + if (strstarts(*path, "@")) { + *relative =3D false; + if (strlen(*path) > XENSTORE_REL_PATH_MAX) + goto inval; + } else { + *relative =3D !strstarts(*path, "/"); + *path =3D canonicalize(conn, ctx, *path); + if (!*path) + return errno; + if (!is_valid_nodename(*path)) + goto inval; + } + + return 0; + + inval: + errno =3D EINVAL; + return errno; +} + +static struct watch *add_watch(struct connection *conn, char *path, char *= token, + bool relative) +{ + struct watch *watch; + + watch =3D talloc(conn, struct watch); + if (!watch) + goto nomem; + watch->node =3D talloc_strdup(watch, path); + watch->token =3D talloc_strdup(watch, token); + if (!watch->node || !watch->token) + goto nomem; + + if (relative) + watch->relative_path =3D get_implicit_path(conn); + else + watch->relative_path =3D NULL; + + INIT_LIST_HEAD(&watch->events); + + domain_watch_inc(conn); + list_add_tail(&watch->list, &conn->watches); + talloc_set_destructor(watch, destroy_watch); + + return watch; + + nomem: + talloc_free(watch); + errno =3D ENOMEM; + return NULL; +} + int do_watch(struct connection *conn, struct buffered_data *in) { struct watch *watch; @@ -214,19 +270,9 @@ int do_watch(struct connection *conn, struct buffered_= data *in) if (get_strings(in, vec, ARRAY_SIZE(vec)) !=3D ARRAY_SIZE(vec)) return EINVAL; =20 - if (strstarts(vec[0], "@")) { - relative =3D false; - if (strlen(vec[0]) > XENSTORE_REL_PATH_MAX) - return EINVAL; - /* check if valid event */ - } else { - relative =3D !strstarts(vec[0], "/"); - vec[0] =3D canonicalize(conn, in, vec[0]); - if (!vec[0]) - return ENOMEM; - if (!is_valid_nodename(vec[0])) - return EINVAL; - } + errno =3D check_watch_path(conn, in, &(vec[0]), &relative); + if (errno) + return errno; =20 /* Check for duplicates. */ list_for_each_entry(watch, &conn->watches, list) { @@ -238,26 +284,11 @@ int do_watch(struct connection *conn, struct buffered= _data *in) if (domain_watch(conn) > quota_nb_watch_per_domain) return E2BIG; =20 - watch =3D talloc(conn, struct watch); + watch =3D add_watch(conn, vec[0], vec[1], relative); if (!watch) - return ENOMEM; - watch->node =3D talloc_strdup(watch, vec[0]); - watch->token =3D talloc_strdup(watch, vec[1]); - if (!watch->node || !watch->token) { - talloc_free(watch); - return ENOMEM; - } - if (relative) - watch->relative_path =3D get_implicit_path(conn); - else - watch->relative_path =3D NULL; + return errno; =20 - INIT_LIST_HEAD(&watch->events); - - domain_watch_inc(conn); - list_add_tail(&watch->list, &conn->watches); trace_create(watch, "watch"); - talloc_set_destructor(watch, destroy_watch); send_ack(conn, XS_WATCH); =20 /* We fire once up front: simplifies clients and restart. */ @@ -338,6 +369,29 @@ const char *dump_state_watches(FILE *fp, struct connec= tion *conn, return ret; } =20 +void read_state_watch(const void *ctx, const void *state) +{ + const struct xs_state_watch *sw =3D state; + struct connection *conn; + char *path, *token; + bool relative; + + conn =3D get_connection_by_id(sw->conn_id); + if (!conn) + barf("connection not found for read watch"); + + path =3D (char *)sw->data; + token =3D path + sw->path_length; + + /* Don't check success, we want the relative information only. */ + check_watch_path(conn, ctx, &path, &relative); + if (!path) + barf("allocation error for read watch"); + + if (!add_watch(conn, path, token, relative)) + barf("error adding watch"); +} + /* * Local variables: * mode: C diff --git a/tools/xenstore/xenstored_watch.h b/tools/xenstore/xenstored_wa= tch.h index 3d81645f45..0e693f0839 100644 --- a/tools/xenstore/xenstored_watch.h +++ b/tools/xenstore/xenstored_watch.h @@ -33,4 +33,6 @@ void conn_delete_all_watches(struct connection *conn); const char *dump_state_watches(FILE *fp, struct connection *conn, unsigned int conn_id); =20 +void read_state_watch(const void *ctx, const void *state); + #endif /* _XENSTORED_WATCH_H */ --=20 2.26.2