All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3 00/11] This is a followup to https://lists.gnu.org/archive/html/qemu-devel/2021-11/msg04325.html,
@ 2022-01-28  0:56 Will Cohen
  2022-01-28  0:56 ` [PATCH v3 01/11] 9p: linux: Fix a couple Linux assumptions Will Cohen
                   ` (10 more replies)
  0 siblings, 11 replies; 22+ messages in thread
From: Will Cohen @ 2022-01-28  0:56 UTC (permalink / raw)
  To: qemu-devel
  Cc: Laurent Vivier, Thomas Huth, Christian Schoenebeck, Greg Kurz,
	hi, Will Cohen, Paolo Bonzini


Since v2, the following changes have been made:

- Re-add incorrectly omitted previous review header to final patch
- Remove redundant utimensat backwards compatibility
- Set XATTR_SIZE_MAX to 64k
- Integrate proposed statfs.h back into file-op-9p.h
- Replace clang references with gcc
- Ensure that synth tests pass

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: Compatibility defn for 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                     | 15 +++-
 fsdev/meson.build                      |  1 +
 hw/9pfs/9p-local.c                     | 19 +++--
 hw/9pfs/9p-proxy.c                     | 18 ++++-
 hw/9pfs/9p-synth.c                     |  4 ++
 hw/9pfs/9p-util-darwin.c               | 97 ++++++++++++++++++++++++++
 hw/9pfs/{9p-util.c => 9p-util-linux.c} |  7 +-
 hw/9pfs/9p-util.h                      | 21 ++++++
 hw/9pfs/9p.c                           | 73 +++++++++++++++++--
 hw/9pfs/codir.c                        |  4 ++
 hw/9pfs/meson.build                    |  3 +-
 include/qemu/xattr.h                   |  4 +-
 meson.build                            | 12 ++--
 tests/qtest/virtio-9p-test.c           |  2 +-
 14 files changed, 257 insertions(+), 23 deletions(-)
 create mode 100644 hw/9pfs/9p-util-darwin.c
 rename hw/9pfs/{9p-util.c => 9p-util-linux.c} (90%)

-- 
2.34.1



^ permalink raw reply	[flat|nested] 22+ messages in thread

* [PATCH v3 01/11] 9p: linux: Fix a couple Linux assumptions
  2022-01-28  0:56 [PATCH v3 00/11] This is a followup to https://lists.gnu.org/archive/html/qemu-devel/2021-11/msg04325.html, Will Cohen
@ 2022-01-28  0:56 ` Will Cohen
  2022-01-28 15:52   ` Greg Kurz
  2022-01-28  0:56 ` [PATCH v3 02/11] 9p: Rename 9p-util -> 9p-util-linux Will Cohen
                   ` (9 subsequent siblings)
  10 siblings, 1 reply; 22+ messages in thread
From: Will Cohen @ 2022-01-28  0:56 UTC (permalink / raw)
  To: qemu-devel
  Cc: Laurent Vivier, Thomas Huth, Christian Schoenebeck, Greg Kurz,
	hi, Michael Roitzsch, Will Cohen, Paolo Bonzini, Keno Fischer,
	Keno Fischer

From: Keno Fischer <keno@alumni.harvard.edu>

 - 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).

Signed-off-by: Keno Fischer <keno@juliacomputing.com>
[Michael Roitzsch: - Rebase for NixOS]
Signed-off-by: Michael Roitzsch <reactorcontrol@icloud.com>
[Will Cohen: - Fix headers for Alpine
             - Integrate statfs.h back into file-op-9p.h]
Signed-off-by: Will Cohen <wwcohen@gmail.com>
---
 fsdev/file-op-9p.h   | 15 ++++++++++++++-
 hw/9pfs/9p-local.c   |  2 ++
 hw/9pfs/9p.c         |  4 ++++
 include/qemu/xattr.h |  4 +++-
 4 files changed, 23 insertions(+), 2 deletions(-)

diff --git a/fsdev/file-op-9p.h b/fsdev/file-op-9p.h
index 8fd89f0447..616c6f503f 100644
--- a/fsdev/file-op-9p.h
+++ b/fsdev/file-op-9p.h
@@ -16,10 +16,23 @@
 
 #include <dirent.h>
 #include <utime.h>
-#include <sys/vfs.h>
 #include "qemu-fsdev-throttle.h"
 #include "p9array.h"
 
+#ifndef QEMU_STATFS_H
+#define QEMU_STATFS_H
+
+#ifdef CONFIG_LINUX
+# include <sys/vfs.h>
+#endif
+#ifdef CONFIG_DARWIN
+# include <sys/param.h>
+# include <sys/mount.h>
+#endif
+
+#endif
+
+
 #define SM_LOCAL_MODE_BITS    0600
 #define SM_LOCAL_DIR_MODE_BITS    0700
 
diff --git a/hw/9pfs/9p-local.c b/hw/9pfs/9p-local.c
index 210d9e7705..1a5e3eed73 100644
--- a/hw/9pfs/9p-local.c
+++ b/hw/9pfs/9p-local.c
@@ -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
diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c
index 15b3f4d385..9c63e14b28 100644
--- a/hw/9pfs/9p.c
+++ b/hw/9pfs/9p.c
@@ -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;
diff --git a/include/qemu/xattr.h b/include/qemu/xattr.h
index a83fe8e749..f1d0f7be74 100644
--- a/include/qemu/xattr.h
+++ b/include/qemu/xattr.h
@@ -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
 
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH v3 02/11] 9p: Rename 9p-util -> 9p-util-linux
  2022-01-28  0:56 [PATCH v3 00/11] This is a followup to https://lists.gnu.org/archive/html/qemu-devel/2021-11/msg04325.html, Will Cohen
  2022-01-28  0:56 ` [PATCH v3 01/11] 9p: linux: Fix a couple Linux assumptions Will Cohen
@ 2022-01-28  0:56 ` Will Cohen
  2022-01-28 16:27   ` Greg Kurz
  2022-01-28  0:56 ` [PATCH v3 03/11] 9p: darwin: Handle struct stat(fs) differences Will Cohen
                   ` (8 subsequent siblings)
  10 siblings, 1 reply; 22+ messages in thread
From: Will Cohen @ 2022-01-28  0:56 UTC (permalink / raw)
  To: qemu-devel
  Cc: Laurent Vivier, Thomas Huth, Christian Schoenebeck, Greg Kurz,
	hi, Michael Roitzsch, Will Cohen, Paolo Bonzini, Keno Fischer

From: Keno Fischer <keno@juliacomputing.com>

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.

Signed-off-by: Keno Fischer <keno@juliacomputing.com>
[Michael Roitzsch: - Rebase for NixOS]
Signed-off-by: Michael Roitzsch <reactorcontrol@icloud.com>
Signed-off-by: Will Cohen <wwcohen@gmail.com>
---
 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%)

diff --git a/hw/9pfs/9p-util.c b/hw/9pfs/9p-util-linux.c
similarity index 97%
rename from hw/9pfs/9p-util.c
rename to hw/9pfs/9p-util-linux.c
index 3221d9b498..398614a5d0 100644
--- a/hw/9pfs/9p-util.c
+++ b/hw/9pfs/9p-util-linux.c
@@ -1,5 +1,5 @@
 /*
- * 9p utilities
+ * 9p utilities (Linux Implementation)
  *
  * Copyright IBM, Corp. 2017
  *
diff --git a/hw/9pfs/meson.build b/hw/9pfs/meson.build
index 99be5d9119..1b28e70040 100644
--- a/hw/9pfs/meson.build
+++ b/hw/9pfs/meson.build
@@ -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)
 
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH v3 03/11] 9p: darwin: Handle struct stat(fs) differences
  2022-01-28  0:56 [PATCH v3 00/11] This is a followup to https://lists.gnu.org/archive/html/qemu-devel/2021-11/msg04325.html, Will Cohen
  2022-01-28  0:56 ` [PATCH v3 01/11] 9p: linux: Fix a couple Linux assumptions Will Cohen
  2022-01-28  0:56 ` [PATCH v3 02/11] 9p: Rename 9p-util -> 9p-util-linux Will Cohen
@ 2022-01-28  0:56 ` Will Cohen
  2022-02-02 17:48   ` Christian Schoenebeck
  2022-01-28  0:56 ` [PATCH v3 04/11] 9p: darwin: Handle struct dirent differences Will Cohen
                   ` (7 subsequent siblings)
  10 siblings, 1 reply; 22+ messages in thread
From: Will Cohen @ 2022-01-28  0:56 UTC (permalink / raw)
  To: qemu-devel
  Cc: Laurent Vivier, Thomas Huth, Christian Schoenebeck, Greg Kurz,
	hi, Michael Roitzsch, Will Cohen, Paolo Bonzini, Keno Fischer

From: Keno Fischer <keno@juliacomputing.com>

Signed-off-by: Keno Fischer <keno@juliacomputing.com>
Signed-off-by: Michael Roitzsch <reactorcontrol@icloud.com>
[Will Cohen: - Note lack of f_namelen and f_frsize on Darwin]
Signed-off-by: Will Cohen <wwcohen@gmail.com>
---
 hw/9pfs/9p-proxy.c | 18 +++++++++++++++---
 hw/9pfs/9p-synth.c |  2 ++
 hw/9pfs/9p.c       | 16 ++++++++++++++--
 3 files changed, 31 insertions(+), 5 deletions(-)

diff --git a/hw/9pfs/9p-proxy.c b/hw/9pfs/9p-proxy.c
index 09bd9f1464..f5aade21b5 100644
--- a/hw/9pfs/9p-proxy.c
+++ b/hw/9pfs/9p-proxy.c
@@ -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,18 @@ 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_atim.tv_sec = prstat->st_atim_sec;
-   stbuf->st_atim.tv_nsec = prstat->st_atim_nsec;
+   stbuf->st_atime = prstat->st_atim_sec;
    stbuf->st_mtime = prstat->st_mtim_sec;
-   stbuf->st_mtim.tv_nsec = prstat->st_mtim_nsec;
    stbuf->st_ctime = prstat->st_ctim_sec;
+#ifdef CONFIG_DARWIN
+   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_nsec = prstat->st_atim_nsec;
+   stbuf->st_mtim.tv_nsec = prstat->st_mtim_nsec;
    stbuf->st_ctim.tv_nsec = prstat->st_ctim_nsec;
+#endif
 }
 
 /*
diff --git a/hw/9pfs/9p-synth.c b/hw/9pfs/9p-synth.c
index b38088e066..4a4a776d06 100644
--- a/hw/9pfs/9p-synth.c
+++ b/hw/9pfs/9p-synth.c
@@ -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;
 }
 
diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c
index 9c63e14b28..1563d7b7c6 100644
--- a/hw/9pfs/9p.c
+++ b/hw/9pfs/9p.c
@@ -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,
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH v3 04/11] 9p: darwin: Handle struct dirent differences
  2022-01-28  0:56 [PATCH v3 00/11] This is a followup to https://lists.gnu.org/archive/html/qemu-devel/2021-11/msg04325.html, Will Cohen
                   ` (2 preceding siblings ...)
  2022-01-28  0:56 ` [PATCH v3 03/11] 9p: darwin: Handle struct stat(fs) differences Will Cohen
@ 2022-01-28  0:56 ` Will Cohen
  2022-02-02 15:07   ` Will Cohen
  2022-01-28  0:56 ` [PATCH v3 05/11] 9p: darwin: Ignore O_{NOATIME, DIRECT} Will Cohen
                   ` (6 subsequent siblings)
  10 siblings, 1 reply; 22+ messages in thread
From: Will Cohen @ 2022-01-28  0:56 UTC (permalink / raw)
  To: qemu-devel
  Cc: Laurent Vivier, Thomas Huth, Christian Schoenebeck, Greg Kurz,
	hi, Michael Roitzsch, Will Cohen, Fabian Franz, Paolo Bonzini,
	Keno Fischer

From: Keno Fischer <keno@juliacomputing.com>

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.

Signed-off-by: Keno Fischer <keno@juliacomputing.com>
[Michael Roitzsch: - Rebase for NixOS]
Signed-off-by: Michael Roitzsch <reactorcontrol@icloud.com>
[Will Cohen: - Adjust to pass testing]
Signed-off-by: Will Cohen <wwcohen@gmail.com>
Signed-off-by: Fabian Franz <github@fabian-franz.de>
---
 hw/9pfs/9p-synth.c |  2 ++
 hw/9pfs/9p.c       | 33 +++++++++++++++++++++++++++++++--
 hw/9pfs/codir.c    |  4 ++++
 3 files changed, 37 insertions(+), 2 deletions(-)

diff --git a/hw/9pfs/9p-synth.c b/hw/9pfs/9p-synth.c
index 4a4a776d06..09b9c25288 100644
--- a/hw/9pfs/9p-synth.c
+++ b/hw/9pfs/9p-synth.c
@@ -222,7 +222,9 @@ static void synth_direntry(V9fsSynthNode *node,
 {
     strcpy(entry->d_name, node->name);
     entry->d_ino = node->attr->inode;
+#ifndef CONFIG_DARWIN
     entry->d_off = off + 1;
+#endif
 }
 
 static struct dirent *synth_get_dentry(V9fsSynthNode *dir,
diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c
index 1563d7b7c6..7851f85f8f 100644
--- a/hw/9pfs/9p.c
+++ b/hw/9pfs/9p.c
@@ -2218,6 +2218,25 @@ static int v9fs_xattr_read(V9fsState *s, V9fsPDU *pdu, V9fsFidState *fidp,
     return offset;
 }
 
+/**
+ * Get the seek offset of a dirent. If not available from the structure itself,
+ * obtain it by calling telldir.
+ */
+static int v9fs_dent_telldir(V9fsPDU *pdu, V9fsFidState *fidp,
+                             struct dirent *dent)
+{
+#ifdef CONFIG_DARWIN
+    /*
+     * 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 use telldir for correctness.
+     */
+    return v9fs_co_telldir(pdu, fidp);
+#else
+    return dent->d_off;
+#endif
+}
+
 static int coroutine_fn v9fs_do_readdir_with_stat(V9fsPDU *pdu,
                                                   V9fsFidState *fidp,
                                                   uint32_t max_count)
@@ -2281,7 +2300,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 = v9fs_dent_telldir(pdu, fidp, dent);
+        if (saved_dir_pos < 0) {
+            err = saved_dir_pos;
+            break;
+        }
     }
 
     v9fs_readdir_unlock(&fidp->fs.dir);
@@ -2420,6 +2443,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 +2504,17 @@ static int coroutine_fn v9fs_do_readdir(V9fsPDU *pdu, V9fsFidState *fidp,
             qid.version = 0;
         }
 
+        off = v9fs_dent_telldir(pdu, fidp, 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);
diff --git a/hw/9pfs/codir.c b/hw/9pfs/codir.c
index 032cce04c4..c1b5694f3f 100644
--- a/hw/9pfs/codir.c
+++ b/hw/9pfs/codir.c
@@ -167,7 +167,11 @@ static int do_readdir_many(V9fsPDU *pdu, V9fsFidState *fidp,
         }
 
         size += len;
+#ifdef CONFIG_DARWIN
+        saved_dir_pos = s->ops->telldir(&s->ctx, &fidp->fs);
+#else
         saved_dir_pos = dent->d_off;
+#endif
     }
 
     /* restore (last) saved position */
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH v3 05/11] 9p: darwin: Ignore O_{NOATIME, DIRECT}
  2022-01-28  0:56 [PATCH v3 00/11] This is a followup to https://lists.gnu.org/archive/html/qemu-devel/2021-11/msg04325.html, Will Cohen
                   ` (3 preceding siblings ...)
  2022-01-28  0:56 ` [PATCH v3 04/11] 9p: darwin: Handle struct dirent differences Will Cohen
@ 2022-01-28  0:56 ` Will Cohen
  2022-01-28  0:56 ` [PATCH v3 06/11] 9p: darwin: Compatibility defn for XATTR_SIZE_MAX Will Cohen
                   ` (5 subsequent siblings)
  10 siblings, 0 replies; 22+ messages in thread
From: Will Cohen @ 2022-01-28  0:56 UTC (permalink / raw)
  To: qemu-devel
  Cc: Laurent Vivier, Thomas Huth, Christian Schoenebeck, Greg Kurz,
	hi, Michael Roitzsch, Will Cohen, Paolo Bonzini, Keno Fischer

From: Keno Fischer <keno@juliacomputing.com>

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.

Signed-off-by: Keno Fischer <keno@juliacomputing.com>
[Michael Roitzsch: - Rebase for NixOS]
Signed-off-by: Michael Roitzsch <reactorcontrol@icloud.com>
[Will Cohen: - Adjust coding style]
Signed-off-by: Will Cohen <wwcohen@gmail.com>
---
 hw/9pfs/9p-util.h |  2 ++
 hw/9pfs/9p.c      | 13 ++++++++++++-
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/hw/9pfs/9p-util.h b/hw/9pfs/9p-util.h
index 546f46dc7d..627baebaba 100644
--- a/hw/9pfs/9p-util.h
+++ b/hw/9pfs/9p-util.h
@@ -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;
     }
 
diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c
index 7851f85f8f..9b0c057e9c 100644
--- a/hw/9pfs/9p.c
+++ b/hw/9pfs/9p.c
@@ -137,11 +137,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 },
     };
 
@@ -170,10 +179,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;
 }
 
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH v3 06/11] 9p: darwin: Compatibility defn for XATTR_SIZE_MAX
  2022-01-28  0:56 [PATCH v3 00/11] This is a followup to https://lists.gnu.org/archive/html/qemu-devel/2021-11/msg04325.html, Will Cohen
                   ` (4 preceding siblings ...)
  2022-01-28  0:56 ` [PATCH v3 05/11] 9p: darwin: Ignore O_{NOATIME, DIRECT} Will Cohen
@ 2022-01-28  0:56 ` Will Cohen
  2022-01-28 16:02   ` Christian Schoenebeck
  2022-01-28  0:56 ` [PATCH v3 07/11] 9p: darwin: *xattr_nofollow implementations Will Cohen
                   ` (4 subsequent siblings)
  10 siblings, 1 reply; 22+ messages in thread
From: Will Cohen @ 2022-01-28  0:56 UTC (permalink / raw)
  To: qemu-devel
  Cc: Laurent Vivier, Thomas Huth, Christian Schoenebeck, Greg Kurz,
	hi, Michael Roitzsch, Will Cohen, Paolo Bonzini, Keno Fischer

From: Keno Fischer <keno@juliacomputing.com>

Signed-off-by: Keno Fischer <keno@juliacomputing.com>
Signed-off-by: Michael Roitzsch <reactorcontrol@icloud.com>
[Will Cohen: - Adjust coding style
             - Lower XATTR_SIZE_MAX to 64k]
Signed-off-by: Will Cohen <wwcohen@gmail.com>
---
 hw/9pfs/9p.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c
index 9b0c057e9c..611ac14c4c 100644
--- a/hw/9pfs/9p.c
+++ b/hw/9pfs/9p.c
@@ -3943,6 +3943,13 @@ out_nofid:
     v9fs_string_free(&name);
 }
 
+#if defined(CONFIG_DARWIN) && !defined(XATTR_SIZE_MAX)
+/*
+ * Darwin doesn't seem to define a maximum xattr size in its user
+ * space header, so manually configure it as 64k.
+ */
+#define XATTR_SIZE_MAX 65536
+#endif
 static void coroutine_fn v9fs_xattrcreate(void *opaque)
 {
     int flags, rflags = 0;
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH v3 07/11] 9p: darwin: *xattr_nofollow implementations
  2022-01-28  0:56 [PATCH v3 00/11] This is a followup to https://lists.gnu.org/archive/html/qemu-devel/2021-11/msg04325.html, Will Cohen
                   ` (5 preceding siblings ...)
  2022-01-28  0:56 ` [PATCH v3 06/11] 9p: darwin: Compatibility defn for XATTR_SIZE_MAX Will Cohen
@ 2022-01-28  0:56 ` Will Cohen
  2022-01-28  0:56 ` [PATCH v3 08/11] 9p: darwin: Compatibility for f/l*xattr Will Cohen
                   ` (3 subsequent siblings)
  10 siblings, 0 replies; 22+ messages in thread
From: Will Cohen @ 2022-01-28  0:56 UTC (permalink / raw)
  To: qemu-devel
  Cc: Laurent Vivier, Thomas Huth, Christian Schoenebeck, Greg Kurz,
	hi, Michael Roitzsch, Will Cohen, Paolo Bonzini, Keno Fischer

From: Keno Fischer <keno@juliacomputing.com>

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.

Signed-off-by: Keno Fischer <keno@juliacomputing.com>
[Michael Roitzsch: - Rebase for NixOS]
Signed-off-by: Michael Roitzsch <reactorcontrol@icloud.com>
Signed-off-by: Will Cohen <wwcohen@gmail.com>
---
 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

diff --git a/hw/9pfs/9p-util-darwin.c b/hw/9pfs/9p-util-darwin.c
new file mode 100644
index 0000000000..cdb4c9e24c
--- /dev/null
+++ b/hw/9pfs/9p-util-darwin.c
@@ -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;
+}
diff --git a/hw/9pfs/meson.build b/hw/9pfs/meson.build
index 1b28e70040..12443b6ad5 100644
--- a/hw/9pfs/meson.build
+++ b/hw/9pfs/meson.build
@@ -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)
 
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH v3 08/11] 9p: darwin: Compatibility for f/l*xattr
  2022-01-28  0:56 [PATCH v3 00/11] This is a followup to https://lists.gnu.org/archive/html/qemu-devel/2021-11/msg04325.html, Will Cohen
                   ` (6 preceding siblings ...)
  2022-01-28  0:56 ` [PATCH v3 07/11] 9p: darwin: *xattr_nofollow implementations Will Cohen
@ 2022-01-28  0:56 ` Will Cohen
  2022-01-28  0:56 ` [PATCH v3 09/11] 9p: darwin: Implement compatibility for mknodat Will Cohen
                   ` (2 subsequent siblings)
  10 siblings, 0 replies; 22+ messages in thread
From: Will Cohen @ 2022-01-28  0:56 UTC (permalink / raw)
  To: qemu-devel
  Cc: Laurent Vivier, Thomas Huth, Christian Schoenebeck, Greg Kurz,
	hi, Michael Roitzsch, Will Cohen, Paolo Bonzini, Keno Fischer

From: Keno Fischer <keno@juliacomputing.com>

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.

Signed-off-by: Keno Fischer <keno@juliacomputing.com>
[Michael Roitzsch: - Rebase for NixOS]
Signed-off-by: Michael Roitzsch <reactorcontrol@icloud.com>
Signed-off-by: Will Cohen <wwcohen@gmail.com>
---
 hw/9pfs/9p-local.c | 12 ++++++++----
 hw/9pfs/9p-util.h  | 17 +++++++++++++++++
 2 files changed, 25 insertions(+), 4 deletions(-)

diff --git a/hw/9pfs/9p-local.c b/hw/9pfs/9p-local.c
index 1a5e3eed73..2bfff79b12 100644
--- a/hw/9pfs/9p-local.c
+++ b/hw/9pfs/9p-local.c
@@ -781,16 +781,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) {
diff --git a/hw/9pfs/9p-util.h b/hw/9pfs/9p-util.h
index 627baebaba..38ef8b289d 100644
--- a/hw/9pfs/9p-util.h
+++ b/hw/9pfs/9p-util.h
@@ -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;
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH v3 09/11] 9p: darwin: Implement compatibility for mknodat
  2022-01-28  0:56 [PATCH v3 00/11] This is a followup to https://lists.gnu.org/archive/html/qemu-devel/2021-11/msg04325.html, Will Cohen
                   ` (7 preceding siblings ...)
  2022-01-28  0:56 ` [PATCH v3 08/11] 9p: darwin: Compatibility for f/l*xattr Will Cohen
@ 2022-01-28  0:56 ` Will Cohen
  2022-01-28  0:56 ` [PATCH v3 10/11] 9p: darwin: meson: Allow VirtFS on Darwin Will Cohen
  2022-01-28  0:56 ` [PATCH v3 11/11] 9p: darwin: adjust assumption on virtio-9p-test Will Cohen
  10 siblings, 0 replies; 22+ messages in thread
From: Will Cohen @ 2022-01-28  0:56 UTC (permalink / raw)
  To: qemu-devel
  Cc: Laurent Vivier, Thomas Huth, Christian Schoenebeck, Greg Kurz,
	hi, Michael Roitzsch, Will Cohen, Paolo Bonzini, Keno Fischer

From: Keno Fischer <keno@juliacomputing.com>

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 as an (unexposed in the
C library) system call that sets the cwd for the current thread only.
This should suffice to use mknod safely.

Signed-off-by: Keno Fischer <keno@juliacomputing.com>
Signed-off-by: Michael Roitzsch <reactorcontrol@icloud.com>
[Will Cohen: - Adjust coding style
             - Replace clang references with gcc]
Signed-off-by: Will Cohen <wwcohen@gmail.com>
---
 hw/9pfs/9p-local.c       |  5 +++--
 hw/9pfs/9p-util-darwin.c | 33 +++++++++++++++++++++++++++++++++
 hw/9pfs/9p-util-linux.c  |  5 +++++
 hw/9pfs/9p-util.h        |  2 ++
 4 files changed, 43 insertions(+), 2 deletions(-)

diff --git a/hw/9pfs/9p-local.c b/hw/9pfs/9p-local.c
index 2bfff79b12..3a8bdf05d5 100644
--- a/hw/9pfs/9p-local.c
+++ b/hw/9pfs/9p-local.c
@@ -673,7 +673,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;
         }
@@ -688,7 +688,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;
         }
@@ -701,6 +701,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;
diff --git a/hw/9pfs/9p-util-darwin.c b/hw/9pfs/9p-util-darwin.c
index cdb4c9e24c..62a88ce4f9 100644
--- a/hw/9pfs/9p-util-darwin.c
+++ b/hw/9pfs/9p-util-darwin.c
@@ -62,3 +62,36 @@ int fsetxattrat_nofollow(int dirfd, const char *filename, const char *name,
     close_preserve_errno(fd);
     return ret;
 }
+
+#ifndef SYS___pthread_fchdir
+# define SYS___pthread_fchdir 349
+#endif
+
+/*
+ * This is an undocumented OS X syscall. It would be best to avoid it,
+ * but there doesn't seem to be another safe way to implement mknodat.
+ * Dear Apple, please implement mknodat before you remove this syscall.
+ */
+static int fchdir_thread_local(int fd)
+{
+#pragma gcc diagnostic push
+#pragma gcc diagnostic ignored "-Wdeprecated-declarations"
+    return syscall(SYS___pthread_fchdir, fd);
+#pragma gcc diagnostic pop
+}
+
+int qemu_mknodat(int dirfd, const char *filename, mode_t mode, dev_t dev)
+{
+    int preserved_errno, err;
+    if (fchdir_thread_local(dirfd) < 0) {
+        return -1;
+    }
+    err = mknod(filename, mode, dev);
+    preserved_errno = errno;
+    /* Stop using the thread-local cwd */
+    fchdir_thread_local(-1);
+    if (err < 0) {
+        errno = preserved_errno;
+    }
+    return err;
+}
diff --git a/hw/9pfs/9p-util-linux.c b/hw/9pfs/9p-util-linux.c
index 398614a5d0..66e0ab1865 100644
--- a/hw/9pfs/9p-util-linux.c
+++ b/hw/9pfs/9p-util-linux.c
@@ -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);
+}
diff --git a/hw/9pfs/9p-util.h b/hw/9pfs/9p-util.h
index 38ef8b289d..bff9b3022c 100644
--- a/hw/9pfs/9p-util.h
+++ b/hw/9pfs/9p-util.h
@@ -97,4 +97,6 @@ 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
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH v3 10/11] 9p: darwin: meson: Allow VirtFS on Darwin
  2022-01-28  0:56 [PATCH v3 00/11] This is a followup to https://lists.gnu.org/archive/html/qemu-devel/2021-11/msg04325.html, Will Cohen
                   ` (8 preceding siblings ...)
  2022-01-28  0:56 ` [PATCH v3 09/11] 9p: darwin: Implement compatibility for mknodat Will Cohen
@ 2022-01-28  0:56 ` Will Cohen
  2022-01-28  0:56 ` [PATCH v3 11/11] 9p: darwin: adjust assumption on virtio-9p-test Will Cohen
  10 siblings, 0 replies; 22+ messages in thread
From: Will Cohen @ 2022-01-28  0:56 UTC (permalink / raw)
  To: qemu-devel
  Cc: Laurent Vivier, Thomas Huth, Christian Schoenebeck, Greg Kurz,
	hi, Michael Roitzsch, Will Cohen, Paolo Bonzini, Keno Fischer

From: Keno Fischer <keno@juliacomputing.com>

Signed-off-by: Keno Fischer <keno@juliacomputing.com>
[Michael Roitzsch: - Rebase for NixOS]
Signed-off-by: Michael Roitzsch <reactorcontrol@icloud.com>
[Will Cohen: - Rebase to master]
Signed-off-by: Will Cohen <wwcohen@gmail.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
---
 fsdev/meson.build |  1 +
 meson.build       | 12 ++++++++----
 2 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/fsdev/meson.build b/fsdev/meson.build
index adf57cc43e..b632b66348 100644
--- a/fsdev/meson.build
+++ b/fsdev/meson.build
@@ -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',
diff --git a/meson.build b/meson.build
index e0cfafe8d9..726c618982 100644
--- a/meson.build
+++ b/meson.build
@@ -1420,17 +1420,21 @@ if not get_option('dbus_display').disabled()
   endif
 endif
 
-have_virtfs = (targetos == 'linux' and
+if targetos == 'darwin'
+  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 not libcap_ng.found() or not libattr.found()
       error('virtio-9p (virtfs) requires libcap-ng-devel and libattr-devel')
     elif not have_system
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH v3 11/11] 9p: darwin: adjust assumption on virtio-9p-test
  2022-01-28  0:56 [PATCH v3 00/11] This is a followup to https://lists.gnu.org/archive/html/qemu-devel/2021-11/msg04325.html, Will Cohen
                   ` (9 preceding siblings ...)
  2022-01-28  0:56 ` [PATCH v3 10/11] 9p: darwin: meson: Allow VirtFS on Darwin Will Cohen
@ 2022-01-28  0:56 ` Will Cohen
  2022-01-28  7:03   ` Thomas Huth
  10 siblings, 1 reply; 22+ messages in thread
From: Will Cohen @ 2022-01-28  0:56 UTC (permalink / raw)
  To: qemu-devel
  Cc: Laurent Vivier, Thomas Huth, Christian Schoenebeck, Greg Kurz,
	hi, Will Cohen, Fabian Franz, Paolo Bonzini

Signed-off-by: Fabian Franz <github@fabian-franz.de>
Signed-off-by: Will Cohen <wwcohen@gmail.com>
---
 tests/qtest/virtio-9p-test.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tests/qtest/virtio-9p-test.c b/tests/qtest/virtio-9p-test.c
index 41fed41de1..6bcf89f0f8 100644
--- a/tests/qtest/virtio-9p-test.c
+++ b/tests/qtest/virtio-9p-test.c
@@ -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);
 
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 22+ messages in thread

* Re: [PATCH v3 11/11] 9p: darwin: adjust assumption on virtio-9p-test
  2022-01-28  0:56 ` [PATCH v3 11/11] 9p: darwin: adjust assumption on virtio-9p-test Will Cohen
@ 2022-01-28  7:03   ` Thomas Huth
  2022-01-28 13:38     ` Will Cohen
  0 siblings, 1 reply; 22+ messages in thread
From: Thomas Huth @ 2022-01-28  7:03 UTC (permalink / raw)
  To: Will Cohen, qemu-devel
  Cc: Laurent Vivier, Christian Schoenebeck, Greg Kurz, hi,
	Fabian Franz, Paolo Bonzini


-EMISSINGPATCHDESCRIPTION

Please avoid sending patches without patch description. E.g. explain here 
*why* this needs to be adjusted.

  Thanks,
   Thomas


On 28/01/2022 01.56, Will Cohen wrote:
> Signed-off-by: Fabian Franz <github@fabian-franz.de>
> Signed-off-by: Will Cohen <wwcohen@gmail.com>
> ---
>   tests/qtest/virtio-9p-test.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/tests/qtest/virtio-9p-test.c b/tests/qtest/virtio-9p-test.c
> index 41fed41de1..6bcf89f0f8 100644
> --- a/tests/qtest/virtio-9p-test.c
> +++ b/tests/qtest/virtio-9p-test.c
> @@ -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);
>   



^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH v3 11/11] 9p: darwin: adjust assumption on virtio-9p-test
  2022-01-28  7:03   ` Thomas Huth
@ 2022-01-28 13:38     ` Will Cohen
  2022-01-28 15:28       ` Christian Schoenebeck
  0 siblings, 1 reply; 22+ messages in thread
From: Will Cohen @ 2022-01-28 13:38 UTC (permalink / raw)
  To: Thomas Huth
  Cc: Laurent Vivier, Christian Schoenebeck, qemu-devel, Greg Kurz, hi,
	Paolo Bonzini

[-- Attachment #1: Type: text/plain, Size: 1436 bytes --]

Apologies! The explanation (and what I'll include in v4) is below:

The 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.

On Fri, Jan 28, 2022 at 2:04 AM Thomas Huth <thuth@redhat.com> wrote:

>
> -EMISSINGPATCHDESCRIPTION
>
> Please avoid sending patches without patch description. E.g. explain here
> *why* this needs to be adjusted.
>
>   Thanks,
>    Thomas
>
>
> On 28/01/2022 01.56, Will Cohen wrote:
> > Signed-off-by: Fabian Franz <github@fabian-franz.de>
> > Signed-off-by: Will Cohen <wwcohen@gmail.com>
> > ---
> >   tests/qtest/virtio-9p-test.c | 2 +-
> >   1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/tests/qtest/virtio-9p-test.c b/tests/qtest/virtio-9p-test.c
> > index 41fed41de1..6bcf89f0f8 100644
> > --- a/tests/qtest/virtio-9p-test.c
> > +++ b/tests/qtest/virtio-9p-test.c
> > @@ -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);
> >
>
>

[-- Attachment #2: Type: text/html, Size: 2132 bytes --]

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH v3 11/11] 9p: darwin: adjust assumption on virtio-9p-test
  2022-01-28 13:38     ` Will Cohen
@ 2022-01-28 15:28       ` Christian Schoenebeck
  0 siblings, 0 replies; 22+ messages in thread
From: Christian Schoenebeck @ 2022-01-28 15:28 UTC (permalink / raw)
  To: qemu-devel
  Cc: Will Cohen, Thomas Huth, Laurent Vivier, Greg Kurz, hi, Paolo Bonzini

On Freitag, 28. Januar 2022 14:38:43 CET Will Cohen wrote:
> Apologies! The explanation (and what I'll include in v4) is below:
> 
> The 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.

Additionally describing the observed misbehaviour is always useful.

Best regards,
Christian Schoenebeck




^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH v3 01/11] 9p: linux: Fix a couple Linux assumptions
  2022-01-28  0:56 ` [PATCH v3 01/11] 9p: linux: Fix a couple Linux assumptions Will Cohen
@ 2022-01-28 15:52   ` Greg Kurz
  0 siblings, 0 replies; 22+ messages in thread
From: Greg Kurz @ 2022-01-28 15:52 UTC (permalink / raw)
  To: Will Cohen
  Cc: Laurent Vivier, Thomas Huth, Christian Schoenebeck, qemu-devel,
	hi, Michael Roitzsch, Paolo Bonzini, Keno Fischer, Keno Fischer

On Thu, 27 Jan 2022 19:56:01 -0500
Will Cohen <wwcohen@gmail.com> wrote:

> From: Keno Fischer <keno@alumni.harvard.edu>
> 
>  - 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).
> 
> Signed-off-by: Keno Fischer <keno@juliacomputing.com>
> [Michael Roitzsch: - Rebase for NixOS]
> Signed-off-by: Michael Roitzsch <reactorcontrol@icloud.com>
> [Will Cohen: - Fix headers for Alpine
>              - Integrate statfs.h back into file-op-9p.h]
> Signed-off-by: Will Cohen <wwcohen@gmail.com>
> ---
>  fsdev/file-op-9p.h   | 15 ++++++++++++++-
>  hw/9pfs/9p-local.c   |  2 ++
>  hw/9pfs/9p.c         |  4 ++++
>  include/qemu/xattr.h |  4 +++-

fsdev/virtfs-proxy-helper.c would need similar fixing in theory
but patch 10 disables the build for non-linux. Maybe just mention
it in the changelog so that people know this is deliberate.

Apart from that, LGTM.

>  4 files changed, 23 insertions(+), 2 deletions(-)
> 
> diff --git a/fsdev/file-op-9p.h b/fsdev/file-op-9p.h
> index 8fd89f0447..616c6f503f 100644
> --- a/fsdev/file-op-9p.h
> +++ b/fsdev/file-op-9p.h
> @@ -16,10 +16,23 @@
>  
>  #include <dirent.h>
>  #include <utime.h>
> -#include <sys/vfs.h>
>  #include "qemu-fsdev-throttle.h"
>  #include "p9array.h"
>  
> +#ifndef QEMU_STATFS_H
> +#define QEMU_STATFS_H
> +

Include guards from the old header file don't make sense
anymore here. You should drop them.

> +#ifdef CONFIG_LINUX
> +# include <sys/vfs.h>
> +#endif
> +#ifdef CONFIG_DARWIN
> +# include <sys/param.h>
> +# include <sys/mount.h>
> +#endif
> +
> +#endif
> +
> +
>  #define SM_LOCAL_MODE_BITS    0600
>  #define SM_LOCAL_DIR_MODE_BITS    0700
>  
> diff --git a/hw/9pfs/9p-local.c b/hw/9pfs/9p-local.c
> index 210d9e7705..1a5e3eed73 100644
> --- a/hw/9pfs/9p-local.c
> +++ b/hw/9pfs/9p-local.c
> @@ -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
> diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c
> index 15b3f4d385..9c63e14b28 100644
> --- a/hw/9pfs/9p.c
> +++ b/hw/9pfs/9p.c
> @@ -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;
> diff --git a/include/qemu/xattr.h b/include/qemu/xattr.h
> index a83fe8e749..f1d0f7be74 100644
> --- a/include/qemu/xattr.h
> +++ b/include/qemu/xattr.h
> @@ -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
>  



^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH v3 06/11] 9p: darwin: Compatibility defn for XATTR_SIZE_MAX
  2022-01-28  0:56 ` [PATCH v3 06/11] 9p: darwin: Compatibility defn for XATTR_SIZE_MAX Will Cohen
@ 2022-01-28 16:02   ` Christian Schoenebeck
  0 siblings, 0 replies; 22+ messages in thread
From: Christian Schoenebeck @ 2022-01-28 16:02 UTC (permalink / raw)
  To: qemu-devel
  Cc: Will Cohen, Laurent Vivier, Thomas Huth, Greg Kurz, hi,
	Michael Roitzsch, Paolo Bonzini, Keno Fischer

On Freitag, 28. Januar 2022 01:56:06 CET Will Cohen wrote:
> From: Keno Fischer <keno@juliacomputing.com>
> 
> Signed-off-by: Keno Fischer <keno@juliacomputing.com>
> Signed-off-by: Michael Roitzsch <reactorcontrol@icloud.com>
> [Will Cohen: - Adjust coding style
>              - Lower XATTR_SIZE_MAX to 64k]
> Signed-off-by: Will Cohen <wwcohen@gmail.com>
> ---
>  hw/9pfs/9p.c | 7 +++++++
>  1 file changed, 7 insertions(+)
> 
> diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c
> index 9b0c057e9c..611ac14c4c 100644
> --- a/hw/9pfs/9p.c
> +++ b/hw/9pfs/9p.c
> @@ -3943,6 +3943,13 @@ out_nofid:
>      v9fs_string_free(&name);
>  }
> 
> +#if defined(CONFIG_DARWIN) && !defined(XATTR_SIZE_MAX)
> +/*
> + * Darwin doesn't seem to define a maximum xattr size in its user
> + * space header, so manually configure it as 64k.
> + */
> +#define XATTR_SIZE_MAX 65536
> +#endif

Yes, but that's not explaining the reason why this is set to 64k. The reason 
is that this a preliminary solution which reflects the limit of Linux guests 
for now, as we don't support macOS guests yet, and not limiting this at all 
would have lead to QEMU crashing on huge g_malloc() calls.

>  static void coroutine_fn v9fs_xattrcreate(void *opaque)
>  {
>      int flags, rflags = 0;





^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH v3 02/11] 9p: Rename 9p-util -> 9p-util-linux
  2022-01-28  0:56 ` [PATCH v3 02/11] 9p: Rename 9p-util -> 9p-util-linux Will Cohen
@ 2022-01-28 16:27   ` Greg Kurz
  0 siblings, 0 replies; 22+ messages in thread
From: Greg Kurz @ 2022-01-28 16:27 UTC (permalink / raw)
  To: Will Cohen
  Cc: Laurent Vivier, Thomas Huth, Christian Schoenebeck, qemu-devel,
	hi, Michael Roitzsch, Paolo Bonzini, Keno Fischer

On Thu, 27 Jan 2022 19:56:02 -0500
Will Cohen <wwcohen@gmail.com> wrote:

> From: Keno Fischer <keno@juliacomputing.com>
> 
> 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.
> 
> Signed-off-by: Keno Fischer <keno@juliacomputing.com>
> [Michael Roitzsch: - Rebase for NixOS]
> Signed-off-by: Michael Roitzsch <reactorcontrol@icloud.com>
> Signed-off-by: Will Cohen <wwcohen@gmail.com>
> ---

Reviewed-by: Greg Kurz <groug@kaod.org>

>  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%)
> 
> diff --git a/hw/9pfs/9p-util.c b/hw/9pfs/9p-util-linux.c
> similarity index 97%
> rename from hw/9pfs/9p-util.c
> rename to hw/9pfs/9p-util-linux.c
> index 3221d9b498..398614a5d0 100644
> --- a/hw/9pfs/9p-util.c
> +++ b/hw/9pfs/9p-util-linux.c
> @@ -1,5 +1,5 @@
>  /*
> - * 9p utilities
> + * 9p utilities (Linux Implementation)
>   *
>   * Copyright IBM, Corp. 2017
>   *
> diff --git a/hw/9pfs/meson.build b/hw/9pfs/meson.build
> index 99be5d9119..1b28e70040 100644
> --- a/hw/9pfs/meson.build
> +++ b/hw/9pfs/meson.build
> @@ -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)
>  



^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH v3 04/11] 9p: darwin: Handle struct dirent differences
  2022-01-28  0:56 ` [PATCH v3 04/11] 9p: darwin: Handle struct dirent differences Will Cohen
@ 2022-02-02 15:07   ` Will Cohen
  2022-02-02 17:37     ` Christian Schoenebeck
  0 siblings, 1 reply; 22+ messages in thread
From: Will Cohen @ 2022-02-02 15:07 UTC (permalink / raw)
  To: qemu-devel
  Cc: Laurent Vivier, Thomas Huth, Christian Schoenebeck, Greg Kurz,
	hi, Michael Roitzsch, Paolo Bonzini, Keno Fischer

[-- Attachment #1: Type: text/plain, Size: 4674 bytes --]

Does the version proposed in v3 address the V9fsFidState issues? In 9p.c
for v2 to v3, we propose

-    return telldir(fidp->fs.dir.stream);
+    return v9fs_co_telldir(pdu, fidp);

and in codir.c from v2 to v3 we propose
-        saved_dir_pos = telldir(fidp->fs.dir.stream);
+        saved_dir_pos = s->ops->telldir(&s->ctx, &fidp->fs);

This removes the direct access to fidp->, and we hope this should be
sufficient to avoid the concurrency
and undefined behaviors you noted in the v2 review.


On Thu, Jan 27, 2022 at 7:56 PM Will Cohen <wwcohen@gmail.com> wrote:

> From: Keno Fischer <keno@juliacomputing.com>
>
> 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.
>
> Signed-off-by: Keno Fischer <keno@juliacomputing.com>
> [Michael Roitzsch: - Rebase for NixOS]
> Signed-off-by: Michael Roitzsch <reactorcontrol@icloud.com>
> [Will Cohen: - Adjust to pass testing]
> Signed-off-by: Will Cohen <wwcohen@gmail.com>
> Signed-off-by: Fabian Franz <github@fabian-franz.de>
> ---
>  hw/9pfs/9p-synth.c |  2 ++
>  hw/9pfs/9p.c       | 33 +++++++++++++++++++++++++++++++--
>  hw/9pfs/codir.c    |  4 ++++
>  3 files changed, 37 insertions(+), 2 deletions(-)
>
> diff --git a/hw/9pfs/9p-synth.c b/hw/9pfs/9p-synth.c
> index 4a4a776d06..09b9c25288 100644
> --- a/hw/9pfs/9p-synth.c
> +++ b/hw/9pfs/9p-synth.c
> @@ -222,7 +222,9 @@ static void synth_direntry(V9fsSynthNode *node,
>  {
>      strcpy(entry->d_name, node->name);
>      entry->d_ino = node->attr->inode;
> +#ifndef CONFIG_DARWIN
>      entry->d_off = off + 1;
> +#endif
>  }
>
>  static struct dirent *synth_get_dentry(V9fsSynthNode *dir,
> diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c
> index 1563d7b7c6..7851f85f8f 100644
> --- a/hw/9pfs/9p.c
> +++ b/hw/9pfs/9p.c
> @@ -2218,6 +2218,25 @@ static int v9fs_xattr_read(V9fsState *s, V9fsPDU
> *pdu, V9fsFidState *fidp,
>      return offset;
>  }
>
> +/**
> + * Get the seek offset of a dirent. If not available from the structure
> itself,
> + * obtain it by calling telldir.
> + */
> +static int v9fs_dent_telldir(V9fsPDU *pdu, V9fsFidState *fidp,
> +                             struct dirent *dent)
> +{
> +#ifdef CONFIG_DARWIN
> +    /*
> +     * 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 use telldir for correctness.
> +     */
> +    return v9fs_co_telldir(pdu, fidp);
> +#else
> +    return dent->d_off;
> +#endif
> +}
> +
>  static int coroutine_fn v9fs_do_readdir_with_stat(V9fsPDU *pdu,
>                                                    V9fsFidState *fidp,
>                                                    uint32_t max_count)
> @@ -2281,7 +2300,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 = v9fs_dent_telldir(pdu, fidp, dent);
> +        if (saved_dir_pos < 0) {
> +            err = saved_dir_pos;
> +            break;
> +        }
>      }
>
>      v9fs_readdir_unlock(&fidp->fs.dir);
> @@ -2420,6 +2443,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 +2504,17 @@ static int coroutine_fn v9fs_do_readdir(V9fsPDU
> *pdu, V9fsFidState *fidp,
>              qid.version = 0;
>          }
>
> +        off = v9fs_dent_telldir(pdu, fidp, 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);
> diff --git a/hw/9pfs/codir.c b/hw/9pfs/codir.c
> index 032cce04c4..c1b5694f3f 100644
> --- a/hw/9pfs/codir.c
> +++ b/hw/9pfs/codir.c
> @@ -167,7 +167,11 @@ static int do_readdir_many(V9fsPDU *pdu, V9fsFidState
> *fidp,
>          }
>
>          size += len;
> +#ifdef CONFIG_DARWIN
> +        saved_dir_pos = s->ops->telldir(&s->ctx, &fidp->fs);
> +#else
>          saved_dir_pos = dent->d_off;
> +#endif
>      }
>
>      /* restore (last) saved position */
> --
> 2.34.1
>
>

[-- Attachment #2: Type: text/html, Size: 6451 bytes --]

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH v3 04/11] 9p: darwin: Handle struct dirent differences
  2022-02-02 15:07   ` Will Cohen
@ 2022-02-02 17:37     ` Christian Schoenebeck
  2022-02-02 18:31       ` Will Cohen
  0 siblings, 1 reply; 22+ messages in thread
From: Christian Schoenebeck @ 2022-02-02 17:37 UTC (permalink / raw)
  To: qemu-devel
  Cc: Will Cohen, Laurent Vivier, Thomas Huth, Greg Kurz, hi,
	Michael Roitzsch, Paolo Bonzini, Keno Fischer

On Mittwoch, 2. Februar 2022 16:07:09 CET Will Cohen wrote:
> Does the version proposed in v3 address the V9fsFidState issues? In 9p.c
> for v2 to v3, we propose
> 
> -    return telldir(fidp->fs.dir.stream);
> +    return v9fs_co_telldir(pdu, fidp);
> 
> and in codir.c from v2 to v3 we propose
> -        saved_dir_pos = telldir(fidp->fs.dir.stream);
> +        saved_dir_pos = s->ops->telldir(&s->ctx, &fidp->fs);
> 
> This removes the direct access to fidp->, and we hope this should be
> sufficient to avoid the concurrency
> and undefined behaviors you noted in the v2 review.

I am not sure why you think that you are no longer accessing fidp, you still 
do, just in a slightly different way.

Let me propose a different solution: on macOS there is 'd_seekoff' in struct 
dirent. As already discussed that dirent field is apparently unused (zero) by 
macOS. So what about filling this dirent field (early, on driver level, not on 
server/controller level [9p.c]) with telldir() for macOS, then you have the 
same info as other systems provide with dirent field 'd_off' later on.

Then you can add an inline helper function or a macro to deal with macOS vs. 
RoW, e.g.:

inline
off_t qemu_dirent_off(struct dirent *dent)
{
#ifdef CONFIG_DARWIN
    return dent->d_seekoff;
#else
    return dent->d_off;
#endif
}

And in 9p.c at all locations where dent->d_off is currently accessed, you 
would just use that helper instead.

Best regards,
Christian Schoenebeck




^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH v3 03/11] 9p: darwin: Handle struct stat(fs) differences
  2022-01-28  0:56 ` [PATCH v3 03/11] 9p: darwin: Handle struct stat(fs) differences Will Cohen
@ 2022-02-02 17:48   ` Christian Schoenebeck
  0 siblings, 0 replies; 22+ messages in thread
From: Christian Schoenebeck @ 2022-02-02 17:48 UTC (permalink / raw)
  To: qemu-devel
  Cc: Will Cohen, Laurent Vivier, Thomas Huth, Greg Kurz, hi,
	Michael Roitzsch, Paolo Bonzini, Keno Fischer

On Freitag, 28. Januar 2022 01:56:03 CET Will Cohen wrote:
> From: Keno Fischer <keno@juliacomputing.com>
> 
> Signed-off-by: Keno Fischer <keno@juliacomputing.com>
> Signed-off-by: Michael Roitzsch <reactorcontrol@icloud.com>
> [Will Cohen: - Note lack of f_namelen and f_frsize on Darwin]
> Signed-off-by: Will Cohen <wwcohen@gmail.com>
> ---
>  hw/9pfs/9p-proxy.c | 18 +++++++++++++++---
>  hw/9pfs/9p-synth.c |  2 ++
>  hw/9pfs/9p.c       | 16 ++++++++++++++--
>  3 files changed, 31 insertions(+), 5 deletions(-)
> 
> diff --git a/hw/9pfs/9p-proxy.c b/hw/9pfs/9p-proxy.c
> index 09bd9f1464..f5aade21b5 100644
> --- a/hw/9pfs/9p-proxy.c
> +++ b/hw/9pfs/9p-proxy.c
> @@ -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,18 @@ 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_atim.tv_sec = prstat->st_atim_sec;

Like already mentioned in v2: please assign some value to
stbuf->st_atim.tv_sec as well, i.e. don't just delete it.

On most systems there is a workaround in place like:

           #define st_atime st_atim.tv_sec      /* Backward compatibility */
           #define st_mtime st_mtim.tv_sec
           #define st_ctime st_ctim.tv_sec

In that case your changes would work, but I would not rely on that.

Best regards,
Christian Schoenebeck

> -   stbuf->st_atim.tv_nsec = prstat->st_atim_nsec;
> +   stbuf->st_atime = prstat->st_atim_sec;
>     stbuf->st_mtime = prstat->st_mtim_sec;
> -   stbuf->st_mtim.tv_nsec = prstat->st_mtim_nsec;
>     stbuf->st_ctime = prstat->st_ctim_sec;
> +#ifdef CONFIG_DARWIN
> +   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_nsec = prstat->st_atim_nsec;
> +   stbuf->st_mtim.tv_nsec = prstat->st_mtim_nsec;
>     stbuf->st_ctim.tv_nsec = prstat->st_ctim_nsec;
> +#endif
>  }
> 
>  /*
> diff --git a/hw/9pfs/9p-synth.c b/hw/9pfs/9p-synth.c
> index b38088e066..4a4a776d06 100644
> --- a/hw/9pfs/9p-synth.c
> +++ b/hw/9pfs/9p-synth.c
> @@ -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;
>  }
> 
> diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c
> index 9c63e14b28..1563d7b7c6 100644
> --- a/hw/9pfs/9p.c
> +++ b/hw/9pfs/9p.c
> @@ -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,




^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH v3 04/11] 9p: darwin: Handle struct dirent differences
  2022-02-02 17:37     ` Christian Schoenebeck
@ 2022-02-02 18:31       ` Will Cohen
  0 siblings, 0 replies; 22+ messages in thread
From: Will Cohen @ 2022-02-02 18:31 UTC (permalink / raw)
  To: Christian Schoenebeck
  Cc: Laurent Vivier, Thomas Huth, qemu-devel, Greg Kurz, hi,
	Michael Roitzsch, Paolo Bonzini, Keno Fischer

[-- Attachment #1: Type: text/plain, Size: 1690 bytes --]

This makes sense! Much appreciated, will revise.

On Wed, Feb 2, 2022 at 12:37 PM Christian Schoenebeck <
qemu_oss@crudebyte.com> wrote:

> On Mittwoch, 2. Februar 2022 16:07:09 CET Will Cohen wrote:
> > Does the version proposed in v3 address the V9fsFidState issues? In 9p.c
> > for v2 to v3, we propose
> >
> > -    return telldir(fidp->fs.dir.stream);
> > +    return v9fs_co_telldir(pdu, fidp);
> >
> > and in codir.c from v2 to v3 we propose
> > -        saved_dir_pos = telldir(fidp->fs.dir.stream);
> > +        saved_dir_pos = s->ops->telldir(&s->ctx, &fidp->fs);
> >
> > This removes the direct access to fidp->, and we hope this should be
> > sufficient to avoid the concurrency
> > and undefined behaviors you noted in the v2 review.
>
> I am not sure why you think that you are no longer accessing fidp, you
> still
> do, just in a slightly different way.
>
> Let me propose a different solution: on macOS there is 'd_seekoff' in
> struct
> dirent. As already discussed that dirent field is apparently unused (zero)
> by
> macOS. So what about filling this dirent field (early, on driver level,
> not on
> server/controller level [9p.c]) with telldir() for macOS, then you have
> the
> same info as other systems provide with dirent field 'd_off' later on.
>
> Then you can add an inline helper function or a macro to deal with macOS
> vs.
> RoW, e.g.:
>
> inline
> off_t qemu_dirent_off(struct dirent *dent)
> {
> #ifdef CONFIG_DARWIN
>     return dent->d_seekoff;
> #else
>     return dent->d_off;
> #endif
> }
>
> And in 9p.c at all locations where dent->d_off is currently accessed, you
> would just use that helper instead.
>
> Best regards,
> Christian Schoenebeck
>
>
>

[-- Attachment #2: Type: text/html, Size: 2220 bytes --]

^ permalink raw reply	[flat|nested] 22+ messages in thread

end of thread, other threads:[~2022-02-02 19:28 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-28  0:56 [PATCH v3 00/11] This is a followup to https://lists.gnu.org/archive/html/qemu-devel/2021-11/msg04325.html, Will Cohen
2022-01-28  0:56 ` [PATCH v3 01/11] 9p: linux: Fix a couple Linux assumptions Will Cohen
2022-01-28 15:52   ` Greg Kurz
2022-01-28  0:56 ` [PATCH v3 02/11] 9p: Rename 9p-util -> 9p-util-linux Will Cohen
2022-01-28 16:27   ` Greg Kurz
2022-01-28  0:56 ` [PATCH v3 03/11] 9p: darwin: Handle struct stat(fs) differences Will Cohen
2022-02-02 17:48   ` Christian Schoenebeck
2022-01-28  0:56 ` [PATCH v3 04/11] 9p: darwin: Handle struct dirent differences Will Cohen
2022-02-02 15:07   ` Will Cohen
2022-02-02 17:37     ` Christian Schoenebeck
2022-02-02 18:31       ` Will Cohen
2022-01-28  0:56 ` [PATCH v3 05/11] 9p: darwin: Ignore O_{NOATIME, DIRECT} Will Cohen
2022-01-28  0:56 ` [PATCH v3 06/11] 9p: darwin: Compatibility defn for XATTR_SIZE_MAX Will Cohen
2022-01-28 16:02   ` Christian Schoenebeck
2022-01-28  0:56 ` [PATCH v3 07/11] 9p: darwin: *xattr_nofollow implementations Will Cohen
2022-01-28  0:56 ` [PATCH v3 08/11] 9p: darwin: Compatibility for f/l*xattr Will Cohen
2022-01-28  0:56 ` [PATCH v3 09/11] 9p: darwin: Implement compatibility for mknodat Will Cohen
2022-01-28  0:56 ` [PATCH v3 10/11] 9p: darwin: meson: Allow VirtFS on Darwin Will Cohen
2022-01-28  0:56 ` [PATCH v3 11/11] 9p: darwin: adjust assumption on virtio-9p-test Will Cohen
2022-01-28  7:03   ` Thomas Huth
2022-01-28 13:38     ` Will Cohen
2022-01-28 15:28       ` Christian Schoenebeck

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.