From: Kohei Tokunaga <ktokunaga.mail@gmail.com>
To: qemu-devel@nongnu.org
Cc: "Alex Bennée" <alex.bennee@linaro.org>,
"Philippe Mathieu-Daudé" <philmd@linaro.org>,
"Thomas Huth" <thuth@redhat.com>,
"Richard Henderson" <richard.henderson@linaro.org>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Kevin Wolf" <kwolf@redhat.com>,
"Hanna Reitz" <hreitz@redhat.com>,
"Kohei Tokunaga" <ktokunaga.mail@gmail.com>,
"Christian Schoenebeck" <qemu_oss@crudebyte.com>,
"Greg Kurz" <groug@kaod.org>,
"Palmer Dabbelt" <palmer@dabbelt.com>,
"Alistair Francis" <alistair.francis@wdc.com>,
"Weiwei Li" <liwei1518@gmail.com>,
"Daniel Henrique Barboza" <dbarboza@ventanamicro.com>,
"Liu Zhiwei" <zhiwei_liu@linux.alibaba.com>,
"Marc-André Lureau" <marcandre.lureau@redhat.com>,
"Daniel P . Berrangé" <berrange@redhat.com>,
"Eduardo Habkost" <eduardo@habkost.net>,
"Peter Maydell" <peter.maydell@linaro.org>,
"Stefan Hajnoczi" <stefanha@redhat.com>,
qemu-block@nongnu.org, qemu-riscv@nongnu.org,
qemu-arm@nongnu.org
Subject: [PATCH 08/10] hw/9pfs: Allow using hw/9pfs with emscripten
Date: Mon, 7 Apr 2025 23:45:59 +0900 [thread overview]
Message-ID: <16376e4b63fad6f847ceadb39b8f9780fc288198.1744032780.git.ktokunaga.mail@gmail.com> (raw)
In-Reply-To: <cover.1744032780.git.ktokunaga.mail@gmail.com>
Emscripten's fiber does not support submitting coroutines to other
threads. So this commit modifies hw/9pfs/coth.h to disable this behavior
when compiled with Emscripten.
Signed-off-by: Kohei Tokunaga <ktokunaga.mail@gmail.com>
---
fsdev/file-op-9p.h | 3 +++
fsdev/meson.build | 2 +-
hw/9pfs/9p-util-stub.c | 43 ++++++++++++++++++++++++++++++++++++++++++
hw/9pfs/9p-util.h | 18 ++++++++++++++++++
hw/9pfs/9p.c | 3 +++
hw/9pfs/coth.h | 12 ++++++++++++
hw/9pfs/meson.build | 2 ++
meson.build | 6 +++---
8 files changed, 85 insertions(+), 4 deletions(-)
create mode 100644 hw/9pfs/9p-util-stub.c
diff --git a/fsdev/file-op-9p.h b/fsdev/file-op-9p.h
index 4997677460..b7ca2640ce 100644
--- a/fsdev/file-op-9p.h
+++ b/fsdev/file-op-9p.h
@@ -26,6 +26,9 @@
# include <sys/param.h>
# include <sys/mount.h>
#endif
+#ifdef EMSCRIPTEN
+#include <sys/vfs.h>
+#endif
#define SM_LOCAL_MODE_BITS 0600
#define SM_LOCAL_DIR_MODE_BITS 0700
diff --git a/fsdev/meson.build b/fsdev/meson.build
index c751d8cb62..c3e92a29d7 100644
--- a/fsdev/meson.build
+++ b/fsdev/meson.build
@@ -5,6 +5,6 @@ fsdev_ss.add(when: ['CONFIG_FSDEV_9P'], if_true: files(
'9p-marshal.c',
'qemu-fsdev.c',
), if_false: files('qemu-fsdev-dummy.c'))
-if host_os in ['linux', 'darwin']
+if host_os in ['linux', 'darwin', 'emscripten']
system_ss.add_all(fsdev_ss)
endif
diff --git a/hw/9pfs/9p-util-stub.c b/hw/9pfs/9p-util-stub.c
new file mode 100644
index 0000000000..57c89902ab
--- /dev/null
+++ b/hw/9pfs/9p-util-stub.c
@@ -0,0 +1,43 @@
+/*
+ * 9p utilities stub functions
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "qemu/osdep.h"
+#include "9p-util.h"
+
+ssize_t fgetxattrat_nofollow(int dirfd, const char *path, const char *name,
+ void *value, size_t size)
+{
+ return -1;
+}
+
+ssize_t flistxattrat_nofollow(int dirfd, const char *filename,
+ char *list, size_t size)
+{
+ return -1;
+}
+
+ssize_t fremovexattrat_nofollow(int dirfd, const char *filename,
+ const char *name)
+{
+ return -1;
+}
+
+int fsetxattrat_nofollow(int dirfd, const char *path, const char *name,
+ void *value, size_t size, int flags)
+{
+ return -1;
+
+}
+
+int qemu_mknodat(int dirfd, const char *filename, mode_t mode, dev_t dev)
+{
+ return -1;
+}
+
+ssize_t fgetxattr(int fd, const char *name, void *value, size_t size)
+{
+ return -1;
+}
diff --git a/hw/9pfs/9p-util.h b/hw/9pfs/9p-util.h
index 7bc4ec8e85..8c5006fcdc 100644
--- a/hw/9pfs/9p-util.h
+++ b/hw/9pfs/9p-util.h
@@ -84,6 +84,24 @@ static inline int errno_to_dotl(int err) {
} else if (err == EOPNOTSUPP) {
err = 95; /* ==EOPNOTSUPP on Linux */
}
+#elif defined(EMSCRIPTEN)
+ /*
+ * FIXME: Only most important errnos translated here yet, this should be
+ * extended to as many errnos being translated as possible in future.
+ */
+ if (err == ENAMETOOLONG) {
+ err = 36; /* ==ENAMETOOLONG on Linux */
+ } else if (err == ENOTEMPTY) {
+ err = 39; /* ==ENOTEMPTY on Linux */
+ } else if (err == ELOOP) {
+ err = 40; /* ==ELOOP on Linux */
+ } else if (err == ENODATA) {
+ err = 61; /* ==ENODATA on Linux */
+ } else if (err == ENOTSUP) {
+ err = 95; /* ==EOPNOTSUPP on Linux */
+ } else if (err == EOPNOTSUPP) {
+ err = 95; /* ==EOPNOTSUPP on Linux */
+ }
#else
#error Missing errno translation to Linux for this host system
#endif
diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c
index 7cad2bce62..4f45f0edd3 100644
--- a/hw/9pfs/9p.c
+++ b/hw/9pfs/9p.c
@@ -4013,6 +4013,9 @@ out_nofid:
* Linux guests.
*/
#define P9_XATTR_SIZE_MAX 65536
+#elif defined(EMSCRIPTEN)
+/* No support for xattr */
+#define P9_XATTR_SIZE_MAX 0
#else
#error Missing definition for P9_XATTR_SIZE_MAX for this host system
#endif
diff --git a/hw/9pfs/coth.h b/hw/9pfs/coth.h
index 2c54249b35..7b0d05ba1b 100644
--- a/hw/9pfs/coth.h
+++ b/hw/9pfs/coth.h
@@ -19,6 +19,7 @@
#include "qemu/coroutine-core.h"
#include "9p.h"
+#ifndef EMSCRIPTEN
/*
* we want to use bottom half because we want to make sure the below
* sequence of events.
@@ -57,6 +58,17 @@
/* re-enter back to qemu thread */ \
qemu_coroutine_yield(); \
} while (0)
+#else
+/*
+ * FIXME: implement this on emscripten but emscripten's coroutine
+ * implementation (fiber) doesn't support submitting a coroutine to other
+ * threads.
+ */
+#define v9fs_co_run_in_worker(code_block) \
+ do { \
+ code_block; \
+ } while (0)
+#endif
void co_run_in_worker_bh(void *);
int coroutine_fn v9fs_co_readlink(V9fsPDU *, V9fsPath *, V9fsString *);
diff --git a/hw/9pfs/meson.build b/hw/9pfs/meson.build
index d35d4f44ff..04f85fb9e9 100644
--- a/hw/9pfs/meson.build
+++ b/hw/9pfs/meson.build
@@ -17,6 +17,8 @@ if host_os == 'darwin'
fs_ss.add(files('9p-util-darwin.c'))
elif host_os == 'linux'
fs_ss.add(files('9p-util-linux.c'))
+elif host_os == 'emscripten'
+ fs_ss.add(files('9p-util-stub.c'))
endif
fs_ss.add(when: 'CONFIG_XEN_BUS', if_true: files('xen-9p-backend.c'))
system_ss.add_all(when: 'CONFIG_FSDEV_9P', if_true: fs_ss)
diff --git a/meson.build b/meson.build
index ab84820bc5..a3aadf8b59 100644
--- a/meson.build
+++ b/meson.build
@@ -2356,11 +2356,11 @@ dbus_display = get_option('dbus_display') \
.allowed()
have_virtfs = get_option('virtfs') \
- .require(host_os == 'linux' or host_os == 'darwin',
+ .require(host_os == 'linux' or host_os == 'darwin' or host_os == 'emscripten',
error_message: 'virtio-9p (virtfs) requires Linux or macOS') \
- .require(host_os == 'linux' or cc.has_function('pthread_fchdir_np'),
+ .require(host_os == 'linux' or host_os == 'emscripten' or cc.has_function('pthread_fchdir_np'),
error_message: 'virtio-9p (virtfs) on macOS requires the presence of pthread_fchdir_np') \
- .require(host_os == 'darwin' or libattr.found(),
+ .require(host_os == 'darwin' or host_os == 'emscripten' or libattr.found(),
error_message: 'virtio-9p (virtfs) on Linux requires libattr-devel') \
.disable_auto_if(not have_tools and not have_system) \
.allowed()
--
2.25.1
next prev parent reply other threads:[~2025-04-07 15:15 UTC|newest]
Thread overview: 46+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-07 14:45 [PATCH 00/10] Enable QEMU to run on browsers Kohei Tokunaga
2025-04-07 14:45 ` [PATCH 01/10] various: Fix type conflict of GLib function pointers Kohei Tokunaga
2025-04-09 10:54 ` Philippe Mathieu-Daudé
2025-04-09 13:43 ` Kohei Tokunaga
2025-04-10 15:58 ` Paolo Bonzini
2025-04-11 10:55 ` Kohei Tokunaga
2025-04-07 14:45 ` [PATCH 02/10] various: Define macros for dependencies on emscripten Kohei Tokunaga
2025-04-10 15:53 ` Paolo Bonzini
2025-04-11 10:59 ` Kohei Tokunaga
2025-04-07 14:45 ` [PATCH 03/10] util/mmap-alloc: Add qemu_ram_mmap implementation for emscripten Kohei Tokunaga
2025-04-07 14:45 ` [PATCH 04/10] util: Add coroutine backend " Kohei Tokunaga
2025-04-07 14:45 ` [PATCH 05/10] meson: Add wasm build in build scripts Kohei Tokunaga
2025-04-09 10:55 ` Philippe Mathieu-Daudé
2025-04-09 13:35 ` Paolo Bonzini
2025-04-10 12:24 ` Kohei Tokunaga
2025-04-10 12:55 ` Paolo Bonzini
2025-04-11 11:23 ` Kohei Tokunaga
2025-04-07 14:45 ` [PATCH 06/10] include/exec: Allow using 64bit guest addresses on emscripten Kohei Tokunaga
2025-04-07 14:45 ` [PATCH 07/10] tcg: Add a TCG backend for WebAssembly Kohei Tokunaga
2025-04-09 10:58 ` Philippe Mathieu-Daudé
2025-04-09 13:53 ` Kohei Tokunaga
2025-04-11 10:50 ` Philippe Mathieu-Daudé
2025-04-12 9:04 ` Kohei Tokunaga
2025-04-12 9:12 ` Kohei Tokunaga
2025-04-07 14:45 ` Kohei Tokunaga [this message]
2025-04-10 11:27 ` [PATCH 08/10] hw/9pfs: Allow using hw/9pfs with emscripten Christian Schoenebeck
2025-04-11 10:47 ` Kohei Tokunaga
2025-04-12 8:21 ` Christian Schoenebeck
2025-04-12 10:21 ` Christian Schoenebeck
2025-04-12 10:38 ` Christian Schoenebeck
2025-04-13 8:12 ` Kohei Tokunaga
2025-04-10 16:29 ` Paolo Bonzini
2025-04-11 14:03 ` Kohei Tokunaga
2025-04-07 14:46 ` [PATCH 09/10] gitlab: Enable CI for wasm build Kohei Tokunaga
2025-04-07 14:46 ` [PATCH 10/10] MAINTAINERS: Update MAINTAINERS file for wasm-related files Kohei Tokunaga
2025-04-09 19:21 ` [PATCH 00/10] Enable QEMU to run on browsers Stefan Hajnoczi
2025-04-10 12:20 ` Philippe Mathieu-Daudé
2025-04-10 13:11 ` Kohei Tokunaga
2025-04-10 13:13 ` Kohei Tokunaga
2025-04-10 21:17 ` Pierrick Bouvier
2025-04-11 14:36 ` Kohei Tokunaga
2025-04-11 15:28 ` Pierrick Bouvier
2025-04-11 9:07 ` Paolo Bonzini
2025-04-11 14:41 ` Kohei Tokunaga
2025-04-11 10:34 ` Daniel P. Berrangé
2025-04-11 15:17 ` Kohei Tokunaga
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=16376e4b63fad6f847ceadb39b8f9780fc288198.1744032780.git.ktokunaga.mail@gmail.com \
--to=ktokunaga.mail@gmail.com \
--cc=alex.bennee@linaro.org \
--cc=alistair.francis@wdc.com \
--cc=berrange@redhat.com \
--cc=dbarboza@ventanamicro.com \
--cc=eduardo@habkost.net \
--cc=groug@kaod.org \
--cc=hreitz@redhat.com \
--cc=kwolf@redhat.com \
--cc=liwei1518@gmail.com \
--cc=marcandre.lureau@redhat.com \
--cc=palmer@dabbelt.com \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=philmd@linaro.org \
--cc=qemu-arm@nongnu.org \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=qemu-riscv@nongnu.org \
--cc=qemu_oss@crudebyte.com \
--cc=richard.henderson@linaro.org \
--cc=stefanha@redhat.com \
--cc=thuth@redhat.com \
--cc=zhiwei_liu@linux.alibaba.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).