All of lore.kernel.org
 help / color / mirror / Atom feed
From: Bin Meng <bmeng.cn@gmail.com>
To: Christian Schoenebeck <qemu_oss@crudebyte.com>,
	Greg Kurz <groug@kaod.org>,
	qemu-devel@nongnu.org
Cc: Bin Meng <bin.meng@windriver.com>,
	Guohuai Shi <guohuai.shi@windriver.com>
Subject: [PATCH 9/9] hw/9p: win32: Translate Windows error number to Linux value
Date: Mon, 25 Apr 2022 22:27:05 +0800	[thread overview]
Message-ID: <20220425142705.2099270-10-bmeng.cn@gmail.com> (raw)
In-Reply-To: <20220425142705.2099270-1-bmeng.cn@gmail.com>

From: Guohuai Shi <guohuai.shi@windriver.com>

Some of Windows error numbers have different value from Linux ones.
For example, ENOTEMPTY is defined to 39 in Linux, but is defined to
41 in Windows. So deleting a directory from a Linux guest on top
of QEMU from a Windows host complains:

  # rmdir tmp
  rmdir: 'tmp': Unknown error 41

This commit provides error number traslation from Windows to Linux.
It can make Linux guest OS happy with the error number when running
on top of QEMU from a Windows host.

This has a side effet that it requires all guest OSes' 9pfs drivers
to use the same errno.

It looks like macOS has different errno too so using 9p in a Linux
on top of QEMU from a macOS host may also fail in the above case.
I suspect we only tested 9p from a macOS guest on top of QEMU from
a macOS host, so this issue was not exposed.

I am not aware of Windows's native support for 9pfs so I think using
the Linux errnor as the standard is probably okay, but I am open for
suggestions.

Signed-off-by: Guohuai Shi <guohuai.shi@windriver.com>
Signed-off-by: Bin Meng <bin.meng@windriver.com>
---

 hw/9pfs/9p.h            |  4 ++++
 hw/9pfs/9p-util-win32.c | 38 ++++++++++++++++++++++++++++++++++++++
 hw/9pfs/9p.c            |  7 +++++++
 3 files changed, 49 insertions(+)

diff --git a/hw/9pfs/9p.h b/hw/9pfs/9p.h
index 87e8eac840..db2013d549 100644
--- a/hw/9pfs/9p.h
+++ b/hw/9pfs/9p.h
@@ -490,6 +490,10 @@ void pdu_free(V9fsPDU *pdu);
 void pdu_submit(V9fsPDU *pdu, P9MsgHeader *hdr);
 void v9fs_reset(V9fsState *s);
 
+#ifdef CONFIG_WIN32
+int errno_translate_win32(int errno_win32);
+#endif
+
 struct V9fsTransport {
     ssize_t     (*pdu_vmarshal)(V9fsPDU *pdu, size_t offset, const char *fmt,
                                 va_list ap);
diff --git a/hw/9pfs/9p-util-win32.c b/hw/9pfs/9p-util-win32.c
index d9b35e7425..c4f90c6503 100644
--- a/hw/9pfs/9p-util-win32.c
+++ b/hw/9pfs/9p-util-win32.c
@@ -20,6 +20,11 @@
 #define V9FS_MAGIC 0x53465039 /* string "9PFS" */
 #endif
 
+struct translate_map {
+    int output;     /* Linux error number */
+    int input;      /* Windows error number */
+};
+
 static int build_ads_name(char *namebuf, size_t namebuflen,
                           const char *dirname, const char *filename,
                           const char *ads_name)
@@ -301,3 +306,36 @@ int qemu_statfs(const char *fs_root, struct statfs *stbuf)
 
     return 0;
 }
+
+int errno_translate_win32(int errno_win32)
+    {
+    unsigned int i;
+
+    /*
+     * The translation table only contains values which could be returned
+     * as a result of a filesystem operation, i.e. network/socket related
+     * errno values need not be considered for translation.
+     */
+    static struct translate_map errno_map[] = {
+        /* Linux errno          Windows errno   */
+        { L_EDEADLK,            EDEADLK         },
+        { L_ENAMETOOLONG,       ENAMETOOLONG    },
+        { L_ENOLCK,             ENOLCK          },
+        { L_ENOSYS,             ENOSYS          },
+        { L_ENOTEMPTY,          ENOTEMPTY       },
+        { L_EILSEQ,             EILSEQ          },
+        { L_ELOOP,              ELOOP           },
+    };
+
+    /* scan errno_win32 table for a matching Linux errno value */
+
+    for (i = 0; i < sizeof(errno_map) / sizeof(errno_map[0]); i++) {
+        if (errno_win32 == errno_map[i].input) {
+            return errno_map[i].output;
+        }
+    }
+
+    /* no translation necessary */
+
+    return errno_win32;
+    }
diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c
index a04889c1d6..0a9c0a509e 100644
--- a/hw/9pfs/9p.c
+++ b/hw/9pfs/9p.c
@@ -1062,6 +1062,13 @@ static void coroutine_fn pdu_complete(V9fsPDU *pdu, ssize_t len)
             id = P9_RERROR;
         }
 
+#ifdef CONFIG_WIN32
+        /*
+         * Some Windows errnos have different value from Linux,
+         * and they need to be translated to the Linux value.
+         */
+        err = errno_translate_win32(err);
+#endif
         ret = pdu_marshal(pdu, len, "d", err);
         if (ret < 0) {
             goto out_notify;
-- 
2.25.1



  parent reply	other threads:[~2022-04-25 14:50 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-25 14:26 [PATCH 0/9] 9pfs: Add 9pfs support for Windows host Bin Meng
2022-04-25 14:26 ` [PATCH 1/9] hw/9pfs: Compile 9p-local.c and 9p-proxy.c for Linux and macOS Bin Meng
2022-04-25 14:26 ` [PATCH 2/9] qemu/xatth.h: Update for Windows build Bin Meng
2022-04-25 14:26 ` [PATCH 3/9] hw/9pfs: Extract common stuff to 9p-local.h Bin Meng
2022-04-25 14:27 ` [PATCH 4/9] fsdev: Add missing definitions for Windows in file-op-9p.h Bin Meng
2022-05-04 17:35   ` Christian Schoenebeck
2022-04-25 14:27 ` [PATCH 5/9] hw/9pfs: Add a 'local' file system backend driver for Windows Bin Meng
2022-05-04 18:01   ` Christian Schoenebeck
2022-05-04 19:34     ` Shi, Guohuai
2022-05-05 11:43       ` Christian Schoenebeck
2022-05-06  6:46         ` Shi, Guohuai
2022-05-09 14:29   ` Greg Kurz
2022-05-09 15:09     ` Shi, Guohuai
2022-05-09 16:20       ` Greg Kurz
2022-05-10  2:13         ` Shi, Guohuai
2022-05-10  2:17           ` Shi, Guohuai
2022-05-10 10:18             ` Christian Schoenebeck
2022-05-10 11:54               ` Christian Schoenebeck
2022-05-10 13:40                 ` Greg Kurz
2022-05-10 14:04                   ` Christian Schoenebeck
2022-05-10 14:34                     ` Greg Kurz
2022-05-10 15:35                       ` Shi, Guohuai
2022-05-11 11:18                         ` Christian Schoenebeck
2022-05-11 12:18                         ` Greg Kurz
2022-05-11 15:57                           ` Shi, Guohuai
2022-05-24 12:23                             ` Christian Schoenebeck
2022-04-25 14:27 ` [PATCH 6/9] hw/9pfs: Update 9p-synth.c for Windows build Bin Meng
2022-04-25 14:27 ` [PATCH 7/9] fsdev: Enable 'local' file system driver backend for Windows Bin Meng
2022-04-25 14:27 ` [PATCH 8/9] meson.build: Turn on virtfs for Windows host Bin Meng
2022-04-25 14:27 ` Bin Meng [this message]
2022-05-04 18:15   ` [PATCH 9/9] hw/9p: win32: Translate Windows error number to Linux value Christian Schoenebeck
2022-04-26  1:41 ` [PATCH 0/9] 9pfs: Add 9pfs support for Windows host Bin Meng
2022-05-03  3:42   ` Bin Meng
2022-05-04 17:16     ` Christian Schoenebeck

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220425142705.2099270-10-bmeng.cn@gmail.com \
    --to=bmeng.cn@gmail.com \
    --cc=bin.meng@windriver.com \
    --cc=groug@kaod.org \
    --cc=guohuai.shi@windriver.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu_oss@crudebyte.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is 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.