9p: Add support for darwin
v4 cover 9p: Add support for darwin
This is a followup to https://lists.nongnu.org/archive/html/qemu-devel/2022-01/msg05993.html,
adding 9p server support for Darwin.
Since v3, the following changes have been made:
- Move XATTR_SIZE_MAX to P9_XATTR_SIZE MAX in 9p.h, and provide explanatory context as preliminary solution
- Add explanatory note surrounding virtio-9p-test with output of pre-patch failing test
- Remove superfluous header guards from file-opt-9p
- Add note about virtfs-proxy-helper being disabled on non-linux for this patch series
- Note radar filed with Apple for missing mknodat syscall
- Replace direct syscall to pthread_fchdir with pthread_fchdir_np, and add check for this function’s presence in meson
- Ensure that d_seekoff is filled using telldir on darwin, and create qemu_dirent_off helper to decide which to access.
- Ensure that [amc]tim.tv_sec are all initialized alongside [amc]tim.tv_nsec in 9p-proxy
- Ensure that all patch email addresses are valid
- Add telldir error handling for dirent on darwin
Keno Fischer (10):
9p: linux: Fix a couple Linux assumptions 9p: Rename 9p-util -> 9p-util-linux
9p: darwin: Handle struct stat(fs) differences 9p: darwin: Handle struct dirent differences 9p: darwin: Ignore O_{NOATIME, DIRECT}
9p: darwin: Move XATTR_SIZE_MAX->P9_XATTR_SIZE_MAX 9p: darwin: *xattr_nofollow implementations 9p: darwin: Compatibility for f/l*xattr 9p: darwin: Implement compatibility for mknodat 9p: darwin: meson: Allow VirtFS on Darwin
Will Cohen (1):
9p: darwin: Adjust assumption on virtio-9p-test
fsdev/file-op-9p.h | 9 ++-
fsdev/meson.build | 1 +
hw/9pfs/9p-local.c | 28 ++++++--
hw/9pfs/9p-proxy.c | 38 ++++++++++-
hw/9pfs/9p-synth.c | 6 ++
hw/9pfs/9p-util-darwin.c | 91 ++++++++++++++++++++++++++
hw/9pfs/{9p-util.c => 9p-util-linux.c} | 7 +-
hw/9pfs/9p-util.h | 38 +++++++++++
hw/9pfs/9p.c | 50 ++++++++++++--
hw/9pfs/9p.h | 11 ++++
hw/9pfs/codir.c | 7 ++
hw/9pfs/meson.build | 3 +-
include/qemu/xattr.h | 4 +-
meson.build | 14 ++--
tests/qtest/virtio-9p-test.c | 2 +-
15 files changed, 285 insertions(+), 24 deletions(-)
create mode 100644 hw/9pfs/9p-util-darwin.c
rename hw/9pfs/{9p-util.c => 9p-util-linux.c} (90%)Signature · 1 line
2.32.0 (Apple Git-132)
PATCH v4 1/11 9p: linux: Fix a couple Linux assumptions
From: Keno Fischer <[email protected]>
- Guard Linux only headers.
- Add qemu/statfs.h header to abstract over the which headers are needed for struct statfs
- Define ENOATTR only if not only defined (it's defined in system headers on Darwin).
While it might at first appear that fsdev/virtfs-proxy-header.c would need similar adjustment for darwin as file-op-9p here, a later patch in this series disables virtfs-proxy-helper for non-Linux. Allowing virtfs-proxy-helper on darwin could potentially be an additional optimization later.
[Will Cohen: - Fix headers for Alpine
- Integrate statfs.h back into file-op-9p.h
- Remove superfluous header guards from file-opt-9p
- Add note about virtfs-proxy-helper being disabled on non-Linux for this patch series]
--- fsdev/file-op-9p.h | 9 ++++++++- hw/9pfs/9p-local.c | 2 ++ hw/9pfs/9p.c | 4 ++++ include/qemu/xattr.h | 4 +++- 4 files changed, 17 insertions(+), 2 deletions(-)
fsdev/file-op-9p.h +8 -1
@@ -16,10 +16,17 @@#include <dirent.h> #include <utime.h> -#include <sys/vfs.h> #include "qemu-fsdev-throttle.h" #include "p9array.h" +#ifdef CONFIG_LINUX +# include <sys/vfs.h> +#endif +#ifdef CONFIG_DARWIN +# include <sys/param.h> +# include <sys/mount.h> +#endif +#define SM_LOCAL_MODE_BITS 0600#define SM_LOCAL_DIR_MODE_BITS 0700
hw/9pfs/9p-local.c +2 -0
@@ -32,10 +32,12 @@#include "qemu/error-report.h" #include "qemu/option.h" #include <libgen.h> +#ifdef CONFIG_LINUX #include <linux/fs.h> #ifdef CONFIG_LINUX_MAGIC_H #include <linux/magic.h> #endif +#endif #include <sys/ioctl.h> #ifndef XFS_SUPER_MAGIC
hw/9pfs/9p.c +4 -0
@@ -32,7 +32,11 @@#include "migration/blocker.h" #include "qemu/xxhash.h" #include <math.h> +#ifdef CONFIG_LINUX #include <linux/limits.h> +#else +#include <limits.h> +#endif int open_fd_hw;int total_open_fd;
include/qemu/xattr.h +3 -1
@@ -22,7 +22,9 @@#ifdef CONFIG_LIBATTR # include <attr/xattr.h> #else -# define ENOATTR ENODATA +# if !defined(ENOATTR ) +# define ENOATTR ENODATA +# endif # include <sys/xattr.h> #endif
Signature · 1 line
2.32.0 (Apple Git-132)
PATCH v4 4/11 9p: darwin: Handle struct dirent differences
In reply to Will CohenFrom: Keno Fischer <[email protected]>
On darwin d_seekoff exists, but is optional and does not seem to be commonly used by file systems. Use telldir instead to obtain the seek offset and inject it into d_seekoff, and create a qemu_dirent_off helper to call it appropriately when appropriate.
[Will Cohen: - Adjust to pass testing
- Ensure that d_seekoff is filled using telldir on darwin, and create qemu_dirent_off helper to decide which to access]
[Fabian Franz: - Add telldir error handling for darwin] [Will Cohen: - Ensure that telldir error handling uses
signed int]
--- hw/9pfs/9p-local.c | 9 +++++++++ hw/9pfs/9p-proxy.c | 16 +++++++++++++++- hw/9pfs/9p-synth.c | 4 ++++ hw/9pfs/9p-util.h | 17 +++++++++++++++++ hw/9pfs/9p.c | 15 +++++++++++++-- hw/9pfs/codir.c | 7 +++++++ 6 files changed, 65 insertions(+), 3 deletions(-)
hw/9pfs/9p-local.c +9 -0
@@ -559,6 +559,15 @@ static struct dirent *local_readdir(FsContext *ctx, V9fsFidOpenState *fs) again: entry =readdir (fs->dir.stream); +#ifdef CONFIG_DARWIN +int td; + td =telldir (fs->dir.stream); +/* If telldir fails, fail the entire readdir call */ +if (td <0 ) { +return NULL ; + } + entry->d_seekoff = td; +#endif if (!entry) {return NULL ; }
hw/9pfs/9p-proxy.c +15 -1
@@ -706,7 +706,21 @@ static off_t proxy_telldir(FsContext *ctx, V9fsFidOpenState *fs)static struct dirent *proxy_readdir (FsContext *ctx,V9fsFidOpenState *fs) { -return readdir (fs->dir.stream); +struct dirent *entry; + entry =readdir (fs->dir.stream); +#ifdef CONFIG_DARWIN +if (!entry) { +return NULL ; + } +int td; + td =telldir (fs->dir.stream); +/* If telldir fails, fail the entire readdir call */ +if (td <0 ) { +return NULL ; + } + entry->d_seekoff = td; +#endif +return entry; }static void proxy_seekdir (FsContext *ctx,V9fsFidOpenState *fs,off_t off)
hw/9pfs/9p-synth.c +4 -0
@@ -222,7 +222,11 @@ static void synth_direntry(V9fsSynthNode *node, {strcpy (entry->d_name, node->name); entry->d_ino = node->attr->inode; +#ifdef CONFIG_DARWIN + entry->d_seekoff = off +1 ; +#else entry->d_off = off +1 ; +#endif } static struct dirent *synth_get_dentry(V9fsSynthNode *dir,
hw/9pfs/9p-util.h +17 -0
@@ -79,3 +79,20 @@ ssize_t fremovexattrat_nofollow(int dirfd, const char *filename, const char *name);#endif + + +/** +* Darwin has d_seekoff, which appears to function similarly to d_off. +* However, it does not appear to be supported on all file systems, +* so ensure it is manually injected earlier and call here when +* needed. +*/ + +inline off_t qemu_dirent_off (struct dirent *dent) +{ +#ifdef CONFIG_DARWIN +return dent->d_seekoff; +#else +return dent->d_off; +#endif +}
hw/9pfs/9p.c +13 -2
@@ -27,6 +27,7 @@#include "virtio-9p.h" #include "fsdev/qemu-fsdev.h" #include "9p-xattr.h" +#include "9p-util.h" #include "coth.h" #include "trace.h" #include "migration/blocker.h"
@@ -2281,7 +2282,11 @@ static int coroutine_fn v9fs_do_readdir_with_stat(V9fsPDU *pdu, count += len;v9fs_stat_free (&v9stat);v9fs_path_free (&path); - saved_dir_pos = dent->d_off; + saved_dir_pos =qemu_dirent_off (dent); +if (saved_dir_pos <0 ) { + err = saved_dir_pos; +break ; + } }v9fs_readdir_unlock (&fidp->fs.dir);
@@ -2420,6 +2425,7 @@ static int coroutine_fn v9fs_do_readdir(V9fsPDU *pdu, V9fsFidState *fidp,V9fsString name;int len, err =0 ;int32_t count =0 ; +off_t off;struct dirent *dent;struct stat *st;struct V9fsDirEnt *entries =NULL ;
@@ -2480,12 +2486,17 @@ static int coroutine_fn v9fs_do_readdir(V9fsPDU *pdu, V9fsFidState *fidp, qid.version =0 ; } + off =qemu_dirent_off (dent); +if (off <0 ) { + err = off; +break ; + }v9fs_string_init (&name);v9fs_string_sprintf (&name,"%s" , dent->d_name);/* 11 = 7 + 4 (7 = start offset, 4 = space for storing count) */ len =pdu_marshal (pdu,11 + count,"Qqbs" , - &qid, dent->d_off, + &qid, off, dent->d_type, &name);v9fs_string_free (&name);
hw/9pfs/codir.c +7 -0
@@ -167,7 +167,14 @@ static int do_readdir_many(V9fsPDU *pdu, V9fsFidState *fidp, } size += len; +/* This conditional statement is identical in +* function to qemu_dirent_off, described in 9p-util.h, +* since that header cannot be included here. */ +#ifdef CONFIG_DARWIN + saved_dir_pos = dent->d_seekoff; +#else saved_dir_pos = dent->d_off; +#endif }/* restore (last) saved position */
Signature · 1 line
2.32.0 (Apple Git-132)
PATCH v4 9/11 9p: darwin: Implement compatibility for mknodat
In reply to Will CohenFrom: Keno Fischer <[email protected]>
Darwin does not support mknodat. However, to avoid race conditions with later setting the permissions, we must avoid using mknod on the full path instead. We could try to fchdir, but that would cause problems if multiple threads try to call mknodat at the same time. However, luckily there is a solution: Darwin includes a function that sets the cwd for the current thread only.
This should suffice to use mknod safely.
This function (pthread_fchdir_np) is protected by a check in meson in a patch later in tihs series.
[Will Cohen: - Adjust coding style
- Replace clang references with gcc
- Note radar filed with Apple for missing syscall
- Replace direct syscall with pthread_fchdir_np and adjust patch notes accordingly]
--- hw/9pfs/9p-local.c | 5 +++-- hw/9pfs/9p-util-darwin.c | 27 +++++++++++++++++++++++++++ hw/9pfs/9p-util-linux.c | 5 +++++ hw/9pfs/9p-util.h | 2 ++ 4 files changed, 37 insertions(+), 2 deletions(-)
hw/9pfs/9p-local.c +3 -2
@@ -682,7 +682,7 @@ static int local_mknod(FsContext *fs_ctx, V9fsPath *dir_path,if (fs_ctx->export_flags &V9FS_SM_MAPPED || fs_ctx->export_flags &V9FS_SM_MAPPED_FILE ) { - err =mknodat (dirfd, name, fs_ctx->fmode |S_IFREG ,0 ); + err =qemu_mknodat (dirfd, name, fs_ctx->fmode |S_IFREG ,0 );if (err ==-1 ) { goto out; }
@@ -697,7 +697,7 @@ static int local_mknod(FsContext *fs_ctx, V9fsPath *dir_path, } }else if (fs_ctx->export_flags &V9FS_SM_PASSTHROUGH || fs_ctx->export_flags &V9FS_SM_NONE ) { - err =mknodat (dirfd, name, credp->fc_mode, credp->fc_rdev); + err =qemu_mknodat (dirfd, name, credp->fc_mode, credp->fc_rdev);if (err ==-1 ) { goto out; }
@@ -710,6 +710,7 @@ static int local_mknod(FsContext *fs_ctx, V9fsPath *dir_path, err_end:unlinkat_preserve_errno (dirfd, name,0 ); + out:close_preserve_errno (dirfd);return err;
hw/9pfs/9p-util-darwin.c +27 -0
@@ -5,6 +5,7 @@* See the COPYING file in the top-level directory. */ +#include <os/availability.h> #include "qemu/osdep.h" #include "qemu/xattr.h" #include "9p-util.h"
@@ -62,3 +63,29 @@ int fsetxattrat_nofollow(int dirfd, const char *filename, const char *name,close_preserve_errno (fd);return ret; } + +/* +* As long as mknodat is not available on macOS, this workaround +* using pthread_fchdir_np is needed. +* +* Radar filed with Apple for implementing mknodat: +* rdar://FB9862426 (https://openradar.appspot.com/FB9862426) +*/ + +int pthread_fchdir_np(int fd) API_AVAILABLE(macosx(10.12)); + +int qemu_mknodat (int dirfd,const char *filename,mode_t mode,dev_t dev) +{ +int preserved_errno, err; +if (pthread_fchdir_np (dirfd) <0 ) { +return -1 ; + } + err =mknod (filename, mode, dev); + preserved_errno = errno; +/* Stop using the thread-local cwd */ +pthread_fchdir_np (-1 ); +if (err <0 ) { + errno = preserved_errno; + } +return err; +}
hw/9pfs/9p-util-linux.c +5 -0
@@ -62,3 +62,8 @@ int fsetxattrat_nofollow(int dirfd, const char *filename, const char *name,g_free (proc_path);return ret; } + +int qemu_mknodat (int dirfd,const char *filename,mode_t mode,dev_t dev) +{ +return mknodat (dirfd, filename, mode, dev); +}
hw/9pfs/9p-util.h +2 -0
@@ -97,6 +97,8 @@ ssize_t flistxattrat_nofollow(int dirfd, const char *filename,ssize_t fremovexattrat_nofollow (int dirfd,const char *filename,const char *name); +int qemu_mknodat (int dirfd,const char *filename,mode_t mode,dev_t dev); +#endif
Signature · 1 line
2.32.0 (Apple Git-132)
PATCH v4 2/11 9p: Rename 9p-util -> 9p-util-linux
In reply to Will CohenFrom: Keno Fischer <[email protected]>
The current file only has the Linux versions of these functions. Rename the file accordingly and update the Makefile to only build it on Linux. A Darwin version of these will follow later in the series.
---
hw/9pfs/{9p-util.c => 9p-util-linux.c} | 2 +-
hw/9pfs/meson.build | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
rename hw/9pfs/{9p-util.c => 9p-util-linux.c} (97%)hw/9pfs/9p-util-linux.c renamed from hw/9pfs/9p-util.c +1 -1
@@ -1,5 +1,5 @@/* -* 9p utilities +* 9p utilities (Linux Implementation) * * Copyright IBM, Corp. 2017 *
hw/9pfs/meson.build +1 -1
@@ -4,7 +4,6 @@ fs_ss.add(files( '9p-posix-acl.c', '9p-proxy.c', '9p-synth.c', - '9p-util.c', '9p-xattr-user.c', '9p-xattr.c', '9p.c',
@@ -14,6 +13,7 @@ fs_ss.add(files( 'coth.c', 'coxattr.c', )) +fs_ss.add(when: 'CONFIG_LINUX', if_true: files('9p-util-linux.c')) fs_ss.add(when: 'CONFIG_XEN', if_true: files('xen-9p-backend.c')) softmmu_ss.add_all(when: 'CONFIG_FSDEV_9P', if_true: fs_ss)
Signature · 1 line
2.32.0 (Apple Git-132)
PATCH v4 6/11 9p: darwin: Move XATTR_SIZE_MAX->P9_XATTR_SIZE_MAX
In reply to Will CohenFrom: Keno Fischer <[email protected]>
Because XATTR_SIZE_MAX is not defined on Darwin, create a cross-platform P9_XATTR_SIZE_MAX instead.
[Will Cohen: - Adjust coding style
- Lower XATTR_SIZE_MAX to 64k
- Add explanatory context related to XATTR_SIZE_MAX]
[Fabian Franz: - Move XATTR_SIZE_MAX reference from 9p.c to
P9_XATTR_SIZE_MAX in 9p.h]
--- hw/9pfs/9p.c | 2 +- hw/9pfs/9p.h | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-)
hw/9pfs/9p.c +1 -1
@@ -3957,7 +3957,7 @@ static void coroutine_fn v9fs_xattrcreate(void *opaque) rflags |=XATTR_REPLACE ; } -if (size >XATTR_SIZE_MAX ) { +if (size >P9_XATTR_SIZE_MAX ) { err = -E2BIG ; goto out_nofid; }
hw/9pfs/9p.h +11 -0
@@ -479,4 +479,15 @@ struct V9fsTransport { void (*push_and_notify)(V9fsPDU *pdu); }; +/* +* Darwin doesn't seem to define a maximum xattr size in its user +* space header, so manually configure it across platforms as 64k. +* +* Having no limit at all can lead to QEMU crashing during large g_malloc() +* calls. Because QEMU does not currently support macOS guests, the below +* preliminary solution only works due to its being a reflection of the limit of +* Linux guests. +*/ +#define P9_XATTR_SIZE_MAX 65536 +#endif
Signature · 1 line
2.32.0 (Apple Git-132)
PATCH v4 3/11 9p: darwin: Handle struct stat(fs) differences
In reply to Will CohenFrom: Keno Fischer <[email protected]>
[Will Cohen: - Note lack of f_namelen and f_frsize on Darwin
- Ensure that tv_sec and tv_nsec are both initialized for Darwin and non-Darwin]
--- hw/9pfs/9p-proxy.c | 22 ++++++++++++++++++++-- hw/9pfs/9p-synth.c | 2 ++ hw/9pfs/9p.c | 16 ++++++++++++++-- 3 files changed, 36 insertions(+), 4 deletions(-)
hw/9pfs/9p-proxy.c +20 -2
@@ -123,10 +123,16 @@ static void prstatfs_to_statfs(struct statfs *stfs, ProxyStatFS *prstfs) stfs->f_bavail = prstfs->f_bavail; stfs->f_files = prstfs->f_files; stfs->f_ffree = prstfs->f_ffree; +#ifdef CONFIG_DARWIN +/* f_namelen and f_frsize do not exist on Darwin */ + stfs->f_fsid.val[0 ] = prstfs->f_fsid[0 ] &0xFFFFFFFFU ; + stfs->f_fsid.val[1 ] = prstfs->f_fsid[1 ] >>32 &0xFFFFFFFFU ; +#else stfs->f_fsid.__val[0 ] = prstfs->f_fsid[0 ] &0xFFFFFFFFU ; stfs->f_fsid.__val[1 ] = prstfs->f_fsid[1 ] >>32 &0xFFFFFFFFU ; stfs->f_namelen = prstfs->f_namelen; stfs->f_frsize = prstfs->f_frsize; +#endif }/* Converts proxy_stat structure to VFS stat structure */
@@ -143,12 +149,24 @@ static void prstat_to_stat(struct stat *stbuf, ProxyStat *prstat) stbuf->st_size = prstat->st_size; stbuf->st_blksize = prstat->st_blksize; stbuf->st_blocks = prstat->st_blocks; + stbuf->st_atime = prstat->st_atim_sec; + stbuf->st_mtime = prstat->st_mtim_sec; + stbuf->st_ctime = prstat->st_ctim_sec; +#ifdef CONFIG_DARWIN + stbuf->st_atimespec.tv_sec = prstat->st_atim_sec; + stbuf->st_mtimespec.tv_sec = prstat->st_mtim_sec; + stbuf->st_ctimespec.tv_sec = prstat->st_ctim_sec; + stbuf->st_atimespec.tv_nsec = prstat->st_atim_nsec; + stbuf->st_mtimespec.tv_nsec = prstat->st_mtim_nsec; + stbuf->st_ctimespec.tv_nsec = prstat->st_ctim_nsec; +#else stbuf->st_atim.tv_sec = prstat->st_atim_sec; + stbuf->st_mtim.tv_sec = prstat->st_mtim_sec; + stbuf->st_ctim.tv_sec = prstat->st_ctim_sec; stbuf->st_atim.tv_nsec = prstat->st_atim_nsec; - stbuf->st_mtime = prstat->st_mtim_sec; stbuf->st_mtim.tv_nsec = prstat->st_mtim_nsec; - stbuf->st_ctime = prstat->st_ctim_sec; stbuf->st_ctim.tv_nsec = prstat->st_ctim_nsec; +#endif }/*
hw/9pfs/9p-synth.c +2 -0
@@ -427,7 +427,9 @@ static int synth_statfs(FsContext *s, V9fsPath *fs_path, stbuf->f_bsize =512 ; stbuf->f_blocks =0 ; stbuf->f_files = synth_node_count; +#ifndef CONFIG_DARWIN stbuf->f_namelen =NAME_MAX ; +#endif return 0 ; }
hw/9pfs/9p.c +14 -2
@@ -1313,11 +1313,17 @@ static int stat_to_v9stat_dotl(V9fsPDU *pdu, const struct stat *stbuf, v9lstat->st_blksize =stat_to_iounit (pdu, stbuf); v9lstat->st_blocks = stbuf->st_blocks; v9lstat->st_atime_sec = stbuf->st_atime; - v9lstat->st_atime_nsec = stbuf->st_atim.tv_nsec; v9lstat->st_mtime_sec = stbuf->st_mtime; - v9lstat->st_mtime_nsec = stbuf->st_mtim.tv_nsec; v9lstat->st_ctime_sec = stbuf->st_ctime; +#ifdef CONFIG_DARWIN + v9lstat->st_atime_nsec = stbuf->st_atimespec.tv_nsec; + v9lstat->st_mtime_nsec = stbuf->st_mtimespec.tv_nsec; + v9lstat->st_ctime_nsec = stbuf->st_ctimespec.tv_nsec; +#else + v9lstat->st_atime_nsec = stbuf->st_atim.tv_nsec; + v9lstat->st_mtime_nsec = stbuf->st_mtim.tv_nsec; v9lstat->st_ctime_nsec = stbuf->st_ctim.tv_nsec; +#endif /* Currently we only support BASIC fields in stat */ v9lstat->st_result_mask =P9_STATS_BASIC ;
@@ -3519,9 +3525,15 @@ static int v9fs_fill_statfs(V9fsState *s, V9fsPDU *pdu, struct statfs *stbuf) f_bavail = stbuf->f_bavail / bsize_factor; f_files = stbuf->f_files; f_ffree = stbuf->f_ffree; +#ifdef CONFIG_DARWIN + fsid_val = (unsigned int )stbuf->f_fsid.val[0 ] | + (unsigned long long )stbuf->f_fsid.val[1 ] <<32 ; + f_namelen =NAME_MAX ; +#else fsid_val = (unsigned int ) stbuf->f_fsid.__val[0 ] | (unsigned long long )stbuf->f_fsid.__val[1 ] <<32 ; f_namelen = stbuf->f_namelen; +#endif return pdu_marshal(pdu, offset, "ddqqqqqqd", f_type, f_bsize, f_blocks, f_bfree,
Signature · 1 line
2.32.0 (Apple Git-132)
PATCH v4 10/11 9p: darwin: meson: Allow VirtFS on Darwin
In reply to Will CohenFrom: Keno Fischer <[email protected]>
--- fsdev/meson.build | 1 + meson.build | 14 ++++++++++---- 2 files changed, 11 insertions(+), 4 deletions(-)
fsdev/meson.build +1 -0
@@ -7,6 +7,7 @@ fsdev_ss.add(when: ['CONFIG_FSDEV_9P'], if_true: files( 'qemu-fsdev.c', ), if_false: files('qemu-fsdev-dummy.c')) softmmu_ss.add_all(when: 'CONFIG_LINUX', if_true: fsdev_ss) +softmmu_ss.add_all(when: 'CONFIG_DARWIN', if_true: fsdev_ss) if have_virtfs_proxy_helper executable('virtfs-proxy-helper',
meson.build +10 -4
@@ -1421,17 +1421,23 @@ if not get_option('dbus_display').disabled() endif endif -have_virtfs = (targetos == 'linux' and +if targetos == 'darwin' and cc.has_function('pthread_fchdir_np') + have_virtfs = have_system +else + have_virtfs = (targetos == 'linux' and have_system and libattr.found() and libcap_ng.found()) +endif -have_virtfs_proxy_helper = have_virtfs and have_tools +have_virtfs_proxy_helper = targetos == 'linux' and have_virtfs and have_tools if get_option('virtfs').enabled() if not have_virtfs - if targetos != 'linux' - error('virtio-9p (virtfs) requires Linux') + if targetos != 'linux' and targetos != 'darwin' + error('virtio-9p (virtfs) requires Linux or Darwin') + elif targetos == 'darwin' and not cc.has_function('pthread_fchdir_np') + error('virtio-9p (virtfs) on Darwin requires the presence of pthread_fchdir_np') elif not libcap_ng.found() or not libattr.found() error('virtio-9p (virtfs) requires libcap-ng-devel and libattr-devel') elif not have_system
Signature · 1 line
2.32.0 (Apple Git-132)
PATCH v4 7/11 9p: darwin: *xattr_nofollow implementations
In reply to Will CohenFrom: Keno Fischer <[email protected]>
This implements the darwin equivalent of the functions that were moved to 9p-util(-linux) earlier in this series in the new 9p-util-darwin file.
--- hw/9pfs/9p-util-darwin.c | 64 ++++++++++++++++++++++++++++++++++++++++ hw/9pfs/meson.build | 1 + 2 files changed, 65 insertions(+) create mode 100644 hw/9pfs/9p-util-darwin.c
hw/9pfs/9p-util-darwin.c new file +64 -0
@@ -0,0 +1,64 @@ +/* +* 9p utilities (Darwin Implementation) +* +* This work is licensed under the terms of the GNU GPL, version 2 or later. +* See the COPYING file in the top-level directory. +*/ + +#include "qemu/osdep.h" +#include "qemu/xattr.h" +#include "9p-util.h" + +ssize_t fgetxattrat_nofollow (int dirfd,const char *filename,const char *name, +void *value,size_t size) +{ +int ret; +int fd =openat_file (dirfd, filename, +O_RDONLY |O_PATH_9P_UTIL |O_NOFOLLOW ,0 ); +if (fd ==-1 ) { +return -1 ; + } + ret =fgetxattr (fd, name, value, size,0 ,0 ); +close_preserve_errno (fd); +return ret; +} + +ssize_t flistxattrat_nofollow (int dirfd,const char *filename, +char *list,size_t size) +{ +int ret; +int fd =openat_file (dirfd, filename, +O_RDONLY |O_PATH_9P_UTIL |O_NOFOLLOW ,0 ); +if (fd ==-1 ) { +return -1 ; + } + ret =flistxattr (fd, list, size,0 ); +close_preserve_errno (fd); +return ret; +} + +ssize_t fremovexattrat_nofollow (int dirfd,const char *filename, +const char *name) +{ +int ret; +int fd =openat_file (dirfd, filename,O_PATH_9P_UTIL |O_NOFOLLOW ,0 ); +if (fd ==-1 ) { +return -1 ; + } + ret =fremovexattr (fd, name,0 ); +close_preserve_errno (fd); +return ret; +} + +int fsetxattrat_nofollow (int dirfd,const char *filename,const char *name, +void *value,size_t size,int flags) +{ +int ret; +int fd =openat_file (dirfd, filename,O_PATH_9P_UTIL |O_NOFOLLOW ,0 ); +if (fd ==-1 ) { +return -1 ; + } + ret =fsetxattr (fd, name, value, size,0 , flags); +close_preserve_errno (fd); +return ret; +}
hw/9pfs/meson.build +1 -0
@@ -14,6 +14,7 @@ fs_ss.add(files( 'coxattr.c', )) fs_ss.add(when: 'CONFIG_LINUX', if_true: files('9p-util-linux.c')) +fs_ss.add(when: 'CONFIG_DARWIN', if_true: files('9p-util-darwin.c')) fs_ss.add(when: 'CONFIG_XEN', if_true: files('xen-9p-backend.c')) softmmu_ss.add_all(when: 'CONFIG_FSDEV_9P', if_true: fs_ss)
Signature · 1 line
2.32.0 (Apple Git-132)
PATCH v4 8/11 9p: darwin: Compatibility for f/l*xattr
In reply to Will CohenFrom: Keno Fischer <[email protected]>
On darwin fgetxattr takes two extra optional arguments, and the l* variants are not defined (in favor of an extra flag to the regular variants.
--- hw/9pfs/9p-local.c | 12 ++++++++---- hw/9pfs/9p-util.h | 17 +++++++++++++++++ 2 files changed, 25 insertions(+), 4 deletions(-)
hw/9pfs/9p-local.c +8 -4
@@ -790,16 +790,20 @@ static int local_fstat(FsContext *fs_ctx, int fid_type,mode_t tmp_mode;dev_t tmp_dev; -if (fgetxattr (fd,"user.virtfs.uid" , &tmp_uid,sizeof (uid_t)) >0 ) { +if (qemu_fgetxattr (fd,"user.virtfs.uid" , + &tmp_uid,sizeof (uid_t)) >0 ) { stbuf->st_uid =le32_to_cpu (tmp_uid); } -if (fgetxattr (fd,"user.virtfs.gid" , &tmp_gid,sizeof (gid_t)) >0 ) { +if (qemu_fgetxattr (fd,"user.virtfs.gid" , + &tmp_gid,sizeof (gid_t)) >0 ) { stbuf->st_gid =le32_to_cpu (tmp_gid); } -if (fgetxattr (fd,"user.virtfs.mode" , &tmp_mode,sizeof (mode_t)) >0 ) { +if (qemu_fgetxattr (fd,"user.virtfs.mode" , + &tmp_mode,sizeof (mode_t)) >0 ) { stbuf->st_mode =le32_to_cpu (tmp_mode); } -if (fgetxattr (fd,"user.virtfs.rdev" , &tmp_dev,sizeof (dev_t)) >0 ) { +if (qemu_fgetxattr (fd,"user.virtfs.rdev" , + &tmp_dev,sizeof (dev_t)) >0 ) { stbuf->st_rdev =le64_to_cpu (tmp_dev); } }else if (fs_ctx->export_flags &V9FS_SM_MAPPED_FILE ) {
hw/9pfs/9p-util.h +17 -0
@@ -19,6 +19,23 @@#define O_PATH_9P_UTIL 0#endif +#ifdef CONFIG_DARWIN +#define qemu_fgetxattr (...) fgetxattr(__VA_ARGS__, 0, 0) +#define qemu_lgetxattr (...) getxattr(__VA_ARGS__, 0, XATTR_NOFOLLOW) +#define qemu_llistxattr (...) listxattr(__VA_ARGS__, XATTR_NOFOLLOW) +#define qemu_lremovexattr (...) removexattr(__VA_ARGS__, XATTR_NOFOLLOW) +static inline int qemu_lsetxattr (const char *path,const char *name, +const void *value,size_t size,int flags) { +return setxattr (path, name, value, size,0 , flags |XATTR_NOFOLLOW ); +} +#else +#define qemu_fgetxattr fgetxattr +#define qemu_lgetxattr lgetxattr +#define qemu_llistxattr llistxattr +#define qemu_lremovexattr lremovexattr +#define qemu_lsetxattr lsetxattr +#endif +static inline void close_preserve_errno (int fd) {int serrno = errno;
Signature · 1 line
2.32.0 (Apple Git-132)
PATCH v4 5/11 9p: darwin: Ignore O_{NOATIME, DIRECT}
In reply to Will CohenFrom: Keno Fischer <[email protected]>
Darwin doesn't have either of these flags. Darwin does have F_NOCACHE, which is similar to O_DIRECT, but has different enough semantics that other projects don't generally map them automatically. In any case, we don't support O_DIRECT on Linux at the moment either.
--- hw/9pfs/9p-util.h | 2 ++ hw/9pfs/9p.c | 13 ++++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-)
hw/9pfs/9p-util.h +2 -0
@@ -41,6 +41,7 @@ again: fd =openat (dirfd, name, flags |O_NOFOLLOW |O_NOCTTY |O_NONBLOCK , mode);if (fd ==-1 ) { +#ifndef CONFIG_DARWIN if (errno ==EPERM && (flags &O_NOATIME )) {/* * The client passed O_NOATIME but we lack permissions to honor it.
@@ -53,6 +54,7 @@ again: flags &= ~O_NOATIME ; goto again; } +#endif return -1 ; }
hw/9pfs/9p.c +12 -1
@@ -138,11 +138,20 @@ static int dotl_to_open_flags(int flags) { P9_DOTL_NONBLOCK, O_NONBLOCK } , { P9_DOTL_DSYNC, O_DSYNC }, { P9_DOTL_FASYNC, FASYNC }, +#ifndef CONFIG_DARWIN + { P9_DOTL_NOATIME, O_NOATIME }, +/* +* On Darwin, we could map to F_NOCACHE, which is +* similar, but doesn't quite have the same +* semantics. However, we don't support O_DIRECT +* even on linux at the moment, so we just ignore +* it here. +*/ { P9_DOTL_DIRECT, O_DIRECT }, +#endif { P9_DOTL_LARGEFILE, O_LARGEFILE }, { P9_DOTL_DIRECTORY, O_DIRECTORY }, { P9_DOTL_NOFOLLOW, O_NOFOLLOW }, - { P9_DOTL_NOATIME, O_NOATIME }, { P9_DOTL_SYNC, O_SYNC }, };
@@ -171,10 +180,12 @@ static int get_dotl_openflags(V9fsState *s, int oflags)*/ flags =dotl_to_open_flags (oflags); flags &= ~(O_NOCTTY |O_ASYNC |O_CREAT ); +#ifndef CONFIG_DARWIN /* * Ignore direct disk access hint until the server supports it. */ flags &= ~O_DIRECT ; +#endif return flags; }
Signature · 1 line
2.32.0 (Apple Git-132)
PATCH v4 11/11 9p: darwin: Adjust assumption on virtio-9p-test
In reply to Will CohenThe previous test depended on the assumption that P9_DOTL_AT_REMOVEDIR and AT_REMOVEDIR have the same value.
While this is true on Linux, it is not true everywhere, and leads to an incorrect test failure on unlink_at, noticed when adding 9p to darwin:
Received response 7 (RLERROR) instead of 77 (RUNLINKAT) Rlerror has errno 22 (Invalid argument)
**
ERROR:../tests/qtest/virtio-9p-test.c:305:v9fs_req_recv: assertion failed (hdr.id == id): (7 == 77) Bail out!
ERROR:../tests/qtest/virtio-9p-test.c:305:v9fs_req_recv: assertion failed (hdr.id == id): (7 == 77)
[Will Cohen: - Add explanation of patch and description
of pre-patch test failure]
--- tests/qtest/virtio-9p-test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tests/qtest/virtio-9p-test.c +1 -1
@@ -1270,7 +1270,7 @@ static void fs_unlinkat_dir(void *obj, void *data, QGuestAllocator *t_alloc)/* ... and is actually a directory */ g_assert ((st.st_mode &S_IFMT ) ==S_IFDIR ); -do_unlinkat (v9p,"/" ,"02" ,AT_REMOVEDIR ); +do_unlinkat (v9p,"/" ,"02" ,P9_DOTL_AT_REMOVEDIR );/* directory should be gone now */ g_assert (stat (new_dir, &st) !=0 );
Signature · 1 line
2.32.0 (Apple Git-132)
Re: [PATCH v4 01/11] 9p: linux: Fix a couple Linux assumptions
In reply to Will CohenQuoted 23 lines · Will Cohen
From: Keno Fischer <[email protected]>
- Guard Linux only headers.
- Addqemu/statfs.hheader to abstract over the which headers are needed for struct statfs
- DefineENOATTRonly if not only defined (it's defined in system headers on Darwin).Signed-off-by Keno Fischer <[email protected]>[Michael Roitzsch: - Rebase for NixOS]Signed-off-by Michael Roitzsch <[email protected]>While it might at first appear that
fsdev/virtfs-proxy-header.cwould need similar adjustment for darwin as file-op-9p here, a later patch in this series disables virtfs-proxy-helper for non-Linux. Allowing virtfs-proxy-helper on darwin could potentially be an additional optimization later.[Will Cohen: - Fix headers for Alpine
- Integratestatfs.hback intofile-op-9p.h
- Remove superfluous header guards from file-opt-9p
- Add note about virtfs-proxy-helper being disabled on non-Linux for this patch series]
Quoted 7 lines
Signed-off-by Will Cohen <[email protected]>--- fsdev/file-op-9p.h | 9 ++++++++- hw/9pfs/9p-local.c | 2 ++ hw/9pfs/9p.c | 4 ++++ include/qemu/xattr.h | 4 +++- 4 files changed, 17 insertions(+), 2 deletions(-)
Re: [PATCH v4 02/11] 9p: Rename 9p-util -> 9p-util-linux
In reply to Will CohenQuoted 12 lines · Will Cohen
From: Keno Fischer <[email protected]>
The current file only has the Linux versions of these functions. Rename the file accordingly and update the
Makefileto only build it on Linux. A Darwin version of these will follow later in the series.Signed-off-by Keno Fischer <[email protected]>[Michael Roitzsch: - Rebase for NixOS]Signed-off-by Michael Roitzsch <[email protected]>Signed-off-by Will Cohen <[email protected]>Reviewed-by Greg Kurz <[email protected]>
Quoted 5 lines
--- hw/9pfs/{9p-util.c => 9p-util-linux.c} | 2 +- hw/9pfs/meson.build | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)rename
hw/9pfs/{9p-util.c=>9p-util-linux.c} (97%)
Re: [PATCH v4 09/11] 9p: darwin: Implement compatibility for mknodat
In reply to Will CohenQuoted 33 lines · Will Cohen
From: Keno Fischer <[email protected]>
Darwin does not support mknodat. However, to avoid race conditions with later setting the permissions, we must avoid using mknod on the full path instead. We could try to fchdir, but that would cause problems if multiple threads try to call mknodat at the same time. However, luckily there is a solution: Darwin includes a function that sets the cwd for the current thread only.
This should suffice to use mknod safely.This function (
pthread_fchdir_np) is protected by a check in meson in a patch later in tihs series.Signed-off-by Keno Fischer <[email protected]>Signed-off-by Michael Roitzsch <[email protected]>[Will Cohen: - Adjust coding style
- Replace clang references with gcc
- Note radar filed with Apple for missing syscall
- Replace direct syscall withpthread_fchdir_npand adjust patch notes accordingly]Signed-off-by Will Cohen <[email protected]>--- hw/9pfs/9p-local.c | 5 +++-- hw/9pfs/9p-util-darwin.c | 27 +++++++++++++++++++++++++++ hw/9pfs/9p-util-linux.c | 5 +++++ hw/9pfs/9p-util.h | 2 ++ 4 files changed, 37 insertions(+), 2 deletions(-)hw/9pfs/9p-util.h +0
-0
hw/9pfs/9p-util.h ssize_t flistxattrat_nofollow(int dirfd, const char *filename, · line 100
Quoted 4 lines
hw/9pfs/9p-util.h +1
-0@@ -97,6 +97,8 @@ ssize_t flistxattrat_nofollow(int dirfd, const char *filename,ssize_t fremovexattrat_nofollow (int dirfd,const char *filename,const char *name); +int qemu_mknodat (int dirfd,const char *filename,mode_t mode,dev_t dev);
I think this belong to "osdep.h" & os-posix.c.
Re: [PATCH v4 10/11] 9p: darwin: meson: Allow VirtFS on Darwin
In reply to Will CohenQuoted 15 lines · Will Cohen
From: Keno Fischer <[email protected]>
Signed-off-by Keno Fischer <[email protected]>[Michael Roitzsch: - Rebase for NixOS]Signed-off-by Michael Roitzsch <[email protected]>[Will Cohen: - Rebase to master]Signed-off-by Will Cohen <[email protected]>Reviewed-by Paolo Bonzini <[email protected]>[Will Cohen: - Add check for pthread_fchdir_np to virtfs]Signed-off-by Will Cohen <[email protected]>--- fsdev/meson.build | 1 + meson.build | 14 ++++++++++---- 2 files changed, 11 insertions(+), 4 deletions(-)
meson.build if not get_option('dbus_display').disabled() · line 1433
Quoted 2 lines
meson.build +1
-1-have_virtfs_proxy_helper = have_virtfs and have_tools +have_virtfs_proxy_helper = targetos == 'linux' and have_virtfs and have_tools
Why do you restrict the proxy-helper to Linux?
Re: [PATCH v4 10/11] 9p: darwin: meson: Allow VirtFS on Darwin
Only because porting the proxy-helper to macOS is outside the scope of this particular patch. While some initial concepts around it have been considered by some of the contributors to this patch, those implementations weren't tested enough and the security implications weren't considered in full. We assume that this could be an additional implementation later on, if the functionality is considered important down the road.
Quoted 22 lines · Philippe Mathieu-Daudé
Quoted 15 lines · Will Cohen
From: Keno Fischer <[email protected]>
Signed-off-by Keno Fischer <[email protected]>[Michael Roitzsch: - Rebase for NixOS]Signed-off-by Michael Roitzsch <[email protected]>[Will Cohen: - Rebase to master]Signed-off-by Will Cohen <[email protected]>Reviewed-by Paolo Bonzini <[email protected]>[Will Cohen: - Add check for pthread_fchdir_np to virtfs]Signed-off-by Will Cohen <[email protected]>--- fsdev/meson.build | 1 + meson.build | 14 ++++++++++---- 2 files changed, 11 insertions(+), 4 deletions(-)Review
Quoted 2 lines
(quoted diff) +1
-1-have_virtfs_proxy_helper = have_virtfs and have_tools +have_virtfs_proxy_helper = targetos == 'linux' and have_virtfs and
have_toolsWhy do you restrict the proxy-helper to Linux?
Re: [PATCH v4 09/11] 9p: darwin: Implement compatibility for mknodat
In reply to Philippe Mathieu-Daudé viaThis patch set currently places it in 9p-util only because 9p is the only place where this issue seems to have come up so far and we were wary of editing files too far afield, but I have no attachment to its specific location!
Quoted 43 lines · Philippe Mathieu-Daudé
hw/9pfs/9p-util.h ssize_t flistxattrat_nofollow(int dirfd, const char
Quoted 33 lines · Will Cohen
From: Keno Fischer <[email protected]>
Darwin does not support mknodat. However, to avoid race conditions with later setting the permissions, we must avoid using mknod on the full path instead. We could try to fchdir, but that would cause problems if multiple threads try to call mknodat at the same time. However, luckily there is a solution: Darwin includes a function that sets the cwd for the current thread only.
This should suffice to use mknod safely.This function (
pthread_fchdir_np) is protected by a check in meson in a patch later in tihs series.Signed-off-by Keno Fischer <[email protected]>Signed-off-by Michael Roitzsch <[email protected]>[Will Cohen: - Adjust coding style
- Replace clang references with gcc
- Note radar filed with Apple for missing syscall
- Replace direct syscall withpthread_fchdir_npand adjust patch notes accordingly]Signed-off-by Will Cohen <[email protected]>--- hw/9pfs/9p-local.c | 5 +++-- hw/9pfs/9p-util-darwin.c | 27 +++++++++++++++++++++++++++ hw/9pfs/9p-util-linux.c | 5 +++++ hw/9pfs/9p-util.h | 2 ++ 4 files changed, 37 insertions(+), 2 deletions(-)hw/9pfs/9p-util.h +0
-0@@ -97,6 +97,8 @@ ssize_t flistxattrat_nofollow(int dirfd, const char*filename,
hw/9pfs/9p-util.h ssize_t flistxattrat_nofollow(int dirfd, const char *filename,
Quoted 4 lines
hw/9pfs/9p-util.h +1
-0ssize_t fremovexattrat_nofollow (int dirfd,const char *filename,const char *name); +int qemu_mknodat(int dirfd, const char *filename, mode_t mode, dev_tdev);
I think this belong to "
osdep.h" &os-posix.c.
Re: [PATCH v4 11/11] 9p: darwin: Adjust assumption on virtio-9p-test
In reply to Will CohenQuoted 29 lines · Will Cohen
The previous test depended on the assumption that
P9_DOTL_AT_REMOVEDIRandAT_REMOVEDIRhave the same value.While this is true on Linux, it is not true everywhere, and leads to an incorrect test failure on
unlink_at, noticed when adding 9p to darwin:Received response 7 (RLERROR) instead of 77 (RUNLINKAT) Rlerror has errno 22 (Invalid argument)
**ERROR:../tests/qtest/virtio-9p-test.c:305:v9fs_req_recv: assertion failed (hdr.id == id): (7 == 77) Bail out!
ERROR:../tests/qtest/virtio-9p-test.c:305:v9fs_req_recv: assertion failed (hdr.id == id): (7 == 77)
Signed-off-by Fabian Franz <[email protected]>[Will Cohen: - Add explanation of patch and description
of pre-patch test failure]Signed-off-by Will Cohen <[email protected]>--- tests/qtest/virtio-9p-test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)tests/qtest/virtio-9p-test.c +0
-0
tests/qtest/virtio-9p-test.c static void fs_unlinkat_dir(void *obj, void *data, QGuestAllocator *t_alloc) · line 1276
Quoted 8 lines
tests/qtest/virtio-9p-test.c +1
-1@@ -1270,7 +1270,7 @@ static void fs_unlinkat_dir(void *obj, void *data, QGuestAllocator *t_alloc)/* ... and is actually a directory */ g_assert ((st.st_mode &S_IFMT ) ==S_IFDIR ); -do_unlinkat (v9p,"/" ,"02" ,AT_REMOVEDIR ); +do_unlinkat (v9p,"/" ,"02" ,P9_DOTL_AT_REMOVEDIR );/* directory should be gone now */ g_assert (stat (new_dir, &st) !=0 );
Re: [PATCH v4 01/11] 9p: linux: Fix a couple Linux assumptions
In reply to Will CohenQuoted 18 lines · On Sun, 6 Feb 2022 15:07:09 -0500 Will Cohen <[email protected]> wrote:
From: Keno Fischer <[email protected]>
- Guard Linux only headers.
- Addqemu/statfs.hheader to abstract over the which headers are needed for struct statfs
- DefineENOATTRonly if not only defined (it's defined in system headers on Darwin).Signed-off-by Keno Fischer <[email protected]>[Michael Roitzsch: - Rebase for NixOS]Signed-off-by Michael Roitzsch <[email protected]>While it might at first appear that
fsdev/virtfs-proxy-header.cwould need similar adjustment for darwin as file-op-9p here, a later patch in this series disables virtfs-proxy-helper for non-Linux. Allowing virtfs-proxy-helper on darwin could potentially be an additional optimization later.
Quoted 7 lines
[Will Cohen: - Fix headers for Alpine
- Integratestatfs.hback intofile-op-9p.h
- Remove superfluous header guards from file-opt-9p
- Add note about virtfs-proxy-helper being disabled on non-Linux for this patch series]Signed-off-by Will Cohen <[email protected]>---
Quoted 77 lines
fsdev/file-op-9p.h | 9 ++++++++- hw/9pfs/9p-local.c | 2 ++ hw/9pfs/9p.c | 4 ++++ include/qemu/xattr.h | 4 +++- 4 files changed, 17 insertions(+), 2 deletions(-)fsdev/file-op-9p.h +8
-1@@ -16,10 +16,17 @@#include <dirent.h> #include <utime.h> -#include <sys/vfs.h> #include "qemu-fsdev-throttle.h" #include "p9array.h" +#ifdef CONFIG_LINUX +# include <sys/vfs.h> +#endif +#ifdef CONFIG_DARWIN +# include <sys/param.h> +# include <sys/mount.h> +#endif +#define SM_LOCAL_MODE_BITS 0600#define SM_LOCAL_DIR_MODE_BITS 0700hw/9pfs/9p-local.c +2
-0@@ -32,10 +32,12 @@#include "qemu/error-report.h" #include "qemu/option.h" #include <libgen.h> +#ifdef CONFIG_LINUX #include <linux/fs.h> #ifdef CONFIG_LINUX_MAGIC_H #include <linux/magic.h> #endif +#endif #include <sys/ioctl.h> #ifndef XFS_SUPER_MAGIC hw/9pfs/9p.c +4
-0@@ -32,7 +32,11 @@#include "migration/blocker.h" #include "qemu/xxhash.h" #include <math.h> +#ifdef CONFIG_LINUX #include <linux/limits.h> +#else +#include <limits.h> +#endif int open_fd_hw;int total_open_fd;include/qemu/xattr.h +3
-1@@ -22,7 +22,9 @@#ifdef CONFIG_LIBATTR # include <attr/xattr.h> #else -# define ENOATTR ENODATA +# if !defined(ENOATTR ) +# define ENOATTR ENODATA +# endif # include <sys/xattr.h> #endif
Re: [PATCH v4 09/11] 9p: darwin: Implement compatibility for mknodat
In reply to Will CohenQuoted 5 lines · On Sun, 6 Feb 2022 20:10:23 -0500 Will Cohen <[email protected]> wrote:
This patch set currently places it in 9p-util only because 9p is the only place where this issue seems to have come up so far and we were wary of editing files too far afield, but I have no attachment to its specific location!
Inline comments are preferred on qemu-devel. Please don't top post ! This complicates the review a lot.
This is indeed a good candidate for osdep. This being said, unless there's some other user in the QEMU code base, it is acceptable to leave it under 9pfs.
Quoted 46 lines
Quoted 43 lines · Philippe Mathieu-Daudé
hw/9pfs/9p-util.h ssize_t flistxattrat_nofollow(int dirfd, const char
Quoted 33 lines · Will Cohen
From: Keno Fischer <[email protected]>
Darwin does not support mknodat. However, to avoid race conditions with later setting the permissions, we must avoid using mknod on the full path instead. We could try to fchdir, but that would cause problems if multiple threads try to call mknodat at the same time. However, luckily there is a solution: Darwin includes a function that sets the cwd for the current thread only.
This should suffice to use mknod safely.This function (
pthread_fchdir_np) is protected by a check in meson in a patch later in tihs series.Signed-off-by Keno Fischer <[email protected]>Signed-off-by Michael Roitzsch <[email protected]>[Will Cohen: - Adjust coding style
- Replace clang references with gcc
- Note radar filed with Apple for missing syscall
- Replace direct syscall withpthread_fchdir_npand adjust patch notes accordingly]Signed-off-by Will Cohen <[email protected]>--- hw/9pfs/9p-local.c | 5 +++-- hw/9pfs/9p-util-darwin.c | 27 +++++++++++++++++++++++++++ hw/9pfs/9p-util-linux.c | 5 +++++ hw/9pfs/9p-util.h | 2 ++ 4 files changed, 37 insertions(+), 2 deletions(-)hw/9pfs/9p-util.h +0
-0@@ -97,6 +97,8 @@ ssize_t flistxattrat_nofollow(int dirfd, const char*filename,
hw/9pfs/9p-util.h ssize_t flistxattrat_nofollow(int dirfd, const char *filename,
Quoted 4 lines
hw/9pfs/9p-util.h +1
-0ssize_t fremovexattrat_nofollow (int dirfd,const char *filename,const char *name); +int qemu_mknodat(int dirfd, const char *filename, mode_t mode, dev_tdev);
I think this belong to "
osdep.h" &os-posix.c.
Re: [PATCH v4 09/11] 9p: darwin: Implement compatibility for mknodat
Quoted 9 lines · Greg Kurz
Quoted 5 lines · On Sun, 6 Feb 2022 20:10:23 -0500 Will Cohen <[email protected]> wrote:
This patch set currently places it in 9p-util only because 9p is the only place where this issue seems to have come up so far and we were wary of editing files too far afield, but I have no attachment to its specific location!
Quoted 6 lines
Inline comments are preferred on qemu-devel. Please don't top post ! This complicates the review a lot.
This is indeed a good candidate for osdep. This being said, unless there's some other user in the QEMU code base, it is acceptable to leave it under 9pfs.
virtiofsd could eventually use it.
Re: [PATCH v4 09/11] 9p: darwin: Implement compatibility for mknodat
Quoted 10 lines · On Mon, 7 Feb 2022 11:30:18 +0100 Philippe Mathieu-Daudé <[email protected]>…
Quoted 9 lines · Greg Kurz
Quoted 5 lines · On Sun, 6 Feb 2022 20:10:23 -0500 Will Cohen <[email protected]> wrote:
This patch set currently places it in 9p-util only because 9p is the only place where this issue seems to have come up so far and we were wary of editing files too far afield, but I have no attachment to its specific location!
Quoted 8 lines
Quoted 6 lines
Inline comments are preferred on qemu-devel. Please don't top post ! This complicates the review a lot.
This is indeed a good candidate for osdep. This being said, unless there's some other user in the QEMU code base, it is acceptable to leave it under 9pfs.
virtiofsd could eventually use it.
Indeed but virtiofsd is for linux hosts only AFAICT and I'm not aware of any work to support any other host OS.
Cc'ing virtio-fs people for inputs on this topic.
Re: [PATCH v4 09/11] 9p: darwin: Implement compatibility for mknodat
Quoted 20 lines · * Greg Kurz ([email protected]) wrote:
Quoted 17 lines · On Mon, 7 Feb 2022 11:30:18 +0100 Philippe Mathieu-Daudé <[email protected]>…
Quoted 15 lines · Greg Kurz
Quoted 5 lines · On Sun, 6 Feb 2022 20:10:23 -0500 Will Cohen <[email protected]> wrote:
This patch set currently places it in 9p-util only because 9p is the only place where this issue seems to have come up so far and we were wary of editing files too far afield, but I have no attachment to its specific location!
Inline comments are preferred on qemu-devel. Please don't top post ! This complicates the review a lot.
This is indeed a good candidate for osdep. This being said, unless there's some other user in the QEMU code base, it is acceptable to leave it under 9pfs.
Quoted 7 lines
Quoted 1 line
virtiofsd could eventually use it.
Indeed but virtiofsd is for linux hosts only AFAICT and I'm not aware of any work to support any other host OS.
Cc'ing virtio-fs people for inputs on this topic.
Indeeed, there's a lot of Linux specific code in the virtiofsd - I know people are interested in other platforms, but I'm not sure that's the right starting point.
Dave
Signature · 1 line
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Re: [PATCH v4 04/11] 9p: darwin: Handle struct dirent differences
In reply to Fabian FranzQuoted 9 lines · Fabian Franz
Comments inline:
hw/9pfs/9p-local.c +0
-0Quoted 6 lines
index
1a5e3eed73..7137a28109100644hw/9pfs/9p-local.c +0
-0@@ -559,6 +559,15 @@ static struct dirent *local_readdir(FsContext *ctx, V9fsFidOpenState *fs)
Quoted 9 lines
hw/9pfs/9p-local.c static struct dirent *local_readdir(FsContext *ctx, · line 565
Quoted 5 lines
hw/9pfs/9p-local.c +3
-0again: entry =readdir (fs->dir.stream); +#ifdef CONFIG_DARWIN +int td; + td =telldir (fs->dir.stream);Maybe call this „off“?
Yes, off is better. Will adjust for v5.
Quoted 12 lines
Quoted 10 lines
hw/9pfs/9p-local.c +6
-0+/* If telldir fails, fail the entire readdir call */ +if (td <0 ) { +return NULL ; + } + entry->d_seekoff = td; +#endif if (!entry) {return NULL ;}
Quoted 2 lines
This needs to be before the #ifdef!
Good catch, will adjust for v5. I moved it around twice and forgot to put it in the right place.
Quoted 69 lines
Quoted 69 lines
hw/9pfs/9p-proxy.c +15
-1@@ -706,7 +706,21 @@ static off_t proxy_telldir(FsContext *ctx, V9fsFidOpenState *fs)static struct dirent *proxy_readdir (FsContext *ctx,V9fsFidOpenState *fs) { -return readdir (fs->dir.stream); +struct dirent *entry; + entry =readdir (fs->dir.stream); +#ifdef CONFIG_DARWIN +if (!entry) { +return NULL ; + } +int td; + td =telldir (fs->dir.stream); +/* If telldir fails, fail the entire readdir call */ +if (td <0 ) { +return NULL ; + } + entry->d_seekoff = td; +#endif +return entry; }static void proxy_seekdir(FsContext *ctx, V9fsFidOpenState *fs,
off_t
off)hw/9pfs/9p-synth.c +4
-0@@ -222,7 +222,11 @@ static void synth_direntry(V9fsSynthNode *node, {strcpy (entry->d_name, node->name); entry->d_ino = node->attr->inode; +#ifdef CONFIG_DARWIN + entry->d_seekoff = off +1 ; +#else entry->d_off = off +1 ; +#endif } static struct dirent *synth_get_dentry(V9fsSynthNode *dir,hw/9pfs/9p-util.h +13
-0@@ -79,3 +79,20 @@ ssize_t fremovexattrat_nofollow(int dirfd, const char *filename, const char *name);#endif + + +/** +* Darwin has d_seekoff, which appears to function similarly to d_off. +* However, it does not appear to be supported on all file systems, +* so ensure it is manually injected earlier and call here when +* needed. +*/ + +inline off_t qemu_dirent_off (struct dirent *dent) +{ +#ifdef CONFIG_DARWIN +return dent->d_seekoff;
Quoted 9 lines
hw/9pfs/9p-util.h
Quoted 4 lines
hw/9pfs/9p-util.h +4
-0+#else +return dent->d_off; +#endif +}Are we sure we want a helper for two times the same ifdef? Deferring to maintainers here however.
Either way works for me too -- my current inclination is to leave it this way (as originally suggested by the maintainers), if for no other reason than that it allows the one comment to be referenced in the case of both uses.
Quoted 20 lines
hw/9pfs/9p.c +0
-0Quoted 18 lines
index
1563d7b7c6..cf694da354100644hw/9pfs/9p.c +2
-1@@ -27,6 +27,7 @@#include "virtio-9p.h" #include "fsdev/qemu-fsdev.h" #include "9p-xattr.h" +#include "9p-util.h" #include "coth.h" #include "trace.h" #include "migration/blocker.h" @@ -2281,7 +2282,11 @@ static int coroutine_fnv9fs_do_readdir_with_stat (V9fsPDU *pdu, count += len;v9fs_stat_free (&v9stat);v9fs_path_free (&path); - saved_dir_pos = dent->d_off; + saved_dir_pos =qemu_dirent_off (dent);
Quoted 9 lines
hw/9pfs/9p.c static int coroutine_fn · line 2290
Quoted 4 lines
hw/9pfs/9p.c +4
-0+if (saved_dir_pos <0 ) { + err = saved_dir_pos; +break ; + }Do we still need this error-handling? I had removed it in my interdiff patch.
That's correct, it in fact can be removed. d_seekoff yields a __uint64_t (
https://developer.apple.com/documentation/kernel/direntry/1415494-d_seekoff?language=objc).
Will adjust for v5.
Quoted 18 lines
Quoted 18 lines
hw/9pfs/9p.c +0
-0}v9fs_readdir_unlock(&fidp->fs.dir);hw/9pfs/9p.c +1
-0@@ -2420,6 +2425,7 @@ static int coroutine_fn v9fs_do_readdir(V9fsPDU *pdu, V9fsFidState *fidp, V9fsString name;int len, err =0 ;int32_t count =0 ; +off_t off;struct dirent *dent;struct stat *st;struct V9fsDirEnt *entries = NULL;hw/9pfs/9p.c +0
-0@@ -2480,12 +2486,17 @@ static int coroutine_fn v9fs_do_readdir(V9fsPDU *pdu, V9fsFidState *fidp, qid.version =0 ; }
Quoted 9 lines
hw/9pfs/9p.c static int coroutine_fn v9fs_do_readdir(V9fsPDU · line 2494
Quoted 5 lines
hw/9pfs/9p.c +5
-0+ off =qemu_dirent_off (dent); +if (off <0 ) { + err = off; +break ; + }Same here - if this can never fail, why add the error handling?
See above.
Quoted 36 lines
Quoted 36 lines
hw/9pfs/9p.c +1
-1v9fs_string_init (&name);v9fs_string_sprintf (&name,"%s" , dent->d_name);/* 11 = 7 + 4 (7 = start offset, 4 = space for storing count) */ len =pdu_marshal (pdu,11 + count,"Qqbs" , - &qid, dent->d_off, + &qid, off, dent->d_type, &name);v9fs_string_free(&name);hw/9pfs/codir.c +7
-0@@ -167,7 +167,14 @@ static int do_readdir_many(V9fsPDU *pdu, V9fsFidState *fidp, } size += len; +/* This conditional statement is identical in +* function to qemu_dirent_off, described in 9p-util.h, +* since that header cannot be included here. */ +#ifdef CONFIG_DARWIN + saved_dir_pos = dent->d_seekoff; +#else saved_dir_pos = dent->d_off; +#endif }/* restore (last) saved position */--
2.32.0 (Apple Git-132)
Re: [PATCH v4 10/11] 9p: darwin: meson: Allow VirtFS on Darwin
In reply to Christian SchoenebeckQuoted 54 lines · Christian Schoenebeck
Quoted 20 lines · On Montag, 7. Februar 2022 02:05:32 CET Will Cohen wrote:
On Sun, Feb 6, 2022 at 4:22 PM Philippe Mathieu-Daudé <[email protected]>
Quoted 17 lines · wrote:
Quoted 16 lines · Will Cohen
From: Keno Fischer <[email protected]>
Signed-off-by Keno Fischer <[email protected]>[Michael Roitzsch: - Rebase for NixOS]Signed-off-by Michael Roitzsch <[email protected]>[Will Cohen: - Rebase to master]Signed-off-by Will Cohen <[email protected]>Reviewed-by Paolo Bonzini <[email protected]>[Will Cohen: - Add check for pthread_fchdir_np to virtfs]Signed-off-by Will Cohen <[email protected]>---
fsdev/meson.build | 1 + meson.build | 14 ++++++++++---- 2 files changed, 11 insertions(+), 4 deletions(-)Quoted 8 lines
Quoted 6 lines
Review
Quoted 2 lines
(quoted diff) +1
-1-have_virtfs_proxy_helper = have_virtfs and have_tools +have_virtfs_proxy_helper = targetos == 'linux' and have_virtfs and
have_toolsWhy do you restrict the proxy-helper to Linux?
Only because porting the proxy-helper to macOS is outside the scope of
this
Quoted 2 lines
particular patch. While some initial concepts around it have been considered by some of the contributors to this patch, those
implementations
Quoted 3 lines
weren't tested enough and the security implications weren't considered in full. We assume that this could be an additional implementation later on, if the functionality is considered important down the road.
In general that's fine with me. I would have probably made that "targetos != 'darwin'" instead of "targetos == 'linux'", but I leave that up
to you.On the long term we will probably deprecate the 9p 'proxy' fs driver anyway.
While it had some good ideas, being realistic though: nobody has worked on the
9p proxy driver/backend for many years and it is not in good shape.I can imagine that due to the ground being laid by these series, that we will
also open 9p for BSD, but that should be done a bit later and hence does not
belong into these series.
Quoted 9 lines
But once again: it would not have hurt to make your intentions clear either in
the commit log or by in-source comment. :)Best regards,
Christian Schoenebeck
Acknowledged! For v5 will change it to != 'darwin' and note it as well, for clarity.
Re: [PATCH v4 04/11] 9p: darwin: Handle struct dirent differences
In reply to Will CohenComments inline:
hw/9pfs/9p-local.c +0 -0
hw/9pfs/9p-local.c static struct dirent *local_readdir(FsContext *ctx, · line 565
Quoted 11 lines
index
1a5e3eed73..7137a28109100644hw/9pfs/9p-local.c +3
-0@@ -559,6 +559,15 @@ static struct dirent *local_readdir(FsContext *ctx, V9fsFidOpenState *fs) again: entry =readdir (fs->dir.stream); +#ifdef CONFIG_DARWIN +int td; + td =telldir (fs->dir.stream);
Maybe call this „off“?
Quoted 10 lines
hw/9pfs/9p-local.c +6
-0+/* If telldir fails, fail the entire readdir call */ +if (td <0 ) { +return NULL ; + } + entry->d_seekoff = td; +#endif if (!entry) {return NULL ;}
This needs to be before the #ifdef!
Quoted 60 lines
hw/9pfs/9p-proxy.c +15
-1@@ -706,7 +706,21 @@ static off_t proxy_telldir(FsContext *ctx, V9fsFidOpenState *fs)static struct dirent *proxy_readdir (FsContext *ctx,V9fsFidOpenState *fs) { -return readdir (fs->dir.stream); +struct dirent *entry; + entry =readdir (fs->dir.stream); +#ifdef CONFIG_DARWIN +if (!entry) { +return NULL ; + } +int td; + td =telldir (fs->dir.stream); +/* If telldir fails, fail the entire readdir call */ +if (td <0 ) { +return NULL ; + } + entry->d_seekoff = td; +#endif +return entry; }static void
proxy_seekdir(FsContext *ctx, V9fsFidOpenState *fs, off_t off)hw/9pfs/9p-synth.c +4
-0@@ -222,7 +222,11 @@ static void synth_direntry(V9fsSynthNode *node, {strcpy (entry->d_name, node->name); entry->d_ino = node->attr->inode; +#ifdef CONFIG_DARWIN + entry->d_seekoff = off +1 ; +#else entry->d_off = off +1 ; +#endif } static struct dirent *synth_get_dentry(V9fsSynthNode *dir,hw/9pfs/9p-util.h +7
-0@@ -79,3 +79,20 @@ ssize_t fremovexattrat_nofollow(int dirfd, const char *filename, const char *name);#endif + + +/** +* Darwin has d_seekoff, which appears to function similarly to d_off. +* However, it does not appear to be supported on all file systems, +* so ensure it is manually injected earlier and call here when +* needed.
hw/9pfs/9p-util.h ssize_t fremovexattrat_nofollow(int dirfd, const char
Quoted 10 lines
hw/9pfs/9p-util.h +10
-0+*/ + +inline off_t qemu_dirent_off (struct dirent *dent) +{ +#ifdef CONFIG_DARWIN +return dent->d_seekoff; +#else +return dent->d_off; +#endif +}
Are we sure we want a helper for two times the same ifdef? Deferring to maintainers here however.
hw/9pfs/9p.c +0 -0
Quoted 12 lines
index
1563d7b7c6..cf694da354100644hw/9pfs/9p.c +1
-0@@ -27,6 +27,7 @@#include "virtio-9p.h" #include "fsdev/qemu-fsdev.h" #include "9p-xattr.h" +#include "9p-util.h" #include "coth.h" #include "trace.h" #include "migration/blocker.h"
hw/9pfs/9p.c static int coroutine_fn · line 2290
Quoted 10 lines
hw/9pfs/9p.c +5
-1@@ -2281,7 +2282,11 @@ static int coroutine_fnv9fs_do_readdir_with_stat (V9fsPDU *pdu, count += len;v9fs_stat_free (&v9stat);v9fs_path_free (&path); - saved_dir_pos = dent->d_off; + saved_dir_pos =qemu_dirent_off (dent); +if (saved_dir_pos <0 ) { + err = saved_dir_pos; +break ; + }
Do we still need this error-handling? I had removed it in my interdiff patch.
Quoted 14 lines
hw/9pfs/9p.c +0
-0}v9fs_readdir_unlock(&fidp->fs.dir);hw/9pfs/9p.c +1
-0@@ -2420,6 +2425,7 @@ static int coroutine_fn v9fs_do_readdir(V9fsPDU *pdu, V9fsFidState *fidp, V9fsString name;int len, err =0 ;int32_t count =0 ; +off_t off;struct dirent *dent;struct stat *st;struct V9fsDirEnt *entries = NULL;
hw/9pfs/9p.c static int coroutine_fn v9fs_do_readdir(V9fsPDU · line 2494
Quoted 9 lines
hw/9pfs/9p.c +5
-0@@ -2480,12 +2486,17 @@ static int coroutine_fn v9fs_do_readdir(V9fsPDU *pdu, V9fsFidState *fidp, qid.version =0 ; } + off =qemu_dirent_off (dent); +if (off <0 ) { + err = off; +break ; + }
Same here - if this can never fail, why add the error handling?
Quoted 34 lines
hw/9pfs/9p.c +1
-1v9fs_string_init (&name);v9fs_string_sprintf (&name,"%s" , dent->d_name);/* 11 = 7 + 4 (7 = start offset, 4 = space for storing count) */ len =pdu_marshal (pdu,11 + count,"Qqbs" , - &qid, dent->d_off, + &qid, off, dent->d_type, &name);v9fs_string_free(&name);hw/9pfs/codir.c +7
-0@@ -167,7 +167,14 @@ static int do_readdir_many(V9fsPDU *pdu, V9fsFidState *fidp, } size += len; +/* This conditional statement is identical in +* function to qemu_dirent_off, described in 9p-util.h, +* since that header cannot be included here. */ +#ifdef CONFIG_DARWIN + saved_dir_pos = dent->d_seekoff; +#else saved_dir_pos = dent->d_off; +#endif }/* restore (last) saved position */--
2.32.0 (Apple Git-132)
Re: [PATCH v4 10/11] 9p: darwin: meson: Allow VirtFS on Darwin
In reply to Will CohenQuoted 25 lines · On Montag, 7. Februar 2022 02:05:32 CET Will Cohen wrote:
On Sun, Feb 6, 2022 at 4:22 PM Philippe Mathieu-Daudé <[email protected]>
Quoted 22 lines · wrote:
Quoted 16 lines · Will Cohen
From: Keno Fischer <[email protected]>
Signed-off-by Keno Fischer <[email protected]>[Michael Roitzsch: - Rebase for NixOS]Signed-off-by Michael Roitzsch <[email protected]>[Will Cohen: - Rebase to master]Signed-off-by Will Cohen <[email protected]>Reviewed-by Paolo Bonzini <[email protected]>[Will Cohen: - Add check for pthread_fchdir_np to virtfs]Signed-off-by Will Cohen <[email protected]>---
fsdev/meson.build | 1 + meson.build | 14 ++++++++++---- 2 files changed, 11 insertions(+), 4 deletions(-)Review
Quoted 2 lines
(quoted diff) +1
-1-have_virtfs_proxy_helper = have_virtfs and have_tools +have_virtfs_proxy_helper = targetos == 'linux' and have_virtfs and
have_tools
Quoted 8 lines
Quoted 1 line
Why do you restrict the proxy-helper to Linux?
Only because porting the proxy-helper to macOS is outside the scope of this particular patch. While some initial concepts around it have been considered by some of the contributors to this patch, those implementations weren't tested enough and the security implications weren't considered in full. We assume that this could be an additional implementation later on, if the functionality is considered important down the road.
In general that's fine with me. I would have probably made that "targetos != 'darwin'" instead of "targetos == 'linux'", but I leave that up to you.
On the long term we will probably deprecate the 9p 'proxy' fs driver anyway. While it had some good ideas, being realistic though: nobody has worked on the 9p proxy driver/backend for many years and it is not in good shape.
I can imagine that due to the ground being laid by these series, that we will also open 9p for BSD, but that should be done a bit later and hence does not belong into these series.
But once again: it would not have hurt to make your intentions clear either in the commit log or by in-source comment. :)
Best regards,
Christian Schoenebeck
Quoted 6 lines · On Sonntag, 6. Februar 2022 21:07:08 CET Will Cohen wrote:
This is a followup to
https://lists.nongnu.org/archive/html/qemu-devel/2022-01/msg05993.html,
adding 9p server support for Darwin.Since v3, the following changes have been made:
Quoted 13 lines
- Move
XATTR_SIZE_MAXtoP9_XATTR_SIZEMAX in9p.h, and provide explanatory context as preliminary solution - Add explanatory note surrounding virtio-9p-test with output of pre-patch failing test - Remove superfluous header guards from file-opt-9p
- Add note about virtfs-proxy-helper being disabled on non-linux for this patch series - Note radar filed with Apple for missing mknodat syscall
- Replace direct syscall topthread_fchdirwithpthread_fchdir_np, and add check for this function’s presence in meson - Ensure thatd_seekoffis filled using telldir on darwin, and createqemu_dirent_offhelper to decide which to access. - Ensure that [amc]tim.tv_sec are all initialized alongside [amc]tim.tv_nsec in 9p-proxy - Ensure that all patch email addresses are valid
- Add telldir error handling for dirent on darwin
As this series already has seen some revisions and is on a good way to become queued soon: it is helpful to immediately see here which patches exactly got changed, because some of the patches already look fine.
For already reviewed patches that you won't change: you can take over people's reviewed-by tags in the next revision.
Best regards,
Christian Schoenebeck
Quoted 33 lines
Keno Fischer (10):
9p: linux: Fix a couple Linux assumptions 9p: Rename 9p-util -> 9p-util-linux
9p: darwin: Handle struct stat(fs) differences 9p: darwin: Handle struct dirent differences 9p: darwin: Ignore O_{NOATIME, DIRECT}
9p: darwin: MoveXATTR_SIZE_MAX->P9_XATTR_SIZE_MAX9p: darwin:*xattr_nofollowimplementations 9p: darwin: Compatibility for f/l*xattr 9p: darwin: Implement compatibility for mknodat 9p: darwin: meson: Allow VirtFS on DarwinWill Cohen (1):
9p: darwin: Adjust assumption on virtio-9p-testfsdev/file-op-9p.h | 9 ++- fsdev/meson.build | 1 + hw/9pfs/9p-local.c | 28 ++++++-- hw/9pfs/9p-proxy.c | 38 ++++++++++- hw/9pfs/9p-synth.c | 6 ++ hw/9pfs/9p-util-darwin.c | 91 ++++++++++++++++++++++++++ hw/9pfs/{9p-util.c => 9p-util-linux.c} | 7 +- hw/9pfs/9p-util.h | 38 +++++++++++ hw/9pfs/9p.c | 50 ++++++++++++-- hw/9pfs/9p.h | 11 ++++ hw/9pfs/codir.c | 7 ++ hw/9pfs/meson.build | 3 +- include/qemu/xattr.h | 4 +- meson.build | 14 ++-- tests/qtest/virtio-9p-test.c | 2 +- 15 files changed, 285 insertions(+), 24 deletions(-) create mode 100644 hw/9pfs/9p-util-darwin.c rename hw/9pfs/{9p-util.c => 9p-util-linux.c} (90%)
Re: [PATCH v4 09/11] 9p: darwin: Implement compatibility for mknodat
In reply to Dr. David Alan GilbertQuoted 30 lines · On Montag, 7. Februar 2022 11:57:25 CET Dr. David Alan Gilbert wrote:
Quoted 29 lines · * Greg Kurz ([email protected]) wrote:
On Mon, 7 Feb 2022 11:30:18 +0100
Quoted 15 lines · Philippe Mathieu-Daudé
Quoted 14 lines · Greg Kurz
On Sun, 6 Feb 2022 20:10:23 -0500
Quoted 7 lines · Will Cohen
This patch set currently places it in 9p-util only because 9p is the only
place where this issue seems to have come up so far and we were wary of
editing files too far afield, but I have no attachment to its specific
location!Inline comments are preferred on qemu-devel. Please don't top post ! This complicates the review a lot.
Quoted 7 lines
Quoted 5 lines
This is indeed a good candidate for osdep. This being said, unless there's
some other user in the QEMU code base, it is acceptable to leave it under
9pfs.virtiofsd could eventually use it.
Indeed but virtiofsd is for linux hosts only AFAICT and I'm not aware of any work to support any other host OS.
Quoted 7 lines
Quoted 1 line
Cc'ing virtio-fs people for inputs on this topic.
Indeeed, there's a lot of Linux specific code in the virtiofsd - I know people are interested in other platforms, but I'm not sure that's the right starting point.
Dave
Agreeing with Greg here: i.e. I would have placed this into osdep, but I would not insist on it either.
Best regards,
Christian Schoenebeck
Re: [PATCH v4 10/11] 9p: darwin: meson: Allow VirtFS on Darwin
In reply to Will CohenQuoted 32 lines · On Sonntag, 6. Februar 2022 21:07:18 CET Will Cohen wrote:
From: Keno Fischer <[email protected]>
Signed-off-by Keno Fischer <[email protected]>[Michael Roitzsch: - Rebase for NixOS]Signed-off-by Michael Roitzsch <[email protected]>[Will Cohen: - Rebase to master]Signed-off-by Will Cohen <[email protected]>Reviewed-by Paolo Bonzini <[email protected]>[Will Cohen: - Add check for pthread_fchdir_np to virtfs]Signed-off-by Will Cohen <[email protected]>--- fsdev/meson.build | 1 + meson.build | 14 ++++++++++---- 2 files changed, 11 insertions(+), 4 deletions(-)fsdev/meson.build +1
-0@@ -7,6 +7,7 @@ fsdev_ss.add(when: ['CONFIG_FSDEV_9P'], if_true: files( 'qemu-fsdev.c', ), if_false: files('qemu-fsdev-dummy.c')) softmmu_ss.add_all(when: 'CONFIG_LINUX', if_true: fsdev_ss) +softmmu_ss.add_all(when: 'CONFIG_DARWIN', if_true: fsdev_ss) if have_virtfs_proxy_helper executable('virtfs-proxy-helper',meson.build +0
-0
meson.build if not get_option('dbus_display').disabled() · line 1425
Quoted 6 lines
meson.build +2
-1@@ -1421,17 +1421,23 @@ if not get_option('dbus_display').disabled() endif endif -have_virtfs = (targetos == 'linux' and +if targetos == 'darwin' and cc.has_function('pthread_fchdir_np') + have_virtfs = have_system
As you are going for a v5 anyway: I would add an error message here if pthread_fchdir_np() is not available. Because it is a bit frustrating for users if their options silently got ignored without any indication why.
Quoted 22 lines
meson.build +4
-1+else + have_virtfs = (targetos == 'linux' and have_system and libattr.found() and libcap_ng.found()) +endif -have_virtfs_proxy_helper = have_virtfs and have_tools +have_virtfs_proxy_helper = targetos == 'linux' and have_virtfs and
have_toolsif get_option('virtfs').enabled()
if nothave_virtfsmeson.build +4
-2- if targetos != 'linux' - error('virtio-9p (virtfs) requires Linux') + if targetos != 'linux' and targetos != 'darwin' + error('virtio-9p (virtfs) requires Linux or Darwin') + elif targetos == 'darwin' and not cc.has_function('pthread_fchdir_np') + error('virtio-9p (virtfs) on Darwin requires the presence of
pthread_fchdir_np') elif notlibcap_ng.found()or notlibattr.found()
error('virtio-9p (virtfs) requires libcap-ng-devel and
libattr-devel') elif nothave_system
Re: [PATCH v4 04/11] 9p: darwin: Handle struct dirent differences
In reply to Will CohenQuoted 48 lines · On Sonntag, 6. Februar 2022 21:07:12 CET Will Cohen wrote:
From: Keno Fischer <[email protected]>
On darwin
d_seekoffexists, but is optional and does not seem to be commonly used by file systems. Usetelldirinstead to obtain the seek offset and inject it intod_seekoff, and create aqemu_dirent_offhelper to call it appropriately when appropriate.Signed-off-by Keno Fischer <[email protected]>[Michael Roitzsch: - Rebase for NixOS]Signed-off-by Michael Roitzsch <[email protected]>[Will Cohen: - Adjust to pass testing
- Ensure thatd_seekoffis filled using telldir on darwin, and createqemu_dirent_offhelper to decide which to access]
[Fabian Franz: - Add telldir error handling for darwin] [Will Cohen: - Ensure that telldir error handling uses
signed int]Signed-off-by Fabian Franz <[email protected]>Signed-off-by Will Cohen <[email protected]>--- hw/9pfs/9p-local.c | 9 +++++++++ hw/9pfs/9p-proxy.c | 16 +++++++++++++++- hw/9pfs/9p-synth.c | 4 ++++ hw/9pfs/9p-util.h | 17 +++++++++++++++++ hw/9pfs/9p.c | 15 +++++++++++++-- hw/9pfs/codir.c | 7 +++++++ 6 files changed, 65 insertions(+), 3 deletions(-)hw/9pfs/9p-local.c +9
-0@@ -559,6 +559,15 @@ static struct dirent *local_readdir(FsContext *ctx, V9fsFidOpenState *fs) again: entry =readdir (fs->dir.stream); +#ifdef CONFIG_DARWIN +int td; + td =telldir (fs->dir.stream); +/* If telldir fails, fail the entire readdir call */ +if (td <0 ) { +return NULL ; + } + entry->d_seekoff = td; +#endif if (!entry) {return NULL ;
Quoted 1 line
}
'entry' may be NULL, so the 'if (!entry) {' check should be before the Darwin specific code to avoid a crash on macOS.
Quoted 51 lines
hw/9pfs/9p-proxy.c +15
-1@@ -706,7 +706,21 @@ static off_t proxy_telldir(FsContext *ctx, V9fsFidOpenState *fs)static struct dirent *proxy_readdir (FsContext *ctx,V9fsFidOpenState *fs) { -return readdir (fs->dir.stream); +struct dirent *entry; + entry =readdir (fs->dir.stream); +#ifdef CONFIG_DARWIN +if (!entry) { +return NULL ; + } +int td; + td =telldir (fs->dir.stream); +/* If telldir fails, fail the entire readdir call */ +if (td <0 ) { +return NULL ; + } + entry->d_seekoff = td; +#endif +return entry; }static void
proxy_seekdir(FsContext *ctx, V9fsFidOpenState *fs, off_t off)hw/9pfs/9p-synth.c +4
-0@@ -222,7 +222,11 @@ static void synth_direntry(V9fsSynthNode *node, {strcpy (entry->d_name, node->name); entry->d_ino = node->attr->inode; +#ifdef CONFIG_DARWIN + entry->d_seekoff = off +1 ; +#else entry->d_off = off +1 ; +#endif } static struct dirent *synth_get_dentry(V9fsSynthNode *dir,hw/9pfs/9p-util.h +0
-0@@ -79,3 +79,20 @@ ssize_t fremovexattrat_nofollow(int dirfd, const char *filename, const char *name);
hw/9pfs/9p-util.h ssize_t fremovexattrat_nofollow(int dirfd, const char · line 90
Quoted 10 lines
hw/9pfs/9p-util.h +9
-0#endif + + +/** +* Darwin has d_seekoff, which appears to function similarly to d_off. +* However, it does not appear to be supported on all file systems, +* so ensure it is manually injected earlier and call here when +* needed. +*/ +
Nitpicking: no blank line here please.
Quoted 21 lines
hw/9pfs/9p-util.h +8
-0+inline off_t qemu_dirent_off (struct dirent *dent) +{ +#ifdef CONFIG_DARWIN +return dent->d_seekoff; +#else +return dent->d_off; +#endif +}hw/9pfs/9p.c +1
-0@@ -27,6 +27,7 @@#include "virtio-9p.h" #include "fsdev/qemu-fsdev.h" #include "9p-xattr.h" +#include "9p-util.h" #include "coth.h" #include "trace.h" #include "migration/blocker.h"
hw/9pfs/9p.c static int coroutine_fn · line 2290
Quoted 10 lines
hw/9pfs/9p.c +5
-1@@ -2281,7 +2282,11 @@ static int coroutine_fn v9fs_do_readdir_with_stat(V9fsPDU *pdu, count += len;v9fs_stat_free (&v9stat);v9fs_path_free (&path); - saved_dir_pos = dent->d_off; + saved_dir_pos =qemu_dirent_off (dent); +if (saved_dir_pos <0 ) { + err = saved_dir_pos; +break ; + } }
That check is no longer needed here, is it?
Quoted 11 lines
hw/9pfs/9p.c +1
-0v9fs_readdir_unlock (&fidp->fs.dir);@@ -2420,6 +2425,7 @@ static int coroutine_fn v9fs_do_readdir(V9fsPDU *pdu, V9fsFidState *fidp, V9fsString name;int len, err =0 ;int32_t count =0 ; +off_t off;struct dirent *dent;struct stat *st;struct V9fsDirEnt *entries =NULL ;
hw/9pfs/9p.c static int coroutine_fn v9fs_do_readdir(V9fsPDU · line 2493
Quoted 8 lines
hw/9pfs/9p.c +5
-0@@ -2480,12 +2486,17 @@ static int coroutine_fn v9fs_do_readdir(V9fsPDU *pdu, V9fsFidState *fidp, qid.version =0 ; } + off =qemu_dirent_off (dent); +if (off <0 ) { + err = off; +break ; + }
Likewise: is this check still needed?
Quoted 16 lines
hw/9pfs/9p.c +1
-1v9fs_string_init (&name);v9fs_string_sprintf (&name,"%s" , dent->d_name);/* 11 = 7 + 4 (7 = start offset, 4 = space for storing count) */ len =pdu_marshal (pdu,11 + count,"Qqbs" , - &qid, dent->d_off, + &qid, off, dent->d_type, &name);v9fs_string_free (&name);hw/9pfs/codir.c +0
-0@@ -167,7 +167,14 @@ static int do_readdir_many(V9fsPDU *pdu, V9fsFidState *fidp, }
hw/9pfs/codir.c static int do_readdir_many(V9fsPDU *pdu, V9fsFidState · line 177
Quoted 10 lines
hw/9pfs/codir.c +7
-0size += len; +/* This conditional statement is identical in +* function to qemu_dirent_off, described in 9p-util.h, +* since that header cannot be included here. */ +#ifdef CONFIG_DARWIN + saved_dir_pos = dent->d_seekoff; +#else saved_dir_pos = dent->d_off; +#endif
Why can't the header not be included here? Obvious preference would be to use qemu_dirent_off() here as well, to have control at one central code location.
Quoted 3 lines
hw/9pfs/codir.c +0
-0}/* restore (last) saved position */
Re: [PATCH v4 10/11] 9p: darwin: meson: Allow VirtFS on Darwin
In reply to Christian SchoenebeckQuoted 55 lines · Christian Schoenebeck
Quoted 32 lines · On Sonntag, 6. Februar 2022 21:07:18 CET Will Cohen wrote:
From: Keno Fischer <[email protected]>
Signed-off-by Keno Fischer <[email protected]>[Michael Roitzsch: - Rebase for NixOS]Signed-off-by Michael Roitzsch <[email protected]>[Will Cohen: - Rebase to master]Signed-off-by Will Cohen <[email protected]>Reviewed-by Paolo Bonzini <[email protected]>[Will Cohen: - Add check for pthread_fchdir_np to virtfs]Signed-off-by Will Cohen <[email protected]>--- fsdev/meson.build | 1 + meson.build | 14 ++++++++++---- 2 files changed, 11 insertions(+), 4 deletions(-)fsdev/meson.build +1
-0@@ -7,6 +7,7 @@ fsdev_ss.add(when: ['CONFIG_FSDEV_9P'], if_true: files( 'qemu-fsdev.c', ), if_false: files('qemu-fsdev-dummy.c')) softmmu_ss.add_all(when: 'CONFIG_LINUX', if_true: fsdev_ss) +softmmu_ss.add_all(when: 'CONFIG_DARWIN', if_true: fsdev_ss) if have_virtfs_proxy_helper executable('virtfs-proxy-helper',meson.build +0
-0meson.build if not get_option('dbus_display').disabled() · line 1425
Quoted 6 lines
meson.build +2
-1@@ -1421,17 +1421,23 @@ if not get_option('dbus_display').disabled() endif endif -have_virtfs = (targetos == 'linux' and +if targetos == 'darwin' and cc.has_function('pthread_fchdir_np') + have_virtfs = have_systemAs you are going for a v5 anyway: I would add an error message here if
pthread_fchdir_np()is not available. Because it is a bit frustrating for users if their options silently got ignored without any indication why.Quoted 11 lines
meson.build +4
-1+else + have_virtfs = (targetos == 'linux' and have_system and libattr.found() and libcap_ng.found()) +endif -have_virtfs_proxy_helper = have_virtfs and have_tools +have_virtfs_proxy_helper = targetos == 'linux' and have_virtfs and
have_tools
Quoted 10 lines
meson.build if not get_option('dbus_display').disabled()
Quoted 7 lines
if get_option('virtfs').enabled()
if nothave_virtfsmeson.build +3
-2- if targetos != 'linux' - error('virtio-9p (virtfs) requires Linux') + if targetos != 'linux' and targetos != 'darwin' + error('virtio-9p (virtfs) requires Linux or Darwin') + elif targetos == 'darwin' and not
cc.has_function('pthread_fchdir_np')Quoted 2 lines
+ error('virtio-9p (virtfs) on Darwin requires the presence of
pthread_fchdir_np')
Does the error message here suffice for that need? Right now if they're running a system without pthread_fchdir_np and don't specify the option, I think it'll just quietly disable, but if they --enable-virtfs and the function isn't there, they should get a note. I assume this is better, so that the ability to compile isn't contingent on having the latest OS, even if full support for older OSes isn't provided.
Quoted 6 lines
elif not
libcap_ng.found()or notlibattr.found()Quoted 2 lines
error('virtio-9p (virtfs) requires libcap-ng-devel and
libattr-devel') elif nothave_system
Re: [PATCH v4 10/11] 9p: darwin: meson: Allow VirtFS on Darwin
In reply to Christian SchoenebeckQuoted 35 lines · On Mon, 07 Feb 2022 15:15:46 +0100 Christian Schoenebeck…
Quoted 25 lines · On Montag, 7. Februar 2022 02:05:32 CET Will Cohen wrote:
On Sun, Feb 6, 2022 at 4:22 PM Philippe Mathieu-Daudé <[email protected]>
Quoted 22 lines · wrote:
Quoted 16 lines · Will Cohen
From: Keno Fischer <[email protected]>
Signed-off-by Keno Fischer <[email protected]>[Michael Roitzsch: - Rebase for NixOS]Signed-off-by Michael Roitzsch <[email protected]>[Will Cohen: - Rebase to master]Signed-off-by Will Cohen <[email protected]>Reviewed-by Paolo Bonzini <[email protected]>[Will Cohen: - Add check for pthread_fchdir_np to virtfs]Signed-off-by Will Cohen <[email protected]>---
fsdev/meson.build | 1 + meson.build | 14 ++++++++++---- 2 files changed, 11 insertions(+), 4 deletions(-)Review
Quoted 2 lines
(quoted diff) +1
-1-have_virtfs_proxy_helper = have_virtfs and have_tools +have_virtfs_proxy_helper = targetos == 'linux' and have_virtfs and
have_toolsQuoted 8 lines
Quoted 1 line
Why do you restrict the proxy-helper to Linux?
Only because porting the proxy-helper to macOS is outside the scope of this particular patch. While some initial concepts around it have been considered by some of the contributors to this patch, those implementations weren't tested enough and the security implications weren't considered in full. We assume that this could be an additional implementation later on, if the functionality is considered important down the road.
Quoted 8 lines
In general that's fine with me. I would have probably made that "targetos != 'darwin'" instead of "targetos == 'linux'", but I leave that up to you.
On the long term we will probably deprecate the 9p 'proxy' fs driver anyway. While it had some good ideas, being realistic though: nobody has worked on the 9p proxy driver/backend for many years and it is not in good shape.
It definitely isn't indeed. Also it is super slow by design since the round trip of a 9p request involves QEMU on both entry and exit:
[guest] --> [QEMU]--> [virtfs-proxy-helper]-->[QEMU]-->[guest]
A more modern and efficient approach would be to have a vhost-user-9p implementation : requests would be directly handled by the external process, without QEMU hops. But this a fair amount of work.
Quoted 11 lines
I can imagine that due to the ground being laid by these series, that we will also open 9p for BSD, but that should be done a bit later and hence does not belong into these series.
But once again: it would not have hurt to make your intentions clear either in the commit log or by in-source comment. :)
Best regards,
Christian Schoenebeck
Quoted 30 lines · Christian Schoenebeck
Quoted 7 lines · On Sonntag, 6. Februar 2022 21:07:08 CET Will Cohen wrote:
This is a followup to
https://lists.nongnu.org/archive/html/qemu-devel/2022-01/msg05993.html,
adding 9p server support for Darwin.Since v3, the following changes have been made:
- Move
XATTR_SIZE_MAXtoP9_XATTR_SIZEMAX in9p.h, and provideexplanatory
Quoted 6 lines
context as preliminary solution - Add explanatory note surrounding virtio-9p-test with output of pre-patch failing test - Remove superfluous header guards from file-opt-9p
- Add note about virtfs-proxy-helper being disabled on non-linux for this patch series - Note radar filed with Apple for missing mknodat syscall
- Replace direct syscall topthread_fchdirwithpthread_fchdir_np, andadd
Quoted 2 lines
check for this function’s presence in meson - Ensure that
d_seekoffis filled using telldir on darwin, and createqemu_dirent_offhelper todecide
Quoted 4 lines
which to access. - Ensure that [amc]tim.tv_sec are all initialized alongside [amc]tim.tv_nsec in 9p-proxy - Ensure that all patch email addresses are valid
- Add telldir error handling for dirent on darwinAs this series already has seen some revisions and is on a good way to become
queued soon: it is helpful to immediately see here which patches exactly got
changed, because some of the patches already look fine.
Quoted 42 lines
For already reviewed patches that you won't change: you can take over people's
reviewed-by tags in the next revision.Best regards,
Christian SchoenebeckQuoted 33 lines
Keno Fischer (10):
9p: linux: Fix a couple Linux assumptions 9p: Rename 9p-util -> 9p-util-linux
9p: darwin: Handle struct stat(fs) differences 9p: darwin: Handle struct dirent differences 9p: darwin: Ignore O_{NOATIME, DIRECT}
9p: darwin: MoveXATTR_SIZE_MAX->P9_XATTR_SIZE_MAX9p: darwin:*xattr_nofollowimplementations 9p: darwin: Compatibility for f/l*xattr 9p: darwin: Implement compatibility for mknodat 9p: darwin: meson: Allow VirtFS on DarwinWill Cohen (1):
9p: darwin: Adjust assumption on virtio-9p-testfsdev/file-op-9p.h | 9 ++- fsdev/meson.build | 1 + hw/9pfs/9p-local.c | 28 ++++++-- hw/9pfs/9p-proxy.c | 38 ++++++++++- hw/9pfs/9p-synth.c | 6 ++ hw/9pfs/9p-util-darwin.c | 91 ++++++++++++++++++++++++++ hw/9pfs/{9p-util.c => 9p-util-linux.c} | 7 +- hw/9pfs/9p-util.h | 38 +++++++++++ hw/9pfs/9p.c | 50 ++++++++++++-- hw/9pfs/9p.h | 11 ++++ hw/9pfs/codir.c | 7 ++ hw/9pfs/meson.build | 3 +- include/qemu/xattr.h | 4 +- meson.build | 14 ++-- tests/qtest/virtio-9p-test.c | 2 +- 15 files changed, 285 insertions(+), 24 deletions(-) create mode 100644 hw/9pfs/9p-util-darwin.c rename hw/9pfs/{9p-util.c => 9p-util-linux.c} (90%)
Understood! Previous reviewed-by tags are already in v4, and these new ones will go into v5!
For reference in terms of changes, patches that were touched in v4:
Keno Fischer (10):
9p: linux: Fix a couple Linux assumptions (1/11) 9p: darwin: Handle struct stat(fs) differences (3/11) 9p: darwin: Handle struct dirent differences (4/11) 9p: darwin: Move XATTR_SIZE_MAX->P9_XATTR_SIZE_MAX (5/11) 9p: darwin: Implement compatibility for mknodat (9/11) 9p: darwin: meson: Allow VirtFS on Darwin (10/11)
Will Cohen (1):
9p: darwin: Adjust assumption on virtio-9p-test (11/11)
Additional changes to patches will be highlighted in the opening note for v5.
Re: [PATCH v4 09/11] 9p: darwin: Implement compatibility for mknodat
In reply to Greg KurzQuoted 20 lines · Greg Kurz
Quoted 17 lines · On Mon, 7 Feb 2022 11:30:18 +0100 Philippe Mathieu-Daudé <[email protected]>…
Quoted 15 lines · Greg Kurz
Quoted 5 lines · On Sun, 6 Feb 2022 20:10:23 -0500 Will Cohen <[email protected]> wrote:
This patch set currently places it in 9p-util only because 9p is the only place where this issue seems to have come up so far and we were wary of editing files too far afield, but I have no attachment to its specific location!
Inline comments are preferred on qemu-devel. Please don't top post ! This complicates the review a lot.
This is indeed a good candidate for osdep. This being said, unless there's some other user in the QEMU code base, it is acceptable to leave it under 9pfs.
Quoted 5 lines
Quoted 1 line
virtiofsd could eventually use it.
Indeed but virtiofsd is for linux hosts only AFAICT and I'm not aware of any work to support any other host OS.
[ CC Sergio ]
Will like to support virtiofs on other host OS. Getting rid of Linux specific parts should be doable. I think bigger challenge is how to make vhost-user stuff work on other OS, like macOS.
If virtiofsd was somehow running as part of qemu (and not as a separate process), then making rest of the filesystem code to work on other OS should not be too hard, I guess.
So question is, can one somehow run same virtiofsd code both as part of qemu as well as separate daemon based on need (and one does not have to maintain two separate code bases).
Thanks
Vivek
Quoted 3 lines
Cc'ing virtio-fs people for inputs on this topic.
Re: [PATCH v4 10/11] 9p: darwin: meson: Allow VirtFS on Darwin
In reply to Greg KurzQuoted 54 lines · On Montag, 7. Februar 2022 15:39:30 CET Greg Kurz wrote:
On Mon, 07 Feb 2022 15:15:46 +0100
Quoted 39 lines · Christian Schoenebeck
Quoted 27 lines · On Montag, 7. Februar 2022 02:05:32 CET Will Cohen wrote:
On Sun, Feb 6, 2022 at 4:22 PM Philippe Mathieu-Daudé <[email protected]>
Quoted 17 lines · wrote:
Quoted 16 lines · Will Cohen
From: Keno Fischer <[email protected]>
Signed-off-by Keno Fischer <[email protected]>[Michael Roitzsch: - Rebase for NixOS]Signed-off-by Michael Roitzsch <[email protected]>[Will Cohen: - Rebase to master]Signed-off-by Will Cohen <[email protected]>Reviewed-by Paolo Bonzini <[email protected]>[Will Cohen: - Add check for pthread_fchdir_np to virtfs]Signed-off-by Will Cohen <[email protected]>---
fsdev/meson.build | 1 + meson.build | 14 ++++++++++---- 2 files changed, 11 insertions(+), 4 deletions(-)Quoted 6 lines
Review
Quoted 2 lines
(quoted diff) +1
-1-have_virtfs_proxy_helper = have_virtfs and have_tools +have_virtfs_proxy_helper = targetos == 'linux' and have_virtfs and
have_toolsWhy do you restrict the proxy-helper to Linux?
Quoted 10 lines
Only because porting the proxy-helper to macOS is outside the scope of this
particular patch. While some initial concepts around it have been considered by some of the contributors to this patch, those implementations
weren't tested enough and the security implications weren't considered in
full. We assume that this could be an additional implementation later on,
if the functionality is considered important down the road.Quoted 8 lines
In general that's fine with me. I would have probably made that "targetos != 'darwin'" instead of "targetos == 'linux'", but I leave that up to you.
On the long term we will probably deprecate the 9p 'proxy' fs driver anyway. While it had some good ideas, being realistic though: nobody has worked on the 9p proxy driver/backend for many years and it is not in good shape.
It definitely isn't indeed. Also it is super slow by design since the round trip of a 9p request involves QEMU on both entry and exit:
Quoted 5 lines
[guest] --> [QEMU]--> [virtfs-proxy-helper]-->[QEMU]-->[guest]A more modern and efficient approach would be to have a vhost-user-9p implementation : requests would be directly handled by the external process, without QEMU hops. But this a fair amount of work.
That's already a bit offtopic, but how would you imagine that to work? You mean a system dependent solution that e.g. plugs in into KVM or something?
Quoted 9 lines
Quoted 9 lines
I can imagine that due to the ground being laid by these series, that we will also open 9p for BSD, but that should be done a bit later and hence does not belong into these series.
But once again: it would not have hurt to make your intentions clear either in the commit log or by in-source comment. :)
Best regards,
Christian Schoenebeck
Re: [PATCH v4 10/11] 9p: darwin: meson: Allow VirtFS on Darwin
In reply to Will CohenQuoted 83 lines · On Montag, 7. Februar 2022 15:37:00 CET Will Cohen wrote:
Quoted 69 lines · Christian Schoenebeck
Quoted 38 lines · On Sonntag, 6. Februar 2022 21:07:18 CET Will Cohen wrote:
From: Keno Fischer <[email protected]>
Signed-off-by Keno Fischer <[email protected]>[Michael Roitzsch: - Rebase for NixOS]Signed-off-by Michael Roitzsch <[email protected]>[Will Cohen: - Rebase to master]Signed-off-by Will Cohen <[email protected]>Reviewed-by Paolo Bonzini <[email protected]>[Will Cohen: - Add check for pthread_fchdir_np to virtfs]Signed-off-by Will Cohen <[email protected]>---
fsdev/meson.build | 1 + meson.build | 14 ++++++++++---- 2 files changed, 11 insertions(+), 4 deletions(-)fsdev/meson.build +1
-0@@ -7,6 +7,7 @@ fsdev_ss.add(when: ['CONFIG_FSDEV_9P'], if_true: files( 'qemu-fsdev.c', ), if_false: files('qemu-fsdev-dummy.c')) softmmu_ss.add_all(when: 'CONFIG_LINUX', if_true: fsdev_ss) +softmmu_ss.add_all(when: 'CONFIG_DARWIN', if_true: fsdev_ss)if
have_virtfs_proxy_helperexecutable('virtfs-proxy-helper',
meson.build +0
-0meson.build if not get_option('dbus_display').disabled() · line 1427
Quoted 8 lines
meson.build +2
-1@@ -1421,17 +1421,23 @@ if not get_option('dbus_display').disabled() endif endif -have_virtfs = (targetos == 'linux' and +if targetos == 'darwin' and cc.has_function('pthread_fchdir_np') + have_virtfs = have_systemAs you are going for a v5 anyway: I would add an error message here if
pthread_fchdir_np()is not available. Because it is a bit frustrating for users if their options silently got ignored without any indication why.Quoted 17 lines
meson.build +4
-1+else + have_virtfs = (targetos == 'linux' and have_system and libattr.found() and libcap_ng.found()) +endif -have_virtfs_proxy_helper = have_virtfs and have_tools +have_virtfs_proxy_helper = targetos == 'linux' and have_virtfs and
have_toolsif get_option('virtfs').enabled()
if not
have_virtfsQuoted 10 lines
meson.build if not get_option('dbus_display').disabled()
Quoted 5 lines
meson.build +3
-2- if targetos != 'linux' - error('virtio-9p (virtfs) requires Linux') + if targetos != 'linux' and targetos != 'darwin' + error('virtio-9p (virtfs) requires Linux or Darwin') + elif targetos == 'darwin' and not
cc.has_function('pthread_fchdir_np')Quoted 2 lines
+ error('virtio-9p (virtfs) on Darwin requires the presence of
pthread_fchdir_np')
Quoted 6 lines
Does the error message here suffice for that need? Right now if they're running a system without
pthread_fchdir_npand don't specify the option, I think it'll just quietly disable, but if they --enable-virtfs and the function isn't there, they should get a note. I assume this is better, so that the ability to compile isn't contingent on having the latest OS, even if full support for older OSes isn't provided.
Ah, got it. Yes, makes sense.
But what I would definitely change is the precise error message text here:
"Darwin" is a bit awkward for a regular user, because most macOS users never heard of "Darwin" in the context of Apple systems before. Using the term "darwin" in code is fine as it can be assumed that developers know the background, but as for regular users I would make it more clear that this is actually about macOS, e.g:
error('virtio-9p (virtfs) requires either Linux or Darwin (macOS)')
I don't mind how to write that exactly; braces, slash, replacing Darwin by macOS or whatever, but it should mention 'macOS' here in some form.
Quoted 5 lines
Quoted 5 lines
elif not
libcap_ng.found()or notlibattr.found()Quoted 3 lines
error('virtio-9p (virtfs) requires libcap-ng-devel and
libattr-devel') elif not
have_system
Re: [PATCH v4 04/11] 9p: darwin: Handle struct dirent differences
In reply to Christian SchoenebeckQuoted 46 lines · Christian Schoenebeck
Quoted 45 lines · On Sonntag, 6. Februar 2022 21:07:12 CET Will Cohen wrote:
From: Keno Fischer <[email protected]>
On darwin
d_seekoffexists, but is optional and does not seem to be commonly used by file systems. Usetelldirinstead to obtain the seek offset and inject it intod_seekoff, and create aqemu_dirent_offhelper to call it appropriately when appropriate.Signed-off-by Keno Fischer <[email protected]>[Michael Roitzsch: - Rebase for NixOS]Signed-off-by Michael Roitzsch <[email protected]>[Will Cohen: - Adjust to pass testing
- Ensure thatd_seekoffis filled using telldir on darwin, and createqemu_dirent_offhelper to decide which to access]
[Fabian Franz: - Add telldir error handling for darwin] [Will Cohen: - Ensure that telldir error handling uses
signed int]Signed-off-by Fabian Franz <[email protected]>Signed-off-by Will Cohen <[email protected]>--- hw/9pfs/9p-local.c | 9 +++++++++ hw/9pfs/9p-proxy.c | 16 +++++++++++++++- hw/9pfs/9p-synth.c | 4 ++++ hw/9pfs/9p-util.h | 17 +++++++++++++++++ hw/9pfs/9p.c | 15 +++++++++++++-- hw/9pfs/codir.c | 7 +++++++ 6 files changed, 65 insertions(+), 3 deletions(-)hw/9pfs/9p-local.c +8
-0@@ -559,6 +559,15 @@ static struct dirent *local_readdir(FsContext *ctx, V9fsFidOpenState *fs) again: entry =readdir (fs->dir.stream); +#ifdef CONFIG_DARWIN +int td; + td =telldir (fs->dir.stream); +/* If telldir fails, fail the entire readdir call */ +if (td <0 ) { +return NULL ; + } + entry->d_seekoff = td;
Quoted 9 lines
Quoted 4 lines
hw/9pfs/9p-local.c +1
-0+#endif if (!entry) {return NULL ;}'entry' may be NULL, so the 'if (!entry) {' check should be before the Darwin
specific code to avoid a crash on macOS.
Adjusting for v5.
Quoted 54 lines
hw/9pfs/9p-proxy.c static off_t proxy_telldir(FsContext *ctx, · line 708
Quoted 9 lines
hw/9pfs/9p-proxy.c +0
-0@@ -706,7 +706,21 @@ static off_t proxy_telldir(FsContext *ctx, V9fsFidOpenState *fs) static struct dirent *proxy_readdir(FsContext *ctx, V9fsFidOpenState*fs)
Quoted 19 lines
hw/9pfs/9p-proxy.c +15
-1{ -return readdir (fs->dir.stream); +struct dirent *entry; + entry =readdir (fs->dir.stream); +#ifdef CONFIG_DARWIN +if (!entry) { +return NULL ; + } +int td; + td =telldir (fs->dir.stream); +/* If telldir fails, fail the entire readdir call */ +if (td <0 ) { +return NULL ; + } + entry->d_seekoff = td; +#endif +return entry; }Quoted 1 line
static void proxy_seekdir(FsContext *ctx, V9fsFidOpenState *fs,
off_toff)
Quoted 23 lines
hw/9pfs/9p-synth.c +4
-0@@ -222,7 +222,11 @@ static void synth_direntry(V9fsSynthNode *node, {strcpy (entry->d_name, node->name); entry->d_ino = node->attr->inode; +#ifdef CONFIG_DARWIN + entry->d_seekoff = off +1 ; +#else entry->d_off = off +1 ; +#endif } static struct dirent *synth_get_dentry(V9fsSynthNode *dir,hw/9pfs/9p-util.h +0
-0@@ -79,3 +79,20 @@ ssize_t fremovexattrat_nofollow(int dirfd, const char *filename, const char *name);
Quoted 13 lines
hw/9pfs/9p-util.h ssize_t fremovexattrat_nofollow(int dirfd, const char *filename, · line 90
Quoted 10 lines
hw/9pfs/9p-util.h +9
-0#endif + + +/** +* Darwin has d_seekoff, which appears to function similarly to d_off. +* However, it does not appear to be supported on all file systems, +* so ensure it is manually injected earlier and call here when +* needed. +*/ +Nitpicking: no blank line here please.
Adjusting for v5.
Quoted 26 lines
Quoted 26 lines
hw/9pfs/9p-util.h +8
-0+inline off_t qemu_dirent_off (struct dirent *dent) +{ +#ifdef CONFIG_DARWIN +return dent->d_seekoff; +#else +return dent->d_off; +#endif +}hw/9pfs/9p.c +1
-1@@ -27,6 +27,7 @@#include "virtio-9p.h" #include "fsdev/qemu-fsdev.h" #include "9p-xattr.h" +#include "9p-util.h" #include "coth.h" #include "trace.h" #include "migration/blocker.h" @@ -2281,7 +2282,11 @@ static int coroutine_fn v9fs_do_readdir_with_stat(V9fsPDU *pdu, count += len;v9fs_stat_free (&v9stat);v9fs_path_free (&path); - saved_dir_pos = dent->d_off;
Quoted 9 lines
hw/9pfs/9p.c static int coroutine_fn v9fs_do_readdir_with_stat(V9fsPDU *pdu, · line 2290
Quoted 6 lines
hw/9pfs/9p.c +5
-0+ saved_dir_pos =qemu_dirent_off (dent); +if (saved_dir_pos <0 ) { + err = saved_dir_pos; +break ; + } }That check is no longer needed here, is it?
Correct! Adjusting for v5.
Quoted 16 lines
hw/9pfs/9p.c static int coroutine_fn v9fs_do_readdir(V9fsPDU
Quoted 4 lines
hw/9pfs/9p.c +0
-0v9fs_readdir_unlock (&fidp->fs.dir);@@ -2420,6 +2425,7 @@ static int coroutine_fn v9fs_do_readdir(V9fsPDU*pdu,
Quoted 11 lines
hw/9pfs/9p.c +1
-0V9fsFidState *fidp, V9fsString name;int len, err =0 ;int32_t count =0 ; +off_t off;struct dirent *dent;struct stat *st;struct V9fsDirEnt *entries =NULL ;@@ -2480,12 +2486,17 @@ static int coroutine_fn v9fs_do_readdir(V9fsPDU *pdu, V9fsFidState *fidp, qid.version =0 ; }
Quoted 8 lines
hw/9pfs/9p.c static int coroutine_fn v9fs_do_readdir(V9fsPDU *pdu, V9fsFidState *fidp, · line 2493
Quoted 5 lines
hw/9pfs/9p.c +5
-0+ off =qemu_dirent_off (dent); +if (off <0 ) { + err = off; +break ; + }Likewise: is this check still needed?
As above, removing for v5.
Quoted 19 lines
hw/9pfs/codir.c static int do_readdir_many(V9fsPDU *pdu,
Quoted 16 lines
hw/9pfs/9p.c +1
-1v9fs_string_init (&name);v9fs_string_sprintf (&name,"%s" , dent->d_name);/* 11 = 7 + 4 (7 = start offset, 4 = space for storing count) */ len =pdu_marshal (pdu,11 + count,"Qqbs" , - &qid, dent->d_off, + &qid, off, dent->d_type, &name);v9fs_string_free (&name);hw/9pfs/codir.c +0
-0@@ -167,7 +167,14 @@ static int do_readdir_many(V9fsPDU *pdu,V9fsFidState
Quoted 2 lines
hw/9pfs/codir.c +0
-0*fidp, }
Quoted 15 lines
hw/9pfs/codir.c static int do_readdir_many(V9fsPDU *pdu, V9fsFidState *fidp, · line 177
Quoted 9 lines
hw/9pfs/codir.c +7
-0size += len; +/* This conditional statement is identical in +* function to qemu_dirent_off, described in 9p-util.h, +* since that header cannot be included here. */ +#ifdef CONFIG_DARWIN + saved_dir_pos = dent->d_seekoff; +#else saved_dir_pos = dent->d_off; +#endif Why can't the header not be included here? Obvious preference would be to use
qemu_dirent_off()here as well, to have control at one central code location.
Only my own imprecision in organizing the includes correctly. After including "9p-xattr.h" as well, this works. Will adjust for v5.
Quoted 7 lines
Quoted 4 lines
hw/9pfs/codir.c +0
-0}/* restore (last) saved position */
Re: [PATCH v4 04/11] 9p: darwin: Handle struct dirent differences
In reply to Will CohenQuoted 86 lines · On Montag, 7. Februar 2022 14:52:58 CET Will Cohen wrote:
On Mon, Feb 7, 2022 at 4:53 AM Fabian Franz <[email protected]>
Quoted 10 lines · wrote:
Comments inline:
hw/9pfs/9p-local.c +0
-0Quoted 7 lines
index
1a5e3eed73..7137a28109100644hw/9pfs/9p-local.c +0
-0@@ -559,6 +559,15 @@ static struct dirent *local_readdir(FsContext *ctx, V9fsFidOpenState *fs)Quoted 8 lines
hw/9pfs/9p-local.c static struct dirent *local_readdir(FsContext *ctx, · line 566
Quoted 6 lines
hw/9pfs/9p-local.c +3
-0again: entry =readdir (fs->dir.stream); +#ifdef CONFIG_DARWIN +int td; + td =telldir (fs->dir.stream);Maybe call this „off“?
Yes, off is better. Will adjust for v5.
Quoted 7 lines
Quoted 7 lines
hw/9pfs/9p-local.c +6
-0+/* If telldir fails, fail the entire readdir call */ +if (td <0 ) { +return NULL ; + } + entry->d_seekoff = td; +#endif Quoted 7 lines
Quoted 5 lines
if (!entry) { return NULL; }This needs to be before the #ifdef!
Good catch, will adjust for v5. I moved it around twice and forgot to put it in the right place.
Quoted 44 lines
Quoted 44 lines
hw/9pfs/9p-proxy.c +15
-1@@ -706,7 +706,21 @@ static off_t proxy_telldir(FsContext *ctx, V9fsFidOpenState *fs)static struct dirent *proxy_readdir (FsContext *ctx,V9fsFidOpenState *fs) { -return readdir (fs->dir.stream); +struct dirent *entry; + entry =readdir (fs->dir.stream); +#ifdef CONFIG_DARWIN +if (!entry) { +return NULL ; + } +int td; + td =telldir (fs->dir.stream); +/* If telldir fails, fail the entire readdir call */ +if (td <0 ) { +return NULL ; + } + entry->d_seekoff = td; +#endif +return entry;}
static void proxy_seekdir(FsContext *ctx, V9fsFidOpenState *fs,
off_toff)
hw/9pfs/9p-synth.c +0
-0@@ -222,7 +222,11 @@ static void synth_direntry(V9fsSynthNode *node, {strcpy (entry->d_name, node->name); entry->d_ino = node->attr->inode;
Quoted 7 lines
Quoted 7 lines
hw/9pfs/9p-synth.c static void synth_direntry(V9fsSynthNode *node,
Quoted 7 lines
hw/9pfs/9p-synth.c +4
-0+#ifdef CONFIG_DARWIN + entry->d_seekoff = off +1 ; +#else entry->d_off = off +1 ; +#endif
See below ...
Quoted 37 lines
Quoted 28 lines
Quoted 28 lines
}
static struct dirent *synth_get_dentry(V9fsSynthNode *dir,
hw/9pfs/9p-util.h +12
-0@@ -79,3 +79,20 @@ ssize_t fremovexattrat_nofollow(int dirfd, const char *filename, const char *name);#endif + + +/** +* Darwin has d_seekoff, which appears to function similarly to d_off. +* However, it does not appear to be supported on all file systems, +* so ensure it is manually injected earlier and call here when +* needed. +*/ + +inline off_t qemu_dirent_off (struct dirent *dent) +{ +#ifdef CONFIG_DARWIN Quoted 8 lines
hw/9pfs/9p-util.h
Quoted 5 lines
hw/9pfs/9p-util.h +5
-0+return dent->d_seekoff; +#else +return dent->d_off; +#endif +}Are we sure we want a helper for two times the same ifdef? Deferring to maintainers here however.
Quoted 4 lines
Either way works for me too -- my current inclination is to leave it this way (as originally suggested by the maintainers), if for no other reason than that it allows the one comment to be referenced in the case of both uses.
As requested by me in this v4, this will be 3 times in v5. So I assume that qualifies the dedicated helper function. :)
As an alternative you could make the helper function a macro instead, then you could use it in 9p-synth.c as well, which would make it 4 times. But I don't mind about that one.
Best regards,
Christian Schoenebeck
Quoted 113 lines
Quoted 24 lines
hw/9pfs/9p.c +0
-0Quoted 23 lines
index
1563d7b7c6..cf694da354100644hw/9pfs/9p.c +1
-0@@ -27,6 +27,7 @@#include "virtio-9p.h" #include "fsdev/qemu-fsdev.h" #include "9p-xattr.h" +#include "9p-util.h" #include "
coth.h"
#include "trace.h"
#include "migration/blocker.h"hw/9pfs/9p.c +0
-0@@ -2281,7 +2282,11 @@ static int coroutine_fnv9fs_do_readdir_with_stat (V9fsPDU *pdu, count += len;v9fs_stat_free (&v9stat);v9fs_path_free (&path);Quoted 9 lines
hw/9pfs/9p.c static int coroutine_fn · line 2292
Quoted 6 lines
hw/9pfs/9p.c +5
-1- saved_dir_pos = dent->d_off; + saved_dir_pos =qemu_dirent_off (dent); +if (saved_dir_pos <0 ) { + err = saved_dir_pos; +break ; + }Do we still need this error-handling? I had removed it in my interdiff patch.
That's correct, it in fact can be removed.
d_seekoffyields a__uint64_t(
https://developer.apple.com/documentation/kernel/direntry/1415494-d_seekoff?
language=objc). Will adjust for v5.Quoted 24 lines
Quoted 24 lines
} v9fs_readdir_unlock(&fidp->fs.dir);hw/9pfs/9p.c +1
-0@@ -2420,6 +2425,7 @@ static int coroutine_fn v9fs_do_readdir(V9fsPDU *pdu, V9fsFidState *fidp, V9fsString name;int len, err =0 ;int32_t count =0 ; +off_t off;struct dirent *dent; struct stat *st; struct V9fsDirEnt *entries = NULL;hw/9pfs/9p.c +0
-0@@ -2480,12 +2486,17 @@ static int coroutine_fn v9fs_do_readdir(V9fsPDU *pdu, V9fsFidState *fidp, qid.version =0 ; }Quoted 7 lines
hw/9pfs/9p.c static int coroutine_fn v9fs_do_readdir(V9fsPDU · line 2496
Quoted 5 lines
hw/9pfs/9p.c +5
-0+ off =qemu_dirent_off (dent); +if (off <0 ) { + err = off; +break ; + }Same here - if this can never fail, why add the error handling?
See above.
Quoted 41 lines
Quoted 41 lines
hw/9pfs/9p.c +1
-1v9fs_string_init (&name);v9fs_string_sprintf (&name,"%s" , dent->d_name);/* 11 = 7 + 4 (7 = start offset, 4 = space for storing count) */ len =pdu_marshal (pdu,11 + count,"Qqbs" , - &qid, dent->d_off, + &qid, off, dent->d_type, &name);v9fs_string_free (&name);hw/9pfs/codir.c +7
-1@@ -167,7 +167,14 @@ static int do_readdir_many(V9fsPDU *pdu, V9fsFidState *fidp, } size += len; +/* This conditional statement is identical in +* function to qemu_dirent_off, described in 9p-util.h, +* since that header cannot be included here. */ +#ifdef CONFIG_DARWIN + saved_dir_pos = dent->d_seekoff; +#else saved_dir_pos = dent->d_off; +#endif }/* restore (last) saved position */ --2.32.0 (Apple Git-132)
Re: [PATCH v4 09/11] 9p: darwin: Implement compatibility for mknodat
In reply to Christian SchoenebeckQuoted 41 lines · Christian Schoenebeck
Quoted 9 lines · On Montag, 7. Februar 2022 11:57:25 CET Dr. David Alan Gilbert wrote:
Quoted 8 lines · * Greg Kurz ([email protected]) wrote:
On Mon, 7 Feb 2022 11:30:18 +0100
Quoted 5 lines · Philippe Mathieu-Daudé
Quoted 4 lines · Greg Kurz
On Sun, 6 Feb 2022 20:10:23 -0500
Quoted 1 line · Will Cohen
This patch set currently places it in 9p-util only because 9p is
the
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
only
place where this issue seems to have come up so far and we werewary
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 4 lines
of
editing files too far afield, but I have no attachment to its specific
location!Inline comments are preferred on qemu-devel. Please don't top post
!
Quoted 11 lines
Quoted 11 lines
Quoted 9 lines
Quoted 7 lines
This complicates the review a lot.
This is indeed a good candidate for osdep. This being said, unless there's
some other user in the QEMU code base, it is acceptable to leave it under
9pfs.virtiofsd could eventually use it.
Indeed but virtiofsd is for linux hosts only AFAICT and I'm not aware
of
Quoted 8 lines
Quoted 3 lines
any work to support any other host OS.
Cc'ing virtio-fs people for inputs on this topic.
Indeeed, there's a lot of Linux specific code in the virtiofsd - I know people are interested in other platforms, but I'm not sure that's the right starting point.
Quoted 10 lines
Quoted 1 line
Dave
Agreeing with Greg here: i.e. I would have placed this into osdep, but I would
not insist on it either.Best regards,
Christian Schoenebeck
This makes sense. A revised version of this patch, moving qemu_mknodat from 9p-util to osdep and os-posix, is attached below. I'd appreciate any feedback from those looped in here, so that the context isn't lost before resubmitting as a v5 patch, especially since this is starting to touch files outside of 9p.
From c9713c87163da7c96b5357d0d85ac318ae3d3051 Mon Sep 17 00:00:00 2001
From: Keno Fischer <[email protected]>
Date: Sat, 16 Jun 2018 20:56:55 -0400
Subject: [PATCH] 9p: darwin: Implement compatibility for mknodat
Darwin does not support mknodat. However, to avoid race conditions with later setting the permissions, we must avoid using mknod on the full path instead. We could try to fchdir, but that would cause problems if multiple threads try to call mknodat at the same time. However, luckily there is a solution: Darwin includes a function that sets the cwd for the current thread only.
This should suffice to use mknod safely.
This function (pthread_fchdir_np) is protected by a check in meson in a patch later in tihs series.
[Will Cohen: - Adjust coding style
- Replace clang references with gcc
- Note radar filed with Apple for missing syscall
- Replace direct syscall with pthread_fchdir_np and adjust patch notes accordingly
- Move qemu_mknodat from 9p-util to osdep and os-posix]
--- hw/9pfs/9p-local.c | 4 ++-- include/qemu/osdep.h | 10 ++++++++++ os-posix.c | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 2 deletions(-)
hw/9pfs/9p-local.c +0 -0
@@ -682,7 +682,7 @@ static int local_mknod(FsContext *fs_ctx, V9fsPath
*dir_path,
if (fs_ctx->export_flags & V9FS_SM_MAPPED ||
fs_ctx->export_flags & V9FS_SM_MAPPED_FILE) {
- err = mknodat(dirfd, name, fs_ctx->fmode | S_IFREG, 0);
+ err = qemu_mknodat(dirfd, name, fs_ctx->fmode | S_IFREG, 0);
if (err == -1) {
goto out;
}
@@ -697,7 +697,7 @@ static int local_mknod(FsContext *fs_ctx, V9fsPath
*dir_path,
}
} else if (fs_ctx->export_flags & V9FS_SM_PASSTHROUGH ||
fs_ctx->export_flags & V9FS_SM_NONE) {
- err = mknodat(dirfd, name, credp->fc_mode, credp->fc_rdev);
+ err = qemu_mknodat(dirfd, name, credp->fc_mode, credp->fc_rdev);
if (err == -1) {
goto out;
}include/qemu/osdep.h +0 -0
@@ -810,3 +810,13 @@ static inline int
platform_does_not_support_system(const char *command)
#endif
#endif
+
+/*
+ * As long as mknodat is not available on macOS, this workaround
+ * using pthread_fchdir_np is needed. qemu_mknodat is defined in
+ * os-posix.c
+ */
+#ifdef CONFIG_DARWIN
+int pthread_fchdir_np(int fd);
+#endif
+int qemu_mknodat(int dirfd, const char *filename, mode_t mode, dev_t dev);
os-posix.c +34 -0
@@ -24,6 +24,7 @@*/ #include "qemu/osdep.h" +#include <os/availability.h> #include <sys/wait.h> #include <pwd.h> #include <grp.h>
@@ -332,3 +333,36 @@ int os_mlock(void)return -ENOSYS ;#endif } + +/* +* As long as mknodat is not available on macOS, this workaround +* using pthread_fchdir_np is needed. +* +* Radar filed with Apple for implementing mknodat: +* rdar://FB9862426 (https://openradar.appspot.com/FB9862426) +*/ +#ifdef CONFIG_DARWIN + +int pthread_fchdir_np(int fd) API_AVAILABLE(macosx(10.12)); + +int qemu_mknodat (int dirfd,const char *filename,mode_t mode,dev_t dev) +{ +int preserved_errno, err; +if (pthread_fchdir_np (dirfd) <0 ) { +return -1 ; + } + err =mknod (filename, mode, dev); + preserved_errno = errno; +/* Stop using the thread-local cwd */ +pthread_fchdir_np (-1 ); +if (err <0 ) { + errno = preserved_errno; + } +return err; +} +#else +int qemu_mknodat (int dirfd,const char *filename,mode_t mode,dev_t dev) +{ +return mknodat (dirfd, filename, mode, dev); +} +#endif
Signature · 1 line
2.34.1
Re: [PATCH v4 09/11] 9p: darwin: Implement compatibility for mknodat
Quoted 185 lines · Will Cohen
Quoted 42 lines · Christian Schoenebeck
Quoted 9 lines · On Montag, 7. Februar 2022 11:57:25 CET Dr. David Alan Gilbert wrote:
Quoted 8 lines · * Greg Kurz ([email protected]) wrote:
On Mon, 7 Feb 2022 11:30:18 +0100
Quoted 5 lines · Philippe Mathieu-Daudé
Quoted 4 lines · Greg Kurz
On Sun, 6 Feb 2022 20:10:23 -0500
Quoted 1 line · Will Cohen
This patch set currently places it in 9p-util only because 9p is
the
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
only
place where this issue seems to have come up so far and we werewary
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 4 lines
of
editing files too far afield, but I have no attachment to its specific
location!Inline comments are preferred on qemu-devel. Please don't top
post !
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
This complicates the review a lot.
This is indeed a good candidate for osdep. This being said, unless there's
some other user in the QEMU code base, it is acceptable to leaveit
Quoted 6 lines
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
under
9pfs.virtiofsd could eventually use it.
Indeed but virtiofsd is for linux hosts only AFAICT and I'm not aware
of
Quoted 8 lines
Quoted 3 lines
any work to support any other host OS.
Cc'ing virtio-fs people for inputs on this topic.
Indeeed, there's a lot of Linux specific code in the virtiofsd - I know people are interested in other platforms, but I'm not sure that's the right starting point.
Quoted 10 lines
Quoted 1 line
Dave
Agreeing with Greg here: i.e. I would have placed this into osdep, but I would
not insist on it either.Best regards,
Christian SchoenebeckThis makes sense. A revised version of this patch, moving
qemu_mknodatfrom 9p-util to osdep and os-posix, is attached below. I'd appreciate any feedback from those looped in here, so that the context isn't lost before resubmitting as a v5 patch, especially since this is starting to touch files outside of 9p.From
c9713c87163da7c96b5357d0d85ac318ae3d3051Mon Sep 17 00:00:00 2001
From: Keno Fischer <[email protected]>
Date: Sat, 16 Jun 2018 20:56:55 -0400
Subject: [PATCH] 9p: darwin: Implement compatibility for mknodatDarwin does not support mknodat. However, to avoid race conditions with later setting the permissions, we must avoid using mknod on the full path instead. We could try to fchdir, but that would cause problems if multiple threads try to call mknodat at the same time. However, luckily there is a solution: Darwin includes a function that sets the cwd for the current thread only.
This should suffice to use mknod safely.This function (
pthread_fchdir_np) is protected by a check in meson in a patch later in tihs series.Signed-off-by Keno Fischer <[email protected]>Signed-off-by Michael Roitzsch <[email protected]>[Will Cohen: - Adjust coding style
- Replace clang references with gcc
- Note radar filed with Apple for missing syscall
- Replace direct syscall withpthread_fchdir_npand adjust patch notes accordingly
- Moveqemu_mknodatfrom 9p-util to osdep and os-posix]Signed-off-by Will Cohen <[email protected]>--- hw/9pfs/9p-local.c | 4 ++-- include/qemu/osdep.h | 10 ++++++++++ os-posix.c | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 2 deletions(-)hw/9pfs/9p-local.c +1
-1@@ -682,7 +682,7 @@ static int local_mknod(FsContext *fs_ctx, V9fsPath *dir_path, if (fs_ctx->export_flags & V9FS_SM_MAPPED || fs_ctx->export_flags & V9FS_SM_MAPPED_FILE) { - err =mknodat (dirfd, name, fs_ctx->fmode |S_IFREG ,0 ); + err =qemu_mknodat (dirfd, name, fs_ctx->fmode |S_IFREG ,0 );if (err ==-1 ) { goto out;}hw/9pfs/9p-local.c +1
-1@@ -697,7 +697,7 @@ static int local_mknod(FsContext *fs_ctx, V9fsPath *dir_path, } }else if (fs_ctx->export_flags &V9FS_SM_PASSTHROUGH || fs_ctx->export_flags &V9FS_SM_NONE ) { - err =mknodat (dirfd, name, credp->fc_mode, credp->fc_rdev); + err =qemu_mknodat (dirfd, name, credp->fc_mode, credp->fc_rdev);if (err ==-1 ) { goto out;}include/qemu/osdep.h +10
-0@@ -810,3 +810,13 @@ static inline int platform_does_not_support_system(const char *command)#endif #endif + +/* +* As long as mknodat is not available on macOS, this workaround +* using pthread_fchdir_np is needed. qemu_mknodat is defined in +* os-posix.c +*/ +#ifdef CONFIG_DARWIN +int pthread_fchdir_np (int fd); +#endif +int qemu_mknodat (int dirfd,const char *filename,mode_t mode,dev_t dev);os-posix.c +34
-1@@ -24,6 +24,7 @@*/ #include "qemu/osdep.h" +#include <os/availability.h> #include <sys/wait.h> #include <pwd.h> #include <grp.h> @@ -332,3 +333,36 @@ int os_mlock(void)return -ENOSYS ;#endif } + +/* +* As long as mknodat is not available on macOS, this workaround +* using pthread_fchdir_np is needed. +* +* Radar filed with Apple for implementing mknodat: +* rdar://FB9862426 (https://openradar.appspot.com/FB9862426) +*/ +#ifdef CONFIG_DARWIN + +int pthread_fchdir_np(int fd) API_AVAILABLE(macosx(10.12)); + +int qemu_mknodat (int dirfd,const char *filename,mode_t mode,dev_t dev) +{ +int preserved_errno, err; +if (pthread_fchdir_np (dirfd) <0 ) { +return -1 ; + } + err =mknod (filename, mode, dev); + preserved_errno = errno; +/* Stop using the thread-local cwd */ +pthread_fchdir_np (-1 ); +if (err <0 ) { + errno = preserved_errno; + } +return err; +} +#else +int qemu_mknodat (int dirfd,const char *filename,mode_t mode,dev_t dev) +{ +return mknodat (dirfd, filename, mode, dev); +} +#endif --
Quoted 2 lines
2.34.1
Noting on
https://www.qemu.org/docs/master/devel/submitting-a-patch.html#when-resending-patches-add-a-version-tag
that resending a single patch outside of a new entire patch series is not helpful, so I'm resubmitting with this patch substituted in as v5 shortly.
Re: [PATCH v4 09/11] 9p: darwin: Implement compatibility for mknodat
In reply to Will CohenQuoted 131 lines · On Montag, 7. Februar 2022 22:07:34 CET Will Cohen wrote:
Quoted 50 lines · Christian Schoenebeck
Quoted 9 lines · On Montag, 7. Februar 2022 11:57:25 CET Dr. David Alan Gilbert wrote:
Quoted 8 lines · * Greg Kurz ([email protected]) wrote:
On Mon, 7 Feb 2022 11:30:18 +0100
Quoted 5 lines · Philippe Mathieu-Daudé
Quoted 4 lines · Greg Kurz
On Sun, 6 Feb 2022 20:10:23 -0500
Quoted 1 line · Will Cohen
This patch set currently places it in 9p-util only because 9p is
the
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
only
place where this issue seems to have come up so far and we werewary
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 4 lines
of
editing files too far afield, but I have no attachment to its specific
location!Inline comments are preferred on qemu-devel. Please don't top post
!
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
This complicates the review a lot.
This is indeed a good candidate for osdep. This being said, unless there's
some other user in the QEMU code base, it is acceptable to leave it
under
9pfs.Quoted 3 lines
Quoted 3 lines
Quoted 1 line
virtiofsd could eventually use it.
Indeed but virtiofsd is for linux hosts only AFAICT and I'm not aware
of
Quoted 8 lines
Quoted 3 lines
any work to support any other host OS.
Cc'ing virtio-fs people for inputs on this topic.
Indeeed, there's a lot of Linux specific code in the virtiofsd - I know people are interested in other platforms, but I'm not sure that's the right starting point.
Quoted 8 lines
Quoted 1 line
Dave
Agreeing with Greg here: i.e. I would have placed this into osdep, but I would
not insist on it either.Best regards,
Christian SchoenebeckThis makes sense. A revised version of this patch, moving
qemu_mknodatfrom 9p-util to osdep and os-posix, is attached below. I'd appreciate any feedback from those looped in here, so that the context isn't lost before resubmitting as a v5 patch, especially since this is starting to touch files outside of 9p.From
c9713c87163da7c96b5357d0d85ac318ae3d3051Mon Sep 17 00:00:00 2001
From: Keno Fischer <[email protected]>
Date: Sat, 16 Jun 2018 20:56:55 -0400
Subject: [PATCH] 9p: darwin: Implement compatibility for mknodatDarwin does not support mknodat. However, to avoid race conditions with later setting the permissions, we must avoid using mknod on the full path instead. We could try to fchdir, but that would cause problems if multiple threads try to call mknodat at the same time. However, luckily there is a solution: Darwin includes a function that sets the cwd for the current thread only.
This should suffice to use mknod safely.This function (
pthread_fchdir_np) is protected by a check in meson in a patch later in tihs series.Signed-off-by Keno Fischer <[email protected]>Signed-off-by Michael Roitzsch <[email protected]>[Will Cohen: - Adjust coding style
- Replace clang references with gcc
- Note radar filed with Apple for missing syscall
- Replace direct syscall withpthread_fchdir_npand adjust patch notes accordingly
- Moveqemu_mknodatfrom 9p-util to osdep and os-posix]Signed-off-by Will Cohen <[email protected]>--- hw/9pfs/9p-local.c | 4 ++-- include/qemu/osdep.h | 10 ++++++++++ os-posix.c | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 2 deletions(-)hw/9pfs/9p-local.c +1
-1@@ -682,7 +682,7 @@ static int local_mknod(FsContext *fs_ctx, V9fsPath *dir_path, if (fs_ctx->export_flags & V9FS_SM_MAPPED || fs_ctx->export_flags & V9FS_SM_MAPPED_FILE) { - err =mknodat (dirfd, name, fs_ctx->fmode |S_IFREG ,0 ); + err =qemu_mknodat (dirfd, name, fs_ctx->fmode |S_IFREG ,0 );if (err ==-1 ) { goto out;}hw/9pfs/9p-local.c +1
-1@@ -697,7 +697,7 @@ static int local_mknod(FsContext *fs_ctx, V9fsPath *dir_path, } }else if (fs_ctx->export_flags &V9FS_SM_PASSTHROUGH || fs_ctx->export_flags &V9FS_SM_NONE ) { - err =mknodat (dirfd, name, credp->fc_mode, credp->fc_rdev); + err =qemu_mknodat (dirfd, name, credp->fc_mode, credp->fc_rdev);if (err ==-1 ) { goto out;}include/qemu/osdep.h +0
-0@@ -810,3 +810,13 @@ static inline int platform_does_not_support_system(const char *command)#endif
include/qemu/osdep.h static inline int
Quoted 10 lines
include/qemu/osdep.h +9
-0#endif + +/* +* As long as mknodat is not available on macOS, this workaround +* using pthread_fchdir_np is needed. qemu_mknodat is defined in +* os-posix.c +*/ +#ifdef CONFIG_DARWIN +int pthread_fchdir_np (int fd); +#endif
I would make that:
#ifdef CONFIG_DARWIN
int pthread_fchdir_np(int fd) API_AVAILABLE(macosx(10.12)); #endif
here and ...
Quoted 18 lines
include/qemu/osdep.h +1
-0+int qemu_mknodat (int dirfd,const char *filename,mode_t mode,dev_t dev);os-posix.c +2
-0@@ -24,6 +24,7 @@*/ #include "qemu/osdep.h" +#include <os/availability.h> #include <sys/wait.h> #include <pwd.h> #include <grp.h> @@ -332,3 +333,36 @@ int os_mlock(void)return -ENOSYS ;#endif } +
os-posix.c int os_mlock(void) · line 346
Quoted 10 lines
os-posix.c +10
-0+/* +* As long as mknodat is not available on macOS, this workaround +* using pthread_fchdir_np is needed. +* +* Radar filed with Apple for implementing mknodat: +* rdar://FB9862426 (https://openradar.appspot.com/FB9862426) +*/ +#ifdef CONFIG_DARWIN + +int pthread_fchdir_np(int fd) API_AVAILABLE(macosx(10.12));
... drop the duplicate declaration of pthread_fchdir_np() here.
Quoted 22 lines
os-posix.c +22
-0+ +int qemu_mknodat (int dirfd,const char *filename,mode_t mode,dev_t dev) +{ +int preserved_errno, err; +if (pthread_fchdir_np (dirfd) <0 ) { +return -1 ; + } + err =mknod (filename, mode, dev); + preserved_errno = errno; +/* Stop using the thread-local cwd */ +pthread_fchdir_np (-1 ); +if (err <0 ) { + errno = preserved_errno; + } +return err; +} +#else +int qemu_mknodat (int dirfd,const char *filename,mode_t mode,dev_t dev) +{ +return mknodat (dirfd, filename, mode, dev); +} +#endif
Re: [PATCH v4 09/11] 9p: darwin: Implement compatibility for mknodat
Quoted 212 lines · Christian Schoenebeck
Quoted 5 lines · On Montag, 7. Februar 2022 22:07:34 CET Will Cohen wrote:
Quoted 2 lines · Christian Schoenebeck
Quoted 1 line · On Montag, 7. Februar 2022 11:57:25 CET Dr. David Alan Gilbert wrote:
* Greg Kurz ([email protected]) wrote:
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
On Mon, 7 Feb 2022 11:30:18 +0100
Quoted 5 lines · Philippe Mathieu-Daudé
Quoted 4 lines · Greg Kurz
On Sun, 6 Feb 2022 20:10:23 -0500
Quoted 1 line · Will Cohen
This patch set currently places it in 9p-util only because 9p
is
Quoted 5 lines
Quoted 5 lines
the
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
only
place where this issue seems to have come up so far and wewere
Quoted 9 lines
Quoted 9 lines
wary
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 4 lines
of
editing files too far afield, but I have no attachment to its specific
location!Inline comments are preferred on qemu-devel. Please don't top
post
Quoted 6 lines
Quoted 6 lines
!
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
This complicates the review a lot.
This is indeed a good candidate for osdep. This being said,
unless
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
there's
some other user in the QEMU code base, it is acceptable toleave
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
it
under
9pfs.virtiofsd could eventually use it.
Indeed but virtiofsd is for linux hosts only AFAICT and I'm not
aware
Quoted 8 lines
Quoted 8 lines
of
Quoted 5 lines
Quoted 3 lines
any work to support any other host OS.
Cc'ing virtio-fs people for inputs on this topic.
Indeeed, there's a lot of Linux specific code in the virtiofsd - I
know
Quoted 6 lines
Quoted 6 lines
Quoted 4 lines
people are interested in other platforms, but I'm not sure that's the right starting point.
Dave
Agreeing with Greg here: i.e. I would have placed this into osdep, but
I
Quoted 7 lines
Quoted 5 lines
would
not insist on it either.Best regards,
Christian SchoenebeckThis makes sense. A revised version of this patch, moving
qemu_mknodatfrom
Quoted 68 lines
9p-util to osdep and os-posix, is attached below. I'd appreciate any feedback from those looped in here, so that the context isn't lost before resubmitting as a v5 patch, especially since this is starting to touch files outside of 9p.
From
c9713c87163da7c96b5357d0d85ac318ae3d3051Mon Sep 17 00:00:00 2001
From: Keno Fischer <[email protected]>
Date: Sat, 16 Jun 2018 20:56:55 -0400
Subject: [PATCH] 9p: darwin: Implement compatibility for mknodatDarwin does not support mknodat. However, to avoid race conditions with later setting the permissions, we must avoid using mknod on the full path instead. We could try to fchdir, but that would cause problems if multiple threads try to call mknodat at the same time. However, luckily there is a solution: Darwin includes a function that sets the cwd for the current thread only.
This should suffice to use mknod safely.This function (
pthread_fchdir_np) is protected by a check in meson in a patch later in tihs series.Signed-off-by Keno Fischer <[email protected]>Signed-off-by Michael Roitzsch <[email protected]>[Will Cohen: - Adjust coding style
- Replace clang references with gcc
- Note radar filed with Apple for missing syscall
- Replace direct syscall withpthread_fchdir_npand adjust patch notes accordingly
- Moveqemu_mknodatfrom 9p-util to osdep and os-posix]Signed-off-by Will Cohen <[email protected]>--- hw/9pfs/9p-local.c | 4 ++-- include/qemu/osdep.h | 10 ++++++++++ os-posix.c | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 2 deletions(-)hw/9pfs/9p-local.c +1
-1@@ -682,7 +682,7 @@ static int local_mknod(FsContext *fs_ctx, V9fsPath *dir_path, if (fs_ctx->export_flags & V9FS_SM_MAPPED || fs_ctx->export_flags & V9FS_SM_MAPPED_FILE) { - err =mknodat (dirfd, name, fs_ctx->fmode |S_IFREG ,0 ); + err =qemu_mknodat (dirfd, name, fs_ctx->fmode |S_IFREG ,0 );if (err ==-1 ) { goto out;}hw/9pfs/9p-local.c +1
-1@@ -697,7 +697,7 @@ static int local_mknod(FsContext *fs_ctx, V9fsPath *dir_path, } }else if (fs_ctx->export_flags &V9FS_SM_PASSTHROUGH || fs_ctx->export_flags &V9FS_SM_NONE ) { - err =mknodat (dirfd, name, credp->fc_mode, credp->fc_rdev); + err =qemu_mknodat (dirfd, name, credp->fc_mode, credp->fc_rdev);if (err ==-1 ) { goto out;}include/qemu/osdep.h +0
-0@@ -810,3 +810,13 @@ static inline int platform_does_not_support_system(const char *command)#endif include/qemu/osdep.h static inline int
Quoted 10 lines
include/qemu/osdep.h +9
-0#endif + +/* +* As long as mknodat is not available on macOS, this workaround +* using pthread_fchdir_np is needed. qemu_mknodat is defined in +* os-posix.c +*/ +#ifdef CONFIG_DARWIN +int pthread_fchdir_np (int fd); +#endif I would make that:
#ifdef
CONFIG_DARWIN
intpthread_fchdir_np(int fd)API_AVAILABLE(macosx(10.12)); #endifhere and ...
Quoted 1 line
+int qemu_mknodat(int dirfd, const char *filename,
mode_tmode,dev_tdev);
Quoted 17 lines
os-posix.c +2
-0@@ -24,6 +24,7 @@*/ #include "qemu/osdep.h" +#include <os/availability.h> #include <sys/wait.h> #include <pwd.h> #include <grp.h> @@ -332,3 +333,36 @@ int os_mlock(void)return -ENOSYS ;#endif } +os-posix.c int os_mlock(void) · line 346
Quoted 10 lines
os-posix.c +10
-0+/* +* As long as mknodat is not available on macOS, this workaround +* using pthread_fchdir_np is needed. +* +* Radar filed with Apple for implementing mknodat: +* rdar://FB9862426 (https://openradar.appspot.com/FB9862426) +*/ +#ifdef CONFIG_DARWIN + +int pthread_fchdir_np(int fd) API_AVAILABLE(macosx(10.12));... drop the duplicate declaration of
pthread_fchdir_np()here.os-posix.c int os_mlock(void) · line 348
Quoted 2 lines
os-posix.c +2
-0+ +int qemu_mknodat(int dirfd, const char *filename, mode_t mode, dev_tdev)
Quoted 6 lines
os-posix.c +6
-0+{ +int preserved_errno, err; +if (pthread_fchdir_np (dirfd) <0 ) { +return -1 ; + } + err =mknod (filename, mode, dev);os-posix.c int os_mlock(void)
Quoted 10 lines
os-posix.c +10
-0+ preserved_errno = errno; +/* Stop using the thread-local cwd */ +pthread_fchdir_np (-1 ); +if (err <0 ) { + errno = preserved_errno; + } +return err; +} +#else +int qemu_mknodat(int dirfd, const char *filename, mode_t mode, dev_tdev)
Quoted 5 lines
os-posix.c int os_mlock(void) · line 368
Quoted 4 lines
os-posix.c +4
-0+{ +return mknodat (dirfd, filename, mode, dev); +} +#endif
Noted and all of that makes sense to me. Sorry about trying to lump this in v4. If more things come up with v5 I'll stick these changes in for v6 as well. If there's no other major comments with v5, I can either still resubmit as v6 or defer to whatever process is easiest for the maintainers to integrate, given that I accept all of these modifications.