From patchwork Tue Dec 15 16:35:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?SsO8cmdlbiBHcm/Dnw==?= X-Patchwork-Id: 11975195 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AB20DC2BB9A for ; Tue, 15 Dec 2020 16:36:51 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 74CED223D6 for ; Tue, 15 Dec 2020 16:36:51 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 74CED223D6 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=suse.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.54549.94944 (Exim 4.92) (envelope-from ) id 1kpDJV-0006qc-In; Tue, 15 Dec 2020 16:36:37 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 54549.94944; Tue, 15 Dec 2020 16:36:37 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kpDJV-0006qJ-D5; Tue, 15 Dec 2020 16:36:37 +0000 Received: by outflank-mailman (input) for mailman id 54549; Tue, 15 Dec 2020 16:36: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 1kpDJT-000667-Gi for xen-devel@lists.xenproject.org; Tue, 15 Dec 2020 16:36:35 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 08cedaff-b36e-4a64-ac8e-a631dd681446; Tue, 15 Dec 2020 16:36:13 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id A878EB278; Tue, 15 Dec 2020 16:36:10 +0000 (UTC) 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: 08cedaff-b36e-4a64-ac8e-a631dd681446 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=1608050170; 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=/9jdr9ciXN6y1fOGGhzb94maMZkUU3XcSi6SB1NLEOc=; b=gX9xld/jXX9t52FNa/wJUfO6Ki6amzM6whCAZ8LoUPwmzXxbODYxrHD53x/RvJsI0w7SyW LmQd23Eg1nop1jPC/PJmR3spZgox6+CEGtsOwqI3keFE5oDqOXUkZJUwx4+sYpO86PjwMw GphPVgEtx4CVT8kB2Vg1RF02u4tF6Rw= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Ian Jackson , Wei Liu , Julien Grall Subject: [PATCH v10 14/25] tools/xenstore: add include file for state structure definitions Date: Tue, 15 Dec 2020 17:35:52 +0100 Message-Id: <20201215163603.21700-15-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201215163603.21700-1-jgross@suse.com> References: <20201215163603.21700-1-jgross@suse.com> MIME-Version: 1.0 Add an include file containing all structures and defines needed for dumping and restoring the internal Xenstore state. Signed-off-by: Juergen Gross Acked-by: Julien Grall --- V4: - drop mfn from connection record (rebase to V5 of state doc patch) - add #ifdef __MINIOS__ (Julien Grall) - correct comments (Julien Grall) - add data_in_len V5: - add data_resp_len V6: - add flag byte to node permissions (Julien Grall) - update migration document V7: - add evtchn_fd V8: - remove ro-socket and read-only connection flag - split off documentation part V9: - add htobe32() macro if needed (Wei Liu) Signed-off-by: Juergen Gross --- tools/xenstore/include/xenstore_state.h | 131 ++++++++++++++++++++++++ 1 file changed, 131 insertions(+) create mode 100644 tools/xenstore/include/xenstore_state.h diff --git a/tools/xenstore/include/xenstore_state.h b/tools/xenstore/include/xenstore_state.h new file mode 100644 index 0000000000..d2a9307400 --- /dev/null +++ b/tools/xenstore/include/xenstore_state.h @@ -0,0 +1,131 @@ +/* + * Xenstore internal state dump definitions. + * Copyright (C) Juergen Gross, SUSE Software Solutions Germany GmbH + * + * Used for live-update and migration, possibly across Xenstore implementations. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; If not, see . + */ + +#ifndef XENSTORE_STATE_H +#define XENSTORE_STATE_H + +#include +#include + +#ifndef htobe32 +#if __BYTE_ORDER == __LITTLE_ENDIAN +#define htobe32(x) __builtin_bswap32(x) +#else +#define htobe32(x) (x) +#endif +#endif + +struct xs_state_preamble { + char ident[8]; +#define XS_STATE_IDENT "xenstore" /* To be used without the NUL byte. */ + uint32_t version; /* Version in big endian format. */ +#define XS_STATE_VERSION 0x00000001 + uint32_t flags; /* Endianess. */ +#if __BYTE_ORDER == __LITTLE_ENDIAN +#define XS_STATE_FLAGS 0x00000000 /* Little endian. */ +#else +#define XS_STATE_FLAGS 0x00000001 /* Big endian. */ +#endif +}; + +/* + * Each record is starting with xs_state_record_header. + * All records have a length of a multiple of 8 bytes. + */ + +/* Common record layout: */ +struct xs_state_record_header { + uint32_t type; +#define XS_STATE_TYPE_END 0x00000000 +#define XS_STATE_TYPE_GLOBAL 0x00000001 +#define XS_STATE_TYPE_CONN 0x00000002 +#define XS_STATE_TYPE_WATCH 0x00000003 +#define XS_STATE_TYPE_TA 0x00000004 +#define XS_STATE_TYPE_NODE 0x00000005 + uint32_t length; /* Length of record in bytes. */ +}; + +/* Global state of Xenstore: */ +struct xs_state_global { + int32_t socket_fd; /* File descriptor for socket connections or -1. */ + int32_t evtchn_fd; /* File descriptor for event channel operations. */ +}; + +/* Connection to Xenstore: */ +struct xs_state_connection { + uint32_t conn_id; /* Used as reference in watch and TA records. */ + uint16_t conn_type; +#define XS_STATE_CONN_TYPE_RING 0 +#define XS_STATE_CONN_TYPE_SOCKET 1 + uint16_t pad; + union { + struct { + uint16_t domid; /* Domain-Id. */ + uint16_t tdomid; /* Id of target domain or DOMID_INVALID. */ + uint32_t evtchn; /* Event channel port. */ + } ring; + int32_t socket_fd; /* File descriptor for socket connections. */ + } spec; + uint16_t data_in_len; /* Number of unprocessed bytes read from conn. */ + uint16_t data_resp_len; /* Size of partial response pending for conn. */ + uint32_t data_out_len; /* Number of bytes not yet written to conn. */ + uint8_t data[]; /* Pending data (read, written) + 0-7 pad bytes. */ +}; + +/* Watch: */ +struct xs_state_watch { + uint32_t conn_id; /* Connection this watch is associated with. */ + uint16_t path_length; /* Number of bytes of path watched (incl. 0). */ + uint16_t token_length; /* Number of bytes of watch token (incl. 0). */ + uint8_t data[]; /* Path bytes, token bytes, 0-7 pad bytes. */ +}; + +/* Transaction: */ +struct xs_state_transaction { + uint32_t conn_id; /* Connection this TA is associated with. */ + uint32_t ta_id; /* Transaction Id. */ +}; + +/* Node (either XS_STATE_TYPE_NODE or XS_STATE_TYPE_TANODE[_MOD]): */ +struct xs_state_node_perm { + uint8_t access; /* Access rights. */ +#define XS_STATE_NODE_PERM_NONE 'n' +#define XS_STATE_NODE_PERM_READ 'r' +#define XS_STATE_NODE_PERM_WRITE 'w' +#define XS_STATE_NODE_PERM_BOTH 'b' + uint8_t flags; +#define XS_STATE_NODE_PERM_IGNORE 0x01 /* Stale permission, ignore for check. */ + uint16_t domid; /* Domain-Id. */ +}; +struct xs_state_node { + uint32_t conn_id; /* Connection in case of transaction or 0. */ + uint32_t ta_id; /* Transaction Id or 0. */ + uint16_t path_len; /* Length of path string including NUL byte. */ + uint16_t data_len; /* Length of node data. */ + uint16_t ta_access; +#define XS_STATE_NODE_TA_DELETED 0x0000 +#define XS_STATE_NODE_TA_READ 0x0001 +#define XS_STATE_NODE_TA_WRITTEN 0x0002 + uint16_t perm_n; /* Number of permissions (0 in TA: node deleted). */ + /* Permissions (first is owner, has full access). */ + struct xs_state_node_perm perms[]; + /* Path and data follows, plus 0-7 pad bytes. */ +}; +#endif /* XENSTORE_STATE_H */