From nobody Fri May 17 10:34:34 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; 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=fail(p=quarantine dis=quarantine) header.from=suse.com Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1707130227574616.5759397962404; Mon, 5 Feb 2024 02:50:27 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.675787.1051282 (Exim 4.92) (envelope-from ) id 1rWwYH-0002Tm-HW; Mon, 05 Feb 2024 10:50:13 +0000 Received: by outflank-mailman (output) from mailman id 675787.1051282; Mon, 05 Feb 2024 10:50:13 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rWwYH-0002Td-Em; Mon, 05 Feb 2024 10:50:13 +0000 Received: by outflank-mailman (input) for mailman id 675787; Mon, 05 Feb 2024 10:50:12 +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 1rWwYF-0000qL-WE for xen-devel@lists.xenproject.org; Mon, 05 Feb 2024 10:50:12 +0000 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 5512502b-c414-11ee-98f5-efadbce2ee36; Mon, 05 Feb 2024 11:50:10 +0100 (CET) Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id F16B81F8BA; Mon, 5 Feb 2024 10:50:09 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id BC91B132DD; Mon, 5 Feb 2024 10:50:09 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id hKaCLGG9wGUBNgAAD6G6ig (envelope-from ); Mon, 05 Feb 2024 10:50: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: 5512502b-c414-11ee-98f5-efadbce2ee36 From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Anthony PERARD , Andrew Cooper Subject: [PATCH v4 01/32] tools: add access macros for unaligned data Date: Mon, 5 Feb 2024 11:49:30 +0100 Message-Id: <20240205105001.24171-2-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240205105001.24171-1-jgross@suse.com> References: <20240205105001.24171-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Authentication-Results: smtp-out2.suse.de; none X-Spamd-Result: default: False [-4.00 / 50.00]; REPLY(-4.00)[] X-Rspamd-Server: rspamd1.dmz-prg2.suse.org X-Rspamd-Queue-Id: F16B81F8BA X-Spam-Level: X-Spam-Score: -4.00 X-Spam-Flag: NO X-ZM-MESSAGEID: 1707130229307100003 Content-Type: text/plain; charset="utf-8" Add the basic access macros for unaligned data to common-macros.h. Signed-off-by: Juergen Gross Acked-by: Andrew Cooper --- V3: - new patch --- tools/include/xen-tools/common-macros.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tools/include/xen-tools/common-macros.h b/tools/include/xen-to= ols/common-macros.h index e5ed603904..81fba2e9f5 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)); \ @@ -87,4 +91,17 @@ #define __AC(X, Y) (X ## Y) #define _AC(X, Y) __AC(X, Y) =20 +#define get_unaligned_t(type, ptr) ({ \ + const struct { type x; } __packed *ptr_ =3D (typeof(ptr_))(ptr); \ + ptr_->x; \ +}) + +#define put_unaligned_t(type, val, ptr) do { \ + struct { type x; } __packed *ptr_ =3D (typeof(ptr_))(ptr); \ + ptr_->x =3D val; \ +} while (0) + +#define get_unaligned(ptr) get_unaligned_t(typeof(*(ptr)), ptr) +#define put_unaligned(val, ptr) put_unaligned_t(typeof(*(ptr)), val, ptr) + #endif /* __XEN_TOOLS_COMMON_MACROS__ */ --=20 2.35.3 From nobody Fri May 17 10:34:34 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; 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=fail(p=quarantine dis=quarantine) header.from=suse.com Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1707130230559781.7026972435549; Mon, 5 Feb 2024 02:50:30 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.675788.1051292 (Exim 4.92) (envelope-from ) id 1rWwYN-0002oV-Qe; Mon, 05 Feb 2024 10:50:19 +0000 Received: by outflank-mailman (output) from mailman id 675788.1051292; Mon, 05 Feb 2024 10:50:19 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rWwYN-0002oL-NW; Mon, 05 Feb 2024 10:50:19 +0000 Received: by outflank-mailman (input) for mailman id 675788; Mon, 05 Feb 2024 10:50:17 +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 1rWwYL-0000qL-OG for xen-devel@lists.xenproject.org; Mon, 05 Feb 2024 10:50:17 +0000 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 58701518-c414-11ee-98f5-efadbce2ee36; Mon, 05 Feb 2024 11:50:15 +0100 (CET) Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 9B52921EBE; Mon, 5 Feb 2024 10:50:15 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 5F828132DD; Mon, 5 Feb 2024 10:50:15 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id mW3SFWe9wGUKNgAAD6G6ig (envelope-from ); Mon, 05 Feb 2024 10:50: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: 58701518-c414-11ee-98f5-efadbce2ee36 From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Anthony PERARD , Jason Andryuk , Andrew Cooper Subject: [PATCH v4 02/32] tools: add a new xen logging daemon Date: Mon, 5 Feb 2024 11:49:31 +0100 Message-Id: <20240205105001.24171-3-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240205105001.24171-1-jgross@suse.com> References: <20240205105001.24171-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spam-Level: Authentication-Results: smtp-out1.suse.de; none X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Spamd-Result: default: False [-4.00 / 50.00]; REPLY(-4.00)[] X-Spam-Score: -4.00 X-Rspamd-Queue-Id: 9B52921EBE X-Spam-Flag: NO X-ZM-MESSAGEID: 1707130231353100007 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 Acked-by: Andrew Cooper Acked-by: Anthony PERARD --- 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) V3: - fix SPDX Identifier (Andrew Cooper) V4: - add strerror() test to error logging (Andrew Cooper) - don't handle "daemon already running" as error (Anthony Perard) --- tools/Makefile | 1 + tools/xen-9pfsd/.gitignore | 1 + tools/xen-9pfsd/Makefile | 38 ++++++++++ tools/xen-9pfsd/xen-9pfsd.c | 147 ++++++++++++++++++++++++++++++++++++ 4 files changed, 187 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..6939d01574 --- /dev/null +++ b/tools/xen-9pfsd/xen-9pfsd.c @@ -0,0 +1,147 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +/* + * xen-9pfsd - Xen 9pfs daemon + * + * Copyright (C) 2024 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, %s", msg, errno, strerror(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); + syslog(LOG_INFO, "daemon already running"); + close_all(); + exit(0); + } + + 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 Fri May 17 10:34:34 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; 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=fail(p=quarantine dis=quarantine) header.from=suse.com Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1707130237010739.4062090355577; Mon, 5 Feb 2024 02:50:37 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.675791.1051303 (Exim 4.92) (envelope-from ) id 1rWwYS-0003EZ-1Z; Mon, 05 Feb 2024 10:50:24 +0000 Received: by outflank-mailman (output) from mailman id 675791.1051303; Mon, 05 Feb 2024 10:50:24 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rWwYR-0003EQ-U9; Mon, 05 Feb 2024 10:50:23 +0000 Received: by outflank-mailman (input) for mailman id 675791; Mon, 05 Feb 2024 10:50:22 +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 1rWwYQ-0002wU-Nh for xen-devel@lists.xenproject.org; Mon, 05 Feb 2024 10:50:22 +0000 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 5bc82005-c414-11ee-8a45-1f161083a0e0; Mon, 05 Feb 2024 11:50:21 +0100 (CET) Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 417491F8BA; Mon, 5 Feb 2024 10:50:21 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 0C3E3132DD; Mon, 5 Feb 2024 10:50:21 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id D65tAW29wGUONgAAD6G6ig (envelope-from ); Mon, 05 Feb 2024 10:50:21 +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: 5bc82005-c414-11ee-8a45-1f161083a0e0 From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Anthony PERARD , Jason Andryuk Subject: [PATCH v4 03/32] tools/xen-9pfsd: connect to frontend Date: Mon, 5 Feb 2024 11:49:32 +0100 Message-Id: <20240205105001.24171-4-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240205105001.24171-1-jgross@suse.com> References: <20240205105001.24171-1-jgross@suse.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Spam-Level: Authentication-Results: smtp-out2.suse.de; none X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Spamd-Result: default: False [-4.00 / 50.00]; REPLY(-4.00)[] X-Spam-Score: -4.00 X-Rspamd-Queue-Id: 417491F8BA X-Spam-Flag: NO X-ZM-MESSAGEID: 1707130237332100001 Add the code for connecting to frontends to xenlogd. Signed-off-by: Juergen Gross Acked-by: Anthony PERARD Reviewed-by: Jason Andryuk --- 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() V3: - fix SPDX indentifier (Andrew Cooper) - better validation of host path (Jason Andryuk) - don't hard-code dom0 in backend nodes (Jason Andryuk) - use bool instead of int for some functions' return types - open root directory (Jason Andryuk) --- tools/xen-9pfsd/Makefile | 2 +- tools/xen-9pfsd/io.c | 45 +++ tools/xen-9pfsd/xen-9pfsd.c | 653 +++++++++++++++++++++++++++++++++++- tools/xen-9pfsd/xen-9pfsd.h | 61 ++++ 4 files changed, 757 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..eb7c136e09 --- /dev/null +++ b/tools/xen-9pfsd/io.c @@ -0,0 +1,45 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +/* + * xen-9pfsd - Xen 9pfs daemon + * + * Copyright (C) 2024 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 6939d01574..73b6c3a30e 100644 --- a/tools/xen-9pfsd/xen-9pfsd.c +++ b/tools/xen-9pfsd/xen-9pfsd.c @@ -24,34 +24,632 @@ =20 #include #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; + + /* Path must be absolute. */ + if ( device->host_path[0] !=3D '/' ) + return 1; + + /* No double "/". */ + if ( strstr(device->host_path, "//") ) + return 1; + + /* No trailing "/" (includes refusing to share "/"). */ + if ( device->host_path[strlen(device->host_path) - 1] =3D=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 bool write_backend_node(device *device, const char *node, + const char *val) +{ + struct path p; + unsigned int num_perms; + struct xs_permissions *old_perms; + 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 false; + } + + old_perms =3D xs_get_permissions(xs, XBT_NULL, p.path, &num_perms); + if ( !old_perms ) + { + syslog(LOG_ERR, "error getting permissions for \"%s\"", p.path); + return false; + } + + perms[0] =3D old_perms[0]; + free(old_perms); + if ( !xs_set_permissions(xs, XBT_NULL, p.path, perms, 2) ) + { + syslog(LOG_ERR, "error setting permissions for \"%s\"", p.path); + return false; + } + + return true; +} + +static bool 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 bool 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 false; + } + + device->backend_state =3D state; + + return true; +} + +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); + + if ( device->root_fd >=3D 0 ) + close(device->root_fd); + + 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; + device->root_fd =3D -1; + + 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; + } + device->root_fd =3D open(device->host_path, O_RDONLY | O_DIRECTORY); + if ( device->root_fd < 0 ) + 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 +666,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; @@ -124,6 +749,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") ) @@ -136,9 +766,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..ff3562164a --- /dev/null +++ b/tools/xen-9pfsd/xen-9pfsd.h @@ -0,0 +1,61 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#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]; + int root_fd; +}; + +extern xenevtchn_handle *xe; + +void *io_thread(void *arg); + +#endif /* XEN_9PFSD_H */ --=20 2.35.3 From nobody Fri May 17 10:34:34 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=1707130240; cv=none; d=zohomail.com; s=zohoarc; b=awO9xhJupkzWeLiI0nrPcMtCaBr8J7ymk5v4R33Bk9MHFD/7d75tqbwlyuDDTHk3eZql0OnQ7hnirTUyleajsuU+eJrzqAuzYMYSoSQ32M4+bgiUJBRodwEdJZz1WFOW0jvzlo1rXpUm/nUemFfHGXzhWpXaH4eukGA+9gcIYCo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1707130240; 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=GzcbwuhHDQyavc9oDP7uqfqZzwZ8UtCeX4PMuuKBycU=; b=Kn5XvKGWuCvJebIMdqUhLzN4t7TeS9g4t+Zg2Oo4NThXC6mFOIGATkoUpN+XlL3HOgLENsdd5WWyrvNxn0agTGrecXzahaWMkJ8bKNjfSH0EaZ8/IsIDA2KTRQDncor+ocZzvxU8l3qm2AnRayUnw2HbzjY0UES3lDZIvzj//NY= 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 1707130240775794.5026001755466; Mon, 5 Feb 2024 02:50:40 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.675793.1051313 (Exim 4.92) (envelope-from ) id 1rWwYY-0003kf-DZ; Mon, 05 Feb 2024 10:50:30 +0000 Received: by outflank-mailman (output) from mailman id 675793.1051313; Mon, 05 Feb 2024 10:50:30 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rWwYY-0003kY-Al; Mon, 05 Feb 2024 10:50:30 +0000 Received: by outflank-mailman (input) for mailman id 675793; Mon, 05 Feb 2024 10:50:29 +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 1rWwYX-0000qL-5b for xen-devel@lists.xenproject.org; Mon, 05 Feb 2024 10:50:29 +0000 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 5f40cfe4-c414-11ee-98f5-efadbce2ee36; Mon, 05 Feb 2024 11:50:27 +0100 (CET) Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id D582221EBE; Mon, 5 Feb 2024 10:50:26 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id A35E8132DD; Mon, 5 Feb 2024 10:50:26 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id 94lrJnK9wGUUNgAAD6G6ig (envelope-from ); Mon, 05 Feb 2024 10:50: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: 5f40cfe4-c414-11ee-98f5-efadbce2ee36 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1707130227; 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=GzcbwuhHDQyavc9oDP7uqfqZzwZ8UtCeX4PMuuKBycU=; b=PTh7ztC19I2BTF/e4pIDbls+TG1KMv8JFYQocDhFAbVH7ujVFUv5gUub7GcE8f0XhtNY2r gbb83rrcaRQJMFPwsTJ1Yo33IhwxRYQQWheOk7fGp8IlnjcNtvE8WE8OpEI9OFQSsJDVwT m87+2jbN9oJ5iSBv/v8ZEVa/cjdq/AY= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1707130226; 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=GzcbwuhHDQyavc9oDP7uqfqZzwZ8UtCeX4PMuuKBycU=; b=TkdsZHGXVL5zRimtIaMPf6U0mYDbJRQ9r9my5q+Zu2LkWS4/1DotO3qgnzL0xw9C/ZrGlI hXhRSzICXk30ofsNnPDFRcpmQ/R/9CbUiuUF//osXNQ0d48uwt2c4yCmuGXHpA025phJLA uodpC7Y0flqA9QriJ9/0T5N4Q940Xcc= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Anthony PERARD , Jason Andryuk Subject: [PATCH v4 04/32] tools/xen-9pfsd: add transport layer Date: Mon, 5 Feb 2024 11:49:33 +0100 Message-Id: <20240205105001.24171-5-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240205105001.24171-1-jgross@suse.com> References: <20240205105001.24171-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Authentication-Results: smtp-out1.suse.de; none X-Spam-Level: X-Spam-Score: -3.30 X-Spamd-Result: default: False [-3.30 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; R_MISSING_CHARSET(2.50)[]; FREEMAIL_ENVRCPT(0.00)[gmail.com]; MIME_GOOD(-0.10)[text/plain]; TO_MATCH_ENVRCPT_ALL(0.00)[]; REPLY(-4.00)[]; BROKEN_CONTENT_TYPE(1.50)[]; RCPT_COUNT_FIVE(0.00)[5]; NEURAL_HAM_LONG(-1.00)[-1.000]; RCVD_COUNT_THREE(0.00)[3]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MID_CONTAINS_FROM(1.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.com:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; FREEMAIL_CC(0.00)[suse.com,xen.org,citrix.com,gmail.com]; RCVD_TLS_ALL(0.00)[]; BAYES_HAM(-3.00)[100.00%] X-Spam-Flag: NO X-ZohoMail-DKIM: pass (identity @suse.com) (identity @suse.com) X-ZM-MESSAGEID: 1707130241354100001 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. Signed-off-by: Juergen Gross Reviewed-by: Jason Andryuk Acked-by: Anthony PERARD --- 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/xen-9pfsd/io.c | 143 +++++++++++++++++++++++++++++++++++- tools/xen-9pfsd/xen-9pfsd.h | 16 ++++ 2 files changed, 156 insertions(+), 3 deletions(-) diff --git a/tools/xen-9pfsd/io.c b/tools/xen-9pfsd/io.c index eb7c136e09..4312a62dfe 100644 --- a/tools/xen-9pfsd/io.c +++ b/tools/xen-9pfsd/io.c @@ -6,39 +6,176 @@ * Copyright (C) 2024 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 ff3562164a..d587f59a32 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 Fri May 17 10:34:34 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; 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=fail(p=quarantine dis=quarantine) header.from=suse.com Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1707130246564569.4591952128571; Mon, 5 Feb 2024 02:50:46 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.675796.1051323 (Exim 4.92) (envelope-from ) id 1rWwYd-0004EO-Ly; Mon, 05 Feb 2024 10:50:35 +0000 Received: by outflank-mailman (output) from mailman id 675796.1051323; Mon, 05 Feb 2024 10:50:35 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rWwYd-0004ED-IZ; Mon, 05 Feb 2024 10:50:35 +0000 Received: by outflank-mailman (input) for mailman id 675796; Mon, 05 Feb 2024 10:50:34 +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 1rWwYc-0000qL-KK for xen-devel@lists.xenproject.org; Mon, 05 Feb 2024 10:50:34 +0000 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 6275bc70-c414-11ee-98f5-efadbce2ee36; Mon, 05 Feb 2024 11:50:32 +0100 (CET) Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 6FDE822100; Mon, 5 Feb 2024 10:50:32 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 453CD132DD; Mon, 5 Feb 2024 10:50:32 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id PVFnD3i9wGUZNgAAD6G6ig (envelope-from ); Mon, 05 Feb 2024 10:50: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: 6275bc70-c414-11ee-98f5-efadbce2ee36 From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Anthony PERARD Subject: [PATCH v4 05/32] tools/xen-9pfsd: add 9pfs response generation support Date: Mon, 5 Feb 2024 11:49:34 +0100 Message-Id: <20240205105001.24171-6-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240205105001.24171-1-jgross@suse.com> References: <20240205105001.24171-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Authentication-Results: smtp-out1.suse.de; none X-Spamd-Result: default: False [-4.00 / 50.00]; REPLY(-4.00)[] X-Rspamd-Server: rspamd1.dmz-prg2.suse.org X-Rspamd-Queue-Id: 6FDE822100 X-Spam-Level: X-Spam-Score: -4.00 X-Spam-Flag: NO X-ZM-MESSAGEID: 1707130247315100001 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 Acked-by: Anthony PERARD Reviewed-by: Jason Andryuk --- V2: - check parameter size limits (Jason Andryuk) V3: - use new unaligned access macros (Jason Andryuk) V4: - use recursion in fill_buffer() as a preparation for reading dirs --- tools/xen-9pfsd/io.c | 217 +++++++++++++++++++++++++++++++++++- tools/xen-9pfsd/xen-9pfsd.h | 3 + 2 files changed, 219 insertions(+), 1 deletion(-) diff --git a/tools/xen-9pfsd/io.c b/tools/xen-9pfsd/io.c index 4312a62dfe..4a44c70c4d 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,200 @@ 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: 1 byte unsigned integer + * u: 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_at(void **data, const char *fmt, ...); +static void vfill_buffer_at(void **data, const char *fmt, va_list ap) +{ + const char *f; + const void *par; + const char *str_val; + const struct p9_qid *qid; + unsigned int len; + unsigned int array_sz =3D 0; + unsigned int elem_sz =3D 0; + + 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); + } + put_unaligned(array_sz, (uint16_t *)*data); + *data +=3D sizeof(uint16_t); + par =3D va_arg(ap, const void *); + elem_sz =3D 0; + break; + + case 'b': + put_unaligned(*(const uint8_t *)par, (uint8_t *)*data); + elem_sz =3D sizeof(uint8_t); + *data +=3D sizeof(uint8_t); + break; + + case 'u': + put_unaligned(*(const uint16_t *)par, (uint16_t *)*data); + 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; + put_unaligned(len, (uint32_t *)*data); + *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': + put_unaligned(*(const uint64_t *)par, (uint64_t *)*data); + elem_sz =3D sizeof(uint64_t); + *data +=3D sizeof(uint64_t); + break; + + case 'Q': + qid =3D par; + elem_sz =3D sizeof(*qid); + fill_buffer_at(data, "bUL", &qid->type, &qid->version, &qid->p= ath); + 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); + } + put_unaligned(len, (uint16_t *)*data); + *data +=3D sizeof(uint16_t); + memcpy(*data, str_val, len); + *data +=3D len; + break; + + case 'U': + put_unaligned(*(const uint32_t *)par, (uint32_t *)*data); + elem_sz =3D sizeof(uint32_t); + *data +=3D sizeof(uint32_t); + break; + + default: + fmt_err(fmt); + } + + if ( array_sz ) + f--; + } +} + +static void fill_buffer_at(void **data, const char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + vfill_buffer_at(data, fmt, ap); + va_end(ap); +} + +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; + va_list ap; + + hdr->cmd =3D cmd; + hdr->tag =3D tag; + + va_start(ap, fmt); + vfill_buffer_at(&data, fmt, ap); + va_end(ap); + + 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 +356,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 +388,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 d587f59a32..0cde0d2bb8 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 Fri May 17 10:34:34 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=1707130253; cv=none; d=zohomail.com; s=zohoarc; b=f/5KdzhxDq6I3B5mUDTvcmwnTDdx1OjuzySYXo0mU/uosVJPHSr978YgDe89GmWAujqzeZYRA69Sd4ZOudsLnx2WGi6d54iW0a4OOedfPl+ySZeYyAcFDmrSMMC/53IsHgoi0YjrjoFJ/37L8hfQJZviJdSqVtxZQuCXmzRnqlk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1707130253; 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=hRIG3K7WCdgf9Z1PIv4Opjhz+muswiZWfpgWnc+2iLg=; b=VtXwL/0XdQaqF9ovwUey+OLfEfvXrrkrNTSG1CToiB+0/gcV9dBsigEOCN/C8eZsujN3NdjVdZa0kTn9+4qCTM+VHXumWjjybh19aHZP/nxPik54nUs5LdlNeutPCA91RyXpZCh44NsPWFeSZOANLD++VL83gcm/RjzCXnpSBJc= 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 1707130253316741.4489909894257; Mon, 5 Feb 2024 02:50:53 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.675799.1051333 (Exim 4.92) (envelope-from ) id 1rWwYj-0004nO-Ss; Mon, 05 Feb 2024 10:50:41 +0000 Received: by outflank-mailman (output) from mailman id 675799.1051333; Mon, 05 Feb 2024 10:50:41 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rWwYj-0004nC-Px; Mon, 05 Feb 2024 10:50:41 +0000 Received: by outflank-mailman (input) for mailman id 675799; Mon, 05 Feb 2024 10:50:40 +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 1rWwYi-0000qL-Eb for xen-devel@lists.xenproject.org; Mon, 05 Feb 2024 10:50:40 +0000 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 65f51b28-c414-11ee-98f5-efadbce2ee36; Mon, 05 Feb 2024 11:50:38 +0100 (CET) Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 1ED821F8BA; Mon, 5 Feb 2024 10:50:38 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id DAF68132DD; Mon, 5 Feb 2024 10:50:37 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id Oq28M329wGUjNgAAD6G6ig (envelope-from ); Mon, 05 Feb 2024 10:50: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: 65f51b28-c414-11ee-98f5-efadbce2ee36 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1707130238; 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=hRIG3K7WCdgf9Z1PIv4Opjhz+muswiZWfpgWnc+2iLg=; b=UDpSx3gHoJ28Rag8I1uLRwN5+my/9UWih3NG0D+C1ZzTJqCX4GQi3cJV2bVhZeBjIEsT2b CNc10NjvPJsnu1H0WoxazDOxkhE1gx3lua7Jv2qEGFGJvV/r593B89mvEJmnvHr/Vn6dRA 8O1bWK34oq0hTxdUd9IECxd3VF39RNE= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1707130238; 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=hRIG3K7WCdgf9Z1PIv4Opjhz+muswiZWfpgWnc+2iLg=; b=UDpSx3gHoJ28Rag8I1uLRwN5+my/9UWih3NG0D+C1ZzTJqCX4GQi3cJV2bVhZeBjIEsT2b CNc10NjvPJsnu1H0WoxazDOxkhE1gx3lua7Jv2qEGFGJvV/r593B89mvEJmnvHr/Vn6dRA 8O1bWK34oq0hTxdUd9IECxd3VF39RNE= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Anthony PERARD , Jason Andryuk Subject: [PATCH v4 06/32] tools/xen-9pfsd: add 9pfs version request support Date: Mon, 5 Feb 2024 11:49:35 +0100 Message-Id: <20240205105001.24171-7-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240205105001.24171-1-jgross@suse.com> References: <20240205105001.24171-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Authentication-Results: smtp-out2.suse.de; none X-Spamd-Result: default: False [-2.10 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; FREEMAIL_ENVRCPT(0.00)[gmail.com]; R_MISSING_CHARSET(2.50)[]; MIME_GOOD(-0.10)[text/plain]; TO_MATCH_ENVRCPT_ALL(0.00)[]; REPLY(-4.00)[]; BROKEN_CONTENT_TYPE(1.50)[]; RCPT_COUNT_FIVE(0.00)[5]; RCVD_COUNT_THREE(0.00)[3]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; MID_CONTAINS_FROM(1.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.com:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; FREEMAIL_CC(0.00)[suse.com,xen.org,citrix.com,gmail.com]; RCVD_TLS_ALL(0.00)[]; BAYES_HAM(-3.00)[100.00%] X-Spam-Level: X-Spam-Flag: NO X-Spam-Score: -2.10 X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1707130255399100001 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 Acked-by: Anthony PERARD Reviewed-by: Jason Andryuk --- V3: - use unaligned helper macros (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 4a44c70c4d..839dd1112c 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 @@ -294,6 +298,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 get_unaligned((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 get_unaligned((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 get_unaligned((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; @@ -305,6 +472,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; @@ -360,6 +557,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 Fri May 17 10:34:34 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; 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=fail(p=quarantine dis=quarantine) header.from=suse.com Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1707130670891831.744293662646; Mon, 5 Feb 2024 02:57:50 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.675837.1051453 (Exim 4.92) (envelope-from ) id 1rWwfT-00034x-H5; Mon, 05 Feb 2024 10:57:39 +0000 Received: by outflank-mailman (output) from mailman id 675837.1051453; Mon, 05 Feb 2024 10:57:39 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rWwfT-00034m-DV; Mon, 05 Feb 2024 10:57:39 +0000 Received: by outflank-mailman (input) for mailman id 675837; Mon, 05 Feb 2024 10:57:38 +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 1rWwYn-0000qL-Pc for xen-devel@lists.xenproject.org; Mon, 05 Feb 2024 10:50:45 +0000 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 692a4a00-c414-11ee-98f5-efadbce2ee36; Mon, 05 Feb 2024 11:50:44 +0100 (CET) Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id AC6BA22100; Mon, 5 Feb 2024 10:50:43 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 8224E132DD; Mon, 5 Feb 2024 10:50:43 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id IPddHoO9wGUqNgAAD6G6ig (envelope-from ); Mon, 05 Feb 2024 10:50: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: 692a4a00-c414-11ee-98f5-efadbce2ee36 From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Anthony PERARD Subject: [PATCH v4 07/32] tools/xen-9pfsd: add 9pfs attach request support Date: Mon, 5 Feb 2024 11:49:36 +0100 Message-Id: <20240205105001.24171-8-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240205105001.24171-1-jgross@suse.com> References: <20240205105001.24171-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spam-Level: Authentication-Results: smtp-out1.suse.de; none X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Spamd-Result: default: False [-4.00 / 50.00]; REPLY(-4.00)[] X-Spam-Score: -4.00 X-Rspamd-Queue-Id: AC6BA22100 X-Spam-Flag: NO X-ZM-MESSAGEID: 1707130671350100002 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 Acked-by: Anthony PERARD Reviewed-by: Jason Andryuk --- V2: - make fill_qid() parameter stbuf const (Jason Andryuk) - free fids after disconnecting guest (Jason Andryuk) V3: - only store relative path in fid (Jason Andryuk) V4: - store a path directly usable by *at() functions in fid (Jason Andryuk) --- tools/xen-9pfsd/io.c | 164 ++++++++++++++++++++++++++++++++++++ tools/xen-9pfsd/xen-9pfsd.c | 6 ++ tools/xen-9pfsd/xen-9pfsd.h | 14 +++ 3 files changed, 184 insertions(+) diff --git a/tools/xen-9pfsd/io.c b/tools/xen-9pfsd/io.c index 839dd1112c..4f6acefc87 100644 --- a/tools/xen-9pfsd/io.c +++ b/tools/xen-9pfsd/io.c @@ -11,11 +11,14 @@ * before looking for the next request. */ =20 +#include #include #include #include #include #include +#include +#include #include /* For cpu barriers. */ #include =20 @@ -23,6 +26,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 @@ -461,6 +465,126 @@ 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(path); + fidp =3D calloc(sizeof(*fidp) + pathlen + 1, 1); + if ( !fidp ) + return NULL; + + fidp->fid =3D fid; + strncpy(fidp->path, path, pathlen); + + 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 const char *relpath_from_path(const char *path) +{ + if (!strcmp(path, "/")) + return "."; + + return (path[0] =3D=3D '/') ? path + 1 : path; +} + +static int fill_qid(device *device, const char *path, struct p9_qid *qid, + const struct stat *stbuf) +{ + struct stat st; + + if ( !stbuf ) + { + if ( fstatat(device->root_fd, path, &st, 0) ) + 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; @@ -502,6 +626,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, relpath_from_path("/")); + if ( !device->root_fid ) + { + p9_error(ring, hdr->tag, errno); + return; + } + + ret =3D fill_qid(device, device->root_fid->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; @@ -561,6 +721,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 73b6c3a30e..b83b896bcc 100644 --- a/tools/xen-9pfsd/xen-9pfsd.c +++ b/tools/xen-9pfsd/xen-9pfsd.c @@ -304,6 +304,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") ) { @@ -399,6 +402,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) @@ -482,6 +487,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 0cde0d2bb8..6c755411a7 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 { @@ -71,10 +78,17 @@ struct device { unsigned int num_rings; struct ring *ring[MAX_RINGS]; int root_fd; + + /* 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 Fri May 17 10:34:34 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=1707130794; cv=none; d=zohomail.com; s=zohoarc; b=f72JSHAJOi2TL4YhOjR6odfqX8t+5FnreeZgD2ttnFsyVoxke+bYqwRH/Rws93+5mkUg9SF5Is77AYe9n6cMchxr0ql+wQzooLi2abmA8+ImBSTsP7cp8V0vod0/8UYCnocATTteXjLBKAzwjJz0rT2h5E/zMs0mic15tAndPOM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1707130794; 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=Bf1Cys4GWKYwJ14lNNx92x1baFWNjqmyMtleMunbvkA=; b=PyaEuomhOGcVOV0YavfvYvT6zXQxOy7zAS7fDbQ/YlB0Zy28JqoqXofmQRPgQEkgtdFzE6fzld/ADXflOxOKbefgRob9mzGRu3zBsjuAPCktg4gV/Q4wNdKCQv/ZFoBJ3amoy9+wncduNhtCsMOtqArl6iwfIH+1tEl6ct9s1Cw= 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 1707130794456695.841552304491; Mon, 5 Feb 2024 02:59:54 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.675901.1051592 (Exim 4.92) (envelope-from ) id 1rWwhP-0003Zw-Vi; Mon, 05 Feb 2024 10:59:39 +0000 Received: by outflank-mailman (output) from mailman id 675901.1051592; Mon, 05 Feb 2024 10:59:39 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rWwhP-0003Zn-T3; Mon, 05 Feb 2024 10:59:39 +0000 Received: by outflank-mailman (input) for mailman id 675901; Mon, 05 Feb 2024 10:59:38 +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 1rWwYt-0000qL-Bg for xen-devel@lists.xenproject.org; Mon, 05 Feb 2024 10:50:51 +0000 Received: from smtp-out1.suse.de (smtp-out1.suse.de [2a07:de40:b251:101:10:150:64:1]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 6c8bcce9-c414-11ee-98f5-efadbce2ee36; Mon, 05 Feb 2024 11:50:49 +0100 (CET) Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 4433B22105; Mon, 5 Feb 2024 10:50:49 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 19F8D132DD; Mon, 5 Feb 2024 10:50:49 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id /rjnBIm9wGUzNgAAD6G6ig (envelope-from ); Mon, 05 Feb 2024 10:50:49 +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: 6c8bcce9-c414-11ee-98f5-efadbce2ee36 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1707130249; 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=Bf1Cys4GWKYwJ14lNNx92x1baFWNjqmyMtleMunbvkA=; b=EIG+DjNxmW0fpUfivt6bfCqvYTaj+xVjYV3cD3UGsQIv11Qluwj4NoAkKOaFYmQTaqH2Oh M9ARoC8mKaLvkfbMW63sRqbfdJNF0LhqZXIOr/fCZBIF94xrXq0QKiYa1TrIjWGCnVrTe/ uSY7vMWRHF3HBFJsIfB+gyWkU9eA1fM= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1707130249; 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=Bf1Cys4GWKYwJ14lNNx92x1baFWNjqmyMtleMunbvkA=; b=EIG+DjNxmW0fpUfivt6bfCqvYTaj+xVjYV3cD3UGsQIv11Qluwj4NoAkKOaFYmQTaqH2Oh M9ARoC8mKaLvkfbMW63sRqbfdJNF0LhqZXIOr/fCZBIF94xrXq0QKiYa1TrIjWGCnVrTe/ uSY7vMWRHF3HBFJsIfB+gyWkU9eA1fM= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Anthony PERARD Subject: [PATCH v4 08/32] tools/xen-9pfsd: add 9pfs walk request support Date: Mon, 5 Feb 2024 11:49:37 +0100 Message-Id: <20240205105001.24171-9-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240205105001.24171-1-jgross@suse.com> References: <20240205105001.24171-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Authentication-Results: smtp-out1.suse.de; none X-Spam-Level: X-Spam-Score: -3.30 X-Spamd-Result: default: False [-3.30 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_THREE(0.00)[4]; R_MISSING_CHARSET(2.50)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; REPLY(-4.00)[]; BROKEN_CONTENT_TYPE(1.50)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; RCVD_COUNT_THREE(0.00)[3]; TO_DN_SOME(0.00)[]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MID_CONTAINS_FROM(1.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.com:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_ALL(0.00)[]; BAYES_HAM(-3.00)[100.00%] X-Spam-Flag: NO X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1707130795682100001 Content-Type: text/plain; charset="utf-8" Add the walk request of the 9pfs protocol. Signed-off-by: Juergen Gross Acked-by: Anthony PERARD Reviewed-by: Jason Andryuk --- V2: - don't allow walking across symbolic links --- tools/xen-9pfsd/io.c | 171 ++++++++++++++++++++++++++++++++++++ tools/xen-9pfsd/xen-9pfsd.h | 1 + 2 files changed, 172 insertions(+) diff --git a/tools/xen-9pfsd/io.c b/tools/xen-9pfsd/io.c index 4f6acefc87..5b827706b7 100644 --- a/tools/xen-9pfsd/io.c +++ b/tools/xen-9pfsd/io.c @@ -28,9 +28,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; @@ -478,6 +480,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) { @@ -578,6 +595,10 @@ static int fill_qid(device *device, const char *path, = struct p9_qid *qid, 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; @@ -585,6 +606,20 @@ static int fill_qid(device *device, const char *path, = struct p9_qid *qid, 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; @@ -662,6 +697,138 @@ 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(device, path, qids + i, NULL); + if ( ret ) + { + if ( !walked ) + { + p9_error(ring, hdr->tag, errno); + goto out; + } + break; + } + walked++; + } + } + + if ( walked =3D=3D n_names ) + { + 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, 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, 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; @@ -725,6 +892,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 6c755411a7..f01fffb0bb 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 Fri May 17 10:34:34 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=1707130741; cv=none; d=zohomail.com; s=zohoarc; b=fyCCuNdQrqBbEWmMVWhjeMdu1WFNy2G9Q2OBVcfYfIYfLPcbWuOg9zWnYFFXaSFOlltT7oRSDz2LHlJ8dzRi4uG9Z58Ah4PuapX5H3e/Bzsl4xSecBytuOsoSiRYgcFjp7OmTct9AONaharGxiQVBe6V8tEuiFW26f1BJG06w4o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1707130741; 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=FTPfVWkUlQhndtMJjvkYVvwFLg3Kri0CAO7AyEi1mRk=; b=M5a1c8CXTNbGJ83KSyqcMfCz/PKGDnOMxmVenTukQTyCgeP/91xP9XtE2m54JQTE6rv3dh4SSgz3idWNJQ/n9cCAGTvY2pg01vq56dQYmKitCgE0stfHFdoM9jfgugsDg82JhNfy1LQLuXsV629TvAs/OL4ksQdjXFZ6PdUX28Q= 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 1707130741570948.734379201866; Mon, 5 Feb 2024 02:59:01 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.675882.1051553 (Exim 4.92) (envelope-from ) id 1rWwgW-00013O-RJ; Mon, 05 Feb 2024 10:58:44 +0000 Received: by outflank-mailman (output) from mailman id 675882.1051553; Mon, 05 Feb 2024 10:58:44 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rWwgW-00013H-Nz; Mon, 05 Feb 2024 10:58:44 +0000 Received: by outflank-mailman (input) for mailman id 675882; Mon, 05 Feb 2024 10:58:43 +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 1rWwYz-0000qL-8U for xen-devel@lists.xenproject.org; Mon, 05 Feb 2024 10:50:57 +0000 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 6fdc9fc0-c414-11ee-98f5-efadbce2ee36; Mon, 05 Feb 2024 11:50:55 +0100 (CET) Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id CE8E01F8BA; Mon, 5 Feb 2024 10:50:54 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id A4FAC132DD; Mon, 5 Feb 2024 10:50:54 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id y93GJo69wGVANgAAD6G6ig (envelope-from ); Mon, 05 Feb 2024 10:50:54 +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: 6fdc9fc0-c414-11ee-98f5-efadbce2ee36 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1707130254; 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=FTPfVWkUlQhndtMJjvkYVvwFLg3Kri0CAO7AyEi1mRk=; b=nA93Rx9YrZr+hop2VC7Ain11fxephLZyrBCuGFLkClL6chC4gvPYH6mTMK1PmSUHfrSRi9 sbz39q7p1lPl91m3o5YHxBxMrUxL7UUx1++H45cSjvKNndTg22FMEHnMfDCvc74uhqD6ma TYYXWXKjt8cFw4AHI4qYp555QtfjJhg= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1707130254; 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=FTPfVWkUlQhndtMJjvkYVvwFLg3Kri0CAO7AyEi1mRk=; b=nA93Rx9YrZr+hop2VC7Ain11fxephLZyrBCuGFLkClL6chC4gvPYH6mTMK1PmSUHfrSRi9 sbz39q7p1lPl91m3o5YHxBxMrUxL7UUx1++H45cSjvKNndTg22FMEHnMfDCvc74uhqD6ma TYYXWXKjt8cFw4AHI4qYp555QtfjJhg= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Anthony PERARD Subject: [PATCH v4 09/32] tools/xen-9pfsd: add 9pfs open request support Date: Mon, 5 Feb 2024 11:49:38 +0100 Message-Id: <20240205105001.24171-10-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240205105001.24171-1-jgross@suse.com> References: <20240205105001.24171-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Authentication-Results: smtp-out2.suse.de; none X-Spam-Level: X-Spam-Score: -3.30 X-Spamd-Result: default: False [-3.30 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_THREE(0.00)[4]; R_MISSING_CHARSET(2.50)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; REPLY(-4.00)[]; BROKEN_CONTENT_TYPE(1.50)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; RCVD_COUNT_THREE(0.00)[3]; TO_DN_SOME(0.00)[]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MID_CONTAINS_FROM(1.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.com:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_ALL(0.00)[]; BAYES_HAM(-3.00)[100.00%] X-Spam-Flag: NO X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1707130743497100001 Content-Type: text/plain; charset="utf-8" Add the open request of the 9pfs protocol. Signed-off-by: Juergen Gross Acked-by: Anthony PERARD Reviewed-by: Jason Andryuk --- V2: - don't allow to open symbolic link V3: - use openat() (Jason Andryuk) - use common error handling in p9_open() --- tools/xen-9pfsd/io.c | 137 ++++++++++++++++++++++++++++++++++++ tools/xen-9pfsd/xen-9pfsd.h | 4 ++ 2 files changed, 141 insertions(+) diff --git a/tools/xen-9pfsd/io.c b/tools/xen-9pfsd/io.c index 5b827706b7..2e2275e8ab 100644 --- a/tools/xen-9pfsd/io.c +++ b/tools/xen-9pfsd/io.c @@ -19,6 +19,8 @@ #include #include #include +#include +#include #include /* For cpu barriers. */ #include =20 @@ -29,6 +31,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" @@ -829,6 +840,128 @@ 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: + errno =3D EINVAL; + 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 ) + { + errno =3D EINVAL; + goto err; + } + + if ( fstatat(device->root_fd, fidp->path, &st, 0) < 0 ) + { + errno =3D ENOENT; + goto err; + } + + if ( S_ISLNK(st.st_mode) ) + { + errno =3D EMLINK; + goto err; + } + + fidp->isdir =3D S_ISDIR(st.st_mode); + fidp->mode =3D mode; + if ( fidp->isdir ) + { + if ( mode !=3D P9_OREAD ) + { + errno =3D EINVAL; + goto err; + } + fidp->fd =3D openat(device->root_fd, fidp->path, O_RDONLY); + if ( fidp->fd < 0 ) + goto err; + fidp->data =3D fdopendir(fidp->fd); + if ( !fidp->data ) + goto err; + } + else + { + flags =3D open_flags_from_mode(mode); + if ( flags < 0 ) + goto err; + + fidp->fd =3D openat(device->root_fd, fidp->path, flags); + if ( fidp->fd < 0 ) + goto err; + } + + fill_qid(device, 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); + + return; + + err: + free_fid(device, fidp); + p9_error(ring, hdr->tag, errno); +} + void *io_thread(void *arg) { struct ring *ring =3D arg; @@ -896,6 +1029,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 f01fffb0bb..757be2da4b 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 Fri May 17 10:34:34 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=1707130692; cv=none; d=zohomail.com; s=zohoarc; b=n4b6RnI585OvxklVCSz8YOsGMBQY8m1rlFZGwcAS6XB/E/rsSBcG4IVP5yzixm92gOQ0VtUWScU/VWtOze+fL/Yhgim9xyNr+eVD3lyB749SxtvtrrJaTNpeVP5YXfjHsZgrQ7PVwQJDjdSBT4QXRsAnjh6ob+9eEGWcSjsILiM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1707130692; 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=pkY/yeFHjo5eL439i+/3VdOn4jDMqN4bEBUDTVhVOHY=; b=a+0q3sV0smcuO+Xr3YBAPa59uYSZ67o0SNRyr+oMLLokfevAEGowDtS/LHvs3ofn5xrqkI7ETV6s+bIQoOgxxHB6gz3I0sb7p5/tnZZOtMlUtcz6sXygizkw1L/7i4durzpKTV8kxNL0vZCH1p1isJE/pNdaVie6kb8kYKk3r00= 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 170713069250174.7200669988132; Mon, 5 Feb 2024 02:58:12 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.675849.1051503 (Exim 4.92) (envelope-from ) id 1rWwfm-0005mH-46; Mon, 05 Feb 2024 10:57:58 +0000 Received: by outflank-mailman (output) from mailman id 675849.1051503; Mon, 05 Feb 2024 10:57:58 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rWwfm-0005m8-0U; Mon, 05 Feb 2024 10:57:58 +0000 Received: by outflank-mailman (input) for mailman id 675849; Mon, 05 Feb 2024 10:57:56 +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 1rWwZ4-0000qL-Gw for xen-devel@lists.xenproject.org; Mon, 05 Feb 2024 10:51:02 +0000 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 73357ec5-c414-11ee-98f5-efadbce2ee36; Mon, 05 Feb 2024 11:51:00 +0100 (CET) Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 6190A1F8BB; Mon, 5 Feb 2024 10:51:00 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 38566132DD; Mon, 5 Feb 2024 10:51:00 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id 2E1cDJS9wGVFNgAAD6G6ig (envelope-from ); Mon, 05 Feb 2024 10:51:00 +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: 73357ec5-c414-11ee-98f5-efadbce2ee36 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1707130260; 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=pkY/yeFHjo5eL439i+/3VdOn4jDMqN4bEBUDTVhVOHY=; b=ADQmRxO77rZcn29jNH9MAIPkKXIBysVSKul248LPHHNK38xBqqAC0Y/wCs273iIaXJ5PR/ 1ybt1oSdufVIt2+RsQMDVmr152hMaYaf4tPBmrj2Kq8mRCzgUguHI729EedFN9Bcj65tU7 JF3joxZEHPVL4+6Vohcmm55XdCHjrJ0= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1707130260; 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=pkY/yeFHjo5eL439i+/3VdOn4jDMqN4bEBUDTVhVOHY=; b=ADQmRxO77rZcn29jNH9MAIPkKXIBysVSKul248LPHHNK38xBqqAC0Y/wCs273iIaXJ5PR/ 1ybt1oSdufVIt2+RsQMDVmr152hMaYaf4tPBmrj2Kq8mRCzgUguHI729EedFN9Bcj65tU7 JF3joxZEHPVL4+6Vohcmm55XdCHjrJ0= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Anthony PERARD Subject: [PATCH v4 10/32] tools/xen-9pfsd: add 9pfs clunk request support Date: Mon, 5 Feb 2024 11:49:39 +0100 Message-Id: <20240205105001.24171-11-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240205105001.24171-1-jgross@suse.com> References: <20240205105001.24171-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Authentication-Results: smtp-out2.suse.de; none X-Spam-Level: X-Spam-Score: -0.30 X-Spamd-Result: default: False [-0.30 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_THREE(0.00)[4]; R_MISSING_CHARSET(2.50)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; REPLY(-4.00)[]; BROKEN_CONTENT_TYPE(1.50)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; RCVD_COUNT_THREE(0.00)[3]; TO_DN_SOME(0.00)[]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MID_CONTAINS_FROM(1.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.com:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_ALL(0.00)[]; BAYES_HAM(-0.00)[12.82%] X-Spam-Flag: NO X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1707130693255100002 Content-Type: text/plain; charset="utf-8" Add the clunk request of the 9pfs protocol. Signed-off-by: Juergen Gross Acked-by: Anthony PERARD Reviewed-by: Jason Andryuk --- V3: - use unlinkat() (Jason Andryuk) --- tools/xen-9pfsd/io.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/tools/xen-9pfsd/io.c b/tools/xen-9pfsd/io.c index 2e2275e8ab..74efd21c10 100644 --- a/tools/xen-9pfsd/io.c +++ b/tools/xen-9pfsd/io.c @@ -32,6 +32,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 */ @@ -962,6 +963,44 @@ static void p9_open(struct ring *ring, struct p9_heade= r *hdr) p9_error(ring, hdr->tag, errno); } =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 ) + unlinkat(device->root_fd, fidp->path, + fidp->isdir ? AT_REMOVEDIR : 0); + } + + /* 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; @@ -1033,6 +1072,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 Fri May 17 10:34:34 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=1707130708; cv=none; d=zohomail.com; s=zohoarc; b=AuHKnJSxKjhgJRHVe7EXkcBdJz/OUm/8rQ4Vo44I0nxDK+KHrdypgEuegb6mwCPVFyqJdVFBKfQB4oYBd2iyL8BIa3+sWIajGn1fOf+jBJpT6+AzRxsc0Y6wlkhGNsChsokOeVUp5OPRdYsN+SR3+5ucxURp6LVBNt159tB5LiA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1707130708; 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=TiXUk4IRdN7gv++KjZZd3JZjo0LQdKQrTPv9GcMVW4c=; b=IBxFidBH75goVKHxuJwYl17MBfV5XcNmRTQ9OJ7aOq1NJ40c6uWPboWAieUwNBnB/s2VBZmA3KpIBhSjhOmaMS2mHogFo+0dOa7arn+efx6w9q2u5tzeroJR6MePRVXEbXOpFed9nKRh1X0k14U43cC7hP/yUGG4O1q3YYiRRh0= 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 1707130707970692.8435451470431; Mon, 5 Feb 2024 02:58:27 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.675860.1051538 (Exim 4.92) (envelope-from ) id 1rWwfw-0007DE-DP; Mon, 05 Feb 2024 10:58:08 +0000 Received: by outflank-mailman (output) from mailman id 675860.1051538; Mon, 05 Feb 2024 10:58:08 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rWwfw-0007Bq-6V; Mon, 05 Feb 2024 10:58:08 +0000 Received: by outflank-mailman (input) for mailman id 675860; Mon, 05 Feb 2024 10:58:06 +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 1rWwZA-0000qL-5V for xen-devel@lists.xenproject.org; Mon, 05 Feb 2024 10:51:08 +0000 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 7686bdb6-c414-11ee-98f5-efadbce2ee36; Mon, 05 Feb 2024 11:51:06 +0100 (CET) Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 097FF22288; Mon, 5 Feb 2024 10:51:06 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id CEB86132DD; Mon, 5 Feb 2024 10:51:05 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id ZqK1MJm9wGVMNgAAD6G6ig (envelope-from ); Mon, 05 Feb 2024 10:51:05 +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: 7686bdb6-c414-11ee-98f5-efadbce2ee36 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1707130266; 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=TiXUk4IRdN7gv++KjZZd3JZjo0LQdKQrTPv9GcMVW4c=; b=FQVch8aIWj1QLZXmLTqR9kRhfv7MfWttqidcAhomHJWNdoZql0vPUgSPp01jnkoeHovpLq 8+/qdAPGYfOWY9xKWIHcyrhlUrj1ny4kfM9tNaYY5nKYDxFqojh7eEC09VuKXIFUNMYOWd 2IhC1N50egyMa7Q/6MBUP62W47vIesM= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1707130266; 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=TiXUk4IRdN7gv++KjZZd3JZjo0LQdKQrTPv9GcMVW4c=; b=FQVch8aIWj1QLZXmLTqR9kRhfv7MfWttqidcAhomHJWNdoZql0vPUgSPp01jnkoeHovpLq 8+/qdAPGYfOWY9xKWIHcyrhlUrj1ny4kfM9tNaYY5nKYDxFqojh7eEC09VuKXIFUNMYOWd 2IhC1N50egyMa7Q/6MBUP62W47vIesM= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Anthony PERARD Subject: [PATCH v4 11/32] tools/xen-9pfsd: add 9pfs create request support Date: Mon, 5 Feb 2024 11:49:40 +0100 Message-Id: <20240205105001.24171-12-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240205105001.24171-1-jgross@suse.com> References: <20240205105001.24171-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Authentication-Results: smtp-out1.suse.de; none X-Spamd-Result: default: False [0.90 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_THREE(0.00)[4]; R_MISSING_CHARSET(2.50)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; REPLY(-4.00)[]; BROKEN_CONTENT_TYPE(1.50)[]; RCVD_COUNT_THREE(0.00)[3]; TO_DN_SOME(0.00)[]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; MID_CONTAINS_FROM(1.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.com:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_ALL(0.00)[] X-Spam-Level: X-Spam-Flag: NO X-Spam-Score: 0.90 X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1707130709349100003 Content-Type: text/plain; charset="utf-8" Add the create request of the 9pfs protocol. Signed-off-by: Juergen Gross Acked-by: Anthony PERARD Reviewed-by: Jason Andryuk --- V2: - set permissions correctly (Jason Andryuk) V3: - use opendirat() etc. (Jason Andryuk) - rework error handling a little bit --- tools/xen-9pfsd/io.c | 151 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 151 insertions(+) diff --git a/tools/xen-9pfsd/io.c b/tools/xen-9pfsd/io.c index 74efd21c10..583eea6059 100644 --- a/tools/xen-9pfsd/io.c +++ b/tools/xen-9pfsd/io.c @@ -32,6 +32,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. */ @@ -42,6 +43,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 @@ -963,6 +970,146 @@ static void p9_open(struct ring *ring, struct p9_head= er *hdr) p9_error(ring, hdr->tag, errno); } =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 ( fstatat(device->root_fd, fidp->path, &st, 0) < 0 ) + { + free_fid(device, fidp); + p9_error(ring, hdr->tag, errno); + return; + } + + path =3D malloc(strlen(fidp->path) + strlen(ring->str + name_off) + 2); + if ( !path ) + { + free_fid(device, fidp); + p9_error(ring, hdr->tag, ENOMEM); + return; + } + sprintf(path, "%s/%s", fidp->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 ) + { + errno =3D EINVAL; + goto err; + } + if ( mkdirat(device->root_fd, new_fidp->path, perm) < 0 ) + goto err; + + XEN_TAILQ_REMOVE(&device->fids, fidp, list); + XEN_TAILQ_INSERT_HEAD(&device->fids, new_fidp, list); + free(fidp); + fidp =3D new_fidp; + new_fidp =3D NULL; + + fidp->fd =3D openat(device->root_fd, fidp->path, O_RDONLY); + if ( fidp->fd < 0 ) + goto err; + fidp->data =3D fdopendir(fidp->fd); + if ( !fidp->data ) + goto err; + } + else + { + flags =3D open_flags_from_mode(mode); + if ( flags < 0 ) + { + errno =3D EINVAL; + goto err; + } + perm &=3D 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; + new_fidp =3D NULL; + + fidp->fd =3D openat(device->root_fd, fidp->path, flags | O_CREAT |= O_EXCL, + perm); + if ( fidp->fd < 0 ) + goto err; + } + + if ( fstatat(device->root_fd, fidp->path, &st, 0) < 0 ) + goto err; + + fill_qid(device, 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: + p9_error(ring, hdr->tag, errno); + + pthread_mutex_unlock(&device->fid_mutex); + + free(new_fidp); + free_fid(device, fidp); +} + static void p9_clunk(struct ring *ring, struct p9_header *hdr) { device *device =3D ring->device; @@ -1072,6 +1219,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 Fri May 17 10:34:34 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; 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=fail(p=quarantine dis=quarantine) header.from=suse.com Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1707130677096572.4454403091919; Mon, 5 Feb 2024 02:57:57 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.675838.1051463 (Exim 4.92) (envelope-from ) id 1rWwfU-0003Nz-QF; Mon, 05 Feb 2024 10:57:40 +0000 Received: by outflank-mailman (output) from mailman id 675838.1051463; Mon, 05 Feb 2024 10:57:40 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rWwfU-0003N5-Mg; Mon, 05 Feb 2024 10:57:40 +0000 Received: by outflank-mailman (input) for mailman id 675838; Mon, 05 Feb 2024 10:57:39 +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 1rWwZF-0000qL-LD for xen-devel@lists.xenproject.org; Mon, 05 Feb 2024 10:51:13 +0000 Received: from smtp-out2.suse.de (smtp-out2.suse.de [2a07:de40:b251:101:10:150:64:2]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 79ce377d-c414-11ee-98f5-efadbce2ee36; Mon, 05 Feb 2024 11:51:11 +0100 (CET) Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 9CE161F8C5; Mon, 5 Feb 2024 10:51:11 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 71686132DD; Mon, 5 Feb 2024 10:51:11 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id Jy0lGp+9wGVXNgAAD6G6ig (envelope-from ); Mon, 05 Feb 2024 10:51:11 +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: 79ce377d-c414-11ee-98f5-efadbce2ee36 From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Anthony PERARD Subject: [PATCH v4 12/32] tools/xen-9pfsd: add 9pfs stat request support Date: Mon, 5 Feb 2024 11:49:41 +0100 Message-Id: <20240205105001.24171-13-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240205105001.24171-1-jgross@suse.com> References: <20240205105001.24171-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spam-Level: Authentication-Results: smtp-out2.suse.de; none X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Spamd-Result: default: False [-4.00 / 50.00]; REPLY(-4.00)[] X-Spam-Score: -4.00 X-Rspamd-Queue-Id: 9CE161F8C5 X-Spam-Flag: NO X-ZM-MESSAGEID: 1707130679239100001 Content-Type: text/plain; charset="utf-8" Add the stat request of the 9pfs protocol. Signed-off-by: Juergen Gross Acked-by: Anthony PERARD Reviewed-by: Jason Andryuk --- V3: - use fstatat() (Jason Andryuk) V4: - add "s" format to fill_buffer() as a preparation for reading dirs --- tools/xen-9pfsd/io.c | 102 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) diff --git a/tools/xen-9pfsd/io.c b/tools/xen-9pfsd/io.c index 583eea6059..031cff9f0e 100644 --- a/tools/xen-9pfsd/io.c +++ b/tools/xen-9pfsd/io.c @@ -34,6 +34,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 */ @@ -60,6 +61,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, @@ -166,6 +186,7 @@ static void fmt_err(const char *fmt) * 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 + * s: stat (struct p9_stat) * U: 4 byte unsigned integer * The parameter is a pointer to a uint32_t value */ @@ -176,6 +197,8 @@ static void vfill_buffer_at(void **data, const char *fm= t, va_list ap) const void *par; const char *str_val; const struct p9_qid *qid; + const struct p9_stat *stat; + uint16_t tlen; unsigned int len; unsigned int array_sz =3D 0; unsigned int elem_sz =3D 0; @@ -259,6 +282,18 @@ static void vfill_buffer_at(void **data, const char *f= mt, va_list ap) *data +=3D len; break; =20 + case 's': + stat =3D par; + elem_sz =3D sizeof(*stat); + tlen =3D stat->size + sizeof(stat->size); + fill_buffer_at(data, "uuuUQUUULSSSSSUUU", &tlen, &stat->size, + &stat->type, &stat->dev, &stat->qid, &stat->mod= e, + &stat->atime, &stat->mtime, &stat->length, + stat->name, stat->uid, stat->gid, stat->muid, + stat->extension, &stat->n_uid, &stat->n_gid, + &stat->n_muid); + break; + case 'U': put_unaligned(*(const uint32_t *)par, (uint32_t *)*data); elem_sz =3D sizeof(uint32_t); @@ -1148,6 +1183,69 @@ 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(device *device, struct p9_stat *p9s, struct stat = *st, + const char *name) +{ + memset(p9s, 0, sizeof(*p9s)); + fill_qid(device, 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; + 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 ( fstatat(device->root_fd, fidp->path, &st, 0) < 0 ) + { + p9_error(ring, hdr->tag, errno); + goto out; + } + fill_p9_stat(device, &p9s, &st, strrchr(fidp->path, '/') + 1); + + fill_buffer(ring, hdr->cmd + 1, hdr->tag, "s", &p9s); + + out: + free_fid(device, fidp); +} + void *io_thread(void *arg) { struct ring *ring =3D arg; @@ -1227,6 +1325,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 Fri May 17 10:34:34 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; 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=fail(p=quarantine dis=quarantine) header.from=suse.com Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1707130657187893.8670720537522; Mon, 5 Feb 2024 02:57:37 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.675831.1051412 (Exim 4.92) (envelope-from ) id 1rWwfE-0001Vv-Ec; Mon, 05 Feb 2024 10:57:24 +0000 Received: by outflank-mailman (output) from mailman id 675831.1051412; Mon, 05 Feb 2024 10:57:24 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rWwfE-0001Vo-Bg; Mon, 05 Feb 2024 10:57:24 +0000 Received: by outflank-mailman (input) for mailman id 675831; Mon, 05 Feb 2024 10:57:22 +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 1rWwZL-0000qL-2S for xen-devel@lists.xenproject.org; Mon, 05 Feb 2024 10:51:19 +0000 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 7d259515-c414-11ee-98f5-efadbce2ee36; Mon, 05 Feb 2024 11:51:17 +0100 (CET) Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 3AB8D2228A; Mon, 5 Feb 2024 10:51:17 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 0AF08132DD; Mon, 5 Feb 2024 10:51:17 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id x5wxAaW9wGVeNgAAD6G6ig (envelope-from ); Mon, 05 Feb 2024 10:51:17 +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: 7d259515-c414-11ee-98f5-efadbce2ee36 From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Anthony PERARD , Jason Andryuk Subject: [PATCH v4 13/32] tools/xen-9pfsd: add 9pfs write request support Date: Mon, 5 Feb 2024 11:49:42 +0100 Message-Id: <20240205105001.24171-14-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240205105001.24171-1-jgross@suse.com> References: <20240205105001.24171-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Authentication-Results: smtp-out1.suse.de; none X-Spamd-Result: default: False [-4.00 / 50.00]; REPLY(-4.00)[] X-Rspamd-Server: rspamd1.dmz-prg2.suse.org X-Rspamd-Queue-Id: 3AB8D2228A X-Spam-Level: X-Spam-Score: -4.00 X-Spam-Flag: NO X-ZM-MESSAGEID: 1707130659232100001 Content-Type: text/plain; charset="utf-8" Add the write request of the 9pfs protocol. Signed-off-by: Juergen Gross Reviewed-by: Jason Andryuk Acked-by: Anthony PERARD --- 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 031cff9f0e..b763e3d8d9 100644 --- a/tools/xen-9pfsd/io.c +++ b/tools/xen-9pfsd/io.c @@ -33,6 +33,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 @@ -1246,6 +1247,55 @@ static void p9_stat(struct ring *ring, struct p9_hea= der *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); +} + void *io_thread(void *arg) { struct ring *ring =3D arg; @@ -1321,6 +1371,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 Fri May 17 10:34:34 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=1707130691; cv=none; d=zohomail.com; s=zohoarc; b=X9/5+fuOspVhy972uRheFFVd3giLLSXdcPAdkBBGL2ZZ5RQu1/fUVmRQN51H2isOoUyrlwovEkUkFf+Rud0MhPsN/MAmR6o23aFeSg7xB+sR+PhBe2amjk7yfVlFsv5VKzsZQkKC98VgS0ukdecO5tIqiXDDZFGdXHqAmow0hhk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1707130691; 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=zG6E8AnOVGoVetT7WwKYTZr00RdCVDPWEd53rIfPGH8=; b=Xj+gvjZqnLNd4qqG71uzcA0QB3yd4I8VjFwDabnT4A0qr68+LGKP7qWnzW9SKr1kgySy3pWk8YgiVC85JwmM+2DtZy+jeFCEe/Uz92P/mp9RZzoWRSadhQBXVOKphE4os9Jl+hXjdG4UOvciKGuN6Ln672d3gKLqHEWdi4QMtYo= 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 1707130691243163.48250348768795; Mon, 5 Feb 2024 02:58:11 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.675847.1051493 (Exim 4.92) (envelope-from ) id 1rWwfi-0005GH-S6; Mon, 05 Feb 2024 10:57:54 +0000 Received: by outflank-mailman (output) from mailman id 675847.1051493; Mon, 05 Feb 2024 10:57: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 1rWwfi-0005Fk-On; Mon, 05 Feb 2024 10:57:54 +0000 Received: by outflank-mailman (input) for mailman id 675847; Mon, 05 Feb 2024 10:57: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 1rWwZP-0002wU-ON for xen-devel@lists.xenproject.org; Mon, 05 Feb 2024 10:51:23 +0000 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 80824b0b-c414-11ee-8a45-1f161083a0e0; Mon, 05 Feb 2024 11:51:23 +0100 (CET) Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id C6FFC1F8C0; Mon, 5 Feb 2024 10:51:22 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 99820132DD; Mon, 5 Feb 2024 10:51:22 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id PxkaJKq9wGVjNgAAD6G6ig (envelope-from ); Mon, 05 Feb 2024 10:51:22 +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: 80824b0b-c414-11ee-8a45-1f161083a0e0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1707130282; 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=zG6E8AnOVGoVetT7WwKYTZr00RdCVDPWEd53rIfPGH8=; b=UU62A3+MXUu2WBMoDgVQoEf4iO6lCkjABHyh+SpKYyuMWTpGm2Nkb9suU+HVxnAu3kQd/K e87se/bad9W6phvLymD3akQwZk+ppyxLQMMQDUFNtp2H5FwWrrbvaJORaDXXwUrP4s+LQ/ hxc1ooYCFK2lbZEtZgQne0g7JxRgEjM= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1707130282; 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=zG6E8AnOVGoVetT7WwKYTZr00RdCVDPWEd53rIfPGH8=; b=UU62A3+MXUu2WBMoDgVQoEf4iO6lCkjABHyh+SpKYyuMWTpGm2Nkb9suU+HVxnAu3kQd/K e87se/bad9W6phvLymD3akQwZk+ppyxLQMMQDUFNtp2H5FwWrrbvaJORaDXXwUrP4s+LQ/ hxc1ooYCFK2lbZEtZgQne0g7JxRgEjM= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Anthony PERARD , Jason Andryuk Subject: [PATCH v4 14/32] tools/xen-9pfsd: add 9pfs read request support Date: Mon, 5 Feb 2024 11:49:43 +0100 Message-Id: <20240205105001.24171-15-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240205105001.24171-1-jgross@suse.com> References: <20240205105001.24171-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Authentication-Results: smtp-out2.suse.de; none X-Spamd-Result: default: False [0.90 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; FREEMAIL_ENVRCPT(0.00)[gmail.com]; R_MISSING_CHARSET(2.50)[]; MIME_GOOD(-0.10)[text/plain]; TO_MATCH_ENVRCPT_ALL(0.00)[]; REPLY(-4.00)[]; BROKEN_CONTENT_TYPE(1.50)[]; RCPT_COUNT_FIVE(0.00)[5]; RCVD_COUNT_THREE(0.00)[3]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; MID_CONTAINS_FROM(1.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.com:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; FREEMAIL_CC(0.00)[suse.com,xen.org,citrix.com,gmail.com]; RCVD_TLS_ALL(0.00)[] X-Spam-Level: X-Spam-Flag: NO X-Spam-Score: 0.90 X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1707130693255100001 Content-Type: text/plain; charset="utf-8" Add the read request of the 9pfs protocol. Signed-off-by: Juergen Gross Reviewed-by: Jason Andryuk Acked-by: Anthony PERARD --- V2: - make error check more readable (Jason Andryuk) V4: - add directory read support --- tools/xen-9pfsd/io.c | 90 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) diff --git a/tools/xen-9pfsd/io.c b/tools/xen-9pfsd/io.c index b763e3d8d9..cfbf3bef59 100644 --- a/tools/xen-9pfsd/io.c +++ b/tools/xen-9pfsd/io.c @@ -33,6 +33,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 @@ -1247,6 +1248,91 @@ static void p9_stat(struct ring *ring, struct p9_hea= der *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 ) + { + errno =3D EBADF; + goto err; + } + + len =3D count; + buf =3D ring->buffer + sizeof(*hdr) + sizeof(uint32_t); + + if ( fidp->isdir ) + { + struct dirent *dirent; + struct stat st; + struct p9_stat p9s; + + while ( len !=3D 0 ) + { + errno =3D 0; + dirent =3D readdir(fidp->data); + if ( !dirent ) + { + if ( errno ) + goto err; + break; + } + if ( fstatat(fidp->fd, dirent->d_name, &st, 0) < 0 ) + goto err; + fill_p9_stat(device, &p9s, &st, dirent->d_name); + if ( p9s.size + sizeof(p9s.size) > len ) + { + seekdir(fidp->data, dirent->d_off); + break; + } + fill_buffer_at(&buf, "s", &p9s); + len -=3D p9s.size + sizeof(p9s.size); + } + } + else + { + 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 ) + goto err; + } + + 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); + + return; + + err: + p9_error(ring, hdr->tag, errno); + goto out; +} + static void p9_write(struct ring *ring, struct p9_header *hdr) { device *device =3D ring->device; @@ -1371,6 +1457,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 Fri May 17 10:34:34 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=1707130680; cv=none; d=zohomail.com; s=zohoarc; b=NKjkZ59FpWYm6pPB3yYeRT05M0PTy9EJl9z67ambDWMfY5FLtuXLKv/PHs1jgRXgwZdH1bpEF6lRkiYOrtpgcliaAFj5KowodWeHnSnngx4N638LiPsmyDxoiFBGktLoZV7Mad3sbGZl1CHt6quJqjfb2gumo00DpLL+d6vJEf0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1707130680; 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=4t9CaY2HdSuK4w688pTUcmMnQS10iOMn7pZg/fdTzSY=; b=NIGlr61CQPq+024G2olKENt2nm7X3ZPS646R9CdNnwdETqud0OZUVUjvKrfrKMHCaGdHExaozY9YkfLcAAA6OyBO8hH/QLXMq0Vs8dsJWAlhzPR4DMleFeg364mPVcj8KNnlnknNxeaMXUPXQTQKnQxj0fa3H0Z8nD0hwjm+br4= 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 1707130680337657.4086836180952; Mon, 5 Feb 2024 02:58:00 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.675842.1051473 (Exim 4.92) (envelope-from ) id 1rWwfZ-00041b-2R; Mon, 05 Feb 2024 10:57:45 +0000 Received: by outflank-mailman (output) from mailman id 675842.1051473; Mon, 05 Feb 2024 10:57: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 1rWwfY-00041Q-VM; Mon, 05 Feb 2024 10:57:44 +0000 Received: by outflank-mailman (input) for mailman id 675842; Mon, 05 Feb 2024 10:57:43 +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 1rWwZW-0000qL-Vy for xen-devel@lists.xenproject.org; Mon, 05 Feb 2024 10:51:31 +0000 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 83f64304-c414-11ee-98f5-efadbce2ee36; Mon, 05 Feb 2024 11:51:29 +0100 (CET) Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 722122228B; Mon, 5 Feb 2024 10:51:28 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 30D55132DD; Mon, 5 Feb 2024 10:51:28 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id 00Z8CrC9wGWONgAAD6G6ig (envelope-from ); Mon, 05 Feb 2024 10:51:28 +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: 83f64304-c414-11ee-98f5-efadbce2ee36 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1707130288; 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=4t9CaY2HdSuK4w688pTUcmMnQS10iOMn7pZg/fdTzSY=; b=FpXGNn3J0p85LBUD59mX6ixHhRtOEUaPKA5cRgtiNCkAioACVKEwKq0rd2cN25Lq+wLZsO WKaRiGRU+S4yv4QuNwa8F27Js0QNNWsHC5+vt+nj/iw6ttr8PHphL8gLbD4NoF5Nc929bX pndAAos6MwBLMzqVZCD7wDRL5vWSVFQ= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1707130288; 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=4t9CaY2HdSuK4w688pTUcmMnQS10iOMn7pZg/fdTzSY=; b=FpXGNn3J0p85LBUD59mX6ixHhRtOEUaPKA5cRgtiNCkAioACVKEwKq0rd2cN25Lq+wLZsO WKaRiGRU+S4yv4QuNwa8F27Js0QNNWsHC5+vt+nj/iw6ttr8PHphL8gLbD4NoF5Nc929bX pndAAos6MwBLMzqVZCD7wDRL5vWSVFQ= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , George Dunlap , Nick Rosbrook , Wei Liu , Anthony PERARD , Jason Andryuk , George Dunlap Subject: [PATCH v4 15/32] tools/libs/light: add backend type for 9pfs PV devices Date: Mon, 5 Feb 2024 11:49:44 +0100 Message-Id: <20240205105001.24171-16-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240205105001.24171-1-jgross@suse.com> References: <20240205105001.24171-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Authentication-Results: smtp-out1.suse.de; none X-Spam-Level: X-Spam-Score: -3.30 X-Spamd-Result: default: False [-3.30 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; R_MISSING_CHARSET(2.50)[]; FREEMAIL_ENVRCPT(0.00)[gmail.com]; MIME_GOOD(-0.10)[text/plain]; TO_MATCH_ENVRCPT_ALL(0.00)[]; REPLY(-4.00)[]; BROKEN_CONTENT_TYPE(1.50)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; RCVD_COUNT_THREE(0.00)[3]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; NEURAL_HAM_SHORT(-0.20)[-1.000]; RCPT_COUNT_SEVEN(0.00)[8]; MID_CONTAINS_FROM(1.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.com:email,cloud.com:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; FREEMAIL_CC(0.00)[suse.com,citrix.com,gmail.com,xen.org,cloud.com]; RCVD_TLS_ALL(0.00)[]; BAYES_HAM(-3.00)[100.00%] X-Spam-Flag: NO X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1707130681256100001 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 Acked-by: George Dunlap # Golang bits --- V3: - regenerate go bindings V4: - rename libxl_device_p9_dm_needed() to libxl__device_p9_dm_needed() (Anthony Perard) - reorder span related functions (Anthony Perard) - add comment for xen9pfsd_spawn() return values (Anthony Perard) - add LIBXL_HAVE_XEN_9PFS to libxl.h (Anthony Perard) - use a copy of 'p9' in xen9pfsd_spawn() (Anthony Perard) --- tools/golang/xenlight/helpers.gen.go | 16 +++ tools/golang/xenlight/types.gen.go | 13 ++ tools/include/libxl.h | 7 + tools/libs/light/libxl_9pfs.c | 159 +++++++++++++++++++++- 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 + 8 files changed, 206 insertions(+), 7 deletions(-) diff --git a/tools/golang/xenlight/helpers.gen.go b/tools/golang/xenlight/h= elpers.gen.go index 35e209ff1b..8f44397a4e 100644 --- a/tools/golang/xenlight/helpers.gen.go +++ b/tools/golang/xenlight/helpers.gen.go @@ -1280,6 +1280,9 @@ return fmt.Errorf("converting field Rdm: %v", err) } x.RdmMemBoundaryMemkb =3D uint64(tmp.rdm_mem_boundary_memkb) x.McaCaps =3D uint64(tmp.mca_caps) +if err :=3D x.Pirq.fromC(&tmp.pirq);err !=3D nil { +return fmt.Errorf("converting field Pirq: %v", err) +} return nil } =20 @@ -1613,6 +1616,9 @@ return fmt.Errorf("converting field Rdm: %v", err) } hvm.rdm_mem_boundary_memkb =3D C.uint64_t(tmp.RdmMemBoundaryMemkb) hvm.mca_caps =3D C.uint64_t(tmp.McaCaps) +if err :=3D tmp.Pirq.toC(&hvm.pirq); err !=3D nil { +return fmt.Errorf("converting field Pirq: %v", err) +} hvmBytes :=3D C.GoBytes(unsafe.Pointer(&hvm),C.sizeof_libxl_domain_build_i= nfo_type_union_hvm) copy(xc.u[:],hvmBytes) case DomainTypePv: @@ -2434,6 +2440,11 @@ x.Tag =3D C.GoString(xc.tag) x.Path =3D C.GoString(xc.path) x.SecurityModel =3D C.GoString(xc.security_model) x.Devid =3D Devid(xc.devid) +x.Type =3D P9Type(xc._type) +x.MaxSpace =3D int(xc.max_space) +x.MaxFiles =3D int(xc.max_files) +x.MaxOpenFiles =3D int(xc.max_open_files) +x.AutoDelete =3D bool(xc.auto_delete) =20 return nil} =20 @@ -2452,6 +2463,11 @@ xc.path =3D C.CString(x.Path)} if x.SecurityModel !=3D "" { xc.security_model =3D C.CString(x.SecurityModel)} xc.devid =3D C.libxl_devid(x.Devid) +xc._type =3D C.libxl_p9_type(x.Type) +xc.max_space =3D C.int(x.MaxSpace) +xc.max_files =3D C.int(x.MaxFiles) +xc.max_open_files =3D C.int(x.MaxOpenFiles) +xc.auto_delete =3D C.bool(x.AutoDelete) =20 return nil } diff --git a/tools/golang/xenlight/types.gen.go b/tools/golang/xenlight/typ= es.gen.go index 7907aa8999..d31722407a 100644 --- a/tools/golang/xenlight/types.gen.go +++ b/tools/golang/xenlight/types.gen.go @@ -122,6 +122,13 @@ NicTypeVifIoemu NicType =3D 1 NicTypeVif NicType =3D 2 ) =20 +type P9Type int +const( +P9TypeUnknown P9Type =3D 0 +P9TypeQemu P9Type =3D 1 +P9TypeXen9Pfsd P9Type =3D 2 +) + type ActionOnShutdown int const( ActionOnShutdownDestroy ActionOnShutdown =3D 1 @@ -651,6 +658,7 @@ SerialList StringList Rdm RdmReserve RdmMemBoundaryMemkb uint64 McaCaps uint64 +Pirq Defbool } =20 func (x DomainBuildInfoTypeUnionHvm) isDomainBuildInfoTypeUnion(){} @@ -888,6 +896,11 @@ Tag string Path string SecurityModel string Devid Devid +Type P9Type +MaxSpace int +MaxFiles int +MaxOpenFiles int +AutoDelete bool } =20 type DevicePvcallsif struct { diff --git a/tools/include/libxl.h b/tools/include/libxl.h index f1652b1664..a554f2ccd6 100644 --- a/tools/include/libxl.h +++ b/tools/include/libxl.h @@ -615,6 +615,13 @@ */ #define LIBXL_HAVE_HVM_PIRQ 1 =20 +/* + * LIBXL_HAVE_XEN_9PFS indicates the presence of the xen-9pfsd related + * fields in libxl_device_p9: type, max_space, max_files, max_open_files a= nd + * auto_delete. + */ +#define LIBXL_HAVE_XEN_9PFS 1 + /* * libxl memory management * diff --git a/tools/libs/light/libxl_9pfs.c b/tools/libs/light/libxl_9pfs.c index 5ab0d3aa21..68fa9947ad 100644 --- a/tools/libs/light/libxl_9pfs.c +++ b/tools/libs/light/libxl_9pfs.c @@ -33,20 +33,173 @@ 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_confirm(libxl__egc *egc, libxl__spawn_state *spawn, + const char *xsdata); +static void xen9pfsd_failed(libxl__egc *egc, libxl__spawn_state *spawn, in= t rc); +static void xen9pfsd_detached(libxl__egc *egc, libxl__spawn_state *spawn); +static void xen9pfsd_spawn_outcome(libxl__egc *egc, libxl__aop9_state *aop= 9, + int rc); + +/* + * Spawn the xen-9pfsd daemon if needed. + * returns: + * < 0 if error + * 0 if no daemon needs to be spawned + * 1 if daemon was spawned + */ +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; + libxl_device_p9_copy(CTX, &aop9->p9, 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 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 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 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 0008fac607..5546335973 100644 --- a/tools/libs/light/libxl_create.c +++ b/tools/libs/light/libxl_create.c @@ -1761,9 +1761,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]); @@ -1900,6 +1897,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 899ad30969..682092a058 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 @@ -943,6 +949,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 Fri May 17 10:34:34 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=1707130796; cv=none; d=zohomail.com; s=zohoarc; b=HKoQWBkbMoqxulsZ5vDQw3MEDzJSyVb8u2jj6THd+zY2Xkb2vY9AzVGXS25YacW8QEoPvMn6wVOByRH8mnZ3cEdJ1odUDuy6BVSOgqsl1RdZ2vkhqO9gefADPMRkQH6OQ1Fcd2R4j5Hp8yeRKJXfzgrHygw8WD6H0RenvVfrxq0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1707130796; 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=h0jxnSPLZTXt0UgW8EvhU376ps4C4d/D3zwFe+T6tRE=; b=jlAKjc8ZLZW/N402Yz7Phbskm2SSxY2br2x6u+YVCHpuI/8faZpIjA9yZOgLREHZ0dDv9XZzLAj70T+zJgbscIo6Z+OfWqXqYYdNHvT0rWbZX1mP9cXg6nZPxc88+hy52jc3LAlRyOxcRHFLmTRfw+oKulAajcewbT3IlXBB0Cw= 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 1707130796150372.9214389222426; Mon, 5 Feb 2024 02:59:56 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.675902.1051598 (Exim 4.92) (envelope-from ) id 1rWwhQ-0003ca-AF; Mon, 05 Feb 2024 10:59:40 +0000 Received: by outflank-mailman (output) from mailman id 675902.1051598; Mon, 05 Feb 2024 10:59:40 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rWwhQ-0003bx-4L; Mon, 05 Feb 2024 10:59:40 +0000 Received: by outflank-mailman (input) for mailman id 675902; Mon, 05 Feb 2024 10:59:39 +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 1rWwZb-0002wU-3o for xen-devel@lists.xenproject.org; Mon, 05 Feb 2024 10:51:35 +0000 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 87365d1d-c414-11ee-8a45-1f161083a0e0; Mon, 05 Feb 2024 11:51:34 +0100 (CET) Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 0C76E1F8BA; Mon, 5 Feb 2024 10:51:34 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id D28CE132DD; Mon, 5 Feb 2024 10:51:33 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id qvb3MbW9wGWVNgAAD6G6ig (envelope-from ); Mon, 05 Feb 2024 10:51:33 +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: 87365d1d-c414-11ee-8a45-1f161083a0e0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1707130294; 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=h0jxnSPLZTXt0UgW8EvhU376ps4C4d/D3zwFe+T6tRE=; b=EnUOwUQ/3F5sKaosP/ma2J4roQfFx+oWZZzhZeBFhGT6sKJXu3PO70y2VtPVMHZEfasPrK xrBOXPAvMS5UNMIh+sVxO16ohUDPO+OQM3nWqKAbW8vre94mjojrgyiWk/LSFq6/mi+xkD +PFHUU162jed1J0ctHrvSoNASg0VKPc= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1707130294; 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=h0jxnSPLZTXt0UgW8EvhU376ps4C4d/D3zwFe+T6tRE=; b=EnUOwUQ/3F5sKaosP/ma2J4roQfFx+oWZZzhZeBFhGT6sKJXu3PO70y2VtPVMHZEfasPrK xrBOXPAvMS5UNMIh+sVxO16ohUDPO+OQM3nWqKAbW8vre94mjojrgyiWk/LSFq6/mi+xkD +PFHUU162jed1J0ctHrvSoNASg0VKPc= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Anthony PERARD , Jason Andryuk Subject: [PATCH v4 16/32] tools/xl: support new 9pfs backend xen_9pfsd Date: Mon, 5 Feb 2024 11:49:45 +0100 Message-Id: <20240205105001.24171-17-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240205105001.24171-1-jgross@suse.com> References: <20240205105001.24171-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Authentication-Results: smtp-out2.suse.de; none X-Spam-Level: X-Spam-Score: -3.30 X-Spamd-Result: default: False [-3.30 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; R_MISSING_CHARSET(2.50)[]; FREEMAIL_ENVRCPT(0.00)[gmail.com]; MIME_GOOD(-0.10)[text/plain]; TO_MATCH_ENVRCPT_ALL(0.00)[]; REPLY(-4.00)[]; BROKEN_CONTENT_TYPE(1.50)[]; RCPT_COUNT_FIVE(0.00)[5]; NEURAL_HAM_LONG(-1.00)[-1.000]; RCVD_COUNT_THREE(0.00)[3]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MID_CONTAINS_FROM(1.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.com:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; FREEMAIL_CC(0.00)[suse.com,xen.org,citrix.com,gmail.com]; RCVD_TLS_ALL(0.00)[]; BAYES_HAM(-3.00)[100.00%] X-Spam-Flag: NO X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1707130797719100001 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/". Do most of the default settings in libxl. Unfortunately the default path can't easily be set in libxl, as the domain name isn't available in the related 9pfs specific function. Settings the defaults in libxl requires to move the sanity checking of 9pfs parameters from xl to libxl, too. Signed-off-by: Juergen Gross Reviewed-by: Jason Andryuk --- V2: - test max_files and max_open_files, too (Jason Andryuk) V4: - fix man page to use the "xen_9pfsd" type due to idl limitation (Jason Andryuk) - set (most of) the defaults in libxl (Anthony Perard) --- docs/man/xl.cfg.5.pod.in | 36 +++++++++++++++++++++++++++++++++-- tools/libs/light/libxl_9pfs.c | 18 ++++++++++++++++++ tools/xl/xl_parse.c | 23 +++++++++++++++++++--- 3 files changed, 72 insertions(+), 5 deletions(-) diff --git a/docs/man/xl.cfg.5.pod.in b/docs/man/xl.cfg.5.pod.in index ea8d41727d..039e057318 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/libs/light/libxl_9pfs.c b/tools/libs/light/libxl_9pfs.c index 68fa9947ad..7593686a90 100644 --- a/tools/libs/light/libxl_9pfs.c +++ b/tools/libs/light/libxl_9pfs.c @@ -20,6 +20,24 @@ static int libxl__device_p9_setdefault(libxl__gc *gc, uint32_t domid, libxl_device_p9 *p9, bool hotplug) { + 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)) { + LOGD(ERROR, domid, "Illegal 9pfs parameter combination"); + return ERROR_INVAL; + } + if (p9->type =3D=3D LIBXL_P9_TYPE_XEN_9PFSD && !p9->tag) { + p9->tag =3D libxl__strdup(NOGC, "Xen"); + } + + if (!p9->path || !p9->security_model || !p9->tag) { + LOGD(ERROR, domid, "9pfs spec missing required field!"); + return ERROR_INVAL; + } + return libxl__resolve_domid(gc, p9->backend_domname, &p9->backend_domi= d); } =20 diff --git a/tools/xl/xl_parse.c b/tools/xl/xl_parse.c index 9b358f11b8..80ffe85f5e 100644 --- a/tools/xl/xl_parse.c +++ b/tools/xl/xl_parse.c @@ -2233,6 +2233,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); @@ -2243,9 +2257,12 @@ void parse_config_data(const char *config_source, =20 libxl_string_list_dispose(&pairs); =20 - if (!p9->path || !p9->security_model || !p9->tag) { - fprintf(stderr, "9pfs spec missing required field!\n"); - exit(1); + if (p9->type =3D=3D LIBXL_P9_TYPE_XEN_9PFSD && !p9->path) { + char *path; + + xasprintf(&path, XEN_LOG_DIR "/guests/%s", c_info->name); + replace_string(&p9->path, path); + free(path); } } } --=20 2.35.3 From nobody Fri May 17 10:34:34 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; 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=fail(p=quarantine dis=quarantine) header.from=suse.com Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1707130699002155.08214288580973; Mon, 5 Feb 2024 02:58:19 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.675857.1051523 (Exim 4.92) (envelope-from ) id 1rWwfs-0006gk-N1; Mon, 05 Feb 2024 10:58:04 +0000 Received: by outflank-mailman (output) from mailman id 675857.1051523; Mon, 05 Feb 2024 10:58: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 1rWwfs-0006gW-JG; Mon, 05 Feb 2024 10:58:04 +0000 Received: by outflank-mailman (input) for mailman id 675857; Mon, 05 Feb 2024 10:58:03 +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 1rWwZh-0000qL-GV for xen-devel@lists.xenproject.org; Mon, 05 Feb 2024 10:51:41 +0000 Received: from smtp-out2.suse.de (smtp-out2.suse.de [2a07:de40:b251:101:10:150:64:2]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 8a8666d6-c414-11ee-98f5-efadbce2ee36; Mon, 05 Feb 2024 11:51:39 +0100 (CET) Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id A9D531F8BD; Mon, 5 Feb 2024 10:51:39 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 73C17132DD; Mon, 5 Feb 2024 10:51:39 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id QSfEGru9wGWeNgAAD6G6ig (envelope-from ); Mon, 05 Feb 2024 10:51:39 +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: 8a8666d6-c414-11ee-98f5-efadbce2ee36 From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Julien Grall , Anthony PERARD , Jason Andryuk Subject: [PATCH v4 17/32] tools/helpers: allocate xenstore event channel for xenstore stubdom Date: Mon, 5 Feb 2024 11:49:46 +0100 Message-Id: <20240205105001.24171-18-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240205105001.24171-1-jgross@suse.com> References: <20240205105001.24171-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spam-Level: Authentication-Results: smtp-out2.suse.de; none X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Spamd-Result: default: False [-4.00 / 50.00]; REPLY(-4.00)[] X-Spam-Score: -4.00 X-Rspamd-Queue-Id: A9D531F8BD X-Spam-Flag: NO X-ZM-MESSAGEID: 1707130699268100003 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 Fri May 17 10:34:34 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; 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=fail(p=quarantine dis=quarantine) header.from=suse.com Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1707130682401958.5728301979981; Mon, 5 Feb 2024 02:58:02 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.675844.1051483 (Exim 4.92) (envelope-from ) id 1rWwfa-0004M1-Lh; Mon, 05 Feb 2024 10:57:46 +0000 Received: by outflank-mailman (output) from mailman id 675844.1051483; Mon, 05 Feb 2024 10:57: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 1rWwfa-0004LN-GO; Mon, 05 Feb 2024 10:57:46 +0000 Received: by outflank-mailman (input) for mailman id 675844; Mon, 05 Feb 2024 10:57:45 +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 1rWwZm-0002wU-6T for xen-devel@lists.xenproject.org; Mon, 05 Feb 2024 10:51:46 +0000 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 8de5d924-c414-11ee-8a45-1f161083a0e0; Mon, 05 Feb 2024 11:51:45 +0100 (CET) Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 558361F8BA; Mon, 5 Feb 2024 10:51:45 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 19C2A132DD; Mon, 5 Feb 2024 10:51:45 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id pOnnBMG9wGWnNgAAD6G6ig (envelope-from ); Mon, 05 Feb 2024 10:51:45 +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: 8de5d924-c414-11ee-8a45-1f161083a0e0 From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Julien Grall , Anthony PERARD , Julien Grall , Jason Andryuk Subject: [PATCH v4 18/32] tools/xenstored: rename xenbus_evtchn() Date: Mon, 5 Feb 2024 11:49:47 +0100 Message-Id: <20240205105001.24171-19-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240205105001.24171-1-jgross@suse.com> References: <20240205105001.24171-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Authentication-Results: smtp-out2.suse.de; none X-Spamd-Result: default: False [-4.00 / 50.00]; REPLY(-4.00)[] X-Rspamd-Server: rspamd1.dmz-prg2.suse.org X-Rspamd-Queue-Id: 558361F8BA X-Spam-Level: X-Spam-Score: -4.00 X-Spam-Flag: NO X-ZM-MESSAGEID: 1707130683140100003 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 Fri May 17 10:34:34 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; 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=fail(p=quarantine dis=quarantine) header.from=suse.com Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1707130696175205.72406730119462; Mon, 5 Feb 2024 02:58:16 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.675851.1051513 (Exim 4.92) (envelope-from ) id 1rWwfp-0006CN-Bz; Mon, 05 Feb 2024 10:58:01 +0000 Received: by outflank-mailman (output) from mailman id 675851.1051513; Mon, 05 Feb 2024 10:58:01 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rWwfp-0006C1-7g; Mon, 05 Feb 2024 10:58:01 +0000 Received: by outflank-mailman (input) for mailman id 675851; Mon, 05 Feb 2024 10:58:00 +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 1rWwZs-0000qL-Nd for xen-devel@lists.xenproject.org; Mon, 05 Feb 2024 10:51:52 +0000 Received: from smtp-out2.suse.de (smtp-out2.suse.de [2a07:de40:b251:101:10:150:64:2]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 913c5fb1-c414-11ee-98f5-efadbce2ee36; Mon, 05 Feb 2024 11:51:51 +0100 (CET) Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id E7BD61F8BB; Mon, 5 Feb 2024 10:51:50 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id B22E3132DD; Mon, 5 Feb 2024 10:51:50 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id Mk79Kca9wGWvNgAAD6G6ig (envelope-from ); Mon, 05 Feb 2024 10:51:50 +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: 913c5fb1-c414-11ee-98f5-efadbce2ee36 From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Samuel Thibault , Jason Andryuk Subject: [PATCH v4 19/32] stubdom: extend xenstore stubdom configs Date: Mon, 5 Feb 2024 11:49:48 +0100 Message-Id: <20240205105001.24171-20-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240205105001.24171-1-jgross@suse.com> References: <20240205105001.24171-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spam-Level: Authentication-Results: smtp-out2.suse.de; none X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Spamd-Result: default: False [-4.00 / 50.00]; REPLY(-4.00)[] X-Spam-Score: -4.00 X-Rspamd-Queue-Id: E7BD61F8BB X-Spam-Flag: NO X-ZM-MESSAGEID: 1707130697288100001 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 Fri May 17 10:34:34 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; 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=fail(p=quarantine dis=quarantine) header.from=suse.com Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1707130737816979.4029761199267; Mon, 5 Feb 2024 02:58:57 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.675883.1051563 (Exim 4.92) (envelope-from ) id 1rWwgY-0001K4-33; Mon, 05 Feb 2024 10:58:46 +0000 Received: by outflank-mailman (output) from mailman id 675883.1051563; Mon, 05 Feb 2024 10:58: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 1rWwgX-0001Jx-WA; Mon, 05 Feb 2024 10:58:45 +0000 Received: by outflank-mailman (input) for mailman id 675883; Mon, 05 Feb 2024 10:58:45 +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 1rWwZy-0000qL-Ft for xen-devel@lists.xenproject.org; Mon, 05 Feb 2024 10:51:58 +0000 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 94923e2f-c414-11ee-98f5-efadbce2ee36; Mon, 05 Feb 2024 11:51:56 +0100 (CET) Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 801021F8BA; Mon, 5 Feb 2024 10:51:56 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 4E3C9132DD; Mon, 5 Feb 2024 10:51:56 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id +NmVEcy9wGW4NgAAD6G6ig (envelope-from ); Mon, 05 Feb 2024 10:51:56 +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: 94923e2f-c414-11ee-98f5-efadbce2ee36 From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Julien Grall , Anthony PERARD Subject: [PATCH v4 20/32] tools: add 9pfs device to xenstore-stubdom Date: Mon, 5 Feb 2024 11:49:49 +0100 Message-Id: <20240205105001.24171-21-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240205105001.24171-1-jgross@suse.com> References: <20240205105001.24171-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spam-Level: Authentication-Results: smtp-out2.suse.de; none X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Spamd-Result: default: False [-4.00 / 50.00]; REPLY(-4.00)[] X-Spam-Score: -4.00 X-Rspamd-Queue-Id: 801021F8BA X-Spam-Flag: NO X-ZM-MESSAGEID: 1707130739514100001 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 --- V2: - add security_model parameter to new libxl function (Jason Andryuk) V4: - rename function to libxl_device_9pfs_add() (Anthony Perard) - use a libxl_device_p9 pointer as parameter (Anthony Perard) --- tools/helpers/init-xenstore-domain.c | 7 +++++++ tools/include/libxl.h | 15 +++++++++++++++ tools/libs/light/libxl_9pfs.c | 16 ++++++++++++++++ 3 files changed, 38 insertions(+) diff --git a/tools/helpers/init-xenstore-domain.c b/tools/helpers/init-xens= tore-domain.c index 140ed610ae..1683438c5c 100644 --- a/tools/helpers/init-xenstore-domain.c +++ b/tools/helpers/init-xenstore-domain.c @@ -433,6 +433,12 @@ int main(int argc, char** argv) int rv, fd; char *maxmem_str =3D NULL; libxl_ctx *ctx; + libxl_device_p9 p9 =3D { .backend_domid =3D 0, + .tag =3D "Xen", + .path =3D XEN_LIB_DIR"/xenstore", + .security_model =3D "none", + .type =3D LIBXL_P9_TYPE_XEN_9PFSD, + }; =20 while ( (opt =3D getopt_long(argc, argv, "v", options, NULL)) !=3D -1 ) { @@ -543,6 +549,7 @@ int main(int argc, char** argv) } libxl_console_add_xenstore(ctx, domid, 0, console_evtchn, console_gfn, NULL); + libxl_device_9pfs_add(ctx, domid, &p9, 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 a554f2ccd6..e6ab5ddb94 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_device_9pfs_add() in libxl. + */ +#define LIBXL_HAVE_P9_ADD_XENSTORE 1 + /* * libxl ABI compatibility * @@ -2074,6 +2081,14 @@ 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_device_9pfs_add writes the Xenstore entries for a domain's + * primary 9pfs device based on domid, and device parameters. + * If needed it will start the backend daemon. + */ +int libxl_device_9pfs_add(libxl_ctx *ctx, uint32_t domid, libxl_device_p9 = *p9, + const libxl_asyncop_how *ao_how) + 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 7593686a90..8f5d475322 100644 --- a/tools/libs/light/libxl_9pfs.c +++ b/tools/libs/light/libxl_9pfs.c @@ -208,6 +208,22 @@ static void libxl__device_p9_add(libxl__egc *egc, uint= 32_t domid, aodev->callback(egc, aodev); } =20 +int libxl_device_9pfs_add(libxl_ctx *ctx, uint32_t domid, libxl_device_p9 = *p9, + const libxl_asyncop_how *ao_how) +{ + AO_CREATE(ctx, domid, ao_how); + libxl__ao_device *aodev; + + 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 Fri May 17 10:34:34 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; 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=fail(p=quarantine dis=quarantine) header.from=suse.com Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1707130669698707.2043800589668; Mon, 5 Feb 2024 02:57:49 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.675835.1051443 (Exim 4.92) (envelope-from ) id 1rWwfP-0002bd-9F; Mon, 05 Feb 2024 10:57:35 +0000 Received: by outflank-mailman (output) from mailman id 675835.1051443; Mon, 05 Feb 2024 10:57:35 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rWwfP-0002bU-5l; Mon, 05 Feb 2024 10:57:35 +0000 Received: by outflank-mailman (input) for mailman id 675835; Mon, 05 Feb 2024 10:57:34 +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 1rWwa3-0002wU-3F for xen-devel@lists.xenproject.org; Mon, 05 Feb 2024 10:52:03 +0000 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 97ed90f9-c414-11ee-8a45-1f161083a0e0; Mon, 05 Feb 2024 11:52:02 +0100 (CET) Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 2E0BD1F8BF; Mon, 5 Feb 2024 10:52:02 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id E5098132DD; Mon, 5 Feb 2024 10:52:01 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id S2JXNtG9wGW/NgAAD6G6ig (envelope-from ); Mon, 05 Feb 2024 10:52:01 +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: 97ed90f9-c414-11ee-8a45-1f161083a0e0 From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Julien Grall , Anthony PERARD , Jason Andryuk , Julien Grall Subject: [PATCH v4 21/32] tools/xenstored: add early_init() function Date: Mon, 5 Feb 2024 11:49:50 +0100 Message-Id: <20240205105001.24171-22-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240205105001.24171-1-jgross@suse.com> References: <20240205105001.24171-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spam-Level: Authentication-Results: smtp-out2.suse.de; none X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Spamd-Result: default: False [-4.00 / 50.00]; REPLY(-4.00)[] X-Spam-Score: -4.00 X-Rspamd-Queue-Id: 2E0BD1F8BF X-Spam-Flag: NO X-ZM-MESSAGEID: 1707130671342100001 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. Remove the call of talloc_enable_leak_report_full(), as it serves no real purpose: the daemon only ever exits due to a crash, in which case a log of talloc()ed memory hardly has any value. Signed-off-by: Juergen Gross Reviewed-by: Jason Andryuk Reviewed-by: Julien Grall --- V2: - rename function - move patch earlier in the series V3: - add more init code for the daemon to early_init() - move mkdir(XENSTORE_LIB_DIR) into a later patch (Julien Grall) - remove stale stubs in minios.c --- tools/xenstored/core.c | 30 +++--------------------------- tools/xenstored/core.h | 7 +++---- tools/xenstored/minios.c | 11 +++-------- tools/xenstored/posix.c | 31 +++++++++++++++++++++++++++++-- 4 files changed, 38 insertions(+), 41 deletions(-) diff --git a/tools/xenstored/core.c b/tools/xenstored/core.c index d4c76d71dc..eba7744fde 100644 --- a/tools/xenstored/core.c +++ b/tools/xenstored/core.c @@ -79,7 +79,7 @@ char **orig_argv; LIST_HEAD(connections); int tracefd =3D -1; bool keep_orphans =3D false; -static int reopen_log_pipe[2]; +int reopen_log_pipe[2]; static int reopen_log_pipe0_pollfd_idx =3D -1; char *tracefile =3D NULL; static struct hashtable *nodes; @@ -2612,7 +2612,7 @@ static void destroy_fds(void) close(sock); } =20 -static void init_sockets(void) +void init_sockets(void) { struct sockaddr_un addr; const char *soc_str =3D xenstore_daemon_path(); @@ -2903,34 +2903,10 @@ 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); - - if (dofork) { - openlog("xenstored", 0, LOG_DAEMON); - if (!live_update) - daemonize(); - } - if (pidfile) - write_pidfile(pidfile); - - /* Talloc leak reports go to stderr, which is closed if we fork. */ - if (!dofork) - talloc_enable_leak_report_full(); - - /* Don't kill us with SIGPIPE. */ - signal(SIGPIPE, SIG_IGN); + early_init(live_update, dofork, pidfile); =20 talloc_enable_null_tracking(); =20 -#ifndef NO_SOCKETS - if (!live_update) - init_sockets(); -#endif - init_pipe(reopen_log_pipe); =20 /* Listen to hypervisor. */ diff --git a/tools/xenstored/core.h b/tools/xenstored/core.h index 480b0f5f7b..72173f1684 100644 --- a/tools/xenstored/core.h +++ b/tools/xenstored/core.h @@ -384,12 +384,11 @@ static inline bool domain_is_unprivileged(const struc= t connection *conn) =20 /* Return the event channel used by xenbus. */ evtchn_port_t get_xenbus_evtchn(void); +void early_init(bool live_update, bool dofork, const char *pidfile); =20 -/* Write out the pidfile */ -void write_pidfile(const char *pidfile); +void init_sockets(void); +extern int reopen_log_pipe[2]; =20 -/* Fork but do not close terminal FDs */ -void daemonize(void); /* Close stdin/stdout/stderr to complete daemonize */ void finish_daemonize(void); =20 diff --git a/tools/xenstored/minios.c b/tools/xenstored/minios.c index 0779efbf91..4f48f63083 100644 --- a/tools/xenstored/minios.c +++ b/tools/xenstored/minios.c @@ -20,14 +20,6 @@ #include "core.h" #include =20 -void write_pidfile(const char *pidfile) -{ -} - -void daemonize(void) -{ -} - void finish_daemonize(void) { } @@ -54,3 +46,6 @@ void unmap_xenbus(void *interface) xengnttab_unmap(*xgt_handle, interface, 1); } =20 +void early_init(bool live_update, bool dofork, const char *pidfile) +{ +} diff --git a/tools/xenstored/posix.c b/tools/xenstored/posix.c index 7e03dd982d..9463ef5c8d 100644 --- a/tools/xenstored/posix.c +++ b/tools/xenstored/posix.c @@ -20,14 +20,17 @@ #include #include #include +#include #include +#include #include +#include =20 #include "utils.h" #include "core.h" #include "osdep.h" =20 -void write_pidfile(const char *pidfile) +static void write_pidfile(const char *pidfile) { char buf[100]; int len; @@ -49,7 +52,7 @@ void write_pidfile(const char *pidfile) } =20 /* Stevens. */ -void daemonize(void) +static void daemonize(void) { pid_t pid; =20 @@ -157,3 +160,27 @@ void *xenbus_map(void) =20 return addr; } + +void early_init(bool live_update, bool dofork, const char *pidfile) +{ + reopen_log(); + + /* Make sure xenstored directory exists. */ + /* Errors ignored here, will be reported when we open files */ + mkdir(xenstore_daemon_rundir(), 0755); + + if (dofork) { + openlog("xenstored", 0, LOG_DAEMON); + if (!live_update) + daemonize(); + } + + if (pidfile) + write_pidfile(pidfile); + + /* Don't kill us with SIGPIPE. */ + signal(SIGPIPE, SIG_IGN); + + if (!live_update) + init_sockets(); +} --=20 2.35.3 From nobody Fri May 17 10:34:34 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=1707130789; cv=none; d=zohomail.com; s=zohoarc; b=mp2ZQrMSbW1W6DsNVYGxWbT5V8Ct7Bj7K7Joosx148koSQSoaTzHMSxYyHQ+zy+AcoCFaKWeUp3U+ryIhra50c9RD+eyOnLIsdU1DPNQfg+Z0wVCgoevsEwnA+ONuU4/u4Sr9ZLrDpFV+lBh20vY2Z9ENIcPIE85YxkY1a4QIGM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1707130789; 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=Zf1h+BIq0Z8Nwwp8lu1GEpj5zMTW9hh2PPOlxbQgdSw=; b=PQSLmc9mj4qL3iIbF4GU2fR38mbFH6SLAk45NicxHscixca54r+8kzVGo9YYLJrgg7QOX9HaxDMW+z2h6x8lf+khzqGYNG3e4H+DRamRe4sjZNgasD+uu+XoNxsYtnfqXN+ZnzJKwgnbxuH8+RFajH7gCQMd1URKw9Db2RIVKws= 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 1707130789337647.2521595718661; Mon, 5 Feb 2024 02:59:49 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.675900.1051583 (Exim 4.92) (envelope-from ) id 1rWwhO-0003Jx-PE; Mon, 05 Feb 2024 10:59:38 +0000 Received: by outflank-mailman (output) from mailman id 675900.1051583; Mon, 05 Feb 2024 10:59: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 1rWwhO-0003Jo-L5; Mon, 05 Feb 2024 10:59:38 +0000 Received: by outflank-mailman (input) for mailman id 675900; Mon, 05 Feb 2024 10:59:37 +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 1rWwa8-0002wU-PT for xen-devel@lists.xenproject.org; Mon, 05 Feb 2024 10:52:08 +0000 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 9b5b870e-c414-11ee-8a45-1f161083a0e0; Mon, 05 Feb 2024 11:52:08 +0100 (CET) Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id CFAA222100; Mon, 5 Feb 2024 10:52:07 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 92C56132DD; Mon, 5 Feb 2024 10:52:07 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id 3wJdIte9wGXHNgAAD6G6ig (envelope-from ); Mon, 05 Feb 2024 10:52:07 +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: 9b5b870e-c414-11ee-8a45-1f161083a0e0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1707130327; 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=Zf1h+BIq0Z8Nwwp8lu1GEpj5zMTW9hh2PPOlxbQgdSw=; b=OF/utg6Saod0ZXXQVz6YP8a8kQYLJUaOHsJvdE98qsRyg1rJK7pZsSihiaAanOsrHPkhXQ bAOhTj/u4IjiplMJze44HbhqLo/70CHki0K8JQyCGG6lKYHZL8KPi/7lraL2RGGm7YpA1V gP5kqTV+ARpE8qHQAPd0MJNPT6FUbao= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1707130327; 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=Zf1h+BIq0Z8Nwwp8lu1GEpj5zMTW9hh2PPOlxbQgdSw=; b=OF/utg6Saod0ZXXQVz6YP8a8kQYLJUaOHsJvdE98qsRyg1rJK7pZsSihiaAanOsrHPkhXQ bAOhTj/u4IjiplMJze44HbhqLo/70CHki0K8JQyCGG6lKYHZL8KPi/7lraL2RGGm7YpA1V gP5kqTV+ARpE8qHQAPd0MJNPT6FUbao= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Julien Grall , Anthony PERARD , Jason Andryuk , Julien Grall Subject: [PATCH v4 22/32] tools/xenstored: move systemd handling to posix.c Date: Mon, 5 Feb 2024 11:49:51 +0100 Message-Id: <20240205105001.24171-23-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240205105001.24171-1-jgross@suse.com> References: <20240205105001.24171-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Authentication-Results: smtp-out1.suse.de; none X-Spam-Level: X-Spam-Score: -3.30 X-Spamd-Result: default: False [-3.30 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; R_MISSING_CHARSET(2.50)[]; FREEMAIL_ENVRCPT(0.00)[gmail.com]; MIME_GOOD(-0.10)[text/plain]; TO_MATCH_ENVRCPT_ALL(0.00)[]; REPLY(-4.00)[]; BROKEN_CONTENT_TYPE(1.50)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; RCVD_COUNT_THREE(0.00)[3]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; NEURAL_HAM_SHORT(-0.20)[-1.000]; RCPT_COUNT_SEVEN(0.00)[7]; MID_CONTAINS_FROM(1.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.com:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; FREEMAIL_CC(0.00)[suse.com,xen.org,citrix.com,gmail.com,amazon.com]; RCVD_TLS_ALL(0.00)[]; BAYES_HAM(-3.00)[100.00%] X-Spam-Flag: NO X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1707130789655100001 Content-Type: text/plain; charset="utf-8" Move systemd handling to a new late_init() function in posix.c. This prepares a future removal of the NO_SOCKETS macro. Signed-off-by: Juergen Gross Reviewed-by: Jason Andryuk Reviewed-by: Julien Grall --- V3: - new patch --- tools/xenstored/core.c | 17 +---------------- tools/xenstored/core.h | 1 + tools/xenstored/minios.c | 4 ++++ tools/xenstored/posix.c | 13 +++++++++++++ 4 files changed, 19 insertions(+), 16 deletions(-) diff --git a/tools/xenstored/core.c b/tools/xenstored/core.c index eba7744fde..7b5e1d0c0f 100644 --- a/tools/xenstored/core.c +++ b/tools/xenstored/core.c @@ -54,16 +54,6 @@ #include "control.h" #include "lu.h" =20 -#ifndef NO_SOCKETS -#if defined(HAVE_SYSTEMD) -#define XEN_SYSTEMD_ENABLED 1 -#endif -#endif - -#if defined(XEN_SYSTEMD_ENABLED) -#include -#endif - extern xenevtchn_handle *xce_handle; /* in domain.c */ static int xce_pollfd_idx =3D -1; static struct pollfd *fds; @@ -2938,12 +2928,7 @@ int main(int argc, char *argv[]) /* Get ready to listen to the tools. */ initialize_fds(&sock_pollfd_idx, &timeout); =20 -#if defined(XEN_SYSTEMD_ENABLED) - if (!live_update) { - sd_notify(1, "READY=3D1"); - fprintf(stderr, SD_NOTICE "xenstored is ready\n"); - } -#endif + late_init(live_update); =20 /* Main loop. */ for (;;) { diff --git a/tools/xenstored/core.h b/tools/xenstored/core.h index 72173f1684..0de2d8a26e 100644 --- a/tools/xenstored/core.h +++ b/tools/xenstored/core.h @@ -385,6 +385,7 @@ static inline bool domain_is_unprivileged(const struct = connection *conn) /* Return the event channel used by xenbus. */ evtchn_port_t get_xenbus_evtchn(void); void early_init(bool live_update, bool dofork, const char *pidfile); +void late_init(bool live_update); =20 void init_sockets(void); extern int reopen_log_pipe[2]; diff --git a/tools/xenstored/minios.c b/tools/xenstored/minios.c index 4f48f63083..45bb0440be 100644 --- a/tools/xenstored/minios.c +++ b/tools/xenstored/minios.c @@ -49,3 +49,7 @@ void unmap_xenbus(void *interface) void early_init(bool live_update, bool dofork, const char *pidfile) { } + +void late_init(bool live_update) +{ +} diff --git a/tools/xenstored/posix.c b/tools/xenstored/posix.c index 9463ef5c8d..97c8dcaba3 100644 --- a/tools/xenstored/posix.c +++ b/tools/xenstored/posix.c @@ -24,6 +24,9 @@ #include #include #include +#if defined(HAVE_SYSTEMD) +#include +#endif #include =20 #include "utils.h" @@ -184,3 +187,13 @@ void early_init(bool live_update, bool dofork, const c= har *pidfile) if (!live_update) init_sockets(); } + +void late_init(bool live_update) +{ +#if defined(HAVE_SYSTEMD) + if (!live_update) { + sd_notify(1, "READY=3D1"); + fprintf(stderr, SD_NOTICE "xenstored is ready\n"); + } +#endif +} --=20 2.35.3 From nobody Fri May 17 10:34:34 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; 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=fail(p=quarantine dis=quarantine) header.from=suse.com Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1707130664316648.5596501362279; Mon, 5 Feb 2024 02:57:44 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.675832.1051416 (Exim 4.92) (envelope-from ) id 1rWwfE-0001Y9-MM; Mon, 05 Feb 2024 10:57:24 +0000 Received: by outflank-mailman (output) from mailman id 675832.1051416; Mon, 05 Feb 2024 10:57:24 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rWwfE-0001XS-Hu; Mon, 05 Feb 2024 10:57:24 +0000 Received: by outflank-mailman (input) for mailman id 675832; Mon, 05 Feb 2024 10:57:22 +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 1rWwaE-0002wU-HF for xen-devel@lists.xenproject.org; Mon, 05 Feb 2024 10:52:14 +0000 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 9ea7bc5c-c414-11ee-8a45-1f161083a0e0; Mon, 05 Feb 2024 11:52:13 +0100 (CET) Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 736251F8BA; Mon, 5 Feb 2024 10:52:13 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 41B7E132DD; Mon, 5 Feb 2024 10:52:13 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id EQSNDt29wGXQNgAAD6G6ig (envelope-from ); Mon, 05 Feb 2024 10:52: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: 9ea7bc5c-c414-11ee-8a45-1f161083a0e0 From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Julien Grall , Anthony PERARD Subject: [PATCH v4 23/32] tools/xenstored: move all log-pipe handling into posix.c Date: Mon, 5 Feb 2024 11:49:52 +0100 Message-Id: <20240205105001.24171-24-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240205105001.24171-1-jgross@suse.com> References: <20240205105001.24171-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spam-Level: Authentication-Results: smtp-out2.suse.de; none X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Spamd-Result: default: False [-4.00 / 50.00]; REPLY(-4.00)[] X-Spam-Score: -4.00 X-Rspamd-Queue-Id: 736251F8BA X-Spam-Flag: NO X-ZM-MESSAGEID: 1707130665152100003 Content-Type: text/plain; charset="utf-8" All of the log-pipe handling is needed only when running as daemon. Move it into posix.c. This requires to have a service function in the main event loop for handling the related requests and one for setting the fds[] array. Use a generic name for those functions, as socket handling can be added to them later, too. Signed-off-by: Juergen Gross Reviewed-by: Julien Grall --- V3: - new patch V4: - rename fds to poll_fds (Julien Grall) --- tools/xenstored/core.c | 69 +++++++++++----------------------------- tools/xenstored/core.h | 11 ++++--- tools/xenstored/minios.c | 14 ++++---- tools/xenstored/posix.c | 47 ++++++++++++++++++++++++++- 4 files changed, 79 insertions(+), 62 deletions(-) diff --git a/tools/xenstored/core.c b/tools/xenstored/core.c index 7b5e1d0c0f..86ab330eaf 100644 --- a/tools/xenstored/core.c +++ b/tools/xenstored/core.c @@ -56,7 +56,7 @@ =20 extern xenevtchn_handle *xce_handle; /* in domain.c */ static int xce_pollfd_idx =3D -1; -static struct pollfd *fds; +struct pollfd *poll_fds; static unsigned int current_array_size; static unsigned int nr_fds; static unsigned int delayed_requests; @@ -69,8 +69,6 @@ char **orig_argv; LIST_HEAD(connections); int tracefd =3D -1; bool keep_orphans =3D false; -int reopen_log_pipe[2]; -static int reopen_log_pipe0_pollfd_idx =3D -1; char *tracefile =3D NULL; static struct hashtable *nodes; unsigned int trace_flags =3D TRACE_OBJ | TRACE_IO; @@ -145,18 +143,6 @@ void trace_destroy(const void *data, const char *type) trace("obj: DESTROY %s %p\n", type, data); } =20 -/** - * 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 - * the poll() in the main loop. - */ -static void trigger_reopen_log(int signal __attribute__((unused))) -{ - char c =3D 'A'; - int dummy; - dummy =3D write(reopen_log_pipe[1], &c, 1); -} - void close_log(void) { if (tracefd >=3D 0) @@ -467,7 +453,7 @@ static bool conn_can_write(struct connection *conn) } =20 /* This function returns index inside the array if succeed, -1 if fail */ -static int set_fd(int fd, short events) +int set_fd(int fd, short events) { int ret; if (current_array_size < nr_fds + 1) { @@ -479,18 +465,18 @@ static int set_fd(int fd, short events) */ newsize =3D ROUNDUP(nr_fds + 1, 8); =20 - new_fds =3D realloc(fds, sizeof(struct pollfd)*newsize); + new_fds =3D realloc(poll_fds, sizeof(struct pollfd)*newsize); if (!new_fds) goto fail; - fds =3D new_fds; + poll_fds =3D new_fds; =20 - memset(&fds[0] + current_array_size, 0, + memset(&poll_fds[0] + current_array_size, 0, sizeof(struct pollfd ) * (newsize-current_array_size)); current_array_size =3D newsize; } =20 - fds[nr_fds].fd =3D fd; - fds[nr_fds].events =3D events; + poll_fds[nr_fds].fd =3D fd; + poll_fds[nr_fds].events =3D events; ret =3D nr_fds; nr_fds++; =20 @@ -505,18 +491,16 @@ static void initialize_fds(int *p_sock_pollfd_idx, in= t *ptimeout) struct connection *conn; uint64_t msecs; =20 - if (fds) - memset(fds, 0, sizeof(struct pollfd) * current_array_size); + if (poll_fds) + memset(poll_fds, 0, sizeof(struct pollfd) * current_array_size); nr_fds =3D 0; =20 /* In case of delayed requests pause for max 1 second. */ *ptimeout =3D delayed_requests ? 1000 : -1; =20 + set_special_fds(); if (sock !=3D -1) *p_sock_pollfd_idx =3D set_fd(sock, POLLIN|POLLPRI); - if (reopen_log_pipe[0] !=3D -1) - reopen_log_pipe0_pollfd_idx =3D - set_fd(reopen_log_pipe[0], POLLIN|POLLPRI); =20 if (xce_handle !=3D NULL) xce_pollfd_idx =3D set_fd(xenevtchn_fd(xce_handle), @@ -2324,12 +2308,12 @@ static bool socket_can_process(struct connection *c= onn, int mask) if (conn->pollfd_idx =3D=3D -1) return false; =20 - if (fds[conn->pollfd_idx].revents & ~(POLLIN | POLLOUT)) { + if (poll_fds[conn->pollfd_idx].revents & ~(POLLIN | POLLOUT)) { talloc_free(conn); return false; } =20 - return (fds[conn->pollfd_idx].revents & mask); + return (poll_fds[conn->pollfd_idx].revents & mask); } =20 static bool socket_can_write(struct connection *conn) @@ -2897,8 +2881,6 @@ int main(int argc, char *argv[]) =20 talloc_enable_null_tracking(); =20 - init_pipe(reopen_log_pipe); - /* Listen to hypervisor. */ if (!live_update) { domain_init(-1); @@ -2913,7 +2895,6 @@ int main(int argc, char *argv[]) xprintf =3D trace; #endif =20 - signal(SIGHUP, trigger_reopen_log); if (tracefile) tracefile =3D talloc_strdup(NULL, tracefile); =20 @@ -2934,43 +2915,29 @@ int main(int argc, char *argv[]) for (;;) { struct connection *conn, *next; =20 - if (poll(fds, nr_fds, timeout) < 0) { + if (poll(poll_fds, nr_fds, timeout) < 0) { if (errno =3D=3D EINTR) continue; barf_perror("Poll failed"); } =20 - if (reopen_log_pipe0_pollfd_idx !=3D -1) { - if (fds[reopen_log_pipe0_pollfd_idx].revents - & ~POLLIN) { - close(reopen_log_pipe[0]); - close(reopen_log_pipe[1]); - init_pipe(reopen_log_pipe); - } else if (fds[reopen_log_pipe0_pollfd_idx].revents - & POLLIN) { - char c; - if (read(reopen_log_pipe[0], &c, 1) !=3D 1) - barf_perror("read failed"); - reopen_log(); - } - reopen_log_pipe0_pollfd_idx =3D -1; - } + handle_special_fds(); =20 if (sock_pollfd_idx !=3D -1) { - if (fds[sock_pollfd_idx].revents & ~POLLIN) { + if (poll_fds[sock_pollfd_idx].revents & ~POLLIN) { barf_perror("sock poll failed"); break; - } else if (fds[sock_pollfd_idx].revents & POLLIN) { + } else if (poll_fds[sock_pollfd_idx].revents & POLLIN) { accept_connection(sock); sock_pollfd_idx =3D -1; } } =20 if (xce_pollfd_idx !=3D -1) { - if (fds[xce_pollfd_idx].revents & ~POLLIN) { + if (poll_fds[xce_pollfd_idx].revents & ~POLLIN) { barf_perror("xce_handle poll failed"); break; - } else if (fds[xce_pollfd_idx].revents & POLLIN) { + } else if (poll_fds[xce_pollfd_idx].revents & POLLIN) { handle_event(); xce_pollfd_idx =3D -1; } diff --git a/tools/xenstored/core.h b/tools/xenstored/core.h index 0de2d8a26e..44c4d0f8b8 100644 --- a/tools/xenstored/core.h +++ b/tools/xenstored/core.h @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -361,6 +362,8 @@ extern int dom0_event; extern int priv_domid; extern bool keep_orphans; =20 +extern struct pollfd *poll_fds; + extern unsigned int timeout_watch_event_msec; =20 /* Get internal time in milliseconds. */ @@ -387,15 +390,15 @@ evtchn_port_t get_xenbus_evtchn(void); void early_init(bool live_update, bool dofork, const char *pidfile); void late_init(bool live_update); =20 +int set_fd(int fd, short events); +void set_special_fds(void); +void handle_special_fds(void); + void init_sockets(void); -extern int reopen_log_pipe[2]; =20 /* Close stdin/stdout/stderr to complete daemonize */ void finish_daemonize(void); =20 -/* Open a pipe for signal handling */ -void init_pipe(int reopen_log_pipe[2]); - #ifndef NO_SOCKETS extern const struct interface_funcs socket_funcs; #endif diff --git a/tools/xenstored/minios.c b/tools/xenstored/minios.c index 45bb0440be..3208169187 100644 --- a/tools/xenstored/minios.c +++ b/tools/xenstored/minios.c @@ -24,12 +24,6 @@ void finish_daemonize(void) { } =20 -void init_pipe(int reopen_log_pipe[2]) -{ - reopen_log_pipe[0] =3D -1; - reopen_log_pipe[1] =3D -1; -} - evtchn_port_t get_xenbus_evtchn(void) { return dom0_event; @@ -53,3 +47,11 @@ void early_init(bool live_update, bool dofork, const cha= r *pidfile) void late_init(bool live_update) { } + +void set_special_fds(void) +{ +} + +void handle_special_fds(void) +{ +} diff --git a/tools/xenstored/posix.c b/tools/xenstored/posix.c index 97c8dcaba3..1ea8475293 100644 --- a/tools/xenstored/posix.c +++ b/tools/xenstored/posix.c @@ -33,6 +33,9 @@ #include "core.h" #include "osdep.h" =20 +static int reopen_log_pipe0_pollfd_idx =3D -1; +static int reopen_log_pipe[2]; + static void write_pidfile(const char *pidfile) { char buf[100]; @@ -82,6 +85,19 @@ static void daemonize(void) umask(0); } =20 +/* + * 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 + * the poll() in the main loop. + */ +static void trigger_reopen_log(int signal __attribute__((unused))) +{ + char c =3D 'A'; + int dummy; + + dummy =3D write(reopen_log_pipe[1], &c, 1); +} + void finish_daemonize(void) { int devnull =3D open("/dev/null", O_RDWR); @@ -93,7 +109,7 @@ void finish_daemonize(void) close(devnull); } =20 -void init_pipe(int reopen_log_pipe[2]) +static void init_pipe(void) { int flags; unsigned int i; @@ -183,9 +199,38 @@ void early_init(bool live_update, bool dofork, const c= har *pidfile) =20 /* Don't kill us with SIGPIPE. */ signal(SIGPIPE, SIG_IGN); + signal(SIGHUP, trigger_reopen_log); =20 if (!live_update) init_sockets(); + + init_pipe(); +} + +void set_special_fds(void) +{ + if (reopen_log_pipe[0] !=3D -1) + reopen_log_pipe0_pollfd_idx =3D + set_fd(reopen_log_pipe[0], POLLIN|POLLPRI); +} + +void handle_special_fds(void) +{ + if (reopen_log_pipe0_pollfd_idx !=3D -1) { + if (poll_fds[reopen_log_pipe0_pollfd_idx].revents & ~POLLIN) { + close(reopen_log_pipe[0]); + close(reopen_log_pipe[1]); + init_pipe(); + } else if (poll_fds[reopen_log_pipe0_pollfd_idx].revents & + POLLIN) { + char c; + + if (read(reopen_log_pipe[0], &c, 1) !=3D 1) + barf_perror("read failed"); + reopen_log(); + } + reopen_log_pipe0_pollfd_idx =3D -1; + } } =20 void late_init(bool live_update) --=20 2.35.3 From nobody Fri May 17 10:34:34 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=1707130706; cv=none; d=zohomail.com; s=zohoarc; b=avG5WqIZAmVv2NJcr6g4yFEQZ2gt/afldvXM3Ptw4AiRzaGrC8BuXgIr8rF4PTIGdBSvDmjMNEJ/DzcdozNpPxjJGkfGNU7vk5zR7fg/lleVylicm04JhNEc4JhnSH6wegZtgjG2GkSlfaT4wl0DGYD6t/N6BjdMEzSmrrOxew8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1707130706; 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=CIIvWmhSlUU/eQ16VgaFDL39qVtBS1MR2oAB75tbNM8=; b=IudUlsWJzSg+w64RI5dbydZAc981E8jX7bIAjxtxpFbQ6ok3cwfv80kKSr6AXrUlk+5xzdUl1FHxPMyaHYV8srl08sysGu7N86NVkuqHfp+JSsbaU6ci1cOP9lFdphVuXIo825VfxTBzWtHp6sd8elWN9+HPUcOUdFhXt1R+j0Q= 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 1707130706154815.9975919057331; Mon, 5 Feb 2024 02:58:26 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.675859.1051533 (Exim 4.92) (envelope-from ) id 1rWwfv-000797-VQ; Mon, 05 Feb 2024 10:58:07 +0000 Received: by outflank-mailman (output) from mailman id 675859.1051533; Mon, 05 Feb 2024 10:58:07 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rWwfv-00078o-RN; Mon, 05 Feb 2024 10:58:07 +0000 Received: by outflank-mailman (input) for mailman id 675859; Mon, 05 Feb 2024 10:58:06 +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 1rWwaK-0002wU-St for xen-devel@lists.xenproject.org; Mon, 05 Feb 2024 10:52:21 +0000 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id a207ee68-c414-11ee-8a45-1f161083a0e0; Mon, 05 Feb 2024 11:52:19 +0100 (CET) Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 091E31F8BA; Mon, 5 Feb 2024 10:52:19 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id CCE5E132DD; Mon, 5 Feb 2024 10:52:18 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id ITeRMOK9wGXZNgAAD6G6ig (envelope-from ); Mon, 05 Feb 2024 10:52: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: a207ee68-c414-11ee-8a45-1f161083a0e0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1707130339; 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=CIIvWmhSlUU/eQ16VgaFDL39qVtBS1MR2oAB75tbNM8=; b=XlSAier3wLqUUZy224T2xQV+Q0qEsF4bUOoL/VFBIzfH1H94CJBFKUD3bdUvkjscxg9ZTT EqLeTnEkTyUUngiXFXdhHAtcja1exG3UROR7oo74dTytMwD5GCPNhoRjct5A34EAJL6/Rf w9REjz+tK+5OVlHZyH34MMIs8yg6Vjs= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1707130339; 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=CIIvWmhSlUU/eQ16VgaFDL39qVtBS1MR2oAB75tbNM8=; b=XlSAier3wLqUUZy224T2xQV+Q0qEsF4bUOoL/VFBIzfH1H94CJBFKUD3bdUvkjscxg9ZTT EqLeTnEkTyUUngiXFXdhHAtcja1exG3UROR7oo74dTytMwD5GCPNhoRjct5A34EAJL6/Rf w9REjz+tK+5OVlHZyH34MMIs8yg6Vjs= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Julien Grall , Anthony PERARD Subject: [PATCH v4 24/32] tools/xenstored: move all socket handling into posix.c Date: Mon, 5 Feb 2024 11:49:53 +0100 Message-Id: <20240205105001.24171-25-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240205105001.24171-1-jgross@suse.com> References: <20240205105001.24171-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Authentication-Results: smtp-out2.suse.de; none X-Spam-Level: X-Spam-Score: -3.30 X-Spamd-Result: default: False [-3.30 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; R_MISSING_CHARSET(2.50)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; REPLY(-4.00)[]; BROKEN_CONTENT_TYPE(1.50)[]; RCPT_COUNT_FIVE(0.00)[5]; NEURAL_HAM_LONG(-1.00)[-1.000]; RCVD_COUNT_THREE(0.00)[3]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; NEURAL_HAM_SHORT(-0.20)[-0.997]; MID_CONTAINS_FROM(1.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.com:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_ALL(0.00)[]; BAYES_HAM(-3.00)[100.00%] X-Spam-Flag: NO X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1707130707378100001 Content-Type: text/plain; charset="utf-8" All of the socket handling is needed only when running as daemon. Move it into posix.c, allowing to remove the NO_SOCKETS macro. Signed-off-by: Juergen Gross Reviewed-by: Julien Grall --- V3: - new patch V4: - make sock local to posix.c (Julien Grall) --- tools/xenstored/Makefile.common | 4 - tools/xenstored/core.c | 160 +------------------------------ tools/xenstored/core.h | 7 +- tools/xenstored/domain.c | 9 +- tools/xenstored/minios.c | 15 +++ tools/xenstored/posix.c | 164 ++++++++++++++++++++++++++++++++ 6 files changed, 188 insertions(+), 171 deletions(-) diff --git a/tools/xenstored/Makefile.common b/tools/xenstored/Makefile.com= mon index 189ab81b8d..ef63ef650c 100644 --- a/tools/xenstored/Makefile.common +++ b/tools/xenstored/Makefile.common @@ -16,10 +16,6 @@ CFLAGS +=3D $(CFLAGS_libxenctrl) CFLAGS +=3D $(CFLAGS_libxenguest) CFLAGS +=3D $(CFLAGS_libxentoolcore) =20 -ifdef CONFIG_STUBDOM -CFLAGS +=3D -DNO_SOCKETS=3D1 -endif - $(XENSTORED_OBJS-y): CFLAGS +=3D $(CFLAGS_libxengnttab) =20 xenstored.a: $(XENSTORED_OBJS-y) diff --git a/tools/xenstored/core.c b/tools/xenstored/core.c index 86ab330eaf..c045a6e5db 100644 --- a/tools/xenstored/core.c +++ b/tools/xenstored/core.c @@ -20,10 +20,6 @@ #include #include #include -#ifndef NO_SOCKETS -#include -#include -#endif #include #include #include @@ -61,8 +57,6 @@ static unsigned int current_array_size; static unsigned int nr_fds; static unsigned int delayed_requests; =20 -static int sock =3D -1; - int orig_argc; char **orig_argv; =20 @@ -486,7 +480,7 @@ fail: return -1; } =20 -static void initialize_fds(int *p_sock_pollfd_idx, int *ptimeout) +static void initialize_fds(int *ptimeout) { struct connection *conn; uint64_t msecs; @@ -499,8 +493,6 @@ static void initialize_fds(int *p_sock_pollfd_idx, int = *ptimeout) *ptimeout =3D delayed_requests ? 1000 : -1; =20 set_special_fds(); - if (sock !=3D -1) - *p_sock_pollfd_idx =3D set_fd(sock, POLLIN|POLLPRI); =20 if (xce_handle !=3D NULL) xce_pollfd_idx =3D set_fd(xenevtchn_fd(xce_handle), @@ -2260,97 +2252,6 @@ struct connection *get_connection_by_id(unsigned int= conn_id) return NULL; } =20 -#ifdef NO_SOCKETS -static void accept_connection(int sock) -{ -} -#else -static int writefd(struct connection *conn, const void *data, unsigned int= len) -{ - int rc; - - while ((rc =3D write(conn->fd, data, len)) < 0) { - if (errno =3D=3D EAGAIN) { - rc =3D 0; - break; - } - if (errno !=3D EINTR) - break; - } - - return rc; -} - -static int readfd(struct connection *conn, void *data, unsigned int len) -{ - int rc; - - while ((rc =3D read(conn->fd, data, len)) < 0) { - if (errno =3D=3D EAGAIN) { - rc =3D 0; - break; - } - if (errno !=3D EINTR) - break; - } - - /* Reading zero length means we're done with this connection. */ - if ((rc =3D=3D 0) && (len !=3D 0)) { - errno =3D EBADF; - rc =3D -1; - } - - return rc; -} - -static bool socket_can_process(struct connection *conn, int mask) -{ - if (conn->pollfd_idx =3D=3D -1) - return false; - - if (poll_fds[conn->pollfd_idx].revents & ~(POLLIN | POLLOUT)) { - talloc_free(conn); - return false; - } - - return (poll_fds[conn->pollfd_idx].revents & mask); -} - -static bool socket_can_write(struct connection *conn) -{ - return socket_can_process(conn, POLLOUT); -} - -static bool socket_can_read(struct connection *conn) -{ - return socket_can_process(conn, POLLIN); -} - -const struct interface_funcs socket_funcs =3D { - .write =3D writefd, - .read =3D readfd, - .can_write =3D socket_can_write, - .can_read =3D socket_can_read, -}; - -static void accept_connection(int sock) -{ - int fd; - struct connection *conn; - - fd =3D accept(sock, NULL, NULL); - if (fd < 0) - return; - - conn =3D new_connection(&socket_funcs); - if (conn) { - conn->fd =3D fd; - conn->id =3D dom0_domid; - } else - close(fd); -} -#endif - /* We create initial nodes manually. */ static void manual_node(const char *name, const char *child) { @@ -2579,46 +2480,6 @@ void corrupt(struct connection *conn, const char *fm= t, ...) errno =3D saved_errno; } =20 -#ifndef NO_SOCKETS -static void destroy_fds(void) -{ - if (sock >=3D 0) - close(sock); -} - -void init_sockets(void) -{ - struct sockaddr_un addr; - const char *soc_str =3D xenstore_daemon_path(); - - if (!soc_str) - barf_perror("Failed to obtain xs domain socket"); - - /* Create sockets for them to listen to. */ - atexit(destroy_fds); - sock =3D socket(PF_UNIX, SOCK_STREAM, 0); - if (sock < 0) - barf_perror("Could not create socket"); - - /* FIXME: Be more sophisticated, don't mug running daemon. */ - unlink(soc_str); - - addr.sun_family =3D AF_UNIX; - - if(strlen(soc_str) >=3D sizeof(addr.sun_path)) - barf_perror("socket string '%s' too long", soc_str); - strcpy(addr.sun_path, soc_str); - if (bind(sock, (struct sockaddr *)&addr, sizeof(addr)) !=3D 0) - barf_perror("Could not bind socket to %s", soc_str); - - if (chmod(soc_str, 0600) !=3D 0) - barf_perror("Could not chmod sockets"); - - if (listen(sock, 1) !=3D 0) - barf_perror("Could not listen on sockets"); -} -#endif - static void usage(void) { fprintf(stderr, @@ -2796,7 +2657,6 @@ int set_trace_switch(const char *arg) int main(int argc, char *argv[]) { int opt; - int sock_pollfd_idx =3D -1; bool dofork =3D true; bool live_update =3D false; const char *pidfile =3D NULL; @@ -2907,7 +2767,7 @@ int main(int argc, char *argv[]) check_store(); =20 /* Get ready to listen to the tools. */ - initialize_fds(&sock_pollfd_idx, &timeout); + initialize_fds(&timeout); =20 late_init(live_update); =20 @@ -2923,16 +2783,6 @@ int main(int argc, char *argv[]) =20 handle_special_fds(); =20 - if (sock_pollfd_idx !=3D -1) { - if (poll_fds[sock_pollfd_idx].revents & ~POLLIN) { - barf_perror("sock poll failed"); - break; - } else if (poll_fds[sock_pollfd_idx].revents & POLLIN) { - accept_connection(sock); - sock_pollfd_idx =3D -1; - } - } - if (xce_pollfd_idx !=3D -1) { if (poll_fds[xce_pollfd_idx].revents & ~POLLIN) { barf_perror("xce_handle poll failed"); @@ -2986,7 +2836,7 @@ int main(int argc, char *argv[]) } } =20 - initialize_fds(&sock_pollfd_idx, &timeout); + initialize_fds(&timeout); } } =20 @@ -2999,7 +2849,7 @@ const char *dump_state_global(FILE *fp) head.length =3D sizeof(glb); if (fwrite(&head, sizeof(head), 1, fp) !=3D 1) return "Dump global state error"; - glb.socket_fd =3D sock; + glb.socket_fd =3D get_socket_fd(); glb.evtchn_fd =3D xenevtchn_fd(xce_handle); if (fwrite(&glb, sizeof(glb), 1, fp) !=3D 1) return "Dump global state error"; @@ -3235,7 +3085,7 @@ void read_state_global(const void *ctx, const void *s= tate) { const struct xs_state_global *glb =3D state; =20 - sock =3D glb->socket_fd; + set_socket_fd(glb->socket_fd); =20 domain_init(glb->evtchn_fd); } diff --git a/tools/xenstored/core.h b/tools/xenstored/core.h index 44c4d0f8b8..6180ec8b5c 100644 --- a/tools/xenstored/core.h +++ b/tools/xenstored/core.h @@ -301,6 +301,7 @@ int rm_node(struct connection *conn, const void *ctx, c= onst char *name); =20 void setup_structure(bool live_update); struct connection *new_connection(const struct interface_funcs *funcs); +struct connection *add_socket_connection(int fd); struct connection *get_connection_by_id(unsigned int conn_id); void check_store(void); void corrupt(struct connection *conn, const char *fmt, ...); @@ -394,14 +395,12 @@ int set_fd(int fd, short events); void set_special_fds(void); void handle_special_fds(void); =20 -void init_sockets(void); +int get_socket_fd(void); +void set_socket_fd(int fd); =20 /* Close stdin/stdout/stderr to complete daemonize */ void finish_daemonize(void); =20 -#ifndef NO_SOCKETS -extern const struct interface_funcs socket_funcs; -#endif extern xengnttab_handle **xgt_handle; =20 int remember_string(struct hashtable *hash, const char *str); diff --git a/tools/xenstored/domain.c b/tools/xenstored/domain.c index 6ef136e01f..040df98b8c 100644 --- a/tools/xenstored/domain.c +++ b/tools/xenstored/domain.c @@ -1739,14 +1739,7 @@ void read_state_connection(const void *ctx, const vo= id *state) struct domain *domain, *tdomain; =20 if (sc->conn_type =3D=3D XS_STATE_CONN_TYPE_SOCKET) { -#ifdef NO_SOCKETS - barf("socket based connection without sockets"); -#else - conn =3D new_connection(&socket_funcs); - if (!conn) - barf("error restoring connection"); - conn->fd =3D sc->spec.socket_fd; -#endif + conn =3D add_socket_connection(sc->spec.socket_fd); } else { domain =3D introduce_domain(ctx, sc->spec.ring.domid, sc->spec.ring.evtchn, true); diff --git a/tools/xenstored/minios.c b/tools/xenstored/minios.c index 3208169187..6d0c11423c 100644 --- a/tools/xenstored/minios.c +++ b/tools/xenstored/minios.c @@ -18,12 +18,18 @@ #include #include #include "core.h" +#include "utils.h" #include =20 void finish_daemonize(void) { } =20 +struct connection *add_socket_connection(int fd) +{ + barf("socket based connection without sockets"); +} + evtchn_port_t get_xenbus_evtchn(void) { return dom0_event; @@ -55,3 +61,12 @@ void set_special_fds(void) void handle_special_fds(void) { } + +int get_socket_fd(void) +{ + return -1; +} + +void set_socket_fd(int fd) +{ +} diff --git a/tools/xenstored/posix.c b/tools/xenstored/posix.c index 1ea8475293..496329dfd1 100644 --- a/tools/xenstored/posix.c +++ b/tools/xenstored/posix.c @@ -24,6 +24,8 @@ #include #include #include +#include +#include #if defined(HAVE_SYSTEMD) #include #endif @@ -32,10 +34,14 @@ #include "utils.h" #include "core.h" #include "osdep.h" +#include "talloc.h" =20 static int reopen_log_pipe0_pollfd_idx =3D -1; static int reopen_log_pipe[2]; =20 +static int sock_pollfd_idx =3D -1; +static int sock =3D -1; + static void write_pidfile(const char *pidfile) { char buf[100]; @@ -180,6 +186,142 @@ void *xenbus_map(void) return addr; } =20 +static int writefd(struct connection *conn, const void *data, unsigned int= len) +{ + int rc; + + while ((rc =3D write(conn->fd, data, len)) < 0) { + if (errno =3D=3D EAGAIN) { + rc =3D 0; + break; + } + if (errno !=3D EINTR) + break; + } + + return rc; +} + +static int readfd(struct connection *conn, void *data, unsigned int len) +{ + int rc; + + while ((rc =3D read(conn->fd, data, len)) < 0) { + if (errno =3D=3D EAGAIN) { + rc =3D 0; + break; + } + if (errno !=3D EINTR) + break; + } + + /* Reading zero length means we're done with this connection. */ + if ((rc =3D=3D 0) && (len !=3D 0)) { + errno =3D EBADF; + rc =3D -1; + } + + return rc; +} + +static bool socket_can_process(struct connection *conn, int mask) +{ + if (conn->pollfd_idx =3D=3D -1) + return false; + + if (poll_fds[conn->pollfd_idx].revents & ~(POLLIN | POLLOUT)) { + talloc_free(conn); + return false; + } + + return (poll_fds[conn->pollfd_idx].revents & mask); +} + +static bool socket_can_write(struct connection *conn) +{ + return socket_can_process(conn, POLLOUT); +} + +static bool socket_can_read(struct connection *conn) +{ + return socket_can_process(conn, POLLIN); +} + +static const struct interface_funcs socket_funcs =3D { + .write =3D writefd, + .read =3D readfd, + .can_write =3D socket_can_write, + .can_read =3D socket_can_read, +}; + +static void accept_connection(int sock) +{ + int fd; + struct connection *conn; + + fd =3D accept(sock, NULL, NULL); + if (fd < 0) + return; + + conn =3D new_connection(&socket_funcs); + if (conn) { + conn->fd =3D fd; + conn->id =3D dom0_domid; + } else + close(fd); +} + +static void destroy_fds(void) +{ + if (sock >=3D 0) + close(sock); +} + +static void init_sockets(void) +{ + struct sockaddr_un addr; + const char *soc_str =3D xenstore_daemon_path(); + + if (!soc_str) + barf_perror("Failed to obtain xs domain socket"); + + /* Create sockets for them to listen to. */ + atexit(destroy_fds); + sock =3D socket(PF_UNIX, SOCK_STREAM, 0); + if (sock < 0) + barf_perror("Could not create socket"); + + /* FIXME: Be more sophisticated, don't mug running daemon. */ + unlink(soc_str); + + addr.sun_family =3D AF_UNIX; + + if (strlen(soc_str) >=3D sizeof(addr.sun_path)) + barf_perror("socket string '%s' too long", soc_str); + strcpy(addr.sun_path, soc_str); + if (bind(sock, (struct sockaddr *)&addr, sizeof(addr)) !=3D 0) + barf_perror("Could not bind socket to %s", soc_str); + + if (chmod(soc_str, 0600) !=3D 0) + barf_perror("Could not chmod sockets"); + + if (listen(sock, 1) !=3D 0) + barf_perror("Could not listen on sockets"); +} + + +struct connection *add_socket_connection(int fd) +{ + struct connection *conn; + + conn =3D new_connection(&socket_funcs); + if (!conn) + barf("error restoring connection"); + conn->fd =3D fd; + + return conn; +} + void early_init(bool live_update, bool dofork, const char *pidfile) { reopen_log(); @@ -212,6 +354,9 @@ void set_special_fds(void) if (reopen_log_pipe[0] !=3D -1) reopen_log_pipe0_pollfd_idx =3D set_fd(reopen_log_pipe[0], POLLIN|POLLPRI); + + if (sock !=3D -1) + sock_pollfd_idx =3D set_fd(sock, POLLIN|POLLPRI); } =20 void handle_special_fds(void) @@ -231,6 +376,15 @@ void handle_special_fds(void) } reopen_log_pipe0_pollfd_idx =3D -1; } + + if (sock_pollfd_idx !=3D -1) { + if (poll_fds[sock_pollfd_idx].revents & ~POLLIN) { + barf_perror("sock poll failed"); + } else if (poll_fds[sock_pollfd_idx].revents & POLLIN) { + accept_connection(sock); + sock_pollfd_idx =3D -1; + } + } } =20 void late_init(bool live_update) @@ -242,3 +396,13 @@ void late_init(bool live_update) } #endif } + +int get_socket_fd(void) +{ + return sock; +} + +void set_socket_fd(int fd) +{ + sock =3D fd; +} --=20 2.35.3 From nobody Fri May 17 10:34:34 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; 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=fail(p=quarantine dis=quarantine) header.from=suse.com Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1707130663299365.5037677698633; Mon, 5 Feb 2024 02:57:43 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.675833.1051433 (Exim 4.92) (envelope-from ) id 1rWwfK-00027u-T8; Mon, 05 Feb 2024 10:57:30 +0000 Received: by outflank-mailman (output) from mailman id 675833.1051433; Mon, 05 Feb 2024 10:57:30 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rWwfK-00027j-PJ; Mon, 05 Feb 2024 10:57:30 +0000 Received: by outflank-mailman (input) for mailman id 675833; Mon, 05 Feb 2024 10:57:29 +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 1rWwaP-0002wU-Fm for xen-devel@lists.xenproject.org; Mon, 05 Feb 2024 10:52:25 +0000 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id a554a333-c414-11ee-8a45-1f161083a0e0; Mon, 05 Feb 2024 11:52:25 +0100 (CET) Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id A66501F8BA; Mon, 5 Feb 2024 10:52:24 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 6982913707; Mon, 5 Feb 2024 10:52:24 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id yqo1GOi9wGXdNgAAD6G6ig (envelope-from ); Mon, 05 Feb 2024 10:52:24 +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: a554a333-c414-11ee-8a45-1f161083a0e0 From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Julien Grall , Anthony PERARD , Jason Andryuk , Julien Grall Subject: [PATCH v4 25/32] tools/xenstored: get own domid in stubdom case Date: Mon, 5 Feb 2024 11:49:54 +0100 Message-Id: <20240205105001.24171-26-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240205105001.24171-1-jgross@suse.com> References: <20240205105001.24171-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Authentication-Results: smtp-out2.suse.de; none X-Spamd-Result: default: False [-4.00 / 50.00]; REPLY(-4.00)[] X-Rspamd-Server: rspamd1.dmz-prg2.suse.org X-Rspamd-Queue-Id: A66501F8BA X-Spam-Level: X-Spam-Score: -4.00 X-Spam-Flag: NO X-ZM-MESSAGEID: 1707130665117100001 Content-Type: text/plain; charset="utf-8" Obtain own domid when running as stubdom. Signed-off-by: Juergen Gross Reviewed-by: Jason Andryuk Reviewed-by: Julien Grall --- V2: - replacement of V1 patch (Andrew Cooper) V3: - rename called function to get_domid() (Julien Grall) - change stub_domid type to domid_t (Julien Grall) --- tools/xenstored/core.c | 1 + tools/xenstored/core.h | 1 + tools/xenstored/minios.c | 4 ++++ 3 files changed, 6 insertions(+) diff --git a/tools/xenstored/core.c b/tools/xenstored/core.c index c045a6e5db..9eb3cdf446 100644 --- a/tools/xenstored/core.c +++ b/tools/xenstored/core.c @@ -2557,6 +2557,7 @@ static struct option options[] =3D { int dom0_domid =3D 0; int dom0_event =3D 0; int priv_domid =3D 0; +domid_t stub_domid =3D DOMID_INVALID; =20 static unsigned int get_optval_uint(const char *arg) { diff --git a/tools/xenstored/core.h b/tools/xenstored/core.h index 6180ec8b5c..f6af086f01 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 domid_t stub_domid; extern bool keep_orphans; =20 extern struct pollfd *poll_fds; diff --git a/tools/xenstored/minios.c b/tools/xenstored/minios.c index 6d0c11423c..22ac8defbd 100644 --- a/tools/xenstored/minios.c +++ b/tools/xenstored/minios.c @@ -20,6 +20,7 @@ #include "core.h" #include "utils.h" #include +#include =20 void finish_daemonize(void) { @@ -48,6 +49,9 @@ void unmap_xenbus(void *interface) =20 void early_init(bool live_update, bool dofork, const char *pidfile) { + stub_domid =3D get_domid(); + if (stub_domid =3D=3D DOMID_INVALID) + barf("could not get own domid"); } =20 void late_init(bool live_update) --=20 2.35.3 From nobody Fri May 17 10:34:34 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=1707130367; cv=none; d=zohomail.com; s=zohoarc; b=hg/fZHythgf1g7BJtXCDu/l84gN7xkVf43wbALN4ErkaiPDEifjTjlUhEQf4sbo24uMISCFlvJHiL31DzcPoar2qTu1G8YdOb21c+KcfQrJ6LcmxUw3VHwLJEWFchcutUHGcF4HBQMqLQKIIvHC+SVDDbYv8IzqJ+6+J4ONbIJQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1707130367; 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=sBN45VY796bPT208E7z1cKUSQ/jSCHWuzgN6GPy8ckw=; b=BpOgimWQoITvoaTboYs5oxw/lVeZ0O9Ce+b00sovj+9dHwlYG4o8BY+9KV2NXUkYofmlZT2TsLG0fBVPp5tGvDFzELjqbXi+ioZQr56xghuMVxehOLIXZzZqfBnK42MdjJLDi1FGgFAblsVreSNoMYIhyZqocuk4itfMNAQQT/E= 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 1707130367952983.0459012198818; Mon, 5 Feb 2024 02:52:47 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.675812.1051343 (Exim 4.92) (envelope-from ) id 1rWwaX-00064m-CR; Mon, 05 Feb 2024 10:52:33 +0000 Received: by outflank-mailman (output) from mailman id 675812.1051343; Mon, 05 Feb 2024 10:52: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 1rWwaX-00064d-95; Mon, 05 Feb 2024 10:52:33 +0000 Received: by outflank-mailman (input) for mailman id 675812; Mon, 05 Feb 2024 10:52: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 1rWwaW-00064Q-Le for xen-devel@lists.xenproject.org; Mon, 05 Feb 2024 10:52:32 +0000 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id a8c4cb0b-c414-11ee-98f5-efadbce2ee36; Mon, 05 Feb 2024 11:52:30 +0100 (CET) Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 5255922285; Mon, 5 Feb 2024 10:52:30 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 14A4A132DD; Mon, 5 Feb 2024 10:52:30 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id QOmNA+69wGXmNgAAD6G6ig (envelope-from ); Mon, 05 Feb 2024 10:52: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: a8c4cb0b-c414-11ee-98f5-efadbce2ee36 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1707130350; 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=sBN45VY796bPT208E7z1cKUSQ/jSCHWuzgN6GPy8ckw=; b=XPLQmfsImAnW4qPMeUaZMNYUKSCWkTag5wGDPSYySdjzxWw0LTfK7czpaKIGUbR2VOgO/U w/sayaMlagAz0M9Fclx3CRPeO7wYiBdhqS4ushlEwZ2F8eoSOVBWGaxr7mgKgLiW+ZIqQ4 BWDxSi9ki62/PDIMB4SWLuhbqmMLaTY= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1707130350; 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=sBN45VY796bPT208E7z1cKUSQ/jSCHWuzgN6GPy8ckw=; b=XPLQmfsImAnW4qPMeUaZMNYUKSCWkTag5wGDPSYySdjzxWw0LTfK7czpaKIGUbR2VOgO/U w/sayaMlagAz0M9Fclx3CRPeO7wYiBdhqS4ushlEwZ2F8eoSOVBWGaxr7mgKgLiW+ZIqQ4 BWDxSi9ki62/PDIMB4SWLuhbqmMLaTY= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Julien Grall , Anthony PERARD , Jason Andryuk , Julien Grall Subject: [PATCH v4 26/32] tools/xenstored: rework ring page (un)map functions Date: Mon, 5 Feb 2024 11:49:55 +0100 Message-Id: <20240205105001.24171-27-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240205105001.24171-1-jgross@suse.com> References: <20240205105001.24171-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Authentication-Results: smtp-out1.suse.de; none X-Spamd-Result: default: False [0.89 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; FREEMAIL_ENVRCPT(0.00)[gmail.com]; R_MISSING_CHARSET(2.50)[]; MIME_GOOD(-0.10)[text/plain]; TO_MATCH_ENVRCPT_ALL(0.00)[]; REPLY(-4.00)[]; BROKEN_CONTENT_TYPE(1.50)[]; RCVD_COUNT_THREE(0.00)[3]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; RCPT_COUNT_SEVEN(0.00)[7]; MID_CONTAINS_FROM(1.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.com:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; FREEMAIL_CC(0.00)[suse.com,xen.org,citrix.com,gmail.com,amazon.com]; RCVD_TLS_ALL(0.00)[]; BAYES_HAM(-0.01)[50.16%] X-Spam-Level: X-Spam-Flag: NO X-Spam-Score: 0.89 X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1707130369872100001 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 040df98b8c..af80a8221d 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 Fri May 17 10:34:34 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=1707130369; cv=none; d=zohomail.com; s=zohoarc; b=UXLPKFfrzftNzeeNs3mtpkaNHVt/bUnRjWg41SOs3ZfFdocoXOOnRoVN80FHzJWDWPB8bcd8bbtHOmvd/d7u1g+GZYOhYGYL48Ezw26WbXm6yaYvWmtEXenpo//9ub6dBZ7lGRH1xJ6idQalsfxUVeUuqKr1KZ/1Nd040p3S8tM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1707130369; 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=WeNBiDTNS7TMepXj/jHm53gvlyAKdRYh91nCqLjvqLA=; b=hekZi5SqSHkgxDZdVg/lFrUsNeFb3P309qVFxzVj0riu+cPm6Nzm1dmfZxkChB9upNWMyFz/pdXJHXEgYI+0xOTAisXHlDqI5iqs7D5i991ctgFjJU4NJ6fQRS1vM4FIa3hLYuVFmJhtPGDKfpk0sTaLL5e0EaucXpKw4vFI4w0= 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 1707130369598307.48216899909244; Mon, 5 Feb 2024 02:52:49 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.675813.1051353 (Exim 4.92) (envelope-from ) id 1rWwad-0006M9-KC; Mon, 05 Feb 2024 10:52:39 +0000 Received: by outflank-mailman (output) from mailman id 675813.1051353; Mon, 05 Feb 2024 10:52:39 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rWwad-0006M0-Gk; Mon, 05 Feb 2024 10:52:39 +0000 Received: by outflank-mailman (input) for mailman id 675813; Mon, 05 Feb 2024 10:52:38 +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 1rWwac-00064Q-28 for xen-devel@lists.xenproject.org; Mon, 05 Feb 2024 10:52:38 +0000 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id ac30caae-c414-11ee-98f5-efadbce2ee36; Mon, 05 Feb 2024 11:52:36 +0100 (CET) Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 1279222100; Mon, 5 Feb 2024 10:52:36 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id BDF5C132DD; Mon, 5 Feb 2024 10:52:35 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id CPKmLPO9wGXuNgAAD6G6ig (envelope-from ); Mon, 05 Feb 2024 10:52:35 +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: ac30caae-c414-11ee-98f5-efadbce2ee36 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1707130356; 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=WeNBiDTNS7TMepXj/jHm53gvlyAKdRYh91nCqLjvqLA=; b=ihzYIvnwhErawe9X0SPXCpAAKCwJ5kImARwcHVfOvAYWrMKt8N3m6pcy/ylnYFzPUrDUc8 fJGFWcsoYkpqv6UQQY1e5LpK/jgZ2kC2Qu+nfUerL6NaPTNOnbNDa4C6iZVz5ImDz+3pTK kuZqJjCB6DEJ06yHzi/BIfO2Uy+VYvI= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1707130356; 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=WeNBiDTNS7TMepXj/jHm53gvlyAKdRYh91nCqLjvqLA=; b=ihzYIvnwhErawe9X0SPXCpAAKCwJ5kImARwcHVfOvAYWrMKt8N3m6pcy/ylnYFzPUrDUc8 fJGFWcsoYkpqv6UQQY1e5LpK/jgZ2kC2Qu+nfUerL6NaPTNOnbNDa4C6iZVz5ImDz+3pTK kuZqJjCB6DEJ06yHzi/BIfO2Uy+VYvI= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Julien Grall , Anthony PERARD , Jason Andryuk , Julien Grall Subject: [PATCH v4 27/32] tools/xenstored: split domain_init() Date: Mon, 5 Feb 2024 11:49:56 +0100 Message-Id: <20240205105001.24171-28-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240205105001.24171-1-jgross@suse.com> References: <20240205105001.24171-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Authentication-Results: smtp-out1.suse.de; none X-Spam-Level: X-Spam-Score: -3.30 X-Spamd-Result: default: False [-3.30 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; R_MISSING_CHARSET(2.50)[]; FREEMAIL_ENVRCPT(0.00)[gmail.com]; MIME_GOOD(-0.10)[text/plain]; TO_MATCH_ENVRCPT_ALL(0.00)[]; REPLY(-4.00)[]; BROKEN_CONTENT_TYPE(1.50)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; RCVD_COUNT_THREE(0.00)[3]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; NEURAL_HAM_SHORT(-0.20)[-1.000]; RCPT_COUNT_SEVEN(0.00)[7]; MID_CONTAINS_FROM(1.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.com:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; FREEMAIL_CC(0.00)[suse.com,xen.org,citrix.com,gmail.com,amazon.com]; RCVD_TLS_ALL(0.00)[]; BAYES_HAM(-3.00)[100.00%] X-Spam-Flag: NO X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1707130369873100002 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 Reviewed-by: Jason Andryuk Reviewed-by: Julien Grall --- V3: - rename new function to domain_early_init() (Julien Grall) --- 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 9eb3cdf446..3bf2ec7734 100644 --- a/tools/xenstored/core.c +++ b/tools/xenstored/core.c @@ -2742,6 +2742,8 @@ int main(int argc, char *argv[]) =20 talloc_enable_null_tracking(); =20 + domain_early_init(); + /* Listen to hypervisor. */ if (!live_update) { domain_init(-1); diff --git a/tools/xenstored/domain.c b/tools/xenstored/domain.c index af80a8221d..621b415088 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_early_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..224c4c23e2 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_early_init(void); void domain_init(int evtfd); void dom0_init(void); void domain_deinit(void); --=20 2.35.3 From nobody Fri May 17 10:34:34 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=1707130377; cv=none; d=zohomail.com; s=zohoarc; b=D+WyykiI3Jzez1J7+MOYPeyzEoRtMRm5+kv4ORLE3IvhWJt+yGTHzLyEkY9808HMn/UOXuuQSpiKkZevki1pqdpsx6Zedrv1ZgdhHztgJpmuHvPl7Ryz68J73j1VUit50kdUPD54JqUdi5NpoDzq/CLsoMBkdpu8PTevfAKh1WQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1707130377; 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=CNBMmRI5jm2OY3r5fUBNPy2uDNZ81cgAaFW7uO2/RZQ=; b=m3Puh1lZ3Honw/I9mJwa9+PYTnUC5M8HUnEcoGhRKTOTYViz7zB5f/PXo587xinV24YYDc+2DGHIxHdFyEc9fn5VuwUrtIvdqSRgvqtCV+mztbSLKT9wL1Ft6OopFxApX182fqYDYNGvU0e2olYwFNxxannervNhLQPLhYVrNqQ= 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 170713037759277.00380033913473; Mon, 5 Feb 2024 02:52:57 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.675814.1051363 (Exim 4.92) (envelope-from ) id 1rWwai-0006fs-T4; Mon, 05 Feb 2024 10:52:44 +0000 Received: by outflank-mailman (output) from mailman id 675814.1051363; Mon, 05 Feb 2024 10:52:44 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rWwai-0006fh-Ov; Mon, 05 Feb 2024 10:52:44 +0000 Received: by outflank-mailman (input) for mailman id 675814; Mon, 05 Feb 2024 10:52:43 +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 1rWwah-00064Q-Qk for xen-devel@lists.xenproject.org; Mon, 05 Feb 2024 10:52:43 +0000 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id af8e7d03-c414-11ee-98f5-efadbce2ee36; Mon, 05 Feb 2024 11:52:42 +0100 (CET) Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id ACCA222288; Mon, 5 Feb 2024 10:52:41 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 72995132DD; Mon, 5 Feb 2024 10:52:41 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id Lxx6Gvm9wGX2NgAAD6G6ig (envelope-from ); Mon, 05 Feb 2024 10:52: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: af8e7d03-c414-11ee-98f5-efadbce2ee36 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1707130361; 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=CNBMmRI5jm2OY3r5fUBNPy2uDNZ81cgAaFW7uO2/RZQ=; b=rd2j+e3DNUEu/4Q9X+OKH3cW4mxygqpC2Q4CSidj4iIM6NEpol3IKANp8g8I2Vkv//VyIi kJzIkXPdk4Wu5Pse18J6awFQUOfbrZ1ZqINl9rPR8O0YgA0RsNJPBa2mUpCIIw/ZR3B2Hx gOp/VaS1Jxatyn3uVijFCGVU6N7sHXA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1707130361; 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=CNBMmRI5jm2OY3r5fUBNPy2uDNZ81cgAaFW7uO2/RZQ=; b=rd2j+e3DNUEu/4Q9X+OKH3cW4mxygqpC2Q4CSidj4iIM6NEpol3IKANp8g8I2Vkv//VyIi kJzIkXPdk4Wu5Pse18J6awFQUOfbrZ1ZqINl9rPR8O0YgA0RsNJPBa2mUpCIIw/ZR3B2Hx gOp/VaS1Jxatyn3uVijFCGVU6N7sHXA= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Julien Grall , Anthony PERARD , Jason Andryuk , Julien Grall Subject: [PATCH v4 28/32] tools/xenstored: map stubdom interface Date: Mon, 5 Feb 2024 11:49:57 +0100 Message-Id: <20240205105001.24171-29-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240205105001.24171-1-jgross@suse.com> References: <20240205105001.24171-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Authentication-Results: smtp-out1.suse.de; none X-Spamd-Result: default: False [-2.10 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; FREEMAIL_ENVRCPT(0.00)[gmail.com]; R_MISSING_CHARSET(2.50)[]; MIME_GOOD(-0.10)[text/plain]; TO_MATCH_ENVRCPT_ALL(0.00)[]; REPLY(-4.00)[]; BROKEN_CONTENT_TYPE(1.50)[]; RCVD_COUNT_THREE(0.00)[3]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; RCPT_COUNT_SEVEN(0.00)[7]; MID_CONTAINS_FROM(1.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.com:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; FREEMAIL_CC(0.00)[suse.com,xen.org,citrix.com,gmail.com,amazon.com]; RCVD_TLS_ALL(0.00)[]; BAYES_HAM(-3.00)[100.00%] X-Spam-Level: X-Spam-Flag: NO X-Spam-Score: -2.10 X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1707130377875100001 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. Use the same pattern as in dom0_init() when running as daemon in dom0 (introduce the own domain, then send an event to the client side to signal Xenstore is ready to communicate). Signed-off-by: Juergen Gross Reviewed-by: Jason Andryuk Reviewed-by: Julien Grall --- 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 3bf2ec7734..48fc787ac1 100644 --- a/tools/xenstored/core.c +++ b/tools/xenstored/core.c @@ -2767,6 +2767,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 621b415088..1a7d5e9756 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 224c4c23e2..844ac11510 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_early_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 Fri May 17 10:34:34 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; 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=fail(p=quarantine dis=quarantine) header.from=suse.com Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1707130380755702.7955475970723; Mon, 5 Feb 2024 02:53:00 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.675815.1051372 (Exim 4.92) (envelope-from ) id 1rWwap-000769-32; Mon, 05 Feb 2024 10:52:51 +0000 Received: by outflank-mailman (output) from mailman id 675815.1051372; Mon, 05 Feb 2024 10:52:51 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rWwap-000762-0N; Mon, 05 Feb 2024 10:52:51 +0000 Received: by outflank-mailman (input) for mailman id 675815; Mon, 05 Feb 2024 10:52:49 +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 1rWwan-00064Q-8e for xen-devel@lists.xenproject.org; Mon, 05 Feb 2024 10:52:49 +0000 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id b2dd3724-c414-11ee-98f5-efadbce2ee36; Mon, 05 Feb 2024 11:52:47 +0100 (CET) Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 55CBF22100; Mon, 5 Feb 2024 10:52:47 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 1BBC413A3A; Mon, 5 Feb 2024 10:52:47 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id oxxXBf+9wGUANwAAD6G6ig (envelope-from ); Mon, 05 Feb 2024 10:52: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: b2dd3724-c414-11ee-98f5-efadbce2ee36 From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Julien Grall , Anthony PERARD , Jason Andryuk , Julien Grall Subject: [PATCH v4 29/32] tools/xenstored: mount 9pfs device in stubdom Date: Mon, 5 Feb 2024 11:49:58 +0100 Message-Id: <20240205105001.24171-30-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240205105001.24171-1-jgross@suse.com> References: <20240205105001.24171-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spam-Level: Authentication-Results: smtp-out1.suse.de; none X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Spamd-Result: default: False [-4.00 / 50.00]; REPLY(-4.00)[] X-Spam-Score: -4.00 X-Rspamd-Queue-Id: 55CBF22100 X-Spam-Flag: NO X-ZM-MESSAGEID: 1707130381863100001 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 Reviewed-by: Julien Grall --- V3: - add logging in case of errors (Julien Grall) --- tools/xenstored/core.h | 6 +++++ tools/xenstored/domain.c | 2 ++ tools/xenstored/minios.c | 54 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+) diff --git a/tools/xenstored/core.h b/tools/xenstored/core.h index f6af086f01..fe0ee90581 100644 --- a/tools/xenstored/core.h +++ b/tools/xenstored/core.h @@ -36,6 +36,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. */ @@ -399,6 +401,10 @@ void handle_special_fds(void); int get_socket_fd(void); void set_socket_fd(int fd); =20 +#ifdef __MINIOS__ +void mount_9pfs(void); +#endif + /* Close stdin/stdout/stderr to complete daemonize */ void finish_daemonize(void); =20 diff --git a/tools/xenstored/domain.c b/tools/xenstored/domain.c index 1a7d5e9756..64c8fd0cc3 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 22ac8defbd..562a9b4972 100644 --- a/tools/xenstored/minios.c +++ b/tools/xenstored/minios.c @@ -17,10 +17,20 @@ */ #include #include +#include +#include "talloc.h" #include "core.h" #include "utils.h" #include #include +#include +#include +#include +#include + +#define P9_STATE_PATH "device/9pfs/0/state" + +static void *p9_device; =20 void finish_daemonize(void) { @@ -74,3 +84,47 @@ int get_socket_fd(void) void set_socket_fd(int fd) { } + +static void mount_thread(void *p) +{ + xenbus_event_queue events =3D NULL; + char *err; + char *dummy; + + err =3D xenbus_watch_path_token(XBT_NIL, P9_STATE_PATH, "9pfs", &events); + if (err) { + log("error \"%s\" when setting watch on \"%s\"\n", err, + P9_STATE_PATH); + free(err); + return; + } + + for (;;) { + xenbus_wait_for_watch(&events); + + /* + * We only care for existence of the state node. + * State changes are handled in init_9pfront(). + */ + err =3D xenbus_read(XBT_NIL, P9_STATE_PATH, &dummy); + if (!err) + break; + free(err); + } + + free(dummy); + + err =3D xenbus_unwatch_path_token(XBT_NIL, P9_STATE_PATH, "9pfs"); + if (err) { + log("error \"%s\" when unwatching \"%s\", leaking watch\n", + err, P9_STATE_PATH); + free(err); + } + + 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 Fri May 17 10:34:34 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; 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=fail(p=quarantine dis=quarantine) header.from=suse.com Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1707130759895597.607245810011; Mon, 5 Feb 2024 02:59:19 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.675893.1051573 (Exim 4.92) (envelope-from ) id 1rWwgt-0002Ju-Aa; Mon, 05 Feb 2024 10:59:07 +0000 Received: by outflank-mailman (output) from mailman id 675893.1051573; Mon, 05 Feb 2024 10:59:07 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rWwgt-0002Jl-7u; Mon, 05 Feb 2024 10:59:07 +0000 Received: by outflank-mailman (input) for mailman id 675893; Mon, 05 Feb 2024 10:59:05 +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 1rWwar-0002wU-Sm for xen-devel@lists.xenproject.org; Mon, 05 Feb 2024 10:52:53 +0000 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id b6364be0-c414-11ee-8a45-1f161083a0e0; Mon, 05 Feb 2024 11:52:53 +0100 (CET) Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 0023422100; Mon, 5 Feb 2024 10:52:52 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id B63F1132DD; Mon, 5 Feb 2024 10:52:52 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id 9ar+KgS+wGUGNwAAD6G6ig (envelope-from ); Mon, 05 Feb 2024 10:52:52 +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: b6364be0-c414-11ee-8a45-1f161083a0e0 From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Julien Grall , Anthony PERARD , Jason Andryuk , Julien Grall Subject: [PATCH v4 30/32] tools/xenstored: add helpers for filename handling Date: Mon, 5 Feb 2024 11:49:59 +0100 Message-Id: <20240205105001.24171-31-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240205105001.24171-1-jgross@suse.com> References: <20240205105001.24171-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spam-Level: Authentication-Results: smtp-out1.suse.de; none X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Spamd-Result: default: False [-4.00 / 50.00]; REPLY(-4.00)[] X-Spam-Score: -4.00 X-Rspamd-Queue-Id: 0023422100 X-Spam-Flag: NO X-ZM-MESSAGEID: 1707130761691100001 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 Reviewed-by: Julien Grall --- V3: - make absolute_filename() return a pointer to const (Julien Grall) --- tools/xenstored/core.c | 15 +++++++++++++-- tools/xenstored/core.h | 5 ++++- tools/xenstored/lu_daemon.c | 4 ++-- tools/xenstored/minios.c | 5 +++++ tools/xenstored/posix.c | 8 +++++++- 5 files changed, 31 insertions(+), 6 deletions(-) diff --git a/tools/xenstored/core.c b/tools/xenstored/core.c index 48fc787ac1..bada1ad9a2 100644 --- a/tools/xenstored/core.c +++ b/tools/xenstored/core.c @@ -63,7 +63,7 @@ char **orig_argv; LIST_HEAD(connections); int tracefd =3D -1; bool keep_orphans =3D false; -char *tracefile =3D NULL; +const char *tracefile =3D NULL; static struct hashtable *nodes; unsigned int trace_flags =3D TRACE_OBJ | TRACE_IO; =20 @@ -137,6 +137,17 @@ void trace_destroy(const void *data, const char *type) trace("obj: DESTROY %s %p\n", type, data); } =20 +/* + * Return an absolute filename. + * In case of a relative filename given as input, prepend XENSTORE_LIB_DIR. + */ +const 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); +} + void close_log(void) { if (tracefd >=3D 0) @@ -2759,7 +2770,7 @@ int main(int argc, char *argv[]) #endif =20 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 fe0ee90581..e58779e88c 100644 --- a/tools/xenstored/core.h +++ b/tools/xenstored/core.h @@ -341,7 +341,7 @@ void close_log(void); extern int orig_argc; extern char **orig_argv; =20 -extern char *tracefile; +extern const char *tracefile; extern int tracefd; =20 /* Trace flag values must be kept in sync with trace_switches[] contents. = */ @@ -405,6 +405,9 @@ void set_socket_fd(int fd); void mount_9pfs(void); #endif =20 +const char *xenstore_rundir(void); +const char *absolute_filename(const void *ctx, const char *filename); + /* Close stdin/stdout/stderr to complete daemonize */ void finish_daemonize(void); =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 562a9b4972..e70386f8c7 100644 --- a/tools/xenstored/minios.c +++ b/tools/xenstored/minios.c @@ -128,3 +128,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 496329dfd1..d88c82d972 100644 --- a/tools/xenstored/posix.c +++ b/tools/xenstored/posix.c @@ -326,9 +326,10 @@ void early_init(bool live_update, bool dofork, const c= har *pidfile) { reopen_log(); =20 - /* Make sure xenstored directory exists. */ + /* 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 if (dofork) { openlog("xenstored", 0, LOG_DAEMON); @@ -406,3 +407,8 @@ void set_socket_fd(int fd) { sock =3D fd; } + +const char *xenstore_rundir(void) +{ + return xenstore_daemon_rundir(); +} --=20 2.35.3 From nobody Fri May 17 10:34:34 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; 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=fail(p=quarantine dis=quarantine) header.from=suse.com Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1707130403189296.887692439421; Mon, 5 Feb 2024 02:53:23 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.675819.1051383 (Exim 4.92) (envelope-from ) id 1rWwb1-0007qY-Cb; Mon, 05 Feb 2024 10:53:03 +0000 Received: by outflank-mailman (output) from mailman id 675819.1051383; Mon, 05 Feb 2024 10:53: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 1rWwb1-0007qP-84; Mon, 05 Feb 2024 10:53:03 +0000 Received: by outflank-mailman (input) for mailman id 675819; Mon, 05 Feb 2024 10:53: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 1rWwaz-00064Q-63 for xen-devel@lists.xenproject.org; Mon, 05 Feb 2024 10:53:01 +0000 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id b997754a-c414-11ee-98f5-efadbce2ee36; Mon, 05 Feb 2024 11:52:58 +0100 (CET) Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 9BEC022100; Mon, 5 Feb 2024 10:52:58 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 5EEF9132DD; Mon, 5 Feb 2024 10:52:58 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id RM2vFQq+wGUQNwAAD6G6ig (envelope-from ); Mon, 05 Feb 2024 10:52: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: b997754a-c414-11ee-98f5-efadbce2ee36 From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Anthony PERARD , Julien Grall , Jason Andryuk , Julien Grall Subject: [PATCH v4 31/32] tools/xenstored: support complete log capabilities in stubdom Date: Mon, 5 Feb 2024 11:50:00 +0100 Message-Id: <20240205105001.24171-32-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240205105001.24171-1-jgross@suse.com> References: <20240205105001.24171-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Authentication-Results: smtp-out1.suse.de; none X-Spamd-Result: default: False [-4.00 / 50.00]; REPLY(-4.00)[] X-Rspamd-Server: rspamd1.dmz-prg2.suse.org X-Rspamd-Queue-Id: 9BEC022100 X-Spam-Level: X-Spam-Score: -4.00 X-Spam-Flag: NO X-ZM-MESSAGEID: 1707130404080100001 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 Reviewed-by: Julien Grall --- V3: - remove now stale comment in sysconfig.xencommons.in (Julien Grall) --- .../Linux/init.d/sysconfig.xencommons.in | 1 - tools/hotplug/Linux/launch-xenstore.in | 1 + tools/xenstored/control.c | 30 +++++++++---------- tools/xenstored/minios.c | 3 ++ 4 files changed, 19 insertions(+), 16 deletions(-) diff --git a/tools/hotplug/Linux/init.d/sysconfig.xencommons.in b/tools/hot= plug/Linux/init.d/sysconfig.xencommons.in index 433e4849af..1bdd830d8a 100644 --- a/tools/hotplug/Linux/init.d/sysconfig.xencommons.in +++ b/tools/hotplug/Linux/init.d/sysconfig.xencommons.in @@ -58,7 +58,6 @@ XENSTORED_ARGS=3D ## Default: Not defined, tracing off # # Log xenstored messages -# Only evaluated if XENSTORETYPE is "daemon". #XENSTORED_TRACE=3D[yes|on|1] =20 ## Type: integer 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 e70386f8c7..a229954cf4 100644 --- a/tools/xenstored/minios.c +++ b/tools/xenstored/minios.c @@ -122,6 +122,9 @@ static void mount_thread(void *p) } =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 Fri May 17 10:34:34 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; 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=fail(p=quarantine dis=quarantine) header.from=suse.com Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1707130398896976.4251948003471; Mon, 5 Feb 2024 02:53:18 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.675820.1051393 (Exim 4.92) (envelope-from ) id 1rWwb4-00088S-Mk; Mon, 05 Feb 2024 10:53:06 +0000 Received: by outflank-mailman (output) from mailman id 675820.1051393; Mon, 05 Feb 2024 10:53:06 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rWwb4-00088L-JX; Mon, 05 Feb 2024 10:53:06 +0000 Received: by outflank-mailman (input) for mailman id 675820; Mon, 05 Feb 2024 10:53:06 +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 1rWwb4-00064Q-5p for xen-devel@lists.xenproject.org; Mon, 05 Feb 2024 10:53:06 +0000 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id bcf3692b-c414-11ee-98f5-efadbce2ee36; Mon, 05 Feb 2024 11:53:04 +0100 (CET) Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 4327822277; Mon, 5 Feb 2024 10:53:04 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 0E8EE132DD; Mon, 5 Feb 2024 10:53:04 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id EVQjAhC+wGUVNwAAD6G6ig (envelope-from ); Mon, 05 Feb 2024 10:53: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: bcf3692b-c414-11ee-98f5-efadbce2ee36 From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Julien Grall , Anthony PERARD , Jason Andryuk Subject: [PATCH v4 32/32] tools/xenstored: have a single do_control_memreport() Date: Mon, 5 Feb 2024 11:50:01 +0100 Message-Id: <20240205105001.24171-33-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240205105001.24171-1-jgross@suse.com> References: <20240205105001.24171-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spam-Level: Authentication-Results: smtp-out1.suse.de; none X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Spamd-Result: default: False [-4.00 / 50.00]; REPLY(-4.00)[] X-Spam-Score: -4.00 X-Rspamd-Queue-Id: 4327822277 X-Spam-Flag: NO X-ZM-MESSAGEID: 1707130400066100001 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..9561289179 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; + const 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