From patchwork Thu Feb 15 13:04:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?SsO8cmdlbiBHcm/Dnw==?= X-Patchwork-Id: 13558349 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A6BAFC48BC4 for ; Thu, 15 Feb 2024 13:05:28 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.681680.1060547 (Exim 4.92) (envelope-from ) id 1rabQW-0002zD-6p; Thu, 15 Feb 2024 13:05:20 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 681680.1060547; Thu, 15 Feb 2024 13:05:20 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rabQW-0002z4-40; Thu, 15 Feb 2024 13:05:20 +0000 Received: by outflank-mailman (input) for mailman id 681680; Thu, 15 Feb 2024 13:05:18 +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 1rabQU-0002yD-RN for xen-devel@lists.xenproject.org; Thu, 15 Feb 2024 13:05:18 +0000 Received: from smtp-out2.suse.de (smtp-out2.suse.de [2a07:de40:b251:101:10:150:64:2]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id dda944a4-cc02-11ee-8a4d-1f161083a0e0; Thu, 15 Feb 2024 14:05:17 +0100 (CET) Received: from imap2.dmz-prg2.suse.org (imap2.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:98]) (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 3A4861F8A4; Thu, 15 Feb 2024 13:05:17 +0000 (UTC) Received: from imap2.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 imap2.dmz-prg2.suse.org (Postfix) with ESMTPS id 04E40139D0; Thu, 15 Feb 2024 13:05:16 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap2.dmz-prg2.suse.org with ESMTPSA id BU9iOwwMzmVxFQAAn2gu4w (envelope-from ); Thu, 15 Feb 2024 13:05:16 +0000 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: dda944a4-cc02-11ee-8a4d-1f161083a0e0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1708002317; 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=rQPRnnpvHJ9iAPaCFRu4161m+4eTjuy3Ob9j9LfvB8M=; b=S5wYaxMBdR42E3tgguDQHkkN9QW8UjTkoOEUy5iNQ4stWpsxcsXr+5f1p7G6rkCZVx11t5 smqZtFF7L5NlMCB1vmKUI3kP33SVNgqfm3qYOoAoUiolsr7pfZKyToFEl7eSXrFeN1/98V 1HVoZM8AxAjp/yF/RT6SeMp9kPZQivQ= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1708002317; 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=rQPRnnpvHJ9iAPaCFRu4161m+4eTjuy3Ob9j9LfvB8M=; b=S5wYaxMBdR42E3tgguDQHkkN9QW8UjTkoOEUy5iNQ4stWpsxcsXr+5f1p7G6rkCZVx11t5 smqZtFF7L5NlMCB1vmKUI3kP33SVNgqfm3qYOoAoUiolsr7pfZKyToFEl7eSXrFeN1/98V 1HVoZM8AxAjp/yF/RT6SeMp9kPZQivQ= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Anthony PERARD , Jason Andryuk , Andrew Cooper Subject: [PATCH v7 01/21] tools: add a new xen 9pfs daemon Date: Thu, 15 Feb 2024 14:04:49 +0100 Message-Id: <20240215130509.24008-2-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240215130509.24008-1-jgross@suse.com> References: <20240215130509.24008-1-jgross@suse.com> MIME-Version: 1.0 Authentication-Results: smtp-out2.suse.de; dkim=pass header.d=suse.com header.s=susede1 header.b=S5wYaxMB X-Spamd-Result: default: False [1.69 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; R_DKIM_ALLOW(-0.20)[suse.com:s=susede1]; SPAMHAUS_XBL(0.00)[2a07:de40:b281:104:10:150:64:98:from]; 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)[]; BROKEN_CONTENT_TYPE(1.50)[]; RCPT_COUNT_FIVE(0.00)[6]; RCVD_COUNT_THREE(0.00)[3]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; DKIM_TRACE(0.00)[suse.com:+]; MX_GOOD(-0.01)[]; MID_CONTAINS_FROM(1.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.com:dkim,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-Rspamd-Server: rspamd1.dmz-prg2.suse.org X-Rspamd-Queue-Id: 3A4861F8A4 X-Spamd-Bar: + Add "xen-9pfsd", a new 9pfs 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) V5: - rename source directory to tools/9pfsd (Andrew Cooper) --- tools/9pfsd/.gitignore | 1 + tools/9pfsd/Makefile | 38 +++++++++++ tools/9pfsd/xen-9pfsd.c | 147 ++++++++++++++++++++++++++++++++++++++++ tools/Makefile | 1 + 4 files changed, 187 insertions(+) create mode 100644 tools/9pfsd/.gitignore create mode 100644 tools/9pfsd/Makefile create mode 100644 tools/9pfsd/xen-9pfsd.c diff --git a/tools/9pfsd/.gitignore b/tools/9pfsd/.gitignore new file mode 100644 index 0000000000..d0c2d223ef --- /dev/null +++ b/tools/9pfsd/.gitignore @@ -0,0 +1 @@ +/xen-9pfsd diff --git a/tools/9pfsd/Makefile b/tools/9pfsd/Makefile new file mode 100644 index 0000000000..089cf5ae24 --- /dev/null +++ b/tools/9pfsd/Makefile @@ -0,0 +1,38 @@ +# +# tools/9pfsd/Makefile +# + +XEN_ROOT = $(CURDIR)/../.. +include $(XEN_ROOT)/tools/Rules.mk + +CFLAGS += $(PTHREAD_CFLAGS) +LDFLAGS += $(PTHREAD_LDFLAGS) + +TARGETS := xen-9pfsd + +XEN-9PFSD_OBJS = xen-9pfsd.o +$(XEN-9PFSD_OBJS): CFLAGS += $(CFLAGS_libxenstore) +$(XEN-9PFSD_OBJS): CFLAGS += $(CFLAGS_libxenevtchn) +$(XEN-9PFSD_OBJS): CFLAGS += $(CFLAGS_libxengnttab) +xen-9pfsd: LDLIBS += $(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/9pfsd/xen-9pfsd.c b/tools/9pfsd/xen-9pfsd.c new file mode 100644 index 0000000000..6939d01574 --- /dev/null +++ b/tools/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 backend). + * + * Usage: xen-9pfsd + * + * xen-9pfsd does NOT support writing any links (neither soft links nor hard + * 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 guest + * can be limited by the backend Xenstore node "max-size" specifying the size + * in MBytes. This size includes the size of the root directory of the guest. + */ + +#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 = 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 = %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 = xs_open(0); + if ( xs == NULL ) + do_err("xs_open() failed"); + + xg = xengnttab_open(NULL, 0); + if ( xg == NULL ) + do_err("xengnttab_open() failed"); + + xe = xenevtchn_open(NULL, 0); + if ( xe == NULL ) + do_err("xenevtchn_open() failed"); + + while ( true ) + { + t = xs_transaction_start(xs); + if ( t == XBT_NULL ) + do_err("xs_transaction_start() failed"); + + val = 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 != EAGAIN ) + do_err("xs_transaction_end() failed"); + } + + daemon_running = true; +} + +int main(int argc, char *argv[]) +{ + struct sigaction act = { .sa_handler = handle_stop, }; + int syslog_mask = 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 |= 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; +} diff --git a/tools/Makefile b/tools/Makefile index 3a510663a0..7d17211782 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -32,6 +32,7 @@ SUBDIRS-y += xenpmd SUBDIRS-$(CONFIG_GOLANG) += golang SUBDIRS-y += xl SUBDIRS-y += helpers +SUBDIRS-y += 9pfsd SUBDIRS-$(CONFIG_X86) += xenpaging SUBDIRS-$(CONFIG_X86) += debugger SUBDIRS-$(CONFIG_TESTS) += tests From patchwork Thu Feb 15 13:04:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?SsO8cmdlbiBHcm/Dnw==?= X-Patchwork-Id: 13558350 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1B957C4829E for ; Thu, 15 Feb 2024 13:05:34 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.681681.1060557 (Exim 4.92) (envelope-from ) id 1rabQc-0003Ih-Jo; Thu, 15 Feb 2024 13:05:26 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 681681.1060557; Thu, 15 Feb 2024 13:05:26 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rabQc-0003IY-G1; Thu, 15 Feb 2024 13:05:26 +0000 Received: by outflank-mailman (input) for mailman id 681681; Thu, 15 Feb 2024 13:05:25 +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 1rabQb-0002j3-HR for xen-devel@lists.xenproject.org; Thu, 15 Feb 2024 13:05:25 +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 e0e694f9-cc02-11ee-98f5-efadbce2ee36; Thu, 15 Feb 2024 14:05:23 +0100 (CET) Received: from imap2.dmz-prg2.suse.org (imap2.dmz-prg2.suse.org [10.150.64.98]) (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 D11BF21FBC; Thu, 15 Feb 2024 13:05:22 +0000 (UTC) Received: from imap2.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 imap2.dmz-prg2.suse.org (Postfix) with ESMTPS id 9C61E139D0; Thu, 15 Feb 2024 13:05:22 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap2.dmz-prg2.suse.org with ESMTPSA id sj/OJBIMzmVzFQAAn2gu4w (envelope-from ); Thu, 15 Feb 2024 13:05:22 +0000 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: e0e694f9-cc02-11ee-98f5-efadbce2ee36 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1708002322; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2rcpEbJbgUxiNrBORk+pKJOPpR9mCjteYZqR1AIlbbY=; b=C8T/0ZV4tO8ots6sBRqict1+jS/oEW9uW0uVKX2Gza3KmZ7iyEg4IUZLoeELdrbaghnxhE tZg4AEERJOzCnEN2+ilRHJ2/ITxjACl0TQoiIv/jF80lHYHFa9leXUilFQLavlgUasISkn dWI74THZOzdvBnVuaOanhmfJqTcUCuM= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1708002322; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2rcpEbJbgUxiNrBORk+pKJOPpR9mCjteYZqR1AIlbbY=; b=C8T/0ZV4tO8ots6sBRqict1+jS/oEW9uW0uVKX2Gza3KmZ7iyEg4IUZLoeELdrbaghnxhE tZg4AEERJOzCnEN2+ilRHJ2/ITxjACl0TQoiIv/jF80lHYHFa9leXUilFQLavlgUasISkn dWI74THZOzdvBnVuaOanhmfJqTcUCuM= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Anthony PERARD , Jason Andryuk Subject: [PATCH v7 02/21] tools/xen-9pfsd: connect to frontend Date: Thu, 15 Feb 2024 14:04:50 +0100 Message-Id: <20240215130509.24008-3-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240215130509.24008-1-jgross@suse.com> References: <20240215130509.24008-1-jgross@suse.com> MIME-Version: 1.0 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]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; 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%] 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/9pfsd/Makefile | 2 +- tools/9pfsd/io.c | 45 +++ tools/9pfsd/xen-9pfsd.c | 653 +++++++++++++++++++++++++++++++++++++++- tools/9pfsd/xen-9pfsd.h | 61 ++++ 4 files changed, 757 insertions(+), 4 deletions(-) create mode 100644 tools/9pfsd/io.c create mode 100644 tools/9pfsd/xen-9pfsd.h diff --git a/tools/9pfsd/Makefile b/tools/9pfsd/Makefile index 089cf5ae24..50573121ed 100644 --- a/tools/9pfsd/Makefile +++ b/tools/9pfsd/Makefile @@ -10,7 +10,7 @@ LDFLAGS += $(PTHREAD_LDFLAGS) TARGETS := xen-9pfsd -XEN-9PFSD_OBJS = xen-9pfsd.o +XEN-9PFSD_OBJS = xen-9pfsd.o io.o $(XEN-9PFSD_OBJS): CFLAGS += $(CFLAGS_libxenstore) $(XEN-9PFSD_OBJS): CFLAGS += $(CFLAGS_libxenevtchn) $(XEN-9PFSD_OBJS): CFLAGS += $(CFLAGS_libxengnttab) diff --git a/tools/9pfsd/io.c b/tools/9pfsd/io.c new file mode 100644 index 0000000000..eb7c136e09 --- /dev/null +++ b/tools/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 = 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 = false; + + return NULL; +} diff --git a/tools/9pfsd/xen-9pfsd.c b/tools/9pfsd/xen-9pfsd.c index 6939d01574..73b6c3a30e 100644 --- a/tools/9pfsd/xen-9pfsd.c +++ b/tools/9pfsd/xen-9pfsd.c @@ -24,34 +24,632 @@ #include #include +#include +#include +#include #include #include #include #include #include #include +#include #include #include #include -#include #include #include +#include "xen-9pfsd.h" + +/* + * List of currently known devices. + * The list itself is modified only in the main thread. When a device is being + * removed its memory needs to be freed after the I/O thread (if existing) + * has stopped. + */ +static XEN_TAILQ_HEAD(devhead, device) devs = 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; static void handle_stop(int sig) { stop_me = true; } +static int check_host_path(device *device) +{ + struct stat statbuf; + char *path, *p; + int ret = 1; + + if ( !device->host_path ) + return 1; + + /* Path must be absolute. */ + if ( device->host_path[0] != '/' ) + 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] == '/' ) + return 1; + + path = strdup(device->host_path); + if ( !path ) + { + syslog(LOG_CRIT, "memory allocation failure!"); + return 1; + } + + for ( p = path; p; ) + { + p = strchr(p + 1, '/'); + if ( p ) + *p = 0; + if ( !stat(path, &statbuf) ) + { + if ( !(statbuf.st_mode & S_IFDIR) ) + break; + if ( !p ) + { + ret = 0; + break; + } + *p = '/'; + continue; + } + if ( mkdir(path, 0777) ) + break; + if ( p ) + *p = '/'; + } + + 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 = 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 = strtoul(string, &end, 10); + if ( *end || val > UINT_MAX ) + val = def; + free(string); + + return val; +} + +static unsigned int read_backend_node_uint(device *device, const char *node, + unsigned int def) +{ + return uint_from_string(read_backend_node(device, node), def); +} + +static unsigned int read_frontend_node_uint(device *device, const char *node, + 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] = { + { .id = 0, .perms = XS_PERM_NONE }, + { .id = device->domid, .perms = 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ḱend node \"%s\" for device %u/%u", + node, device->domid, device->devid); + return false; + } + + old_perms = 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] = 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 = state; + + return true; +} + +static device *find_device(unsigned int domid, unsigned int devid) +{ + device *device; + + XEN_TAILQ_FOREACH( device, &devs, list ) + { + if ( domid == device->domid && devid == 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 >= 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 = calloc(1, sizeof(*device)); + if ( !device ) + { + syslog(LOG_CRIT, "Got no memory for new device %u/%u", domid, devid); + return NULL; + } + + device->domid = domid; + device->devid = devid; + device->root_fd = -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 = 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 = read_backend_node_uint(device, "max-space", 0); + device->max_files = read_backend_node_uint(device, "max-files", 0); + device->max_open_files = + read_backend_node_uint(device, "max-open-files", 0) + ?: MAX_OPEN_FILES_DEFAULT; + device->auto_delete = read_backend_node_uint(device, "auto-delete", 0); + + device->host_path = 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 = 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 = true; + pthread_cond_signal(&ring->cond); + pthread_join(ring->thread, NULL); + ring->stop_thread = false; + } + + if ( ring->data.in ) + { + xengnttab_unmap(xg, ring->data.in, 1 << ring->ring_order); + ring->data.in = NULL; + } + if ( ring->intf ) + { + xengnttab_unmap(xg, ring->intf, 1 ); + ring->intf = NULL; + } + + if ( ring->evtchn ) + { + xenevtchn_unbind(xe, ring->evtchn); + ring->evtchn = 0; + } + + pthread_mutex_destroy(&ring->mutex); + pthread_cond_destroy(&ring->cond); +} + +static void disconnect_guest(device *device) +{ + unsigned int ring_idx; + + for ( ring_idx = 0; ring_idx < device->num_rings; ring_idx++ ) + { + disconnect_ring(device->ring[ring_idx]); + free(device->ring[ring_idx]); + device->ring[ring_idx] = NULL; + } + + device->num_rings = 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 = read_frontend_node_uint(device, "version", 0); + if ( val != 1 ) + return connect_err(device, "frontend specifies illegal version"); + device->num_rings = 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 = 0; ring_idx < device->num_rings; ring_idx++ ) + { + ring = calloc(1, sizeof(*ring)); + if ( !ring ) + return connect_err(device, "could not allocate ring memory"); + device->ring[ring_idx] = ring; + ring->device = device; + pthread_cond_init(&ring->cond, NULL); + pthread_mutex_init(&ring->mutex, NULL); + + snprintf(node, sizeof(node), "event-channel-%u", ring_idx); + val = read_frontend_node_uint(device, node, 0); + if ( val == 0 ) + return connect_err(device, "frontend specifies illegal evtchn"); + evtchn = xenevtchn_bind_interdomain(xe, device->domid, val); + if ( evtchn < 0 ) + return connect_err(device, "could not bind to event channel"); + ring->evtchn = evtchn; + + snprintf(node, sizeof(node), "ring-ref%u", ring_idx); + val = read_frontend_node_uint(device, node, 0); + if ( val == 0 ) + return connect_err(device, + "frontend specifies illegal grant for ring"); + ring->intf = 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 = ring->intf->ring_order; + if ( ring->ring_order > MAX_RING_ORDER || ring->ring_order < 1 ) + return connect_err(device, "frontend specifies illegal ring order"); + ring->ring_size = XEN_FLEX_RING_SIZE(ring->ring_order); + ring->data.in = xengnttab_map_domain_grant_refs(xg, + 1 << ring->ring_order, + device->domid, + ring->intf->ref, + PROT_READ | PROT_WRITE); + if ( !ring->data.in ) + return connect_err(device, "could not map ring pages"); + ring->data.out = 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 = 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 = xs_read(xs, XBT_NULL, p.path, &len); + if ( !state ) + { + close_device(device, XenbusStateClosed); + return; + } + + new_state = 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 = XenbusStateUnknown; + } + free(state); + + if ( new_state == 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 = new_state; +} + +static void check_device(unsigned int domid, unsigned int devid) +{ + device *device; + + device = find_device(domid, devid); + if ( !device ) + { + device = new_device(domid, devid); + if ( !device ) + return; + } + + device->last_seen = 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 = xs_directory(xs, XBT_NULL, "backend/xen_9pfs", &n_doms); + if ( doms == NULL ) + return; + + for ( dom = 0; dom < n_doms; dom++ ) + { + errno = 0; + domid = strtoul(doms[dom], &end, 10); + if ( errno || *end || domid >= DOMID_FIRST_RESERVED ) + continue; + + snprintf(dom_path, sizeof(dom_path), "backend/xen_9pfs/%lu", domid); + devices = xs_directory(xs, XBT_NULL, dom_path, &n_devs); + + for ( dev = 0; dev < n_devs; dev++ ) + { + errno = 0; + devid = 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 != 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) != 2 ) + { + syslog(LOG_WARNING, "unknown watch event %s %s", path, token); + return; + } + + device = 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); } +static void handle_event(void) +{ + xenevtchn_port_or_error_t evtchn; + device *device; + struct ring *ring; + unsigned int ring_idx; + + evtchn = xenevtchn_pending(xe); + if ( evtchn < 0 ) + do_err("xenevtchn_pending() failed"); + + XEN_TAILQ_FOREACH( device, &devs, list ) + { + for ( ring_idx = 0; ring_idx < device->num_rings; ring_idx++ ) + { + ring = device->ring[ring_idx]; + if ( ring && ring->evtchn == 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 = 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] = { + { .events = POLLIN }, + { .events = POLLIN } + }; umask(027); if ( getenv("XEN_9PFSD_VERBOSE") ) @@ -136,9 +766,26 @@ int main(int argc, char *argv[]) xen_connect(); + if ( !xs_watch(xs, "backend/xen_9pfs", "main") ) + do_err("xs_watch() in main thread failed"); + p[0].fd = xs_fileno(xs); + p[1].fd = xenevtchn_fd(xe); + + scan_backend(); + while ( !stop_me ) { - sleep(60); + while ( (p[0].revents & POLLIN) && + (watch = xs_check_watch(xs)) != NULL ) + { + handle_watch(watch[XS_WATCH_PATH], watch[XS_WATCH_TOKEN]); + free(watch); + } + + if ( p[1].revents & POLLIN ) + handle_event(); + + poll(p, 2, -1); } close_all(); diff --git a/tools/9pfsd/xen-9pfsd.h b/tools/9pfsd/xen-9pfsd.h new file mode 100644 index 0000000000..ff3562164a --- /dev/null +++ b/tools/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 */ From patchwork Thu Feb 15 13:04:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?SsO8cmdlbiBHcm/Dnw==?= X-Patchwork-Id: 13558351 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id BC793C48BEB for ; Thu, 15 Feb 2024 13:05:38 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.681683.1060567 (Exim 4.92) (envelope-from ) id 1rabQg-0003br-Py; Thu, 15 Feb 2024 13:05:30 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 681683.1060567; Thu, 15 Feb 2024 13:05: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 1rabQg-0003bk-Mi; Thu, 15 Feb 2024 13:05:30 +0000 Received: by outflank-mailman (input) for mailman id 681683; Thu, 15 Feb 2024 13:05: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 1rabQf-0002yD-HA for xen-devel@lists.xenproject.org; Thu, 15 Feb 2024 13:05:29 +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 e44470ff-cc02-11ee-8a4d-1f161083a0e0; Thu, 15 Feb 2024 14:05:28 +0100 (CET) Received: from imap2.dmz-prg2.suse.org (imap2.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:98]) (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 67D451F8A6; Thu, 15 Feb 2024 13:05:28 +0000 (UTC) Received: from imap2.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 imap2.dmz-prg2.suse.org (Postfix) with ESMTPS id 386FC139D0; Thu, 15 Feb 2024 13:05:28 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap2.dmz-prg2.suse.org with ESMTPSA id vCNYDBgMzmV6FQAAn2gu4w (envelope-from ); Thu, 15 Feb 2024 13:05:28 +0000 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: e44470ff-cc02-11ee-8a4d-1f161083a0e0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1708002328; 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=1Cx2zmy0kYHTdVFW0XAu4VXbYGYjbC4IGhNjDXCFbLc=; b=OQSbNEU7Smow+Yd1EQEszr2VrY9Vusv4XxaYHbjA3SzJadL5FLQvcCIAp9k3FceLAWvV1y 8ARNu+dl5xtlMsuMlSQVspJFWhbnNx+h44zufWFebqnNUVPZdLirUt5Y7aOzxi3t0Ncd2h FX0d2znM1/p2wGOY5Yp6Z3JFBKyAgxs= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1708002328; 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=1Cx2zmy0kYHTdVFW0XAu4VXbYGYjbC4IGhNjDXCFbLc=; b=OQSbNEU7Smow+Yd1EQEszr2VrY9Vusv4XxaYHbjA3SzJadL5FLQvcCIAp9k3FceLAWvV1y 8ARNu+dl5xtlMsuMlSQVspJFWhbnNx+h44zufWFebqnNUVPZdLirUt5Y7aOzxi3t0Ncd2h FX0d2znM1/p2wGOY5Yp6Z3JFBKyAgxs= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Anthony PERARD , Jason Andryuk Subject: [PATCH v7 03/21] tools/xen-9pfsd: add transport layer Date: Thu, 15 Feb 2024 14:04:51 +0100 Message-Id: <20240215130509.24008-4-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240215130509.24008-1-jgross@suse.com> References: <20240215130509.24008-1-jgross@suse.com> MIME-Version: 1.0 X-Spamd-Bar: / Authentication-Results: smtp-out2.suse.de; dkim=pass header.d=suse.com header.s=susede1 header.b=OQSbNEU7 X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Spamd-Result: default: False [0.49 / 50.00]; RCVD_VIA_SMTP_AUTH(0.00)[]; SPAMHAUS_XBL(0.00)[2a07:de40:b281:104:10:150:64:98:from]; TO_DN_SOME(0.00)[]; R_MISSING_CHARSET(2.50)[]; BROKEN_CONTENT_TYPE(1.50)[]; RCPT_COUNT_FIVE(0.00)[5]; RCVD_COUNT_THREE(0.00)[3]; DKIM_TRACE(0.00)[suse.com:+]; MX_GOOD(-0.01)[]; NEURAL_HAM_SHORT(-0.20)[-1.000]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; BAYES_HAM(-3.00)[100.00%]; ARC_NA(0.00)[]; R_DKIM_ALLOW(-0.20)[suse.com:s=susede1]; FROM_HAS_DN(0.00)[]; FREEMAIL_ENVRCPT(0.00)[gmail.com]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; NEURAL_HAM_LONG(-1.00)[-1.000]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; MID_CONTAINS_FROM(1.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.com:dkim,suse.com:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; FREEMAIL_CC(0.00)[suse.com,xen.org,citrix.com,gmail.com]; RCVD_TLS_ALL(0.00)[] X-Rspamd-Queue-Id: 67D451F8A6 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/9pfsd/io.c | 143 +++++++++++++++++++++++++++++++++++++++- tools/9pfsd/xen-9pfsd.h | 16 +++++ 2 files changed, 156 insertions(+), 3 deletions(-) diff --git a/tools/9pfsd/io.c b/tools/9pfsd/io.c index eb7c136e09..4312a62dfe 100644 --- a/tools/9pfsd/io.c +++ b/tools/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. */ #include +#include #include #include +#include /* For cpu barriers. */ +#include #include "xen-9pfsd.h" +/* + * 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 frontend, + * 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 = 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 = 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 = ring_out_data(ring); + RING_IDX prod, cons; + + size = min(total_len - off, out_data); + prod = xen_9pfs_mask(ring->intf->out_prod, ring->ring_size); + cons = 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 += size; + ring->intf->out_cons = 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 = ring_in_free(ring); + RING_IDX prod, cons; + + size = min(total_len - off, in_data); + prod = xen_9pfs_mask(ring->prod_pvt_in, ring->ring_size); + cons = 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 += size; + ring->intf->in_prod = 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); } void *io_thread(void *arg) { struct ring *ring = arg; + unsigned int count = 0; + struct p9_header hdr; + bool in_hdr = true; + + ring->max_size = ring->ring_size; + ring->buffer = malloc(ring->max_size); + if ( !ring->buffer ) + { + syslog(LOG_CRIT, "memory allocation failure!"); + return NULL; + } 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); - /* TODO: I/O handling. */ + if ( ring->stop_thread || ring->error ) + continue; + + if ( !ring->handle_response ) + { + if ( in_hdr ) + { + count += get_request_bytes(ring, count, sizeof(hdr)); + if ( count != sizeof(hdr) ) + continue; + hdr = *(struct p9_header *)ring->buffer; + if ( hdr.size > ring->max_size || hdr.size < sizeof(hdr) ) + { + syslog(LOG_ERR, "%u.%u specified illegal request length %u", + ring->device->domid, ring->device->devid, hdr.size); + ring->error = true; + continue; + } + in_hdr = false; + } + + count += get_request_bytes(ring, count, hdr.size); + if ( count < hdr.size ) + continue; + + /* TODO: handle request (will rewrite hdr.size). */ + + ring->handle_response = true; + hdr.size = ((struct p9_header *)ring->buffer)->size; + count = 0; + } + + if ( ring->handle_response ) + { + count += put_response_bytes(ring, count, hdr.size); + + if ( count == hdr.size ) + { + /* Signal presence of response. */ + xenevtchn_notify(xe, ring->evtchn); + + ring->handle_response = false; + in_hdr = true; + count = 0; + } + } } + free(ring->buffer); + ring->thread_active = false; return NULL; diff --git a/tools/9pfsd/xen-9pfsd.h b/tools/9pfsd/xen-9pfsd.h index ff3562164a..d587f59a32 100644 --- a/tools/9pfsd/xen-9pfsd.h +++ b/tools/9pfsd/xen-9pfsd.h @@ -15,6 +15,12 @@ #define MAX_RING_ORDER 9 #define MAX_OPEN_FILES_DEFAULT 5 +struct p9_header { + uint32_t size; + uint8_t cmd; + uint16_t tag; +} __attribute__((packed)); + typedef struct device device; 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. */ }; struct device { From patchwork Thu Feb 15 13:04:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?SsO8cmdlbiBHcm/Dnw==?= X-Patchwork-Id: 13558352 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 02CC8C48BC4 for ; Thu, 15 Feb 2024 13:05:43 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.681686.1060577 (Exim 4.92) (envelope-from ) id 1rabQn-0003zP-7G; Thu, 15 Feb 2024 13:05:37 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 681686.1060577; Thu, 15 Feb 2024 13:05:37 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rabQn-0003zF-4P; Thu, 15 Feb 2024 13:05:37 +0000 Received: by outflank-mailman (input) for mailman id 681686; Thu, 15 Feb 2024 13:05:36 +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 1rabQm-0002j3-A4 for xen-devel@lists.xenproject.org; Thu, 15 Feb 2024 13:05:36 +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 e793b404-cc02-11ee-98f5-efadbce2ee36; Thu, 15 Feb 2024 14:05:34 +0100 (CET) Received: from imap2.dmz-prg2.suse.org (imap2.dmz-prg2.suse.org [10.150.64.98]) (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 1281521FBC; Thu, 15 Feb 2024 13:05:34 +0000 (UTC) Received: from imap2.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 imap2.dmz-prg2.suse.org (Postfix) with ESMTPS id D09C4139D0; Thu, 15 Feb 2024 13:05:33 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap2.dmz-prg2.suse.org with ESMTPSA id ONtNMR0MzmV9FQAAn2gu4w (envelope-from ); Thu, 15 Feb 2024 13:05:33 +0000 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: e793b404-cc02-11ee-98f5-efadbce2ee36 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1708002334; 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=O73f+E3GNfH4W5rlXCuJYVhh6QCuB0n/PfhAGghm1+4=; b=Q063CRzUshxKsyPLO69hrUAcvSURwusl0CX0OnRdG1Ei5qcVv6sx+wVfn99iTumv4bQVTq vzVquLerBUSriWpgiUkp21Gx50VRzujHIAHNgUTt+Mp+aFnxZ6rXBhANK2DC0yFWXzN3K5 +Pqc+fUSwZywfZKYEFhAYvpDS96gtQs= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1708002334; 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=O73f+E3GNfH4W5rlXCuJYVhh6QCuB0n/PfhAGghm1+4=; b=Q063CRzUshxKsyPLO69hrUAcvSURwusl0CX0OnRdG1Ei5qcVv6sx+wVfn99iTumv4bQVTq vzVquLerBUSriWpgiUkp21Gx50VRzujHIAHNgUTt+Mp+aFnxZ6rXBhANK2DC0yFWXzN3K5 +Pqc+fUSwZywfZKYEFhAYvpDS96gtQs= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Anthony PERARD , Jason Andryuk Subject: [PATCH v7 04/21] tools/xen-9pfsd: add 9pfs response generation support Date: Thu, 15 Feb 2024 14:04:52 +0100 Message-Id: <20240215130509.24008-5-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240215130509.24008-1-jgross@suse.com> References: <20240215130509.24008-1-jgross@suse.com> MIME-Version: 1.0 Authentication-Results: smtp-out1.suse.de; none X-Spamd-Result: default: False [1.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)[]; 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%] 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/9pfsd/io.c | 217 +++++++++++++++++++++++++++++++++++++++- tools/9pfsd/xen-9pfsd.h | 3 + 2 files changed, 219 insertions(+), 1 deletion(-) diff --git a/tools/9pfsd/io.c b/tools/9pfsd/io.c index 4312a62dfe..4a44c70c4d 100644 --- a/tools/9pfsd/io.c +++ b/tools/9pfsd/io.c @@ -11,6 +11,7 @@ * before looking for the next request. */ +#include #include #include #include @@ -20,6 +21,16 @@ #include "xen-9pfsd.h" +/* 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 frontend, @@ -100,6 +111,200 @@ static bool io_work_pending(struct ring *ring) return ring->handle_response ? ring_in_free(ring) : ring_out_data(ring); } +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 elements) + * 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 the 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, then 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 = 0; + unsigned int elem_sz = 0; + + for ( f = fmt; *f; f++ ) + { + if ( !array_sz ) + par = va_arg(ap, const void *); + else + { + par += elem_sz; + array_sz--; + } + + switch ( *f ) + { + case 'a': + f++; + if ( !*f || array_sz ) + fmt_err(fmt); + array_sz = *(const unsigned int *)par; + if ( array_sz > 0xffff ) + { + syslog(LOG_CRIT, "array size %u in fill_buffer()", array_sz); + exit(1); + } + put_unaligned(array_sz, (uint16_t *)*data); + *data += sizeof(uint16_t); + par = va_arg(ap, const void *); + elem_sz = 0; + break; + + case 'b': + put_unaligned(*(const uint8_t *)par, (uint8_t *)*data); + elem_sz = sizeof(uint8_t); + *data += sizeof(uint8_t); + break; + + case 'u': + put_unaligned(*(const uint16_t *)par, (uint16_t *)*data); + elem_sz = sizeof(uint16_t); + *data += sizeof(uint16_t); + break; + + case 'D': + if ( array_sz ) + fmt_err(fmt); + len = *(const unsigned int *)par; + put_unaligned(len, (uint32_t *)*data); + *data += sizeof(uint32_t); + par = va_arg(ap, const void *); + if ( *data != par ) + memcpy(*data, par, len); + *data += len; + break; + + case 'L': + put_unaligned(*(const uint64_t *)par, (uint64_t *)*data); + elem_sz = sizeof(uint64_t); + *data += sizeof(uint64_t); + break; + + case 'Q': + qid = par; + elem_sz = sizeof(*qid); + fill_buffer_at(data, "bUL", &qid->type, &qid->version, &qid->path); + break; + + case 'S': + str_val = par; + elem_sz = sizeof(str_val); + len = 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 += sizeof(uint16_t); + memcpy(*data, str_val, len); + *data += len; + break; + + case 'U': + put_unaligned(*(const uint32_t *)par, (uint32_t *)*data); + elem_sz = sizeof(uint32_t); + *data += 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 = ring->buffer; + void *data = hdr + 1; + va_list ap; + + hdr->cmd = cmd; + hdr->tag = tag; + + va_start(ap, fmt); + vfill_buffer_at(&data, fmt, ap); + va_end(ap); + + hdr->size = 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 = realloc(ring->str, ring->str_used + len + 1); + if ( !tmp ) + return ~0; + ring->str = tmp; + ring->str_size = ring->str_used + len + 1; + } + + ret = ring->str_used; + memcpy(ring->str + ret, str, len); + ring->str_used += len; + ring->str[ring->str_used++] = 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 = add_string(ring, ring->buffer, strlen(ring->buffer)); + fill_buffer(ring, P9_CMD_ERROR, tag, "SU", + erroff != ~0 ? ring->str + erroff : "cannot allocate memory", + &err); +} + void *io_thread(void *arg) { struct ring *ring = arg; @@ -151,7 +356,16 @@ void *io_thread(void *arg) if ( count < hdr.size ) continue; - /* TODO: handle request (will rewrite hdr.size). */ + ring->str_used = 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; + } ring->handle_response = true; hdr.size = ((struct p9_header *)ring->buffer)->size; @@ -174,6 +388,7 @@ void *io_thread(void *arg) } } + free(ring->str); free(ring->buffer); ring->thread_active = false; diff --git a/tools/9pfsd/xen-9pfsd.h b/tools/9pfsd/xen-9pfsd.h index d587f59a32..0cde0d2bb8 100644 --- a/tools/9pfsd/xen-9pfsd.h +++ b/tools/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. */ }; struct device { From patchwork Thu Feb 15 13:04:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?SsO8cmdlbiBHcm/Dnw==?= X-Patchwork-Id: 13558353 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5E585C48BC4 for ; Thu, 15 Feb 2024 13:05:49 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.681688.1060587 (Exim 4.92) (envelope-from ) id 1rabQs-0004OO-HB; Thu, 15 Feb 2024 13:05:42 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 681688.1060587; Thu, 15 Feb 2024 13:05:42 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rabQs-0004OC-DS; Thu, 15 Feb 2024 13:05:42 +0000 Received: by outflank-mailman (input) for mailman id 681688; Thu, 15 Feb 2024 13:05:40 +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 1rabQq-0002yD-QN for xen-devel@lists.xenproject.org; Thu, 15 Feb 2024 13:05:40 +0000 Received: from smtp-out1.suse.de (smtp-out1.suse.de [2a07:de40:b251:101:10:150:64:1]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id eafd7db8-cc02-11ee-8a4d-1f161083a0e0; Thu, 15 Feb 2024 14:05:40 +0100 (CET) Received: from imap2.dmz-prg2.suse.org (imap2.dmz-prg2.suse.org [10.150.64.98]) (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 B6B9222031; Thu, 15 Feb 2024 13:05:39 +0000 (UTC) Received: from imap2.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 imap2.dmz-prg2.suse.org (Postfix) with ESMTPS id 7FAD4139D0; Thu, 15 Feb 2024 13:05:39 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap2.dmz-prg2.suse.org with ESMTPSA id reBzHSMMzmWNFQAAn2gu4w (envelope-from ); Thu, 15 Feb 2024 13:05:39 +0000 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: eafd7db8-cc02-11ee-8a4d-1f161083a0e0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1708002339; 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=Ep5GCYtOAcPi9Z1A4O1nBYAfiV8kAZfwfen9awb2d94=; b=SGwNfKu2eT+wcBk3tiUVz3WPOmLp2PjVIuZ2y/oT/YC7y0811+wVrgYlkj6upmuz8i3JGA dytxKOyt3gi9MjI3jhRICF7d8tN2/Gv3ZV4EmlBFyz73ypRUWGAo3lLHSy2+IPpsU0BZu9 /8gOIf2E4rWtVJ4xeSY/cxtXsU3m430= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1708002339; 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=Ep5GCYtOAcPi9Z1A4O1nBYAfiV8kAZfwfen9awb2d94=; b=SGwNfKu2eT+wcBk3tiUVz3WPOmLp2PjVIuZ2y/oT/YC7y0811+wVrgYlkj6upmuz8i3JGA dytxKOyt3gi9MjI3jhRICF7d8tN2/Gv3ZV4EmlBFyz73ypRUWGAo3lLHSy2+IPpsU0BZu9 /8gOIf2E4rWtVJ4xeSY/cxtXsU3m430= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Anthony PERARD , Jason Andryuk Subject: [PATCH v7 05/21] tools/xen-9pfsd: add 9pfs version request support Date: Thu, 15 Feb 2024 14:04:53 +0100 Message-Id: <20240215130509.24008-6-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240215130509.24008-1-jgross@suse.com> References: <20240215130509.24008-1-jgross@suse.com> MIME-Version: 1.0 Authentication-Results: smtp-out1.suse.de; none X-Spamd-Result: default: False [0.70 / 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)[]; 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%] 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/9pfsd/io.c | 201 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 201 insertions(+) diff --git a/tools/9pfsd/io.c b/tools/9pfsd/io.c index 4a44c70c4d..839dd1112c 100644 --- a/tools/9pfsd/io.c +++ b/tools/9pfsd/io.c @@ -22,8 +22,12 @@ #include "xen-9pfsd.h" /* P9 protocol commands (response is either cmd+1 or P9_CMD_ERROR). */ +#define P9_CMD_VERSION 100 #define P9_CMD_ERROR 107 +#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, const char *str, return ret; } +static bool chk_data(struct ring *ring, void *data, unsigned int len) +{ + struct p9_header *hdr = ring->buffer; + + if ( data + len <= ring->buffer + hdr->size ) + return true; + + errno = E2BIG; + + return false; +} + +static bool fill_data_elem(void **par, void **array, unsigned int *array_sz, + unsigned int elem_sz, void *data) +{ + if ( *array_sz && !*array ) + { + *array = calloc(*array_sz, elem_sz); + if ( !*array ) + return false; + *par = *array; + } + + memcpy(*par, data, elem_sz); + + if ( *array_sz ) + { + *par += elem_sz; + *array_sz -= 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 elements) + * 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 the 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, then 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 stored 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 = ring->buffer; + void *data = hdr + 1; + void *par; + unsigned int pars = 0; + const char *f; + va_list ap; + unsigned int len; + unsigned int str_off; + unsigned int array_sz = 0; + void **array = NULL; + + va_start(ap, fmt); + + for ( f = fmt; *f; f++ ) + { + if ( !array_sz ) + par = 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 = get_unaligned((uint16_t *)data); + data += sizeof(uint16_t); + *(unsigned int *)par = array_sz; + array = va_arg(ap, void **); + *array = 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 += sizeof(uint8_t); + break; + + case 'D': + if ( array_sz ) + fmt_err(fmt); + if ( !chk_data(ring, data, sizeof(uint32_t)) ) + return pars; + len = get_unaligned((uint32_t *)data); + data += sizeof(uint32_t); + *(unsigned int *)par = len; + par = va_arg(ap, void *); + if ( !chk_data(ring, data, len) ) + return pars; + memcpy(par, data, len); + data += 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 += sizeof(uint64_t); + break; + + case 'S': + if ( !chk_data(ring, data, sizeof(uint16_t)) ) + return pars; + len = get_unaligned((uint16_t *)data); + data += sizeof(uint16_t); + if ( !chk_data(ring, data, len) ) + return pars; + str_off = add_string(ring, data, len); + if ( str_off == ~0 ) + return pars; + if ( !fill_data_elem(&par, array, &array_sz, sizeof(unsigned int), + &str_off) ) + return pars; + data += 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 += 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); } +static void p9_version(struct ring *ring, struct p9_header *hdr) +{ + uint32_t max_size; + unsigned int off; + char *version; + int ret; + + ret = fill_data(ring, "US", &max_size, &off); + if ( ret != 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 = max_size; + + version = ring->str + off; + if ( strcmp(version, P9_VERSION) ) + version = "unknown"; + + fill_buffer(ring, hdr->cmd + 1, hdr->tag, "US", &ring->max_size, version); +} + void *io_thread(void *arg) { struct ring *ring = arg; @@ -360,6 +557,10 @@ void *io_thread(void *arg) 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); From patchwork Thu Feb 15 13:04:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?SsO8cmdlbiBHcm/Dnw==?= X-Patchwork-Id: 13558354 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 8A1C9C48BC4 for ; Thu, 15 Feb 2024 13:05:54 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.681689.1060597 (Exim 4.92) (envelope-from ) id 1rabQx-0004o8-OB; Thu, 15 Feb 2024 13:05:47 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 681689.1060597; Thu, 15 Feb 2024 13:05:47 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rabQx-0004nz-Kj; Thu, 15 Feb 2024 13:05:47 +0000 Received: by outflank-mailman (input) for mailman id 681689; Thu, 15 Feb 2024 13:05:46 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rabQw-0002yD-Di for xen-devel@lists.xenproject.org; Thu, 15 Feb 2024 13:05:46 +0000 Received: from smtp-out1.suse.de (smtp-out1.suse.de [2a07:de40:b251:101:10:150:64:1]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id ee5ab304-cc02-11ee-8a4d-1f161083a0e0; Thu, 15 Feb 2024 14:05:45 +0100 (CET) Received: from imap2.dmz-prg2.suse.org (imap2.dmz-prg2.suse.org [10.150.64.98]) (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 58A2022031; Thu, 15 Feb 2024 13:05:45 +0000 (UTC) Received: from imap2.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 imap2.dmz-prg2.suse.org (Postfix) with ESMTPS id 277AC139D0; Thu, 15 Feb 2024 13:05:45 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap2.dmz-prg2.suse.org with ESMTPSA id 0kcxCCkMzmWSFQAAn2gu4w (envelope-from ); Thu, 15 Feb 2024 13:05:45 +0000 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: ee5ab304-cc02-11ee-8a4d-1f161083a0e0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1708002345; 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=L9NcHDZsirisD0yciG+rBpMttYLBTYJ34tUyYEKGqh8=; b=Fa3l8KpEg+ehmFbS58CxlBh61ofDZoNquqBKccQwvm/ccCfzmOK5QDkMHUYW3+RT58RvmB FVejcuUkGK6+yvW12CshYcpvrZRJ1V7IgC9drPnC396TW5sYAKN1wH94WGvx7nnxwyvCBc Y6mCtYZR+rPH2YOyCIimXV1E6ZXlSt4= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1708002345; 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=L9NcHDZsirisD0yciG+rBpMttYLBTYJ34tUyYEKGqh8=; b=Fa3l8KpEg+ehmFbS58CxlBh61ofDZoNquqBKccQwvm/ccCfzmOK5QDkMHUYW3+RT58RvmB FVejcuUkGK6+yvW12CshYcpvrZRJ1V7IgC9drPnC396TW5sYAKN1wH94WGvx7nnxwyvCBc Y6mCtYZR+rPH2YOyCIimXV1E6ZXlSt4= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Anthony PERARD , Jason Andryuk Subject: [PATCH v7 06/21] tools/xen-9pfsd: add 9pfs attach request support Date: Thu, 15 Feb 2024 14:04:54 +0100 Message-Id: <20240215130509.24008-7-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240215130509.24008-1-jgross@suse.com> References: <20240215130509.24008-1-jgross@suse.com> MIME-Version: 1.0 Authentication-Results: smtp-out1.suse.de; none X-Spamd-Result: default: False [1.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)[]; 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%] 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) V7: - use EBADF instead of EBADFD (Andrew Cooper) - use strcpy() instead of strncpy() (Andrew Cooper) --- tools/9pfsd/io.c | 162 ++++++++++++++++++++++++++++++++++++++++ tools/9pfsd/xen-9pfsd.c | 6 ++ tools/9pfsd/xen-9pfsd.h | 14 ++++ 3 files changed, 182 insertions(+) diff --git a/tools/9pfsd/io.c b/tools/9pfsd/io.c index 839dd1112c..4c422b06ac 100644 --- a/tools/9pfsd/io.c +++ b/tools/9pfsd/io.c @@ -11,11 +11,14 @@ * before looking for the next request. */ +#include #include #include #include #include #include +#include +#include #include /* For cpu barriers. */ #include @@ -23,6 +26,7 @@ /* 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 #define P9_MIN_MSIZE 2048 @@ -461,6 +465,124 @@ static int fill_data(struct ring *ring, const char *fmt, ...) return pars; } +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 == fid ) + return fidp; + } + + return NULL; +} + +static struct p9_fid *alloc_fid_mem(device *device, unsigned int fid, + const char *path) +{ + struct p9_fid *fidp; + + fidp = calloc(sizeof(*fidp) + strlen(path) + 1, 1); + if ( !fidp ) + return NULL; + + fidp->fid = fid; + strcpy(fidp->path, path); + + return fidp; +} + +static struct p9_fid *alloc_fid(device *device, unsigned int fid, + const char *path) +{ + struct p9_fid *fidp = NULL; + + pthread_mutex_lock(&device->fid_mutex); + + if ( find_fid(device, fid) ) + { + errno = EBADF; + goto out; + } + + if ( device->n_fids >= device->max_open_files ) + { + errno = EMFILE; + goto out; + } + + fidp = alloc_fid_mem(device, fid, path); + if ( !fidp ) + goto out; + + fidp->ref = 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 = XEN_TAILQ_FIRST(&device->fids)) != 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] == '/') ? 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 = &st; + } + + qid->type = S_ISDIR(stbuf->st_mode) ? QID_TYPE_DIR : 0; + qid->version = stbuf->st_mtime ^ (stbuf->st_size << 8); + qid->path = stbuf->st_ino; + + return 0; +} + static void p9_error(struct ring *ring, uint16_t tag, uint32_t err) { unsigned int erroff; @@ -502,6 +624,42 @@ static void p9_version(struct ring *ring, struct p9_header *hdr) fill_buffer(ring, hdr->cmd + 1, hdr->tag, "US", &ring->max_size, version); } +static void p9_attach(struct ring *ring, struct p9_header *hdr) +{ + device *device = ring->device; + uint32_t fid; + uint32_t dummy_u32; + unsigned int dummy_uint; + struct p9_qid qid; + int ret; + + ret = fill_data(ring, "UUSSU", &fid, &dummy_u32, &dummy_uint, &dummy_uint, + &dummy_u32); + if ( ret != 5 ) + { + p9_error(ring, hdr->tag, errno); + return; + } + + device->root_fid = alloc_fid(device, fid, relpath_from_path("/")); + if ( !device->root_fid ) + { + p9_error(ring, hdr->tag, errno); + return; + } + + ret = fill_qid(device, device->root_fid->path, &qid, NULL); + if ( ret ) + { + free_fid(device, device->root_fid); + device->root_fid = 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 = arg; @@ -561,6 +719,10 @@ void *io_thread(void *arg) p9_version(ring, &hdr); break; + 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/9pfsd/xen-9pfsd.c b/tools/9pfsd/xen-9pfsd.c index 73b6c3a30e..b83b896bcc 100644 --- a/tools/9pfsd/xen-9pfsd.c +++ b/tools/9pfsd/xen-9pfsd.c @@ -304,6 +304,9 @@ static device *new_device(unsigned int domid, unsigned int devid) return NULL; } + pthread_mutex_init(&device->fid_mutex, NULL); + XEN_TAILQ_INIT(&device->fids); + val = read_backend_node(device, "security_model"); if ( !val || strcmp(val, "none") ) { @@ -399,6 +402,8 @@ static void disconnect_guest(device *device) } device->num_rings = 0; + + free_fids(device); } 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); disconnect_guest(device); + pthread_mutex_destroy(&device->fid_mutex); free_device(device); } diff --git a/tools/9pfsd/xen-9pfsd.h b/tools/9pfsd/xen-9pfsd.h index 0cde0d2bb8..6c755411a7 100644 --- a/tools/9pfsd/xen-9pfsd.h +++ b/tools/9pfsd/xen-9pfsd.h @@ -21,6 +21,13 @@ struct p9_header { uint16_t tag; } __attribute__((packed)); +struct p9_fid { + XEN_TAILQ_ENTRY(struct p9_fid) list; + unsigned int fid; + unsigned int ref; + char path[]; +}; + typedef struct device device; 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; }; extern xenevtchn_handle *xe; void *io_thread(void *arg); +void free_fids(device *device); #endif /* XEN_9PFSD_H */ From patchwork Thu Feb 15 13:04:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?SsO8cmdlbiBHcm/Dnw==?= X-Patchwork-Id: 13558355 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 13AEAC48BC4 for ; Thu, 15 Feb 2024 13:05:59 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.681694.1060607 (Exim 4.92) (envelope-from ) id 1rabR3-0005Lb-4C; Thu, 15 Feb 2024 13:05:53 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 681694.1060607; Thu, 15 Feb 2024 13:05:53 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rabR3-0005LM-0h; Thu, 15 Feb 2024 13:05:53 +0000 Received: by outflank-mailman (input) for mailman id 681694; Thu, 15 Feb 2024 13:05:52 +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 1rabR2-0002yD-0A for xen-devel@lists.xenproject.org; Thu, 15 Feb 2024 13:05:52 +0000 Received: from smtp-out1.suse.de (smtp-out1.suse.de [2a07:de40:b251:101:10:150:64:1]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id f1a94555-cc02-11ee-8a4d-1f161083a0e0; Thu, 15 Feb 2024 14:05:51 +0100 (CET) Received: from imap2.dmz-prg2.suse.org (imap2.dmz-prg2.suse.org [10.150.64.98]) (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 E383121FBC; Thu, 15 Feb 2024 13:05:50 +0000 (UTC) Received: from imap2.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 imap2.dmz-prg2.suse.org (Postfix) with ESMTPS id B4694139D0; Thu, 15 Feb 2024 13:05:50 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap2.dmz-prg2.suse.org with ESMTPSA id GK6mKi4MzmWYFQAAn2gu4w (envelope-from ); Thu, 15 Feb 2024 13:05:50 +0000 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: f1a94555-cc02-11ee-8a4d-1f161083a0e0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1708002351; 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=MIRj03S7dyhfHn0FgSCrUIpTTvYsmpq2WPHIZTrX2Ro=; b=JhZ2inOVsD0KKdqDQliC3jPTwlHBgjDRzQalSNDG3gqKW5Q6R26jUUZVFLQ5pqbXwdiHfK BTvqrgD6i1KHjm86lpERE15Q6Fqv9E9BiAOCkqbC9SxDp6ImSFyhyLkpCMOqqOKIdk9wP4 Dv2pnilOHwFlDa5R6g2MOaW+keCldiM= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1708002350; 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=MIRj03S7dyhfHn0FgSCrUIpTTvYsmpq2WPHIZTrX2Ro=; b=WnfwcAXDczwd+79EjnXDrxmXaMvxJ/pktlxFfZXvjcJZGcWg8A7K8r3I2pB2NSJIquVaUw rk2b/fIjqiGu860G15Kr8djXS4xmqUVpfsEKQL/1bXfTpiCPE0LV6qXbFg/s8a+Pt7GKLI SjTeh+Z1d6r/W/DkWyrTMvyjSkMTJ04= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Anthony PERARD , Jason Andryuk Subject: [PATCH v7 07/21] tools/xen-9pfsd: add 9pfs walk request support Date: Thu, 15 Feb 2024 14:04:55 +0100 Message-Id: <20240215130509.24008-8-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240215130509.24008-1-jgross@suse.com> References: <20240215130509.24008-1-jgross@suse.com> MIME-Version: 1.0 Authentication-Results: smtp-out1.suse.de; none X-Spamd-Result: default: False [1.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)[]; 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%] 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 V6: - use EBADF instead of EBADFD (Andrew Cooper) - use strncpy() with strlen() + 1 (Andrew Cooper) V7: - undo V6 changes as they were in wrong patch --- tools/9pfsd/io.c | 171 ++++++++++++++++++++++++++++++++++++++++ tools/9pfsd/xen-9pfsd.h | 1 + 2 files changed, 172 insertions(+) diff --git a/tools/9pfsd/io.c b/tools/9pfsd/io.c index 4c422b06ac..731fbd1ad7 100644 --- a/tools/9pfsd/io.c +++ b/tools/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 #define P9_MIN_MSIZE 2048 #define P9_VERSION "9P2000.u" +#define P9_WALK_MAXELEM 16 struct p9_qid { uint8_t type; @@ -478,6 +480,21 @@ static struct p9_fid *find_fid(device *device, unsigned int fid) return NULL; } +static struct p9_fid *get_fid_ref(device *device, unsigned int fid) +{ + struct p9_fid *fidp; + + pthread_mutex_lock(&device->fid_mutex); + + fidp = 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) { @@ -576,6 +593,10 @@ static int fill_qid(device *device, const char *path, struct p9_qid *qid, stbuf = &st; } + /* Don't allow symbolic links. */ + if ( S_ISLNK(stbuf->st_mode) ) + return EMLINK; + qid->type = S_ISDIR(stbuf->st_mode) ? QID_TYPE_DIR : 0; qid->version = stbuf->st_mtime ^ (stbuf->st_size << 8); qid->path = stbuf->st_ino; @@ -583,6 +604,20 @@ static int fill_qid(device *device, const char *path, struct p9_qid *qid, return 0; } +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; @@ -660,6 +695,138 @@ static void p9_attach(struct ring *ring, struct p9_header *hdr) fill_buffer(ring, hdr->cmd + 1, hdr->tag, "Q", &qid); } +static void p9_walk(struct ring *ring, struct p9_header *hdr) +{ + device *device = ring->device; + uint32_t fid; + uint32_t newfid; + struct p9_fid *fidp = NULL; + struct p9_qid *qids = NULL; + unsigned int n_names = 0; + unsigned int *names = NULL; + unsigned int walked = 0; + unsigned int i; + char *path = NULL; + unsigned int path_len; + int ret; + + ret = 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 != 3 + n_names ) + { + p9_error(ring, hdr->tag, errno); + goto out; + } + + fidp = 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 = strlen(fidp->path) + 1; + for ( i = 0; i < n_names; i++ ) + { + if ( !name_ok(ring->str + names[i]) ) + { + p9_error(ring, hdr->tag, ENOENT); + goto out; + } + path_len += strlen(ring->str + names[i]) + 1; + } + path = calloc(path_len + 1, 1); + if ( !path ) + { + p9_error(ring, hdr->tag, ENOMEM); + goto out; + } + strcpy(path, fidp->path); + + if ( n_names ) + { + qids = calloc(n_names, sizeof(*qids)); + if ( !qids ) + { + p9_error(ring, hdr->tag, ENOMEM); + goto out; + } + for ( i = 0; i < n_names; i++ ) + { + strcat(path, "/"); + strcat(path, ring->str + names[i]); + ret = fill_qid(device, path, qids + i, NULL); + if ( ret ) + { + if ( !walked ) + { + p9_error(ring, hdr->tag, errno); + goto out; + } + break; + } + walked++; + } + } + + if ( walked == n_names ) + { + bool ok = false; + + if ( fid == newfid ) + { + struct p9_fid *new_fidp; + + pthread_mutex_lock(&device->fid_mutex); + + if ( fidp->ref != 2 ) + { + errno = EBUSY; + } + else + { + new_fidp = alloc_fid_mem(device, fid, path); + if ( new_fidp ) + { + new_fidp->ref = 2; + XEN_TAILQ_REMOVE(&device->fids, fidp, list); + XEN_TAILQ_INSERT_HEAD(&device->fids, new_fidp, list); + free(fidp); + fidp = new_fidp; + ok = true; + } + } + + pthread_mutex_unlock(&device->fid_mutex); + } + else + ok = 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 = arg; @@ -723,6 +890,10 @@ void *io_thread(void *arg) p9_attach(ring, &hdr); break; + 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/9pfsd/xen-9pfsd.h b/tools/9pfsd/xen-9pfsd.h index 6c755411a7..f01fffb0bb 100644 --- a/tools/9pfsd/xen-9pfsd.h +++ b/tools/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[]; }; From patchwork Thu Feb 15 13:04:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?SsO8cmdlbiBHcm/Dnw==?= X-Patchwork-Id: 13558356 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 03CE5C48BC4 for ; Thu, 15 Feb 2024 13:06:05 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.681696.1060617 (Exim 4.92) (envelope-from ) id 1rabR9-0005sg-Cy; Thu, 15 Feb 2024 13:05:59 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 681696.1060617; Thu, 15 Feb 2024 13:05:59 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rabR9-0005sV-9E; Thu, 15 Feb 2024 13:05:59 +0000 Received: by outflank-mailman (input) for mailman id 681696; Thu, 15 Feb 2024 13:05:57 +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 1rabR7-0002yD-HU for xen-devel@lists.xenproject.org; Thu, 15 Feb 2024 13:05:57 +0000 Received: from smtp-out2.suse.de (smtp-out2.suse.de [2a07:de40:b251:101:10:150:64:2]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id f503beee-cc02-11ee-8a4d-1f161083a0e0; Thu, 15 Feb 2024 14:05:57 +0100 (CET) Received: from imap2.dmz-prg2.suse.org (imap2.dmz-prg2.suse.org [10.150.64.98]) (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 8ACC31F8A4; Thu, 15 Feb 2024 13:05:56 +0000 (UTC) Received: from imap2.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 imap2.dmz-prg2.suse.org (Postfix) with ESMTPS id 56694139D0; Thu, 15 Feb 2024 13:05:56 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap2.dmz-prg2.suse.org with ESMTPSA id 70V3EzQMzmWeFQAAn2gu4w (envelope-from ); Thu, 15 Feb 2024 13:05:56 +0000 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: f503beee-cc02-11ee-8a4d-1f161083a0e0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1708002356; 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=y958eMYICr4NUQbK+9A+PrL+kcGy4gkIM8hHmNn6rfg=; b=LtJ0yJpYTTETF9XJaoW+MWfkdp1rZXY63Htg3kAAu2jxKdQTpSSmSsr8vknbjKtDZAQM8S 45MV7MZjRP36xetkeP7sb/Lg9lyGQpO+dArm5ceglvscuW8+v/b6fAaCKuFlkwOkA4bzD5 CJjicTMxZ+ZI29F19ZvbZSCXX6CANV0= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1708002356; 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=y958eMYICr4NUQbK+9A+PrL+kcGy4gkIM8hHmNn6rfg=; b=LtJ0yJpYTTETF9XJaoW+MWfkdp1rZXY63Htg3kAAu2jxKdQTpSSmSsr8vknbjKtDZAQM8S 45MV7MZjRP36xetkeP7sb/Lg9lyGQpO+dArm5ceglvscuW8+v/b6fAaCKuFlkwOkA4bzD5 CJjicTMxZ+ZI29F19ZvbZSCXX6CANV0= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Anthony PERARD , Jason Andryuk Subject: [PATCH v7 08/21] tools/xen-9pfsd: add 9pfs open request support Date: Thu, 15 Feb 2024 14:04:56 +0100 Message-Id: <20240215130509.24008-9-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240215130509.24008-1-jgross@suse.com> References: <20240215130509.24008-1-jgross@suse.com> MIME-Version: 1.0 Authentication-Results: smtp-out2.suse.de; none X-Spamd-Result: default: False [0.70 / 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)[]; 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%] 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/9pfsd/io.c | 137 ++++++++++++++++++++++++++++++++++++++++ tools/9pfsd/xen-9pfsd.h | 4 ++ 2 files changed, 141 insertions(+) diff --git a/tools/9pfsd/io.c b/tools/9pfsd/io.c index 731fbd1ad7..5ec780af14 100644 --- a/tools/9pfsd/io.c +++ b/tools/9pfsd/io.c @@ -19,6 +19,8 @@ #include #include #include +#include +#include #include /* For cpu barriers. */ #include @@ -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 */ #define P9_MIN_MSIZE 2048 #define P9_VERSION "9P2000.u" @@ -827,6 +838,128 @@ static void p9_walk(struct ring *ring, struct p9_header *hdr) free(names); } +static int open_flags_from_mode(uint8_t mode) +{ + int flags; + + switch ( mode & P9_OMODEMASK ) + { + case P9_OREAD: + flags = O_RDONLY; + break; + + case P9_OWRITE: + flags = O_WRONLY; + break; + + case P9_ORDWR: + flags = O_RDWR; + break; + + default: + errno = EINVAL; + return -1; + } + + if ( mode & P9_OTRUNC ) + flags |= 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 = 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 = fill_data(ring, "Ub", &fid, &mode); + if ( ret != 2 ) + { + p9_error(ring, hdr->tag, EINVAL); + return; + } + if ( mode & ~(P9_OMODEMASK | P9_OTRUNC | P9_OREMOVE) ) + { + p9_error(ring, hdr->tag, EINVAL); + return; + } + + fidp = get_fid_ref(device, fid); + if ( !fidp ) + { + p9_error(ring, hdr->tag, ENOENT); + return; + } + if ( fidp->opened ) + { + errno = EINVAL; + goto err; + } + + if ( fstatat(device->root_fd, fidp->path, &st, 0) < 0 ) + { + errno = ENOENT; + goto err; + } + + if ( S_ISLNK(st.st_mode) ) + { + errno = EMLINK; + goto err; + } + + fidp->isdir = S_ISDIR(st.st_mode); + fidp->mode = mode; + if ( fidp->isdir ) + { + if ( mode != P9_OREAD ) + { + errno = EINVAL; + goto err; + } + fidp->fd = openat(device->root_fd, fidp->path, O_RDONLY); + if ( fidp->fd < 0 ) + goto err; + fidp->data = fdopendir(fidp->fd); + if ( !fidp->data ) + goto err; + } + else + { + flags = open_flags_from_mode(mode); + if ( flags < 0 ) + goto err; + + fidp->fd = openat(device->root_fd, fidp->path, flags); + if ( fidp->fd < 0 ) + goto err; + } + + fill_qid(device, fidp->path, &qid, &st); + iounit = get_iounit(ring, &st); + fidp->opened = 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 = arg; @@ -894,6 +1027,10 @@ void *io_thread(void *arg) p9_walk(ring, &hdr); break; + 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/9pfsd/xen-9pfsd.h b/tools/9pfsd/xen-9pfsd.h index f01fffb0bb..757be2da4b 100644 --- a/tools/9pfsd/xen-9pfsd.h +++ b/tools/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[]; }; From patchwork Thu Feb 15 13:04:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?SsO8cmdlbiBHcm/Dnw==?= X-Patchwork-Id: 13558357 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 482B7C48BC4 for ; Thu, 15 Feb 2024 13:06:13 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.681700.1060626 (Exim 4.92) (envelope-from ) id 1rabRH-0006Rt-KW; Thu, 15 Feb 2024 13:06:07 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 681700.1060626; Thu, 15 Feb 2024 13:06: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 1rabRH-0006Rm-Hi; Thu, 15 Feb 2024 13:06:07 +0000 Received: by outflank-mailman (input) for mailman id 681700; Thu, 15 Feb 2024 13:06: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 1rabRG-0002j3-0a for xen-devel@lists.xenproject.org; Thu, 15 Feb 2024 13:06:06 +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 f97c1002-cc02-11ee-98f5-efadbce2ee36; Thu, 15 Feb 2024 14:06:04 +0100 (CET) Received: from imap2.dmz-prg2.suse.org (imap2.dmz-prg2.suse.org [10.150.64.98]) (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 2D5FA2218B; Thu, 15 Feb 2024 13:06:02 +0000 (UTC) Received: from imap2.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 imap2.dmz-prg2.suse.org (Postfix) with ESMTPS id F0877139D0; Thu, 15 Feb 2024 13:06:01 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap2.dmz-prg2.suse.org with ESMTPSA id 1GtCOTkMzmWhFQAAn2gu4w (envelope-from ); Thu, 15 Feb 2024 13:06:01 +0000 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: f97c1002-cc02-11ee-98f5-efadbce2ee36 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1708002364; 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=ZWrUdAn8G/WYw7Z+1jcLbLASeGn0zV6YHdFDB/FVJZ8=; b=WgaQ/5YU2tUY56RnuiKXPRFallvy18SVnEjYPNrEX3XLq5N59GKfVqUZp2UCLaf/ZQ/D1D 4QC9lszG9OQUn3DOzjI0g7ojnSwIWRaF5oxXmdedPi9MGbKQBk/vxF80/aXNEhsPxDfDUt ucxdK4xbTHkNCsSqxLMVYuBtBaldQSM= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1708002362; 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=ZWrUdAn8G/WYw7Z+1jcLbLASeGn0zV6YHdFDB/FVJZ8=; b=k4LFMBKBObiyWNa/GnSmZtrPLKnlN7hRgRgTxV4Zuy/MZPQH7lMt3nCoFbZ7K2zr49Y+60 KeaE03RHfdMGe20O0Kve6XD1UAMFm9HkAF0z5vuR/VCGLo0rWNAykq7NxqIfnVOhpu53sF q0JAXAwZe1Ra2rjNiarO1I/X/Omfv0E= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Anthony PERARD , Jason Andryuk Subject: [PATCH v7 09/21] tools/xen-9pfsd: add 9pfs clunk request support Date: Thu, 15 Feb 2024 14:04:57 +0100 Message-Id: <20240215130509.24008-10-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240215130509.24008-1-jgross@suse.com> References: <20240215130509.24008-1-jgross@suse.com> MIME-Version: 1.0 Authentication-Results: smtp-out1.suse.de; none X-Spamd-Result: default: False [4.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)[]; 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,citrix.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(-0.00)[11.21%] 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/9pfsd/io.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/tools/9pfsd/io.c b/tools/9pfsd/io.c index 5ec780af14..6af14e5ee9 100644 --- a/tools/9pfsd/io.c +++ b/tools/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 /* P9 protocol open flags. */ #define P9_OREAD 0 /* read */ @@ -960,6 +961,44 @@ static void p9_open(struct ring *ring, struct p9_header *hdr) p9_error(ring, hdr->tag, errno); } +static void p9_clunk(struct ring *ring, struct p9_header *hdr) +{ + device *device = ring->device; + uint32_t fid; + struct p9_fid *fidp; + int ret; + + ret = fill_data(ring, "U", &fid); + if ( ret != 1 ) + { + p9_error(ring, hdr->tag, EINVAL); + return; + } + + fidp = get_fid_ref(device, fid); + if ( !fidp ) + { + p9_error(ring, hdr->tag, ENOENT); + return; + } + + if ( fidp->opened ) + { + fidp->opened = 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 = arg; @@ -1031,6 +1070,10 @@ void *io_thread(void *arg) p9_open(ring, &hdr); break; + 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); From patchwork Thu Feb 15 13:04:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?SsO8cmdlbiBHcm/Dnw==?= X-Patchwork-Id: 13558362 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 4CAAFC48BC4 for ; Thu, 15 Feb 2024 13:10:03 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.681732.1060683 (Exim 4.92) (envelope-from ) id 1rabUx-0002RA-Ky; Thu, 15 Feb 2024 13:09:55 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 681732.1060683; Thu, 15 Feb 2024 13:09:55 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rabUx-0002QB-Fy; Thu, 15 Feb 2024 13:09:55 +0000 Received: by outflank-mailman (input) for mailman id 681732; Thu, 15 Feb 2024 13:09:53 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rabRK-0002j3-7x for xen-devel@lists.xenproject.org; Thu, 15 Feb 2024 13:06:10 +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 fba55b8b-cc02-11ee-98f5-efadbce2ee36; Thu, 15 Feb 2024 14:06:08 +0100 (CET) Received: from imap2.dmz-prg2.suse.org (imap2.dmz-prg2.suse.org [10.150.64.98]) (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 B87DB21FBC; Thu, 15 Feb 2024 13:06:07 +0000 (UTC) Received: from imap2.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 imap2.dmz-prg2.suse.org (Postfix) with ESMTPS id 8A0B9139D0; Thu, 15 Feb 2024 13:06:07 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap2.dmz-prg2.suse.org with ESMTPSA id +n9ZID8MzmWkFQAAn2gu4w (envelope-from ); Thu, 15 Feb 2024 13:06:07 +0000 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: fba55b8b-cc02-11ee-98f5-efadbce2ee36 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1708002367; 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=IqwLddRteFeWRdtvf3aJAKcFAk5qC0k1ozwKLE3hJvs=; b=L71WoaIkbO/kGN6pa6MY7H4p9ml/R5jcHk89fIWMtI2ZSzAhckIvQCvQyCbU5LxLPRdjOq zUFS/S3Vr/uO5BPxyHB86L/ZMpcAAQu/ZKyinyvRFdT6p1dRb5Gdu+yaGCOlvPrsZZtSoK O1ipBjLnqSOvlYdo+cPcwcdW6BQ41Yk= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1708002367; 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=IqwLddRteFeWRdtvf3aJAKcFAk5qC0k1ozwKLE3hJvs=; b=L71WoaIkbO/kGN6pa6MY7H4p9ml/R5jcHk89fIWMtI2ZSzAhckIvQCvQyCbU5LxLPRdjOq zUFS/S3Vr/uO5BPxyHB86L/ZMpcAAQu/ZKyinyvRFdT6p1dRb5Gdu+yaGCOlvPrsZZtSoK O1ipBjLnqSOvlYdo+cPcwcdW6BQ41Yk= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Anthony PERARD , Jason Andryuk Subject: [PATCH v7 10/21] tools/xen-9pfsd: add 9pfs create request support Date: Thu, 15 Feb 2024 14:04:58 +0100 Message-Id: <20240215130509.24008-11-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240215130509.24008-1-jgross@suse.com> References: <20240215130509.24008-1-jgross@suse.com> MIME-Version: 1.0 Authentication-Results: smtp-out1.suse.de; none X-Spamd-Result: default: False [4.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)[]; 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,citrix.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)[] 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/9pfsd/io.c | 151 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 151 insertions(+) diff --git a/tools/9pfsd/io.c b/tools/9pfsd/io.c index 6af14e5ee9..8fa80865b4 100644 --- a/tools/9pfsd/io.c +++ b/tools/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 /* 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 */ +/* 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 @@ -961,6 +968,146 @@ static void p9_open(struct ring *ring, struct p9_header *hdr) p9_error(ring, hdr->tag, errno); } +static void p9_create(struct ring *ring, struct p9_header *hdr) +{ + device *device = 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 = fill_data(ring, "USUbS", &fid, &name_off, &perm, &mode, &ext_off); + if ( ret != 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 = 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 = 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 = 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 = fidp->ref; + + if ( perm & P9_CREATE_PERM_DIR ) + { + perm &= P9_CREATE_PERM_DIR_MASK & st.st_mode; + if ( mode != P9_OREAD ) + { + errno = 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 = new_fidp; + new_fidp = NULL; + + fidp->fd = openat(device->root_fd, fidp->path, O_RDONLY); + if ( fidp->fd < 0 ) + goto err; + fidp->data = fdopendir(fidp->fd); + if ( !fidp->data ) + goto err; + } + else + { + flags = open_flags_from_mode(mode); + if ( flags < 0 ) + { + errno = EINVAL; + goto err; + } + perm &= P9_CREATE_PERM_FILE_MASK & st.st_mode; + + XEN_TAILQ_REMOVE(&device->fids, fidp, list); + XEN_TAILQ_INSERT_HEAD(&device->fids, new_fidp, list); + free(fidp); + fidp = new_fidp; + new_fidp = NULL; + + fidp->fd = 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 = get_iounit(ring, &st); + fidp->opened = true; + fidp->mode = 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 = ring->device; @@ -1070,6 +1217,10 @@ void *io_thread(void *arg) p9_open(ring, &hdr); break; + case P9_CMD_CREATE: + p9_create(ring, &hdr); + break; + case P9_CMD_CLUNK: p9_clunk(ring, &hdr); break; From patchwork Thu Feb 15 13:04:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?SsO8cmdlbiBHcm/Dnw==?= X-Patchwork-Id: 13558366 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 37C54C48BF2 for ; Thu, 15 Feb 2024 13:10:04 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.681735.1060694 (Exim 4.92) (envelope-from ) id 1rabUy-0002f2-DJ; Thu, 15 Feb 2024 13:09:56 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 681735.1060694; Thu, 15 Feb 2024 13:09:56 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rabUy-0002d4-3Z; Thu, 15 Feb 2024 13:09:56 +0000 Received: by outflank-mailman (input) for mailman id 681735; Thu, 15 Feb 2024 13:09:53 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rabRP-0002j3-F1 for xen-devel@lists.xenproject.org; Thu, 15 Feb 2024 13:06:15 +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 fefd6f6b-cc02-11ee-98f5-efadbce2ee36; Thu, 15 Feb 2024 14:06:13 +0100 (CET) Received: from imap2.dmz-prg2.suse.org (imap2.dmz-prg2.suse.org [10.150.64.98]) (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 5989922031; Thu, 15 Feb 2024 13:06:13 +0000 (UTC) Received: from imap2.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 imap2.dmz-prg2.suse.org (Postfix) with ESMTPS id 2B059139D0; Thu, 15 Feb 2024 13:06:13 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap2.dmz-prg2.suse.org with ESMTPSA id 9f4nCUUMzmWvFQAAn2gu4w (envelope-from ); Thu, 15 Feb 2024 13:06:13 +0000 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: fefd6f6b-cc02-11ee-98f5-efadbce2ee36 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1708002373; 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=U8pzJQi1IB2cDnOVCOc5xAPOt+AhORB1buKXKU5naO0=; b=J/JBlX4J7n2B15CvskZcQARsA1c7jI2Djn679BAZHKO0wEn52fkCoTxWqYV4Dz08ddNc9Y a1FxHqPoO8uzp4E/WnY+OECOsbwxrzwBRvT1jtJAlr971pixwqxQzeVaqQS5yOgh5zOZaZ Iy71AX5RPzhc8EflbEjfaqKpOJ/Iqkw= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1708002373; 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=U8pzJQi1IB2cDnOVCOc5xAPOt+AhORB1buKXKU5naO0=; b=J/JBlX4J7n2B15CvskZcQARsA1c7jI2Djn679BAZHKO0wEn52fkCoTxWqYV4Dz08ddNc9Y a1FxHqPoO8uzp4E/WnY+OECOsbwxrzwBRvT1jtJAlr971pixwqxQzeVaqQS5yOgh5zOZaZ Iy71AX5RPzhc8EflbEjfaqKpOJ/Iqkw= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Anthony PERARD , Jason Andryuk Subject: [PATCH v7 11/21] tools/xen-9pfsd: add 9pfs stat request support Date: Thu, 15 Feb 2024 14:04:59 +0100 Message-Id: <20240215130509.24008-12-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240215130509.24008-1-jgross@suse.com> References: <20240215130509.24008-1-jgross@suse.com> MIME-Version: 1.0 Authentication-Results: smtp-out1.suse.de; none X-Spamd-Result: default: False [1.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)[]; 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,citrix.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%] 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/9pfsd/io.c | 102 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) diff --git a/tools/9pfsd/io.c b/tools/9pfsd/io.c index 8fa80865b4..8c36106d90 100644 --- a/tools/9pfsd/io.c +++ b/tools/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 /* P9 protocol open flags. */ #define P9_OREAD 0 /* read */ @@ -60,6 +61,25 @@ struct p9_qid { uint64_t path; }; +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 frontend, @@ -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 *fmt, 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 = 0; unsigned int elem_sz = 0; @@ -259,6 +282,18 @@ static void vfill_buffer_at(void **data, const char *fmt, va_list ap) *data += len; break; + case 's': + stat = par; + elem_sz = sizeof(*stat); + tlen = stat->size + sizeof(stat->size); + fill_buffer_at(data, "uuuUQUUULSSSSSUUU", &tlen, &stat->size, + &stat->type, &stat->dev, &stat->qid, &stat->mode, + &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 = sizeof(uint32_t); @@ -1146,6 +1181,69 @@ static void p9_clunk(struct ring *ring, struct p9_header *hdr) fill_buffer(ring, hdr->cmd + 1, hdr->tag, ""); } +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 = st->st_mode & 0777; + if ( S_ISDIR(st->st_mode) ) + p9s->mode |= P9_CREATE_PERM_DIR; + p9s->atime = st->st_atime; + p9s->mtime = st->st_mtime; + p9s->length = st->st_size; + p9s->name = name; + p9s->uid = ""; + p9s->gid = ""; + p9s->muid = ""; + p9s->extension = ""; + p9s->n_uid = 0; + p9s->n_gid = 0; + p9s->n_muid = 0; + + /* + * Size of individual fields without the size field, including 5 2-byte + * string length fields. + */ + p9s->size = 71 + strlen(p9s->name); +} + +static void p9_stat(struct ring *ring, struct p9_header *hdr) +{ + device *device = ring->device; + uint32_t fid; + struct p9_fid *fidp; + struct p9_stat p9s; + struct stat st; + int ret; + + ret = fill_data(ring, "U", &fid); + if ( ret != 1 ) + { + p9_error(ring, hdr->tag, EINVAL); + return; + } + + fidp = 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 = arg; @@ -1225,6 +1323,10 @@ void *io_thread(void *arg) p9_clunk(ring, &hdr); break; + 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); From patchwork Thu Feb 15 13:05:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?SsO8cmdlbiBHcm/Dnw==?= X-Patchwork-Id: 13558368 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2E482C48BC4 for ; Thu, 15 Feb 2024 13:10:09 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.681745.1060737 (Exim 4.92) (envelope-from ) id 1rabV4-000483-2K; Thu, 15 Feb 2024 13:10:02 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 681745.1060737; Thu, 15 Feb 2024 13:10:02 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rabV3-00047q-UP; Thu, 15 Feb 2024 13:10:01 +0000 Received: by outflank-mailman (input) for mailman id 681745; Thu, 15 Feb 2024 13:10:00 +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 1rabRU-0002yD-2B for xen-devel@lists.xenproject.org; Thu, 15 Feb 2024 13:06:20 +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 0275e794-cc03-11ee-8a4d-1f161083a0e0; Thu, 15 Feb 2024 14:06:19 +0100 (CET) Received: from imap2.dmz-prg2.suse.org (imap2.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:98]) (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 006A021FBC; Thu, 15 Feb 2024 13:06:19 +0000 (UTC) Received: from imap2.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 imap2.dmz-prg2.suse.org (Postfix) with ESMTPS id B8FD1139D0; Thu, 15 Feb 2024 13:06:18 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap2.dmz-prg2.suse.org with ESMTPSA id xeCvK0oMzmW0FQAAn2gu4w (envelope-from ); Thu, 15 Feb 2024 13:06:18 +0000 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: 0275e794-cc03-11ee-8a4d-1f161083a0e0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1708002379; 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=X2VtlH36Dxgp8+Z8DrH/UT3snGVBYS8nN8oGoKs6b2w=; b=KDATXNSOJfA0nBe69MLrQTUtsFGMQkggIkAsB8pNY0Tadg16Z429hgUvGCZ6Po5dorEnWb FJqoyL6m5tWPE7k39wAAttK7P8l0eMTkB2ed208Avr7RVdxJGjBXYNqpBBBkjKgdcEGA5J a6PkCmn6zwGFdF3UrUmxK5wTuabOLqQ= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1708002379; 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=X2VtlH36Dxgp8+Z8DrH/UT3snGVBYS8nN8oGoKs6b2w=; b=KDATXNSOJfA0nBe69MLrQTUtsFGMQkggIkAsB8pNY0Tadg16Z429hgUvGCZ6Po5dorEnWb FJqoyL6m5tWPE7k39wAAttK7P8l0eMTkB2ed208Avr7RVdxJGjBXYNqpBBBkjKgdcEGA5J a6PkCmn6zwGFdF3UrUmxK5wTuabOLqQ= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Anthony PERARD , Jason Andryuk Subject: [PATCH v7 12/21] tools/xen-9pfsd: add 9pfs write request support Date: Thu, 15 Feb 2024 14:05:00 +0100 Message-Id: <20240215130509.24008-13-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240215130509.24008-1-jgross@suse.com> References: <20240215130509.24008-1-jgross@suse.com> MIME-Version: 1.0 X-Spamd-Bar: +++ Authentication-Results: smtp-out1.suse.de; dkim=pass header.d=suse.com header.s=susede1 header.b=KDATXNSO X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Spamd-Result: default: False [3.49 / 50.00]; RCVD_VIA_SMTP_AUTH(0.00)[]; SPAMHAUS_XBL(0.00)[2a07:de40:b281:104:10:150:64:98:from]; TO_DN_SOME(0.00)[]; R_MISSING_CHARSET(2.50)[]; BROKEN_CONTENT_TYPE(1.50)[]; RCPT_COUNT_FIVE(0.00)[5]; RCVD_COUNT_THREE(0.00)[3]; DKIM_TRACE(0.00)[suse.com:+]; MX_GOOD(-0.01)[]; NEURAL_HAM_SHORT(-0.20)[-1.000]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; BAYES_HAM(-0.00)[19.25%]; ARC_NA(0.00)[]; R_DKIM_ALLOW(-0.20)[suse.com:s=susede1]; FROM_HAS_DN(0.00)[]; FREEMAIL_ENVRCPT(0.00)[gmail.com]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; NEURAL_HAM_LONG(-1.00)[-1.000]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; MID_CONTAINS_FROM(1.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.com:dkim,suse.com:email,citrix.com:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; FREEMAIL_CC(0.00)[suse.com,xen.org,citrix.com,gmail.com]; RCVD_TLS_ALL(0.00)[] X-Rspamd-Queue-Id: 006A021FBC Add the write request of the 9pfs protocol. Signed-off-by: Juergen Gross Reviewed-by: Jason Andryuk Acked-by: Anthony PERARD --- tools/9pfsd/io.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/tools/9pfsd/io.c b/tools/9pfsd/io.c index 8c36106d90..1832c6b06e 100644 --- a/tools/9pfsd/io.c +++ b/tools/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 @@ -1244,6 +1245,55 @@ static void p9_stat(struct ring *ring, struct p9_header *hdr) free_fid(device, fidp); } +static void p9_write(struct ring *ring, struct p9_header *hdr) +{ + device *device = ring->device; + uint32_t fid; + uint64_t off; + unsigned int len; + uint32_t written; + void *buf; + struct p9_fid *fidp; + int ret; + + ret = fill_data(ring, "ULD", &fid, &off, &len, ring->buffer); + if ( ret != 3 ) + { + p9_error(ring, hdr->tag, EINVAL); + return; + } + + fidp = get_fid_ref(device, fid); + if ( !fidp || !fidp->opened || fidp->isdir ) + { + p9_error(ring, hdr->tag, EBADF); + goto out; + } + + buf = ring->buffer; + + while ( len != 0 ) + { + ret = pwrite(fidp->fd, buf, len, off); + if ( ret < 0 ) + break; + len -= ret; + buf += ret; + off += ret; + } + + written = buf - ring->buffer; + if ( written == 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 = arg; @@ -1319,6 +1369,10 @@ void *io_thread(void *arg) p9_create(ring, &hdr); break; + case P9_CMD_WRITE: + p9_write(ring, &hdr); + break; + case P9_CMD_CLUNK: p9_clunk(ring, &hdr); break; From patchwork Thu Feb 15 13:05:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?SsO8cmdlbiBHcm/Dnw==?= X-Patchwork-Id: 13558370 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id CD3B8C48BC4 for ; Thu, 15 Feb 2024 13:10:42 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.681765.1060756 (Exim 4.92) (envelope-from ) id 1rabVb-0007ae-1v; Thu, 15 Feb 2024 13:10:35 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 681765.1060756; Thu, 15 Feb 2024 13:10: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 1rabVa-0007aV-VH; Thu, 15 Feb 2024 13:10:34 +0000 Received: by outflank-mailman (input) for mailman id 681765; Thu, 15 Feb 2024 13:10:33 +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 1rabRZ-0002yD-P0 for xen-devel@lists.xenproject.org; Thu, 15 Feb 2024 13:06:25 +0000 Received: from smtp-out1.suse.de (smtp-out1.suse.de [2a07:de40:b251:101:10:150:64:1]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 05b67721-cc03-11ee-8a4d-1f161083a0e0; Thu, 15 Feb 2024 14:06:25 +0100 (CET) Received: from imap2.dmz-prg2.suse.org (imap2.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:98]) (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 8E16D22031; Thu, 15 Feb 2024 13:06:24 +0000 (UTC) Received: from imap2.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 imap2.dmz-prg2.suse.org (Postfix) with ESMTPS id 5DF61139D0; Thu, 15 Feb 2024 13:06:24 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap2.dmz-prg2.suse.org with ESMTPSA id 4UaHFVAMzmW3FQAAn2gu4w (envelope-from ); Thu, 15 Feb 2024 13:06:24 +0000 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: 05b67721-cc03-11ee-8a4d-1f161083a0e0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1708002384; 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=87vA+v/yqSIw13sXcaxXTXhvJpR4gCj67AXmDFAMYsw=; b=HD/PUmo7iajzRJRmv5GvMx4aXD/9HOxHWCNarSFpPIqNhxjvPnMNSkn+h7FVMT+zzl4Kel BNSF9ruffO9492OvZlDnu9So4OiRXtHR1CgyRHs+ennHo7Ai+HHqDp7mfEgQo9YaUMHYOI YLrBAFdEQNvYkyTQTmq9K+BFK+8c7ms= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1708002384; 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=87vA+v/yqSIw13sXcaxXTXhvJpR4gCj67AXmDFAMYsw=; b=HD/PUmo7iajzRJRmv5GvMx4aXD/9HOxHWCNarSFpPIqNhxjvPnMNSkn+h7FVMT+zzl4Kel BNSF9ruffO9492OvZlDnu9So4OiRXtHR1CgyRHs+ennHo7Ai+HHqDp7mfEgQo9YaUMHYOI YLrBAFdEQNvYkyTQTmq9K+BFK+8c7ms= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Anthony PERARD , Jason Andryuk Subject: [PATCH v7 13/21] tools/xen-9pfsd: add 9pfs read request support Date: Thu, 15 Feb 2024 14:05:01 +0100 Message-Id: <20240215130509.24008-14-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240215130509.24008-1-jgross@suse.com> References: <20240215130509.24008-1-jgross@suse.com> MIME-Version: 1.0 Authentication-Results: smtp-out1.suse.de; dkim=pass header.d=suse.com header.s=susede1 header.b="HD/PUmo7" X-Spamd-Result: default: False [4.69 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; R_DKIM_ALLOW(-0.20)[suse.com:s=susede1]; SPAMHAUS_XBL(0.00)[2a07:de40:b281:104:10:150:64:98:from]; 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)[]; BROKEN_CONTENT_TYPE(1.50)[]; DWL_DNSWL_BLOCKED(0.00)[suse.com:dkim]; RCPT_COUNT_FIVE(0.00)[5]; RCVD_COUNT_THREE(0.00)[3]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; DKIM_TRACE(0.00)[suse.com:+]; MX_GOOD(-0.01)[]; MID_CONTAINS_FROM(1.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.com:dkim,suse.com:email,citrix.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(-0.00)[20.42%] X-Rspamd-Server: rspamd1.dmz-prg2.suse.org X-Rspamd-Queue-Id: 8E16D22031 X-Spamd-Bar: ++++ 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 V5: - rewinddir() if reading a directory and offset is 0 (Jason Andryuk) --- tools/9pfsd/io.c | 93 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) diff --git a/tools/9pfsd/io.c b/tools/9pfsd/io.c index 1832c6b06e..ba2d4a436e 100644 --- a/tools/9pfsd/io.c +++ b/tools/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 @@ -1245,6 +1246,94 @@ static void p9_stat(struct ring *ring, struct p9_header *hdr) free_fid(device, fidp); } +static void p9_read(struct ring *ring, struct p9_header *hdr) +{ + device *device = ring->device; + uint32_t fid; + uint64_t off; + unsigned int len; + uint32_t count; + void *buf; + struct p9_fid *fidp; + int ret; + + ret = fill_data(ring, "ULU", &fid, &off, &count); + if ( ret != 3 ) + { + p9_error(ring, hdr->tag, EINVAL); + return; + } + + fidp = get_fid_ref(device, fid); + if ( !fidp || !fidp->opened ) + { + errno = EBADF; + goto err; + } + + len = count; + buf = ring->buffer + sizeof(*hdr) + sizeof(uint32_t); + + if ( fidp->isdir ) + { + struct dirent *dirent; + struct stat st; + struct p9_stat p9s; + + if ( off == 0 ) + rewinddir(fidp->data); + + while ( len != 0 ) + { + errno = 0; + dirent = 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 -= p9s.size + sizeof(p9s.size); + } + } + else + { + while ( len != 0 ) + { + ret = pread(fidp->fd, buf, len, off); + if ( ret <= 0 ) + break; + len -= ret; + buf += ret; + off += ret; + } + if ( ret < 0 && len == count ) + goto err; + } + + buf = ring->buffer + sizeof(*hdr) + sizeof(uint32_t); + len = 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 = ring->device; @@ -1369,6 +1458,10 @@ void *io_thread(void *arg) p9_create(ring, &hdr); break; + case P9_CMD_READ: + p9_read(ring, &hdr); + break; + case P9_CMD_WRITE: p9_write(ring, &hdr); break; From patchwork Thu Feb 15 13:05:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?SsO8cmdlbiBHcm/Dnw==?= X-Patchwork-Id: 13558360 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 85D44C4829E for ; Thu, 15 Feb 2024 13:09:25 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.681719.1060657 (Exim 4.92) (envelope-from ) id 1rabUL-0000qm-NA; Thu, 15 Feb 2024 13:09:17 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 681719.1060657; Thu, 15 Feb 2024 13:09:17 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rabUL-0000qf-KA; Thu, 15 Feb 2024 13:09:17 +0000 Received: by outflank-mailman (input) for mailman id 681719; Thu, 15 Feb 2024 13:09:16 +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 1rabRg-0002j3-Pd for xen-devel@lists.xenproject.org; Thu, 15 Feb 2024 13:06:32 +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 09242fa7-cc03-11ee-98f5-efadbce2ee36; Thu, 15 Feb 2024 14:06:30 +0100 (CET) Received: from imap2.dmz-prg2.suse.org (imap2.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:98]) (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 3CF961FD63; Thu, 15 Feb 2024 13:06:30 +0000 (UTC) Received: from imap2.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 imap2.dmz-prg2.suse.org (Postfix) with ESMTPS id EE111139D0; Thu, 15 Feb 2024 13:06:29 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap2.dmz-prg2.suse.org with ESMTPSA id yACnOFUMzmW+FQAAn2gu4w (envelope-from ); Thu, 15 Feb 2024 13:06:29 +0000 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: 09242fa7-cc03-11ee-98f5-efadbce2ee36 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1708002390; 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=zgmWzK99RZBrySpVIOBOfTuvIg1qZCvB7PuUVcrLtSw=; b=fdQozqubiTxpK61xHdVDLgeuphh8maCl7TpPVAl75xx0+AHbkTNX95JBSvYiGkc0f27OPO Lp8lZUU2Mfrt60O9V88gOC6A9F87XibynB1RQo5Y/oC3grjbdUm2XTwRHkXK4ilGttEzuv 0N+7Ocrg8k/fOWdlJdA14ExCaDqVJR0= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1708002390; 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=zgmWzK99RZBrySpVIOBOfTuvIg1qZCvB7PuUVcrLtSw=; b=fdQozqubiTxpK61xHdVDLgeuphh8maCl7TpPVAl75xx0+AHbkTNX95JBSvYiGkc0f27OPO Lp8lZUU2Mfrt60O9V88gOC6A9F87XibynB1RQo5Y/oC3grjbdUm2XTwRHkXK4ilGttEzuv 0N+7Ocrg8k/fOWdlJdA14ExCaDqVJR0= 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 v7 14/21] tools/libs/light: add backend type for 9pfs PV devices Date: Thu, 15 Feb 2024 14:05:02 +0100 Message-Id: <20240215130509.24008-15-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240215130509.24008-1-jgross@suse.com> References: <20240215130509.24008-1-jgross@suse.com> MIME-Version: 1.0 X-Spamd-Bar: / Authentication-Results: smtp-out2.suse.de; dkim=pass header.d=suse.com header.s=susede1 header.b=fdQozqub X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Spamd-Result: default: False [0.49 / 50.00]; RCVD_VIA_SMTP_AUTH(0.00)[]; SPAMHAUS_XBL(0.00)[2a07:de40:b281:104:10:150:64:98:from]; TO_DN_SOME(0.00)[]; R_MISSING_CHARSET(2.50)[]; BROKEN_CONTENT_TYPE(1.50)[]; RCVD_COUNT_THREE(0.00)[3]; DKIM_TRACE(0.00)[suse.com:+]; MX_GOOD(-0.01)[]; RCPT_COUNT_SEVEN(0.00)[8]; NEURAL_HAM_SHORT(-0.20)[-1.000]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; BAYES_HAM(-3.00)[100.00%]; ARC_NA(0.00)[]; R_DKIM_ALLOW(-0.20)[suse.com:s=susede1]; FROM_HAS_DN(0.00)[]; FREEMAIL_ENVRCPT(0.00)[gmail.com]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; NEURAL_HAM_LONG(-1.00)[-1.000]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; MID_CONTAINS_FROM(1.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.com:dkim,suse.com:email,citrix.com:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; FREEMAIL_CC(0.00)[suse.com,citrix.com,gmail.com,xen.org,cloud.com]; RCVD_TLS_ALL(0.00)[] X-Rspamd-Queue-Id: 3CF961FD63 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 Reviewed-by: Anthony PERARD --- 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) V6: - rebase (Anthony Perard) - drop callback from struct libxl__aop9_state (Anthony Perard) --- tools/golang/xenlight/helpers.gen.go | 10 ++ tools/golang/xenlight/types.gen.go | 12 ++ tools/include/libxl.h | 7 + tools/libs/light/libxl_9pfs.c | 157 +++++++++++++++++++++- 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, 197 insertions(+), 7 deletions(-) diff --git a/tools/golang/xenlight/helpers.gen.go b/tools/golang/xenlight/helpers.gen.go index 0f8e23773c..8f44397a4e 100644 --- a/tools/golang/xenlight/helpers.gen.go +++ b/tools/golang/xenlight/helpers.gen.go @@ -2440,6 +2440,11 @@ x.Tag = C.GoString(xc.tag) x.Path = C.GoString(xc.path) x.SecurityModel = C.GoString(xc.security_model) x.Devid = Devid(xc.devid) +x.Type = P9Type(xc._type) +x.MaxSpace = int(xc.max_space) +x.MaxFiles = int(xc.max_files) +x.MaxOpenFiles = int(xc.max_open_files) +x.AutoDelete = bool(xc.auto_delete) return nil} @@ -2458,6 +2463,11 @@ xc.path = C.CString(x.Path)} if x.SecurityModel != "" { xc.security_model = C.CString(x.SecurityModel)} xc.devid = C.libxl_devid(x.Devid) +xc._type = C.libxl_p9_type(x.Type) +xc.max_space = C.int(x.MaxSpace) +xc.max_files = C.int(x.MaxFiles) +xc.max_open_files = C.int(x.MaxOpenFiles) +xc.auto_delete = C.bool(x.AutoDelete) return nil } diff --git a/tools/golang/xenlight/types.gen.go b/tools/golang/xenlight/types.gen.go index 9c8b7b81f6..d31722407a 100644 --- a/tools/golang/xenlight/types.gen.go +++ b/tools/golang/xenlight/types.gen.go @@ -122,6 +122,13 @@ NicTypeVifIoemu NicType = 1 NicTypeVif NicType = 2 ) +type P9Type int +const( +P9TypeUnknown P9Type = 0 +P9TypeQemu P9Type = 1 +P9TypeXen9Pfsd P9Type = 2 +) + type ActionOnShutdown int const( ActionOnShutdownDestroy ActionOnShutdown = 1 @@ -889,6 +896,11 @@ Tag string Path string SecurityModel string Devid Devid +Type P9Type +MaxSpace int +MaxFiles int +MaxOpenFiles int +AutoDelete bool } type DevicePvcallsif struct { diff --git a/tools/include/libxl.h b/tools/include/libxl.h index 46bc774126..9a3e702557 100644 --- a/tools/include/libxl.h +++ b/tools/include/libxl.h @@ -615,6 +615,13 @@ */ #define LIBXL_HAVE_HVM_PIRQ 1 +/* + * 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 and + * 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..900c0d46a0 100644 --- a/tools/libs/light/libxl_9pfs.c +++ b/tools/libs/light/libxl_9pfs.c @@ -33,20 +33,171 @@ static int libxl__set_xenstore_p9(libxl__gc *gc, uint32_t domid, flexarray_append_pair(front, "tag", p9->tag); + if (p9->type == 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 *device) +{ + device->backend_devid = type->devid; + device->backend_domid = type->backend_domid; + device->backend_kind = type->type == LIBXL_P9_TYPE_QEMU + ? LIBXL__DEVICE_KIND_9PFS + : LIBXL__DEVICE_KIND_XEN_9PFS; + device->devid = type->devid; + device->domid = domid; + device->kind = LIBXL__DEVICE_KIND_9PFS; + return 0; } -#define libxl__add_p9s NULL +static int libxl__device_p9_dm_needed(void *e, unsigned domid) +{ + libxl_device_p9 *elem = e; + + return elem->type == LIBXL_P9_TYPE_QEMU && elem->backend_domid == 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; +}; + +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, int rc); +static void xen9pfsd_detached(libxl__egc *egc, libxl__spawn_state *spawn); +static void xen9pfsd_spawn_outcome(libxl__egc *egc, libxl__aop9_state *aop9, + 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[] = { "xen-9pfsd", NULL }; + char *path = GCSPRINTF("/local/domain/%u/libxl/xen-9pfs", + p9->backend_domid); + + if (p9->type != LIBXL_P9_TYPE_XEN_9PFSD || + libxl__xs_read(gc, XBT_NULL, GCSPRINTF("%s/state", path))) + return 0; + + GCNEW(aop9); + aop9->aodev = aodev; + libxl_device_p9_copy(CTX, &aop9->p9, p9); + aop9->domid = domid; + + aop9->spawn.ao = aodev->ao; + aop9->spawn.what = "xen-9pfs daemon"; + aop9->spawn.xspath = GCSPRINTF("%s/state", path); + aop9->spawn.timeout_ms = LIBXL_DEVICE_MODEL_START_TIMEOUT * 1000; + aop9->spawn.pidpath = GCSPRINTF("%s/pid", path); + aop9->spawn.midproc_cb = libxl__spawn_record_pid; + aop9->spawn.confirm_cb = xen9pfsd_confirm; + aop9->spawn.failure_cb = xen9pfsd_failed; + aop9->spawn.detached_cb = xen9pfsd_detached; + rc = 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, int rc) +{ + libxl__aop9_state *aop9 = 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 = CONTAINER_OF(spawn, *aop9, spawn); + + xen9pfsd_spawn_outcome(egc, aop9, 0); +} + +static void xen9pfsd_spawn_outcome(libxl__egc *egc, libxl__aop9_state *aop9, + int rc) +{ + aop9->aodev->rc = 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 = xen9pfsd_spawn(egc, domid, p9, aodev); + if (rc == 1) + return; + + if (rc == 0) + libxl__device_add_async(egc, domid, &libxl__p9_devtype, p9, aodev); + + aodev->rc = rc; + if (rc) + aodev->callback(egc, aodev); +} + #define libxl_device_p9_list NULL #define libxl_device_p9_compare NULL static LIBXL_DEFINE_UPDATE_DEVID(p9) -static LIBXL_DEFINE_DEVICE_FROM_TYPE(p9) +static LIBXL_DEFINE_DEVICES_ADD(p9) LIBXL_DEFINE_DEVICE_REMOVE(p9) DEFINE_DEVICE_TYPE_STRUCT(p9, 9PFS, p9s, - .skip_attach = 1, .set_xenstore_config = (device_set_xenstore_config_fn_t) libxl__set_xenstore_p9, + .dm_needed = libxl__device_p9_dm_needed, ); diff --git a/tools/libs/light/libxl_create.c b/tools/libs/light/libxl_create.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, libxl__multidev *multidev, libxl__device_console_dispose(&console); } - for (i = 0; i < d_config->num_p9s; i++) - libxl__device_add(gc, domid, &libxl__p9_devtype, &d_config->p9s[i]); - for (i = 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[] = { &libxl__vdispl_devtype, &libxl__vsnd_devtype, &libxl__virtio_devtype, + &libxl__p9_devtype, NULL }; 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_domain_config *d_config) goto out; } - if (d_config->num_vfbs > 0 || d_config->num_p9s > 0) { + if (d_config->num_vfbs > 0) { ret = 1; goto out; } diff --git a/tools/libs/light/libxl_types.idl b/tools/libs/light/libxl_types.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 = Enumeration("nic_type", [ (2, "VIF"), ]) +libxl_p9_type = Enumeration("p9_type", [ + (0, "unknown"), + (1, "qemu"), + (2, "xen_9pfsd"), + ]) + libxl_action_on_shutdown = Enumeration("action_on_shutdown", [ (1, "DESTROY"), @@ -943,6 +949,11 @@ libxl_device_p9 = 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), ]) libxl_device_pvcallsif = Struct("device_pvcallsif", [ diff --git a/tools/libs/light/libxl_types_internal.idl b/tools/libs/light/libxl_types_internal.idl index 56dccac153..0425e9b6b0 100644 --- a/tools/libs/light/libxl_types_internal.idl +++ b/tools/libs/light/libxl_types_internal.idl @@ -35,6 +35,7 @@ libxl__device_kind = Enumeration("device_kind", [ (17, "VIRTIO_DISK"), (18, "VIRTIO"), (19, "VBD3"), + (20, "XEN_9PFS"), ]) libxl__console_backend = Enumeration("console_backend", [ From patchwork Thu Feb 15 13:05:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?SsO8cmdlbiBHcm/Dnw==?= X-Patchwork-Id: 13558369 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D133AC4829E for ; Thu, 15 Feb 2024 13:10:15 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.681746.1060747 (Exim 4.92) (envelope-from ) id 1rabV9-0005E6-Fn; Thu, 15 Feb 2024 13:10:07 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 681746.1060747; Thu, 15 Feb 2024 13:10: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 1rabV9-0005DY-AH; Thu, 15 Feb 2024 13:10:07 +0000 Received: by outflank-mailman (input) for mailman id 681746; Thu, 15 Feb 2024 13:10:05 +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 1rabRm-0002j3-5u for xen-devel@lists.xenproject.org; Thu, 15 Feb 2024 13:06: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 0c6cbca3-cc03-11ee-98f5-efadbce2ee36; Thu, 15 Feb 2024 14:06:36 +0100 (CET) Received: from imap2.dmz-prg2.suse.org (imap2.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:98]) (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 D600021FBC; Thu, 15 Feb 2024 13:06:35 +0000 (UTC) Received: from imap2.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 imap2.dmz-prg2.suse.org (Postfix) with ESMTPS id 9B76F139D0; Thu, 15 Feb 2024 13:06:35 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap2.dmz-prg2.suse.org with ESMTPSA id MOKXJFsMzmXCFQAAn2gu4w (envelope-from ); Thu, 15 Feb 2024 13:06:35 +0000 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: 0c6cbca3-cc03-11ee-98f5-efadbce2ee36 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1708002395; 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=jJ/RTfjmaHP3lqBxIj2S65NW4z+aqqiAB78+0Fnq5Fc=; b=hWcRbB4JuTMVGtIaoSBUy3a/+xeZfBrkALT1RXfzlaVEiY4Am8RNmNdF8EyTmMaqoKQh1q jMynNj7ZqXSoFAMcH5zDMJtlupoQFCdKcV20v6EaqKHcaPE2nPuaqo/eYypMWHyDHxK5g+ adFkVn+UTZ8EcqK8s37U/r096xYYasY= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1708002395; 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=jJ/RTfjmaHP3lqBxIj2S65NW4z+aqqiAB78+0Fnq5Fc=; b=hWcRbB4JuTMVGtIaoSBUy3a/+xeZfBrkALT1RXfzlaVEiY4Am8RNmNdF8EyTmMaqoKQh1q jMynNj7ZqXSoFAMcH5zDMJtlupoQFCdKcV20v6EaqKHcaPE2nPuaqo/eYypMWHyDHxK5g+ adFkVn+UTZ8EcqK8s37U/r096xYYasY= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Anthony PERARD , Jason Andryuk Subject: [PATCH v7 15/21] tools/xl: support new 9pfs backend xen_9pfsd Date: Thu, 15 Feb 2024 14:05:03 +0100 Message-Id: <20240215130509.24008-16-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240215130509.24008-1-jgross@suse.com> References: <20240215130509.24008-1-jgross@suse.com> MIME-Version: 1.0 Authentication-Results: smtp-out1.suse.de; dkim=pass header.d=suse.com header.s=susede1 header.b=hWcRbB4J X-Spamd-Result: default: False [1.69 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; R_DKIM_ALLOW(-0.20)[suse.com:s=susede1]; SPAMHAUS_XBL(0.00)[2a07:de40:b281:104:10:150:64:98:from]; 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)[]; BROKEN_CONTENT_TYPE(1.50)[]; DWL_DNSWL_BLOCKED(0.00)[suse.com:dkim]; RCPT_COUNT_FIVE(0.00)[5]; RCVD_COUNT_THREE(0.00)[3]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; DKIM_TRACE(0.00)[suse.com:+]; MX_GOOD(-0.01)[]; MID_CONTAINS_FROM(1.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[citrix.com:email,suse.com:dkim,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-Rspamd-Server: rspamd1.dmz-prg2.suse.org X-Rspamd-Queue-Id: D600021FBC X-Spamd-Bar: + 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 Reviewed-by: Anthony PERARD --- 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: =over 4 +=item B + +The backendtype for the PV device. Supported values are B and +B. The default is B. + =item B 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 defaults to +"Xen". =item B @@ -785,12 +791,38 @@ squash or remap). =item B -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/". =item B Specify the backend domain name or id, defaults to dom0. +=item 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. + +=item 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. + +=item B + +Specify the maximum used disk space in MiB below B. A value of 0 (which +is the default) doesn't limit the usable disk space. Only valid for +B. + +=item 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 the +file limit set via B is being reached. Only valid for +B. + =back =item B diff --git a/tools/libs/light/libxl_9pfs.c b/tools/libs/light/libxl_9pfs.c index 900c0d46a0..ddeb4f20a7 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 == LIBXL_P9_TYPE_UNKNOWN) { + p9->type = LIBXL_P9_TYPE_QEMU; + } + if (p9->type == 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 == LIBXL_P9_TYPE_XEN_9PFSD && !p9->tag) { + p9->tag = 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_domid); } 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 = parse_ulong(value); + } else if (!strcmp(key, "max-open-files")) { + p9->max_open_files = parse_ulong(value); + } else if (!strcmp(key, "max-space")) { + p9->max_space = parse_ulong(value); + } else if (!strcmp(key, "auto-delete")) { + p9->auto_delete = 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, libxl_string_list_dispose(&pairs); - if (!p9->path || !p9->security_model || !p9->tag) { - fprintf(stderr, "9pfs spec missing required field!\n"); - exit(1); + if (p9->type == 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); } } } From patchwork Thu Feb 15 13:05:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?SsO8cmdlbiBHcm/Dnw==?= X-Patchwork-Id: 13558361 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 74A97C4829E for ; Thu, 15 Feb 2024 13:09:47 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.681725.1060667 (Exim 4.92) (envelope-from ) id 1rabUi-0001ge-WC; Thu, 15 Feb 2024 13:09:41 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 681725.1060667; Thu, 15 Feb 2024 13:09: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 1rabUi-0001gX-S8; Thu, 15 Feb 2024 13:09:40 +0000 Received: by outflank-mailman (input) for mailman id 681725; Thu, 15 Feb 2024 13:09: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 1rabRq-0002yD-9T for xen-devel@lists.xenproject.org; Thu, 15 Feb 2024 13:06:42 +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 0fb82da1-cc03-11ee-8a4d-1f161083a0e0; Thu, 15 Feb 2024 14:06:41 +0100 (CET) Received: from imap2.dmz-prg2.suse.org (imap2.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:98]) (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 5934A1F8A4; Thu, 15 Feb 2024 13:06:41 +0000 (UTC) Received: from imap2.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 imap2.dmz-prg2.suse.org (Postfix) with ESMTPS id 2F783139D0; Thu, 15 Feb 2024 13:06:41 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap2.dmz-prg2.suse.org with ESMTPSA id hyQtCmEMzmXUFQAAn2gu4w (envelope-from ); Thu, 15 Feb 2024 13:06:41 +0000 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: 0fb82da1-cc03-11ee-8a4d-1f161083a0e0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1708002401; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/eJaaQzJFr9iaY84hbFZ6eF6VnkmvJwoY+5FWl4+J1Y=; b=jX3jfVxde2pVviIVT8uNiTW6GFTPiKpGpbzzIV/CuUotoF8slE/BAxdldseGn1C/rOUnQA VVyuQo93hbpTiLGPf+++ZbsQP3IW+wePe7GtwbpG9jMZK3zwt8IvGfE4+uv7Aud6ZkFhMP w8LRbnkiHuT0jiPW0y3m58lIyBnrd6w= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1708002401; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/eJaaQzJFr9iaY84hbFZ6eF6VnkmvJwoY+5FWl4+J1Y=; b=jX3jfVxde2pVviIVT8uNiTW6GFTPiKpGpbzzIV/CuUotoF8slE/BAxdldseGn1C/rOUnQA VVyuQo93hbpTiLGPf+++ZbsQP3IW+wePe7GtwbpG9jMZK3zwt8IvGfE4+uv7Aud6ZkFhMP w8LRbnkiHuT0jiPW0y3m58lIyBnrd6w= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Samuel Thibault , Jason Andryuk Subject: [PATCH v7 16/21] stubdom: extend xenstore stubdom configs Date: Thu, 15 Feb 2024 14:05:04 +0100 Message-Id: <20240215130509.24008-17-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240215130509.24008-1-jgross@suse.com> References: <20240215130509.24008-1-jgross@suse.com> MIME-Version: 1.0 Authentication-Results: smtp-out2.suse.de; dkim=pass header.d=suse.com header.s=susede1 header.b=jX3jfVxd X-Spamd-Result: default: False [3.69 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; R_DKIM_ALLOW(-0.20)[suse.com:s=susede1]; SPAMHAUS_XBL(0.00)[2a07:de40:b281:104:10:150:64:98:from]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_THREE(0.00)[4]; FREEMAIL_ENVRCPT(0.00)[gmail.com]; R_MISSING_CHARSET(2.50)[]; MIME_GOOD(-0.10)[text/plain]; TO_MATCH_ENVRCPT_ALL(0.00)[]; BROKEN_CONTENT_TYPE(1.50)[]; TO_DN_SOME(0.00)[]; RCVD_COUNT_THREE(0.00)[3]; DWL_DNSWL_BLOCKED(0.00)[suse.com:dkim]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; DKIM_TRACE(0.00)[suse.com:+]; MX_GOOD(-0.01)[]; MID_CONTAINS_FROM(1.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.com:dkim,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,ens-lyon.org,gmail.com]; RCVD_TLS_ALL(0.00)[]; BAYES_HAM(-1.00)[87.16%] X-Rspamd-Server: rspamd1.dmz-prg2.suse.org X-Rspamd-Queue-Id: 5934A1F8A4 X-Spamd-Bar: +++ 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=n CONFIG_FBFRONT=n CONFIG_KBDFRONT=n CONFIG_CONSFRONT=n -CONFIG_XENBUS=n CONFIG_LWIP=n +CONFIG_9PFRONT=y CONFIG_BALLOON=y XEN_INTERFACE_VERSION=__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=n CONFIG_FBFRONT=n CONFIG_KBDFRONT=n CONFIG_CONSFRONT=n -CONFIG_XENBUS=n CONFIG_LWIP=n +CONFIG_9PFRONT=y CONFIG_BALLOON=y XEN_INTERFACE_VERSION=__XEN_LATEST_INTERFACE_VERSION__ From patchwork Thu Feb 15 13:05:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?SsO8cmdlbiBHcm/Dnw==?= X-Patchwork-Id: 13558367 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id EC72AC4829E for ; Thu, 15 Feb 2024 13:10:06 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.681736.1060704 (Exim 4.92) (envelope-from ) id 1rabUz-0002rc-20; Thu, 15 Feb 2024 13:09:57 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 681736.1060704; Thu, 15 Feb 2024 13:09:56 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rabUy-0002pz-LQ; Thu, 15 Feb 2024 13:09:56 +0000 Received: by outflank-mailman (input) for mailman id 681736; Thu, 15 Feb 2024 13:09: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 1rabRv-0002yD-Vq for xen-devel@lists.xenproject.org; Thu, 15 Feb 2024 13:06:47 +0000 Received: from smtp-out1.suse.de (smtp-out1.suse.de [2a07:de40:b251:101:10:150:64:1]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 130f66a3-cc03-11ee-8a4d-1f161083a0e0; Thu, 15 Feb 2024 14:06:47 +0100 (CET) Received: from imap2.dmz-prg2.suse.org (imap2.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:98]) (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 EDA8C2218B; Thu, 15 Feb 2024 13:06:46 +0000 (UTC) Received: from imap2.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 imap2.dmz-prg2.suse.org (Postfix) with ESMTPS id BD91D139D0; Thu, 15 Feb 2024 13:06:46 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap2.dmz-prg2.suse.org with ESMTPSA id YX3WLGYMzmXdFQAAn2gu4w (envelope-from ); Thu, 15 Feb 2024 13:06:46 +0000 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: 130f66a3-cc03-11ee-8a4d-1f161083a0e0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1708002407; 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=t9xMwpWGoJR7DxJ7ry2LqpTZcYdrlw/DDzPveaCxkX4=; b=NWTV1O7+qMrKduemySPAi9pxEk50M8lXxylbztxDGFmIAC2mPVX9cfX8X4FcV0WQZV7yNT PptQ0VhwJusKelloetHOj+ZTb+loVj9DrhhfGjVmqsHXvZxslmKw5yo2QctiQNYxAIp2BB hSAJPpt6iyCPUmervLJZhEfGCtr0vq8= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1708002406; 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=t9xMwpWGoJR7DxJ7ry2LqpTZcYdrlw/DDzPveaCxkX4=; b=mGVNtHN0KEiBdxt0vQFpibpCKnOCj+9fkMUNaoUMoljhy4NNRLLV9f5dhxtCRinqpzcq2n S8EH6Wmy1gG0pH2yjv2lEAv1sL49QzJv04v5V2K4HDcL8TYPlvZ9BSwvG/m8gRxSU2sWjd 7jfmgz/QDs4Ez7QJH0DDc8usqZx3wdA= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Julien Grall , Anthony PERARD Subject: [PATCH v7 17/21] tools: add 9pfs device to xenstore-stubdom Date: Thu, 15 Feb 2024 14:05:05 +0100 Message-Id: <20240215130509.24008-18-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240215130509.24008-1-jgross@suse.com> References: <20240215130509.24008-1-jgross@suse.com> MIME-Version: 1.0 X-Spamd-Bar: +++ Authentication-Results: smtp-out1.suse.de; dkim=pass header.d=suse.com header.s=susede1 header.b=mGVNtHN0 X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Spamd-Result: default: False [3.49 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; R_DKIM_ALLOW(-0.20)[suse.com:s=susede1]; SPAMHAUS_XBL(0.00)[2a07:de40:b281:104:10:150:64:98:from]; 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]; 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]; DKIM_TRACE(0.00)[suse.com:+]; MX_GOOD(-0.01)[]; MID_CONTAINS_FROM(1.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.com:dkim,suse.com:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; NEURAL_HAM_SHORT(-0.20)[-1.000]; RCVD_TLS_ALL(0.00)[] X-Rspamd-Queue-Id: EDA8C2218B 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 = "Xen" - type = "xen_9pfsd" - path = "/var/lib/xen/xenstore" - security-model = "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-xenstore-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 = NULL; libxl_ctx *ctx; + libxl_device_p9 p9 = { .backend_domid = 0, + .tag = "Xen", + .path = XEN_LIB_DIR"/xenstore", + .security_model = "none", + .type = LIBXL_P9_TYPE_XEN_9PFSD, + }; while ( (opt = getopt_long(argc, argv, "v", options, NULL)) != -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); fd = creat(XEN_RUN_DIR "/xenstored.pid", 0666); diff --git a/tools/include/libxl.h b/tools/include/libxl.h index 9a3e702557..44a2205d2b 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, uint32_t domid, uint32_t backend, const libxl_asyncop_how *ao_how) LIBXL_EXTERNAL_CALLERS_ONLY; +/* 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 == 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 ddeb4f20a7..48f894f070 100644 --- a/tools/libs/light/libxl_9pfs.c +++ b/tools/libs/light/libxl_9pfs.c @@ -206,6 +206,22 @@ static void libxl__device_p9_add(libxl__egc *egc, uint32_t domid, aodev->callback(egc, aodev); } +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 = LIBXL__DEVICE_ACTION_ADD; + aodev->callback = 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 From patchwork Thu Feb 15 13:05:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?SsO8cmdlbiBHcm/Dnw==?= X-Patchwork-Id: 13558371 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B263EC48BEB for ; Thu, 15 Feb 2024 13:10:45 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.681767.1060767 (Exim 4.92) (envelope-from ) id 1rabVe-0007tg-A3; Thu, 15 Feb 2024 13:10:38 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 681767.1060767; Thu, 15 Feb 2024 13:10: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 1rabVe-0007tZ-6d; Thu, 15 Feb 2024 13:10:38 +0000 Received: by outflank-mailman (input) for mailman id 681767; Thu, 15 Feb 2024 13:10:37 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rabS2-0002j3-Of for xen-devel@lists.xenproject.org; Thu, 15 Feb 2024 13:06:54 +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 167399cd-cc03-11ee-98f5-efadbce2ee36; Thu, 15 Feb 2024 14:06:53 +0100 (CET) Received: from imap2.dmz-prg2.suse.org (imap2.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:98]) (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 AE2561F8A4; Thu, 15 Feb 2024 13:06:52 +0000 (UTC) Received: from imap2.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 imap2.dmz-prg2.suse.org (Postfix) with ESMTPS id 61994139D0; Thu, 15 Feb 2024 13:06:52 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap2.dmz-prg2.suse.org with ESMTPSA id KqoqFmwMzmXgFQAAn2gu4w (envelope-from ); Thu, 15 Feb 2024 13:06:52 +0000 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: 167399cd-cc03-11ee-98f5-efadbce2ee36 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1708002412; 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=GuKS5JMiiFYV782dbcVdzQvPQKcEtbDic1ZOTvla/ok=; b=kMLckWSFMkQtF6U6N8FrxhjleNVeWZgPEz8ruSgoyl1jSP1DgC53AHZ2HLN+hkBQVp6F30 qTX4MDM4DN0nPD/+frTaYS+7m4+deVLbHPpj3nnOf3GS7Y+AlBs9bF8AsTLS6hwheSJa24 2vFPHRGzssljphMjQnmavCaJHsf7r8U= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1708002412; 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=GuKS5JMiiFYV782dbcVdzQvPQKcEtbDic1ZOTvla/ok=; b=kMLckWSFMkQtF6U6N8FrxhjleNVeWZgPEz8ruSgoyl1jSP1DgC53AHZ2HLN+hkBQVp6F30 qTX4MDM4DN0nPD/+frTaYS+7m4+deVLbHPpj3nnOf3GS7Y+AlBs9bF8AsTLS6hwheSJa24 2vFPHRGzssljphMjQnmavCaJHsf7r8U= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Julien Grall , Anthony PERARD , Jason Andryuk , Julien Grall Subject: [PATCH v7 18/21] tools/xenstored: mount 9pfs device in stubdom Date: Thu, 15 Feb 2024 14:05:06 +0100 Message-Id: <20240215130509.24008-19-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240215130509.24008-1-jgross@suse.com> References: <20240215130509.24008-1-jgross@suse.com> MIME-Version: 1.0 Authentication-Results: smtp-out2.suse.de; dkim=pass header.d=suse.com header.s=susede1 header.b=kMLckWSF X-Spamd-Result: default: False [1.69 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; R_DKIM_ALLOW(-0.20)[suse.com:s=susede1]; SPAMHAUS_XBL(0.00)[2a07:de40:b281:104:10:150:64:98:from]; 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)[]; BROKEN_CONTENT_TYPE(1.50)[]; DWL_DNSWL_BLOCKED(0.00)[suse.com:dkim]; RCVD_COUNT_THREE(0.00)[3]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; DKIM_TRACE(0.00)[suse.com:+]; MX_GOOD(-0.01)[]; RCPT_COUNT_SEVEN(0.00)[7]; MID_CONTAINS_FROM(1.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.com:dkim,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-Rspamd-Server: rspamd1.dmz-prg2.suse.org X-Rspamd-Queue-Id: AE2561F8A4 X-Spamd-Bar: + 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" +#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); +#ifdef __MINIOS__ +void mount_9pfs(void); +#endif + /* Close stdin/stdout/stderr to complete daemonize */ void finish_daemonize(void); 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"); xenevtchn_notify(xce_handle, stubdom->port); + + mount_9pfs(); #endif } 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; 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 = NULL; + char *err; + char *dummy; + + err = 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 = xenbus_read(XBT_NIL, P9_STATE_PATH, &dummy); + if (!err) + break; + free(err); + } + + free(dummy); + + err = 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 = init_9pfront(0, XENSTORE_LIB_DIR); +} + +void mount_9pfs(void) +{ + create_thread("mount-9pfs", mount_thread, NULL); +} From patchwork Thu Feb 15 13:05:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?SsO8cmdlbiBHcm/Dnw==?= X-Patchwork-Id: 13558364 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 34F04C48BF0 for ; Thu, 15 Feb 2024 13:10:04 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.681731.1060677 (Exim 4.92) (envelope-from ) id 1rabUx-0002O0-Bm; Thu, 15 Feb 2024 13:09:55 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 681731.1060677; Thu, 15 Feb 2024 13:09:55 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rabUx-0002Nt-7Y; Thu, 15 Feb 2024 13:09:55 +0000 Received: by outflank-mailman (input) for mailman id 681731; Thu, 15 Feb 2024 13:09:53 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rabS8-0002j3-IQ for xen-devel@lists.xenproject.org; Thu, 15 Feb 2024 13:07:00 +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 19d40f09-cc03-11ee-98f5-efadbce2ee36; Thu, 15 Feb 2024 14:06:58 +0100 (CET) Received: from imap2.dmz-prg2.suse.org (imap2.dmz-prg2.suse.org [10.150.64.98]) (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 5FFC62218B; Thu, 15 Feb 2024 13:06:58 +0000 (UTC) Received: from imap2.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 imap2.dmz-prg2.suse.org (Postfix) with ESMTPS id 17AB9139D0; Thu, 15 Feb 2024 13:06:58 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap2.dmz-prg2.suse.org with ESMTPSA id aBk4BHIMzmXlFQAAn2gu4w (envelope-from ); Thu, 15 Feb 2024 13:06:58 +0000 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: 19d40f09-cc03-11ee-98f5-efadbce2ee36 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1708002418; 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=xUq3AE+SsnVI0DjnPSJQwNriZRE6cVmY47vrUqUrQuc=; b=Z8GQHXYLcYMI+4d3BxocWdQ8ugWSTSeWig17x3hZy+1S6u9hFchxBjqrSZsr5C9eaiV2GW C5/0N5G8dVorAaUWLstuJaFqhJOgtdNX5t6qsPxa6N/TM95D43h3U7zeYWHP+JHj/pcHK2 u92XgSkHq/3h1qP4xXb37nwmG5WPSxU= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1708002418; 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=xUq3AE+SsnVI0DjnPSJQwNriZRE6cVmY47vrUqUrQuc=; b=Z8GQHXYLcYMI+4d3BxocWdQ8ugWSTSeWig17x3hZy+1S6u9hFchxBjqrSZsr5C9eaiV2GW C5/0N5G8dVorAaUWLstuJaFqhJOgtdNX5t6qsPxa6N/TM95D43h3U7zeYWHP+JHj/pcHK2 u92XgSkHq/3h1qP4xXb37nwmG5WPSxU= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Julien Grall , Anthony PERARD , Jason Andryuk , Julien Grall Subject: [PATCH v7 19/21] tools/xenstored: add helpers for filename handling Date: Thu, 15 Feb 2024 14:05:07 +0100 Message-Id: <20240215130509.24008-20-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240215130509.24008-1-jgross@suse.com> References: <20240215130509.24008-1-jgross@suse.com> MIME-Version: 1.0 Authentication-Results: smtp-out1.suse.de; none X-Spamd-Result: default: False [0.70 / 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)[]; 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%] 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 = -1; bool keep_orphans = false; -char *tracefile = NULL; +const char *tracefile = NULL; static struct hashtable *nodes; unsigned int trace_flags = TRACE_OBJ | TRACE_IO; @@ -137,6 +137,17 @@ void trace_destroy(const void *data, const char *type) trace("obj: DESTROY %s %p\n", type, data); } +/* + * 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] != '/') + return talloc_asprintf(ctx, XENSTORE_LIB_DIR "/%s", filename); + return talloc_strdup(ctx, filename); +} + void close_log(void) { if (tracefd >= 0) @@ -2759,7 +2770,7 @@ int main(int argc, char *argv[]) #endif if (tracefile) - tracefile = talloc_strdup(NULL, tracefile); + tracefile = absolute_filename(NULL, tracefile); #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; -extern char *tracefile; +extern const char *tracefile; extern int tracefd; /* 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 +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); 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 = 0; state->filename = talloc_asprintf(NULL, "%s/state_dump", - xenstore_daemon_rundir()); + xenstore_rundir()); if (!state->filename) barf("Allocation failure"); @@ -65,7 +65,7 @@ FILE *lu_dump_open(const void *ctx) int fd; filename = talloc_asprintf(ctx, "%s/state_dump", - xenstore_daemon_rundir()); + xenstore_rundir()); if (!filename) return NULL; 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 char *pidfile) { reopen_log(); - /* 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); if (dofork) { openlog("xenstored", 0, LOG_DAEMON); @@ -406,3 +407,8 @@ void set_socket_fd(int fd) { sock = fd; } + +const char *xenstore_rundir(void) +{ + return xenstore_daemon_rundir(); +} From patchwork Thu Feb 15 13:05:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?SsO8cmdlbiBHcm/Dnw==?= X-Patchwork-Id: 13558359 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 550CDC4829E for ; Thu, 15 Feb 2024 13:09:14 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.681713.1060647 (Exim 4.92) (envelope-from ) id 1rabUA-00008n-E6; Thu, 15 Feb 2024 13:09:06 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 681713.1060647; Thu, 15 Feb 2024 13:09: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 1rabUA-00008g-B4; Thu, 15 Feb 2024 13:09:06 +0000 Received: by outflank-mailman (input) for mailman id 681713; Thu, 15 Feb 2024 13:09:05 +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 1rabSG-0002j3-64 for xen-devel@lists.xenproject.org; Thu, 15 Feb 2024 13:07: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 1e6ceba8-cc03-11ee-98f5-efadbce2ee36; Thu, 15 Feb 2024 14:07:06 +0100 (CET) Received: from imap2.dmz-prg2.suse.org (imap2.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:98]) (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 1069221FBC; Thu, 15 Feb 2024 13:07:04 +0000 (UTC) Received: from imap2.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 imap2.dmz-prg2.suse.org (Postfix) with ESMTPS id C0A7D139D0; Thu, 15 Feb 2024 13:07:03 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap2.dmz-prg2.suse.org with ESMTPSA id gvdYLXcMzmXnFQAAn2gu4w (envelope-from ); Thu, 15 Feb 2024 13:07:03 +0000 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: 1e6ceba8-cc03-11ee-98f5-efadbce2ee36 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1708002426; 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=mx+xsXHmP+kMTvkOl3Dx/uX2x1DBpbeqqzrtIUR5SLs=; b=CXaDg2Ov5Npo6W35bdMbfKhQ13AC06etHiojWIjbj3eOLo8wndkIGzHojJ/kJ3iWvUoVow F4nct+l1bc5YGv8OwlKb4vttk9asIBbgAubrUd2iE7DYvZHdiKK3sJ6uaTJU3V4xeteWG5 At0ltHM15EHCGELZM/C5JaDs5VWj74M= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1708002424; 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=mx+xsXHmP+kMTvkOl3Dx/uX2x1DBpbeqqzrtIUR5SLs=; b=TZu9bZybVfoUrF4bOMVjZJFqR1YgDa3ugxAjBUJRms6AFO3LpQaZphxTQyvgmy5/hBukCx v0FMnG65xSbfFOBQBwxPMTkl6yrouOhuOIquQ4daPmLOx2XJb9bilNHuUiXROBoT90e87k IY+cjPrlOQlW3NwcnXN2W+hcRFRHIik= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Anthony PERARD , Julien Grall , Jason Andryuk , Julien Grall Subject: [PATCH v7 20/21] tools/xenstored: support complete log capabilities in stubdom Date: Thu, 15 Feb 2024 14:05:08 +0100 Message-Id: <20240215130509.24008-21-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240215130509.24008-1-jgross@suse.com> References: <20240215130509.24008-1-jgross@suse.com> MIME-Version: 1.0 X-Spamd-Bar: / Authentication-Results: smtp-out1.suse.de; dkim=pass header.d=suse.com header.s=susede1 header.b=TZu9bZyb X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Spamd-Result: default: False [0.49 / 50.00]; RCVD_VIA_SMTP_AUTH(0.00)[]; SPAMHAUS_XBL(0.00)[2a07:de40:b281:104:10:150:64:98:from]; TO_DN_SOME(0.00)[]; R_MISSING_CHARSET(2.50)[]; BROKEN_CONTENT_TYPE(1.50)[]; RCVD_COUNT_THREE(0.00)[3]; DKIM_TRACE(0.00)[suse.com:+]; MX_GOOD(-0.01)[]; RCPT_COUNT_SEVEN(0.00)[7]; NEURAL_HAM_SHORT(-0.20)[-1.000]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; BAYES_HAM(-3.00)[100.00%]; ARC_NA(0.00)[]; R_DKIM_ALLOW(-0.20)[suse.com:s=susede1]; FROM_HAS_DN(0.00)[]; FREEMAIL_ENVRCPT(0.00)[gmail.com]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; NEURAL_HAM_LONG(-1.00)[-1.000]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; MID_CONTAINS_FROM(1.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[xencommons.in:url,suse.com:dkim,suse.com:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; FREEMAIL_CC(0.00)[suse.com,xen.org,citrix.com,gmail.com,amazon.com]; RCVD_TLS_ALL(0.00)[] X-Rspamd-Queue-Id: 1069221FBC 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/hotplug/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= ## Default: Not defined, tracing off # # Log xenstored messages -# Only evaluated if XENSTORETYPE is "daemon". #XENSTORED_TRACE=[yes|on|1] ## Type: integer diff --git a/tools/hotplug/Linux/launch-xenstore.in b/tools/hotplug/Linux/launch-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 && . @CONFIG_DIR@/@CONFIG_LEAF [ -z "$XENSTORE_DOMAIN_SIZE" ] && XENSTORE_DOMAIN_SIZE=8 XENSTORE_DOMAIN_ARGS="$XENSTORE_DOMAIN_ARGS --memory $XENSTORE_DOMAIN_SIZE" [ -z "$XENSTORE_MAX_DOMAIN_SIZE" ] || XENSTORE_DOMAIN_ARGS="$XENSTORE_DOMAIN_ARGS --maxmem $XENSTORE_MAX_DOMAIN_SIZE" + [ -z "$XENSTORED_TRACE" ] || XENSTORE_DOMAIN_ARGS="$XENSTORE_DOMAIN_ARGS -T xenstored-trace.log" 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; } -#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, close_log(); talloc_free(tracefile); - tracefile = talloc_strdup(NULL, vec[0]); + tracefile = absolute_filename(NULL, vec[0]); reopen_log(); send_ack(conn, XS_CONTROL); return 0; } +#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[] = { "[-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) } p9_device = init_9pfront(0, XENSTORE_LIB_DIR); + + /* Start logging if selected. */ + reopen_log(); } void mount_9pfs(void) From patchwork Thu Feb 15 13:05:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?SsO8cmdlbiBHcm/Dnw==?= X-Patchwork-Id: 13558365 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E6CDDC48BEB for ; Thu, 15 Feb 2024 13:10:03 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.681737.1060707 (Exim 4.92) (envelope-from ) id 1rabUz-0002z3-Cw; Thu, 15 Feb 2024 13:09:57 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 681737.1060707; Thu, 15 Feb 2024 13:09:57 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rabUz-0002u1-20; Thu, 15 Feb 2024 13:09:57 +0000 Received: by outflank-mailman (input) for mailman id 681737; Thu, 15 Feb 2024 13:09:54 +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 1rabSI-0002yD-OM for xen-devel@lists.xenproject.org; Thu, 15 Feb 2024 13:07:10 +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 20a66eb0-cc03-11ee-8a4d-1f161083a0e0; Thu, 15 Feb 2024 14:07:10 +0100 (CET) Received: from imap2.dmz-prg2.suse.org (imap2.dmz-prg2.suse.org [10.150.64.98]) (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 BBDC821FBC; Thu, 15 Feb 2024 13:07:09 +0000 (UTC) Received: from imap2.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 imap2.dmz-prg2.suse.org (Postfix) with ESMTPS id 7B051139EF; Thu, 15 Feb 2024 13:07:09 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap2.dmz-prg2.suse.org with ESMTPSA id f+tTHH0MzmXxFQAAn2gu4w (envelope-from ); Thu, 15 Feb 2024 13:07:09 +0000 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: 20a66eb0-cc03-11ee-8a4d-1f161083a0e0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1708002429; 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=GGQ2M6ZDlC8Q8t5jjlaB/u1rTlT60Df0gemVV+Z+fCo=; b=PaWTl29bD7UBwuZ7U9ILETzd1RNJoYjgX1vV3RcGNRiNtH16bn+c97WnFrskzNo/znmat4 WD6nIcchxCQt8p6QlFbidr/SnoUdlgbJyX7Ivkk0C6MxShazKbwE85bww7RVmFcvl2gTPW Rr5PsDTOALvCQhXHKuMk+EnV+YdktHE= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1708002429; 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=GGQ2M6ZDlC8Q8t5jjlaB/u1rTlT60Df0gemVV+Z+fCo=; b=PaWTl29bD7UBwuZ7U9ILETzd1RNJoYjgX1vV3RcGNRiNtH16bn+c97WnFrskzNo/znmat4 WD6nIcchxCQt8p6QlFbidr/SnoUdlgbJyX7Ivkk0C6MxShazKbwE85bww7RVmFcvl2gTPW Rr5PsDTOALvCQhXHKuMk+EnV+YdktHE= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Julien Grall , Anthony PERARD , Jason Andryuk Subject: [PATCH v7 21/21] tools/xenstored: have a single do_control_memreport() Date: Thu, 15 Feb 2024 14:05:09 +0100 Message-Id: <20240215130509.24008-22-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240215130509.24008-1-jgross@suse.com> References: <20240215130509.24008-1-jgross@suse.com> MIME-Version: 1.0 Authentication-Results: smtp-out1.suse.de; none X-Spamd-Result: default: False [3.69 / 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)[]; BROKEN_CONTENT_TYPE(1.50)[]; RCPT_COUNT_FIVE(0.00)[6]; 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(-0.01)[45.67%] 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; } -#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; if (num > 1) @@ -255,8 +243,12 @@ static int do_control_memreport(const void *ctx, struct connection *conn, if (!fp) close(fd); } - } else - fp = fopen(vec[0], "a"); + } else { + filename = absolute_filename(ctx, vec[0]); + if (!filename) + return ENOMEM; + fp = fopen(filename, "a"); + } 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 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[] = { " 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]]" },