Skip to contentSkip to conversation

9pfs: macOS host fixes

PATCH Superseded Christian Schoenebeck 4 participants 27 messages Apr 19, 2022 – Apr 21, 2022

v1 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#1 lore raw

PATCH 1/5 9pfs: fix qemu_mknodat(S_IFREG) on macOS

In reply to Christian Schoenebeck

mknod() on macOS does not support creating regular files, so divert to openat_file() if S_IFREG is passed with mode argument.

Furthermore, 'man 2 mknodat' on Linux says: "Zero file type is equivalent to type S_IFREG".

---
 hw/9pfs/9p-util-darwin.c | 4 ++++
 1 file changed, 4 insertions(+)
hw/9pfs/9p-util-darwin.c +4 -0
index bec0253474..53e0625501 100644
@@ -77,6 +77,10 @@ int fsetxattrat_nofollow(int dirfd, const char *filename, const char *name,
 int qemu_mknodat(int dirfd, const char *filename, mode_t mode, dev_t dev)
 {
     int preserved_errno, err;
+
+    if (S_ISREG(mode) || !(mode & S_IFMT)) {
+        return openat_file(dirfd, filename, O_CREAT, mode);
+    }
     if (!pthread_fchdir_np) {
         error_report_once("pthread_fchdir_np() not available on this version of macOS");
         return -ENOTSUP;
Signature · 1 line
2.32.0 (Apple Git-132)
#6 lore raw

PATCH 2/5 9pfs: fix qemu_mknodat(S_IFSOCK) on macOS

In reply to Christian Schoenebeck

mknod() on macOS does not support creating sockets, so divert to call sequence socket(), bind() and chmod() respectively if S_IFSOCK was passed with mode argument.

---
 hw/9pfs/9p-util-darwin.c | 24 +++++++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)
hw/9pfs/9p-util-darwin.c +23 -1
index 53e0625501..252a6fc5dd 100644
@@ -74,6 +74,24 @@ int fsetxattrat_nofollow(int dirfd, const char *filename, const char *name,
  */
 #if defined CONFIG_PTHREAD_FCHDIR_NP
 
+static int create_socket_file_at_cwd(const char *filename, mode_t mode) {
+    int fd, err;
+    struct sockaddr_un addr = {
+        .sun_family = AF_UNIX
+    };
+
+    fd = socket(PF_UNIX, SOCK_DGRAM, 0);
+    if (fd < 0) {
+        return fd;
+    }
+    snprintf(addr.sun_path, sizeof(addr.sun_path), "./%s", filename);
+    err = bind(fd, (struct sockaddr *) &addr, sizeof(addr));
+    if (err < 0) {
+        return err;
+    }
+    return chmod(addr.sun_path, mode);
+}
+
 int qemu_mknodat(int dirfd, const char *filename, mode_t mode, dev_t dev)
 {
     int preserved_errno, err;
@@ -88,7 +106,11 @@ int qemu_mknodat(int dirfd, const char *filename, mode_t mode, dev_t dev)
     if (pthread_fchdir_np(dirfd) < 0) {
         return -1;
     }
-    err = mknod(filename, mode, dev);
+    if (S_ISSOCK(mode)) {
+        err = create_socket_file_at_cwd(filename, mode);
+    } else {
+        err = mknod(filename, mode, dev);
+    }
     preserved_errno = errno;
     /* Stop using the thread-local cwd */
     pthread_fchdir_np(-1);
Signature · 1 line
2.32.0 (Apple Git-132)
#13 lore raw

PATCH 3/5 9pfs: fix wrong encoding of rdev field in Rgetattr on macOS

In reply to Christian Schoenebeck

The 'rdev' field in 9p reponse 'Rgetattr' is of type dev_t, which is actually a system dependant type and therefore both the size and encoding of dev_t differ between macOS and Linux.

So far we have sent 'rdev' to guest in host's dev_t format as-is, which caused devices to appear with wrong device numbers on guests running on macOS hosts, eventually leading to various misbehaviours on guest in conjunction with device files.

This patch fixes this issue by converting the device number from host's dev_t format to Linux dev_t format. As 9p request 'Tgettattr' is exclusive to protocol version 9p2000.L, it should be fair to assume that 'rdev' field is assumed to be in Linux dev_t format by client as well.

---
 hw/9pfs/9p.c | 37 ++++++++++++++++++++++++++++++++++++-
 1 file changed, 36 insertions(+), 1 deletion(-)
hw/9pfs/9p.c +36 -1
index 225f31fc31..d953035e1c 100644
@@ -1318,6 +1318,41 @@ static int32_t stat_to_iounit(const V9fsPDU *pdu, const struct stat *stbuf)
     return blksize_to_iounit(pdu, stbuf->st_blksize);
 }
 
+#if !defined(CONFIG_LINUX)
+
+/*
+ * Generates a Linux device number (a.k.a. dev_t) for given device major
+ * and minor numbers.
+ */
+static uint64_t makedev_dotl(uint32_t dev_major, uint32_t dev_minor)
+{
+    uint64_t dev;
+
+    // from glibc sysmacros.h:
+    dev  = (((uint64_t) (dev_major & 0x00000fffu)) <<  8);
+    dev |= (((uint64_t) (dev_major & 0xfffff000u)) << 32);
+    dev |= (((uint64_t) (dev_minor & 0x000000ffu)) <<  0);
+    dev |= (((uint64_t) (dev_minor & 0xffffff00u)) << 12);
+    return dev;
+}
+
+#endif
+
+/*
+ * Converts given device number from host's device number format to Linux
+ * device number format. As both the size of type dev_t and encoding of
+ * dev_t is system dependant, we have to convert them for Linux guests if
+ * host is not running Linux.
+ */
+static uint64_t host_dev_to_dotl_dev(dev_t dev)
+{
+#ifdef CONFIG_LINUX
+    return dev;
+#else
+    return makedev_dotl(major(dev), minor(dev));
+#endif
+}
+
 static int stat_to_v9stat_dotl(V9fsPDU *pdu, const struct stat *stbuf,
                                 V9fsStatDotl *v9lstat)
 {
@@ -1327,7 +1362,7 @@ static int stat_to_v9stat_dotl(V9fsPDU *pdu, const struct stat *stbuf,
     v9lstat->st_nlink = stbuf->st_nlink;
     v9lstat->st_uid = stbuf->st_uid;
     v9lstat->st_gid = stbuf->st_gid;
-    v9lstat->st_rdev = stbuf->st_rdev;
+    v9lstat->st_rdev = host_dev_to_dotl_dev(stbuf->st_rdev);
     v9lstat->st_size = stbuf->st_size;
     v9lstat->st_blksize = stat_to_iounit(pdu, stbuf);
     v9lstat->st_blocks = stbuf->st_blocks;
Signature · 1 line
2.32.0 (Apple Git-132)
#0 lore raw

cover 9pfs: macOS host fixes

A bunch of fixes for recently added (QEMU 7.0) 9p support on macOS hosts.

Note: there are still issues to address with case-insensitive file systems on macOS hosts. But I'll send a separate RFC on that issue.

Christian Schoenebeck (5):
9pfs: fix qemu_mknodat(S_IFREG) on macOS
9pfs: fix qemu_mknodat(S_IFSOCK) on macOS
9pfs: fix wrong encoding of rdev field in Rgetattr on macOS 9pfs: fix wrong errno being sent to Linux client on macOS host 9pfs: fix removing non-existent POSIX ACL xattr on macOS host

 hw/9pfs/9p-posix-acl.c   |  8 ++++-
 hw/9pfs/9p-util-darwin.c | 28 +++++++++++++++++-
 hw/9pfs/9p.c             | 64 +++++++++++++++++++++++++++++++++++++++-
 3 files changed, 97 insertions(+), 3 deletions(-)
Signature · 1 line
2.32.0 (Apple Git-132)
#17 lore raw

PATCH 4/5 9pfs: fix wrong errno being sent to Linux client on macOS host

Linux and macOS only share some errno definitions with equal macro name and value. In fact most mappings for errno are completely different on the two systems.

This patch converts some important errno values from macOS host to corresponding Linux errno values before eventually sending such error codes along with Tlerror replies (if 9p2000.L is used that is), which fixes a bunch of misbehaviours when running a Linux client on macOS host.

For instance this patch fixes:

mount -t 9p -o posixacl ...

on Linux guest if security_mode=mapped was used for 9p server, which refused to mount successfully, because macOS returned ENOATTR==93 when client tried to retrieve POSIX ACL xattrs, because errno 93 is defined as EPROTONOSUPPORT==93 on Linux, so Linux client believed that xattrs were not supported by filesystem on host in general.

---
 hw/9pfs/9p.c | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)
hw/9pfs/9p.c +27 -0
index d953035e1c..becc41cbfd 100644
@@ -57,6 +57,31 @@ enum {
 
 P9ARRAY_DEFINE_TYPE(V9fsPath, v9fs_path_free);
 
+/* Translates errno from host -> Linux if needed */
+static int errno_to_dotl(int err) {
+#if defined(CONFIG_LINUX)
+    /* nothing to translate (Linux -> Linux) */
+#elif defined(CONFIG_DARWIN)
+    /* translation mandatory for macOS hosts */
+    if (err == ENAMETOOLONG) {
+        err = 36; /* ==ENAMETOOLONG on Linux */
+    } else if (err == ENOTEMPTY) {
+        err = 39; /* ==ENOTEMPTY on Linux */
+    } else if (err == ELOOP) {
+        err = 40; /* ==ELOOP on Linux */
+    } else if (err == ENOATTR) {
+        err = 61; /* ==ENODATA on Linux */
+    } else if (err == ENOTSUP) {
+        err = 95; /* ==EOPNOTSUPP on Linux */
+    } else if (err == EOPNOTSUPP) {
+        err = 95; /* ==EOPNOTSUPP on Linux */
+    }
+#else
+#error Missing errno translation to Linux for this host system
+#endif
+    return err;
+}
+
 static ssize_t pdu_marshal(V9fsPDU *pdu, size_t offset, const char *fmt, ...)
 {
     ssize_t ret;
@@ -1054,6 +1079,8 @@ static void coroutine_fn pdu_complete(V9fsPDU *pdu, ssize_t len)
             }
             len += ret;
             id = P9_RERROR;
+        } else {
+            err = errno_to_dotl(err);
         }
 
         ret = pdu_marshal(pdu, len, "d", err);
Signature · 1 line
2.32.0 (Apple Git-132)
#22 lore raw

PATCH 5/5 9pfs: fix removing non-existent POSIX ACL xattr on macOS host

In reply to Christian Schoenebeck

When mapped POSIX ACL is used, we are ignoring errors when trying to remove a POSIX ACL xattr that does not exist. On Linux hosts we would get ENODATA in such cases, on macOS hosts however we get ENOATTR instead, so ignore ENOATTR errors as well.

This patch fixes e.g. a command on Linux guest like:

  cp --preserve=mode old new
---
 hw/9pfs/9p-posix-acl.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
hw/9pfs/9p-posix-acl.c +7 -1
index eadae270dd..2bf155f941 100644
@@ -65,7 +65,13 @@ static int mp_pacl_removexattr(FsContext *ctx,
     int ret;
 
     ret = local_removexattr_nofollow(ctx, path, MAP_ACL_ACCESS);
-    if (ret == -1 && errno == ENODATA) {
+    if (ret == -1 &&
+          (errno == ENODATA
+#ifdef ENOATTR
+          || errno == ENOATTR
+#endif
+          )
+    ) {
         /*
          * We don't get ENODATA error when trying to remove a
          * posix acl that is not present. So don't throw the error
Signature · 1 line
2.32.0 (Apple Git-132)
Reviewed-by on v1 1/5
#2 lore raw

Re: [PATCH 1/5] 9pfs: fix qemu_mknodat(S_IFREG) on macOS

In reply to Christian Schoenebeck
Quoted 31 lines · Christian Schoenebeck

mknod() on macOS does not support creating regular files, so divert to openat_file() if S_IFREG is passed with mode argument.

Furthermore, 'man 2 mknodat' on Linux says: "Zero file type is equivalent to type S_IFREG".

Signed-off-by
<https://lore.kernel.org/qemu-devel/17933734.zYzKuhC07K@silver/Signed-off-by>:
Christian Schoenebeck <[email protected]>

---
 hw/9pfs/9p-util-darwin.c | 4 ++++
 1 file changed, 4 insertions(+)
hw/9pfs/9p-util-darwin.c +4 -0
index bec0253474..53e0625501 100644
@@ -77,6 +77,10 @@ int fsetxattrat_nofollow(int dirfd, const char
 *filename, const char *name,
 int qemu_mknodat(int dirfd, const char *filename, mode_t mode, dev_t dev)
 {
     int preserved_errno, err;
+
+    if (S_ISREG(mode) || !(mode & S_IFMT)) {
+        return openat_file(dirfd, filename, O_CREAT, mode);
+    }
     if (!pthread_fchdir_np) {
         error_report_once("pthread_fchdir_np() not available on this
version of macOS");
         return -ENOTSUP;
Quoted 3 lines

--
2.32.0 (Apple Git-132)

Quoted 2 lines
#7 lore raw

Re: [PATCH 2/5] 9pfs: fix qemu_mknodat(S_IFSOCK) on macOS

In reply to Christian Schoenebeck
Quoted 61 lines · Christian Schoenebeck

mknod() on macOS does not support creating sockets, so divert to call sequence socket(), bind() and chmod() respectively if S_IFSOCK was passed with mode argument.

Signed-off-by
<https://lore.kernel.org/qemu-devel/17933734.zYzKuhC07K@silver/Signed-off-by>:
Christian Schoenebeck <[email protected]>

---
 hw/9pfs/9p-util-darwin.c | 24 +++++++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)
hw/9pfs/9p-util-darwin.c +18 -0
index 53e0625501..252a6fc5dd 100644
@@ -74,6 +74,24 @@ int fsetxattrat_nofollow(int dirfd, const char
 *filename, const char *name,
  */
 #if defined CONFIG_PTHREAD_FCHDIR_NP
 
+static int create_socket_file_at_cwd(const char *filename, mode_t mode) {
+    int fd, err;
+    struct sockaddr_un addr = {
+        .sun_family = AF_UNIX
+    };
+
+    fd = socket(PF_UNIX, SOCK_DGRAM, 0);
+    if (fd < 0) {
+        return fd;
+    }
+    snprintf(addr.sun_path, sizeof(addr.sun_path), "./%s", filename);
+    err = bind(fd, (struct sockaddr *) &addr, sizeof(addr));
+    if (err < 0) {
+        return err;
+    }
+    return chmod(addr.sun_path, mode);
+}
+
 int qemu_mknodat(int dirfd, const char *filename, mode_t mode, dev_t dev)
 {
     int preserved_errno, err;
hw/9pfs/9p-util-darwin.c +5 -1
@@ -88,7 +106,11 @@ int qemu_mknodat(int dirfd, const char *filename,
 mode_t mode, dev_t dev)
     if (pthread_fchdir_np(dirfd) < 0) {
         return -1;
     }
-    err = mknod(filename, mode, dev);
+    if (S_ISSOCK(mode)) {
+        err = create_socket_file_at_cwd(filename, mode);
+    } else {
+        err = mknod(filename, mode, dev);
+    }
     preserved_errno = errno;
     /* Stop using the thread-local cwd */
     pthread_fchdir_np(-1);

--
2.32.0 (Apple Git-132)

#3 lore raw

Re: [PATCH 1/5] 9pfs: fix qemu_mknodat(S_IFREG) on macOS

In reply to Christian Schoenebeck
Quoted 17 lines · Christian Schoenebeck

mknod() on macOS does not support creating regular files, so divert to openat_file() if S_IFREG is passed with mode argument.

Furthermore, 'man 2 mknodat' on Linux says: "Zero file type is equivalent to type S_IFREG".

---
  hw/9pfs/9p-util-darwin.c | 4 ++++
  1 file changed, 4 insertions(+)
hw/9pfs/9p-util-darwin.c +0 -0
index bec0253474..53e0625501 100644

hw/9pfs/9p-util-darwin.c int fsetxattrat_nofollow(int dirfd, const char *filename, const char *name, · line 86

Quoted 10 lines
hw/9pfs/9p-util-darwin.c +4 -0
@@ -77,6 +77,10 @@ int fsetxattrat_nofollow(int dirfd, const char *filename, const char *name,
  int qemu_mknodat(int dirfd, const char *filename, mode_t mode, dev_t dev)
  {
      int preserved_errno, err;
+
+    if (S_ISREG(mode) || !(mode & S_IFMT)) {
+        return openat_file(dirfd, filename, O_CREAT, mode);
+    }
      if (!pthread_fchdir_np) {
          error_report_once("pthread_fchdir_np() not available on this version of macOS");
          return -ENOTSUP;

openat_file returns a file descriptor on success while mknodat returns 0 on success. The inconsistency should be handled.

Regards,
Akihiko Odaki

#4 lore raw

Re: [PATCH 1/5] 9pfs: fix qemu_mknodat(S_IFREG) on macOS

Quoted 23 lines · On Wed, 20 Apr 2022 11:03:52 +0900 Akihiko Odaki <[email protected]>…
Quoted 22 lines · Christian Schoenebeck

mknod() on macOS does not support creating regular files, so divert to openat_file() if S_IFREG is passed with mode argument.

Furthermore, 'man 2 mknodat' on Linux says: "Zero file type is equivalent to type S_IFREG".

---
  hw/9pfs/9p-util-darwin.c | 4 ++++
  1 file changed, 4 insertions(+)
hw/9pfs/9p-util-darwin.c +2 -0
index bec0253474..53e0625501 100644
@@ -77,6 +77,10 @@ int fsetxattrat_nofollow(int dirfd, const char *filename, const char *name,
  int qemu_mknodat(int dirfd, const char *filename, mode_t mode, dev_t dev)
  {
      int preserved_errno, err;
+
+    if (S_ISREG(mode) || !(mode & S_IFMT)) {
Quoted 9 lines

hw/9pfs/9p-util-darwin.c int fsetxattrat_nofollow(int dirfd, const char *filename, const char *name, · line 86

Quoted 5 lines
hw/9pfs/9p-util-darwin.c +2 -0
+        return openat_file(dirfd, filename, O_CREAT, mode);
+    }
      if (!pthread_fchdir_np) {
          error_report_once("pthread_fchdir_np() not available on this version of macOS");
          return -ENOTSUP;

openat_file returns a file descriptor on success while mknodat returns 0 on success. The inconsistency should be handled.

And most importantly that file descriptor must be closed !

Quoted 2 lines

Regards,
Akihiko Odaki

#8 lore raw

Re: [PATCH 2/5] 9pfs: fix qemu_mknodat(S_IFSOCK) on macOS

In reply to Christian Schoenebeck
Quoted 4 lines · On Tue, 19 Apr 2022 13:41:03 +0200 Christian Schoenebeck…

mknod() on macOS does not support creating sockets, so divert to call sequence socket(), bind() and chmod() respectively if S_IFSOCK was passed with mode argument.

Hmm... thinking again about this one : QEMU on linux calls the libc version of mknodat() which doesn't seem to support S_IFSOCK according to the mknod(3P) manual page. So I'm not sure there's something to be actually fixed here... what's the observed behavior on linux ?

Quoted 48 lines
---
 hw/9pfs/9p-util-darwin.c | 24 +++++++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)
hw/9pfs/9p-util-darwin.c +23 -1
index 53e0625501..252a6fc5dd 100644
@@ -74,6 +74,24 @@ int fsetxattrat_nofollow(int dirfd, const char *filename, const char *name,
  */
 #if defined CONFIG_PTHREAD_FCHDIR_NP
 
+static int create_socket_file_at_cwd(const char *filename, mode_t mode) {
+    int fd, err;
+    struct sockaddr_un addr = {
+        .sun_family = AF_UNIX
+    };
+
+    fd = socket(PF_UNIX, SOCK_DGRAM, 0);
+    if (fd < 0) {
+        return fd;
+    }
+    snprintf(addr.sun_path, sizeof(addr.sun_path), "./%s", filename);
+    err = bind(fd, (struct sockaddr *) &addr, sizeof(addr));
+    if (err < 0) {
+        return err;
+    }
+    return chmod(addr.sun_path, mode);
+}
+
 int qemu_mknodat(int dirfd, const char *filename, mode_t mode, dev_t dev)
 {
     int preserved_errno, err;
@@ -88,7 +106,11 @@ int qemu_mknodat(int dirfd, const char *filename, mode_t mode, dev_t dev)
     if (pthread_fchdir_np(dirfd) < 0) {
         return -1;
     }
-    err = mknod(filename, mode, dev);
+    if (S_ISSOCK(mode)) {
+        err = create_socket_file_at_cwd(filename, mode);
+    } else {
+        err = mknod(filename, mode, dev);
+    }
     preserved_errno = errno;
     /* Stop using the thread-local cwd */
     pthread_fchdir_np(-1);
#5 lore raw

Re: [PATCH 1/5] 9pfs: fix qemu_mknodat(S_IFREG) on macOS

In reply to Greg Kurz
Quoted 36 lines · On Mittwoch, 20. April 2022 10:40:05 CEST Greg Kurz wrote:

On Wed, 20 Apr 2022 11:03:52 +0900

Quoted 33 lines · Akihiko Odaki
Quoted 32 lines · Christian Schoenebeck

mknod() on macOS does not support creating regular files, so divert to openat_file() if S_IFREG is passed with mode argument.

Furthermore, 'man 2 mknodat' on Linux says: "Zero file type is equivalent to type S_IFREG".

---

  hw/9pfs/9p-util-darwin.c | 4 ++++
  1 file changed, 4 insertions(+)
hw/9pfs/9p-util-darwin.c +4 -0
index bec0253474..53e0625501 100644
@@ -77,6 +77,10 @@ int fsetxattrat_nofollow(int dirfd, const char
 *filename, const char *name,> > 
  int qemu_mknodat(int dirfd, const char *filename, mode_t mode, dev_t
  dev)
  {
 
      int preserved_errno, err;
 
+
+    if (S_ISREG(mode) || !(mode & S_IFMT)) {
+        return openat_file(dirfd, filename, O_CREAT, mode);
+    }
 
      if (!pthread_fchdir_np) {
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

error_report_once("pthread_fchdir_np() not available on this version of macOS"); return -ENOTSUP;

openat_file returns a file descriptor on success while mknodat returns 0 on success. The inconsistency should be handled.

And most importantly that file descriptor must be closed !

Good spot, both of you! Revising -> v2.

Thanks guys!

Best regards,
Christian Schoenebeck

#9 lore raw

Re: [PATCH 2/5] 9pfs: fix qemu_mknodat(S_IFSOCK) on macOS

In reply to Greg Kurz
Quoted 11 lines · On Mittwoch, 20. April 2022 11:09:46 CEST Greg Kurz wrote:

On Tue, 19 Apr 2022 13:41:03 +0200

Quoted 3 lines · Christian Schoenebeck

mknod() on macOS does not support creating sockets, so divert to call sequence socket(), bind() and chmod() respectively if S_IFSOCK was passed with mode argument.

Hmm... thinking again about this one : QEMU on linux calls the libc version of mknodat() which doesn't seem to support S_IFSOCK according to the mknod(3P) manual page. So I'm not sure there's something to be actually fixed here... what's the observed behavior on linux ?

It's unclear to me where you got that from. In all Linux man pages I looked up so far it said S_IFSOCK was supported. But I also tested this now with security_model=none on a Linux host and it works as expected, i.e. it creates a file of type socket on the Linux host filesystem.

We are really talking about a Linux host, right?

Best regards,
Christian Schoenebeck

#11 lore raw

Re: [PATCH 2/5] 9pfs: fix qemu_mknodat(S_IFSOCK) on macOS

In reply to Christian Schoenebeck
Quoted 24 lines · On Tue, 19 Apr 2022 13:41:03 +0200 Christian Schoenebeck…

mknod() on macOS does not support creating sockets, so divert to call sequence socket(), bind() and chmod() respectively if S_IFSOCK was passed with mode argument.

---
 hw/9pfs/9p-util-darwin.c | 24 +++++++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)
hw/9pfs/9p-util-darwin.c +6 -0
index 53e0625501..252a6fc5dd 100644
@@ -74,6 +74,24 @@ int fsetxattrat_nofollow(int dirfd, const char *filename, const char *name,
  */
 #if defined CONFIG_PTHREAD_FCHDIR_NP
 
+static int create_socket_file_at_cwd(const char *filename, mode_t mode) {
+    int fd, err;
+    struct sockaddr_un addr = {
+        .sun_family = AF_UNIX
+    };
+

hw/9pfs/9p-util-darwin.c int fsetxattrat_nofollow(int dirfd, const char *filename, const char *name, · line 92

Quoted 10 lines
hw/9pfs/9p-util-darwin.c +10 -0
+    fd = socket(PF_UNIX, SOCK_DGRAM, 0);
+    if (fd < 0) {
+        return fd;
+    }
+    snprintf(addr.sun_path, sizeof(addr.sun_path), "./%s", filename);
+    err = bind(fd, (struct sockaddr *) &addr, sizeof(addr));
+    if (err < 0) {
+        return err;
+    }
+    return chmod(addr.sun_path, mode);

As with the other patch, you should close() the socket.

Quoted 18 lines
hw/9pfs/9p-util-darwin.c +7 -1
+}
+
 int qemu_mknodat(int dirfd, const char *filename, mode_t mode, dev_t dev)
 {
     int preserved_errno, err;
@@ -88,7 +106,11 @@ int qemu_mknodat(int dirfd, const char *filename, mode_t mode, dev_t dev)
     if (pthread_fchdir_np(dirfd) < 0) {
         return -1;
     }
-    err = mknod(filename, mode, dev);
+    if (S_ISSOCK(mode)) {
+        err = create_socket_file_at_cwd(filename, mode);
+    } else {
+        err = mknod(filename, mode, dev);
+    }
     preserved_errno = errno;
     /* Stop using the thread-local cwd */
     pthread_fchdir_np(-1);
#10 lore raw

Re: [PATCH 2/5] 9pfs: fix qemu_mknodat(S_IFSOCK) on macOS

In reply to Christian Schoenebeck
Quoted 13 lines · On Wed, 20 Apr 2022 12:28:01 +0200 Christian Schoenebeck…
Quoted 11 lines · On Mittwoch, 20. April 2022 11:09:46 CEST Greg Kurz wrote:

On Tue, 19 Apr 2022 13:41:03 +0200

Quoted 3 lines · Christian Schoenebeck

mknod() on macOS does not support creating sockets, so divert to call sequence socket(), bind() and chmod() respectively if S_IFSOCK was passed with mode argument.

Hmm... thinking again about this one : QEMU on linux calls the libc version of mknodat() which doesn't seem to support S_IFSOCK according to the mknod(3P) manual page. So I'm not sure there's something to be actually fixed here... what's the observed behavior on linux ?

Quoted 7 lines

It's unclear to me where you got that from. In all Linux man pages I looked up so far it said S_IFSOCK was supported. But I also tested this now with security_model=none on a Linux host and it works as expected, i.e. it creates a file of type socket on the Linux host filesystem.

We are really talking about a Linux host, right?

Yes but you can forget this remark. I've checked the glibc sources and it directly calls the syscall... I guess I got confused by the mknod(3P) manual page. Sorry for the noise :-)

Quoted 4 lines

Best regards,
Christian Schoenebeck

#12 lore raw

Re: [PATCH 2/5] 9pfs: fix qemu_mknodat(S_IFSOCK) on macOS

In reply to Greg Kurz
Quoted 34 lines · On Mittwoch, 20. April 2022 14:10:44 CEST Greg Kurz wrote:

On Tue, 19 Apr 2022 13:41:03 +0200

Quoted 31 lines · Christian Schoenebeck

mknod() on macOS does not support creating sockets, so divert to call sequence socket(), bind() and chmod() respectively if S_IFSOCK was passed with mode argument.

---

 hw/9pfs/9p-util-darwin.c | 24 +++++++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)
hw/9pfs/9p-util-darwin.c +10 -0
index 53e0625501..252a6fc5dd 100644
@@ -74,6 +74,24 @@ int fsetxattrat_nofollow(int dirfd, const char
 *filename, const char *name,> 
  */
 
 #if defined CONFIG_PTHREAD_FCHDIR_NP
 
+static int create_socket_file_at_cwd(const char *filename, mode_t mode) {
+    int fd, err;
+    struct sockaddr_un addr = {
+        .sun_family = AF_UNIX
+    };
+
+    fd = socket(PF_UNIX, SOCK_DGRAM, 0);
+    if (fd < 0) {
+        return fd;
+    }
Quoted 8 lines

hw/9pfs/9p-util-darwin.c int fsetxattrat_nofollow(int dirfd, const char *filename, const char *name, · line 92

Quoted 6 lines
hw/9pfs/9p-util-darwin.c +6 -0
+    snprintf(addr.sun_path, sizeof(addr.sun_path), "./%s", filename);
+    err = bind(fd, (struct sockaddr *) &addr, sizeof(addr));
+    if (err < 0) {
+        return err;
+    }
+    return chmod(addr.sun_path, mode);

As with the other patch, you should close() the socket.

I was concerned that close(fd) might cause the socket file to disappear. But I just tested this now on macOS and it works fine. So will be fixed in v2.

Thanks!

Best regards,
Christian Schoenebeck

Reviewed-by on v1 3/5
#14 lore raw

Re: [PATCH 3/5] 9pfs: fix wrong encoding of rdev field in Rgetattr on macOS

In reply to Christian Schoenebeck
Quoted 9 lines · On Tue, 19 Apr 2022 13:41:15 +0200 Christian Schoenebeck…

The 'rdev' field in 9p reponse 'Rgetattr' is of type dev_t, which is actually a system dependant type and therefore both the size and encoding of dev_t differ between macOS and Linux.

So far we have sent 'rdev' to guest in host's dev_t format as-is, which caused devices to appear with wrong device numbers on guests running on macOS hosts, eventually leading to various misbehaviours on guest in conjunction with device files.

Quoted 6 lines

This patch fixes this issue by converting the device number from host's dev_t format to Linux dev_t format. As 9p request 'Tgettattr' is exclusive to protocol version 9p2000.L, it should be fair to assume that 'rdev' field is assumed to be in Linux dev_t format by client as well.

For the sake of accuracy : this is converting the host's dev_t to glibc's format (MMMM_Mmmm_mmmM_MMmm, 64 bits) actually, which is compatible with linux's format (mmmM_MMmm, 32 bits), as described in <bits/sysmacros.h>.

Quoted 38 lines
---
 hw/9pfs/9p.c | 37 ++++++++++++++++++++++++++++++++++++-
 1 file changed, 36 insertions(+), 1 deletion(-)
hw/9pfs/9p.c +25 -0
index 225f31fc31..d953035e1c 100644
@@ -1318,6 +1318,41 @@ static int32_t stat_to_iounit(const V9fsPDU *pdu, const struct stat *stbuf)
     return blksize_to_iounit(pdu, stbuf->st_blksize);
 }
 
+#if !defined(CONFIG_LINUX)
+
+/*
+ * Generates a Linux device number (a.k.a. dev_t) for given device major
+ * and minor numbers.
+ */
+static uint64_t makedev_dotl(uint32_t dev_major, uint32_t dev_minor)
+{
+    uint64_t dev;
+
+    // from glibc sysmacros.h:
+    dev  = (((uint64_t) (dev_major & 0x00000fffu)) <<  8);
+    dev |= (((uint64_t) (dev_major & 0xfffff000u)) << 32);
+    dev |= (((uint64_t) (dev_minor & 0x000000ffu)) <<  0);
+    dev |= (((uint64_t) (dev_minor & 0xffffff00u)) << 12);
+    return dev;
+}
+
+#endif
+
+/*
+ * Converts given device number from host's device number format to Linux
+ * device number format. As both the size of type dev_t and encoding of
+ * dev_t is system dependant, we have to convert them for Linux guests if
+ * host is not running Linux.

hw/9pfs/9p.c static int32_t stat_to_iounit(const V9fsPDU *pdu, const struct stat *stbuf) · line 1355

Quoted 10 lines
hw/9pfs/9p.c +10 -0
+ */
+static uint64_t host_dev_to_dotl_dev(dev_t dev)
+{
+#ifdef CONFIG_LINUX
+    return dev;
+#else
+    return makedev_dotl(major(dev), minor(dev));
+#endif
+}
+

It is a bit unfortunate to inflate 9p.c, which is large enough, with glue code. Even if they are only used here, I'd personally put them in 9p-util.h. No big deal.

Quoted 12 lines
hw/9pfs/9p.c +1 -1
 static int stat_to_v9stat_dotl(V9fsPDU *pdu, const struct stat *stbuf,
                                 V9fsStatDotl *v9lstat)
 {
@@ -1327,7 +1362,7 @@ static int stat_to_v9stat_dotl(V9fsPDU *pdu, const struct stat *stbuf,
     v9lstat->st_nlink = stbuf->st_nlink;
     v9lstat->st_uid = stbuf->st_uid;
     v9lstat->st_gid = stbuf->st_gid;
-    v9lstat->st_rdev = stbuf->st_rdev;
+    v9lstat->st_rdev = host_dev_to_dotl_dev(stbuf->st_rdev);
     v9lstat->st_size = stbuf->st_size;
     v9lstat->st_blksize = stat_to_iounit(pdu, stbuf);
     v9lstat->st_blocks = stbuf->st_blocks;
#23 lore raw

Re: [PATCH 5/5] 9pfs: fix removing non-existent POSIX ACL xattr on macOS host

In reply to Christian Schoenebeck
Quoted 19 lines · On Tue, 19 Apr 2022 13:43:30 +0200 Christian Schoenebeck…

When mapped POSIX ACL is used, we are ignoring errors when trying to remove a POSIX ACL xattr that does not exist. On Linux hosts we would get ENODATA in such cases, on macOS hosts however we get ENOATTR instead, so ignore ENOATTR errors as well.

This patch fixes e.g. a command on Linux guest like:

  cp --preserve=mode old new
---
 hw/9pfs/9p-posix-acl.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
hw/9pfs/9p-posix-acl.c +0 -0
index eadae270dd..2bf155f941 100644

hw/9pfs/9p-posix-acl.c static int mp_pacl_removexattr(FsContext *ctx, · line 73

Quoted 10 lines
hw/9pfs/9p-posix-acl.c +6 -1
@@ -65,7 +65,13 @@ static int mp_pacl_removexattr(FsContext *ctx,
     int ret;
 
     ret = local_removexattr_nofollow(ctx, path, MAP_ACL_ACCESS);
-    if (ret == -1 && errno == ENODATA) {
+    if (ret == -1 &&
+          (errno == ENODATA
+#ifdef ENOATTR
+          || errno == ENOATTR
+#endif
+          )

We already have this in <qemu/xattr.h> which is included by 9p-posix-acl.c :

/*
* Modern distributions (e.g. Fedora 15), have no libattr.so, place attr.h
* in /usr/include/sys, and don't have ENOATTR.
*/

#ifdef CONFIG_LIBATTR
# include <attr/xattr.h>
#else
# if !defined(ENOATTR)
# define ENOATTR ENODATA
# endif
# include <sys/xattr.h>
#endif

I guess this patch could just s/ENODATA/ENOATTR/ to avoid the extra ifdefery.

Quoted 4 lines
hw/9pfs/9p-posix-acl.c +1 -0
+    ) {
         /*
          * We don't get ENODATA error when trying to remove a
          * posix acl that is not present. So don't throw the error
#15 lore raw

Re: [PATCH 3/5] 9pfs: fix wrong encoding of rdev field in Rgetattr on macOS

In reply to Greg Kurz
Quoted 18 lines · On Donnerstag, 21. April 2022 09:30:56 CEST Greg Kurz wrote:

On Tue, 19 Apr 2022 13:41:15 +0200

Quoted 9 lines · Christian Schoenebeck

The 'rdev' field in 9p reponse 'Rgetattr' is of type dev_t, which is actually a system dependant type and therefore both the size and encoding of dev_t differ between macOS and Linux.

So far we have sent 'rdev' to guest in host's dev_t format as-is, which caused devices to appear with wrong device numbers on guests running on macOS hosts, eventually leading to various misbehaviours on guest in conjunction with device files.

Quoted 5 lines

This patch fixes this issue by converting the device number from host's dev_t format to Linux dev_t format. As 9p request 'Tgettattr' is exclusive to protocol version 9p2000.L, it should be fair to assume that 'rdev' field is assumed to be in Linux dev_t format by client as well.

Quoted 3 lines

For the sake of accuracy : this is converting the host's dev_t to glibc's format (MMMM_Mmmm_mmmM_MMmm, 64 bits) actually, which is compatible with linux's format (mmmM_MMmm, 32 bits), as described in <bits/sysmacros.h>.

You want me to put this to the commit log?

Quoted 47 lines
Quoted 47 lines

---

 hw/9pfs/9p.c | 37 ++++++++++++++++++++++++++++++++++++-
 1 file changed, 36 insertions(+), 1 deletion(-)
hw/9pfs/9p.c +0 -0
index 225f31fc31..d953035e1c 100644
@@ -1318,6 +1318,41 @@ static int32_t stat_to_iounit(const V9fsPDU *pdu,

const struct stat *stbuf)>

     return blksize_to_iounit(pdu, stbuf->st_blksize);

}

hw/9pfs/9p.c +31 -0
+#if !defined(CONFIG_LINUX)
+
+/*
+ * Generates a Linux device number (a.k.a. dev_t) for given device major
+ * and minor numbers.
+ */
+static uint64_t makedev_dotl(uint32_t dev_major, uint32_t dev_minor)
+{
+    uint64_t dev;
+
+    // from glibc sysmacros.h:
+    dev  = (((uint64_t) (dev_major & 0x00000fffu)) <<  8);
+    dev |= (((uint64_t) (dev_major & 0xfffff000u)) << 32);
+    dev |= (((uint64_t) (dev_minor & 0x000000ffu)) <<  0);
+    dev |= (((uint64_t) (dev_minor & 0xffffff00u)) << 12);
+    return dev;
+}
+
+#endif
+
+/*
+ * Converts given device number from host's device number format to Linux
+ * device number format. As both the size of type dev_t and encoding of
+ * dev_t is system dependant, we have to convert them for Linux guests if
+ * host is not running Linux.
+ */
+static uint64_t host_dev_to_dotl_dev(dev_t dev)
+{
+#ifdef CONFIG_LINUX
+    return dev;
+#else
Quoted 8 lines

hw/9pfs/9p.c static int32_t stat_to_iounit(const V9fsPDU *pdu, const struct stat *stbuf) · line 1355

Quoted 4 lines
hw/9pfs/9p.c +4 -0
+    return makedev_dotl(major(dev), minor(dev));
+#endif
+}
+

It is a bit unfortunate to inflate 9p.c, which is large enough, with glue code. Even if they are only used here, I'd personally put them in 9p-util.h. No big deal.

Makes sense, I'll move it.

Quoted 1 line

Thanks!

Quoted 18 lines
Quoted 18 lines

static int stat_to_v9stat_dotl(V9fsPDU *pdu, const struct stat *stbuf,

V9fsStatDotl *v9lstat)

{

hw/9pfs/9p.c +0 -0
@@ -1327,7 +1362,7 @@ static int stat_to_v9stat_dotl(V9fsPDU *pdu, const

struct stat *stbuf,>

     v9lstat->st_nlink = stbuf->st_nlink;
     v9lstat->st_uid = stbuf->st_uid;
     v9lstat->st_gid = stbuf->st_gid;
hw/9pfs/9p.c +1 -1
-    v9lstat->st_rdev = stbuf->st_rdev;
+    v9lstat->st_rdev = host_dev_to_dotl_dev(stbuf->st_rdev);
 
     v9lstat->st_size = stbuf->st_size;
     v9lstat->st_blksize = stat_to_iounit(pdu, stbuf);
     v9lstat->st_blocks = stbuf->st_blocks;
#18 lore raw

Re: [PATCH 4/5] 9pfs: fix wrong errno being sent to Linux client on macOS host

In reply to Christian Schoenebeck
Quoted 10 lines · On Tue, 19 Apr 2022 13:41:59 +0200 Christian Schoenebeck…

Linux and macOS only share some errno definitions with equal macro name and value. In fact most mappings for errno are completely different on the two systems.

This patch converts some important errno values from macOS host to corresponding Linux errno values before eventually sending such error codes along with Tlerror replies (if 9p2000.L is used that is), which fixes a bunch of misbehaviours when running a Linux client on macOS host.

This even fixes an actual protocol violation :

lerror -- return error code

size[4] Rlerror tag[2] ecode[4]

lerror replaces the reply message used in a successful call. ecode is a numerical Linux errno.
^^^^^^^^^^^^^^^^^^^^^

Taken from https://github.com/chaos/diod/wiki/protocol#lerror----return-error-code

Quoted 32 lines

For instance this patch fixes:

mount -t 9p -o posixacl ...

on Linux guest if security_mode=mapped was used for 9p server, which refused to mount successfully, because macOS returned ENOATTR==93 when client tried to retrieve POSIX ACL xattrs, because errno 93 is defined as EPROTONOSUPPORT==93 on Linux, so Linux client believed that xattrs were not supported by filesystem on host in general.

---
 hw/9pfs/9p.c | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)
hw/9pfs/9p.c +9 -0
index d953035e1c..becc41cbfd 100644
@@ -57,6 +57,31 @@ enum {
 
 P9ARRAY_DEFINE_TYPE(V9fsPath, v9fs_path_free);
 
+/* Translates errno from host -> Linux if needed */
+static int errno_to_dotl(int err) {
+#if defined(CONFIG_LINUX)
+    /* nothing to translate (Linux -> Linux) */
+#elif defined(CONFIG_DARWIN)
+    /* translation mandatory for macOS hosts */
+    if (err == ENAMETOOLONG) {
+        err = 36; /* ==ENAMETOOLONG on Linux */
+    } else if (err == ENOTEMPTY) {

hw/9pfs/9p.c enum { · line 78

Quoted 10 lines
hw/9pfs/9p.c +10 -0
+        err = 39; /* ==ENOTEMPTY on Linux */
+    } else if (err == ELOOP) {
+        err = 40; /* ==ELOOP on Linux */
+    } else if (err == ENOATTR) {
+        err = 61; /* ==ENODATA on Linux */
+    } else if (err == ENOTSUP) {
+        err = 95; /* ==EOPNOTSUPP on Linux */
+    } else if (err == EOPNOTSUPP) {
+        err = 95; /* ==EOPNOTSUPP on Linux */
+    }

I'm assuming you have audited all errnos, right ? Just to be sure that this won't bite anymore.

hw/9pfs/9p.c enum { · line 84

Quoted 6 lines
hw/9pfs/9p.c +6 -0
+#else
+#error Missing errno translation to Linux for this host system
+#endif
+    return err;
+}
+

As with the other patch, I'd rather move this magic to 9p-util.h .

Quoted 12 lines
hw/9pfs/9p.c +2 -0
 static ssize_t pdu_marshal(V9fsPDU *pdu, size_t offset, const char *fmt, ...)
 {
     ssize_t ret;
@@ -1054,6 +1079,8 @@ static void coroutine_fn pdu_complete(V9fsPDU *pdu, ssize_t len)
             }
             len += ret;
             id = P9_RERROR;
+        } else {
+            err = errno_to_dotl(err);
         }
 
         ret = pdu_marshal(pdu, len, "d", err);
#16 lore raw

Re: [PATCH 3/5] 9pfs: fix wrong encoding of rdev field in Rgetattr on macOS

In reply to Christian Schoenebeck
Quoted 19 lines · On Thu, 21 Apr 2022 12:25:23 +0200 Christian Schoenebeck…
Quoted 18 lines · On Donnerstag, 21. April 2022 09:30:56 CEST Greg Kurz wrote:

On Tue, 19 Apr 2022 13:41:15 +0200

Quoted 14 lines · Christian Schoenebeck

The 'rdev' field in 9p reponse 'Rgetattr' is of type dev_t, which is actually a system dependant type and therefore both the size and encoding of dev_t differ between macOS and Linux.

So far we have sent 'rdev' to guest in host's dev_t format as-is, which caused devices to appear with wrong device numbers on guests running on macOS hosts, eventually leading to various misbehaviours on guest in conjunction with device files.

This patch fixes this issue by converting the device number from host's dev_t format to Linux dev_t format. As 9p request 'Tgettattr' is exclusive to protocol version 9p2000.L, it should be fair to assume that 'rdev' field is assumed to be in Linux dev_t format by client as well.

Quoted 6 lines
Quoted 3 lines

For the sake of accuracy : this is converting the host's dev_t to glibc's format (MMMM_Mmmm_mmmM_MMmm, 64 bits) actually, which is compatible with linux's format (mmmM_MMmm, 32 bits), as described in <bits/sysmacros.h>.

You want me to put this to the commit log?

Maybe closer to the code that does the actual magic...

Quoted 14 lines
Quoted 14 lines
Quoted 14 lines

---

 hw/9pfs/9p.c | 37 ++++++++++++++++++++++++++++++++++++-
 1 file changed, 36 insertions(+), 1 deletion(-)
hw/9pfs/9p.c +0 -0
index 225f31fc31..d953035e1c 100644
@@ -1318,6 +1318,41 @@ static int32_t stat_to_iounit(const V9fsPDU *pdu,

const struct stat *stbuf)>

     return blksize_to_iounit(pdu, stbuf->st_blksize);
Quoted 7 lines
Quoted 7 lines

hw/9pfs/9p.c static int32_t stat_to_iounit(const V9fsPDU *pdu, const struct stat *stbuf) · line 1325

Quoted 7 lines

}

hw/9pfs/9p.c +5 -0
+#if !defined(CONFIG_LINUX)
+
+/*
+ * Generates a Linux device number (a.k.a. dev_t) for given device major
+ * and minor numbers.

... here ^^.

Quoted 61 lines
Quoted 26 lines
Quoted 26 lines

+ */

hw/9pfs/9p.c +25 -0
+static uint64_t makedev_dotl(uint32_t dev_major, uint32_t dev_minor)
+{
+    uint64_t dev;
+
+    // from glibc sysmacros.h:
+    dev  = (((uint64_t) (dev_major & 0x00000fffu)) <<  8);
+    dev |= (((uint64_t) (dev_major & 0xfffff000u)) << 32);
+    dev |= (((uint64_t) (dev_minor & 0x000000ffu)) <<  0);
+    dev |= (((uint64_t) (dev_minor & 0xffffff00u)) << 12);
+    return dev;
+}
+
+#endif
+
+/*
+ * Converts given device number from host's device number format to Linux
+ * device number format. As both the size of type dev_t and encoding of
+ * dev_t is system dependant, we have to convert them for Linux guests if
+ * host is not running Linux.
+ */
+static uint64_t host_dev_to_dotl_dev(dev_t dev)
+{
+#ifdef CONFIG_LINUX
+    return dev;
+#else
Quoted 8 lines

hw/9pfs/9p.c static int32_t stat_to_iounit(const V9fsPDU *pdu, const struct stat *stbuf) · line 1355

Quoted 4 lines
hw/9pfs/9p.c +4 -0
+    return makedev_dotl(major(dev), minor(dev));
+#endif
+}
+

It is a bit unfortunate to inflate 9p.c, which is large enough, with glue code. Even if they are only used here, I'd personally put them in 9p-util.h. No big deal.

Makes sense, I'll move it.

Quoted 1 line

Thanks!

Quoted 18 lines
Quoted 18 lines

static int stat_to_v9stat_dotl(V9fsPDU *pdu, const struct stat *stbuf,

V9fsStatDotl *v9lstat)

{

hw/9pfs/9p.c +0 -0
@@ -1327,7 +1362,7 @@ static int stat_to_v9stat_dotl(V9fsPDU *pdu, const

struct stat *stbuf,>

     v9lstat->st_nlink = stbuf->st_nlink;
     v9lstat->st_uid = stbuf->st_uid;
     v9lstat->st_gid = stbuf->st_gid;
hw/9pfs/9p.c +1 -1
-    v9lstat->st_rdev = stbuf->st_rdev;
+    v9lstat->st_rdev = host_dev_to_dotl_dev(stbuf->st_rdev);
 
     v9lstat->st_size = stbuf->st_size;
     v9lstat->st_blksize = stat_to_iounit(pdu, stbuf);
     v9lstat->st_blocks = stbuf->st_blocks;
#24 lore raw

Re: [PATCH 5/5] 9pfs: fix removing non-existent POSIX ACL xattr on macOS host

In reply to Greg Kurz
Quoted 53 lines · On Donnerstag, 21. April 2022 10:26:11 CEST Greg Kurz wrote:

On Tue, 19 Apr 2022 13:43:30 +0200

Quoted 21 lines · Christian Schoenebeck

When mapped POSIX ACL is used, we are ignoring errors when trying to remove a POSIX ACL xattr that does not exist. On Linux hosts we would get ENODATA in such cases, on macOS hosts however we get ENOATTR instead, so ignore ENOATTR errors as well.

This patch fixes e.g. a command on Linux guest like:
cp --preserve=mode old new

---

 hw/9pfs/9p-posix-acl.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
hw/9pfs/9p-posix-acl.c +0 -0
index eadae270dd..2bf155f941 100644
@@ -65,7 +65,13 @@ static int mp_pacl_removexattr(FsContext *ctx,
 
     int ret;

hw/9pfs/9p-posix-acl.c static int mp_pacl_removexattr(FsContext *ctx, · line 75

Quoted 10 lines
hw/9pfs/9p-posix-acl.c +6 -1
 
     ret = local_removexattr_nofollow(ctx, path, MAP_ACL_ACCESS);
 
-    if (ret == -1 && errno == ENODATA) {
+    if (ret == -1 &&
+          (errno == ENODATA
+#ifdef ENOATTR
+          || errno == ENOATTR
+#endif
+          )

We already have this in <qemu/xattr.h> which is included by 9p-posix-acl.c :

/*
* Modern distributions (e.g. Fedora 15), have no libattr.so, place attr.h
* in /usr/include/sys, and don't have ENOATTR.
*/

#ifdef CONFIG_LIBATTR
# include <attr/xattr.h>
#else
# if !defined(ENOATTR)
# define ENOATTR ENODATA
# endif
# include <sys/xattr.h>
#endif

Quoted 2 lines

I guess this patch could just s/ENODATA/ENOATTR/ to avoid the extra ifdefery.

Not viable, because macOS does have both ENODATA==96 and ENOATTR==93. On Linux the two macros were historically defined to the same numeric values, that's why it worked there.

Maybe I should define a separate macro like:

#if ...

# define P9_ENOATTR ENOATTR
#else
# define P9_ENOATTR ENODATA
#end

?

Actually good that you pointed me at this, because I just realized there is a 2nd place in 9p-posix-acl.c which would require this as well. For some reason the 2nd place just did not trigger while I was testing it on macOS.

Best regards,
Christian Schoenebeck

#19 lore raw

Re: [PATCH 4/5] 9pfs: fix wrong errno being sent to Linux client on macOS host

In reply to Greg Kurz
Quoted 17 lines · On Donnerstag, 21. April 2022 12:48:35 CEST Greg Kurz wrote:

On Tue, 19 Apr 2022 13:41:59 +0200

Quoted 9 lines · Christian Schoenebeck

Linux and macOS only share some errno definitions with equal macro name and value. In fact most mappings for errno are completely different on the two systems.

This patch converts some important errno values from macOS host to corresponding Linux errno values before eventually sending such error codes along with Tlerror replies (if 9p2000.L is used that is), which fixes a bunch of misbehaviours when running a Linux client on macOS host.

This even fixes an actual protocol violation :

lerror -- return error code

Quoted 8 lines

size[4] Rlerror tag[2] ecode[4]

lerror replaces the reply message used in a successful call. ecode is a numerical Linux errno.
^^^^^^^^^^^^^^^^^^^^^

Taken from
https://github.com/chaos/diod/wiki/protocol#lerror----return-error-code

Again, something to add to the commit log?

Quoted 37 lines
Quoted 37 lines

For instance this patch fixes:
mount -t 9p -o posixacl ...

on Linux guest if security_mode=mapped was used for 9p server, which refused to mount successfully, because macOS returned ENOATTR==93 when client tried to retrieve POSIX ACL xattrs, because errno 93 is defined as EPROTONOSUPPORT==93 on Linux, so Linux client believed that xattrs were not supported by filesystem on host in general.

---

 hw/9pfs/9p.c | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)
hw/9pfs/9p.c +14 -0
index d953035e1c..becc41cbfd 100644
@@ -57,6 +57,31 @@ enum {
 
 P9ARRAY_DEFINE_TYPE(V9fsPath, v9fs_path_free);
 
+/* Translates errno from host -> Linux if needed */
+static int errno_to_dotl(int err) {
+#if defined(CONFIG_LINUX)
+    /* nothing to translate (Linux -> Linux) */
+#elif defined(CONFIG_DARWIN)
+    /* translation mandatory for macOS hosts */
+    if (err == ENAMETOOLONG) {
+        err = 36; /* ==ENAMETOOLONG on Linux */
+    } else if (err == ENOTEMPTY) {
+        err = 39; /* ==ENOTEMPTY on Linux */
+    } else if (err == ELOOP) {
+        err = 40; /* ==ELOOP on Linux */
+    } else if (err == ENOATTR) {
+        err = 61; /* ==ENODATA on Linux */
Quoted 8 lines

hw/9pfs/9p.c enum { · line 78

Quoted 5 lines
hw/9pfs/9p.c +5 -0
+    } else if (err == ENOTSUP) {
+        err = 95; /* ==EOPNOTSUPP on Linux */
+    } else if (err == EOPNOTSUPP) {
+        err = 95; /* ==EOPNOTSUPP on Linux */
+    }

I'm assuming you have audited all errnos, right ? Just to be sure that this won't bite anymore.

Depends on what you mean with "all". Like I wrote in the commit log, for now I translated in this patch those errnos that I identified as important, and those are audited by me of course (checked the man pages for what errors are expected as result from calls on Linux vs. macOS side and looked up numeric values from header files on both sides, tests).

However if you rather mean really all errnos that were ever defined on Linux and macOS, then the answer is no. That would probably quite some work, and I'm not sure if you could just try to translate them dry, i.e. by just looking at the headers or something.

So yes, your concern is justified. The question is, should this all be translated right now already, or would it be OK to address this minimum set of errno translation for now (especially for qemu-stable) and then later address the rest?

On the long term you would probably import the Linux errno header file into the code base, then prefix the individual macros with something like DOTL_ENODATA, etc. and then use those macros for translating the errnos instead of using literal numerics, maybe using GCC's designated array initializers then.

Quoted 8 lines

hw/9pfs/9p.c enum { · line 84

Quoted 6 lines
hw/9pfs/9p.c +6 -0
+#else
+#error Missing errno translation to Linux for this host system
+#endif
+    return err;
+}
+

As with the other patch, I'd rather move this magic to 9p-util.h .

Makes sense. There is indeed already too much utility code piled up in 9p.c.

Quoted 17 lines
Quoted 17 lines
hw/9pfs/9p.c +0 -0
 static ssize_t pdu_marshal(V9fsPDU *pdu, size_t offset, const char *fmt,
 ...) {
 
     ssize_t ret;
hw/9pfs/9p.c +0 -0
@@ -1054,6 +1079,8 @@ static void coroutine_fn pdu_complete(V9fsPDU *pdu,

ssize_t len)>

             }
             len += ret;
             id = P9_RERROR;
hw/9pfs/9p.c +2 -0
+        } else {
+            err = errno_to_dotl(err);
 
         }
 
         ret = pdu_marshal(pdu, len, "d", err);
#20 lore raw

Re: [PATCH 4/5] 9pfs: fix wrong errno being sent to Linux client on macOS host

Quoted 20 lines · On Thu, 21 Apr 2022 13:13:08 +0200 Christian Schoenebeck…
Quoted 19 lines · On Donnerstag, 21. April 2022 12:48:35 CEST Greg Kurz wrote:

On Tue, 19 Apr 2022 13:41:59 +0200

Quoted 9 lines · Christian Schoenebeck

Linux and macOS only share some errno definitions with equal macro name and value. In fact most mappings for errno are completely different on the two systems.

This patch converts some important errno values from macOS host to corresponding Linux errno values before eventually sending such error codes along with Tlerror replies (if 9p2000.L is used that is), which fixes a bunch of misbehaviours when running a Linux client on macOS host.

This even fixes an actual protocol violation :

lerror -- return error code

size[4] Rlerror tag[2] ecode[4]

Quoted 9 lines
Quoted 6 lines

lerror replaces the reply message used in a successful call. ecode is a numerical Linux errno.
^^^^^^^^^^^^^^^^^^^^^

Taken from
https://github.com/chaos/diod/wiki/protocol#lerror----return-error-code

Again, something to add to the commit log?

IMHO a protocol violation is important enough to be mentioned but I'll leave it to you.

Quoted 46 lines
Quoted 37 lines
Quoted 37 lines

For instance this patch fixes:
mount -t 9p -o posixacl ...

on Linux guest if security_mode=mapped was used for 9p server, which refused to mount successfully, because macOS returned ENOATTR==93 when client tried to retrieve POSIX ACL xattrs, because errno 93 is defined as EPROTONOSUPPORT==93 on Linux, so Linux client believed that xattrs were not supported by filesystem on host in general.

---

 hw/9pfs/9p.c | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)
hw/9pfs/9p.c +14 -0
index d953035e1c..becc41cbfd 100644
@@ -57,6 +57,31 @@ enum {
 
 P9ARRAY_DEFINE_TYPE(V9fsPath, v9fs_path_free);
 
+/* Translates errno from host -> Linux if needed */
+static int errno_to_dotl(int err) {
+#if defined(CONFIG_LINUX)
+    /* nothing to translate (Linux -> Linux) */
+#elif defined(CONFIG_DARWIN)
+    /* translation mandatory for macOS hosts */
+    if (err == ENAMETOOLONG) {
+        err = 36; /* ==ENAMETOOLONG on Linux */
+    } else if (err == ENOTEMPTY) {
+        err = 39; /* ==ENOTEMPTY on Linux */
+    } else if (err == ELOOP) {
+        err = 40; /* ==ELOOP on Linux */
+    } else if (err == ENOATTR) {
+        err = 61; /* ==ENODATA on Linux */
Quoted 8 lines

hw/9pfs/9p.c enum { · line 78

Quoted 5 lines
hw/9pfs/9p.c +5 -0
+    } else if (err == ENOTSUP) {
+        err = 95; /* ==EOPNOTSUPP on Linux */
+    } else if (err == EOPNOTSUPP) {
+        err = 95; /* ==EOPNOTSUPP on Linux */
+    }

I'm assuming you have audited all errnos, right ? Just to be sure that this won't bite anymore.

Quoted 6 lines

Depends on what you mean with "all". Like I wrote in the commit log, for now I translated in this patch those errnos that I identified as important, and those are audited by me of course (checked the man pages for what errors are expected as result from calls on Linux vs. macOS side and looked up numeric values from header files on both sides, tests).

I was pretty sure you'd have done that at least :-)

Quoted 5 lines

However if you rather mean really all errnos that were ever defined on Linux and macOS, then the answer is no. That would probably quite some work, and I'm not sure if you could just try to translate them dry, i.e. by just looking at the headers or something.

But yes I was rather meaning the full errno set.

Quoted 5 lines

So yes, your concern is justified. The question is, should this all be translated right now already, or would it be OK to address this minimum set of errno translation for now (especially for qemu-stable) and then later address the rest?

My concern is about the maintenance burden of investigating future implementations of this issue, so I'd say it is mostly up to you as the principal maintainer. Maybe leave a FIXME comment in the code that the list of translated errnos isn't exhaustive at least ?

Quoted 6 lines

On the long term you would probably import the Linux errno header file into the code base, then prefix the individual macros with something like DOTL_ENODATA, etc. and then use those macros for translating the errnos instead of using literal numerics, maybe using GCC's designated array initializers then.

This would make sense indeed since 9p2000.L explicitly mentions the numerical linux errnos.

Quoted 30 lines
Quoted 8 lines

hw/9pfs/9p.c enum { · line 84

Quoted 6 lines
hw/9pfs/9p.c +6 -0
+#else
+#error Missing errno translation to Linux for this host system
+#endif
+    return err;
+}
+

As with the other patch, I'd rather move this magic to 9p-util.h .

Makes sense. There is indeed already too much utility code piled up in 9p.c.

Quoted 17 lines
Quoted 17 lines
hw/9pfs/9p.c +0 -0
 static ssize_t pdu_marshal(V9fsPDU *pdu, size_t offset, const char *fmt,
 ...) {
 
     ssize_t ret;
hw/9pfs/9p.c +0 -0
@@ -1054,6 +1079,8 @@ static void coroutine_fn pdu_complete(V9fsPDU *pdu,

ssize_t len)>

             }
             len += ret;
             id = P9_RERROR;
hw/9pfs/9p.c +2 -0
+        } else {
+            err = errno_to_dotl(err);
 
         }
 
         ret = pdu_marshal(pdu, len, "d", err);
#21 lore raw

Re: [PATCH 4/5] 9pfs: fix wrong errno being sent to Linux client on macOS host

Quoted 27 lines · On Donnerstag, 21. April 2022 13:46:26 CEST Greg Kurz wrote:

On Thu, 21 Apr 2022 13:13:08 +0200

Quoted 24 lines · Christian Schoenebeck
Quoted 23 lines · On Donnerstag, 21. April 2022 12:48:35 CEST Greg Kurz wrote:

On Tue, 19 Apr 2022 13:41:59 +0200

Quoted 9 lines · Christian Schoenebeck

Linux and macOS only share some errno definitions with equal macro name and value. In fact most mappings for errno are completely different on the two systems.

This patch converts some important errno values from macOS host to corresponding Linux errno values before eventually sending such error codes along with Tlerror replies (if 9p2000.L is used that is), which fixes a bunch of misbehaviours when running a Linux client on macOS host.

This even fixes an actual protocol violation :

lerror -- return error code

size[4] Rlerror tag[2] ecode[4]

lerror replaces the reply message used in a successful call. ecode is a numerical Linux errno.
^^^^^^^^^^^^^^^^^^^^^

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

Taken from
https://github.com/chaos/diod/wiki/protocol#lerror----return-error-code

Again, something to add to the commit log?

IMHO a protocol violation is important enough to be mentioned but I'll leave it to you.

Ok, will do.

Quoted 66 lines
Quoted 46 lines
Quoted 37 lines
Quoted 37 lines

For instance this patch fixes:
mount -t 9p -o posixacl ...

on Linux guest if security_mode=mapped was used for 9p server, which refused to mount successfully, because macOS returned ENOATTR==93 when client tried to retrieve POSIX ACL xattrs, because errno 93 is defined as EPROTONOSUPPORT==93 on Linux, so Linux client believed that xattrs were not supported by filesystem on host in general.

---

 hw/9pfs/9p.c | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)
hw/9pfs/9p.c +14 -0
index d953035e1c..becc41cbfd 100644
@@ -57,6 +57,31 @@ enum {
 
 P9ARRAY_DEFINE_TYPE(V9fsPath, v9fs_path_free);
 
+/* Translates errno from host -> Linux if needed */
+static int errno_to_dotl(int err) {
+#if defined(CONFIG_LINUX)
+    /* nothing to translate (Linux -> Linux) */
+#elif defined(CONFIG_DARWIN)
+    /* translation mandatory for macOS hosts */
+    if (err == ENAMETOOLONG) {
+        err = 36; /* ==ENAMETOOLONG on Linux */
+    } else if (err == ENOTEMPTY) {
+        err = 39; /* ==ENOTEMPTY on Linux */
+    } else if (err == ELOOP) {
+        err = 40; /* ==ELOOP on Linux */
+    } else if (err == ENOATTR) {
+        err = 61; /* ==ENODATA on Linux */
Quoted 8 lines

hw/9pfs/9p.c enum { · line 78

Quoted 5 lines
hw/9pfs/9p.c +5 -0
+    } else if (err == ENOTSUP) {
+        err = 95; /* ==EOPNOTSUPP on Linux */
+    } else if (err == EOPNOTSUPP) {
+        err = 95; /* ==EOPNOTSUPP on Linux */
+    }

I'm assuming you have audited all errnos, right ? Just to be sure that this won't bite anymore.

Quoted 5 lines

Depends on what you mean with "all". Like I wrote in the commit log, for now I translated in this patch those errnos that I identified as important, and those are audited by me of course (checked the man pages for what errors are expected as result from calls on Linux vs. macOS side and looked up numeric values from header files on both sides, tests).

I was pretty sure you'd have done that at least :-)

Quoted 4 lines

However if you rather mean really all errnos that were ever defined on Linux and macOS, then the answer is no. That would probably quite some work, and I'm not sure if you could just try to translate them dry, i.e. by just looking at the headers or something.

But yes I was rather meaning the full errno set.

Quoted 4 lines

So yes, your concern is justified. The question is, should this all be translated right now already, or would it be OK to address this minimum set of errno translation for now (especially for qemu-stable) and then later address the rest?

Quoted 4 lines

My concern is about the maintenance burden of investigating future implementations of this issue, so I'd say it is mostly up to you as the principal maintainer. Maybe leave a FIXME comment in the code that the list of translated errnos isn't exhaustive at least ?

I stick to this minimal approach with FIXME comment then for now. I have tested this patch thoroughly on macOS and did not encounter similar issues. So I think it is good enough as first-aid patch at least.

The aforementioned case-insensitive filesystem issues are a higher priority from my PoV, because they trigger various misbehaviour in my tests.

Best regards,
Christian Schoenebeck

Quoted 41 lines
Quoted 6 lines

On the long term you would probably import the Linux errno header file into
the code base, then prefix the individual macros with something like DOTL_ENODATA, etc. and then use those macros for translating the errnos instead of using literal numerics, maybe using GCC's designated array initializers then.

This would make sense indeed since 9p2000.L explicitly mentions the numerical linux errnos.

Quoted 31 lines
Quoted 8 lines

hw/9pfs/9p.c enum { · line 84

Quoted 6 lines
hw/9pfs/9p.c +6 -0
+#else
+#error Missing errno translation to Linux for this host system
+#endif
+    return err;
+}
+

As with the other patch, I'd rather move this magic to 9p-util.h .

Makes sense. There is indeed already too much utility code piled up in 9p.c.>

Quoted 20 lines
Quoted 20 lines
hw/9pfs/9p.c +0 -0
 static ssize_t pdu_marshal(V9fsPDU *pdu, size_t offset, const char
 *fmt,
 ...) {
 
     ssize_t ret;
hw/9pfs/9p.c +0 -0
@@ -1054,6 +1079,8 @@ static void coroutine_fn pdu_complete(V9fsPDU
 *pdu,

ssize_t len)>

             }
             len += ret;
             id = P9_RERROR;
hw/9pfs/9p.c +2 -0
+        } else {
+            err = errno_to_dotl(err);
 
         }
 
         ret = pdu_marshal(pdu, len, "d", err);
#25 lore raw

Re: [PATCH 5/5] 9pfs: fix removing non-existent POSIX ACL xattr on macOS host

In reply to Christian Schoenebeck
Quoted 54 lines · On Thu, 21 Apr 2022 12:55:24 +0200 Christian Schoenebeck…
Quoted 53 lines · On Donnerstag, 21. April 2022 10:26:11 CEST Greg Kurz wrote:

On Tue, 19 Apr 2022 13:43:30 +0200

Quoted 21 lines · Christian Schoenebeck

When mapped POSIX ACL is used, we are ignoring errors when trying to remove a POSIX ACL xattr that does not exist. On Linux hosts we would get ENODATA in such cases, on macOS hosts however we get ENOATTR instead, so ignore ENOATTR errors as well.

This patch fixes e.g. a command on Linux guest like:
cp --preserve=mode old new

---

 hw/9pfs/9p-posix-acl.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
hw/9pfs/9p-posix-acl.c +0 -0
index eadae270dd..2bf155f941 100644
@@ -65,7 +65,13 @@ static int mp_pacl_removexattr(FsContext *ctx,
 
     int ret;

hw/9pfs/9p-posix-acl.c static int mp_pacl_removexattr(FsContext *ctx, · line 75

Quoted 10 lines
hw/9pfs/9p-posix-acl.c +6 -1
 
     ret = local_removexattr_nofollow(ctx, path, MAP_ACL_ACCESS);
 
-    if (ret == -1 && errno == ENODATA) {
+    if (ret == -1 &&
+          (errno == ENODATA
+#ifdef ENOATTR
+          || errno == ENOATTR
+#endif
+          )

We already have this in <qemu/xattr.h> which is included by 9p-posix-acl.c :

/*
* Modern distributions (e.g. Fedora 15), have no libattr.so, place attr.h
* in /usr/include/sys, and don't have ENOATTR.
*/

#ifdef CONFIG_LIBATTR
# include <attr/xattr.h>
#else
# if !defined(ENOATTR)
# define ENOATTR ENODATA
# endif
# include <sys/xattr.h>
#endif

Quoted 7 lines
Quoted 2 lines

I guess this patch could just s/ENODATA/ENOATTR/ to avoid the extra ifdefery.

Not viable, because macOS does have both ENODATA==96 and ENOATTR==93. On Linux the two macros were historically defined to the same numeric values, that's why it worked there.

I was meaning your current fix could simply do:

- if (ret == -1 && errno == ENODATA) {
+ if (ret == -1 && errno == ENOATTR) {

since ENOATTR works in all cases, but this is rather a hack.

Another solution would be to ensure that local_removexattr_nofollow() only reports linux errnos. This could be handled cleanly in the fremovexattrat_nofollow() implementation in 9p-util-darwin.c.

Since the 9p code base mostly assumes the host is linux, this should probably be generalized to other places where we check errno.

Quoted 18 lines

Maybe I should define a separate macro like:

#if ...

# define P9_ENOATTR ENOATTR
#else
# define P9_ENOATTR ENODATA
#end

?

Actually good that you pointed me at this, because I just realized there is a 2nd place in 9p-posix-acl.c which would require this as well. For some reason the 2nd place just did not trigger while I was testing it on macOS.

Best regards,
Christian Schoenebeck

#26 lore raw

Re: [PATCH 5/5] 9pfs: fix removing non-existent POSIX ACL xattr on macOS host

Quoted 70 lines · On Donnerstag, 21. April 2022 14:26:37 CEST Greg Kurz wrote:

On Thu, 21 Apr 2022 12:55:24 +0200

Quoted 55 lines · Christian Schoenebeck
Quoted 54 lines · On Donnerstag, 21. April 2022 10:26:11 CEST Greg Kurz wrote:

On Tue, 19 Apr 2022 13:43:30 +0200

Quoted 21 lines · Christian Schoenebeck

When mapped POSIX ACL is used, we are ignoring errors when trying to remove a POSIX ACL xattr that does not exist. On Linux hosts we would get ENODATA in such cases, on macOS hosts however we get ENOATTR instead, so ignore ENOATTR errors as well.

This patch fixes e.g. a command on Linux guest like:
cp --preserve=mode old new

---

 hw/9pfs/9p-posix-acl.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
hw/9pfs/9p-posix-acl.c +0 -0
index eadae270dd..2bf155f941 100644
@@ -65,7 +65,13 @@ static int mp_pacl_removexattr(FsContext *ctx,
 
     int ret;

hw/9pfs/9p-posix-acl.c static int mp_pacl_removexattr(FsContext *ctx, · line 75

Quoted 10 lines
hw/9pfs/9p-posix-acl.c +6 -1
 
     ret = local_removexattr_nofollow(ctx, path, MAP_ACL_ACCESS);
 
-    if (ret == -1 && errno == ENODATA) {
+    if (ret == -1 &&
+          (errno == ENODATA
+#ifdef ENOATTR
+          || errno == ENOATTR
+#endif
+          )

We already have this in <qemu/xattr.h> which is included by 9p-posix-acl.c :

/*

* Modern distributions (e.g. Fedora 15), have no libattr.so, place attr.h
* in /usr/include/sys, and don't have ENOATTR.
*/

#ifdef CONFIG_LIBATTR
# include <attr/xattr.h>
#else
# if !defined(ENOATTR)
# define ENOATTR ENODATA
# endif
# include <sys/xattr.h>
#endif

Quoted 6 lines
Quoted 2 lines

I guess this patch could just s/ENODATA/ENOATTR/ to avoid the extra ifdefery.

Not viable, because macOS does have both ENODATA==96 and ENOATTR==93. On Linux the two macros were historically defined to the same numeric values, that's why it worked there.

I was meaning your current fix could simply do:

(quoted diff) +1 -1
-    if (ret == -1 && errno == ENODATA) {
+    if (ret == -1 && errno == ENOATTR) {
Quoted 8 lines

since ENOATTR works in all cases, but this is rather a hack.

Another solution would be to ensure that local_removexattr_nofollow() only reports linux errnos. This could be handled cleanly in the fremovexattrat_nofollow() implementation in 9p-util-darwin.c.

Since the 9p code base mostly assumes the host is linux, this should probably be generalized to other places where we check errno.

Got it. I tend to go with the former (checking errno == ENOATTR and defining ENOATTR if non existent). I find that a bit cleaner than the latter which would have the potential to mask another error (ENODATA).

Quoted 17 lines
Quoted 17 lines

Maybe I should define a separate macro like:

#if ...

# define P9_ENOATTR ENOATTR
#else
# define P9_ENOATTR ENODATA
#end

?

Actually good that you pointed me at this, because I just realized there is a 2nd place in 9p-posix-acl.c which would require this as well. For some reason the 2nd place just did not trigger while I was testing it on macOS.

Best regards,
Christian Schoenebeck