9pfs: Add FreeBSD support
PATCH 1/1 9pfs: Add FreeBSD support
This is largely derived from existing Darwin support. FreeBSD apparently has better support for *at() system calls so doesn't require workarounds for a missing mknodat(). The implementation has a couple of warts however:
- The extattr(2) system calls don't support anything akin to XATTR_CREATE or XATTR_REPLACE, so a racy workaround is implemented.
- Attribute names cannot begin with "user." on ZFS, so the prefix is trimmed off. FreeBSD's extattr system calls sport an extra "namespace" identifier, and attributes created by the 9pfs backend live in the universal user namespace, so this seems innocent enough.
The 9pfs tests were verified to pass on the UFS, ZFS and tmpfs filesystems.
--- fsdev/file-op-9p.h | 6 +- fsdev/meson.build | 2 +- hw/9pfs/9p-synth.c | 2 +- hw/9pfs/9p-util-freebsd.c | 124 ++++++++++++++++++++++++++++++++++++++ hw/9pfs/9p-util.h | 19 ++++-- hw/9pfs/9p.c | 16 ++++- hw/9pfs/meson.build | 2 + include/qemu/xattr.h | 6 +- meson.build | 8 +-- 9 files changed, 170 insertions(+), 15 deletions(-) create mode 100644 hw/9pfs/9p-util-freebsd.c
fsdev/file-op-9p.h +4 -2
@@ -21,9 +21,11 @@#ifdef CONFIG_LINUX # include <sys/vfs.h> -#endif -#ifdef CONFIG_DARWIN +#elif defined(CONFIG_DARWIN ) || defined(CONFIG_FREEBSD )# include <sys/param.h> +# ifdef CONFIG_FREEBSD +# undef MACHINE/* work around some unfortunate namespace pollution */ +# endif # include <sys/mount.h> #endif
fsdev/meson.build +1 -1
@@ -5,6 +5,6 @@ fsdev_ss.add(when: ['CONFIG_FSDEV_9P'], if_true: files( '9p-marshal.c', 'qemu-fsdev.c', ), if_false: files('qemu-fsdev-dummy.c')) -if host_os in ['linux', 'darwin'] +if host_os in ['linux', 'darwin', 'freebsd'] system_ss.add_all(fsdev_ss) endif
hw/9pfs/9p-synth.c +1 -1
@@ -451,7 +451,7 @@ 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 +#if !defined(CONFIG_DARWIN ) && !defined(CONFIG_FREEBSD ) stbuf->f_namelen =NAME_MAX ;#endif return 0 ;
hw/9pfs/9p-util-freebsd.c new file +124 -0
124 lines not on this page · raw message
hw/9pfs/9p-util.h +15 -4
@@ -21,6 +21,14 @@#define O_PATH_9P_UTIL 0#endif +#ifdef CONFIG_FREEBSD +/* +* FreeBSD does not have these flags, so we can only emulate them (racily). +*/ +#define XATTR_CREATE 0x1 +#define XATTR_REPLACE 0x2 +#endif +#if !defined(CONFIG_LINUX )/*
@@ -64,9 +72,9 @@ static inline uint64_t host_dev_to_dotl_dev(dev_t dev)static inline int errno_to_dotl (int err) {#if defined(CONFIG_LINUX )/* nothing to translate (Linux -> Linux) */ -#elif defined(CONFIG_DARWIN ) +#elif defined(CONFIG_DARWIN ) || defined(CONFIG_FREEBSD )/* -* translation mandatory for macOS hosts +* translation mandatory for non-Linux hosts * * FIXME: Only most important errnos translated here yet, this should be * extended to as many errnos being translated as possible in future.
@@ -155,13 +163,13 @@ static inline int openat_file(int dirfd, const char *name, int flags, { int fd, serrno, ret; -#ifndef CONFIG_DARWIN +#if !defined(CONFIG_DARWIN) && !defined(CONFIG_FREEBSD) again: #endif fd = qemu_openat(dirfd, name, flags | O_NOFOLLOW | O_NOCTTY | O_NONBLOCK, mode); if (fd == -1) { -#ifndef CONFIG_DARWIN +#if !defined(CONFIG_DARWIN) && !defined(CONFIG_FREEBSD) if (errno == EPERM && (flags & O_NOATIME)) { /* * The client passed O_NOATIME but we lack permissions to honor it.
@@ -202,6 +210,9 @@ again:return fd; } +#ifdef CONFIG_FREEBSD +ssize_t fgetxattr (int dirfd,const char *name,void *value,size_t size); +#endif ssize_t fgetxattrat_nofollow (int dirfd,const char *path,const char *name,void *value,size_t size); int fsetxattrat_nofollow(int dirfd, const char *path, const char *name,
hw/9pfs/9p.c +14 -2
@@ -136,8 +136,10 @@ 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 +#if !defined(CONFIG_DARWIN) && !defined(CONFIG_FREEBSD) { P9_DOTL_NOATIME, O_NOATIME }, +#endif +#ifndef CONFIG_DARWIN/* * On Darwin, we could map to F_NOCACHE, which is * similar, but doesn't quite have the same
@@ -3658,7 +3660,7 @@ 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 +#if defined(CONFIG_DARWIN ) || defined(CONFIG_FREEBSD ) fsid_val = (unsigned int )stbuf->f_fsid.val[0 ] | (unsigned long long )stbuf->f_fsid.val[1 ] <<32 ; f_namelen =NAME_MAX ;
@@ -4050,6 +4052,16 @@ out_nofid:* Linux guests. */ #define P9_XATTR_SIZE_MAX 65536 +#elif defined(CONFIG_FREEBSD ) +/* +* FreeBSD similarly doesn't define a maximum xattr size, the limit is +* filesystem dependent. On UFS filesystems it's 2 times the filesystem block +* size, typically 32KB. On ZFS it depends on the value of the xattr property; +* with the default value there is no limit, and with xattr=sa it is 64KB. +* +* So, a limit of 64k seems reasonable here too. +*/ +#define P9_XATTR_SIZE_MAX 65536#else #error Missing definition for P9_XATTR_SIZE_MAX for this host system#endif
hw/9pfs/meson.build +2 -0
@@ -15,6 +15,8 @@ fs_ss.add(files( )) if host_os == 'darwin' fs_ss.add(files('9p-util-darwin.c')) +elif host_os == 'freebsd' + fs_ss.add(files('9p-util-freebsd.c')) elif host_os == 'linux' fs_ss.add(files('9p-util-linux.c')) endif
include/qemu/xattr.h +5 -1
@@ -26,7 +26,11 @@# define ENOATTR ENODATA# endif # ifndef CONFIG_WIN32 -# include <sys/xattr.h> +# ifdef CONFIG_FREEBSD +# include <sys/extattr.h> +# else +# include <sys/xattr.h> +# endif # endif #endif
meson.build +4 -4
@@ -2382,11 +2382,11 @@ dbus_display = get_option('dbus_display') \ .allowed() have_virtfs = get_option('virtfs') \ - .require(host_os == 'linux' or host_os == 'darwin', - error_message: 'virtio-9p (virtfs) requires Linux or macOS') \ - .require(host_os == 'linux' or cc.has_function('pthread_fchdir_np'), + .require(host_os == 'linux' or host_os == 'darwin' or host_os == 'freebsd', + error_message: 'virtio-9p (virtfs) requires Linux or macOS or FreeBSD') \ + .require(host_os != 'darwin' or cc.has_function('pthread_fchdir_np'), error_message: 'virtio-9p (virtfs) on macOS requires the presence of pthread_fchdir_np') \ - .require(host_os == 'darwin' or libattr.found(), + .require(host_os != 'linux' or libattr.found(), error_message: 'virtio-9p (virtfs) on Linux requires libattr-devel') \ .disable_auto_if(not have_tools and not have_system) \ .allowed()
Signature · 1 line
2.49.0
Quoted 11 lines · CEST Mark Johnston
This is largely derived from existing Darwin support. FreeBSD apparently has better support for
*at()system calls so doesn't require workarounds for a missingmknodat(). The implementation has a couple of warts however:
- The extattr(2) system calls don't support anything akin toXATTR_CREATEorXATTR_REPLACE, so a racy workaround is implemented.
- Attribute names cannot begin with "user." on ZFS, so the prefix is trimmed off. FreeBSD's extattr system calls sport an extra "namespace" identifier, and attributes created by the 9pfs backend live in the universal user namespace, so this seems innocent enough.
Quoted 4 lines
The 9pfs tests were verified to pass on the UFS, ZFS and tmpfs filesystems.
Signed-off-by Mark Johnston <[email protected]>
Hi Mark,
first off, the problem is I currently don't have a FreeBSD host to test and won't have the time in near future neither.
So what was your general intention regarding this patch, fire and forget, or would you be around for issues/patches regarding 9pfs FreeBSD support?
Quoted 18 lines
--- fsdev/file-op-9p.h | 6 +- fsdev/meson.build | 2 +- hw/9pfs/9p-synth.c | 2 +- hw/9pfs/9p-util-freebsd.c | 124 ++++++++++++++++++++++++++++++++++++++ hw/9pfs/9p-util.h | 19 ++++-- hw/9pfs/9p.c | 16 ++++- hw/9pfs/meson.build | 2 + include/qemu/xattr.h | 6 +- meson.build | 8 +-- 9 files changed, 170 insertions(+), 15 deletions(-) create mode 100644 hw/9pfs/9p-util-freebsd.cfsdev/file-op-9p.h +0
-0
fsdev/file-op-9p.h line 28
Quoted 10 lines
fsdev/file-op-9p.h +4
-2@@ -21,9 +21,11 @@#ifdef CONFIG_LINUX # include <sys/vfs.h> -#endif -#ifdef CONFIG_DARWIN +#elif defined(CONFIG_DARWIN ) || defined(CONFIG_FREEBSD )# include <sys/param.h> +# ifdef CONFIG_FREEBSD +# undef MACHINE/* work around some unfortunate namespace pollution */ +# endif
Details? :)
Quoted 34 lines
fsdev/file-op-9p.h +0
-0# include <sys/mount.h> #endif fsdev/meson.build +1
-1@@ -5,6 +5,6 @@ fsdev_ss.add(when: ['CONFIG_FSDEV_9P'], if_true: files( '9p-marshal.c', 'qemu-fsdev.c', ), if_false: files('qemu-fsdev-dummy.c')) -if host_os in ['linux', 'darwin'] +if host_os in ['linux', 'darwin', 'freebsd'] system_ss.add_all(fsdev_ss) endifhw/9pfs/9p-synth.c +1
-1@@ -451,7 +451,7 @@ 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 +#if !defined(CONFIG_DARWIN ) && !defined(CONFIG_FREEBSD ) stbuf->f_namelen =NAME_MAX ;#endif return 0 ;hw/9pfs/9p-util-freebsd.c new file +0
-0
hw/9pfs/9p-util-freebsd.c line 6
Quoted 6 lines
hw/9pfs/9p-util-freebsd.c new file +6
-0@@ -0,0 +1,124 @@ +/* +* 9p utilities (FreeBSD 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. +*/
I think for new source files in QEMU the policy is to use
SPDX-License-Identifier: ... now?
Is this source file really specific to exactly FreeBSD? From the name it suggests that potential future support for other BSD flavours would need their own source file.
Quoted 10 lines
hw/9pfs/9p-util-freebsd.c new file +10
-0+ +/* +* Not so fast! You might want to read the 9p developer docs first: +* https://wiki.qemu.org/Documentation/9p +*/ + +#include "qemu/osdep.h" +#include "qemu/xattr.h" +#include "9p-util.h" +
hw/9pfs/9p-util-freebsd.c line 26
Quoted 10 lines
hw/9pfs/9p-util-freebsd.c new file +10
-0+static const char *mangle_xattr_name (const char *name) +{ +/* +* ZFS forbits attributes in the user namespace starting with "user.". +*/ +if (strncmp (name,"user." ,5 ) ==0 ) { +return name +5 ; + } +return name; +}
"ZFS forbids ..."
hw/9pfs/9p-util-freebsd.c line 32
Quoted 6 lines
hw/9pfs/9p-util-freebsd.c new file +6
-0+ +ssize_t fgetxattr (int fd,const char *name,void *value,size_t size) +{ + name =mangle_xattr_name (name); +return extattr_get_fd (fd,EXTATTR_NAMESPACE_USER , name, value, size); +}
I assume if "user." prefix isn't accepted, then "system." is neither, right? Because "system." prefix is used by 9pfs server as well.
Probably the right extattr namespace should be diverted here according to the prefix being passed.
I see there is a conversion function in FreeBSD for this called extattr_string_to_namespace(). But given that the only ones supported are either EXTATTR_NAMESPACE_USER or EXTATTR_NAMESPACE_SYSTEM and since the prefix has to be extracted from the string by own code anway, I guess a simple inliner would do as well.
Quoted 98 lines
hw/9pfs/9p-util-freebsd.c new file +92
-0+ +ssize_t fgetxattrat_nofollow (int dirfd,const char *filename,const char *name, +void *value,size_t size) +{ +ssize_t ret; +int fd; + + fd =openat_file (dirfd, filename, +O_RDONLY |O_PATH_9P_UTIL |O_NOFOLLOW ,0 ); +if (fd ==-1 ) { +return -1 ; + } + name =mangle_xattr_name (name); + ret =extattr_get_fd (fd,EXTATTR_NAMESPACE_USER , name, value, size); +close_preserve_errno (fd); +return ret; +} + +ssize_t flistxattrat_nofollow (int dirfd,const char *filename, +char *list,size_t size) +{ +ssize_t ret; +int fd; + + fd =openat_file (dirfd, filename, +O_RDONLY |O_PATH_9P_UTIL |O_NOFOLLOW ,0 ); +if (fd ==-1 ) { +return -1 ; + } + ret =extattr_list_fd (fd,EXTATTR_NAMESPACE_USER , list, size); +close_preserve_errno (fd); +return ret; +} + +ssize_t fremovexattrat_nofollow (int dirfd,const char *filename, +const char *name) +{ +int fd, ret; + + fd =openat_file (dirfd, filename, +O_RDONLY |O_PATH_9P_UTIL |O_NOFOLLOW ,0 ); +if (fd ==-1 ) { +return -1 ; + } + name =mangle_xattr_name (name); + ret =extattr_delete_fd (fd,EXTATTR_NAMESPACE_USER , name); +close_preserve_errno (fd); +return ret; +} + +int fsetxattrat_nofollow (int dirfd,const char *filename,const char *name, +void *value,size_t size,int flags) +{ +ssize_t ret; +int fd; + + name =mangle_xattr_name (name); +if (flags == (XATTR_CREATE |XATTR_REPLACE )) { + errno =EINVAL ; +return -1 ; + } + fd =openat_file (dirfd, filename, +O_RDONLY |O_PATH_9P_UTIL |O_NOFOLLOW ,0 ); +if (fd ==-1 ) { +return -1 ; + } +if (flags & (XATTR_CREATE |XATTR_REPLACE )) { + ret =extattr_get_fd (fd,EXTATTR_NAMESPACE_USER , name,NULL ,0 ); +if (ret ==-1 && errno !=ENOATTR ) { +close_preserve_errno (fd); +return -1 ; + } +if (ret >=0 && (flags &XATTR_CREATE )) { + errno =EEXIST ; +close_preserve_errno (fd); +return -1 ; + } +if (ret ==-1 && (flags &XATTR_REPLACE )) { + errno =ENOATTR ; +close_preserve_errno (fd); +return -1 ; + } + } + ret =extattr_set_fd (fd,EXTATTR_NAMESPACE_USER , name, value, size); +close_preserve_errno (fd); +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 +0
-0@@ -21,6 +21,14 @@#define O_PATH_9P_UTIL 0
hw/9pfs/9p-util.h line 31
Quoted 10 lines
hw/9pfs/9p-util.h +8
-0#endif +#ifdef CONFIG_FREEBSD +/* +* FreeBSD does not have these flags, so we can only emulate them (racily). +*/ +#define XATTR_CREATE 0x1 +#define XATTR_REPLACE 0x2 +#endif +
What do you mean with "racily" here?
Quoted 70 lines
hw/9pfs/9p-util.h +7
-4#if !defined(CONFIG_LINUX )/* @@ -64,9 +72,9 @@ static inline uint64_t host_dev_to_dotl_dev(dev_t dev)static inline int errno_to_dotl (int err) {#if defined(CONFIG_LINUX )/* nothing to translate (Linux -> Linux) */ -#elif defined(CONFIG_DARWIN ) +#elif defined(CONFIG_DARWIN ) || defined(CONFIG_FREEBSD )/* -* translation mandatory for macOS hosts +* translation mandatory for non-Linux hosts * * FIXME: Only most important errnos translated here yet, this should be * extended to as many errnos being translated as possible in future. @@ -155,13 +163,13 @@ static inline int openat_file(int dirfd, const char *name, int flags, { int fd, serrno, ret; -#ifndef CONFIG_DARWIN +#if !defined(CONFIG_DARWIN) && !defined(CONFIG_FREEBSD) again: #endif fd = qemu_openat(dirfd, name, flags | O_NOFOLLOW | O_NOCTTY | O_NONBLOCK, mode); if (fd == -1) { -#ifndef CONFIG_DARWIN +#if !defined(CONFIG_DARWIN) && !defined(CONFIG_FREEBSD) if (errno == EPERM && (flags & O_NOATIME)) { /* * The client passed O_NOATIME but we lack permissions to honor it.@@ -202,6 +210,9 @@ again:return fd; } +#ifdef CONFIG_FREEBSD +ssize_t fgetxattr (int dirfd,const char *name,void *value,size_t size); +#endif ssize_t fgetxattrat_nofollow (int dirfd,const char *path,const char *name,void *value,size_t size); int fsetxattrat_nofollow(int dirfd, const char *path, const char *name,hw/9pfs/9p.c +4
-2@@ -136,8 +136,10 @@ 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 +#if !defined(CONFIG_DARWIN) && !defined(CONFIG_FREEBSD) { P9_DOTL_NOATIME, O_NOATIME }, +#endif +#ifndef CONFIG_DARWIN/* * On Darwin, we could map to F_NOCACHE, which is * similar, but doesn't quite have the same @@ -3658,7 +3660,7 @@ 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 +#if defined(CONFIG_DARWIN ) || defined(CONFIG_FREEBSD ) fsid_val = (unsigned int )stbuf->f_fsid.val[0 ] | (unsigned long long )stbuf->f_fsid.val[1 ] <<32 ; f_namelen =NAME_MAX ;@@ -4050,6 +4052,16 @@ out_nofid:* Linux guests. */ #define P9_XATTR_SIZE_MAX 65536
hw/9pfs/9p.c out_nofid: · line 4064
Quoted 10 lines
hw/9pfs/9p.c +10
-0+#elif defined(CONFIG_FREEBSD ) +/* +* FreeBSD similarly doesn't define a maximum xattr size, the limit is +* filesystem dependent. On UFS filesystems it's 2 times the filesystem block +* size, typically 32KB. On ZFS it depends on the value of the xattr property; +* with the default value there is no limit, and with xattr=sa it is 64KB. +* +* So, a limit of 64k seems reasonable here too. +*/ +#define P9_XATTR_SIZE_MAX 65536
Yeah, even though the limit with UFS being lower, 64k should be fine. This macro is just to prevent a guest to shoot down the QEMU process by requesting a ridiculous large xattr (RAM) buffer that would exceed host's RAM quota for the process. If the underlying fs supports less, its syscall would still return an appropriate error which is eventually returned to 9p client.
/Christian
Quoted 54 lines
hw/9pfs/9p.c +0
-0#else #error Missing definition for P9_XATTR_SIZE_MAX for this host system#endif hw/9pfs/meson.build +2
-0@@ -15,6 +15,8 @@ fs_ss.add(files( )) if host_os == 'darwin' fs_ss.add(files('9p-util-darwin.c')) +elif host_os == 'freebsd' + fs_ss.add(files('9p-util-freebsd.c')) elif host_os == 'linux' fs_ss.add(files('9p-util-linux.c')) endifinclude/qemu/xattr.h +5
-1@@ -26,7 +26,11 @@# define ENOATTR ENODATA# endif # ifndef CONFIG_WIN32 -# include <sys/xattr.h> +# ifdef CONFIG_FREEBSD +# include <sys/extattr.h> +# else +# include <sys/xattr.h> +# endif # endif #endif meson.build +4
-4@@ -2382,11 +2382,11 @@ dbus_display = get_option('dbus_display') \ .allowed() have_virtfs = get_option('virtfs') \ - .require(host_os == 'linux' or host_os == 'darwin', - error_message: 'virtio-9p (virtfs) requires Linux or macOS') \ - .require(host_os == 'linux' or cc.has_function('pthread_fchdir_np'), + .require(host_os == 'linux' or host_os == 'darwin' or host_os == 'freebsd', + error_message: 'virtio-9p (virtfs) requires Linux or macOS or FreeBSD') \ + .require(host_os != 'darwin' or cc.has_function('pthread_fchdir_np'), error_message: 'virtio-9p (virtfs) on macOS requires the presence of pthread_fchdir_np') \ - .require(host_os == 'darwin' or libattr.found(), + .require(host_os != 'linux' or libattr.found(), error_message: 'virtio-9p (virtfs) on Linux requires libattr-devel') \ .disable_auto_if(not have_tools and not have_system) \ .allowed()
Quoted 38 lines · Christian Schoenebeck
Quoted 11 lines · CEST Mark Johnston
This is largely derived from existing Darwin support. FreeBSD apparently has better support for
*at()system calls so doesn't require workarounds for a missingmknodat(). The implementation has a couple of warts however:
- The extattr(2) system calls don't support anything akin toXATTR_CREATEorXATTR_REPLACE, so a racy workaround is implemented.
- Attribute names cannot begin with "user." on ZFS, so the prefix is trimmed off. FreeBSD's extattr system calls sport an extra "namespace" identifier, and attributes created by the 9pfs backend live in the universal user namespace, so this seems innocent enough.Quoted 4 lines
The 9pfs tests were verified to pass on the UFS, ZFS and tmpfs filesystems.
Signed-off-by Mark Johnston <[email protected]>Hi Mark,
first off, the problem is I currently don't have a FreeBSD host to test and won't have the time in near future neither.
So what was your general intention regarding this patch, fire and forget, or would you be around for issues/patches regarding 9pfs FreeBSD support?
Quoted 12 lines
--- fsdev/file-op-9p.h | 6 +- fsdev/meson.build | 2 +- hw/9pfs/9p-synth.c | 2 +- hw/9pfs/9p-util-freebsd.c | 124 ++++++++++++++++++++++++++++++++++++++ hw/9pfs/9p-util.h | 19 ++++-- hw/9pfs/9p.c | 16 ++++- hw/9pfs/meson.build | 2 + include/qemu/xattr.h | 6 +- meson.build | 8 +-- 9 files changed, 170 insertions(+), 15 deletions(-) create mode 100644 hw/9pfs/9p-util-freebsd.c
Quoted 15 lines
hw/9pfs/9p-util-freebsd.c line 6
Quoted 12 lines
hw/9pfs/9p-util-freebsd.c new file +6
-0@@ -0,0 +1,124 @@ +/* +* 9p utilities (FreeBSD 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. +*/ I think for new source files in QEMU the policy is to use
SPDX-License-Identifier: ... now?
Yes, checkpatch.pl should complain both about the missing SPDX tag and about this license blurb which would be redundant if SPDX were present.
With regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
Quoted 17 lines · Christian Schoenebeck
Quoted 11 lines · CEST Mark Johnston
This is largely derived from existing Darwin support. FreeBSD apparently has better support for
*at()system calls so doesn't require workarounds for a missingmknodat(). The implementation has a couple of warts however:
- The extattr(2) system calls don't support anything akin toXATTR_CREATEorXATTR_REPLACE, so a racy workaround is implemented.
- Attribute names cannot begin with "user." on ZFS, so the prefix is trimmed off. FreeBSD's extattr system calls sport an extra "namespace" identifier, and attributes created by the 9pfs backend live in the universal user namespace, so this seems innocent enough.Quoted 4 lines
The 9pfs tests were verified to pass on the UFS, ZFS and tmpfs filesystems.
Signed-off-by Mark Johnston <[email protected]>
Quoted 7 lines
Hi Mark,
first off, the problem is I currently don't have a FreeBSD host to test and won't have the time in near future neither.
So what was your general intention regarding this patch, fire and forget, or would you be around for issues/patches regarding 9pfs FreeBSD support?
Thank you for taking a look.
I'll certainly be around to help deal with issues and patches relating to 9pfs+FreeBSD hosts. It's hard to prove that, but for what it's worth I use QEMU fairly extensively for FreeBSD development when I can't use the native hypervisor, and that's not likely to change anytime soon.
Would adding myself to MAINTAINERS for virtio-9pfs (or a new virtio-9pfs-freebsd category) be appropriate in that case?
Quoted 19 lines
Quoted 19 lines
--- fsdev/file-op-9p.h | 6 +- fsdev/meson.build | 2 +- hw/9pfs/9p-synth.c | 2 +- hw/9pfs/9p-util-freebsd.c | 124 ++++++++++++++++++++++++++++++++++++++ hw/9pfs/9p-util.h | 19 ++++-- hw/9pfs/9p.c | 16 ++++- hw/9pfs/meson.build | 2 + include/qemu/xattr.h | 6 +- meson.build | 8 +-- 9 files changed, 170 insertions(+), 15 deletions(-) create mode 100644 hw/9pfs/9p-util-freebsd.cfsdev/file-op-9p.h +0
-0@@ -21,9 +21,11 @@
Quoted 11 lines
fsdev/file-op-9p.h line 28
Quoted 9 lines
fsdev/file-op-9p.h +4
-2#ifdef CONFIG_LINUX # include <sys/vfs.h> -#endif -#ifdef CONFIG_DARWIN +#elif defined(CONFIG_DARWIN ) || defined(CONFIG_FREEBSD )# include <sys/param.h> +# ifdef CONFIG_FREEBSD +# undef MACHINE/* work around some unfortunate namespace pollution */ +# endif Details? :)
We need sys/mount.h for struct statfs. sys/mount.h implicitly includes sys/param.h, which is really sloppy about polluting the namespace with identifiers that only the kernel cares about 99% of the time. In particular, it includes a platform-specific param.h which defines
#define MACHINE "amd64"
#define MACHINE_ARCH "amd64"
among other things. This conflicts with QEMU's MACHINE macro.
It's a mess. I have some local FreeBSD patches to avoid including param.h from sys/mount.h, but of course a number of applications have come to rely on the pollution, so they all need to be fixed first.
At some point, I think the block above can become something like
#elif defined(CONFIG_DARWIN) || defined(CONFIG_FREEBSD) # ifndef CONFIG_FREEBSD # include <sys/param.h> # endif # include <sys/mount.h>
but for now I need this workaround.
Quoted 35 lines
Quoted 35 lines
fsdev/file-op-9p.h +0
-0# include <sys/mount.h> #endif fsdev/meson.build +1
-1@@ -5,6 +5,6 @@ fsdev_ss.add(when: ['CONFIG_FSDEV_9P'], if_true: files( '9p-marshal.c', 'qemu-fsdev.c', ), if_false: files('qemu-fsdev-dummy.c')) -if host_os in ['linux', 'darwin'] +if host_os in ['linux', 'darwin', 'freebsd'] system_ss.add_all(fsdev_ss) endifhw/9pfs/9p-synth.c +1
-1@@ -451,7 +451,7 @@ 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 +#if !defined(CONFIG_DARWIN ) && !defined(CONFIG_FREEBSD ) stbuf->f_namelen =NAME_MAX ;#endif return 0 ;hw/9pfs/9p-util-freebsd.c new file +1
-0@@ -0,0 +1,124 @@ +/*
Quoted 8 lines
hw/9pfs/9p-util-freebsd.c line 6
Quoted 5 lines
hw/9pfs/9p-util-freebsd.c new file +5
-0+* 9p utilities (FreeBSD 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. +*/ I think for new source files in QEMU the policy is to use
SPDX-License-Identifier: ... now?
checkpatch.pl does complain about that, yes, but it also qualifies the warning with, "unless this file was copied from existing code already having such text." I used 9p-util-darwin.c as a starting point for this file, so kept the existing license text. I can certainly change it though.
Quoted 3 lines
Is this source file really specific to exactly FreeBSD? From the name it suggests that potential future support for other BSD flavours would need their own source file.
Hmm, not really. Other BSDs seem to implement a compatible syscall interface when they implement it at all. (NetBSD's interface seems to be compatible; OpenBSD doesn't appear to implement extattrs at all, and DragonflyBSD is missing the extattr_*_fd() variants.)
FreeBSD appears to be the only one that implements O_PATH, but that seems to be optional if I'm reading correctly.
So, I could preemptively change it to 9p-util-bsd.c, or wait for someone to come along and add support for another BSD.
Quoted 14 lines
Quoted 14 lines
hw/9pfs/9p-util-freebsd.c new file +14
-0+ +/* +* Not so fast! You might want to read the 9p developer docs first: +* https://wiki.qemu.org/Documentation/9p +*/ + +#include "qemu/osdep.h" +#include "qemu/xattr.h" +#include "9p-util.h" + +static const char *mangle_xattr_name (const char *name) +{ +/* +* ZFS forbits attributes in the user namespace starting with "user.".
Quoted 8 lines
hw/9pfs/9p-util-freebsd.c line 26
Quoted 6 lines
hw/9pfs/9p-util-freebsd.c new file +6
-0+*/ +if (strncmp (name,"user." ,5 ) ==0 ) { +return name +5 ; + } +return name; +}"ZFS forbids ..."
Fixed, thanks.
Quoted 9 lines
hw/9pfs/9p-util-freebsd.c line 32
Quoted 7 lines
hw/9pfs/9p-util-freebsd.c new file +6
-0+ +ssize_t fgetxattr (int fd,const char *name,void *value,size_t size) +{ + name =mangle_xattr_name (name); +return extattr_get_fd (fd,EXTATTR_NAMESPACE_USER , name, value, size); +}I assume if "user." prefix isn't accepted, then "system." is neither, right?
That's right.
Quoted 10 lines
Because "system." prefix is used by 9pfs server as well.
Probably the right extattr namespace should be diverted here according to the prefix being passed.
I see there is a conversion function in FreeBSD for this called
extattr_string_to_namespace(). But given that the only ones supported are eitherEXTATTR_NAMESPACE_USERorEXTATTR_NAMESPACE_SYSTEMand since the prefix has to be extracted from the string by own code anway, I guess a simple inliner would do as well.
Yes, I think that's not too fragile. I implemented that in my local version.
Quoted 100 lines
Quoted 100 lines
hw/9pfs/9p-util-freebsd.c new file +92
-0+ +ssize_t fgetxattrat_nofollow (int dirfd,const char *filename,const char *name, +void *value,size_t size) +{ +ssize_t ret; +int fd; + + fd =openat_file (dirfd, filename, +O_RDONLY |O_PATH_9P_UTIL |O_NOFOLLOW ,0 ); +if (fd ==-1 ) { +return -1 ; + } + name =mangle_xattr_name (name); + ret =extattr_get_fd (fd,EXTATTR_NAMESPACE_USER , name, value, size); +close_preserve_errno (fd); +return ret; +} + +ssize_t flistxattrat_nofollow (int dirfd,const char *filename, +char *list,size_t size) +{ +ssize_t ret; +int fd; + + fd =openat_file (dirfd, filename, +O_RDONLY |O_PATH_9P_UTIL |O_NOFOLLOW ,0 ); +if (fd ==-1 ) { +return -1 ; + } + ret =extattr_list_fd (fd,EXTATTR_NAMESPACE_USER , list, size); +close_preserve_errno (fd); +return ret; +} + +ssize_t fremovexattrat_nofollow (int dirfd,const char *filename, +const char *name) +{ +int fd, ret; + + fd =openat_file (dirfd, filename, +O_RDONLY |O_PATH_9P_UTIL |O_NOFOLLOW ,0 ); +if (fd ==-1 ) { +return -1 ; + } + name =mangle_xattr_name (name); + ret =extattr_delete_fd (fd,EXTATTR_NAMESPACE_USER , name); +close_preserve_errno (fd); +return ret; +} + +int fsetxattrat_nofollow (int dirfd,const char *filename,const char *name, +void *value,size_t size,int flags) +{ +ssize_t ret; +int fd; + + name =mangle_xattr_name (name); +if (flags == (XATTR_CREATE |XATTR_REPLACE )) { + errno =EINVAL ; +return -1 ; + } + fd =openat_file (dirfd, filename, +O_RDONLY |O_PATH_9P_UTIL |O_NOFOLLOW ,0 ); +if (fd ==-1 ) { +return -1 ; + } +if (flags & (XATTR_CREATE |XATTR_REPLACE )) { + ret =extattr_get_fd (fd,EXTATTR_NAMESPACE_USER , name,NULL ,0 ); +if (ret ==-1 && errno !=ENOATTR ) { +close_preserve_errno (fd); +return -1 ; + } +if (ret >=0 && (flags &XATTR_CREATE )) { + errno =EEXIST ; +close_preserve_errno (fd); +return -1 ; + } +if (ret ==-1 && (flags &XATTR_REPLACE )) { + errno =ENOATTR ; +close_preserve_errno (fd); +return -1 ; + } + } + ret =extattr_set_fd (fd,EXTATTR_NAMESPACE_USER , name, value, size); +close_preserve_errno (fd); +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 +0
-0@@ -21,6 +21,14 @@#define O_PATH_9P_UTIL 0#endif
Quoted 10 lines
hw/9pfs/9p-util.h line 31
Quoted 8 lines
hw/9pfs/9p-util.h +8
-0+#ifdef CONFIG_FREEBSD +/* +* FreeBSD does not have these flags, so we can only emulate them (racily). +*/ +#define XATTR_CREATE 0x1 +#define XATTR_REPLACE 0x2 +#endif +What do you mean with "racily" here?
FreeBSD cannot atomically check for the existence of and set an extattr, the system call interface simply doesn't support it today. This means that fsetxattrat_nofollow() needs back-to-back system calls to check for the existence of an attribute and then potentially set it.
Quoted 145 lines
Quoted 70 lines
hw/9pfs/9p-util.h +7
-4#if !defined(CONFIG_LINUX )/* @@ -64,9 +72,9 @@ static inline uint64_t host_dev_to_dotl_dev(dev_t dev)static inline int errno_to_dotl (int err) {#if defined(CONFIG_LINUX )/* nothing to translate (Linux -> Linux) */ -#elif defined(CONFIG_DARWIN ) +#elif defined(CONFIG_DARWIN ) || defined(CONFIG_FREEBSD )/* -* translation mandatory for macOS hosts +* translation mandatory for non-Linux hosts * * FIXME: Only most important errnos translated here yet, this should be * extended to as many errnos being translated as possible in future. @@ -155,13 +163,13 @@ static inline int openat_file(int dirfd, const char *name, int flags, { int fd, serrno, ret; -#ifndef CONFIG_DARWIN +#if !defined(CONFIG_DARWIN) && !defined(CONFIG_FREEBSD) again: #endif fd = qemu_openat(dirfd, name, flags | O_NOFOLLOW | O_NOCTTY | O_NONBLOCK, mode); if (fd == -1) { -#ifndef CONFIG_DARWIN +#if !defined(CONFIG_DARWIN) && !defined(CONFIG_FREEBSD) if (errno == EPERM && (flags & O_NOATIME)) { /* * The client passed O_NOATIME but we lack permissions to honor it.@@ -202,6 +210,9 @@ again:return fd; } +#ifdef CONFIG_FREEBSD +ssize_t fgetxattr (int dirfd,const char *name,void *value,size_t size); +#endif ssize_t fgetxattrat_nofollow (int dirfd,const char *path,const char *name,void *value,size_t size); int fsetxattrat_nofollow(int dirfd, const char *path, const char *name,hw/9pfs/9p.c +4
-2@@ -136,8 +136,10 @@ 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 +#if !defined(CONFIG_DARWIN) && !defined(CONFIG_FREEBSD) { P9_DOTL_NOATIME, O_NOATIME }, +#endif +#ifndef CONFIG_DARWIN/* * On Darwin, we could map to F_NOCACHE, which is * similar, but doesn't quite have the same @@ -3658,7 +3660,7 @@ 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 +#if defined(CONFIG_DARWIN ) || defined(CONFIG_FREEBSD ) fsid_val = (unsigned int )stbuf->f_fsid.val[0 ] | (unsigned long long )stbuf->f_fsid.val[1 ] <<32 ; f_namelen =NAME_MAX ;@@ -4050,6 +4052,16 @@ out_nofid:* Linux guests. */ #define P9_XATTR_SIZE_MAX 65536hw/9pfs/9p.c out_nofid: · line 4064
Quoted 10 lines
hw/9pfs/9p.c +10
-0+#elif defined(CONFIG_FREEBSD ) +/* +* FreeBSD similarly doesn't define a maximum xattr size, the limit is +* filesystem dependent. On UFS filesystems it's 2 times the filesystem block +* size, typically 32KB. On ZFS it depends on the value of the xattr property; +* with the default value there is no limit, and with xattr=sa it is 64KB. +* +* So, a limit of 64k seems reasonable here too. +*/ +#define P9_XATTR_SIZE_MAX 65536Yeah, even though the limit with UFS being lower, 64k should be fine. This macro is just to prevent a guest to shoot down the QEMU process by requesting a ridiculous large xattr (RAM) buffer that would exceed host's RAM quota for the process. If the underlying fs supports less, its syscall would still return an appropriate error which is eventually returned to 9p client.
/Christian
Quoted 54 lines
hw/9pfs/9p.c +0
-0#else #error Missing definition for P9_XATTR_SIZE_MAX for this host system#endif hw/9pfs/meson.build +2
-0@@ -15,6 +15,8 @@ fs_ss.add(files( )) if host_os == 'darwin' fs_ss.add(files('9p-util-darwin.c')) +elif host_os == 'freebsd' + fs_ss.add(files('9p-util-freebsd.c')) elif host_os == 'linux' fs_ss.add(files('9p-util-linux.c')) endifinclude/qemu/xattr.h +5
-1@@ -26,7 +26,11 @@# define ENOATTR ENODATA# endif # ifndef CONFIG_WIN32 -# include <sys/xattr.h> +# ifdef CONFIG_FREEBSD +# include <sys/extattr.h> +# else +# include <sys/xattr.h> +# endif # endif #endif meson.build +4
-4@@ -2382,11 +2382,11 @@ dbus_display = get_option('dbus_display') \ .allowed() have_virtfs = get_option('virtfs') \ - .require(host_os == 'linux' or host_os == 'darwin', - error_message: 'virtio-9p (virtfs) requires Linux or macOS') \ - .require(host_os == 'linux' or cc.has_function('pthread_fchdir_np'), + .require(host_os == 'linux' or host_os == 'darwin' or host_os == 'freebsd', + error_message: 'virtio-9p (virtfs) requires Linux or macOS or FreeBSD') \ + .require(host_os != 'darwin' or cc.has_function('pthread_fchdir_np'), error_message: 'virtio-9p (virtfs) on macOS requires the presence of pthread_fchdir_np') \ - .require(host_os == 'darwin' or libattr.found(), + .require(host_os != 'linux' or libattr.found(), error_message: 'virtio-9p (virtfs) on Linux requires libattr-devel') \ .disable_auto_if(not have_tools and not have_system) \ .allowed()
Quoted 52 lines · Mark Johnston
Quoted 17 lines · Christian Schoenebeck
Quoted 11 lines · CEST Mark Johnston
This is largely derived from existing Darwin support. FreeBSD apparently has better support for
*at()system calls so doesn't require workarounds for a missingmknodat(). The implementation has a couple of warts however:
- The extattr(2) system calls don't support anything akin toXATTR_CREATEorXATTR_REPLACE, so a racy workaround is implemented.
- Attribute names cannot begin with "user." on ZFS, so the prefix is trimmed off. FreeBSD's extattr system calls sport an extra "namespace" identifier, and attributes created by the 9pfs backend live in the universal user namespace, so this seems innocent enough.Quoted 4 lines
The 9pfs tests were verified to pass on the UFS, ZFS and tmpfs filesystems.
Signed-off-by Mark Johnston <[email protected]>Quoted 7 lines
Hi Mark,
first off, the problem is I currently don't have a FreeBSD host to test and won't have the time in near future neither.
So what was your general intention regarding this patch, fire and forget, or would you be around for issues/patches regarding 9pfs FreeBSD support?
Thank you for taking a look.
I'll certainly be around to help deal with issues and patches relating to 9pfs+FreeBSD hosts. It's hard to prove that, but for what it's worth I use QEMU fairly extensively for FreeBSD development when I can't use the native hypervisor, and that's not likely to change anytime soon.
Would adding myself to
MAINTAINERSfor virtio-9pfs (or a new virtio-9pfs-freebsd category) be appropriate in that case?Quoted 7 lines
Quoted 7 lines
hw/9pfs/9p-util-freebsd.c new file +1
-0@@ -0,0 +1,124 @@ +/* Quoted 8 lines
hw/9pfs/9p-util-freebsd.c line 6
Quoted 5 lines
hw/9pfs/9p-util-freebsd.c new file +5
-0+* 9p utilities (FreeBSD 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. +*/ I think for new source files in QEMU the policy is to use
SPDX-License-Identifier: ... now?
Quoted 5 lines
checkpatch.pl does complain about that, yes, but it also qualifies the warning with, "unless this file was copied from existing code already having such text." I used
9p-util-darwin.cas a starting point for this file, so kept the existing license text. I can certainly change it though.
In that case, this is fine as is.
With regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
Quoted 2 lines · CEST Mark Johnston
Quoted 1 line · Christian Schoenebeck
On Wednesday, July 23, 2025 5:55:58 PM CEST Mark Johnston wrote:
[...]
Quoted 9 lines
Thank you for taking a look.
I'll certainly be around to help deal with issues and patches relating to 9pfs+FreeBSD hosts. It's hard to prove that, but for what it's worth I use QEMU fairly extensively for FreeBSD development when I can't use the native hypervisor, and that's not likely to change anytime soon.
Would adding myself to
MAINTAINERSfor virtio-9pfs (or a new virtio-9pfs-freebsd category) be appropriate in that case?
Good to hear that you will be around!
I leave it to you whether you want to add yourself as reviewer of patches to MAINTAINER's 9pfs section.
For other things like adding a virtio-9pfs-freebsd subsection or something, it's probably a bit too early.
Quoted 34 lines
Quoted 6 lines
Quoted 6 lines
fsdev/file-op-9p.h +0
-0@@ -21,9 +21,11 @@Quoted 11 lines
fsdev/file-op-9p.h line 28
Quoted 9 lines
fsdev/file-op-9p.h +4
-2#ifdef CONFIG_LINUX # include <sys/vfs.h> -#endif -#ifdef CONFIG_DARWIN +#elif defined(CONFIG_DARWIN ) || defined(CONFIG_FREEBSD )# include <sys/param.h> +# ifdef CONFIG_FREEBSD +# undef MACHINE/* work around some unfortunate namespace pollution */ +# endif Details? :)
We need
sys/mount.hfor struct statfs.sys/mount.himplicitly includessys/param.h, which is really sloppy about polluting the namespace with identifiers that only the kernel cares about 99% of the time. In particular, it includes a platform-specificparam.hwhich defines#define MACHINE "amd64"
#defineMACHINE_ARCH"amd64"among other things. This conflicts with QEMU's MACHINE macro.
It's a mess. I have some local FreeBSD patches to avoid including
param.hfromsys/mount.h, but of course a number of applications have come to rely on the pollution, so they all need to be fixed first.At some point, I think the block above can become something like
Quoted 7 lines
#elif defined(CONFIG_DARWIN) || defined(CONFIG_FREEBSD) # ifndef CONFIG_FREEBSD # include <sys/param.h> # endif # include <sys/mount.h>but for now I need this workaround.
OK.
Quoted 44 lines
Quoted 35 lines
Quoted 35 lines
fsdev/file-op-9p.h +0
-0# include <sys/mount.h> #endif fsdev/meson.build +1
-1@@ -5,6 +5,6 @@ fsdev_ss.add(when: ['CONFIG_FSDEV_9P'], if_true: files( '9p-marshal.c', 'qemu-fsdev.c', ), if_false: files('qemu-fsdev-dummy.c')) -if host_os in ['linux', 'darwin'] +if host_os in ['linux', 'darwin', 'freebsd'] system_ss.add_all(fsdev_ss) endifhw/9pfs/9p-synth.c +1
-1@@ -451,7 +451,7 @@ 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 +#if !defined(CONFIG_DARWIN ) && !defined(CONFIG_FREEBSD ) stbuf->f_namelen =NAME_MAX ;#endif return 0 ;hw/9pfs/9p-util-freebsd.c new file +1
-0@@ -0,0 +1,124 @@ +/* Quoted 8 lines
hw/9pfs/9p-util-freebsd.c line 6
Quoted 5 lines
hw/9pfs/9p-util-freebsd.c new file +5
-0+* 9p utilities (FreeBSD 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. +*/ I think for new source files in QEMU the policy is to use
SPDX-License-Identifier: ... now?
Quoted 5 lines
checkpatch.pl does complain about that, yes, but it also qualifies the warning with, "unless this file was copied from existing code already having such text." I used
9p-util-darwin.cas a starting point for this file, so kept the existing license text. I can certainly change it though.
Both ways are fine with me in this case. Do as you find appropriate.
Quoted 9 lines
Quoted 3 lines
Is this source file really specific to exactly FreeBSD? From the name it suggests that potential future support for other BSD flavours would need their own source file.
Hmm, not really. Other BSDs seem to implement a compatible syscall interface when they implement it at all. (NetBSD's interface seems to be compatible; OpenBSD doesn't appear to implement extattrs at all, and DragonflyBSD is missing the extattr_*_fd() variants.)
Quoted 5 lines
FreeBSD appears to be the only one that implements
O_PATH, but that seems to be optional if I'm reading correctly.So, I could preemptively change it to
9p-util-bsd.c, or wait for someone to come along and add support for another BSD.
Yeah, that was on nit level as well. It's fine to leave the name, as FreeBSD is currently the only supported one.
Quoted 19 lines
Quoted 8 lines
Quoted 8 lines
hw/9pfs/9p-util.h +0
-0@@ -21,6 +21,14 @@#define O_PATH_9P_UTIL 0#endif Quoted 10 lines
hw/9pfs/9p-util.h line 31
Quoted 8 lines
hw/9pfs/9p-util.h +8
-0+#ifdef CONFIG_FREEBSD +/* +* FreeBSD does not have these flags, so we can only emulate them (racily). +*/ +#define XATTR_CREATE 0x1 +#define XATTR_REPLACE 0x2 +#endif +What do you mean with "racily" here?
Quoted 4 lines
FreeBSD cannot atomically check for the existence of and set an extattr, the system call interface simply doesn't support it today. This means that
fsetxattrat_nofollow()needs back-to-back system calls to check for the existence of an attribute and then potentially set it.
Ah, I was misinterpreting your comment as if it were "racily defining" the macros. Maybe change the comment to something like "... can only emulate their intended behaviour (racily) ...".
Thanks!
/Christian
Quoted 11 lines · Christian Schoenebeck
Quoted 2 lines · CEST Mark Johnston
Quoted 1 line · Christian Schoenebeck
On Wednesday, July 23, 2025 5:55:58 PM CEST Mark Johnston wrote:
[...]
Quoted 7 lines
Thank you for taking a look.
I'll certainly be around to help deal with issues and patches relating to 9pfs+FreeBSD hosts. It's hard to prove that, but for what it's worth I use QEMU fairly extensively for FreeBSD development when I can't use the native hypervisor, and that's not likely to change anytime soon.
Quoted 7 lines
Quoted 2 lines
Would adding myself to
MAINTAINERSfor virtio-9pfs (or a new virtio-9pfs-freebsd category) be appropriate in that case?Good to hear that you will be around!
I leave it to you whether you want to add yourself as reviewer of patches to MAINTAINER's 9pfs section.
Ok. I'll leave myself off the list for now then. If the patch is applied and any FreeBSD-related problems crop up, please let me know of course I'll try to fix them ASAP. If this turns out to be a regular occurrence (hopefully not), I can add myself and be more proactive about responding to patches or bug reports.
Quoted 19 lines
Quoted 19 lines
Quoted 18 lines
Quoted 6 lines
hw/9pfs/9p-util.h +0
-0@@ -21,6 +21,14 @@#define O_PATH_9P_UTIL 0hw/9pfs/9p-util.h line 31
Quoted 10 lines
hw/9pfs/9p-util.h +8
-0#endif +#ifdef CONFIG_FREEBSD +/* +* FreeBSD does not have these flags, so we can only emulate them (racily). +*/ +#define XATTR_CREATE 0x1 +#define XATTR_REPLACE 0x2 +#endif +What do you mean with "racily" here?
Quoted 8 lines
Quoted 4 lines
FreeBSD cannot atomically check for the existence of and set an extattr, the system call interface simply doesn't support it today. This means that
fsetxattrat_nofollow()needs back-to-back system calls to check for the existence of an attribute and then potentially set it.Ah, I was misinterpreting your comment as if it were "racily defining" the macros. Maybe change the comment to something like "... can only emulate their intended behaviour (racily) ...".
Done. I'll send out a v2 shortly.