From nobody Thu May 16 01:45:44 2024 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=1699632540; cv=none; d=zohomail.com; s=zohoarc; b=Ey6+CIPZTANAXAAbiFg1jzVbBtWBWT1Js4LrLwACO5rY9MNOpSSv4KbLtxCxZsLfV4JIZq80GpVbGHlKfrAdHHcQ63aM4RHnaBpyOum2iUtCwQBn9iSxTWsbQVlr9YNr+R7ViUIguy4oPbekH+/e/kqvlc3VRlQTvCI+0BLOiqw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1699632540; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=KX1+eDPCalxeEFEgNKEP+cxmDRb/81lwwxJPAyo97p8=; b=NJ2VWSOsFSkOgtZkZl4TIfRgd1GfXUoz61loA3n8Y/5mEuLH+kHQiSG/VKYePdXZEjSGBDYWSRAUhU5bcCVVDI1gtnSkyrYEEFn9ex4a1e+GPqEtp5LMjlv3LIPqkbN9ZkuyWSZS5SIs4wNtdEirMj1CcwD2XnHQmjpa+2cXX2I= 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 1699632540680827.5989323138049; Fri, 10 Nov 2023 08:09:00 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.630465.983300 (Exim 4.92) (envelope-from ) id 1r1U3O-0004ND-Fr; Fri, 10 Nov 2023 16:08:18 +0000 Received: by outflank-mailman (output) from mailman id 630465.983300; Fri, 10 Nov 2023 16:08:18 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1r1U3O-0004N6-D8; Fri, 10 Nov 2023 16:08:18 +0000 Received: by outflank-mailman (input) for mailman id 630465; Fri, 10 Nov 2023 16:08:16 +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 1r1U3M-00048H-MB for xen-devel@lists.xenproject.org; Fri, 10 Nov 2023 16:08:16 +0000 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 5a44d42c-7fe3-11ee-98da-6d05b1d4d9a1; Fri, 10 Nov 2023 17:08:14 +0100 (CET) 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-out1.suse.de (Postfix) with ESMTPS id A21742187C; Fri, 10 Nov 2023 16:08:12 +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 86B2113398; Fri, 10 Nov 2023 16:08:12 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id kG2FH2xVTmVfCAAAMHmgww (envelope-from ); Fri, 10 Nov 2023 16:08:12 +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: 5a44d42c-7fe3-11ee-98da-6d05b1d4d9a1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1699632492; 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=KX1+eDPCalxeEFEgNKEP+cxmDRb/81lwwxJPAyo97p8=; b=L9r11Bm4y/+fJwlqKCNLLex1A43vSYJMwabGjObqK+M89XOC4w2PqCxN+9hEdQeXLgcWLs 01k3padm3b4rDhdJO747kpz/WOGH4ulpWwfopn5X1711QHLZ7YaPdsbsGA2lGaChntxDBN okSazRAVPRjgmazZYTYiY7b9Q8Vca/8= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross Subject: [PATCH v2 01/29] xen/public: add some more 9pfs xenstore paths Date: Fri, 10 Nov 2023 17:07:36 +0100 Message-Id: <20231110160804.29021-2-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20231110160804.29021-1-jgross@suse.com> References: <20231110160804.29021-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1699632541848100001 Content-Type: text/plain; charset="utf-8" Add some optional additional backend paths for 9pfs PV devices. Those paths will be supported by the new xenlogd 9pfs backend. Signed-off-by: Juergen Gross Reviewed-by: Jason Andryuk --- xen/include/public/io/9pfs.h | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/xen/include/public/io/9pfs.h b/xen/include/public/io/9pfs.h index 9ad2773082..ac4bf0434b 100644 --- a/xen/include/public/io/9pfs.h +++ b/xen/include/public/io/9pfs.h @@ -71,6 +71,40 @@ * created on the guest (no user ownership squash or remap) * Only "none" is supported in this version of the protocol. * + * max-files + * Values: + * + * The maximum number of files (including directories) allowed for + * this device. Backend support of this node is optional. If the n= ode + * is not present or the value is zero the number of files is not + * limited. + * + * max-open-files + * Values: + * + * The maximum number of files the guest is allowed to have opened + * concurrently. Multiple concurrent opens of the same file are co= unted + * individually. Backend support of this node is optional. If the = node + * is not present or the value is zero a backend specific default = is + * applied. + * + * max-space + * Values: + * + * The maximum file space in MiBs the guest is allowed to use for = this + * device. Backend support of this node is optional. If the node is + * not present or the value is zero the space is not limited. + * + * auto-delete + * Values: + * + * When set to "1" the backend will delete the file with the oldest + * modification date below in case the allowed maximum file + * space (see ) or file number (see ) is bei= ng + * exceeded due to guest activity (creation or extension of files). + * Files currently opened by the guest won't be deleted. Backend + * support of this node is optional. + * *************************************************************************= ***** * Frontend XenBus Nodes *************************************************************************= ***** --=20 2.35.3 From nobody Thu May 16 01:45:44 2024 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=1699632545; cv=none; d=zohomail.com; s=zohoarc; b=hV3K0e4MLL62riEoisPOZacG/QKDSTso4f1u9F0S+0ENl/Oul6GrhGdx2FjHVuZOoQ9c4FZvmkGbUs3bArKNlXAD9EYAnSEMXUg+Nqg/RIdxBD89ZX+ZoC2QcDW2DFRYz376r6Sng/dGBO6OnDpK0v2NMJQEKstiq1f7fkuMTuU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1699632545; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=W9YiMiAuot0hCz4ZuuowgGxQE+TXmWYLhxPrRiHeKuQ=; b=XPN9Bp3FQH6UiFFpAW4u0P0SMiMYdrIhy+/M4jx79y7wbsXUdudJjC78HQ7QGjKMRb7LMdbMArcGgAHz6d3O6DBYoAO0PMnNXfB3QmkppQE5nmS98+kvEyPKiwsmfBk7s0/aJ6PuPCtXsvr/DZpQA5zPgEByCgW3zw3ExoGwDCg= 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 1699632545323116.51401933861621; Fri, 10 Nov 2023 08:09:05 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.630466.983310 (Exim 4.92) (envelope-from ) id 1r1U3S-0004dN-N8; Fri, 10 Nov 2023 16:08:22 +0000 Received: by outflank-mailman (output) from mailman id 630466.983310; Fri, 10 Nov 2023 16:08: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 1r1U3S-0004dG-KK; Fri, 10 Nov 2023 16:08:22 +0000 Received: by outflank-mailman (input) for mailman id 630466; Fri, 10 Nov 2023 16:08:21 +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 1r1U3R-0004cS-KF for xen-devel@lists.xenproject.org; Fri, 10 Nov 2023 16:08:21 +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 5c9d8f7d-7fe3-11ee-9b0e-b553b5be7939; Fri, 10 Nov 2023 17:08:18 +0100 (CET) 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 3ACF71F8BD; Fri, 10 Nov 2023 16:08: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 12AF313398; Fri, 10 Nov 2023 16:08:18 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id bhAxA3JVTmVtCAAAMHmgww (envelope-from ); Fri, 10 Nov 2023 16:08: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: 5c9d8f7d-7fe3-11ee-9b0e-b553b5be7939 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1699632498; 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=W9YiMiAuot0hCz4ZuuowgGxQE+TXmWYLhxPrRiHeKuQ=; b=EPj4HJ6X73gfTD1pbbWQ0uoOFClsHdDJ057LJNc4jIzbACN+Jp27IXw7c7k7qsa/XJTdKB aL38vczwvHIuqo1VnUtnFcvFkeNb1oTsdlEszpwGhc83HCt00a1Y8xldTuIszF+mR2ESv5 4KVaQwDp0iCD7h1lJ5DVRAHb7FmvU6g= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Anthony PERARD Subject: [PATCH v2 02/29] tools: add a new xen logging daemon Date: Fri, 10 Nov 2023 17:07:37 +0100 Message-Id: <20231110160804.29021-3-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20231110160804.29021-1-jgross@suse.com> References: <20231110160804.29021-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1699632545854100007 Content-Type: text/plain; charset="utf-8" Add "xen-9pfsd", a new logging daemon meant to support infrastructure domains (e.g. xenstore-stubdom) to access files in dom0. For now only add the code needed for starting the daemon and registering it with Xenstore via a new "libxl/xen-9pfs/state" node by writing the "running" state to it. Signed-off-by: Juergen Gross Reviewed-by: Jason Andryuk --- V2: - rename from xenlogd to xen-9pfsd (Andrew Cooper) - use a backend domain local Xenstore node (Jason Andryuk) - use "volatile" for stop_me (Andrew Cooper) --- tools/Makefile | 1 + tools/xen-9pfsd/.gitignore | 1 + tools/xen-9pfsd/Makefile | 38 ++++++++++ tools/xen-9pfsd/xen-9pfsd.c | 145 ++++++++++++++++++++++++++++++++++++ 4 files changed, 185 insertions(+) create mode 100644 tools/xen-9pfsd/.gitignore create mode 100644 tools/xen-9pfsd/Makefile create mode 100644 tools/xen-9pfsd/xen-9pfsd.c diff --git a/tools/Makefile b/tools/Makefile index 3a510663a0..f8faa3a902 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -32,6 +32,7 @@ SUBDIRS-y +=3D xenpmd SUBDIRS-$(CONFIG_GOLANG) +=3D golang SUBDIRS-y +=3D xl SUBDIRS-y +=3D helpers +SUBDIRS-y +=3D xen-9pfsd SUBDIRS-$(CONFIG_X86) +=3D xenpaging SUBDIRS-$(CONFIG_X86) +=3D debugger SUBDIRS-$(CONFIG_TESTS) +=3D tests diff --git a/tools/xen-9pfsd/.gitignore b/tools/xen-9pfsd/.gitignore new file mode 100644 index 0000000000..d0c2d223ef --- /dev/null +++ b/tools/xen-9pfsd/.gitignore @@ -0,0 +1 @@ +/xen-9pfsd diff --git a/tools/xen-9pfsd/Makefile b/tools/xen-9pfsd/Makefile new file mode 100644 index 0000000000..4e35202f08 --- /dev/null +++ b/tools/xen-9pfsd/Makefile @@ -0,0 +1,38 @@ +# +# tools/xen-9pfsd/Makefile +# + +XEN_ROOT =3D $(CURDIR)/../.. +include $(XEN_ROOT)/tools/Rules.mk + +CFLAGS +=3D $(PTHREAD_CFLAGS) +LDFLAGS +=3D $(PTHREAD_LDFLAGS) + +TARGETS :=3D xen-9pfsd + +XEN-9PFSD_OBJS =3D xen-9pfsd.o +$(XEN-9PFSD_OBJS): CFLAGS +=3D $(CFLAGS_libxenstore) +$(XEN-9PFSD_OBJS): CFLAGS +=3D $(CFLAGS_libxenevtchn) +$(XEN-9PFSD_OBJS): CFLAGS +=3D $(CFLAGS_libxengnttab) +xen-9pfsd: LDLIBS +=3D $(call xenlibs-ldlibs,store evtchn gnttab) + +.PHONY: all +all: $(TARGETS) + +xen-9pfsd: $(XEN-9PFSD_OBJS) + $(CC) $(LDFLAGS) -o $@ $(XEN-9PFSD_OBJS) $(LDLIBS) $(APPEND_LDFLAGS) + +.PHONY: install +install: all + $(INSTALL_DIR) $(DESTDIR)$(LIBEXEC_BIN) + for i in $(TARGETS); do $(INSTALL_PROG) $$i $(DESTDIR)$(LIBEXEC_BIN); done + +.PHONY: uninstall +uninstall: + for i in $(TARGETS); do rm -f $(DESTDIR)$(LIBEXEC_BIN)/$$i; done + +.PHONY: clean +clean: + $(RM) *.o $(TARGETS) $(DEPS_RM) + +distclean: clean diff --git a/tools/xen-9pfsd/xen-9pfsd.c b/tools/xen-9pfsd/xen-9pfsd.c new file mode 100644 index 0000000000..c365b35fe5 --- /dev/null +++ b/tools/xen-9pfsd/xen-9pfsd.c @@ -0,0 +1,145 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +/* + * xen-9pfsd - Xen 9pfs daemon + * + * Copyright (C) 2023 Juergen Gross + * + * Daemon to enable guests to access a directory of the dom0 file system. + * Access is made via the 9pfs protocol (xen-9pfsd acts as a PV 9pfs backe= nd). + * + * Usage: xen-9pfsd + * + * xen-9pfsd does NOT support writing any links (neither soft links nor ha= rd + * links), and it is accepting only canonicalized file paths in order to + * avoid the possibility to "escape" from the guest specific directory. + * + * The backend device string is "xen_9pfs", the tag used for mounting the + * 9pfs device is "Xen". + * + * As an additional security measure the maximum file space used by the gu= est + * can be limited by the backend Xenstore node "max-size" specifying the s= ize + * in MBytes. This size includes the size of the root directory of the gue= st. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static volatile bool stop_me; +static bool daemon_running; +static struct xs_handle *xs; +static xengnttab_handle *xg; +static xenevtchn_handle *xe; + +static void handle_stop(int sig) +{ + stop_me =3D true; +} + +static void close_all(void) +{ + if ( daemon_running ) + xs_rm(xs, XBT_NULL, "libxl/xen-9pfs"); + if ( xe ) + xenevtchn_close(xe); + if ( xg ) + xengnttab_close(xg); + if ( xs ) + xs_close(xs); + closelog(); +} + +static void do_err(const char *msg) +{ + syslog(LOG_ALERT, "%s, errno =3D %d", msg, errno); + close_all(); + exit(1); +} + +static void xen_connect(void) +{ + xs_transaction_t t; + char *val; + unsigned int len; + + xs =3D xs_open(0); + if ( xs =3D=3D NULL ) + do_err("xs_open() failed"); + + xg =3D xengnttab_open(NULL, 0); + if ( xg =3D=3D NULL ) + do_err("xengnttab_open() failed"); + + xe =3D xenevtchn_open(NULL, 0); + if ( xe =3D=3D NULL ) + do_err("xenevtchn_open() failed"); + + while ( true ) + { + t =3D xs_transaction_start(xs); + if ( t =3D=3D XBT_NULL ) + do_err("xs_transaction_start() failed"); + + val =3D xs_read(xs, t, "libxl/xen-9pfs/state", &len); + if ( val ) + { + free(val); + xs_transaction_end(xs, t, true); + do_err("daemon already running"); + } + + if ( !xs_write(xs, t, "libxl/xen-9pfs/state", "running", + strlen("running")) ) + { + xs_transaction_end(xs, t, true); + do_err("xs_write() failed writing state"); + } + + if ( xs_transaction_end(xs, t, false) ) + break; + if ( errno !=3D EAGAIN ) + do_err("xs_transaction_end() failed"); + } + + daemon_running =3D true; +} + +int main(int argc, char *argv[]) +{ + struct sigaction act =3D { .sa_handler =3D handle_stop, }; + int syslog_mask =3D LOG_MASK(LOG_WARNING) | LOG_MASK(LOG_ERR) | + LOG_MASK(LOG_CRIT) | LOG_MASK(LOG_ALERT) | + LOG_MASK(LOG_EMERG); + + umask(027); + if ( getenv("XEN_9PFSD_VERBOSE") ) + syslog_mask |=3D LOG_MASK(LOG_NOTICE) | LOG_MASK(LOG_INFO); + openlog("xen-9pfsd", LOG_CONS, LOG_DAEMON); + setlogmask(syslog_mask); + + sigemptyset(&act.sa_mask); + sigaction(SIGHUP, &act, NULL); + + xen_connect(); + + while ( !stop_me ) + { + sleep(60); + } + + close_all(); + + return 0; +} --=20 2.35.3 From nobody Thu May 16 01:45:44 2024 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=1699632542; cv=none; d=zohomail.com; s=zohoarc; b=dkJOd6dwX6ZxyD5yoskK5ByLEsArHn4AAcDx5yphAig7NEq2wQlZijWLkUd0VtiBq+Cfj7P2ohRHVTN+ovAG/mLTs7VHwJ3UZnVTnIt4pegHqWvCiHeg2T4kKLRaQQBtzfM8XD836RSY1POqqdQidXu2+DIrZlKIIAYllCZSvT4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1699632542; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=qaecwcPQrQoZBr5cMiDKL915MBWxnfCx9RL4QO3WWDk=; b=V90235Ja7rfYa/BwwN/jM8Jr83+FtFdiNX/tHUnCTt3pNwR38WMzysBFFSRi5CPtANafPfPhFa3/wElKN9O4IiGWIDx7obCnRr5V7u+kSItVGxSNLugewLUc/0LJ/HcF6yxxyltPvkv4DvtHlqoL7Uplzz4o1mEsnTM0Fs8fo2U= 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 1699632542484636.5732740381717; Fri, 10 Nov 2023 08:09:02 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.630467.983320 (Exim 4.92) (envelope-from ) id 1r1U3X-0004wV-0F; Fri, 10 Nov 2023 16:08:27 +0000 Received: by outflank-mailman (output) from mailman id 630467.983320; Fri, 10 Nov 2023 16:08:26 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1r1U3W-0004wO-TC; Fri, 10 Nov 2023 16:08:26 +0000 Received: by outflank-mailman (input) for mailman id 630467; Fri, 10 Nov 2023 16:08:25 +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 1r1U3V-00048H-2v for xen-devel@lists.xenproject.org; Fri, 10 Nov 2023 16:08:25 +0000 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 5ff07add-7fe3-11ee-98da-6d05b1d4d9a1; Fri, 10 Nov 2023 17:08:24 +0100 (CET) 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-out1.suse.de (Postfix) with ESMTPS id CBE2E2187C; Fri, 10 Nov 2023 16:08:23 +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 A0E0B13398; Fri, 10 Nov 2023 16:08:23 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id n4P6JXdVTmV+CAAAMHmgww (envelope-from ); Fri, 10 Nov 2023 16:08:23 +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: 5ff07add-7fe3-11ee-98da-6d05b1d4d9a1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1699632503; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=qaecwcPQrQoZBr5cMiDKL915MBWxnfCx9RL4QO3WWDk=; b=f77DYaRlG3Aamf+PKq9tBs0CunCXk2c64ZxY2ov+0OvMFFTBajIzCCzUDBf7+bKJbmNLHj B3rtd0zqDNC4dc6Sm7KusTapilNPN/fH3PhRsAgiganqp/0keqWBKTQltaQwJMVFBY2R11 0gVNLLgeXH/n+gcpReUikjK8GkBD2l4= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Anthony PERARD Subject: [PATCH v2 03/29] tools/xenlogd: connect to frontend Date: Fri, 10 Nov 2023 17:07:38 +0100 Message-Id: <20231110160804.29021-4-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20231110160804.29021-1-jgross@suse.com> References: <20231110160804.29021-1-jgross@suse.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1699632543909100004 Add the code for connecting to frontends to xenlogd. Signed-off-by: Juergen Gross --- V2: - support multiple rings per device (Jason Andryuk) - don't set .revents initially (Jason Andryuk) - call poll() with infinite timeout (Jason Andryuk) - take mutex before calling pthread_cond_signal() --- tools/xen-9pfsd/Makefile | 2 +- tools/xen-9pfsd/io.c | 45 +++ tools/xen-9pfsd/xen-9pfsd.c | 625 +++++++++++++++++++++++++++++++++++- tools/xen-9pfsd/xen-9pfsd.h | 60 ++++ 4 files changed, 728 insertions(+), 4 deletions(-) create mode 100644 tools/xen-9pfsd/io.c create mode 100644 tools/xen-9pfsd/xen-9pfsd.h diff --git a/tools/xen-9pfsd/Makefile b/tools/xen-9pfsd/Makefile index 4e35202f08..2023b19c62 100644 --- a/tools/xen-9pfsd/Makefile +++ b/tools/xen-9pfsd/Makefile @@ -10,7 +10,7 @@ LDFLAGS +=3D $(PTHREAD_LDFLAGS) =20 TARGETS :=3D xen-9pfsd =20 -XEN-9PFSD_OBJS =3D xen-9pfsd.o +XEN-9PFSD_OBJS =3D xen-9pfsd.o io.o $(XEN-9PFSD_OBJS): CFLAGS +=3D $(CFLAGS_libxenstore) $(XEN-9PFSD_OBJS): CFLAGS +=3D $(CFLAGS_libxenevtchn) $(XEN-9PFSD_OBJS): CFLAGS +=3D $(CFLAGS_libxengnttab) diff --git a/tools/xen-9pfsd/io.c b/tools/xen-9pfsd/io.c new file mode 100644 index 0000000000..e1e37970f4 --- /dev/null +++ b/tools/xen-9pfsd/io.c @@ -0,0 +1,45 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +/* + * xen-9pfsd - Xen 9pfs daemon + * + * Copyright (C) 2023 Juergen Gross + * + * I/O thread handling. + */ + +#include +#include +#include + +#include "xen-9pfsd.h" + +static bool io_work_pending(struct ring *ring) +{ + if ( ring->stop_thread ) + return true; + return false; +} + +void *io_thread(void *arg) +{ + struct ring *ring =3D arg; + + while ( !ring->stop_thread ) + { + pthread_mutex_lock(&ring->mutex); + if ( !io_work_pending(ring) ) + { + if ( xenevtchn_unmask(xe, ring->evtchn) < 0 ) + syslog(LOG_WARNING, "xenevtchn_unmask() failed"); + pthread_cond_wait(&ring->cond, &ring->mutex); + } + pthread_mutex_unlock(&ring->mutex); + + /* TODO: I/O handling. */ + } + + ring->thread_active =3D false; + + return NULL; +} diff --git a/tools/xen-9pfsd/xen-9pfsd.c b/tools/xen-9pfsd/xen-9pfsd.c index c365b35fe5..cc5734402d 100644 --- a/tools/xen-9pfsd/xen-9pfsd.c +++ b/tools/xen-9pfsd/xen-9pfsd.c @@ -24,34 +24,604 @@ =20 #include #include +#include +#include #include #include #include #include #include #include +#include #include #include #include -#include #include #include =20 +#include "xen-9pfsd.h" + +/* + * List of currently known devices. + * The list itself is modified only in the main thread. When a device is b= eing + * removed its memory needs to be freed after the I/O thread (if existing) + * has stopped. + */ +static XEN_TAILQ_HEAD(devhead, device) devs =3D XEN_TAILQ_HEAD_INITIALIZER= (devs); + +struct path { + char path[100]; +}; + static volatile bool stop_me; static bool daemon_running; static struct xs_handle *xs; static xengnttab_handle *xg; -static xenevtchn_handle *xe; +static unsigned int now; + +xenevtchn_handle *xe; =20 static void handle_stop(int sig) { stop_me =3D true; } =20 +static int check_host_path(device *device) +{ + struct stat statbuf; + char *path, *p; + int ret =3D 1; + + if ( !device->host_path ) + return 1; + + if ( device->host_path[0] !=3D '/' ) + return 1; + + path =3D strdup(device->host_path); + if ( !path ) + { + syslog(LOG_CRIT, "memory allocation failure!"); + return 1; + } + + for ( p =3D path; p; ) + { + p =3D strchr(p + 1, '/'); + if ( p ) + *p =3D 0; + if ( !stat(path, &statbuf) ) + { + if ( !(statbuf.st_mode & S_IFDIR) ) + break; + if ( !p ) + { + ret =3D 0; + break; + } + *p =3D '/'; + continue; + } + if ( mkdir(path, 0777) ) + break; + if ( p ) + *p =3D '/'; + } + + free(path); + return ret; +} + +static void construct_frontend_path(device *device, const char *node, + struct path *p) +{ + snprintf(p->path, sizeof(p->path), "/local/domain/%u/device/9pfs/%u/%s= ", + device->domid, device->devid, node); +} + +static void construct_backend_path(device *device, const char *node, + struct path *p) +{ + snprintf(p->path, sizeof(p->path), "backend/xen_9pfs/%u/%u/%s", + device->domid, device->devid, node); +} + +static char *read_backend_node(device *device, const char *node) +{ + struct path p; + char *val; + unsigned int len; + + construct_backend_path(device, node, &p); + val =3D xs_read(xs, XBT_NULL, p.path, &len); + + return val; +} + +static unsigned int uint_from_string(char *string, unsigned int def) +{ + unsigned long val; + char *end; + + if ( !string ) + return def; + + val =3D strtoul(string, &end, 10); + if ( *end || val > UINT_MAX ) + val =3D def; + free(string); + + return val; +} + +static unsigned int read_backend_node_uint(device *device, const char *nod= e, + unsigned int def) +{ + return uint_from_string(read_backend_node(device, node), def); +} + +static unsigned int read_frontend_node_uint(device *device, const char *no= de, + unsigned int def) +{ + struct path p; + unsigned int len; + + construct_frontend_path(device, node, &p); + + return uint_from_string(xs_read(xs, XBT_NULL, p.path, &len), def); +} + +static int write_backend_node(device *device, const char *node, const char= *val) +{ + struct path p; + struct xs_permissions perms[2] =3D { + { .id =3D 0, .perms =3D XS_PERM_NONE }, + { .id =3D device->domid, .perms =3D XS_PERM_READ } + }; + + construct_backend_path(device, node, &p); + if ( !xs_write(xs, XBT_NULL, p.path, val, strlen(val)) ) + { + syslog(LOG_ERR, "error writing bac=E1=B8=B1end node \"%s\" for dev= ice %u/%u", + node, device->domid, device->devid); + return 1; + } + + if ( !xs_set_permissions(xs, XBT_NULL, p.path, perms, 2) ) + { + syslog(LOG_ERR, "error setting permissions for \"%s\"", p.path); + return 1; + } + + return 0; +} + +static int write_backend_node_uint(device *device, const char *node, + unsigned int val) +{ + char str[12]; + + snprintf(str, sizeof(str), "%u", val); + + return write_backend_node(device, node, str); +} + +static int write_backend_state(device *device, enum xenbus_state state) +{ + struct path p; + char val[2]; + + snprintf(val, sizeof(val), "%u", state); + construct_backend_path(device, "state", &p); + if ( !xs_write(xs, XBT_NULL, p.path, val, 1) ) + { + syslog(LOG_ERR, "error writing backend state %u for device %u/%u", + state, device->domid, device->devid); + return 1; + } + + device->backend_state =3D state; + + return 0; +} + +static device *find_device(unsigned int domid, unsigned int devid) +{ + device *device; + + XEN_TAILQ_FOREACH( device, &devs, list ) + { + if ( domid =3D=3D device->domid && devid =3D=3D device->devid ) + return device; + } + + return NULL; +} + +static void free_device(device *device) +{ + char token[20]; + struct path p; + + construct_frontend_path(device, "state", &p); + snprintf(token, sizeof(token), "%u/%u", device->domid, device->devid); + xs_unwatch(xs, p.path, token); + + free(device->host_path); + free(device); +} + +static device *new_device(unsigned int domid, unsigned int devid) +{ + device *device; + char token[20]; + struct path p; + char *val; + + device =3D calloc(1, sizeof(*device)); + if ( !device ) + { + syslog(LOG_CRIT, "Got no memory for new device %u/%u", domid, devi= d); + return NULL; + } + + device->domid =3D domid; + device->devid =3D devid; + + construct_frontend_path(device, "state", &p); + snprintf(token, sizeof(token), "%u/%u", domid, devid); + if ( !xs_watch(xs, p.path, token) ) + { + syslog(LOG_ERR, "Setting up watch for device %u/%u failed", + domid, devid); + free(device); + return NULL; + } + + val =3D read_backend_node(device, "security_model"); + if ( !val || strcmp(val, "none") ) + { + syslog(LOG_ERR, "Security model \"%s\" for device %u/%u invalid.", + val, domid, devid); + free(val); + goto err; + } + free(val); + + device->max_space =3D read_backend_node_uint(device, "max-space", 0); + device->max_files =3D read_backend_node_uint(device, "max-files", 0); + device->max_open_files =3D + read_backend_node_uint(device, "max-open-files", 0) + ?: MAX_OPEN_FILES_DEFAULT; + device->auto_delete =3D read_backend_node_uint(device, "auto-delete", = 0); + + device->host_path =3D read_backend_node(device, "path"); + if ( check_host_path(device) ) + { + syslog(LOG_ERR, "Host path \"%s\" for device %u/%u invalid.", + device->host_path, domid, devid); + goto err; + } + + if ( write_backend_node(device, "versions", "1") ) + goto err; + if ( write_backend_node_uint(device, "max-rings", MAX_RINGS) ) + goto err; + if ( write_backend_node_uint(device, "max-ring-page-order", + MAX_RING_ORDER) ) + goto err; + + if ( write_backend_state(device, XenbusStateInitWait) ) + goto err; + + XEN_TAILQ_INSERT_TAIL(&devs, device, list); + syslog(LOG_INFO, "New device %u/%u added", domid, devid); + + return device; + + err: + free_device(device); + return NULL; +} + +static void disconnect_ring(struct ring *ring) +{ + if ( !ring ) + return; + + if ( ring->thread_active ) + { + ring->stop_thread =3D true; + pthread_cond_signal(&ring->cond); + pthread_join(ring->thread, NULL); + ring->stop_thread =3D false; + } + + if ( ring->data.in ) + { + xengnttab_unmap(xg, ring->data.in, 1 << ring->ring_order); + ring->data.in =3D NULL; + } + if ( ring->intf ) + { + xengnttab_unmap(xg, ring->intf, 1 ); + ring->intf =3D NULL; + } + + if ( ring->evtchn ) + { + xenevtchn_unbind(xe, ring->evtchn); + ring->evtchn =3D 0; + } + + pthread_mutex_destroy(&ring->mutex); + pthread_cond_destroy(&ring->cond); +} + +static void disconnect_guest(device *device) +{ + unsigned int ring_idx; + + for ( ring_idx =3D 0; ring_idx < device->num_rings; ring_idx++ ) + { + disconnect_ring(device->ring[ring_idx]); + free(device->ring[ring_idx]); + device->ring[ring_idx] =3D NULL; + } + + device->num_rings =3D 0; +} + +static void close_device(device *device, enum xenbus_state state) +{ + disconnect_guest(device); + write_backend_state(device, state); +} + +static void connect_err(device *device, const char *msg) +{ + syslog(LOG_WARNING, "%s", msg); + close_device(device, XenbusStateClosed); +} + +static void connect_device(device *device) +{ + unsigned int val; + unsigned int ring_idx; + char node[20]; + struct ring *ring; + xenevtchn_port_or_error_t evtchn; + + val =3D read_frontend_node_uint(device, "version", 0); + if ( val !=3D 1 ) + return connect_err(device, "frontend specifies illegal version"); + device->num_rings =3D read_frontend_node_uint(device, "num-rings", 0); + if ( device->num_rings < 1 || device->num_rings > MAX_RINGS ) + return connect_err(device, "frontend specifies illegal ring number= "); + + for ( ring_idx =3D 0; ring_idx < device->num_rings; ring_idx++ ) + { + ring =3D calloc(1, sizeof(*ring)); + if ( !ring ) + return connect_err(device, "could not allocate ring memory"); + device->ring[ring_idx] =3D ring; + ring->device =3D device; + pthread_cond_init(&ring->cond, NULL); + pthread_mutex_init(&ring->mutex, NULL); + + + snprintf(node, sizeof(node), "event-channel-%u", ring_idx); + val =3D read_frontend_node_uint(device, node, 0); + if ( val =3D=3D 0 ) + return connect_err(device, "frontend specifies illegal evtchn"= ); + evtchn =3D xenevtchn_bind_interdomain(xe, device->domid, val); + if ( evtchn < 0 ) + return connect_err(device, "could not bind to event channel"); + ring->evtchn =3D evtchn; + + snprintf(node, sizeof(node), "ring-ref%u", ring_idx); + val =3D read_frontend_node_uint(device, node, 0); + if ( val =3D=3D 0 ) + return connect_err(device, + "frontend specifies illegal grant for ring"= ); + ring->intf =3D xengnttab_map_grant_ref(xg, device->domid, val, + PROT_READ | PROT_WRITE); + if ( !ring->intf ) + return connect_err(device, "could not map interface page"); + ring->ring_order =3D ring->intf->ring_order; + if ( ring->ring_order > MAX_RING_ORDER || ring->ring_order < 1 ) + return connect_err(device, "frontend specifies illegal ring or= der"); + ring->ring_size =3D XEN_FLEX_RING_SIZE(ring->ring_order); + ring->data.in =3D xengnttab_map_domain_grant_refs(xg, + 1 << ring->ring_or= der, + device->domid, + ring->intf->ref, + PROT_READ | PROT_W= RITE); + if ( !ring->data.in ) + return connect_err(device, "could not map ring pages"); + ring->data.out =3D ring->data.in + ring->ring_size; + + if ( pthread_create(&ring->thread, NULL, io_thread, ring) ) + return connect_err(device, "could not start I/O thread"); + ring->thread_active =3D true; + } + + write_backend_state(device, XenbusStateConnected); +} + +static void remove_device(device *device) +{ + XEN_TAILQ_REMOVE(&devs, device, list); + + disconnect_guest(device); + free_device(device); +} + +static void remove_all_devices(void) +{ + device *device, *tmp; + + XEN_TAILQ_FOREACH_SAFE( device, &devs, list, tmp ) + remove_device(device); +} + +static void frontend_changed(device *device) +{ + struct path p; + char *state, *end; + unsigned int len; + unsigned long new_state; + + construct_frontend_path(device, "state", &p); + state =3D xs_read(xs, XBT_NULL, p.path, &len); + if ( !state ) + { + close_device(device, XenbusStateClosed); + return; + } + + new_state =3D strtoul(state, &end, 10); + if ( *end || new_state > XenbusStateReconfigured ) + { + syslog(LOG_WARNING, "unknown state \"%s\" seen for device %u/%u", = state, + device->domid, device->devid); + new_state =3D XenbusStateUnknown; + } + free(state); + + if ( new_state =3D=3D device->frontend_state ) + return; + + switch ( new_state ) + { + case XenbusStateInitialising: + break; + + case XenbusStateInitialised: + connect_device(device); + break; + + case XenbusStateConnected: + break; + + case XenbusStateClosing: + close_device(device, XenbusStateClosing); + break; + + case XenbusStateClosed: + close_device(device, XenbusStateClosed); + break; + + default: + syslog(LOG_WARNING, "not handled frontend state %lu for device %u/= %u", + new_state, device->domid, device->devid); + break; + } + + device->frontend_state =3D new_state; +} + +static void check_device(unsigned int domid, unsigned int devid) +{ + device *device; + + device =3D find_device(domid, devid); + if ( !device ) + { + device =3D new_device(domid, devid); + if ( !device ) + return; + } + + device->last_seen =3D now; +} + +static void scan_backend(void) +{ + char **doms; + unsigned int n_doms, dom; + char **devices; + unsigned int n_devs, dev; + char dom_path[24]; + unsigned long domid, devid; + char *end; + device *device, *tmp; + + now++; + + doms =3D xs_directory(xs, XBT_NULL, "backend/xen_9pfs", &n_doms); + if ( doms =3D=3D NULL ) + return; + + for ( dom =3D 0; dom < n_doms; dom++ ) + { + errno =3D 0; + domid =3D strtoul(doms[dom], &end, 10); + if ( errno || *end || domid >=3D DOMID_FIRST_RESERVED ) + continue; + + snprintf(dom_path, sizeof(dom_path), "backend/xen_9pfs/%lu", domid= ); + devices =3D xs_directory(xs, XBT_NULL, dom_path, &n_devs); + + for ( dev =3D 0; dev < n_devs; dev++ ) + { + errno =3D 0; + devid =3D strtoul(devices[dev], &end, 10); + if ( errno || *end || devid > UINT_MAX ) + continue; + + check_device(domid, devid); + } + + free(devices); + } + + free(doms); + + XEN_TAILQ_FOREACH_SAFE( device, &devs, list, tmp ) + { + if ( device->last_seen !=3D now ) + remove_device(device); + } +} + +static void handle_watch(char *path, char *token) +{ + unsigned int domid, devid; + device *device; + + if ( !strcmp(token, "main") ) + { + scan_backend(); + return; + } + + if ( sscanf(token, "%u/%u", &domid, &devid) !=3D 2 ) + { + syslog(LOG_WARNING, "unknown watch event %s %s", path, token); + return; + } + + device =3D find_device(domid, devid); + if ( !device ) + { + syslog(LOG_WARNING, "watch event for unknown device %u/%u", + domid, devid); + return; + } + + frontend_changed(device); +} + static void close_all(void) { if ( daemon_running ) + { xs_rm(xs, XBT_NULL, "libxl/xen-9pfs"); + xs_unwatch(xs, "backend/xen_9pfs", "main"); + + remove_all_devices(); + } if ( xe ) xenevtchn_close(xe); if ( xg ) @@ -68,6 +638,33 @@ static void do_err(const char *msg) exit(1); } =20 +static void handle_event(void) +{ + xenevtchn_port_or_error_t evtchn; + device *device; + struct ring *ring; + unsigned int ring_idx; + + evtchn =3D xenevtchn_pending(xe); + if ( evtchn < 0 ) + do_err("xenevtchn_pending() failed"); + + XEN_TAILQ_FOREACH( device, &devs, list ) + { + for ( ring_idx =3D 0; ring_idx < device->num_rings; ring_idx++ ) + { + ring =3D device->ring[ring_idx]; + if ( ring && ring->evtchn =3D=3D evtchn ) + { + pthread_mutex_lock(&ring->mutex); + pthread_cond_signal(&ring->cond); + pthread_mutex_unlock(&ring->mutex); + return; + } + } + } +} + static void xen_connect(void) { xs_transaction_t t; @@ -122,6 +719,11 @@ int main(int argc, char *argv[]) int syslog_mask =3D LOG_MASK(LOG_WARNING) | LOG_MASK(LOG_ERR) | LOG_MASK(LOG_CRIT) | LOG_MASK(LOG_ALERT) | LOG_MASK(LOG_EMERG); + char **watch; + struct pollfd p[2] =3D { + { .events =3D POLLIN }, + { .events =3D POLLIN } + }; =20 umask(027); if ( getenv("XEN_9PFSD_VERBOSE") ) @@ -134,9 +736,26 @@ int main(int argc, char *argv[]) =20 xen_connect(); =20 + if ( !xs_watch(xs, "backend/xen_9pfs", "main") ) + do_err("xs_watch() in main thread failed"); + p[0].fd =3D xs_fileno(xs); + p[1].fd =3D xenevtchn_fd(xe); + + scan_backend(); + while ( !stop_me ) { - sleep(60); + while ( (p[0].revents & POLLIN) && + (watch =3D xs_check_watch(xs)) !=3D NULL ) + { + handle_watch(watch[XS_WATCH_PATH], watch[XS_WATCH_TOKEN]); + free(watch); + } + + if ( p[1].revents & POLLIN ) + handle_event(); + + poll(p, 2, -1); } =20 close_all(); diff --git a/tools/xen-9pfsd/xen-9pfsd.h b/tools/xen-9pfsd/xen-9pfsd.h new file mode 100644 index 0000000000..432f321d0d --- /dev/null +++ b/tools/xen-9pfsd/xen-9pfsd.h @@ -0,0 +1,60 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#ifndef XEN_9PFSD_H +#define XEN_9PFSD_H + +#include +#include +#include +#include +#include +#include +#include + +#define MAX_RINGS 4 +#define MAX_RING_ORDER 9 +#define MAX_OPEN_FILES_DEFAULT 5 + +typedef struct device device; + +struct ring { + device *device; + pthread_t thread; + bool thread_active; + bool stop_thread; + pthread_cond_t cond; + pthread_mutex_t mutex; + + evtchn_port_t evtchn; + struct xen_9pfs_data_intf *intf; + unsigned int ring_order; + RING_IDX ring_size; + struct xen_9pfs_data data; +}; + +struct device { + /* Admin data. */ + XEN_TAILQ_ENTRY(device) list; + unsigned int last_seen; /* Set in scan_backend(). */ + unsigned int domid; + unsigned int devid; + + /* Tool side configuration data. */ + char *host_path; + unsigned int max_space; + unsigned int max_files; + unsigned int max_open_files; + bool auto_delete; + + /* Connection data. */ + enum xenbus_state backend_state; + enum xenbus_state frontend_state; + unsigned int num_rings; + struct ring *ring[MAX_RINGS]; +}; + +extern xenevtchn_handle *xe; + +void *io_thread(void *arg); + +#endif /* XEN_9PFSD_H */ --=20 2.35.3 From nobody Thu May 16 01:45:44 2024 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=1699632545; cv=none; d=zohomail.com; s=zohoarc; b=XBemIIABrJrJtVJ7nTZxDrs3mIwfC9Zlla7HveBA5241Vmtx0ysnCExPa7YqIYhAUy3guFyO3+fgGkcv8/fcd3n5H8aEpCScK50N9fQ/LTrixT5M956h6UZYUlo09p7P5Ji/4t5VFgCfYwLQ5PDB6kDkrgK7RXai8rJrdwf7ofU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1699632545; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=8LEAVDIRj4dc7c1ZNOEz/ljD8n08+X/zewMO8NL1MKE=; b=dlPBpmx8H39hzS6lJttXLaopoBDUDYaHEsRs1USLJPekuU7Z+JoQrZYP2o0qFKuEecLtS9BdslV1WXytrmkJESWJIVeQPkz0eMl0unpSG9zNR+mCgF0OJFhZg2GnRzuzMc4iuov+QPsGF1y3dFsyeIdCOxzdUeSNT15/4wlrymc= 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 1699632545217685.956613210176; Fri, 10 Nov 2023 08:09:05 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.630468.983330 (Exim 4.92) (envelope-from ) id 1r1U3c-0005Jm-Di; Fri, 10 Nov 2023 16:08:32 +0000 Received: by outflank-mailman (output) from mailman id 630468.983330; Fri, 10 Nov 2023 16:08:32 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1r1U3c-0005Jd-Al; Fri, 10 Nov 2023 16:08:32 +0000 Received: by outflank-mailman (input) for mailman id 630468; Fri, 10 Nov 2023 16:08:31 +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 1r1U3b-0004cS-Bc for xen-devel@lists.xenproject.org; Fri, 10 Nov 2023 16:08:31 +0000 Received: from smtp-out1.suse.de (smtp-out1.suse.de [2001:67c:2178:6::1c]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 63409075-7fe3-11ee-9b0e-b553b5be7939; Fri, 10 Nov 2023 17:08:29 +0100 (CET) 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-out1.suse.de (Postfix) with ESMTPS id 5C6432187C; Fri, 10 Nov 2023 16:08:29 +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 36A1A13398; Fri, 10 Nov 2023 16:08:29 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id GsjgC31VTmWHCAAAMHmgww (envelope-from ); Fri, 10 Nov 2023 16:08:29 +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: 63409075-7fe3-11ee-9b0e-b553b5be7939 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1699632509; 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=8LEAVDIRj4dc7c1ZNOEz/ljD8n08+X/zewMO8NL1MKE=; b=avO07QTMvYah2jhfMuq9fGB0fxdz6dSkbFavEn+u00ueRUl4NXqHkocf/nxdqG6sucC3kH nYaTTbDIEKpNC0mRFLRxygPRHf1SNf8AkcUUT7GAkMZ4QtS6D6nHnv6Cj9asMKpHNO+x92 QTksY3Ok9H1dFJTRSk0T4pRSpbTkvpc= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Anthony PERARD Subject: [PATCH v2 04/29] tools/xenlogd: add transport layer Date: Fri, 10 Nov 2023 17:07:39 +0100 Message-Id: <20231110160804.29021-5-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20231110160804.29021-1-jgross@suse.com> References: <20231110160804.29021-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1699632545861100008 Content-Type: text/plain; charset="utf-8" Add the transport layer of 9pfs. This is basically the infrastructure to receive requests from the frontend and to send the related answers via the rings. In order to avoid unaligned accesses e.g. on Arm, add the definition of __packed to the common-macros.h header. Signed-off-by: Juergen Gross Reviewed-by: Jason Andryuk --- V2: - rename put_request_bytes() (Jason Andryuk) - rename get_request_bytes() and put_response_bytes() len parameter (Jason Andryuk) - don't unmask event channel if error indicator is set (Jason Andryuk) --- tools/include/xen-tools/common-macros.h | 4 + tools/xen-9pfsd/io.c | 143 +++++++++++++++++++++++- tools/xen-9pfsd/xen-9pfsd.h | 16 +++ 3 files changed, 160 insertions(+), 3 deletions(-) diff --git a/tools/include/xen-tools/common-macros.h b/tools/include/xen-to= ols/common-macros.h index e5ed603904..c3fd7d2a30 100644 --- a/tools/include/xen-tools/common-macros.h +++ b/tools/include/xen-tools/common-macros.h @@ -79,6 +79,10 @@ #define __must_check __attribute__((__warn_unused_result__)) #endif =20 +#ifndef __packed +#define __packed __attribute__((__packed__)) +#endif + #define container_of(ptr, type, member) ({ \ typeof(((type *)0)->member) *mptr__ =3D (ptr); \ (type *)((char *)mptr__ - offsetof(type, member)); \ diff --git a/tools/xen-9pfsd/io.c b/tools/xen-9pfsd/io.c index e1e37970f4..d9aa081bea 100644 --- a/tools/xen-9pfsd/io.c +++ b/tools/xen-9pfsd/io.c @@ -6,39 +6,176 @@ * Copyright (C) 2023 Juergen Gross * * I/O thread handling. + * + * Only handle one request at a time, pushing out the complete response + * before looking for the next request. */ =20 #include +#include #include #include +#include /* For cpu barriers. */ +#include =20 #include "xen-9pfsd.h" =20 +/* + * Note that the ring names "in" and "out" are from the frontend's + * perspective, so the "in" ring will be used for responses to the fronten= d, + * while the "out" ring is used for requests from the frontend to the + * backend. + */ +static unsigned int ring_in_free(struct ring *ring) +{ + unsigned int queued; + + queued =3D xen_9pfs_queued(ring->prod_pvt_in, ring->intf->in_cons, + ring->ring_size); + xen_rmb(); + + return ring->ring_size - queued; +} + +static unsigned int ring_out_data(struct ring *ring) +{ + unsigned int queued; + + queued =3D xen_9pfs_queued(ring->intf->out_prod, ring->cons_pvt_out, + ring->ring_size); + xen_rmb(); + + return queued; +} + +static unsigned int get_request_bytes(struct ring *ring, unsigned int off, + unsigned int total_len) +{ + unsigned int size; + unsigned int out_data =3D ring_out_data(ring); + RING_IDX prod, cons; + + size =3D min(total_len - off, out_data); + prod =3D xen_9pfs_mask(ring->intf->out_prod, ring->ring_size); + cons =3D xen_9pfs_mask(ring->cons_pvt_out, ring->ring_size); + xen_9pfs_read_packet(ring->buffer + off, ring->data.out, size, + prod, &cons, ring->ring_size); + + xen_rmb(); /* Read data out before setting visible consumer.= */ + ring->cons_pvt_out +=3D size; + ring->intf->out_cons =3D ring->cons_pvt_out; + + /* Signal that more space is available now. */ + xenevtchn_notify(xe, ring->evtchn); + + return size; +} + +static unsigned int put_response_bytes(struct ring *ring, unsigned int off, + unsigned int total_len) +{ + unsigned int size; + unsigned int in_data =3D ring_in_free(ring); + RING_IDX prod, cons; + + size =3D min(total_len - off, in_data); + prod =3D xen_9pfs_mask(ring->prod_pvt_in, ring->ring_size); + cons =3D xen_9pfs_mask(ring->intf->in_cons, ring->ring_size); + xen_9pfs_write_packet(ring->data.in, ring->buffer + off, size, + &prod, cons, ring->ring_size); + + xen_wmb(); /* Write data out before setting visible producer= . */ + ring->prod_pvt_in +=3D size; + ring->intf->in_prod =3D ring->prod_pvt_in; + + return size; +} + static bool io_work_pending(struct ring *ring) { if ( ring->stop_thread ) return true; - return false; + if ( ring->error ) + return false; + return ring->handle_response ? ring_in_free(ring) : ring_out_data(ring= ); } =20 void *io_thread(void *arg) { struct ring *ring =3D arg; + unsigned int count =3D 0; + struct p9_header hdr; + bool in_hdr =3D true; + + ring->max_size =3D ring->ring_size; + ring->buffer =3D malloc(ring->max_size); + if ( !ring->buffer ) + { + syslog(LOG_CRIT, "memory allocation failure!"); + return NULL; + } =20 while ( !ring->stop_thread ) { pthread_mutex_lock(&ring->mutex); if ( !io_work_pending(ring) ) { - if ( xenevtchn_unmask(xe, ring->evtchn) < 0 ) + if ( !ring->error && xenevtchn_unmask(xe, ring->evtchn) < 0 ) syslog(LOG_WARNING, "xenevtchn_unmask() failed"); pthread_cond_wait(&ring->cond, &ring->mutex); } pthread_mutex_unlock(&ring->mutex); =20 - /* TODO: I/O handling. */ + if ( ring->stop_thread || ring->error ) + continue; + + if ( !ring->handle_response ) + { + if ( in_hdr ) + { + count +=3D get_request_bytes(ring, count, sizeof(hdr)); + if ( count !=3D sizeof(hdr) ) + continue; + hdr =3D *(struct p9_header *)ring->buffer; + if ( hdr.size > ring->max_size || hdr.size < sizeof(hdr) ) + { + syslog(LOG_ERR, "%u.%u specified illegal request lengt= h %u", + ring->device->domid, ring->device->devid, hdr.s= ize); + ring->error =3D true; + continue; + } + in_hdr =3D false; + } + + count +=3D get_request_bytes(ring, count, hdr.size); + if ( count < hdr.size ) + continue; + + /* TODO: handle request (will rewrite hdr.size). */ + + ring->handle_response =3D true; + hdr.size =3D ((struct p9_header *)ring->buffer)->size; + count =3D 0; + } + + if ( ring->handle_response ) + { + count +=3D put_response_bytes(ring, count, hdr.size); + + if ( count =3D=3D hdr.size ) + { + /* Signal presence of response. */ + xenevtchn_notify(xe, ring->evtchn); + + ring->handle_response =3D false; + in_hdr =3D true; + count =3D 0; + } + } } =20 + free(ring->buffer); + ring->thread_active =3D false; =20 return NULL; diff --git a/tools/xen-9pfsd/xen-9pfsd.h b/tools/xen-9pfsd/xen-9pfsd.h index 432f321d0d..7d6921f164 100644 --- a/tools/xen-9pfsd/xen-9pfsd.h +++ b/tools/xen-9pfsd/xen-9pfsd.h @@ -15,6 +15,12 @@ #define MAX_RING_ORDER 9 #define MAX_OPEN_FILES_DEFAULT 5 =20 +struct p9_header { + uint32_t size; + uint8_t cmd; + uint16_t tag; +} __attribute__((packed)); + typedef struct device device; =20 struct ring { @@ -29,7 +35,17 @@ struct ring { struct xen_9pfs_data_intf *intf; unsigned int ring_order; RING_IDX ring_size; + + /* Transport layer data. */ struct xen_9pfs_data data; + RING_IDX prod_pvt_in; + RING_IDX cons_pvt_out; + + /* Request and response handling. */ + uint32_t max_size; + bool error; /* Protocol error - stop processing. */ + bool handle_response; /* Main loop now handling response. */ + void *buffer; /* Request/response buffer. */ }; =20 struct device { --=20 2.35.3 From nobody Thu May 16 01:45:44 2024 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=1699632558; cv=none; d=zohomail.com; s=zohoarc; b=EfyO7TAmaw5wkMCMTAWRQl8u2PNcjbMFrAJo/g83slaKWUMg0sAnMIxO6nHEMkAYj/F6zpCqGEYfdArXFDYqZGUDQCmb9+KC3rLv8K4erlighVLQ2CQAZKgfehDov4jmNFHU1e0IP59rolMFNsCnD1ZbZPSzcmg6CYGvNTDwVYg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1699632558; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=1e+Cb2aixtcSDjfMsjykwbmXm5R8mm2/99MOt3KBKUc=; b=c1YuSxTYDvhK9FpQfXePOUxPOkRI+igsec6n88/G4F5doT0K/P1V9LouZZSwll9PMWAgLxikQpp6+UtZbAAQQZPHYHWzepu/qiHfX7dh96kQfh4iL0DpcKUYvm+i0/gbDmq/+ky7j3zHY+/AJ3g24NUlNAJt+6lxImUBiFlh01U= 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 1699632558596510.52105362507655; Fri, 10 Nov 2023 08:09:18 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.630469.983340 (Exim 4.92) (envelope-from ) id 1r1U3i-0005hr-LX; Fri, 10 Nov 2023 16:08:38 +0000 Received: by outflank-mailman (output) from mailman id 630469.983340; Fri, 10 Nov 2023 16:08:38 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1r1U3i-0005hc-IK; Fri, 10 Nov 2023 16:08:38 +0000 Received: by outflank-mailman (input) for mailman id 630469; Fri, 10 Nov 2023 16:08:37 +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 1r1U3g-0004cS-Vb for xen-devel@lists.xenproject.org; Fri, 10 Nov 2023 16:08:36 +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 669bc161-7fe3-11ee-9b0e-b553b5be7939; Fri, 10 Nov 2023 17:08:35 +0100 (CET) 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 039351F8BD; Fri, 10 Nov 2023 16:08:35 +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 D050613398; Fri, 10 Nov 2023 16:08:34 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id +AKPMYJVTmWSCAAAMHmgww (envelope-from ); Fri, 10 Nov 2023 16:08:34 +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: 669bc161-7fe3-11ee-9b0e-b553b5be7939 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1699632515; 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=1e+Cb2aixtcSDjfMsjykwbmXm5R8mm2/99MOt3KBKUc=; b=k4koCgMcA/+zhj3ojDwqYRe6rZ2m7SLZe9Yc02seI7cGDTyVOXrLp3JRTIsQTE/0MwVkxy lPxmiT54F+Xp2dzH6xKqAtf5AANckF9p+Iv20iEPsJO84O0dT18pObDIGzB/cgnGnZjKpT zcdtNSQ/ZIhjElPmrFQ885I77rOsAlg= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Anthony PERARD Subject: [PATCH v2 05/29] tools/xenlogd: add 9pfs response generation support Date: Fri, 10 Nov 2023 17:07:40 +0100 Message-Id: <20231110160804.29021-6-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20231110160804.29021-1-jgross@suse.com> References: <20231110160804.29021-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1699632560386100003 Content-Type: text/plain; charset="utf-8" Add support for generation a 9pfs protocol response via a format based approach. Strings are stored in a per device string buffer and they are referenced via their offset in this buffer. This allows to avoid having to dynamically allocate memory for each single string. As a first user of the response handling add a generic p9_error() function which will be used to return any error to the client. Add all format parsing variants in order to avoid additional code churn later when adding the users of those variants. Prepare a special case for the "read" case already (format character 'D'): in order to avoid adding another buffer for read data support doing the read I/O directly into the response buffer. Signed-off-by: Juergen Gross Reviewed-by: Jason Andryuk --- V2: - check parameter size limits (Jason Andryuk) --- tools/xen-9pfsd/io.c | 199 +++++++++++++++++++++++++++++++++++- tools/xen-9pfsd/xen-9pfsd.h | 3 + 2 files changed, 201 insertions(+), 1 deletion(-) diff --git a/tools/xen-9pfsd/io.c b/tools/xen-9pfsd/io.c index d9aa081bea..a64199c9de 100644 --- a/tools/xen-9pfsd/io.c +++ b/tools/xen-9pfsd/io.c @@ -11,6 +11,7 @@ * before looking for the next request. */ =20 +#include #include #include #include @@ -20,6 +21,16 @@ =20 #include "xen-9pfsd.h" =20 +/* P9 protocol commands (response is either cmd+1 or P9_CMD_ERROR). */ +#define P9_CMD_ERROR 107 + +struct p9_qid { + uint8_t type; +#define QID_TYPE_DIR 0x80 + uint32_t version; + uint64_t path; +}; + /* * Note that the ring names "in" and "out" are from the frontend's * perspective, so the "in" ring will be used for responses to the fronten= d, @@ -100,6 +111,182 @@ static bool io_work_pending(struct ring *ring) return ring->handle_response ? ring_in_free(ring) : ring_out_data(ring= ); } =20 +static void fmt_err(const char *fmt) +{ + syslog(LOG_CRIT, "illegal format %s passed to fill_buffer()", fmt); + exit(1); +} + +/* + * Fill buffer with response data. + * fmt is a sequence of format characters. Supported characters are: + * a: an array (2 bytes number of elements + the following format as eleme= nts) + * The number of elements is passed in the first unsigned int parameter= , the + * next parameter is a pointer to an array of elements as denoted by th= e next + * format character. + * b: 2 byte unsigned integer + * The parameter is a pointer to a uint16_t value + * D: Data blob (4 byte length + bytes) + * 2 parameters are consumed, first an unsigned int for the length, the= n a + * pointer to the first uint8_t value. + * No array support. + * L: 8 byte unsigned integer + * The parameter is a pointer to a uint64_t value + * Q: Qid (struct p9_qid) + * S: String (2 byte length + characters) + * The length is obtained via strlen() of the parameter, being a pointer + * to the first character of the string + * U: 4 byte unsigned integer + * The parameter is a pointer to a uint32_t value + */ +static void fill_buffer(struct ring *ring, uint8_t cmd, uint16_t tag, + const char *fmt, ...) +{ + struct p9_header *hdr =3D ring->buffer; + void *data =3D hdr + 1; + const char *f; + const void *par; + const char *str_val; + const struct p9_qid *qid; + unsigned int len; + va_list ap; + unsigned int array_sz =3D 0; + unsigned int elem_sz =3D 0; + + hdr->cmd =3D cmd; + hdr->tag =3D tag; + + va_start(ap, fmt); + + for ( f =3D fmt; *f; f++ ) + { + if ( !array_sz ) + par =3D va_arg(ap, const void *); + else + { + par +=3D elem_sz; + array_sz--; + } + + switch ( *f ) + { + case 'a': + f++; + if ( !*f || array_sz ) + fmt_err(fmt); + array_sz =3D *(const unsigned int *)par; + if ( array_sz > 0xffff ) + { + syslog(LOG_CRIT, "array size %u in fill_buffer()", array_s= z); + exit(1); + } + *(__packed uint16_t *)data =3D array_sz; + data +=3D sizeof(uint16_t); + par =3D va_arg(ap, const void *); + elem_sz =3D 0; + break; + + case 'u': + *(__packed uint16_t *)data =3D *(const uint16_t *)par; + elem_sz =3D sizeof(uint16_t); + data +=3D sizeof(uint16_t); + break; + + case 'D': + if ( array_sz ) + fmt_err(fmt); + len =3D *(const unsigned int *)par; + *(__packed uint32_t *)data =3D len; + data +=3D sizeof(uint32_t); + par =3D va_arg(ap, const void *); + if ( data !=3D par ) + memcpy(data, par, len); + data +=3D len; + break; + + case 'L': + *(__packed uint64_t *)data =3D *(const uint64_t *)par; + elem_sz =3D sizeof(uint64_t); + data +=3D sizeof(uint64_t); + break; + + case 'Q': + qid =3D par; + elem_sz =3D sizeof(*qid); + *(uint8_t *)data =3D qid->type; + data +=3D sizeof(uint8_t); + *(__packed uint32_t *)data =3D qid->version; + data +=3D sizeof(uint32_t); + *(__packed uint64_t *)data =3D qid->path; + data +=3D sizeof(uint64_t); + break; + + case 'S': + str_val =3D par; + elem_sz =3D sizeof(str_val); + len =3D strlen(str_val); + if ( len > 0xffff ) + { + syslog(LOG_CRIT, "string length %u in fill_buffer()", len); + exit(1); + } + *(__packed uint16_t *)data =3D len; + data +=3D sizeof(uint16_t); + memcpy(data, str_val, len); + data +=3D len; + break; + + case 'U': + *(__packed uint32_t *)data =3D *(const uint32_t *)par; + elem_sz =3D sizeof(uint32_t); + data +=3D sizeof(uint32_t); + break; + + default: + fmt_err(fmt); + } + + if ( array_sz ) + f--; + } + + hdr->size =3D data - ring->buffer; +} + +static unsigned int add_string(struct ring *ring, const char *str, + unsigned int len) +{ + char *tmp; + unsigned int ret; + + if ( ring->str_used + len + 1 > ring->str_size ) + { + tmp =3D realloc(ring->str, ring->str_used + len + 1); + if ( !tmp ) + return ~0; + ring->str =3D tmp; + ring->str_size =3D ring->str_used + len + 1; + } + + ret =3D ring->str_used; + memcpy(ring->str + ret, str, len); + ring->str_used +=3D len; + ring->str[ring->str_used++] =3D 0; + + return ret; +} + +static void p9_error(struct ring *ring, uint16_t tag, uint32_t err) +{ + unsigned int erroff; + + strerror_r(err, ring->buffer, ring->ring_size); + erroff =3D add_string(ring, ring->buffer, strlen(ring->buffer)); + fill_buffer(ring, P9_CMD_ERROR, tag, "SU", + erroff !=3D ~0 ? ring->str + erroff : "cannot allocate mem= ory", + &err); +} + void *io_thread(void *arg) { struct ring *ring =3D arg; @@ -151,7 +338,16 @@ void *io_thread(void *arg) if ( count < hdr.size ) continue; =20 - /* TODO: handle request (will rewrite hdr.size). */ + ring->str_used =3D 0; + + switch ( hdr.cmd ) + { + default: + syslog(LOG_DEBUG, "%u.%u sent unhandled command %u\n", + ring->device->domid, ring->device->devid, hdr.cmd); + p9_error(ring, hdr.tag, EOPNOTSUPP); + break; + } =20 ring->handle_response =3D true; hdr.size =3D ((struct p9_header *)ring->buffer)->size; @@ -174,6 +370,7 @@ void *io_thread(void *arg) } } =20 + free(ring->str); free(ring->buffer); =20 ring->thread_active =3D false; diff --git a/tools/xen-9pfsd/xen-9pfsd.h b/tools/xen-9pfsd/xen-9pfsd.h index 7d6921f164..5ff87ca5bd 100644 --- a/tools/xen-9pfsd/xen-9pfsd.h +++ b/tools/xen-9pfsd/xen-9pfsd.h @@ -46,6 +46,9 @@ struct ring { bool error; /* Protocol error - stop processing. */ bool handle_response; /* Main loop now handling response. */ void *buffer; /* Request/response buffer. */ + char *str; /* String work space. */ + unsigned int str_size; /* Size of *str. */ + unsigned int str_used; /* Currently used size of *str. */ }; =20 struct device { --=20 2.35.3 From nobody Thu May 16 01:45:44 2024 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=1699632559; cv=none; d=zohomail.com; s=zohoarc; b=h/Z8xrhKgg3yL5NRDo/fs/k6I0Xpu4vC3ZX6imvLSfpWr4tzp85R5HoxmzroPkXMJpQRJ/CxKklN5yI+i/LMz2hdiUgcikkxvwJQNp98g0UF08W1AgHT7A4Q7kKnDjNbjWX/fMl4EgX9WZZR1+6TmVPdWWg7mLaVe4wUPVkjT4Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1699632559; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=tooUvz6FSGb8K06sOpKXRnrRbkqffRx97szMMei45Hw=; b=BoKNUO/3aCiWNFWeY5Aci+LLuOuXHZKkQ2GB1aHVQCj5jo66573ASsmEW3Jm7ajTAzX06votPvlUcD5h+9lISIECfakxg0j3SCtvbjgCMGnUJ5F1C0dTvKMeXJyoUrUoJ8OZEVsZY4vtWKUZ0MethCgSOxrCjsn7MorG4f+Fid4= 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 1699632559398379.5009304127881; Fri, 10 Nov 2023 08:09:19 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.630470.983349 (Exim 4.92) (envelope-from ) id 1r1U3n-00066g-TS; Fri, 10 Nov 2023 16:08:43 +0000 Received: by outflank-mailman (output) from mailman id 630470.983349; Fri, 10 Nov 2023 16:08:43 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1r1U3n-00066U-QC; Fri, 10 Nov 2023 16:08:43 +0000 Received: by outflank-mailman (input) for mailman id 630470; Fri, 10 Nov 2023 16:08:42 +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 1r1U3m-0004cS-NU for xen-devel@lists.xenproject.org; Fri, 10 Nov 2023 16:08:42 +0000 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 69fcd54a-7fe3-11ee-9b0e-b553b5be7939; Fri, 10 Nov 2023 17:08:40 +0100 (CET) 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-out1.suse.de (Postfix) with ESMTPS id A5A642187C; Fri, 10 Nov 2023 16:08:40 +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 7E56313398; Fri, 10 Nov 2023 16:08:40 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id TzSmHYhVTmWcCAAAMHmgww (envelope-from ); Fri, 10 Nov 2023 16:08:40 +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: 69fcd54a-7fe3-11ee-9b0e-b553b5be7939 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1699632520; 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=tooUvz6FSGb8K06sOpKXRnrRbkqffRx97szMMei45Hw=; b=tlA6p9t0nSccOSbLTO1kBgNwYEhf7tr2LWfp19PpywVRZtrYcoxjVLHClDng+TR5AZ0GwF oU/67O/XZ3hmx3D9vtOkAOGM608YPfTSnrdJ5ltNtBEzZOJi2JbbGQ2k5ZnH8PUJLYdMvJ d8VcQNxaHlDufltVxLdyE4UymsV7X8k= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Anthony PERARD , Jason Andryuk Subject: [PATCH v2 06/29] tools/xenlogd: add 9pfs version request support Date: Fri, 10 Nov 2023 17:07:41 +0100 Message-Id: <20231110160804.29021-7-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20231110160804.29021-1-jgross@suse.com> References: <20231110160804.29021-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1699632559953100001 Content-Type: text/plain; charset="utf-8" Add the version request of the 9pfs protocol. For the version use the "9P2000.u" variant, as it is supported by Mini-OS and Linux. For the request parsing add all format items needed even in future in order to avoid code churn for those additions later. Signed-off-by: Juergen Gross Reviewed-by: Jason Andryuk --- tools/xen-9pfsd/io.c | 201 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 201 insertions(+) diff --git a/tools/xen-9pfsd/io.c b/tools/xen-9pfsd/io.c index a64199c9de..18f81319b4 100644 --- a/tools/xen-9pfsd/io.c +++ b/tools/xen-9pfsd/io.c @@ -22,8 +22,12 @@ #include "xen-9pfsd.h" =20 /* P9 protocol commands (response is either cmd+1 or P9_CMD_ERROR). */ +#define P9_CMD_VERSION 100 #define P9_CMD_ERROR 107 =20 +#define P9_MIN_MSIZE 2048 +#define P9_VERSION "9P2000.u" + struct p9_qid { uint8_t type; #define QID_TYPE_DIR 0x80 @@ -276,6 +280,169 @@ static unsigned int add_string(struct ring *ring, con= st char *str, return ret; } =20 +static bool chk_data(struct ring *ring, void *data, unsigned int len) +{ + struct p9_header *hdr =3D ring->buffer; + + if ( data + len <=3D ring->buffer + hdr->size ) + return true; + + errno =3D E2BIG; + + return false; +} + +static bool fill_data_elem(void **par, void **array, unsigned int *array_s= z, + unsigned int elem_sz, void *data) +{ + if ( *array_sz && !*array ) + { + *array =3D calloc(*array_sz, elem_sz); + if ( !*array ) + return false; + *par =3D *array; + } + + memcpy(*par, data, elem_sz); + + if ( *array_sz ) + { + *par +=3D elem_sz; + *array_sz -=3D 1; + } + + return true; +} + +/* + * Fill variables with request data. + * fmt is a sequence of format characters. Supported characters are: + * a: an array (2 bytes number of elements + the following format as eleme= nts) + * The number of elements is stored in the first unsigned int parameter= , the + * next parameter is a pointer to an array of elements as denoted by th= e next + * format character. The array is allocated dynamically. + * b: 1 byte unsigned integer + * The value is stored in the next parameter with type uint8_t. + * D: Data blob (4 byte length + bytes) + * 2 parameters are consumed, first an unsigned int for the length, the= n a + * pointer to the first uint8_t value. + * No array support. + * L: 8 byte unsigned integer + * The value is stored in the next parameter with type uint64_t. + * S: String (2 byte length + characters) + * The 0-terminated string is stored in device->str + off, off is store= d in + * the next parameter with type unsigned int. + * U: 4 byte unsigned integer + * The value is stored in the next parameter with type uint32_t. + * + * Return value: number of filled variables, errno will be set in case of + * error. + */ +static int fill_data(struct ring *ring, const char *fmt, ...) +{ + struct p9_header *hdr =3D ring->buffer; + void *data =3D hdr + 1; + void *par; + unsigned int pars =3D 0; + const char *f; + va_list ap; + unsigned int len; + unsigned int str_off; + unsigned int array_sz =3D 0; + void **array =3D NULL; + + va_start(ap, fmt); + + for ( f =3D fmt; *f; f++ ) + { + if ( !array_sz ) + par =3D va_arg(ap, void *); + + switch ( *f ) + { + case 'a': + f++; + if ( !*f || array_sz ) + fmt_err(fmt); + if ( !chk_data(ring, data, sizeof(uint16_t)) ) + return pars; + array_sz =3D *(__packed uint16_t *)data; + data +=3D sizeof(uint16_t); + *(unsigned int *)par =3D array_sz; + array =3D va_arg(ap, void **); + *array =3D NULL; + break; + + case 'b': + if ( !chk_data(ring, data, sizeof(uint8_t)) ) + return pars; + if ( !fill_data_elem(&par, array, &array_sz, sizeof(uint8_t), + data) ) + return pars; + data +=3D sizeof(uint8_t); + break; + + case 'D': + if ( array_sz ) + fmt_err(fmt); + if ( !chk_data(ring, data, sizeof(uint32_t)) ) + return pars; + len =3D *(__packed uint32_t *)data; + data +=3D sizeof(uint32_t); + *(unsigned int *)par =3D len; + par =3D va_arg(ap, void *); + if ( !chk_data(ring, data, len) ) + return pars; + memcpy(par, data, len); + data +=3D len; + break; + + case 'L': + if ( !chk_data(ring, data, sizeof(uint64_t)) ) + return pars; + if ( !fill_data_elem(&par, array, &array_sz, sizeof(uint64_t), + data) ) + return pars; + data +=3D sizeof(uint64_t); + break; + + case 'S': + if ( !chk_data(ring, data, sizeof(uint16_t)) ) + return pars; + len =3D *(__packed uint16_t *)data; + data +=3D sizeof(uint16_t); + if ( !chk_data(ring, data, len) ) + return pars; + str_off =3D add_string(ring, data, len); + if ( str_off =3D=3D ~0 ) + return pars; + if ( !fill_data_elem(&par, array, &array_sz, sizeof(unsigned i= nt), + &str_off) ) + return pars; + data +=3D len; + break; + + case 'U': + if ( !chk_data(ring, data, sizeof(uint32_t)) ) + return pars; + if ( !fill_data_elem(&par, array, &array_sz, sizeof(uint32_t), + data) ) + return pars; + data +=3D sizeof(uint32_t); + break; + + default: + fmt_err(fmt); + } + + if ( array_sz ) + f--; + pars++; + } + + return pars; +} + static void p9_error(struct ring *ring, uint16_t tag, uint32_t err) { unsigned int erroff; @@ -287,6 +454,36 @@ static void p9_error(struct ring *ring, uint16_t tag, = uint32_t err) &err); } =20 +static void p9_version(struct ring *ring, struct p9_header *hdr) +{ + uint32_t max_size; + unsigned int off; + char *version; + int ret; + + ret =3D fill_data(ring, "US", &max_size, &off); + if ( ret !=3D 2 ) + { + p9_error(ring, hdr->tag, errno); + return; + } + + if ( max_size < P9_MIN_MSIZE ) + { + p9_error(ring, hdr->tag, EMSGSIZE); + return; + } + + if ( max_size < ring->max_size ) + ring->max_size =3D max_size; + + version =3D ring->str + off; + if ( strcmp(version, P9_VERSION) ) + version =3D "unknown"; + + fill_buffer(ring, hdr->cmd + 1, hdr->tag, "US", &ring->max_size, versi= on); +} + void *io_thread(void *arg) { struct ring *ring =3D arg; @@ -342,6 +539,10 @@ void *io_thread(void *arg) =20 switch ( hdr.cmd ) { + case P9_CMD_VERSION: + p9_version(ring, &hdr); + break; + default: syslog(LOG_DEBUG, "%u.%u sent unhandled command %u\n", ring->device->domid, ring->device->devid, hdr.cmd); --=20 2.35.3 From nobody Thu May 16 01:45:44 2024 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=1699632561; cv=none; d=zohomail.com; s=zohoarc; b=kITeE95jKSYvuhe82mJjxO7YAuDT4UioUyY6ZNo9yt4O6ql1XDYtAbjqDUO15bmdK/tYCYeOxcgWQhGvHIuVJu1TI8VntfKjJX3ObVicOfNDV1JHZjf/dsbPqaBxtWpIhK8sRTqUmNUosaH6UqUU57BS7XfdIY4rvAPzKwB8DUA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1699632561; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=DXMUzNYrgUE7yKY/59/v2Vn6B+SqNKU5mV5KPcdYjpU=; b=bV5+i878FyxbpZ6vYwPCS+zs9e5Ve19jjC4WveAScuE2CEXa4bNzKaPP+itzWztX6UTRLdrL9cMpiswi1eUoML9RausjhT1lft/HCU/tU71xUWDbwXiSeI47oDvcc5iNf4KyEHmcEb80yqoDrDmM2eeiGzVL4w5kzEGWJ6BK7DU= 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 1699632561071402.8410570154367; Fri, 10 Nov 2023 08:09:21 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.630476.983360 (Exim 4.92) (envelope-from ) id 1r1U3t-0006WT-D3; Fri, 10 Nov 2023 16:08:49 +0000 Received: by outflank-mailman (output) from mailman id 630476.983360; Fri, 10 Nov 2023 16:08:49 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1r1U3t-0006WG-9e; Fri, 10 Nov 2023 16:08:49 +0000 Received: by outflank-mailman (input) for mailman id 630476; Fri, 10 Nov 2023 16:08:48 +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 1r1U3s-0004cS-JM for xen-devel@lists.xenproject.org; Fri, 10 Nov 2023 16:08:48 +0000 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 6d4ee1bb-7fe3-11ee-9b0e-b553b5be7939; Fri, 10 Nov 2023 17:08:46 +0100 (CET) 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-out1.suse.de (Postfix) with ESMTPS id 3D5432187C; Fri, 10 Nov 2023 16:08:46 +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 14AF013398; Fri, 10 Nov 2023 16:08:46 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id i96uA45VTmWmCAAAMHmgww (envelope-from ); Fri, 10 Nov 2023 16:08:46 +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: 6d4ee1bb-7fe3-11ee-9b0e-b553b5be7939 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1699632526; 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=DXMUzNYrgUE7yKY/59/v2Vn6B+SqNKU5mV5KPcdYjpU=; b=fqE2QvSzbCJMwaxIhGm0OkBdBxXN6SUXC82ZvxfZaKcwnfbjpOoe0eg8jO/xT6vYkW0EM7 JWOBKwBKgtcBNXHsxu2PtauLhlPTTzHHhRe0//VV7MpMtNpqle12Ib6mqIoaO5lSEueOuQ RQFfe9ClnyuKyvPk47PzZQEPb5vkEXQ= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Anthony PERARD Subject: [PATCH v2 07/29] tools/xenlogd: add 9pfs attach request support Date: Fri, 10 Nov 2023 17:07:42 +0100 Message-Id: <20231110160804.29021-8-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20231110160804.29021-1-jgross@suse.com> References: <20231110160804.29021-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1699632562010100005 Content-Type: text/plain; charset="utf-8" Add the attach request of the 9pfs protocol. This introduces the "fid" scheme of the 9pfs protocol. As this will be needed later, use a dedicated memory allocation function in alloc_fid() and prepare a fid reference count. For filling the qid data take the approach from the qemu 9pfs backend implementation. Signed-off-by: Juergen Gross Reviewed-by: Jason Andryuk --- V2: - make fill_qid() parameter stbuf const (Jason Andryuk) - free fids after disconnecting guest (Jason Andryuk) --- tools/xen-9pfsd/io.c | 155 ++++++++++++++++++++++++++++++++++++ tools/xen-9pfsd/xen-9pfsd.c | 6 ++ tools/xen-9pfsd/xen-9pfsd.h | 14 ++++ 3 files changed, 175 insertions(+) diff --git a/tools/xen-9pfsd/io.c b/tools/xen-9pfsd/io.c index 18f81319b4..03e45d5f8b 100644 --- a/tools/xen-9pfsd/io.c +++ b/tools/xen-9pfsd/io.c @@ -16,6 +16,8 @@ #include #include #include +#include +#include #include /* For cpu barriers. */ #include =20 @@ -23,6 +25,7 @@ =20 /* P9 protocol commands (response is either cmd+1 or P9_CMD_ERROR). */ #define P9_CMD_VERSION 100 +#define P9_CMD_ATTACH 104 #define P9_CMD_ERROR 107 =20 #define P9_MIN_MSIZE 2048 @@ -443,6 +446,118 @@ static int fill_data(struct ring *ring, const char *f= mt, ...) return pars; } =20 +static struct p9_fid *find_fid(device *device, unsigned int fid) +{ + struct p9_fid *fidp; + + XEN_TAILQ_FOREACH(fidp, &device->fids, list) + { + if ( fidp->fid =3D=3D fid ) + return fidp; + } + + return NULL; +} + +static struct p9_fid *alloc_fid_mem(device *device, unsigned int fid, + const char *path) +{ + struct p9_fid *fidp; + size_t pathlen; + + pathlen =3D strlen(device->host_path) + strlen(path) + 1; + fidp =3D calloc(sizeof(*fidp) + pathlen, 1); + if ( !fidp ) + return NULL; + + fidp->fid =3D fid; + snprintf(fidp->path, pathlen, "%s%s", device->host_path, path); + + return fidp; +} + +static struct p9_fid *alloc_fid(device *device, unsigned int fid, + const char *path) +{ + struct p9_fid *fidp =3D NULL; + + pthread_mutex_lock(&device->fid_mutex); + + if ( find_fid(device, fid) ) + { + errno =3D EBADFD; + goto out; + } + + if ( device->n_fids >=3D device->max_open_files ) + { + errno =3D EMFILE; + goto out; + } + + fidp =3D alloc_fid_mem(device, fid, path); + if ( !fidp ) + goto out; + + fidp->ref =3D 1; + XEN_TAILQ_INSERT_HEAD(&device->fids, fidp, list); + device->n_fids++; + + out: + pthread_mutex_unlock(&device->fid_mutex); + + return fidp; +} + +static void free_fid(device *device, struct p9_fid *fidp) +{ + if ( !fidp ) + return; + + pthread_mutex_lock(&device->fid_mutex); + + fidp->ref--; + if ( !fidp->ref ) + { + device->n_fids--; + XEN_TAILQ_REMOVE(&device->fids, fidp, list); + free(fidp); + } + + pthread_mutex_unlock(&device->fid_mutex); +} + +void free_fids(device *device) +{ + struct p9_fid *fidp; + + while ( (fidp =3D XEN_TAILQ_FIRST(&device->fids)) !=3D NULL ) + { + XEN_TAILQ_REMOVE(&device->fids, fidp, list); + free(fidp); + } +} + +static int fill_qid(const char *path, struct p9_qid *qid, + const struct stat *stbuf) +{ + struct stat st; + + if ( !stbuf ) + { + if ( stat(path, &st) ) + return errno; + + stbuf =3D &st; + } + + qid->type =3D S_ISDIR(stbuf->st_mode) ? QID_TYPE_DIR : 0; + qid->version =3D stbuf->st_mtime ^ (stbuf->st_size << 8); + qid->path =3D stbuf->st_ino; + + return 0; +} + static void p9_error(struct ring *ring, uint16_t tag, uint32_t err) { unsigned int erroff; @@ -484,6 +599,42 @@ static void p9_version(struct ring *ring, struct p9_he= ader *hdr) fill_buffer(ring, hdr->cmd + 1, hdr->tag, "US", &ring->max_size, versi= on); } =20 +static void p9_attach(struct ring *ring, struct p9_header *hdr) +{ + device *device =3D ring->device; + uint32_t fid; + uint32_t dummy_u32; + unsigned int dummy_uint; + struct p9_qid qid; + int ret; + + ret =3D fill_data(ring, "UUSSU", &fid, &dummy_u32, &dummy_uint, &dummy= _uint, + &dummy_u32); + if ( ret !=3D 5 ) + { + p9_error(ring, hdr->tag, errno); + return; + } + + device->root_fid =3D alloc_fid(device, fid, ""); + if ( !device->root_fid ) + { + p9_error(ring, hdr->tag, errno); + return; + } + + ret =3D fill_qid(device->host_path, &qid, NULL); + if ( ret ) + { + free_fid(device, device->root_fid); + device->root_fid =3D NULL; + p9_error(ring, hdr->tag, ret); + return; + } + + fill_buffer(ring, hdr->cmd + 1, hdr->tag, "Q", &qid); +} + void *io_thread(void *arg) { struct ring *ring =3D arg; @@ -543,6 +694,10 @@ void *io_thread(void *arg) p9_version(ring, &hdr); break; =20 + case P9_CMD_ATTACH: + p9_attach(ring, &hdr); + break; + default: syslog(LOG_DEBUG, "%u.%u sent unhandled command %u\n", ring->device->domid, ring->device->devid, hdr.cmd); diff --git a/tools/xen-9pfsd/xen-9pfsd.c b/tools/xen-9pfsd/xen-9pfsd.c index cc5734402d..534c0cefa5 100644 --- a/tools/xen-9pfsd/xen-9pfsd.c +++ b/tools/xen-9pfsd/xen-9pfsd.c @@ -278,6 +278,9 @@ static device *new_device(unsigned int domid, unsigned = int devid) return NULL; } =20 + pthread_mutex_init(&device->fid_mutex, NULL); + XEN_TAILQ_INIT(&device->fids); + val =3D read_backend_node(device, "security_model"); if ( !val || strcmp(val, "none") ) { @@ -370,6 +373,8 @@ static void disconnect_guest(device *device) } =20 device->num_rings =3D 0; + + free_fids(device); } =20 static void close_device(device *device, enum xenbus_state state) @@ -454,6 +459,7 @@ static void remove_device(device *device) XEN_TAILQ_REMOVE(&devs, device, list); =20 disconnect_guest(device); + pthread_mutex_destroy(&device->fid_mutex); free_device(device); } =20 diff --git a/tools/xen-9pfsd/xen-9pfsd.h b/tools/xen-9pfsd/xen-9pfsd.h index 5ff87ca5bd..e511acdb76 100644 --- a/tools/xen-9pfsd/xen-9pfsd.h +++ b/tools/xen-9pfsd/xen-9pfsd.h @@ -21,6 +21,13 @@ struct p9_header { uint16_t tag; } __attribute__((packed)); =20 +struct p9_fid { + XEN_TAILQ_ENTRY(struct p9_fid) list; + unsigned int fid; + unsigned int ref; + char path[]; +}; + typedef struct device device; =20 struct ring { @@ -70,10 +77,17 @@ struct device { enum xenbus_state frontend_state; unsigned int num_rings; struct ring *ring[MAX_RINGS]; + + /* File system handling. */ + pthread_mutex_t fid_mutex; + XEN_TAILQ_HEAD(fidhead, struct p9_fid) fids; + struct p9_fid *root_fid; + unsigned int n_fids; }; =20 extern xenevtchn_handle *xe; =20 void *io_thread(void *arg); +void free_fids(device *device); =20 #endif /* XEN_9PFSD_H */ --=20 2.35.3 From nobody Thu May 16 01:45:44 2024 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=1699632561; cv=none; d=zohomail.com; s=zohoarc; b=XTk5h7cSFtsMxNKOUq5YduESl2gbJq3Vvn5MEyn3K+dbAAdYi40iIQ0D5Wz0/u+xJLpJ/Wr483WhOTogdJ4KbKIM5Bw8FegyfddKhGfsBVUy8ymjlFmWG8iutx9T+scQFHxzSx6rYZP6yXyUp9WvB0XKQs4IinENlV3u0+BmOVY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1699632561; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=yCnoHphD4HsPnyqo8Rif8MZ+KRauUhOK16PVIiar+e4=; b=m2Ga+y07EvDytGdSQFZTINGoiHtyvWBeXyK+8yfCRIH6ZQHYf4k7Y8mylXikH+LVaFSm6txs4nSi6Yr2149kKCdypWL7/EnWIJrVdIvdTozkuhLuwfoW8IuEToWE+FGzUML2Ypjk0Atx8ir05awP0iR1h781iO4Jk76OFeFlxyY= 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 1699632561295564.5193959110755; Fri, 10 Nov 2023 08:09:21 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.630478.983370 (Exim 4.92) (envelope-from ) id 1r1U3y-0006ws-N0; Fri, 10 Nov 2023 16:08:54 +0000 Received: by outflank-mailman (output) from mailman id 630478.983370; Fri, 10 Nov 2023 16:08:54 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1r1U3y-0006wj-Ih; Fri, 10 Nov 2023 16:08:54 +0000 Received: by outflank-mailman (input) for mailman id 630478; Fri, 10 Nov 2023 16:08:53 +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 1r1U3x-0004cS-MI for xen-devel@lists.xenproject.org; Fri, 10 Nov 2023 16:08:53 +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 709e9f67-7fe3-11ee-9b0e-b553b5be7939; Fri, 10 Nov 2023 17:08:52 +0100 (CET) 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 C40FB1F8BD; Fri, 10 Nov 2023 16:08:51 +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 9D4C413398; Fri, 10 Nov 2023 16:08:51 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id go4CJZNVTmWtCAAAMHmgww (envelope-from ); Fri, 10 Nov 2023 16:08:51 +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: 709e9f67-7fe3-11ee-9b0e-b553b5be7939 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1699632531; 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=yCnoHphD4HsPnyqo8Rif8MZ+KRauUhOK16PVIiar+e4=; b=j6pAGEZXlSZA9LCZF0PTqGm2Xhn+ZB9R/boeq01bE+rb6Jrmqi0Io1yMbSQzHTSGWBAJ/z 6ib3wsgqol4YKg3u+sJ0rOxCI50Dx7JnRE6tb/qkiMxTWLwYTWO26FB3ih5Dm2qq5n+l96 C8uWMzGYVpT5THx7N+cOZYS5v+ZRW3A= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Anthony PERARD Subject: [PATCH v2 08/29] tools/xenlogd: add 9pfs walk request support Date: Fri, 10 Nov 2023 17:07:43 +0100 Message-Id: <20231110160804.29021-9-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20231110160804.29021-1-jgross@suse.com> References: <20231110160804.29021-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1699632562011100006 Content-Type: text/plain; charset="utf-8" Add the walk request of the 9pfs protocol. Signed-off-by: Juergen Gross Reviewed-by: Jason Andryuk --- V2: - don't allow walking across symbolic links --- tools/xen-9pfsd/io.c | 172 ++++++++++++++++++++++++++++++++++++ tools/xen-9pfsd/xen-9pfsd.h | 1 + 2 files changed, 173 insertions(+) diff --git a/tools/xen-9pfsd/io.c b/tools/xen-9pfsd/io.c index 03e45d5f8b..62c64474e6 100644 --- a/tools/xen-9pfsd/io.c +++ b/tools/xen-9pfsd/io.c @@ -27,9 +27,11 @@ #define P9_CMD_VERSION 100 #define P9_CMD_ATTACH 104 #define P9_CMD_ERROR 107 +#define P9_CMD_WALK 110 =20 #define P9_MIN_MSIZE 2048 #define P9_VERSION "9P2000.u" +#define P9_WALK_MAXELEM 16 =20 struct p9_qid { uint8_t type; @@ -459,6 +461,21 @@ static struct p9_fid *find_fid(device *device, unsigne= d int fid) return NULL; } =20 +static struct p9_fid *get_fid_ref(device *device, unsigned int fid) +{ + struct p9_fid *fidp; + + pthread_mutex_lock(&device->fid_mutex); + + fidp =3D find_fid(device, fid); + if ( fidp ) + fidp->ref++; + + pthread_mutex_unlock(&device->fid_mutex); + + return fidp; +} + static struct p9_fid *alloc_fid_mem(device *device, unsigned int fid, const char *path) { @@ -551,6 +568,10 @@ static int fill_qid(const char *path, struct p9_qid *q= id, stbuf =3D &st; } =20 + /* Don't allow symbolic links. */ + if ( S_ISLNK(stbuf->st_mode) ) + return EMLINK; + qid->type =3D S_ISDIR(stbuf->st_mode) ? QID_TYPE_DIR : 0; qid->version =3D stbuf->st_mtime ^ (stbuf->st_size << 8); qid->path =3D stbuf->st_ino; @@ -558,6 +579,20 @@ static int fill_qid(const char *path, struct p9_qid *q= id, return 0; } =20 +static bool name_ok(const char *str) +{ + if ( !*str ) + return false; + + if ( strchr(str, '/' ) ) + return false; + + if ( !strcmp(str, "..") || !strcmp(str, ".") ) + return false; + + return true; +} + static void p9_error(struct ring *ring, uint16_t tag, uint32_t err) { unsigned int erroff; @@ -635,6 +670,139 @@ static void p9_attach(struct ring *ring, struct p9_he= ader *hdr) fill_buffer(ring, hdr->cmd + 1, hdr->tag, "Q", &qid); } =20 +static void p9_walk(struct ring *ring, struct p9_header *hdr) +{ + device *device =3D ring->device; + uint32_t fid; + uint32_t newfid; + struct p9_fid *fidp =3D NULL; + struct p9_qid *qids =3D NULL; + unsigned int n_names =3D 0; + unsigned int *names =3D NULL; + unsigned int walked =3D 0; + unsigned int i; + char *path =3D NULL; + unsigned int path_len; + int ret; + + ret =3D fill_data(ring, "UUaS", &fid, &newfid, &n_names, &names); + if ( n_names > P9_WALK_MAXELEM ) + { + p9_error(ring, hdr->tag, EINVAL); + goto out; + } + if ( ret !=3D 3 + n_names ) + { + p9_error(ring, hdr->tag, errno); + goto out; + } + + fidp =3D get_fid_ref(device, fid); + if ( !fidp ) + { + p9_error(ring, hdr->tag, ENOENT); + goto out; + } + if ( fidp->opened ) + { + p9_error(ring, hdr->tag, EINVAL); + goto out; + } + + path_len =3D strlen(fidp->path) + 1; + for ( i =3D 0; i < n_names; i++ ) + { + if ( !name_ok(ring->str + names[i]) ) + { + p9_error(ring, hdr->tag, ENOENT); + goto out; + } + path_len +=3D strlen(ring->str + names[i]) + 1; + } + path =3D calloc(path_len + 1, 1); + if ( !path ) + { + p9_error(ring, hdr->tag, ENOMEM); + goto out; + } + strcpy(path, fidp->path); + + if ( n_names ) + { + qids =3D calloc(n_names, sizeof(*qids)); + if ( !qids ) + { + p9_error(ring, hdr->tag, ENOMEM); + goto out; + } + for ( i =3D 0; i < n_names; i++ ) + { + strcat(path, "/"); + strcat(path, ring->str + names[i]); + ret =3D fill_qid(path, qids + i, NULL); + if ( ret ) + { + if ( !walked ) + { + p9_error(ring, hdr->tag, errno); + goto out; + } + break; + } + walked++; + } + } + + if ( walked =3D=3D n_names ) + { + const char *rel_path =3D path + strlen(device->host_path); + bool ok =3D false; + + if ( fid =3D=3D newfid ) + { + struct p9_fid *new_fidp; + + pthread_mutex_lock(&device->fid_mutex); + + if ( fidp->ref !=3D 2 ) + { + errno =3D EBUSY; + } + else + { + new_fidp =3D alloc_fid_mem(device, fid, rel_path); + if ( new_fidp ) + { + new_fidp->ref =3D 2; + XEN_TAILQ_REMOVE(&device->fids, fidp, list); + XEN_TAILQ_INSERT_HEAD(&device->fids, new_fidp, list); + free(fidp); + fidp =3D new_fidp; + ok =3D true; + } + } + + pthread_mutex_unlock(&device->fid_mutex); + } + else + ok =3D alloc_fid(device, newfid, rel_path); + + if ( !ok ) + { + p9_error(ring, hdr->tag, errno); + goto out; + } + } + + fill_buffer(ring, hdr->cmd + 1, hdr->tag, "aQ", &walked, qids); + + out: + free_fid(device, fidp); + free(qids); + free(path); + free(names); +} + void *io_thread(void *arg) { struct ring *ring =3D arg; @@ -698,6 +866,10 @@ void *io_thread(void *arg) p9_attach(ring, &hdr); break; =20 + case P9_CMD_WALK: + p9_walk(ring, &hdr); + break; + default: syslog(LOG_DEBUG, "%u.%u sent unhandled command %u\n", ring->device->domid, ring->device->devid, hdr.cmd); diff --git a/tools/xen-9pfsd/xen-9pfsd.h b/tools/xen-9pfsd/xen-9pfsd.h index e511acdb76..75eaac9f7b 100644 --- a/tools/xen-9pfsd/xen-9pfsd.h +++ b/tools/xen-9pfsd/xen-9pfsd.h @@ -25,6 +25,7 @@ struct p9_fid { XEN_TAILQ_ENTRY(struct p9_fid) list; unsigned int fid; unsigned int ref; + bool opened; char path[]; }; =20 --=20 2.35.3 From nobody Thu May 16 01:45:44 2024 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=1699632573; cv=none; d=zohomail.com; s=zohoarc; b=jxIMifepKwjMi8ZLmJCK1nNS7z2ptRw//nvN22qlxZWIDq55t/gA7QY8TPLQAFqKyotx33xNR3rpyJl2E9J9j7aO14iJ8eavJItGpLO8xTq1BU8OsrzSlPi+3OlH5fntjr98Y0ydtbg1X22kmpQwdeJVoRZipAITAhfkzqBz1kY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1699632573; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=QiUP5xnrschicxXEJivLL6dPJo7q2V//fsn+oEaA+V0=; b=TwDC6KrvXR0xDH0JMQGOtr7hcbCCdw1k4h0zlVIeVjTpV45UkGhDBnK1V34ptF/FoXFQErovRxTRToE8WdIEtYjuGLZ7BkNN7HeuZymccUhbxHIYep0IaF84WkxOXLFCW3FgEMt9SezRRgwSlCleMgkTDG7tkhNz1t0Z8uCalIE= 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 1699632573097961.641300811776; Fri, 10 Nov 2023 08:09:33 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.630480.983380 (Exim 4.92) (envelope-from ) id 1r1U43-0007OZ-Vm; Fri, 10 Nov 2023 16:08:59 +0000 Received: by outflank-mailman (output) from mailman id 630480.983380; Fri, 10 Nov 2023 16:08:59 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1r1U43-0007OM-S4; Fri, 10 Nov 2023 16:08:59 +0000 Received: by outflank-mailman (input) for mailman id 630480; Fri, 10 Nov 2023 16:08:58 +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 1r1U42-00048H-8s for xen-devel@lists.xenproject.org; Fri, 10 Nov 2023 16:08:58 +0000 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 73f78584-7fe3-11ee-98da-6d05b1d4d9a1; Fri, 10 Nov 2023 17:08:57 +0100 (CET) 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-out1.suse.de (Postfix) with ESMTPS id 6C24D2187C; Fri, 10 Nov 2023 16:08:57 +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 4723013398; Fri, 10 Nov 2023 16:08:57 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id qcEZEJlVTmW1CAAAMHmgww (envelope-from ); Fri, 10 Nov 2023 16:08:57 +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: 73f78584-7fe3-11ee-98da-6d05b1d4d9a1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1699632537; 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=QiUP5xnrschicxXEJivLL6dPJo7q2V//fsn+oEaA+V0=; b=girxLdzabNpEHZ/6AXB/Uth9cG9z9CGZ0+wU4RIK3EQSv47y6jU4YNuPXkFp/+jHn8rvt8 Vxjv4p8NKbefIH2YeLWj5EKLkXQJpz65r7B612ZGrEeNafF8bdmN5F3nmMpw3abxf8Opnm njjLB0K/7Z/9lc0EoktviqMlBjhy0AA= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Anthony PERARD Subject: [PATCH v2 09/29] tools/xenlogd: add 9pfs open request support Date: Fri, 10 Nov 2023 17:07:44 +0100 Message-Id: <20231110160804.29021-10-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20231110160804.29021-1-jgross@suse.com> References: <20231110160804.29021-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1699632573946100001 Content-Type: text/plain; charset="utf-8" Add the open request of the 9pfs protocol. Signed-off-by: Juergen Gross Reviewed-by: Jason Andryuk --- V2: - don't allow to open symbolic link --- tools/xen-9pfsd/io.c | 144 ++++++++++++++++++++++++++++++++++++ tools/xen-9pfsd/xen-9pfsd.h | 4 + 2 files changed, 148 insertions(+) diff --git a/tools/xen-9pfsd/io.c b/tools/xen-9pfsd/io.c index 62c64474e6..bb9c78a1f5 100644 --- a/tools/xen-9pfsd/io.c +++ b/tools/xen-9pfsd/io.c @@ -18,6 +18,8 @@ #include #include #include +#include +#include #include /* For cpu barriers. */ #include =20 @@ -28,6 +30,15 @@ #define P9_CMD_ATTACH 104 #define P9_CMD_ERROR 107 #define P9_CMD_WALK 110 +#define P9_CMD_OPEN 112 + +/* P9 protocol open flags. */ +#define P9_OREAD 0 /* read */ +#define P9_OWRITE 1 /* write */ +#define P9_ORDWR 2 /* read and write */ +#define P9_OMODEMASK 0x03 +#define P9_OTRUNC 0x10 /* or'ed in, truncate file first */ +#define P9_OREMOVE 0x40 /* or'ed in, remove file after clunk */ =20 #define P9_MIN_MSIZE 2048 #define P9_VERSION "9P2000.u" @@ -803,6 +814,135 @@ static void p9_walk(struct ring *ring, struct p9_head= er *hdr) free(names); } =20 +static int open_flags_from_mode(uint8_t mode) +{ + int flags; + + switch ( mode & P9_OMODEMASK ) + { + case P9_OREAD: + flags =3D O_RDONLY; + break; + + case P9_OWRITE: + flags =3D O_WRONLY; + break; + + case P9_ORDWR: + flags =3D O_RDWR; + break; + + default: + return -1; + } + + if ( mode & P9_OTRUNC ) + flags |=3D O_TRUNC; + + return flags; +} + +static unsigned int get_iounit(struct ring *ring, struct stat *st) +{ + return (ring->max_size - st->st_blksize) & ~(st->st_blksize - 1); +} + +static void p9_open(struct ring *ring, struct p9_header *hdr) +{ + device *device =3D ring->device; + uint32_t fid; + uint8_t mode; + struct p9_fid *fidp; + struct stat st; + struct p9_qid qid; + uint32_t iounit; + int flags; + int ret; + + ret =3D fill_data(ring, "Ub", &fid, &mode); + if ( ret !=3D 2 ) + { + p9_error(ring, hdr->tag, EINVAL); + return; + } + if ( mode & ~(P9_OMODEMASK | P9_OTRUNC | P9_OREMOVE) ) + { + p9_error(ring, hdr->tag, EINVAL); + return; + } + + fidp =3D get_fid_ref(device, fid); + if ( !fidp ) + { + p9_error(ring, hdr->tag, ENOENT); + return; + } + if ( fidp->opened ) + { + free_fid(device, fidp); + p9_error(ring, hdr->tag, EINVAL); + return; + } + + if ( stat(fidp->path, &st) < 0 ) + { + free_fid(device, fidp); + p9_error(ring, hdr->tag, ENOENT); + return; + } + + if ( S_ISLNK(st.st_mode) ) + { + free_fid(device, fidp); + p9_error(ring, hdr->tag, EMLINK); + return; + } + + fidp->isdir =3D S_ISDIR(st.st_mode); + fidp->mode =3D mode; + if ( fidp->isdir ) + { + if ( mode !=3D P9_OREAD ) + { + free_fid(device, fidp); + p9_error(ring, hdr->tag, EINVAL); + return; + } + fidp->data =3D opendir(fidp->path); + if ( !fidp->data ) + { + free_fid(device, fidp); + p9_error(ring, hdr->tag, errno); + return; + } + fidp->fd =3D dirfd(fidp->data); + } + else + { + flags =3D open_flags_from_mode(mode); + if ( flags < 0 ) + { + free_fid(device, fidp); + p9_error(ring, hdr->tag, EINVAL); + return; + } + + fidp->fd =3D open(fidp->path, flags); + if ( fidp->fd < 0 ) + { + free_fid(device, fidp); + p9_error(ring, hdr->tag, errno); + return; + } + } + + fill_qid(fidp->path, &qid, &st); + iounit =3D get_iounit(ring, &st); + fidp->opened =3D true; + + fill_buffer(ring, hdr->cmd + 1, hdr->tag, "QU", &qid, &iounit); +} + void *io_thread(void *arg) { struct ring *ring =3D arg; @@ -870,6 +1010,10 @@ void *io_thread(void *arg) p9_walk(ring, &hdr); break; =20 + case P9_CMD_OPEN: + p9_open(ring, &hdr); + break; + default: syslog(LOG_DEBUG, "%u.%u sent unhandled command %u\n", ring->device->domid, ring->device->devid, hdr.cmd); diff --git a/tools/xen-9pfsd/xen-9pfsd.h b/tools/xen-9pfsd/xen-9pfsd.h index 75eaac9f7b..1ca3093f1a 100644 --- a/tools/xen-9pfsd/xen-9pfsd.h +++ b/tools/xen-9pfsd/xen-9pfsd.h @@ -25,7 +25,11 @@ struct p9_fid { XEN_TAILQ_ENTRY(struct p9_fid) list; unsigned int fid; unsigned int ref; + int fd; + uint8_t mode; bool opened; + bool isdir; + void *data; /* File type specific. */ char path[]; }; =20 --=20 2.35.3 From nobody Thu May 16 01:45:44 2024 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=1699633342; cv=none; d=zohomail.com; s=zohoarc; b=Trsx1TswPlUS8rUa48j9QYfpOzwMeHeTY9wZtZpC68TylACFYrx1Ixhhijlt+9oUb0t2VKIFqxAQeZhwHDqL92PytN6IrG30K9IUyF9UvHk5DXGdzmT5ePa8jYXhIgTJaUX5rCKYhQnaQfLNRcBHlnP6ZbVxwffjKFjo/9ypmyE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1699633342; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=ia0sJSe348M/0TeGjDY+uWzzzIk2QcQkMJh7HRaDODM=; b=fECK7saW3jZdIT1gErZYk8l+4GX1HoV20B4urBwUZ2DMRrpxwuwWBjC/gkA3DJ9JQEemcjw1SITHBrv7Vc4uqR7V4SklLccyyvJeIul10U725+ycFSnnaUiUDYf69cIPR28ao/fqV2yostmpgmDCaF3ETHMkKxHDsMqDJ6DinKw= 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 1699633342312434.3764046899903; Fri, 10 Nov 2023 08:22:22 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.630570.983530 (Exim 4.92) (envelope-from ) id 1r1UGh-0005RC-3f; Fri, 10 Nov 2023 16:22:03 +0000 Received: by outflank-mailman (output) from mailman id 630570.983530; Fri, 10 Nov 2023 16:22:03 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1r1UGh-0005R5-0m; Fri, 10 Nov 2023 16:22:03 +0000 Received: by outflank-mailman (input) for mailman id 630570; Fri, 10 Nov 2023 16:22:01 +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 1r1U49-0004cS-A9 for xen-devel@lists.xenproject.org; Fri, 10 Nov 2023 16:09:05 +0000 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 7749dc35-7fe3-11ee-9b0e-b553b5be7939; Fri, 10 Nov 2023 17:09:03 +0100 (CET) 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-out1.suse.de (Postfix) with ESMTPS id F35DF2187C; Fri, 10 Nov 2023 16:09:02 +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 D09FA13398; Fri, 10 Nov 2023 16:09:02 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id b2SXMZ5VTmXECAAAMHmgww (envelope-from ); Fri, 10 Nov 2023 16:09:02 +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: 7749dc35-7fe3-11ee-9b0e-b553b5be7939 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1699632542; 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=ia0sJSe348M/0TeGjDY+uWzzzIk2QcQkMJh7HRaDODM=; b=WbHjVERfn/TIaMSP3gCmuO+GnCi/8siUI0Ud/lKpJlrCaVfLNuww4ujvC6HxAWUpZOht1T +DmtJ78ObAXbUjWTfroZrr3d5m7XPkSFuW/BUgjd8jYkDM/hs4i9FgnES/VqsD/SOVYc2d B1/pw3sf3Jr77aNLf2bPrF/LSZT20OU= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Anthony PERARD Subject: [PATCH v2 10/29] tools/xenlogd: add 9pfs clunk request support Date: Fri, 10 Nov 2023 17:07:45 +0100 Message-Id: <20231110160804.29021-11-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20231110160804.29021-1-jgross@suse.com> References: <20231110160804.29021-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1699633343493100001 Content-Type: text/plain; charset="utf-8" Add the clunk request of the 9pfs protocol. Signed-off-by: Juergen Gross Reviewed-by: Jason Andryuk --- tools/xen-9pfsd/io.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/tools/xen-9pfsd/io.c b/tools/xen-9pfsd/io.c index bb9c78a1f5..c182ef0483 100644 --- a/tools/xen-9pfsd/io.c +++ b/tools/xen-9pfsd/io.c @@ -31,6 +31,7 @@ #define P9_CMD_ERROR 107 #define P9_CMD_WALK 110 #define P9_CMD_OPEN 112 +#define P9_CMD_CLUNK 120 =20 /* P9 protocol open flags. */ #define P9_OREAD 0 /* read */ @@ -943,6 +944,43 @@ static void p9_open(struct ring *ring, struct p9_heade= r *hdr) fill_buffer(ring, hdr->cmd + 1, hdr->tag, "QU", &qid, &iounit); } =20 +static void p9_clunk(struct ring *ring, struct p9_header *hdr) +{ + device *device =3D ring->device; + uint32_t fid; + struct p9_fid *fidp; + int ret; + + ret =3D fill_data(ring, "U", &fid); + if ( ret !=3D 1 ) + { + p9_error(ring, hdr->tag, EINVAL); + return; + } + + fidp =3D get_fid_ref(device, fid); + if ( !fidp ) + { + p9_error(ring, hdr->tag, ENOENT); + return; + } + + if ( fidp->opened ) + { + fidp->opened =3D false; + free_fid(device, fidp); + close(fidp->fd); + if ( fidp->mode & P9_OREMOVE ) + unlink(fidp->path); + } + + /* 2 calls of free_fid(): one for our reference, and one to free it. */ + free_fid(device, fidp); + free_fid(device, fidp); + + fill_buffer(ring, hdr->cmd + 1, hdr->tag, ""); +} + void *io_thread(void *arg) { struct ring *ring =3D arg; @@ -1014,6 +1052,10 @@ void *io_thread(void *arg) p9_open(ring, &hdr); break; =20 + case P9_CMD_CLUNK: + p9_clunk(ring, &hdr); + break; + default: syslog(LOG_DEBUG, "%u.%u sent unhandled command %u\n", ring->device->domid, ring->device->devid, hdr.cmd); --=20 2.35.3 From nobody Thu May 16 01:45:44 2024 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=1699632587; cv=none; d=zohomail.com; s=zohoarc; b=khdl6ERqsLsHduC1yXZPU2+mwRxkcGeqYHTL2X1Egwd+m5HLt11dlPe34i/+jNHUDommZP9ocLQW51U/qyO5KVsNX75zOea4RJzkcbRMgNJRXMEpp1VhISrn3Hxzppj7aQ0jUZ6wn46i489FzrXeKFETwChFY9YxHhkH1ZZduYs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1699632587; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=kpIVjIc8Trw1a/1y0NH1SiQxKICQ+nMOfKarWypzx+Q=; b=M+aM0Ja25XgkaGSFm4JUKfJmGxedCwzeBHSYG1IuH/117ozKtTM4/6Ur5AIWj9b+SOZjz661dJouojb5D9xy80hxmubbl1WMzWd2i4u++ObVTmvh0234XZkZLtFDqCu1eTcrHVFGYeVuUONey1yOG2Kh/UL3EgVFBbE9z8jMaSE= 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 1699632587329422.0907987731807; Fri, 10 Nov 2023 08:09:47 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.630483.983390 (Exim 4.92) (envelope-from ) id 1r1U4F-0008Bs-7m; Fri, 10 Nov 2023 16:09:11 +0000 Received: by outflank-mailman (output) from mailman id 630483.983390; Fri, 10 Nov 2023 16:09:11 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1r1U4F-0008Bl-4y; Fri, 10 Nov 2023 16:09:11 +0000 Received: by outflank-mailman (input) for mailman id 630483; Fri, 10 Nov 2023 16:09:09 +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 1r1U4D-00048H-Cj for xen-devel@lists.xenproject.org; Fri, 10 Nov 2023 16:09:09 +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 7a95d5d6-7fe3-11ee-98da-6d05b1d4d9a1; Fri, 10 Nov 2023 17:09:08 +0100 (CET) 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 84D2D1F8BE; Fri, 10 Nov 2023 16:09:08 +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 5E46413398; Fri, 10 Nov 2023 16:09:08 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 2bevFaRVTmXVCAAAMHmgww (envelope-from ); Fri, 10 Nov 2023 16:09:08 +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: 7a95d5d6-7fe3-11ee-98da-6d05b1d4d9a1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1699632548; 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=kpIVjIc8Trw1a/1y0NH1SiQxKICQ+nMOfKarWypzx+Q=; b=tGXwddmjostmiVooVmFEGT5GCy6dfbDfopotvd5d+wVp1RGi2PHYRILi/W4F6LMkp07pox brh1LY9ikmCqgQYUN681aEqWl8P0tua4LTCQ3JwCpNQMnrkY0O9W6Mpls3silg87cMS8pK 7U+KtwvBgm5L2sM/ZgohYPJv0GlcwhE= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Anthony PERARD Subject: [PATCH v2 11/29] tools/xenlogd: add 9pfs create request support Date: Fri, 10 Nov 2023 17:07:46 +0100 Message-Id: <20231110160804.29021-12-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20231110160804.29021-1-jgross@suse.com> References: <20231110160804.29021-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1699632587957100001 Content-Type: text/plain; charset="utf-8" Add the create request of the 9pfs protocol. Signed-off-by: Juergen Gross Reviewed-by: Jason Andryuk --- V2: - set permissions correctly (Jason Andryuk) --- tools/xen-9pfsd/io.c | 159 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 159 insertions(+) diff --git a/tools/xen-9pfsd/io.c b/tools/xen-9pfsd/io.c index c182ef0483..a605f51dc6 100644 --- a/tools/xen-9pfsd/io.c +++ b/tools/xen-9pfsd/io.c @@ -31,6 +31,7 @@ #define P9_CMD_ERROR 107 #define P9_CMD_WALK 110 #define P9_CMD_OPEN 112 +#define P9_CMD_CREATE 114 #define P9_CMD_CLUNK 120 =20 /* P9 protocol open flags. */ @@ -41,6 +42,12 @@ #define P9_OTRUNC 0x10 /* or'ed in, truncate file first */ #define P9_OREMOVE 0x40 /* or'ed in, remove file after clunk */ =20 +/* P9 protocol create permission masks. */ +#define P9_CREATE_PERM_DIR 0x80000000 +#define P9_CREATE_PERM_NOTSUPP 0x03b00000 /* link, symlink, ... */ +#define P9_CREATE_PERM_DIR_MASK 0777 +#define P9_CREATE_PERM_FILE_MASK 0666 + #define P9_MIN_MSIZE 2048 #define P9_VERSION "9P2000.u" #define P9_WALK_MAXELEM 16 @@ -944,6 +951,154 @@ static void p9_open(struct ring *ring, struct p9_head= er *hdr) fill_buffer(ring, hdr->cmd + 1, hdr->tag, "QU", &qid, &iounit); } =20 +static void p9_create(struct ring *ring, struct p9_header *hdr) +{ + device *device =3D ring->device; + uint32_t fid; + unsigned int name_off; + uint32_t perm; + uint8_t mode; + unsigned int ext_off; + struct p9_fid *fidp; + struct p9_fid *new_fidp; + char *path; + struct stat st; + struct p9_qid qid; + uint32_t iounit; + int flags; + int ret; + + ret =3D fill_data(ring, "USUbS", &fid, &name_off, &perm, &mode, &ext_o= ff); + if ( ret !=3D 5 ) + { + p9_error(ring, hdr->tag, EINVAL); + return; + } + + if ( !name_ok(ring->str + name_off) ) + { + p9_error(ring, hdr->tag, ENOENT); + return; + } + + if ( perm & P9_CREATE_PERM_NOTSUPP ) + { + p9_error(ring, hdr->tag, EINVAL); + return; + } + + fidp =3D get_fid_ref(device, fid); + if ( !fidp || fidp->opened ) + { + free_fid(device, fidp); + p9_error(ring, hdr->tag, EINVAL); + return; + } + if ( stat(fidp->path, &st) < 0 ) + { + free_fid(device, fidp); + p9_error(ring, hdr->tag, errno); + return; + } + + path =3D malloc(strlen(fidp->path) + strlen(ring->str + name_off) + 2 - + strlen(device->host_path)); + if ( !path ) + { + free_fid(device, fidp); + p9_error(ring, hdr->tag, ENOMEM); + return; + } + sprintf(path, "%s/%s", fidp->path + strlen(device->host_path), + ring->str + name_off); + new_fidp =3D alloc_fid_mem(device, fid, path); + free(path); + if ( !new_fidp ) + { + free_fid(device, fidp); + p9_error(ring, hdr->tag, ENOMEM); + return; + } + + pthread_mutex_lock(&device->fid_mutex); + + new_fidp->ref =3D fidp->ref; + + if ( perm & P9_CREATE_PERM_DIR ) + { + perm &=3D P9_CREATE_PERM_DIR_MASK & st.st_mode; + if ( mode !=3D P9_OREAD ) + { + p9_error(ring, hdr->tag, EINVAL); + free(new_fidp); + goto err; + } + if ( mkdir(new_fidp->path, perm) < 0 ) + { + p9_error(ring, hdr->tag, errno); + free(new_fidp); + goto err; + } + + XEN_TAILQ_REMOVE(&device->fids, fidp, list); + XEN_TAILQ_INSERT_HEAD(&device->fids, new_fidp, list); + free(fidp); + fidp =3D new_fidp; + + fidp->data =3D opendir(fidp->path); + if ( !fidp->data ) + { + p9_error(ring, hdr->tag, errno); + goto err; + } + fidp->fd =3D dirfd(fidp->data); + } + else + { + flags =3D open_flags_from_mode(mode); + if ( flags < 0 ) + { + p9_error(ring, hdr->tag, EINVAL); + free(new_fidp); + goto err; + } + flags |=3D perm & P9_CREATE_PERM_FILE_MASK & st.st_mode; + + XEN_TAILQ_REMOVE(&device->fids, fidp, list); + XEN_TAILQ_INSERT_HEAD(&device->fids, new_fidp, list); + free(fidp); + fidp =3D new_fidp; + + fidp->fd =3D creat(fidp->path, flags); + if ( fidp->fd < 0 ) + { + p9_error(ring, hdr->tag, errno); + goto err; + } + } + + if ( stat(fidp->path, &st) < 0 ) + { + p9_error(ring, hdr->tag, errno); + goto err; + } + fill_qid(fidp->path, &qid, &st); + iounit =3D get_iounit(ring, &st); + fidp->opened =3D true; + fidp->mode =3D mode; + + pthread_mutex_unlock(&device->fid_mutex); + + fill_buffer(ring, hdr->cmd + 1, hdr->tag, "QU", &qid, &iounit); + + return; + + err: + pthread_mutex_unlock(&device->fid_mutex); + + free_fid(device, fidp); +} + static void p9_clunk(struct ring *ring, struct p9_header *hdr) { device *device =3D ring->device; @@ -1052,6 +1207,10 @@ void *io_thread(void *arg) p9_open(ring, &hdr); break; =20 + case P9_CMD_CREATE: + p9_create(ring, &hdr); + break; + case P9_CMD_CLUNK: p9_clunk(ring, &hdr); break; --=20 2.35.3 From nobody Thu May 16 01:45:44 2024 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=1699633162; cv=none; d=zohomail.com; s=zohoarc; b=B6Ks0Dgl+ireOqvcf1A+O/+DCz9h/LQLqZ82MUVSX+WSqLffuyFziAHAmkYPbZQHqLgVXeepcJwzqrVqZdqeeW/WwKLleSAlVhOlk2NGf16bGHN3zpC07gpkFzlNsY6xatRidq3rVH78D6bjoxshBZaFWwqqCNesI/3wWm15JVU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1699633162; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=ci5L/DBfOaTU/puLQPxWUNYgGysJWDyG7t97Oi0b76s=; b=IyePNMtZPnafOA6DP7k6MSoILfYHGl2/zJ53qtSqaWocLKZsdWgOanUf2u1wHG0qREFrvdKCWzEDAMlwtrhJlQEwVvut2hT4P+ebAFfmxZ7WMOVpXtkAaJckApUPoEPO9Qvd7Ohal9illb6ZI6XkpLaTj2rZobzX+m2pByY0j6Y= 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 1699633162572267.43468212392065; Fri, 10 Nov 2023 08:19:22 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.630557.983520 (Exim 4.92) (envelope-from ) id 1r1UDg-0003Hu-L8; Fri, 10 Nov 2023 16:18:56 +0000 Received: by outflank-mailman (output) from mailman id 630557.983520; Fri, 10 Nov 2023 16:18:56 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1r1UDg-0003Hl-I1; Fri, 10 Nov 2023 16:18:56 +0000 Received: by outflank-mailman (input) for mailman id 630557; Fri, 10 Nov 2023 16:18:55 +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 1r1U4K-0004cS-1U for xen-devel@lists.xenproject.org; Fri, 10 Nov 2023 16:09:16 +0000 Received: from smtp-out1.suse.de (smtp-out1.suse.de [2001:67c:2178:6::1c]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 7df34bcb-7fe3-11ee-9b0e-b553b5be7939; Fri, 10 Nov 2023 17:09:14 +0100 (CET) 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-out1.suse.de (Postfix) with ESMTPS id 28C94219B3; Fri, 10 Nov 2023 16:09:14 +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 E819913398; Fri, 10 Nov 2023 16:09:13 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id Q45VN6lVTmXdCAAAMHmgww (envelope-from ); Fri, 10 Nov 2023 16:09:13 +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: 7df34bcb-7fe3-11ee-9b0e-b553b5be7939 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1699632554; 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=ci5L/DBfOaTU/puLQPxWUNYgGysJWDyG7t97Oi0b76s=; b=cphz9qwIUvQcq3vzGbkm0nskov+53Ye/t9dubrPcPRqB2dM1o52GzdSQqU9AH2hB7UhHt/ KbSLXQZGSGatmv7NmJuCV1RnSXAvqN0Z1OJKu8B7iE0nG/8nyPVgQSo8otLK6Yauu4F5ya uuTMK/xBvlaU9sr+vVLrFTQCbhleBk4= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Anthony PERARD , Jason Andryuk Subject: [PATCH v2 12/29] tools/xenlogd: add 9pfs stat request support Date: Fri, 10 Nov 2023 17:07:47 +0100 Message-Id: <20231110160804.29021-13-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20231110160804.29021-1-jgross@suse.com> References: <20231110160804.29021-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1699633164719100001 Content-Type: text/plain; charset="utf-8" Add the stat request of the 9pfs protocol. Signed-off-by: Juergen Gross Reviewed-by: Jason Andryuk --- tools/xen-9pfsd/io.c | 92 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) diff --git a/tools/xen-9pfsd/io.c b/tools/xen-9pfsd/io.c index a605f51dc6..e5abd25857 100644 --- a/tools/xen-9pfsd/io.c +++ b/tools/xen-9pfsd/io.c @@ -33,6 +33,7 @@ #define P9_CMD_OPEN 112 #define P9_CMD_CREATE 114 #define P9_CMD_CLUNK 120 +#define P9_CMD_STAT 124 =20 /* P9 protocol open flags. */ #define P9_OREAD 0 /* read */ @@ -59,6 +60,25 @@ struct p9_qid { uint64_t path; }; =20 +struct p9_stat { + uint16_t size; + uint16_t type; + uint32_t dev; + struct p9_qid qid; + uint32_t mode; + uint32_t atime; + uint32_t mtime; + uint64_t length; + const char *name; + const char *uid; + const char *gid; + const char *muid; + const char *extension; + uint32_t n_uid; + uint32_t n_gid; + uint32_t n_muid; +}; + /* * Note that the ring names "in" and "out" are from the frontend's * perspective, so the "in" ring will be used for responses to the fronten= d, @@ -1136,6 +1156,74 @@ static void p9_clunk(struct ring *ring, struct p9_he= ader *hdr) fill_buffer(ring, hdr->cmd + 1, hdr->tag, ""); } =20 +static void fill_p9_stat(struct p9_stat *p9s, struct stat *st, const char = *name) +{ + memset(p9s, 0, sizeof(*p9s)); + fill_qid(NULL, &p9s->qid, st); + p9s->mode =3D st->st_mode & 0777; + if ( S_ISDIR(st->st_mode) ) + p9s->mode |=3D P9_CREATE_PERM_DIR; + p9s->atime =3D st->st_atime; + p9s->mtime =3D st->st_mtime; + p9s->length =3D st->st_size; + p9s->name =3D name; + p9s->uid =3D ""; + p9s->gid =3D ""; + p9s->muid =3D ""; + p9s->extension =3D ""; + p9s->n_uid =3D 0; + p9s->n_gid =3D 0; + p9s->n_muid =3D 0; + + /* + * Size of individual fields without the size field, including 5 2-byte + * string length fields. + */ + p9s->size =3D 71 + strlen(p9s->name); +} + +static void p9_stat(struct ring *ring, struct p9_header *hdr) +{ + device *device =3D ring->device; + uint32_t fid; + struct p9_fid *fidp; + struct p9_stat p9s; + struct stat st; + uint16_t total_length; + int ret; + + ret =3D fill_data(ring, "U", &fid); + if ( ret !=3D 1 ) + { + p9_error(ring, hdr->tag, EINVAL); + return; + } + + fidp =3D get_fid_ref(device, fid); + if ( !fidp ) + { + p9_error(ring, hdr->tag, ENOENT); + return; + } + + if ( stat(fidp->path, &st) < 0 ) + { + p9_error(ring, hdr->tag, errno); + goto out; + } + fill_p9_stat(&p9s, &st, strrchr(fidp->path, '/') + 1); + + total_length =3D p9s.size + sizeof(p9s.size); + fill_buffer(ring, hdr->cmd + 1, hdr->tag, "uuuUQUUULSSSSSUUU", + &total_length, &p9s.size, &p9s.type, &p9s.dev, &p9s.qid, + &p9s.mode, &p9s.atime, &p9s.mtime, &p9s.length, p9s.name, + p9s.uid, p9s.gid, p9s.muid, p9s.extension, &p9s.n_uid, + &p9s.n_gid, &p9s.n_muid); + + out: + free_fid(device, fidp); +} + void *io_thread(void *arg) { struct ring *ring =3D arg; @@ -1215,6 +1303,10 @@ void *io_thread(void *arg) p9_clunk(ring, &hdr); break; =20 + case P9_CMD_STAT: + p9_stat(ring, &hdr); + break; + default: syslog(LOG_DEBUG, "%u.%u sent unhandled command %u\n", ring->device->domid, ring->device->devid, hdr.cmd); --=20 2.35.3 From nobody Thu May 16 01:45:44 2024 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=1699632883; cv=none; d=zohomail.com; s=zohoarc; b=By4tqDngXwu7LkPxAoHGIxQOV+GefsLKA/QADaTmb+r0UzxuwX/rz4rXHopxk7pdreX1IMaCyObp2Do53Ykufk1lQj4Li4InU03rNaM1yJDqOyj+eK7EQASbHa2UkeE50oGIB8U5GX8rP0ZbS3xpuErkH3weChks6H84IAHQ5F4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1699632883; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=eLw5zP4CF8KqwQQ9wObvj3vXheWZzp/lHPiMhL0KY6Y=; b=KDClQGunWlAPB1B+gWwyJg1oac/O0nuUQNh/P5FmeVtOMVMbVkgjjJGJYC/H+5y/8ya65WQxdNWqqbimdUn00gIgjgE9gEa5xAtTsE0IISjtOv4O+BSYMsq5kvDlTRklqJvWKxZi5Otuj0t/O85Q24xGCovlXKtLte5bjf/qO48= 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 1699632883728624.5531902103801; Fri, 10 Nov 2023 08:14:43 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.630523.983441 (Exim 4.92) (envelope-from ) id 1r1U9K-0005xE-9Q; Fri, 10 Nov 2023 16:14:26 +0000 Received: by outflank-mailman (output) from mailman id 630523.983441; Fri, 10 Nov 2023 16:14:26 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1r1U9K-0005vR-37; Fri, 10 Nov 2023 16:14:26 +0000 Received: by outflank-mailman (input) for mailman id 630523; Fri, 10 Nov 2023 16:14:24 +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 1r1U4P-0004cS-GE for xen-devel@lists.xenproject.org; Fri, 10 Nov 2023 16:09:21 +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 81411efa-7fe3-11ee-9b0e-b553b5be7939; Fri, 10 Nov 2023 17:09:19 +0100 (CET) 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 AF25E1F8BB; Fri, 10 Nov 2023 16:09:19 +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 81BD613398; Fri, 10 Nov 2023 16:09:19 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 4upLHq9VTmX6CAAAMHmgww (envelope-from ); Fri, 10 Nov 2023 16:09:19 +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: 81411efa-7fe3-11ee-9b0e-b553b5be7939 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1699632559; 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=eLw5zP4CF8KqwQQ9wObvj3vXheWZzp/lHPiMhL0KY6Y=; b=Yph/2NnJqQ41t5yJWpV8UkSkNb3UGxlGKP4BcLgFTDW2f7WAX5JYgFm/io2oLT7ZeXmDcr I6kXCDLfeG79xdwGHe0319Swdh8BzywfjWQCo/uSIIYQ9Rrrv4gn/iaBU0bTmyMQs2bsXq NTMaLSWKHFdnQfb1HhMth2a9yqxDU68= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Anthony PERARD , Jason Andryuk Subject: [PATCH v2 13/29] tools/xenlogd: add 9pfs write request support Date: Fri, 10 Nov 2023 17:07:48 +0100 Message-Id: <20231110160804.29021-14-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20231110160804.29021-1-jgross@suse.com> References: <20231110160804.29021-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1699632885291100001 Content-Type: text/plain; charset="utf-8" Add the write request of the 9pfs protocol. Signed-off-by: Juergen Gross Reviewed-by: Jason Andryuk --- tools/xen-9pfsd/io.c | 54 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/tools/xen-9pfsd/io.c b/tools/xen-9pfsd/io.c index e5abd25857..f8d981c2a6 100644 --- a/tools/xen-9pfsd/io.c +++ b/tools/xen-9pfsd/io.c @@ -32,6 +32,7 @@ #define P9_CMD_WALK 110 #define P9_CMD_OPEN 112 #define P9_CMD_CREATE 114 +#define P9_CMD_WRITE 118 #define P9_CMD_CLUNK 120 #define P9_CMD_STAT 124 =20 @@ -1119,6 +1120,55 @@ static void p9_create(struct ring *ring, struct p9_h= eader *hdr) free_fid(device, fidp); } =20 +static void p9_write(struct ring *ring, struct p9_header *hdr) +{ + device *device =3D ring->device; + uint32_t fid; + uint64_t off; + unsigned int len; + uint32_t written; + void *buf; + struct p9_fid *fidp; + int ret; + + ret =3D fill_data(ring, "ULD", &fid, &off, &len, ring->buffer); + if ( ret !=3D 3 ) + { + p9_error(ring, hdr->tag, EINVAL); + return; + } + + fidp =3D get_fid_ref(device, fid); + if ( !fidp || !fidp->opened || fidp->isdir ) + { + p9_error(ring, hdr->tag, EBADF); + goto out; + } + + buf =3D ring->buffer; + + while ( len !=3D 0 ) + { + ret =3D pwrite(fidp->fd, buf, len, off); + if ( ret < 0 ) + break; + len -=3D ret; + buf +=3D ret; + off +=3D ret; + } + + written =3D buf - ring->buffer; + if ( written =3D=3D 0 ) + { + p9_error(ring, hdr->tag, errno); + goto out; + } + fill_buffer(ring, hdr->cmd + 1, hdr->tag, "U", &written); + + out: + free_fid(device, fidp); +} + static void p9_clunk(struct ring *ring, struct p9_header *hdr) { device *device =3D ring->device; @@ -1299,6 +1349,10 @@ void *io_thread(void *arg) p9_create(ring, &hdr); break; =20 + case P9_CMD_WRITE: + p9_write(ring, &hdr); + break; + case P9_CMD_CLUNK: p9_clunk(ring, &hdr); break; --=20 2.35.3 From nobody Thu May 16 01:45:44 2024 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=1699633389; cv=none; d=zohomail.com; s=zohoarc; b=D4Q9fnoY+I3ZuEpJSAG0HcC/YBfkKGzKaia0TR9CuSVlgJw9a+teHebpxAidpaZyL55x2LGja7UiGLLf/rF+jjMTM3i8DJw2UYCDx9jUxxcJLw1ElaAs/vF8l+9c/2cInIB/I4MSn59VDk/144aIcesz7nbG9QsReC2q+riZjZA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1699633389; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=lNELVOtIBvsXIZZicR5yL0eKM2DQUzTKU2kSsnMPGxo=; b=KuINxQrKhJbHyXxOIUi9TTNLF4UOLVLd8EGcbRiq9Qirj1IjtBvilWkX+tFpkesppEMSe9Er8VL/SW21umiCaJqU4jNNnDofLnqxHe2kh3/Zux/GmuHLTNQq6Gsldvxp4RG5BMsOtZ/rCrBSs2KCYEhet0BJH5zO26t+NBRL/2Q= 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 169963338946316.564798028218547; Fri, 10 Nov 2023 08:23:09 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.630576.983559 (Exim 4.92) (envelope-from ) id 1r1UHQ-0006ha-Bt; Fri, 10 Nov 2023 16:22:48 +0000 Received: by outflank-mailman (output) from mailman id 630576.983559; Fri, 10 Nov 2023 16:22:48 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1r1UHQ-0006eL-6S; Fri, 10 Nov 2023 16:22:48 +0000 Received: by outflank-mailman (input) for mailman id 630576; Fri, 10 Nov 2023 16:22:46 +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 1r1U4V-0004cS-U3 for xen-devel@lists.xenproject.org; Fri, 10 Nov 2023 16:09:27 +0000 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 84962116-7fe3-11ee-9b0e-b553b5be7939; Fri, 10 Nov 2023 17:09:25 +0100 (CET) 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-out1.suse.de (Postfix) with ESMTPS id 4BC2F219B3; Fri, 10 Nov 2023 16:09:25 +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 1E4CA13398; Fri, 10 Nov 2023 16:09:25 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id xHsQBrVVTmUJCQAAMHmgww (envelope-from ); Fri, 10 Nov 2023 16:09:25 +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: 84962116-7fe3-11ee-9b0e-b553b5be7939 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1699632565; 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=lNELVOtIBvsXIZZicR5yL0eKM2DQUzTKU2kSsnMPGxo=; b=sVcDy2eCiRDJlVk10Kk2Wm9uV0EeUF1Mfbd06tvg2Jc+tPdaEOOb7cpdgGpvn7VpZpKcOH LZcZna+SV0w4v8dmxw6g9PbNi7fwy6meX+IbAnLHxhWTJsyZdy/JN0DPnZMbNMqE1Y/Zm3 /WlKEPtTsIP0e9kdXPILeyfMTjmbnPQ= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Anthony PERARD , Jason Andryuk Subject: [PATCH v2 14/29] tools/xenlogd: add 9pfs read request support Date: Fri, 10 Nov 2023 17:07:49 +0100 Message-Id: <20231110160804.29021-15-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20231110160804.29021-1-jgross@suse.com> References: <20231110160804.29021-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1699633391600100005 Content-Type: text/plain; charset="utf-8" Add the read request of the 9pfs protocol. For now support only reading plain files (no directories). Signed-off-by: Juergen Gross Reviewed-by: Jason Andryuk --- V2: - make error check more readable (Jason Andryuk) --- tools/xen-9pfsd/io.c | 64 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/tools/xen-9pfsd/io.c b/tools/xen-9pfsd/io.c index f8d981c2a6..1edea2e24a 100644 --- a/tools/xen-9pfsd/io.c +++ b/tools/xen-9pfsd/io.c @@ -32,6 +32,7 @@ #define P9_CMD_WALK 110 #define P9_CMD_OPEN 112 #define P9_CMD_CREATE 114 +#define P9_CMD_READ 116 #define P9_CMD_WRITE 118 #define P9_CMD_CLUNK 120 #define P9_CMD_STAT 124 @@ -1120,6 +1121,65 @@ static void p9_create(struct ring *ring, struct p9_h= eader *hdr) free_fid(device, fidp); } =20 +static void p9_read(struct ring *ring, struct p9_header *hdr) +{ + device *device =3D ring->device; + uint32_t fid; + uint64_t off; + unsigned int len; + uint32_t count; + void *buf; + struct p9_fid *fidp; + int ret; + + ret =3D fill_data(ring, "ULU", &fid, &off, &count); + if ( ret !=3D 3 ) + { + p9_error(ring, hdr->tag, EINVAL); + return; + } + + fidp =3D get_fid_ref(device, fid); + if ( !fidp || !fidp->opened ) + { + p9_error(ring, hdr->tag, EBADF); + goto out; + } + + if ( fidp->isdir ) + { + p9_error(ring, hdr->tag, EOPNOTSUPP); + goto out; + } + else + { + len =3D count; + buf =3D ring->buffer + sizeof(*hdr) + sizeof(uint32_t); + + while ( len !=3D 0 ) + { + ret =3D pread(fidp->fd, buf, len, off); + if ( ret <=3D 0 ) + break; + len -=3D ret; + buf +=3D ret; + off +=3D ret; + } + if ( ret < 0 && len =3D=3D count ) + { + p9_error(ring, hdr->tag, errno); + goto out; + } + + buf =3D ring->buffer + sizeof(*hdr) + sizeof(uint32_t); + len =3D count - len; + fill_buffer(ring, hdr->cmd + 1, hdr->tag, "D", &len, buf); + } + + out: + free_fid(device, fidp); +} + static void p9_write(struct ring *ring, struct p9_header *hdr) { device *device =3D ring->device; @@ -1349,6 +1409,10 @@ void *io_thread(void *arg) p9_create(ring, &hdr); break; =20 + case P9_CMD_READ: + p9_read(ring, &hdr); + break; + case P9_CMD_WRITE: p9_write(ring, &hdr); break; --=20 2.35.3 From nobody Thu May 16 01:45:44 2024 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=1699633373; cv=none; d=zohomail.com; s=zohoarc; b=LTF3XOTEEqfyvlSjJ9yFXW82mIy6kep3kKWCkV0/ORd5pqcp12nRttx3ZEyF4L3KtpERID98tRUtY4w6H0Fbcqw5PfNKl37uZ31MzTZCHcXH4rzcPbGy/YqQPiVgyBgrn8w5ZM05enCdhhl6CixdrTOAWUK5/ga0maln1HZreuU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1699633373; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=AQywzv/Y34quHnZ9IPkhWdaZOnTMkCrPxK530+/Vdyk=; b=ipOMrUE+JSINhb+/NZr1K86osQWbIxXsi3QdC89nTkJ/s3zqCpAAX9w5V7qsMot4oIZHH67CBDhjakSPKJw2eXnXscihXYZJG83ZcsPdts+BL+Qw5hSWVf7AB4bzT4Ttp+mdEY7qKy2VD9MaWMwMZwxlUtxoSrFgJ8WNHOK654w= 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 1699633373542690.5361719482255; Fri, 10 Nov 2023 08:22:53 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.630573.983539 (Exim 4.92) (envelope-from ) id 1r1UHB-0005xt-BC; Fri, 10 Nov 2023 16:22:33 +0000 Received: by outflank-mailman (output) from mailman id 630573.983539; Fri, 10 Nov 2023 16:22:33 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1r1UHB-0005xm-8O; Fri, 10 Nov 2023 16:22:33 +0000 Received: by outflank-mailman (input) for mailman id 630573; Fri, 10 Nov 2023 16:22:32 +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 1r1U4b-0004cS-0b for xen-devel@lists.xenproject.org; Fri, 10 Nov 2023 16:09:33 +0000 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 87ec2cad-7fe3-11ee-9b0e-b553b5be7939; Fri, 10 Nov 2023 17:09:31 +0100 (CET) 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-out1.suse.de (Postfix) with ESMTPS id DBB4D219B4; Fri, 10 Nov 2023 16:09:30 +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 AFCD613398; Fri, 10 Nov 2023 16:09:30 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id lqqGKbpVTmUUCQAAMHmgww (envelope-from ); Fri, 10 Nov 2023 16:09:30 +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: 87ec2cad-7fe3-11ee-9b0e-b553b5be7939 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1699632570; 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=AQywzv/Y34quHnZ9IPkhWdaZOnTMkCrPxK530+/Vdyk=; b=mu9TP7L1yI1zwGVB6+cGrFpBl5fMSyW4VRzkzPMWEvU8jAohppN7uAIYX+vOAepSS12/RL d9hV5kLi0/6ZfCOgH6+daraINLiwTiI0RkLwgfiJKk9VPlUatUNG6RUGzfiAHQL6ufZzRM AGyd4I9poESYJAS87ZAZNkAZe4pTP0g= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Anthony PERARD , Jason Andryuk Subject: [PATCH v2 15/29] tools/libs/light: add backend type for 9pfs PV devices Date: Fri, 10 Nov 2023 17:07:50 +0100 Message-Id: <20231110160804.29021-16-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20231110160804.29021-1-jgross@suse.com> References: <20231110160804.29021-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1699633375599100001 Content-Type: text/plain; charset="utf-8" Make the backend type of 9pfs PV devices configurable. The default is "qemu" with the related Xenstore backend-side directory being "9pfs". Add another type "xen-9pfsd" with the related Xenstore backend-side directory "xen_9pfs". As additional security features it is possible to specify: - "max-space" for limiting the maximum space consumed on the filesystem in MBs - "max-files" for limiting the maximum number of files in the filesystem - "max-open-files" for limiting the maximum number of concurrent open files For convenience "auto-delete" is available to let the backend delete the oldest file of the guest in case otherwise "max-space" or "max-files" would be violated. The xen-9pfsd daemon will be started by libxenlight automatically when the first "xen_9pfs" device is being created. Signed-off-by: Juergen Gross Reviewed-by: Jason Andryuk --- tools/libs/light/libxl_9pfs.c | 145 +++++++++++++++++++++- tools/libs/light/libxl_create.c | 4 +- tools/libs/light/libxl_dm.c | 2 +- tools/libs/light/libxl_types.idl | 11 ++ tools/libs/light/libxl_types_internal.idl | 1 + 5 files changed, 156 insertions(+), 7 deletions(-) diff --git a/tools/libs/light/libxl_9pfs.c b/tools/libs/light/libxl_9pfs.c index 5ab0d3aa21..87e9dda8e7 100644 --- a/tools/libs/light/libxl_9pfs.c +++ b/tools/libs/light/libxl_9pfs.c @@ -33,20 +33,159 @@ static int libxl__set_xenstore_p9(libxl__gc *gc, uint3= 2_t domid, =20 flexarray_append_pair(front, "tag", p9->tag); =20 + if (p9->type =3D=3D LIBXL_P9_TYPE_XEN_9PFSD) { + flexarray_append_pair(back, "max-space", + GCSPRINTF("%u", p9->max_space)); + flexarray_append_pair(back, "max-files", + GCSPRINTF("%u", p9->max_files)); + flexarray_append_pair(back, "max-open-files", + GCSPRINTF("%u", p9->max_open_files)); + flexarray_append_pair(back, "auto-delete", + p9->auto_delete ? "1" : "0"); + } + + return 0; +} + +static int libxl__device_from_p9(libxl__gc *gc, uint32_t domid, + libxl_device_p9 *type, libxl__device *dev= ice) +{ + device->backend_devid =3D type->devid; + device->backend_domid =3D type->backend_domid; + device->backend_kind =3D type->type =3D=3D LIBXL_P9_TYPE_QEMU + ? LIBXL__DEVICE_KIND_9PFS + : LIBXL__DEVICE_KIND_XEN_9PFS; + device->devid =3D type->devid; + device->domid =3D domid; + device->kind =3D LIBXL__DEVICE_KIND_9PFS; + return 0; } =20 -#define libxl__add_p9s NULL +static int libxl_device_p9_dm_needed(void *e, unsigned domid) +{ + libxl_device_p9 *elem =3D e; + + return elem->type =3D=3D LIBXL_P9_TYPE_QEMU && elem->backend_domid =3D= =3D domid; +} + +typedef struct libxl__aop9_state libxl__aop9_state; + +struct libxl__aop9_state { + libxl__spawn_state spawn; + libxl__ao_device *aodev; + libxl_device_p9 *p9; + uint32_t domid; + void (*callback)(libxl__egc *, libxl__aop9_state *, int); +}; + +static void xen9pfsd_spawn_outcome(libxl__egc *egc, libxl__aop9_state *aop= 9, + int rc) +{ + aop9->aodev->rc =3D rc; + if (rc) + aop9->aodev->callback(egc, aop9->aodev); + else + libxl__device_add_async(egc, aop9->domid, &libxl__p9_devtype, + aop9->p9, aop9->aodev); +} + +static void xen9pfsd_confirm(libxl__egc *egc, libxl__spawn_state *spawn, + const char *xsdata) +{ + STATE_AO_GC(spawn->ao); + + if (!xsdata) + return; + + if (strcmp(xsdata, "running")) + return; + + libxl__spawn_initiate_detach(gc, spawn); +} + +static void xen9pfsd_failed(libxl__egc *egc, libxl__spawn_state *spawn, in= t rc) +{ + libxl__aop9_state *aop9 =3D CONTAINER_OF(spawn, *aop9, spawn); + + xen9pfsd_spawn_outcome(egc, aop9, rc); +} + +static void xen9pfsd_detached(libxl__egc *egc, libxl__spawn_state *spawn) +{ + libxl__aop9_state *aop9 =3D CONTAINER_OF(spawn, *aop9, spawn); + + xen9pfsd_spawn_outcome(egc, aop9, 0); +} + +static int xen9pfsd_spawn(libxl__egc *egc, uint32_t domid, libxl_device_p9= *p9, + libxl__ao_device *aodev) +{ + STATE_AO_GC(aodev->ao); + struct libxl__aop9_state *aop9; + int rc; + char *args[] =3D { "xen-9pfsd", NULL }; + char *path =3D GCSPRINTF("/local/domain/%u/libxl/xen-9pfs", + p9->backend_domid); + + if (p9->type !=3D LIBXL_P9_TYPE_XEN_9PFSD || + libxl__xs_read(gc, XBT_NULL, GCSPRINTF("%s/state", path))) + return 0; + + GCNEW(aop9); + aop9->aodev =3D aodev; + aop9->p9 =3D p9; + aop9->domid =3D domid; + aop9->callback =3D xen9pfsd_spawn_outcome; + + aop9->spawn.ao =3D aodev->ao; + aop9->spawn.what =3D "xen-9pfs daemon"; + aop9->spawn.xspath =3D GCSPRINTF("%s/state", path); + aop9->spawn.timeout_ms =3D LIBXL_DEVICE_MODEL_START_TIMEOUT * 1000; + aop9->spawn.pidpath =3D GCSPRINTF("%s/pid", path); + aop9->spawn.midproc_cb =3D libxl__spawn_record_pid; + aop9->spawn.confirm_cb =3D xen9pfsd_confirm; + aop9->spawn.failure_cb =3D xen9pfsd_failed; + aop9->spawn.detached_cb =3D xen9pfsd_detached; + rc =3D libxl__spawn_spawn(egc, &aop9->spawn); + if (rc < 0) + return rc; + if (!rc) { + setsid(); + libxl__exec(gc, -1, -1, -1, LIBEXEC_BIN "/xen-9pfsd", args, NULL); + } + + return 1; +} + +static void libxl__device_p9_add(libxl__egc *egc, uint32_t domid, + libxl_device_p9 *p9, + libxl__ao_device *aodev) +{ + int rc; + + rc =3D xen9pfsd_spawn(egc, domid, p9, aodev); + if (rc =3D=3D 1) + return; + + if (rc =3D=3D 0) + libxl__device_add_async(egc, domid, &libxl__p9_devtype, p9, aodev); + + aodev->rc =3D rc; + if (rc) + aodev->callback(egc, aodev); +} + #define libxl_device_p9_list NULL #define libxl_device_p9_compare NULL =20 static LIBXL_DEFINE_UPDATE_DEVID(p9) -static LIBXL_DEFINE_DEVICE_FROM_TYPE(p9) +static LIBXL_DEFINE_DEVICES_ADD(p9) =20 LIBXL_DEFINE_DEVICE_REMOVE(p9) =20 DEFINE_DEVICE_TYPE_STRUCT(p9, 9PFS, p9s, - .skip_attach =3D 1, .set_xenstore_config =3D (device_set_xenstore_config_fn_t) libxl__set_xenstore_p9, + .dm_needed =3D libxl_device_p9_dm_needed, ); diff --git a/tools/libs/light/libxl_create.c b/tools/libs/light/libxl_creat= e.c index ce1d431103..b19e9379b6 100644 --- a/tools/libs/light/libxl_create.c +++ b/tools/libs/light/libxl_create.c @@ -1760,9 +1760,6 @@ static void domcreate_launch_dm(libxl__egc *egc, libx= l__multidev *multidev, libxl__device_console_dispose(&console); } =20 - for (i =3D 0; i < d_config->num_p9s; i++) - libxl__device_add(gc, domid, &libxl__p9_devtype, &d_config->p9s[i]= ); - for (i =3D 0; i < d_config->num_pvcallsifs; i++) libxl__device_add(gc, domid, &libxl__pvcallsif_devtype, &d_config->pvcallsifs[i]); @@ -1899,6 +1896,7 @@ const libxl__device_type *device_type_tbl[] =3D { &libxl__vdispl_devtype, &libxl__vsnd_devtype, &libxl__virtio_devtype, + &libxl__p9_devtype, NULL }; =20 diff --git a/tools/libs/light/libxl_dm.c b/tools/libs/light/libxl_dm.c index 14b593110f..2aaaeb5aa7 100644 --- a/tools/libs/light/libxl_dm.c +++ b/tools/libs/light/libxl_dm.c @@ -3761,7 +3761,7 @@ int libxl__need_xenpv_qemu(libxl__gc *gc, libxl_domai= n_config *d_config) goto out; } =20 - if (d_config->num_vfbs > 0 || d_config->num_p9s > 0) { + if (d_config->num_vfbs > 0) { ret =3D 1; goto out; } diff --git a/tools/libs/light/libxl_types.idl b/tools/libs/light/libxl_type= s.idl index 7d8bd5d216..82565c4c10 100644 --- a/tools/libs/light/libxl_types.idl +++ b/tools/libs/light/libxl_types.idl @@ -150,6 +150,12 @@ libxl_nic_type =3D Enumeration("nic_type", [ (2, "VIF"), ]) =20 +libxl_p9_type =3D Enumeration("p9_type", [ + (0, "unknown"), + (1, "qemu"), + (2, "xen_9pfsd"), + ]) + libxl_action_on_shutdown =3D Enumeration("action_on_shutdown", [ (1, "DESTROY"), =20 @@ -942,6 +948,11 @@ libxl_device_p9 =3D Struct("device_p9", [ ("path", string), ("security_model", string), ("devid", libxl_devid), + ("type", libxl_p9_type), + ("max_space", integer), + ("max_files", integer), + ("max_open_files", integer), + ("auto_delete", bool), ]) =20 libxl_device_pvcallsif =3D Struct("device_pvcallsif", [ diff --git a/tools/libs/light/libxl_types_internal.idl b/tools/libs/light/l= ibxl_types_internal.idl index e24288f1a5..39da71cef5 100644 --- a/tools/libs/light/libxl_types_internal.idl +++ b/tools/libs/light/libxl_types_internal.idl @@ -34,6 +34,7 @@ libxl__device_kind =3D Enumeration("device_kind", [ (16, "VINPUT"), (17, "VIRTIO_DISK"), (18, "VIRTIO"), + (19, "XEN_9PFS"), ]) =20 libxl__console_backend =3D Enumeration("console_backend", [ --=20 2.35.3 From nobody Thu May 16 01:45:44 2024 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=1699633152; cv=none; d=zohomail.com; s=zohoarc; b=Dpxk094D1KJbh2yHuq0GeOo6TtFD7s00sPRaz18tMqhItAiyZr5fH616Id9occwIpKuYIyBacMM9zZvVkmo7NqKJzUGGfTm2Ndkq6puk0Mg26OZVahTlT6vJaKEexKQtAigmH0dFo6DivcPUO2PyqTviwfnQd1rfjSLAGQznheA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1699633152; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=HGxfpQnBGmt7EKeO4ArwxOs8iM93M39A7iQXembmjjI=; b=PHcbBo+0hhbPS6UBUuprvjkNKbFaScyvOa43nNrOSa32Y7WK7Y0c780ySUkVzlLDvbdXzNdoYXZtAi0WW9DIllOcs03ihlC4T4ZsGpq1YxC526MXRXo4wp+vlfat1bcunKZF90qHdWfaiSK5DrM5QfpTKDcjP/icV4vMb+/DGbc= 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 1699633152935403.14310644893374; Fri, 10 Nov 2023 08:19:12 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.630555.983510 (Exim 4.92) (envelope-from ) id 1r1UDY-0002pj-D3; Fri, 10 Nov 2023 16:18:48 +0000 Received: by outflank-mailman (output) from mailman id 630555.983510; Fri, 10 Nov 2023 16:18:48 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1r1UDY-0002pc-AR; Fri, 10 Nov 2023 16:18:48 +0000 Received: by outflank-mailman (input) for mailman id 630555; Fri, 10 Nov 2023 16:18:47 +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 1r1U4g-0004cS-Bf for xen-devel@lists.xenproject.org; Fri, 10 Nov 2023 16:09:38 +0000 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 8b3d1eae-7fe3-11ee-9b0e-b553b5be7939; Fri, 10 Nov 2023 17:09:36 +0100 (CET) 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-out1.suse.de (Postfix) with ESMTPS id 71E0A219B7; Fri, 10 Nov 2023 16:09:36 +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 4C18413398; Fri, 10 Nov 2023 16:09:36 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id vEssEcBVTmUaCQAAMHmgww (envelope-from ); Fri, 10 Nov 2023 16:09:36 +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: 8b3d1eae-7fe3-11ee-9b0e-b553b5be7939 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1699632576; 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=HGxfpQnBGmt7EKeO4ArwxOs8iM93M39A7iQXembmjjI=; b=ItLkvdPbSYVmVg2RKKPMhP0bA5pLRolTC6Auheiox9RWlqF8iOnW41BOaJGB7pCGSHbLz0 9JAD8SpDR0KxovXammuDVjsxoepjPdZlNDA4GM6A0+bdTKk8XQZEVmIg14ujTehE8SAdsm WrtoCn61aD2yUd/ay5ad2c9c7MLrTHA= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Anthony PERARD Subject: [PATCH v2 16/29] tools/xl: support new 9pfs backend xen-9pfsd Date: Fri, 10 Nov 2023 17:07:51 +0100 Message-Id: <20231110160804.29021-17-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20231110160804.29021-1-jgross@suse.com> References: <20231110160804.29021-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1699633154640100001 Content-Type: text/plain; charset="utf-8" Add support for the new 9pfs backend "xen-9pfsd". For this backend type the tag defaults to "Xen" and the host side path to "/var/log/xen/guests/". Signed-off-by: Juergen Gross Reviewed-by: Jason Andryuk --- V2: - test max_files and max_open_files, too (Jason Andryuk) --- docs/man/xl.cfg.5.pod.in | 36 ++++++++++++++++++++++++++++++++++-- tools/xl/xl_parse.c | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+), 2 deletions(-) diff --git a/docs/man/xl.cfg.5.pod.in b/docs/man/xl.cfg.5.pod.in index 2e234b450e..80011adbf3 100644 --- a/docs/man/xl.cfg.5.pod.in +++ b/docs/man/xl.cfg.5.pod.in @@ -772,10 +772,16 @@ settings, from the following list: =20 =3Dover 4 =20 +=3Ditem B + +The backendtype for the PV device. Supported values are B and +B. The default is B. + =3Ditem B =20 9pfs tag to identify the filesystem share. The tag is needed on the -guest side to mount it. +guest side to mount it. For the backendtype of B the tag defaul= ts to +"Xen". =20 =3Ditem B =20 @@ -785,12 +791,38 @@ squash or remap). =20 =3Ditem B =20 -Filesystem path on the backend to export. +Filesystem path on the backend to export. For the backendtype of B +the path defaults to "@XEN_LOG_DIR@/guests/". =20 =3Ditem B =20 Specify the backend domain name or id, defaults to dom0. =20 +=3Ditem B + +Specify the maximum number of files below B. A value of 0 (which +is the default) doesn't limit the number of files. Only valid for +B. + +=3Ditem B + +Specify the maximum number of concurrently opened files below B. +Multiple opens of the same file are counted individually. Only valid for +B, which has a default of B. + +=3Ditem B + +Specify the maximum used disk space in MiB below B. A value of 0 (wh= ich +is the default) doesn't limit the usable disk space. Only valid for +B. + +=3Ditem B + +When set the backend will delete the oldest file which is currently not +opened by the guest in case the disk space limit set via B or t= he +file limit set via B is being reached. Only valid for +B. + =3Dback =20 =3Ditem B diff --git a/tools/xl/xl_parse.c b/tools/xl/xl_parse.c index ed983200c3..3ded557ebc 100644 --- a/tools/xl/xl_parse.c +++ b/tools/xl/xl_parse.c @@ -2232,6 +2232,20 @@ void parse_config_data(const char *config_source, replace_string(&p9->tag, value); } else if (!strcmp(key, "backend")) { replace_string(&p9->backend_domname, value); + } else if (!strcmp(key, "type")) { + if (libxl_p9_type_from_string(value, &p9->type)) { + fprintf(stderr, "failed to parse 9pfs type: %s\n", + value); + exit(1); + } + } else if (!strcmp(key, "max-files")) { + p9->max_files =3D parse_ulong(value); + } else if (!strcmp(key, "max-open-files")) { + p9->max_open_files =3D parse_ulong(value); + } else if (!strcmp(key, "max-space")) { + p9->max_space =3D parse_ulong(value); + } else if (!strcmp(key, "auto-delete")) { + p9->auto_delete =3D strtoul(value, NULL, 0); } else { fprintf(stderr, "Unknown 9pfs parameter '%s'\n", key); exit(1); @@ -2242,6 +2256,28 @@ void parse_config_data(const char *config_source, =20 libxl_string_list_dispose(&pairs); =20 + if (p9->type =3D=3D LIBXL_P9_TYPE_UNKNOWN) { + p9->type =3D LIBXL_P9_TYPE_QEMU; + } + if (p9->type =3D=3D LIBXL_P9_TYPE_QEMU && + (p9->max_files || p9->max_open_files || p9->max_space || + p9->auto_delete)) { + fprintf(stderr, "Illegal 9pfs parameter combination\n"); + exit(1); + } + if (p9->type =3D=3D LIBXL_P9_TYPE_XEN_9PFSD) { + if (!p9->tag) { + replace_string(&p9->tag, "Xen"); + } + if (!p9->path) { + char *path; + + xasprintf(&path, XEN_LOG_DIR "/guests/%s", c_info->nam= e); + replace_string(&p9->path, path); + free(path); + } + } + if (!p9->path || !p9->security_model || !p9->tag) { fprintf(stderr, "9pfs spec missing required field!\n"); exit(1); --=20 2.35.3 From nobody Thu May 16 01:45:44 2024 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=1699633387; cv=none; d=zohomail.com; s=zohoarc; b=VeWJ99znMbfNQ5+eisIqHPRALWQrtS/g0iGgLjjVq/F7TNhrgrpHAACj1M2Q5wvSXQRp5XT6BDJmrQQx+qZKur6e4/ZFV0JOJRwOVctC2eAFbgfceDnr0OqSaUHe5HVFJ871/X5BMZpt9g37tJnq9D0LNR830U6aiT4ek5jkaxI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1699633387; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Gi0/c29PpXoSdVTcw0fAZAZaMgimOB0NYPLB5++nb6M=; b=hXJlsZIxR6c3D8cgqwdrc+u6kM57YTq5M8fk85FqJICPiGgRMWGznzFM/AwHrBKdLtHNFLV3cbHo0ipIZFnQOqdop7I4kvq2i2h50HEj+Jv3iARR89Y7HumSNvaPt5THcHa1hRFYRkm8X5C4ZKupCV7WJuUPGnr5P6JkqlFhQPY= 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 1699633387458970.3860434101082; Fri, 10 Nov 2023 08:23:07 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.630574.983550 (Exim 4.92) (envelope-from ) id 1r1UHP-0006Yo-Nr; Fri, 10 Nov 2023 16:22:47 +0000 Received: by outflank-mailman (output) from mailman id 630574.983550; Fri, 10 Nov 2023 16:22:47 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1r1UHP-0006Yh-L3; Fri, 10 Nov 2023 16:22:47 +0000 Received: by outflank-mailman (input) for mailman id 630574; Fri, 10 Nov 2023 16:22:46 +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 1r1U4k-00048H-Lx for xen-devel@lists.xenproject.org; Fri, 10 Nov 2023 16:09:42 +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 8e91d334-7fe3-11ee-98da-6d05b1d4d9a1; Fri, 10 Nov 2023 17:09:42 +0100 (CET) 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 1211B1F8BF; Fri, 10 Nov 2023 16:09:42 +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 D3B9913398; Fri, 10 Nov 2023 16:09:41 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id ECVUMsVVTmUiCQAAMHmgww (envelope-from ); Fri, 10 Nov 2023 16:09:41 +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: 8e91d334-7fe3-11ee-98da-6d05b1d4d9a1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1699632582; 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=Gi0/c29PpXoSdVTcw0fAZAZaMgimOB0NYPLB5++nb6M=; b=Z30w/aZQLNjYbno+UC74sMltaZTgugAz0+C9+J1GXT8KYvVwYVQGBdlajYAwv90dMQwvvc dWkDmTq9ajmPK39DpTcywWiOKg27O2BmwUCMn4PATOnxyOdemvJFu9wMlmQ8GsLS7wHggY pO+Qni8CV/LdVkVXF/GyB2v7mWbVS58= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Julien Grall , Anthony PERARD , Jason Andryuk Subject: [PATCH v2 17/29] tools/helpers: allocate xenstore event channel for xenstore stubdom Date: Fri, 10 Nov 2023 17:07:52 +0100 Message-Id: <20231110160804.29021-18-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20231110160804.29021-1-jgross@suse.com> References: <20231110160804.29021-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1699633389770100001 Content-Type: text/plain; charset="utf-8" In order to prepare support of PV frontends in xenstore-stubdom, add allocation of a Xenstore event channel to init-xenstore-domain.c. Signed-off-by: Juergen Gross Reviewed-by: Jason Andryuk --- tools/helpers/init-xenstore-domain.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tools/helpers/init-xenstore-domain.c b/tools/helpers/init-xens= tore-domain.c index b2d5df8ba5..140ed610ae 100644 --- a/tools/helpers/init-xenstore-domain.c +++ b/tools/helpers/init-xenstore-domain.c @@ -248,6 +248,13 @@ static int build(xc_interface *xch) dom->cmdline =3D xc_dom_strdup(dom, cmdline); dom->xenstore_domid =3D domid; dom->console_evtchn =3D console_evtchn; + rv =3D xc_evtchn_alloc_unbound(xch, domid, domid); + if ( rv < 0 ) + { + fprintf(stderr, "xc_evtchn_alloc_unbound failed\n"); + goto err; + } + dom->xenstore_evtchn =3D rv; =20 rv =3D xc_dom_mem_init(dom, memory); if ( rv ) --=20 2.35.3 From nobody Thu May 16 01:45:44 2024 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=1699633393; cv=none; d=zohomail.com; s=zohoarc; b=RUIno6IbVboRTNwVOLBl9NRLgufXJ4BMyYBVggguoHCHXZjHpP29lJLT3tAkRLmwkXTQ93xGc3yOW3gLDpCzAXsyClD/dwNxMjJSwo7KrHG716o50SdkgXo0cVB07M+6JOZoRZXtFq4BoXVADNGRs/R8PlHjJ6OFW+AxViuHc0s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1699633393; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=xNe8mrte8l3zt8GAD/vWfM/ysJb8YxQM0ihzz8RCAYI=; b=EdZuHY1kwrVkxa5IPN9JHPHz4pUhFAi/uwOGcb1xLp4d4JBge18e4JL9SdUfd4uBcpkhGwOveY5pa2fHOdw+oQguwUmvKmboKm4Fu4f4xzdp/+F1A42qzL71+ba+wr5p39Qh/oj4fgGRBI9cdzRZqspXB57Fw7f2jleWHfwn2rI= 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 1699633393331462.6363584711995; Fri, 10 Nov 2023 08:23:13 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.630577.983568 (Exim 4.92) (envelope-from ) id 1r1UHQ-0006rL-Qt; Fri, 10 Nov 2023 16:22:48 +0000 Received: by outflank-mailman (output) from mailman id 630577.983568; Fri, 10 Nov 2023 16:22:48 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1r1UHQ-0006py-J4; Fri, 10 Nov 2023 16:22:48 +0000 Received: by outflank-mailman (input) for mailman id 630577; Fri, 10 Nov 2023 16:22:47 +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 1r1U4q-00048H-BB for xen-devel@lists.xenproject.org; Fri, 10 Nov 2023 16:09:48 +0000 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 91eb3491-7fe3-11ee-98da-6d05b1d4d9a1; Fri, 10 Nov 2023 17:09:47 +0100 (CET) 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-out1.suse.de (Postfix) with ESMTPS id A924C219B3; Fri, 10 Nov 2023 16:09:47 +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 7526D13398; Fri, 10 Nov 2023 16:09:47 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id IHdAG8tVTmUqCQAAMHmgww (envelope-from ); Fri, 10 Nov 2023 16:09:47 +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: 91eb3491-7fe3-11ee-98da-6d05b1d4d9a1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1699632587; 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=xNe8mrte8l3zt8GAD/vWfM/ysJb8YxQM0ihzz8RCAYI=; b=ucxlTLAXKFAcGDQbY9fAu0mQd7o0xCebfdSQCjL7xOhZ94FSMZpLWABLGr2nHNTUk1EKH4 xZug1sGyzKygMXjT0O7zLXGMmKC+oBdSAIDhyURU8FCzBkP6IobYQlrHF1bj9jf4wWZ61k vj9ZZPF36c1WVYUjb10Pggdq4Mpot5g= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Julien Grall , Anthony PERARD , Julien Grall Subject: [PATCH v2 18/29] tools/xenstored: rename xenbus_evtchn() Date: Fri, 10 Nov 2023 17:07:53 +0100 Message-Id: <20231110160804.29021-19-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20231110160804.29021-1-jgross@suse.com> References: <20231110160804.29021-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1699633393588100007 Content-Type: text/plain; charset="utf-8" Rename the xenbus_evtchn() function to get_xenbus_evtchn() in order to avoid two externally visible symbols with the same name when Xenstore- stubdom is being built with a Mini-OS with CONFIG_XENBUS set. Signed-off-by: Juergen Gross Reviewed-by: Julien Grall Reviewed-by: Jason Andryuk --- tools/xenstored/core.h | 2 +- tools/xenstored/domain.c | 2 +- tools/xenstored/minios.c | 2 +- tools/xenstored/posix.c | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tools/xenstored/core.h b/tools/xenstored/core.h index ad87199042..480b0f5f7b 100644 --- a/tools/xenstored/core.h +++ b/tools/xenstored/core.h @@ -383,7 +383,7 @@ static inline bool domain_is_unprivileged(const struct = connection *conn) } =20 /* Return the event channel used by xenbus. */ -evtchn_port_t xenbus_evtchn(void); +evtchn_port_t get_xenbus_evtchn(void); =20 /* Write out the pidfile */ void write_pidfile(const char *pidfile); diff --git a/tools/xenstored/domain.c b/tools/xenstored/domain.c index 409b53acf9..6ef136e01f 100644 --- a/tools/xenstored/domain.c +++ b/tools/xenstored/domain.c @@ -1208,7 +1208,7 @@ void dom0_init(void) evtchn_port_t port; struct domain *dom0; =20 - port =3D xenbus_evtchn(); + port =3D get_xenbus_evtchn(); if (port =3D=3D -1) barf_perror("Failed to initialize dom0 port"); =20 diff --git a/tools/xenstored/minios.c b/tools/xenstored/minios.c index b5c3a205e6..0779efbf91 100644 --- a/tools/xenstored/minios.c +++ b/tools/xenstored/minios.c @@ -38,7 +38,7 @@ void init_pipe(int reopen_log_pipe[2]) reopen_log_pipe[1] =3D -1; } =20 -evtchn_port_t xenbus_evtchn(void) +evtchn_port_t get_xenbus_evtchn(void) { return dom0_event; } diff --git a/tools/xenstored/posix.c b/tools/xenstored/posix.c index 6ac45fdb45..7e03dd982d 100644 --- a/tools/xenstored/posix.c +++ b/tools/xenstored/posix.c @@ -111,7 +111,7 @@ void unmap_xenbus(void *interface) munmap(interface, getpagesize()); } =20 -evtchn_port_t xenbus_evtchn(void) +evtchn_port_t get_xenbus_evtchn(void) { int fd; int rc; --=20 2.35.3 From nobody Thu May 16 01:45:44 2024 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=1699632890; cv=none; d=zohomail.com; s=zohoarc; b=Az9htIhmAEK7o66spoXh44msywjYSbRC3TzjGexrhg2XNSGHu0Lg3mysk5S2X9bJrgNlQqyC2PYt14g9xxEaXRN1qxRE5q1WEeQjThaOmB6SGzNiTgL+dkwNbneqCHBZCxUy/HsJnDt7QD1c6g+0tMSobsb5JcywcDN3+LwEfik= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1699632890; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=/eJaaQzJFr9iaY84hbFZ6eF6VnkmvJwoY+5FWl4+J1Y=; b=ZTd+leWi8BSgUMjn1W22SKCE84Pln96K4Qpw0j54JBeEAyjhvGrxOvTswwh6lrL354AA6/axfQmw1PzcvCY7x7xJW5713iHn26qV+lZctaqXbFGDAO1ecmYK/nyeN1LtNNlG5OP3ux9z1JDEJkSmrtc5Is2WK/VZ8+krRWLKhkk= 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 169963289058853.80067870039602; Fri, 10 Nov 2023 08:14:50 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.630522.983433 (Exim 4.92) (envelope-from ) id 1r1U9J-0005rH-Td; Fri, 10 Nov 2023 16:14:25 +0000 Received: by outflank-mailman (output) from mailman id 630522.983433; Fri, 10 Nov 2023 16:14:25 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1r1U9J-0005qY-Oz; Fri, 10 Nov 2023 16:14:25 +0000 Received: by outflank-mailman (input) for mailman id 630522; Fri, 10 Nov 2023 16:14:24 +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 1r1U4v-00048H-SK for xen-devel@lists.xenproject.org; Fri, 10 Nov 2023 16:09:53 +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 953cd4ae-7fe3-11ee-98da-6d05b1d4d9a1; Fri, 10 Nov 2023 17:09:53 +0100 (CET) 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 3DBD51F8BB; Fri, 10 Nov 2023 16:09:53 +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 1A37613398; Fri, 10 Nov 2023 16:09:53 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id EW8zBdFVTmUzCQAAMHmgww (envelope-from ); Fri, 10 Nov 2023 16:09:53 +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: 953cd4ae-7fe3-11ee-98da-6d05b1d4d9a1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1699632593; 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=/eJaaQzJFr9iaY84hbFZ6eF6VnkmvJwoY+5FWl4+J1Y=; b=j+9FbhVRixcfSc4RQoHkyGzsZgSrfAlaFfND6u3bft1XKup8BIMdyGvFS4HeI+a0FSkUXT JHLihcs+sW6R3DBE0rh376sv/QOwbx1MSpp9M8UjMZ3RWhcJ7oF4taK4RoUNLMpTS/J3J9 gXRDE46ttNHHggIqKeHcQiTg6dkfEdg= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Samuel Thibault , Jason Andryuk Subject: [PATCH v2 19/29] stubdom: extend xenstore stubdom configs Date: Fri, 10 Nov 2023 17:07:54 +0100 Message-Id: <20231110160804.29021-20-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20231110160804.29021-1-jgross@suse.com> References: <20231110160804.29021-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1699632891226100003 Content-Type: text/plain; charset="utf-8" Extend the config files of the Xenstore stubdoms to include XENBUS and 9PFRONT items in order to support file based logging. Signed-off-by: Juergen Gross Reviewed-by: Jason Andryuk --- stubdom/xenstore-minios.cfg | 2 +- stubdom/xenstorepvh-minios.cfg | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/stubdom/xenstore-minios.cfg b/stubdom/xenstore-minios.cfg index a41704bb6b..239da519b9 100644 --- a/stubdom/xenstore-minios.cfg +++ b/stubdom/xenstore-minios.cfg @@ -3,7 +3,7 @@ CONFIG_NETFRONT=3Dn CONFIG_FBFRONT=3Dn CONFIG_KBDFRONT=3Dn CONFIG_CONSFRONT=3Dn -CONFIG_XENBUS=3Dn CONFIG_LWIP=3Dn +CONFIG_9PFRONT=3Dy CONFIG_BALLOON=3Dy XEN_INTERFACE_VERSION=3D__XEN_LATEST_INTERFACE_VERSION__ diff --git a/stubdom/xenstorepvh-minios.cfg b/stubdom/xenstorepvh-minios.cfg index 6af51f5753..752b90d7d3 100644 --- a/stubdom/xenstorepvh-minios.cfg +++ b/stubdom/xenstorepvh-minios.cfg @@ -4,7 +4,7 @@ CONFIG_NETFRONT=3Dn CONFIG_FBFRONT=3Dn CONFIG_KBDFRONT=3Dn CONFIG_CONSFRONT=3Dn -CONFIG_XENBUS=3Dn CONFIG_LWIP=3Dn +CONFIG_9PFRONT=3Dy CONFIG_BALLOON=3Dy XEN_INTERFACE_VERSION=3D__XEN_LATEST_INTERFACE_VERSION__ --=20 2.35.3 From nobody Thu May 16 01:45:44 2024 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=1699633466; cv=none; d=zohomail.com; s=zohoarc; b=D7sDczuwRZbnKw0YYpy3+Bp9RS7bPfC9NJgx7PlsJPqmn9PQIM8o/ak/6Z/UxL6YyCK+Tu8u/nRyalvgakTYE5WOdGJ9vkF6yr749rwRbjdwHLX/NUDeMW74LNZKX9FrlTke1RKKIiQWl9af/cX0u7qGq6Xd2d6bMZPsbMWQzjo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1699633466; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=ZmsEZfcmBXuYs7oC5tXzfAlBdGqmVSsNJ0eH3iUymvE=; b=ZA7k3qoHUzq6iw5yQlxcbkdmQEmhVDlBTuA+nMYjZqTRYNtzG6zH3tJxp2VyFpiLsINhl66k49FttBMrYmvoWZZ/QHYaKiIbq/BccJrsHaWyiHM3f/TnoXASXKXlrZufcZPiiTCcyJTV6MspZJRl4GstZBj13BKy/E2VfrNc0cI= 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 1699633466804541.3393990056102; Fri, 10 Nov 2023 08:24:26 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.630593.983600 (Exim 4.92) (envelope-from ) id 1r1UIV-0001cx-Ax; Fri, 10 Nov 2023 16:23:55 +0000 Received: by outflank-mailman (output) from mailman id 630593.983600; Fri, 10 Nov 2023 16:23:55 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1r1UIV-0001cq-7x; Fri, 10 Nov 2023 16:23:55 +0000 Received: by outflank-mailman (input) for mailman id 630593; Fri, 10 Nov 2023 16:23:53 +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 1r1U51-00048H-Hv for xen-devel@lists.xenproject.org; Fri, 10 Nov 2023 16:09:59 +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 9890ad91-7fe3-11ee-98da-6d05b1d4d9a1; Fri, 10 Nov 2023 17:09:59 +0100 (CET) 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 CD1181F8BB; Fri, 10 Nov 2023 16:09:58 +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 9A26213398; Fri, 10 Nov 2023 16:09:58 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id w21FJNZVTmU5CQAAMHmgww (envelope-from ); Fri, 10 Nov 2023 16:09:58 +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: 9890ad91-7fe3-11ee-98da-6d05b1d4d9a1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1699632598; 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=ZmsEZfcmBXuYs7oC5tXzfAlBdGqmVSsNJ0eH3iUymvE=; b=g5/EGGUUsdiG5THU15oyWavMNNBR7tr84++c2GGUfjRATJg2tjQiRMoZfXTaksvkw0QSMG t2hPlCFh3yvJZaFiYi5/rr/JXdVD9W8rPTOdVym+cw+dJVgEXk4zS5s/4Mx8wlhX+aQaDP UCtdR7RdKkJ7sSD+BqClubV2QtfR7sM= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Julien Grall , Anthony PERARD , Jason Andryuk Subject: [PATCH v2 20/29] tools: add 9pfs device to xenstore-stubdom Date: Fri, 10 Nov 2023 17:07:55 +0100 Message-Id: <20231110160804.29021-21-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20231110160804.29021-1-jgross@suse.com> References: <20231110160804.29021-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1699633467947100001 Content-Type: text/plain; charset="utf-8" Add a 9pfs device to Xenstore stubdom in order to allow it to do e.g. logging into a dom0 file. Use the following parameters for the new device: - tag =3D "xen" - type =3D "xen-9pfsd" - path =3D "/var/lib/xen/xenstore" - security-model =3D "none" For now don't limit allowed file space or number of files. Add a new libxl function for adding it similar to the function for adding the console device. Signed-off-by: Juergen Gross Reviewed-by: Jason Andryuk --- V2: - add security_model parameter to new libxl function (Jason Andryuk) --- tools/helpers/init-xenstore-domain.c | 2 ++ tools/include/libxl.h | 17 ++++++++++++++++ tools/libs/light/libxl_9pfs.c | 29 ++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+) diff --git a/tools/helpers/init-xenstore-domain.c b/tools/helpers/init-xens= tore-domain.c index 140ed610ae..591cb3766d 100644 --- a/tools/helpers/init-xenstore-domain.c +++ b/tools/helpers/init-xenstore-domain.c @@ -543,6 +543,8 @@ int main(int argc, char** argv) } libxl_console_add_xenstore(ctx, domid, 0, console_evtchn, console_gfn, NULL); + libxl_p9_add_xenstore(ctx, domid, 0, LIBXL_P9_TYPE_XEN_9PFSD, "xen", + XEN_LIB_DIR"/xenstore", "none", 0, 0, 0, 0, NULL= ); libxl_ctx_free(ctx); =20 fd =3D creat(XEN_RUN_DIR "/xenstored.pid", 0666); diff --git a/tools/include/libxl.h b/tools/include/libxl.h index 907aa0a330..00693264f7 100644 --- a/tools/include/libxl.h +++ b/tools/include/libxl.h @@ -583,6 +583,13 @@ * libxl_console_add_xenstore() in libxl. */ #define LIBXL_HAVE_CONSOLE_ADD_XENSTORE 1 + +/* + * LIBXL_HAVE_P9_ADD_XENSTORE indicates presence of the function + * libxl_p9_add_xenstore() in libxl. + */ +#define LIBXL_HAVE_P9_ADD_XENSTORE 1 + /* * libxl ABI compatibility * @@ -2060,6 +2067,16 @@ int libxl_console_add_xenstore(libxl_ctx *ctx, uint3= 2_t domid, uint32_t backend, const libxl_asyncop_how *ao_how) LIBXL_EXTERNAL_CALLERS_ONLY; =20 +/* libxl_p9_add_xenstore writes the Xenstore entries for a domain's + * primary 9pfs device based on domid, backend type and device parameters. + */ +int libxl_p9_add_xenstore(libxl_ctx *ctx, uint32_t domid, uint32_t backend, + libxl_p9_type type, char *tag, char *path, + char *security_model, unsigned int max_space, + unsigned int max_files, unsigned int max_open_fi= les, + bool auto_delete, const libxl_asyncop_how *ao_ho= w) + LIBXL_EXTERNAL_CALLERS_ONLY; + /* May be called with info_r =3D=3D NULL to check for domain's existence. * Returns ERROR_DOMAIN_NOTFOUND if domain does not exist (used to return * ERROR_INVAL for this scenario). */ diff --git a/tools/libs/light/libxl_9pfs.c b/tools/libs/light/libxl_9pfs.c index 87e9dda8e7..43702e3d9f 100644 --- a/tools/libs/light/libxl_9pfs.c +++ b/tools/libs/light/libxl_9pfs.c @@ -176,6 +176,35 @@ static void libxl__device_p9_add(libxl__egc *egc, uint= 32_t domid, aodev->callback(egc, aodev); } =20 +int libxl_p9_add_xenstore(libxl_ctx *ctx, uint32_t domid, uint32_t backend, + libxl_p9_type type, char *tag, char *path, + char *security_model, unsigned int max_space, + unsigned int max_files, unsigned int max_open_fi= les, + bool auto_delete, const libxl_asyncop_how *ao_ho= w) +{ + AO_CREATE(ctx, domid, ao_how); + libxl__ao_device *aodev; + libxl_device_p9 p9 =3D { .backend_domid =3D backend, + .tag =3D tag, + .path =3D path, + .security_model =3D security_model, + .type =3D type, + .max_space =3D max_space, + .max_files =3D max_files, + .max_open_files =3D max_open_files, + .auto_delete =3D auto_delete, + }; + + GCNEW(aodev); + libxl__prepare_ao_device(ao, aodev); + aodev->action =3D LIBXL__DEVICE_ACTION_ADD; + aodev->callback =3D device_addrm_aocomplete; + + libxl__device_p9_add(egc, domid, &p9, aodev); + + return AO_INPROGRESS; +} + #define libxl_device_p9_list NULL #define libxl_device_p9_compare NULL =20 --=20 2.35.3 From nobody Thu May 16 01:45:44 2024 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=1699633102; cv=none; d=zohomail.com; s=zohoarc; b=TwqD9t05HkKQqMKiKZZEXw/yaCy+WDgKswKX3bOlUkmLqrUjabx5LJm/qsBaQqJnBxyEgGOjSZzaU9wlkX9pS8L6+zAOfzXMCOh9/KhtNjNwSTLZ4DWN4DMA4iHqjf3GkewS0SDUQc+YzZjvOhKycQHQ2XsVV+igzFeLUBRBI10= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1699633102; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=xXrI1g3Tvz8/s3KD+jk6UgdILP23SjhAZanYf4v0CdE=; b=nPOrfF/kLHBhUH5ekwBUNDiKKEUOHLcAPbrPSVp4R+LyP0wp/014UpkADAmfP3HCeWOphWfe7hZNfwbLa+kDY18CZixe4Tt0lIuJHtzxNskV95OcTGpu+Nt72bEtNQZrIgW4QSQrBoiqoYW3S+QI1wVmCJAyYBf3AZQxHrnokrc= 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 1699633102733116.61842397931275; Fri, 10 Nov 2023 08:18:22 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.630551.983500 (Exim 4.92) (envelope-from ) id 1r1UCp-00025M-4f; Fri, 10 Nov 2023 16:18:03 +0000 Received: by outflank-mailman (output) from mailman id 630551.983500; Fri, 10 Nov 2023 16:18:03 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1r1UCp-00025F-1c; Fri, 10 Nov 2023 16:18:03 +0000 Received: by outflank-mailman (input) for mailman id 630551; Fri, 10 Nov 2023 16:18:02 +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 1r1U58-0004cS-6w for xen-devel@lists.xenproject.org; Fri, 10 Nov 2023 16:10:06 +0000 Received: from smtp-out1.suse.de (smtp-out1.suse.de [2001:67c:2178:6::1c]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 9be5011b-7fe3-11ee-9b0e-b553b5be7939; Fri, 10 Nov 2023 17:10:04 +0100 (CET) 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-out1.suse.de (Postfix) with ESMTPS id 6490D219B4; Fri, 10 Nov 2023 16:10:04 +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 34DB813398; Fri, 10 Nov 2023 16:10:04 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 2kyUC9xVTmVVCQAAMHmgww (envelope-from ); Fri, 10 Nov 2023 16:10:04 +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: 9be5011b-7fe3-11ee-9b0e-b553b5be7939 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1699632604; 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=xXrI1g3Tvz8/s3KD+jk6UgdILP23SjhAZanYf4v0CdE=; b=EUKZTg0W+7XorSEy1L1YhxkUCzrrBiMgIauLfCY1hfNf0HLs55rTlEAlJVPfH8ey1ARC7L 2tjNKt2sPStZB/lRJBFVrVGJODWY49v8L8tOwR17JEvI7SGNQV9zGJ82Q/mlAawRrLzhEY YvVFKZQQlCSU8a5r6+MukxmCzG+UtgY= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Julien Grall , Anthony PERARD , Jason Andryuk Subject: [PATCH v2 21/29] tools/xenstored: add early_init() function Date: Fri, 10 Nov 2023 17:07:56 +0100 Message-Id: <20231110160804.29021-22-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20231110160804.29021-1-jgross@suse.com> References: <20231110160804.29021-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1699633104359100001 Content-Type: text/plain; charset="utf-8" Some xenstored initialization needs to be done in the daemon case only, so split it out into a new early_init() function being a stub in the stubdom case. Signed-off-by: Juergen Gross Reviewed-by: Jason Andryuk --- V2: - rename function - move patch earlier in the series --- tools/xenstored/core.c | 6 +----- tools/xenstored/core.h | 3 +++ tools/xenstored/minios.c | 3 +++ tools/xenstored/posix.c | 11 +++++++++++ 4 files changed, 18 insertions(+), 5 deletions(-) diff --git a/tools/xenstored/core.c b/tools/xenstored/core.c index edd07711db..0c14823fb0 100644 --- a/tools/xenstored/core.c +++ b/tools/xenstored/core.c @@ -2933,11 +2933,7 @@ int main(int argc, char *argv[]) if (optind !=3D argc) barf("%s: No arguments desired", argv[0]); =20 - reopen_log(); - - /* Make sure xenstored directory exists. */ - /* Errors ignored here, will be reported when we open files */ - mkdir(xenstore_daemon_rundir(), 0755); + early_init(); =20 if (dofork) { openlog("xenstored", 0, LOG_DAEMON); diff --git a/tools/xenstored/core.h b/tools/xenstored/core.h index 480b0f5f7b..d0ac587f8f 100644 --- a/tools/xenstored/core.h +++ b/tools/xenstored/core.h @@ -35,6 +35,8 @@ #include "list.h" #include "hashtable.h" =20 +#define XENSTORE_LIB_DIR XEN_LIB_DIR "/xenstore" + #ifndef O_CLOEXEC #define O_CLOEXEC 0 /* O_CLOEXEC support is needed for Live Update in the daemon case. */ @@ -384,6 +386,7 @@ static inline bool domain_is_unprivileged(const struct = connection *conn) =20 /* Return the event channel used by xenbus. */ evtchn_port_t get_xenbus_evtchn(void); +void early_init(void); =20 /* Write out the pidfile */ void write_pidfile(const char *pidfile); diff --git a/tools/xenstored/minios.c b/tools/xenstored/minios.c index 0779efbf91..0cdec3ae51 100644 --- a/tools/xenstored/minios.c +++ b/tools/xenstored/minios.c @@ -54,3 +54,6 @@ void unmap_xenbus(void *interface) xengnttab_unmap(*xgt_handle, interface, 1); } =20 +void early_init(void) +{ +} diff --git a/tools/xenstored/posix.c b/tools/xenstored/posix.c index 7e03dd982d..fcb7791bd7 100644 --- a/tools/xenstored/posix.c +++ b/tools/xenstored/posix.c @@ -22,6 +22,7 @@ #include #include #include +#include =20 #include "utils.h" #include "core.h" @@ -157,3 +158,13 @@ void *xenbus_map(void) =20 return addr; } + +void early_init(void) +{ + reopen_log(); + + /* Make sure xenstored directories exist. */ + /* Errors ignored here, will be reported when we open files */ + mkdir(xenstore_daemon_rundir(), 0755); + mkdir(XENSTORE_LIB_DIR, 0755); +} --=20 2.35.3 From nobody Thu May 16 01:45:44 2024 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=1699633401; cv=none; d=zohomail.com; s=zohoarc; b=RsrxuONfBa5Z2S7/+IBOtNAic+IqIXhbOh2pffbesJmTWEgjxKzXuxUpMLNgXoL9m/8LL9jnlvD1lpulL9x+6i60m0sTR4JsJYmzv1a7ED0YdkJPdxdEH4TXIRetpdBUYrj/bpe7hJ2YlqwkMQDOahW2MTEOuLDVGrm/NxXhN1Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1699633401; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=oAZKhBAd6GT93Obj94j3yjFdAss/Va3cfRb6VorS53Y=; b=EasoqiqCTLjdCUJG1hgEHx1f4fOf84yXx2cVfFt+tteNxNH6DJXBIt9X1JZyun4w8ttvwjoC8b8vgW04ieySThhxonStL2X+LyewCv6J9Y2cWnqonTzLsXKZEKd5O7etIlMLg/DZPemkDRN23GcYCdg33ZDDqgJo8ExTkSxr93A= 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 1699633401266509.8613654802049; Fri, 10 Nov 2023 08:23:21 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.630580.983590 (Exim 4.92) (envelope-from ) id 1r1UHg-0008Lp-27; Fri, 10 Nov 2023 16:23:04 +0000 Received: by outflank-mailman (output) from mailman id 630580.983590; Fri, 10 Nov 2023 16:23:04 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1r1UHf-0008Lg-Uw; Fri, 10 Nov 2023 16:23:03 +0000 Received: by outflank-mailman (input) for mailman id 630580; Fri, 10 Nov 2023 16:23:02 +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 1r1U5D-0004cS-RJ for xen-devel@lists.xenproject.org; Fri, 10 Nov 2023 16:10:11 +0000 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 9f34dd96-7fe3-11ee-9b0e-b553b5be7939; Fri, 10 Nov 2023 17:10:10 +0100 (CET) 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-out1.suse.de (Postfix) with ESMTPS id EC087219B4; Fri, 10 Nov 2023 16:10:09 +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 C169613398; Fri, 10 Nov 2023 16:10:09 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id gH/kLeFVTmVeCQAAMHmgww (envelope-from ); Fri, 10 Nov 2023 16:10:09 +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: 9f34dd96-7fe3-11ee-9b0e-b553b5be7939 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1699632609; 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=oAZKhBAd6GT93Obj94j3yjFdAss/Va3cfRb6VorS53Y=; b=pYmsLvxEBdeltPTcFGkEkHv24YTfJNEAC2lyvak5KOpvB+amuNQODE61RgjMGa5hJAVA74 J97NxeTvPXhfG4VWOqCZp+twRFdYig+Tg6zQVK824PZ0iMqke+MmeT4bxQtr55fEnJadUm JwVDVfdGnY33teaiWL2DvaMT9AYyNkU= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Julien Grall , Anthony PERARD Subject: [PATCH v2 22/29] tools/xenstored: get own domid in stubdom case Date: Fri, 10 Nov 2023 17:07:57 +0100 Message-Id: <20231110160804.29021-23-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20231110160804.29021-1-jgross@suse.com> References: <20231110160804.29021-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1699633401652100001 Content-Type: text/plain; charset="utf-8" Obtain the own domid from the Xenstore special grant entry when running as stubdom. Signed-off-by: Juergen Gross --- V2: - replacement of V1 patch (ANdrew Cooper) --- tools/xenstored/core.c | 1 + tools/xenstored/core.h | 1 + tools/xenstored/minios.c | 5 +++++ 3 files changed, 7 insertions(+) diff --git a/tools/xenstored/core.c b/tools/xenstored/core.c index 0c14823fb0..8e271e31f9 100644 --- a/tools/xenstored/core.c +++ b/tools/xenstored/core.c @@ -2738,6 +2738,7 @@ static struct option options[] =3D { int dom0_domid =3D 0; int dom0_event =3D 0; int priv_domid =3D 0; +int stub_domid =3D -1; =20 static unsigned int get_optval_uint(const char *arg) { diff --git a/tools/xenstored/core.h b/tools/xenstored/core.h index d0ac587f8f..3c28007d11 100644 --- a/tools/xenstored/core.h +++ b/tools/xenstored/core.h @@ -361,6 +361,7 @@ do { \ extern int dom0_domid; extern int dom0_event; extern int priv_domid; +extern int stub_domid; extern bool keep_orphans; =20 extern unsigned int timeout_watch_event_msec; diff --git a/tools/xenstored/minios.c b/tools/xenstored/minios.c index 0cdec3ae51..202d70387a 100644 --- a/tools/xenstored/minios.c +++ b/tools/xenstored/minios.c @@ -19,6 +19,8 @@ #include #include "core.h" #include +#include +#include =20 void write_pidfile(const char *pidfile) { @@ -56,4 +58,7 @@ void unmap_xenbus(void *interface) =20 void early_init(void) { + stub_domid =3D evtchn_get_domid(); + if (stub_domid =3D=3D DOMID_INVALID) + barf("could not get own domid"); } --=20 2.35.3 From nobody Thu May 16 01:45:44 2024 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=1699632992; cv=none; d=zohomail.com; s=zohoarc; b=Z23SwhHLvqxpi5+mImT6b7K7LIPHoqLCaKLr8tpykTMLiETPyYTeI8ou1bvcbrFiLtq5TnFLqKNtzHQLAovon4SYLGTRQio1q7VtjkBxjgFX+2tiMXNnL6s5AOkoDxC36QpYBySYkntRY4qjF/VyX2hhpSWr8nRMjT2PS1WydUo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1699632992; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=OyPsqGgDSHfZ39Pq/Ikf6PwNSKByuBj9AES+Iv7pAgI=; b=KR+gsGZ1XL2ode4MysJseJvhEdSimGqRS/Cf/Lgzl/tCUmVpwhidv4evyK1tnq3LIn1qnP5o936GAaAmpJ38u/vOpYBlEgPDK4IIWrboMONPSi3sgsX3zymsKVAb6kvsR7TvzYAhAlWgymqJqAIRC/zxmGby+jl/UhEvQOe/Fyg= 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 1699632992198638.8613962981054; Fri, 10 Nov 2023 08:16:32 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.630538.983480 (Exim 4.92) (envelope-from ) id 1r1UB2-0000az-DX; Fri, 10 Nov 2023 16:16:12 +0000 Received: by outflank-mailman (output) from mailman id 630538.983480; Fri, 10 Nov 2023 16:16:12 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1r1UB2-0000an-Af; Fri, 10 Nov 2023 16:16:12 +0000 Received: by outflank-mailman (input) for mailman id 630538; Fri, 10 Nov 2023 16:16:11 +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 1r1U5J-0004cS-9Y for xen-devel@lists.xenproject.org; Fri, 10 Nov 2023 16:10:17 +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 a2861be8-7fe3-11ee-9b0e-b553b5be7939; Fri, 10 Nov 2023 17:10:15 +0100 (CET) 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 812551F8BB; Fri, 10 Nov 2023 16:10:15 +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 5557C13398; Fri, 10 Nov 2023 16:10:15 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 7heiE+dVTmVsCQAAMHmgww (envelope-from ); Fri, 10 Nov 2023 16:10:15 +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: a2861be8-7fe3-11ee-9b0e-b553b5be7939 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1699632615; 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=OyPsqGgDSHfZ39Pq/Ikf6PwNSKByuBj9AES+Iv7pAgI=; b=Asni5z0LeZJAE+mbtPoJnydmK4eCw6uieINjJDGR/LNQ5QrKT0S08AWEJpqOoSOJgmkJh8 rD8tsV9BzhY+uxV+Fudc8dYyI8qvG3Bdqgu75ST5KEfS2X0s2N0EtRcY1rVRvJnNgV4FYZ G3Zrwwge18F/vvREzqnLZrHcc3PUnRI= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Julien Grall , Anthony PERARD , Jason Andryuk Subject: [PATCH v2 23/29] tools/xenstored: rework ring page (un)map functions Date: Fri, 10 Nov 2023 17:07:58 +0100 Message-Id: <20231110160804.29021-24-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20231110160804.29021-1-jgross@suse.com> References: <20231110160804.29021-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1699632993777100001 Content-Type: text/plain; charset="utf-8" When [un]mapping the ring page of a Xenstore client, different actions are required for "normal" guests and dom0. Today this distinction is made at call site. Move this distinction into [un]map_interface() instead, avoiding code duplication and preparing special handling for [un]mapping the stub domain's ring page. Signed-off-by: Juergen Gross Reviewed-by: Jason Andryuk Reviewed-by: Julien Grall --- tools/xenstored/domain.c | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/tools/xenstored/domain.c b/tools/xenstored/domain.c index 6ef136e01f..58b0942043 100644 --- a/tools/xenstored/domain.c +++ b/tools/xenstored/domain.c @@ -497,14 +497,20 @@ static const struct interface_funcs domain_funcs =3D { =20 static void *map_interface(domid_t domid) { + if (domid =3D=3D xenbus_master_domid()) + return xenbus_map(); + return xengnttab_map_grant_ref(*xgt_handle, domid, GNTTAB_RESERVED_XENSTORE, PROT_READ|PROT_WRITE); } =20 -static void unmap_interface(void *interface) +static void unmap_interface(domid_t domid, void *interface) { - xengnttab_unmap(*xgt_handle, interface, 1); + if (domid =3D=3D xenbus_master_domid()) + unmap_xenbus(interface); + else + xengnttab_unmap(*xgt_handle, interface, 1); } =20 static int domain_tree_remove_sub(const void *ctx, struct connection *conn, @@ -594,14 +600,8 @@ static int destroy_domain(void *_domain) eprintf("> Unbinding port %i failed!\n", domain->port); } =20 - if (domain->interface) { - /* Domain 0 was mapped by dom0_init, so it must be unmapped - using munmap() and not the grant unmap call. */ - if (domain->domid =3D=3D dom0_domid) - unmap_xenbus(domain->interface); - else - unmap_interface(domain->interface); - } + if (domain->interface) + unmap_interface(domain->domid, domain->interface); =20 fire_special_watches("@releaseDomain"); =20 @@ -966,18 +966,13 @@ static struct domain *introduce_domain(const void *ct= x, return NULL; =20 if (!domain->introduced) { - interface =3D is_master_domain ? xenbus_map() - : map_interface(domid); + interface =3D map_interface(domid); if (!interface && !restore) return NULL; if (new_domain(domain, port, restore)) { rc =3D errno; - if (interface) { - if (is_master_domain) - unmap_xenbus(interface); - else - unmap_interface(interface); - } + if (interface) + unmap_interface(domid, interface); errno =3D rc; return NULL; } --=20 2.35.3 From nobody Thu May 16 01:45:44 2024 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=1699632906; cv=none; d=zohomail.com; s=zohoarc; b=T+DtB9M0j1NT2EuS6wizKH9lXxpcozmFrJ86ouYWvXgfifEFvpxhmLjoci297IVeAJuabM1URqbm9H5/bOT63l7tR4NzsdZ/bm3zC0jg5H2qRdeoyFdhwZKZlmZo/qh4GBOsxj8oaEG8ogFdVRxz2g9a8/09WJiia2TVwds6Wso= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1699632906; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=qDO/X/0jg8xpOn7q+RDSIPZg5lBqWAwK528RC/aXZU4=; b=R9O0PhWKi3EoStk3SOdkvQUBAZ6KTJApnlUzgmxHjkFVllvNLcjx45thgCsiA7KbvjKOJIanBMoeIlSgcYYf47s9spsaeSKy2/HHx5JVTAWuLgoWPVnETAmVTe1tvviK2n+69V0O+t5Dgmk0ZWPN8CoiI+s+hyUGdht461rKgmQ= 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 1699632906177832.9319757241019; Fri, 10 Nov 2023 08:15:06 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.630527.983466 (Exim 4.92) (envelope-from ) id 1r1U9e-00077a-4X; Fri, 10 Nov 2023 16:14:46 +0000 Received: by outflank-mailman (output) from mailman id 630527.983466; Fri, 10 Nov 2023 16:14:46 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1r1U9d-000773-Ut; Fri, 10 Nov 2023 16:14:45 +0000 Received: by outflank-mailman (input) for mailman id 630527; Fri, 10 Nov 2023 16:14:44 +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 1r1U5O-0004cS-TF for xen-devel@lists.xenproject.org; Fri, 10 Nov 2023 16:10:22 +0000 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id a5da948c-7fe3-11ee-9b0e-b553b5be7939; Fri, 10 Nov 2023 17:10:21 +0100 (CET) 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-out1.suse.de (Postfix) with ESMTPS id 1E0392187C; Fri, 10 Nov 2023 16:10:21 +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 E79B913398; Fri, 10 Nov 2023 16:10:20 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id umUuN+xVTmV+CQAAMHmgww (envelope-from ); Fri, 10 Nov 2023 16:10:20 +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: a5da948c-7fe3-11ee-9b0e-b553b5be7939 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1699632621; 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=qDO/X/0jg8xpOn7q+RDSIPZg5lBqWAwK528RC/aXZU4=; b=Xa/lnhV47bVWI+B+KDHnUvXzthekQC5dAH6tjxmq0f96KHjPmcB32VJTyp53msnkhAksoe QLCHVD2/u/pqeTkJ4xeG8Pr9Jb9MNKhu2JSEUqkHweH42tNWEzcqv31w2sbQjwwpAsxM9+ dYN8zL4rAxLVvxFRBKKRplYHIVg+D0o= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Julien Grall , Anthony PERARD Subject: [PATCH v2 24/29] tools/xenstored: split domain_init() Date: Fri, 10 Nov 2023 17:07:59 +0100 Message-Id: <20231110160804.29021-25-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20231110160804.29021-1-jgross@suse.com> References: <20231110160804.29021-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1699632907294100001 Content-Type: text/plain; charset="utf-8" Today domain_init() is called either just before calling dom0_init() in case no live update is being performed, or it is called after reading the global state from read_state_global(), as the event channel fd is needed. Split up domain_init() into a preparation part which can be called unconditionally, and in a part setting up the event channel handle. Note that there is no chance that chk_domain_generation() can be called now before xc_handle has been setup, so there is no need for the related special case anymore. Signed-off-by: Juergen Gross --- tools/xenstored/core.c | 2 ++ tools/xenstored/domain.c | 12 ++++++------ tools/xenstored/domain.h | 1 + 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/tools/xenstored/core.c b/tools/xenstored/core.c index 8e271e31f9..b9ec50b34c 100644 --- a/tools/xenstored/core.c +++ b/tools/xenstored/core.c @@ -2960,6 +2960,8 @@ int main(int argc, char *argv[]) =20 init_pipe(reopen_log_pipe); =20 + domain_static_init(); + /* Listen to hypervisor. */ if (!no_domain_init && !live_update) { domain_init(-1); diff --git a/tools/xenstored/domain.c b/tools/xenstored/domain.c index 58b0942043..fa17f68618 100644 --- a/tools/xenstored/domain.c +++ b/tools/xenstored/domain.c @@ -1224,10 +1224,8 @@ static int domeq_fn(const void *key1, const void *ke= y2) return *(const unsigned int *)key1 =3D=3D *(const unsigned int *)key2; } =20 -void domain_init(int evtfd) +void domain_static_init(void) { - int rc; - /* Start with a random rather low domain count for the hashtable. */ domhash =3D create_hashtable(NULL, "domains", domhash_fn, domeq_fn, 0); if (!domhash) @@ -1258,6 +1256,11 @@ void domain_init(int evtfd) xengnttab_set_max_grants(*xgt_handle, DOMID_FIRST_RESERVED); =20 talloc_set_destructor(xgt_handle, close_xgt_handle); +} + +void domain_init(int evtfd) +{ + int rc; =20 if (evtfd < 0) xce_handle =3D xenevtchn_open(NULL, XENEVTCHN_NO_CLOEXEC); @@ -1291,9 +1294,6 @@ static bool chk_domain_generation(unsigned int domid,= uint64_t gen) { struct domain *d; =20 - if (!xc_handle && domid =3D=3D dom0_domid) - return true; - d =3D find_domain_struct(domid); =20 return d && d->generation <=3D gen; diff --git a/tools/xenstored/domain.h b/tools/xenstored/domain.h index 7625dca8cd..6c00540311 100644 --- a/tools/xenstored/domain.h +++ b/tools/xenstored/domain.h @@ -82,6 +82,7 @@ int do_get_domain_path(const void *ctx, struct connection= *conn, int do_reset_watches(const void *ctx, struct connection *conn, struct buffered_data *in); =20 +void domain_static_init(void); void domain_init(int evtfd); void dom0_init(void); void domain_deinit(void); --=20 2.35.3 From nobody Thu May 16 01:45:44 2024 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=1699632906; cv=none; d=zohomail.com; s=zohoarc; b=kUc8A1qIW6+TJfCKOWPy7m1KfAMDStZXBqxmnNedK5R/yMppH+dQtjVWyQEJFuJeIDsqnxQbizT+ds59oNH7RcbzuDp4HlsfjhBXhJRRr78NXA3LWHLli/WE39adJ5wlZ8wpvWeRDOff1J20ZwB0dmulIiQNMqG1L3OrjxZGaA0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1699632906; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=mAbYvWWcrF68SCYMWW0W6XWNuB7mZzftdWlLKLvl9pU=; b=WJEzOslRmdYtyGZ1ocehMbEIgUylLrdZhkKtgP9APObD2xEm8MdxJfCz4YAJ/PUtGugww2A2L/PRoVsgo3Mrb1rdsh1T81IZkwIcRCwGSf++PubA0jdoQ4dyGKMsb/1WlfNvWs+0GEBa8DQDG3eFPP4E6w8hnvimfqwOL26Z3Sk= 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 1699632906159122.46410787035109; Fri, 10 Nov 2023 08:15:06 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.630526.983459 (Exim 4.92) (envelope-from ) id 1r1U9d-00073y-PS; Fri, 10 Nov 2023 16:14:45 +0000 Received: by outflank-mailman (output) from mailman id 630526.983459; Fri, 10 Nov 2023 16:14:45 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1r1U9d-00073r-Mf; Fri, 10 Nov 2023 16:14:45 +0000 Received: by outflank-mailman (input) for mailman id 630526; Fri, 10 Nov 2023 16:14:44 +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 1r1U5U-0004cS-Dt for xen-devel@lists.xenproject.org; Fri, 10 Nov 2023 16:10:28 +0000 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id a92a9192-7fe3-11ee-9b0e-b553b5be7939; Fri, 10 Nov 2023 17:10:26 +0100 (CET) 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-out1.suse.de (Postfix) with ESMTPS id A64232187C; Fri, 10 Nov 2023 16:10:26 +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 7A11813398; Fri, 10 Nov 2023 16:10:26 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id dKiIHPJVTmWHCQAAMHmgww (envelope-from ); Fri, 10 Nov 2023 16:10:26 +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: a92a9192-7fe3-11ee-9b0e-b553b5be7939 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1699632626; 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=mAbYvWWcrF68SCYMWW0W6XWNuB7mZzftdWlLKLvl9pU=; b=DVUj5/b6cpWnCnGmCTFbetK58RT9pBIJUTQXyRAHou6IK0XzoQ5554iTmQf/oWfGJadQMi u4dIppB5EArsihlHbayzARU95IQ/gLlOBjrYLdDooFnQYClowIVx7XY8xZ4GG8BVRT3VkT ymiIhwAQA7WUy7xxq6NEC4ejYJ6saeo= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Julien Grall , Anthony PERARD Subject: [PATCH v2 25/29] tools/xenstored: map stubdom interface Date: Fri, 10 Nov 2023 17:08:00 +0100 Message-Id: <20231110160804.29021-26-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20231110160804.29021-1-jgross@suse.com> References: <20231110160804.29021-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1699632907312100002 Content-Type: text/plain; charset="utf-8" When running as stubdom, map the stubdom's Xenstore ring page in order to support using the 9pfs frontend. Signed-off-by: Juergen Gross --- tools/xenstored/core.c | 2 ++ tools/xenstored/domain.c | 27 ++++++++++++++++++++++++++- tools/xenstored/domain.h | 1 + 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/tools/xenstored/core.c b/tools/xenstored/core.c index b9ec50b34c..4a9d874f17 100644 --- a/tools/xenstored/core.c +++ b/tools/xenstored/core.c @@ -2991,6 +2991,8 @@ int main(int argc, char *argv[]) lu_read_state(); #endif =20 + stubdom_init(); + check_store(); =20 /* Get ready to listen to the tools. */ diff --git a/tools/xenstored/domain.c b/tools/xenstored/domain.c index fa17f68618..162b87b460 100644 --- a/tools/xenstored/domain.c +++ b/tools/xenstored/domain.c @@ -37,6 +37,10 @@ #include #include =20 +#ifdef __MINIOS__ +#include +#endif + static xc_interface **xc_handle; xengnttab_handle **xgt_handle; static evtchn_port_t virq_port; @@ -500,6 +504,11 @@ static void *map_interface(domid_t domid) if (domid =3D=3D xenbus_master_domid()) return xenbus_map(); =20 +#ifdef __MINIOS__ + if (domid =3D=3D stub_domid) + return xenstore_buf; +#endif + return xengnttab_map_grant_ref(*xgt_handle, domid, GNTTAB_RESERVED_XENSTORE, PROT_READ|PROT_WRITE); @@ -509,7 +518,7 @@ static void unmap_interface(domid_t domid, void *interf= ace) { if (domid =3D=3D xenbus_master_domid()) unmap_xenbus(interface); - else + else if (domid !=3D stub_domid) xengnttab_unmap(*xgt_handle, interface, 1); } =20 @@ -1214,6 +1223,22 @@ void dom0_init(void) xenevtchn_notify(xce_handle, dom0->port); } =20 +void stubdom_init(void) +{ +#ifdef __MINIOS__ + struct domain *stubdom; + + if (stub_domid < 0) + return; + + stubdom =3D introduce_domain(NULL, stub_domid, xenbus_evtchn, false); + if (!stubdom) + barf_perror("Failed to initialize stubdom"); + + xenevtchn_notify(xce_handle, stubdom->port); +#endif +} + static unsigned int domhash_fn(const void *k) { return *(const unsigned int *)k; diff --git a/tools/xenstored/domain.h b/tools/xenstored/domain.h index 6c00540311..49c60c56bf 100644 --- a/tools/xenstored/domain.h +++ b/tools/xenstored/domain.h @@ -85,6 +85,7 @@ int do_reset_watches(const void *ctx, struct connection *= conn, void domain_static_init(void); void domain_init(int evtfd); void dom0_init(void); +void stubdom_init(void); void domain_deinit(void); void ignore_connection(struct connection *conn, unsigned int err); =20 --=20 2.35.3 From nobody Thu May 16 01:45:44 2024 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=1699633060; cv=none; d=zohomail.com; s=zohoarc; b=k8DSmxytHveq1p3ve2LaqtF/bd0jgGwB+UEJH2b59D8N7zU73ysS3Xf4bUklNB32BpnGxyn2ikeuWspkWjyHiF5+h2dDmZsyp1iE6NPW4+e/zb0tvII6A6PrNJ/WlhAG/OI050HjI5bdZykJLbA26Vx3FZmzEJcy3lCoc8he4D8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1699633060; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Vjpc0T/4VDXSdpS0hg0yt0ghHsFzK4h1yp4x3xySp2A=; b=aHOww3kfTbDxNeEfMa0lsZqPti2I5C8RYAolr+5tnf6RuSLYDZUmYS03Dsj7+oBzKFkpVt58TpnadbRah4ZUMfD/1uCdNMZErQ4oT78myI7uKzIJG5jccYzR2H+KYauNzoZ10M36MlOb5hxEBO8UZc2zpzWkhth7zx5OeAQ/QF4= 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 1699633060375284.3761253076393; Fri, 10 Nov 2023 08:17:40 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.630546.983489 (Exim 4.92) (envelope-from ) id 1r1UC8-0001Q6-Mt; Fri, 10 Nov 2023 16:17:20 +0000 Received: by outflank-mailman (output) from mailman id 630546.983489; Fri, 10 Nov 2023 16:17: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 1r1UC8-0001Pz-K2; Fri, 10 Nov 2023 16:17:20 +0000 Received: by outflank-mailman (input) for mailman id 630546; Fri, 10 Nov 2023 16:17:19 +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 1r1U5a-0004cS-2b for xen-devel@lists.xenproject.org; Fri, 10 Nov 2023 16:10:34 +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 ac846114-7fe3-11ee-9b0e-b553b5be7939; Fri, 10 Nov 2023 17:10:32 +0100 (CET) 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 49A921F8BD; Fri, 10 Nov 2023 16:10:32 +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 18D7613398; Fri, 10 Nov 2023 16:10:32 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id ubq6BPhVTmWSCQAAMHmgww (envelope-from ); Fri, 10 Nov 2023 16:10:32 +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: ac846114-7fe3-11ee-9b0e-b553b5be7939 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1699632632; 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=Vjpc0T/4VDXSdpS0hg0yt0ghHsFzK4h1yp4x3xySp2A=; b=UWQ1RfvWe7PzM+1PAIbvRRjdmVKfRv8umPLDKPIbGnGzLw0XROY+nREvsGOO9HtMH27Efd 4o0zmdHM6ehW3nrFSeDrFTjSAfEFlKjxD2+DlMfqm+qLw0cKntpft2llj2mBZYj3VuVDTJ 9HOmUIo5r9ewC648rFQTe1ycIjia7aU= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Julien Grall , Anthony PERARD , Jason Andryuk Subject: [PATCH v2 26/29] tools/xenstored: mount 9pfs device in stubdom Date: Fri, 10 Nov 2023 17:08:01 +0100 Message-Id: <20231110160804.29021-27-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20231110160804.29021-1-jgross@suse.com> References: <20231110160804.29021-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1699633062074100001 Content-Type: text/plain; charset="utf-8" Mount the 9pfs device in stubdom enabling it to use files. This has to happen in a worker thread in order to allow the main thread handling the required Xenstore accesses in parallel. Signed-off-by: Juergen Gross Reviewed-by: Jason Andryuk --- tools/xenstored/core.h | 4 ++++ tools/xenstored/domain.c | 2 ++ tools/xenstored/minios.c | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+) diff --git a/tools/xenstored/core.h b/tools/xenstored/core.h index 3c28007d11..a0d3592961 100644 --- a/tools/xenstored/core.h +++ b/tools/xenstored/core.h @@ -389,6 +389,10 @@ static inline bool domain_is_unprivileged(const struct= connection *conn) evtchn_port_t get_xenbus_evtchn(void); void early_init(void); =20 +#ifdef __MINIOS__ +void mount_9pfs(void); +#endif + /* Write out the pidfile */ void write_pidfile(const char *pidfile); =20 diff --git a/tools/xenstored/domain.c b/tools/xenstored/domain.c index 162b87b460..4263c1360f 100644 --- a/tools/xenstored/domain.c +++ b/tools/xenstored/domain.c @@ -1236,6 +1236,8 @@ void stubdom_init(void) barf_perror("Failed to initialize stubdom"); =20 xenevtchn_notify(xce_handle, stubdom->port); + + mount_9pfs(); #endif } =20 diff --git a/tools/xenstored/minios.c b/tools/xenstored/minios.c index 202d70387a..fddbede869 100644 --- a/tools/xenstored/minios.c +++ b/tools/xenstored/minios.c @@ -19,8 +19,16 @@ #include #include "core.h" #include +#include #include #include +#include +#include +#include + +#define P9_STATE_PATH "device/9pfs/0/state" + +static void *p9_device; =20 void write_pidfile(const char *pidfile) { @@ -62,3 +70,31 @@ void early_init(void) if (stub_domid =3D=3D DOMID_INVALID) barf("could not get own domid"); } + +static void mount_thread(void *p) +{ + xenbus_event_queue events =3D NULL; + char *err; + char *dummy; + + free(xenbus_watch_path_token(XBT_NIL, P9_STATE_PATH, "9pfs", &events)); + + for (;;) { + xenbus_wait_for_watch(&events); + err =3D xenbus_read(XBT_NIL, P9_STATE_PATH, &dummy); + if (!err) + break; + free(err); + } + + free(dummy); + + free(xenbus_unwatch_path_token(XBT_NIL, P9_STATE_PATH, "9pfs")); + + p9_device =3D init_9pfront(0, XENSTORE_LIB_DIR); +} + +void mount_9pfs(void) +{ + create_thread("mount-9pfs", mount_thread, NULL); +} --=20 2.35.3 From nobody Thu May 16 01:45:44 2024 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=1699633388; cv=none; d=zohomail.com; s=zohoarc; b=mBWWI3I5mMmZ/U9Z4aU9mclu2dPHNqPqDbu+4YcZZPS49wc3gSuS3wwi8CwEr616Gy20HbQr3454hEef2Kk1yU3e8URvi35tukvgiaA1mwq0QvnTL4PjII2icGytBx1EF/cA72XtT9xPAacnfjINc8Hshl8z9tXT0Edzcm04oZ8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1699633388; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=EdPFyHzBpfLl8phFJP9JfSgms8FOuRsGhsZ9dt1Y3Sc=; b=O7uXBJmm2QPbvb/yUxGgVMRGo8Nn9mX/voWBc28IusfY0Ub9mCc3iG5jb4xsaLvuDycClmoCEyeShqmTs/r9yJR7vCOIIV72tMQxPvwA71siADrf0/YMXv5nTAjdvUMkcfUjH6RyLZmaAd+BGCUUhafPu6yAQAfdKMjpuhUgPTA= 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 1699633388832940.7355106032867; Fri, 10 Nov 2023 08:23:08 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.630575.983556 (Exim 4.92) (envelope-from ) id 1r1UHQ-0006c1-2o; Fri, 10 Nov 2023 16:22:48 +0000 Received: by outflank-mailman (output) from mailman id 630575.983556; Fri, 10 Nov 2023 16:22:48 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1r1UHP-0006bb-Sk; Fri, 10 Nov 2023 16:22:47 +0000 Received: by outflank-mailman (input) for mailman id 630575; Fri, 10 Nov 2023 16:22:46 +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 1r1U5f-0004cS-Og for xen-devel@lists.xenproject.org; Fri, 10 Nov 2023 16:10:39 +0000 Received: from smtp-out2.suse.de (smtp-out2.suse.de [2001:67c:2178:6::1d]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id afde8a42-7fe3-11ee-9b0e-b553b5be7939; Fri, 10 Nov 2023 17:10:38 +0100 (CET) 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 E007D1F8BD; Fri, 10 Nov 2023 16:10:37 +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 AF21513398; Fri, 10 Nov 2023 16:10:37 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id e4pqKf1VTmWeCQAAMHmgww (envelope-from ); Fri, 10 Nov 2023 16:10:37 +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: afde8a42-7fe3-11ee-9b0e-b553b5be7939 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1699632637; 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=EdPFyHzBpfLl8phFJP9JfSgms8FOuRsGhsZ9dt1Y3Sc=; b=m0XrOh53fEJ9STIBbKVJWxUtB8+DijG8ygb8l3kfLXPp1nI7/bIGjudfFj539KZHZylQ5S hLXY7mZIZ2HflDL+s7bVUCeqd396OPLRW0M0u4IlOVO1LOBT1GyyNf0zjSa2bK5SK4JHp7 iTUthuAWy5/5jovqiK3qhEaE8AQx2fs= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Julien Grall , Anthony PERARD , Jason Andryuk Subject: [PATCH v2 27/29] tools/xenstored: add helpers for filename handling Date: Fri, 10 Nov 2023 17:08:02 +0100 Message-Id: <20231110160804.29021-28-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20231110160804.29021-1-jgross@suse.com> References: <20231110160804.29021-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1699633389798100002 Content-Type: text/plain; charset="utf-8" Add some helpers for handling filenames which might need different implementations between stubdom and daemon environments: - expansion of relative filenames (those are not really defined today, just expand them to be relative to /var/lib/xen/xenstore) - expansion of xenstore_daemon_rundir() (used e.g. for saving the state file in case of live update - needs to be unchanged in the daemon case, but should result in /var/lib/xen/xenstore for stubdom) Signed-off-by: Juergen Gross Reviewed-by: Jason Andryuk --- tools/xenstored/core.c | 9 ++++++++- tools/xenstored/core.h | 3 +++ tools/xenstored/lu_daemon.c | 4 ++-- tools/xenstored/minios.c | 5 +++++ tools/xenstored/posix.c | 5 +++++ 5 files changed, 23 insertions(+), 3 deletions(-) diff --git a/tools/xenstored/core.c b/tools/xenstored/core.c index 4a9d874f17..77befd24c9 100644 --- a/tools/xenstored/core.c +++ b/tools/xenstored/core.c @@ -158,6 +158,13 @@ void trace_destroy(const void *data, const char *type) trace("obj: DESTROY %s %p\n", type, data); } =20 +char *absolute_filename(const void *ctx, const char *filename) +{ + if (filename[0] !=3D '/') + return talloc_asprintf(ctx, XENSTORE_LIB_DIR "/%s", filename); + return talloc_strdup(ctx, filename); +} + /** * Signal handler for SIGHUP, which requests that the trace log is reopened * (in the main loop). A single byte is written to reopen_log_pipe, to aw= aken @@ -2983,7 +2990,7 @@ int main(int argc, char *argv[]) =20 signal(SIGHUP, trigger_reopen_log); if (tracefile) - tracefile =3D talloc_strdup(NULL, tracefile); + tracefile =3D absolute_filename(NULL, tracefile); =20 #ifndef NO_LIVE_UPDATE /* Read state in case of live update. */ diff --git a/tools/xenstored/core.h b/tools/xenstored/core.h index a0d3592961..51e1dddb22 100644 --- a/tools/xenstored/core.h +++ b/tools/xenstored/core.h @@ -393,6 +393,9 @@ void early_init(void); void mount_9pfs(void); #endif =20 +const char *xenstore_rundir(void); +char *absolute_filename(const void *ctx, const char *filename); + /* Write out the pidfile */ void write_pidfile(const char *pidfile); =20 diff --git a/tools/xenstored/lu_daemon.c b/tools/xenstored/lu_daemon.c index 71bcabadd3..6351111ab0 100644 --- a/tools/xenstored/lu_daemon.c +++ b/tools/xenstored/lu_daemon.c @@ -24,7 +24,7 @@ void lu_get_dump_state(struct lu_dump_state *state) state->size =3D 0; =20 state->filename =3D talloc_asprintf(NULL, "%s/state_dump", - xenstore_daemon_rundir()); + xenstore_rundir()); if (!state->filename) barf("Allocation failure"); =20 @@ -65,7 +65,7 @@ FILE *lu_dump_open(const void *ctx) int fd; =20 filename =3D talloc_asprintf(ctx, "%s/state_dump", - xenstore_daemon_rundir()); + xenstore_rundir()); if (!filename) return NULL; =20 diff --git a/tools/xenstored/minios.c b/tools/xenstored/minios.c index fddbede869..cfc2377857 100644 --- a/tools/xenstored/minios.c +++ b/tools/xenstored/minios.c @@ -98,3 +98,8 @@ void mount_9pfs(void) { create_thread("mount-9pfs", mount_thread, NULL); } + +const char *xenstore_rundir(void) +{ + return XENSTORE_LIB_DIR; +} diff --git a/tools/xenstored/posix.c b/tools/xenstored/posix.c index fcb7791bd7..76f5c9ab84 100644 --- a/tools/xenstored/posix.c +++ b/tools/xenstored/posix.c @@ -168,3 +168,8 @@ void early_init(void) mkdir(xenstore_daemon_rundir(), 0755); mkdir(XENSTORE_LIB_DIR, 0755); } + +const char *xenstore_rundir(void) +{ + return xenstore_daemon_rundir(); +} --=20 2.35.3 From nobody Thu May 16 01:45:44 2024 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=1699632675; cv=none; d=zohomail.com; s=zohoarc; b=hQzRdzW6m1kp0i3EeXQF4p2nWmsYZQTZNOgrY1SdjboQFzZGPp1ygYc37iOjqP4bKpO/E7NHnEsu38Go0unpAck8L/5cwL/0fU2iQrzMIvyIOlXEdjTVmoyDihha4zhNc7wrC7XgFPjDD2P/DCQtwmTAC2doUPZDFrQC2Zto+s8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1699632675; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=nTwqfROeJryVbG+zGDI1eHpfuMSuaLvCQQtzYJfCoiA=; b=SuTs46XZFIr3Tq8v7I7/gRexsGs5eN+M/RIu8zg7AJUZ+hnumXDB6paP0zqpUir9PoNRV4AHQ81+sCm36Pmkh2KNyYr+2S8G8G/OthlmDt/0V6QZ2K3XsPHutnCGaqyAS38lt2+ypHmJuEJ6LgkEo8GQV9UR3j1U+3St7dPrReM= 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 1699632675199215.5826598950041; Fri, 10 Nov 2023 08:11:15 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.630496.983399 (Exim 4.92) (envelope-from ) id 1r1U5l-0002wG-MI; Fri, 10 Nov 2023 16:10:45 +0000 Received: by outflank-mailman (output) from mailman id 630496.983399; Fri, 10 Nov 2023 16:10:45 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1r1U5l-0002w9-Jf; Fri, 10 Nov 2023 16:10:45 +0000 Received: by outflank-mailman (input) for mailman id 630496; Fri, 10 Nov 2023 16:10:44 +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 1r1U5k-0002ug-M7 for xen-devel@lists.xenproject.org; Fri, 10 Nov 2023 16:10:44 +0000 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id b332abae-7fe3-11ee-98da-6d05b1d4d9a1; Fri, 10 Nov 2023 17:10:43 +0100 (CET) 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-out1.suse.de (Postfix) with ESMTPS id 7FE1F2187C; Fri, 10 Nov 2023 16:10:43 +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 4D06913398; Fri, 10 Nov 2023 16:10:43 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id al5oEQNWTmWoCQAAMHmgww (envelope-from ); Fri, 10 Nov 2023 16:10:43 +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: b332abae-7fe3-11ee-98da-6d05b1d4d9a1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1699632643; 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=nTwqfROeJryVbG+zGDI1eHpfuMSuaLvCQQtzYJfCoiA=; b=RfWGZinRrRZXatry7aWM44E0EugGScZO8EY+COaF39FnMJ0L2nHzIdWHyYhe01fSp9Ggvx koEdsl8rqUB52mrn52sFcde5+r+1T4dlxVKk585dNo1PGHTc0CIya53xZ+j3Z6iNNyP47E YC84SwXTdFljWgQIhD0TroS+6PweTYM= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Anthony PERARD , Julien Grall , Jason Andryuk Subject: [PATCH v2 28/29] tools/xenstored: support complete log capabilities in stubdom Date: Fri, 10 Nov 2023 17:08:03 +0100 Message-Id: <20231110160804.29021-29-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20231110160804.29021-1-jgross@suse.com> References: <20231110160804.29021-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1699632676357100001 Content-Type: text/plain; charset="utf-8" With 9pfs being fully available in Xenstore-stubdom now, there is no reason to not fully support all logging capabilities in stubdom. Open the logfile on stubdom only after the 9pfs file system has been mounted. Signed-off-by: Juergen Gross Reviewed-by: Jason Andryuk --- tools/hotplug/Linux/launch-xenstore.in | 1 + tools/xenstored/control.c | 30 +++++++++++++------------- tools/xenstored/minios.c | 3 +++ 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/tools/hotplug/Linux/launch-xenstore.in b/tools/hotplug/Linux/l= aunch-xenstore.in index e854ca1eb8..da4eeca7c5 100644 --- a/tools/hotplug/Linux/launch-xenstore.in +++ b/tools/hotplug/Linux/launch-xenstore.in @@ -98,6 +98,7 @@ test -f @CONFIG_DIR@/@CONFIG_LEAF_DIR@/xencommons && . @C= ONFIG_DIR@/@CONFIG_LEAF [ -z "$XENSTORE_DOMAIN_SIZE" ] && XENSTORE_DOMAIN_SIZE=3D8 XENSTORE_DOMAIN_ARGS=3D"$XENSTORE_DOMAIN_ARGS --memory $XENSTORE_DOMAIN_S= IZE" [ -z "$XENSTORE_MAX_DOMAIN_SIZE" ] || XENSTORE_DOMAIN_ARGS=3D"$XENSTORE_D= OMAIN_ARGS --maxmem $XENSTORE_MAX_DOMAIN_SIZE" + [ -z "$XENSTORED_TRACE" ] || XENSTORE_DOMAIN_ARGS=3D"$XENSTORE_DOMAIN_ARG= S -T xenstored-trace.log" =20 echo -n Starting $XENSTORE_DOMAIN_KERNEL... ${LIBEXEC_BIN}/init-xenstore-domain $XENSTORE_DOMAIN_ARGS || exit 1 diff --git a/tools/xenstored/control.c b/tools/xenstored/control.c index b2f64d674f..dae23a5ac0 100644 --- a/tools/xenstored/control.c +++ b/tools/xenstored/control.c @@ -201,19 +201,6 @@ static int do_control_quota_s(const void *ctx, struct = connection *conn, return EINVAL; } =20 -#ifdef __MINIOS__ -static int do_control_memreport(const void *ctx, struct connection *conn, - const char **vec, int num) -{ - if (num) - return EINVAL; - - talloc_report_full(NULL, stdout); - - send_ack(conn, XS_CONTROL); - return 0; -} -#else static int do_control_logfile(const void *ctx, struct connection *conn, const char **vec, int num) { @@ -222,13 +209,26 @@ static int do_control_logfile(const void *ctx, struct= connection *conn, =20 close_log(); talloc_free(tracefile); - tracefile =3D talloc_strdup(NULL, vec[0]); + tracefile =3D absolute_filename(NULL, vec[0]); reopen_log(); =20 send_ack(conn, XS_CONTROL); return 0; } =20 +#ifdef __MINIOS__ +static int do_control_memreport(const void *ctx, struct connection *conn, + const char **vec, int num) +{ + if (num) + return EINVAL; + + talloc_report_full(NULL, stdout); + + send_ack(conn, XS_CONTROL); + return 0; +} +#else static int do_control_memreport(const void *ctx, struct connection *conn, const char **vec, int num) { @@ -309,10 +309,10 @@ static struct cmd_s cmds[] =3D { "[-c ] [-F] [-t ] \n" " Default timeout is 60 seconds.", 5 }, #endif + { "logfile", do_control_logfile, "" }, #ifdef __MINIOS__ { "memreport", do_control_memreport, "" }, #else - { "logfile", do_control_logfile, "" }, { "memreport", do_control_memreport, "[]" }, #endif { "print", do_control_print, "" }, diff --git a/tools/xenstored/minios.c b/tools/xenstored/minios.c index cfc2377857..9e78b96d07 100644 --- a/tools/xenstored/minios.c +++ b/tools/xenstored/minios.c @@ -92,6 +92,9 @@ static void mount_thread(void *p) free(xenbus_unwatch_path_token(XBT_NIL, P9_STATE_PATH, "9pfs")); =20 p9_device =3D init_9pfront(0, XENSTORE_LIB_DIR); + + /* Start logging if selected. */ + reopen_log(); } =20 void mount_9pfs(void) --=20 2.35.3 From nobody Thu May 16 01:45:44 2024 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=1699632679; cv=none; d=zohomail.com; s=zohoarc; b=EYDFVVY+xwYl3XQrOEsSoRstpv8r0FnKDf6YfI8tSgInBiVsRPFmLufcQ22KaylMWf6EQWgicXHYL+L9TrYw4qADFUFHl+78C/qw5tmcEzDn5UIKSZKfGGSXMwAtTLCQlAK9plMeOSVw3I93TTxxmgMvRJajZWi6/MdFx4NT/HU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1699632679; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=2stzGKgVm/SXqJipf+P7KPzRw/p+H9JtpMBW4gsBrV0=; b=ggypHs3Im03QJMtpweO7faYu85npMvCed25xlZN6a0EMVeK8VF+45cJC0EkkKSLKdct8eGw5kCWkB6h45T2ddE+y5Bzt/tso0y84qnm+XV83uqdZJNCehjq1bF7syRnIhV04swZ0OPgFVjtMtmfLZEAhzb6vk7O0OxhJVDmwUbQ= 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 1699632679932453.59368094369654; Fri, 10 Nov 2023 08:11:19 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.630497.983410 (Exim 4.92) (envelope-from ) id 1r1U5q-0003El-VP; Fri, 10 Nov 2023 16:10:50 +0000 Received: by outflank-mailman (output) from mailman id 630497.983410; Fri, 10 Nov 2023 16:10:50 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1r1U5q-0003Ee-Rh; Fri, 10 Nov 2023 16:10:50 +0000 Received: by outflank-mailman (input) for mailman id 630497; Fri, 10 Nov 2023 16:10:49 +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 1r1U5p-0002ug-Rp for xen-devel@lists.xenproject.org; Fri, 10 Nov 2023 16:10:49 +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 b6873b0c-7fe3-11ee-98da-6d05b1d4d9a1; Fri, 10 Nov 2023 17:10:49 +0100 (CET) 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 1ABCF1F8BB; Fri, 10 Nov 2023 16:10:49 +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 DC9B113398; Fri, 10 Nov 2023 16:10:48 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 10V8NAhWTmWwCQAAMHmgww (envelope-from ); Fri, 10 Nov 2023 16:10:48 +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: b6873b0c-7fe3-11ee-98da-6d05b1d4d9a1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1699632649; 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=2stzGKgVm/SXqJipf+P7KPzRw/p+H9JtpMBW4gsBrV0=; b=P9MegLjse7d4oPkyrjeUoxIqukH5kaDe8okcyvleh8vWngucZYMpdNMzqQ2k+Dq361aOMo Uhxf9xEejcsGYXyo9bo3j4AOXcYmB/qgjZoKF36NerWjvNRA9Yf2aGpma3B5Yg6nml9evu 9gVRyndUaOlHj7NByBdVVn8aqenIOXo= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Julien Grall , Anthony PERARD , Jason Andryuk Subject: [PATCH v2 29/29] tools/xenstored: have a single do_control_memreport() Date: Fri, 10 Nov 2023 17:08:04 +0100 Message-Id: <20231110160804.29021-30-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20231110160804.29021-1-jgross@suse.com> References: <20231110160804.29021-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1699632680347100001 Content-Type: text/plain; charset="utf-8" With 9pfs now available in Xenstore-stubdom, there is no reason to have distinct do_control_memreport() variants for the daemon and the stubdom implementations. Signed-off-by: Juergen Gross Reviewed-by: Jason Andryuk --- tools/xenstored/control.c | 27 +++++++-------------------- 1 file changed, 7 insertions(+), 20 deletions(-) diff --git a/tools/xenstored/control.c b/tools/xenstored/control.c index dae23a5ac0..7db2c4703b 100644 --- a/tools/xenstored/control.c +++ b/tools/xenstored/control.c @@ -216,23 +216,11 @@ static int do_control_logfile(const void *ctx, struct= connection *conn, return 0; } =20 -#ifdef __MINIOS__ -static int do_control_memreport(const void *ctx, struct connection *conn, - const char **vec, int num) -{ - if (num) - return EINVAL; - - talloc_report_full(NULL, stdout); - - send_ack(conn, XS_CONTROL); - return 0; -} -#else static int do_control_memreport(const void *ctx, struct connection *conn, const char **vec, int num) { FILE *fp; + char *filename; int fd; =20 if (num > 1) @@ -255,8 +243,12 @@ static int do_control_memreport(const void *ctx, struc= t connection *conn, if (!fp) close(fd); } - } else - fp =3D fopen(vec[0], "a"); + } else { + filename =3D absolute_filename(ctx, vec[0]); + if (!filename) + return ENOMEM; + fp =3D fopen(filename, "a"); + } =20 if (!fp) return EBADF; @@ -267,7 +259,6 @@ static int do_control_memreport(const void *ctx, struct= connection *conn, send_ack(conn, XS_CONTROL); return 0; } -#endif =20 static int do_control_print(const void *ctx, struct connection *conn, const char **vec, int num) @@ -310,11 +301,7 @@ static struct cmd_s cmds[] =3D { " Default timeout is 60 seconds.", 5 }, #endif { "logfile", do_control_logfile, "" }, -#ifdef __MINIOS__ - { "memreport", do_control_memreport, "" }, -#else { "memreport", do_control_memreport, "[]" }, -#endif { "print", do_control_print, "" }, { "quota", do_control_quota, "[set ||max [-r]]" }, --=20 2.35.3