Add initial 9pfs support for Windows hosts
RFC PATCH 1/1 Add initial 9pfs support for Windows hosts
It was tested on Windows & Linux hosts, on the later no obvious regressions could be found. The guest was a Knoppix 7.6.0 live cd.
This is WIP and a RFC - it isn't meant to be upstreamed yet. The error_printf are only for debugging and will be deleted in the final patch.
There are some comments with "mifritscher" - I'm not quite sure how to handle these problems (e.g. on mingw, this in 32 bit, while on Linux this is 16 bit and so on). Additionally, some places from which I suspect problems are marked with a #warning.
What works:
* mount
* stat
* chdir
* readdir (aka ls)
* read of small files (<10k)
* overwrite
What does not work:
* create new files (in 90% problems with path handling (old path occurs)
* read / probably write big files
TODO:
* fix broken functionality
* test & fix mapped permission style
* prepend a 777 on all files if security modell "NONE"
* test everything - on Windows and Linux
---
Many thanks to Stefan Weil for supporting me!
Makefile.objs | 1 + configure | 15 +++- fsdev/9p-iov-marshal.c | 2 + fsdev/9p-marshal.c | 4 +- fsdev/file-op-9p.h | 35 +++++++- fsdev/qemu-fsdev.c | 2 + hw/9pfs/9p-local.c | 200 +++++++++++++++++++++++++++++++++++++++++---- hw/9pfs/9p-synth.c | 10 ++- hw/9pfs/9p.c | 99 ++++++++++++++++++++-- hw/9pfs/9p.h | 70 +++++++++++++++- hw/9pfs/Makefile.objs | 7 +- hw/9pfs/codir.c | 35 ++++++++ hw/9pfs/cofile.c | 15 ++++ hw/9pfs/cofs.c | 15 ++++ hw/9pfs/virtio-9p-device.c | 4 +- 15 files changed, 478 insertions(+), 36 deletions(-)
Makefile.objs +1 -0
@@ -48,6 +48,7 @@ common-obj-$(CONFIG_WIN32) += os-win32.o common-obj-$(CONFIG_POSIX) += os-posix.o common-obj-$(CONFIG_LINUX) += fsdev/ +common-obj-$(CONFIG_WIN32) += fsdev/ common-obj-y += migration/ common-obj-y += qemu-char.o #aio.o
configure +12 -3
@@ -4566,12 +4566,21 @@ if test "$want_tools" = "yes" ; then fi if test "$softmmu" = yes ; then if test "$virtfs" != no ; then - if test "$cap" = yes && test "$linux" = yes && test "$attr" = yes ; then + if test "$linux" = yes ; then + if test "$cap" = yes && test "$attr" = yes ; then + virtfs=yes + tools="$tools fsdev/virtfs-proxy-helper\$(EXESUF)" + else + if test "$virtfs" = yes; then + error_exit "VirtFS requires libcap-devel and libattr-devel on Linux" + fi + virtfs=no + fi + elif test "$mingw32" = yes; then virtfs=yes - tools="$tools fsdev/virtfs-proxy-helper\$(EXESUF)" else if test "$virtfs" = yes; then - error_exit "VirtFS is supported only on Linux and requires libcap-devel and libattr-devel" + error_exit "VirtFS is only supported on Linux or Windows" fi virtfs=no fi
fsdev/9p-iov-marshal.c +2 -0
@@ -15,7 +15,9 @@#include <glib.h> #include <glib/gprintf.h> #include <utime.h> +#ifndef _WIN32#include <sys/uio.h> +#endif #include "9p-iov-marshal.h" #include "qemu/bswap.h"
fsdev/9p-marshal.c +3 -1
@@ -16,7 +16,9 @@#include <glib/gprintf.h> #include <dirent.h> #include <utime.h> -#include <sys/uio.h> +#ifndef WIN32 +#include <sys/uio.h> +#endif #include "9p-marshal.h"
fsdev/file-op-9p.h +33 -2
@@ -14,12 +14,43 @@#define _FILEOP_H#include <dirent.h> #include <utime.h> -#include <sys/uio.h> -#include <sys/vfs.h> +#ifndef _WIN32 +#include <sys/uio.h> +#include <sys/vfs.h> +#endif #define SM_LOCAL_MODE_BITS 0600#define SM_LOCAL_DIR_MODE_BITS 0700 +#ifdef _WIN32 +typedef uint32_t uid_t ; +typedef uint32_t gid_t ; + +/* from http://man7.org/linux/man-pages/man2/statfs.2.html */ +typedef uint32_t __fsword_t ; +typedef uint32_t fsblkcnt_t ; +typedef uint32_t fsfilcnt_t ; + +/* from linux/include/uapi/asm-generic/posix_types.h */ +typedef struct { +long __val[2 ]; +}fsid_t ; + +struct statfs { +__fsword_t f_type; +__fsword_t f_bsize; +fsblkcnt_t f_blocks; +fsblkcnt_t f_bfree; +fsblkcnt_t f_bavail; +fsfilcnt_t f_files; +fsfilcnt_t f_ffree; +fsid_t f_fsid; +__fsword_t f_namelen; +__fsword_t f_frsize; +__fsword_t f_flags; +}; +#endif + typedef struct FsCred { uid_t fc_uid;
fsdev/qemu-fsdev.c +2 -0
@@ -26,7 +26,9 @@ static FsDriverTable FsDrivers[] = { { .name = "handle", .ops = &handle_ops}, #endif { .name = "synth", .ops = &synth_ops}, +#ifndef WIN32 { .name = "proxy", .ops = &proxy_ops}, +#endif }; int qemu_fsdev_add(QemuOpts *opts)
hw/9pfs/9p-local.c +182 -18
410 lines not on this page · raw message
hw/9pfs/9p-synth.c +9 -1
@@ -15,7 +15,9 @@#include "qemu/osdep.h" #include "hw/virtio/virtio.h" #include "9p.h" -#include "9p-xattr.h" +#ifndef _WIN32 +#include "9p-xattr.h" +#endif #include "fsdev/qemu-fsdev.h" #include "9p-synth.h" #include "qemu/rcu.h"
@@ -152,8 +154,10 @@ static void v9fs_synth_fill_statbuf(V9fsSynthNode *node, struct stat *stbuf) stbuf->st_gid =0 ; stbuf->st_rdev =0 ; stbuf->st_size =0 ; +#ifndef _WIN32 stbuf->st_blksize =0 ; stbuf->st_blocks =0 ; +#endif stbuf->st_atime =0 ; stbuf->st_mtime =0 ; stbuf->st_ctime =0 ;
@@ -222,7 +226,11 @@ static void v9fs_synth_direntry(V9fsSynthNode *node, {strcpy (entry->d_name, node->name); entry->d_ino = node->attr->inode; +#ifdef _WIN32 +#warning "Can cause problems!" +#else entry->d_off = off +1 ; +#endif } static int v9fs_synth_get_dentry(V9fsSynthNode *dir, struct dirent *entry,
hw/9pfs/9p.c +94 -5
269 lines not on this page · raw message
hw/9pfs/9p.h +68 -2
90 lines not on this page · raw message
hw/9pfs/Makefile.objs +4 -3
@@ -1,9 +1,10 @@ common-obj-y = 9p.o -common-obj-y += 9p-local.o 9p-xattr.o -common-obj-y += 9p-xattr-user.o 9p-posix-acl.o +common-obj-$(CONFIG_LINUX) += 9p-local.o 9p-xattr.o +common-obj-$(CONFIG_LINUX) += 9p-xattr-user.o 9p-posix-acl.o +common-obj-$(CONFIG_WIN32) += 9p-local.o common-obj-y += coth.o cofs.o codir.o cofile.o common-obj-y += coxattr.o 9p-synth.o common-obj-$(CONFIG_OPEN_BY_HANDLE) += 9p-handle.o -common-obj-y += 9p-proxy.o +common-obj-$(CONFIG_POSIX) += 9p-proxy.o obj-y += virtio-9p-device.o
hw/9pfs/codir.c +35 -0
@@ -17,6 +17,8 @@#include "qemu/thread.h" #include "qemu/coroutine.h" #include "coth.h" +/* mifritscher: after killing the debug printf, kill this as well! */ +#include "qemu/error-report.h" int v9fs_co_readdir_r (V9fsPDU *pdu,V9fsFidState *fidp,struct dirent *dent,struct dirent **result)
@@ -37,6 +39,12 @@ int v9fs_co_readdir_r(V9fsPDU *pdu, V9fsFidState *fidp, struct dirent *dent, err =0 ; } }); +#ifdef _WIN32 +error_printf ("v9fs_co_readdir_r: %s %d %p\n" , + (&fidp->fs)->dir->dd_name, err, *result); +#else +error_printf ("v9fs_co_readdir_r: %d %p\n" , err, *result); +#endif return err; }
@@ -55,6 +63,12 @@ off_t v9fs_co_telldir(V9fsPDU *pdu, V9fsFidState *fidp) err = -errno; } }); +#ifdef _WIN32 +error_printf ("v9fs_co_telldir_r: %s %lld\n" , + (&fidp->fs)->dir->dd_name, err); +#else +error_printf ("v9fs_co_telldir_r: %ld\n" , err); +#endif return err; }
@@ -68,6 +82,11 @@ void v9fs_co_seekdir(V9fsPDU *pdu, V9fsFidState *fidp, off_t offset) { s->ops->seekdir (&s->ctx, &fidp->fs, offset); }); +#ifdef _WIN32 +error_printf ("v9fs_co_seekdir: %s\n" , (&fidp->fs)->dir->dd_name); +#else +error_printf ("v9fs_co_seekdir\n" ); +#endif }void v9fs_co_rewinddir (V9fsPDU *pdu,V9fsFidState *fidp)
@@ -80,6 +99,11 @@ void v9fs_co_rewinddir(V9fsPDU *pdu, V9fsFidState *fidp) { s->ops->rewinddir (&s->ctx, &fidp->fs); }); +#ifdef _WIN32 +error_printf ("v9fs_co_rewinddir: %s\n" , (&fidp->fs)->dir->dd_name); +#else +error_printf ("v9fs_co_rewinddir\n" ); +#endif } int v9fs_co_mkdir(V9fsPDU *pdu, V9fsFidState *fidp, V9fsString *name,
@@ -116,6 +140,11 @@ int v9fs_co_mkdir(V9fsPDU *pdu, V9fsFidState *fidp, V9fsString *name, } });v9fs_path_unlock (s); +#ifdef _WIN32 +error_printf ("v9fs_co_mkdir: %s %d\n" , (&fidp->fs)->dir->dd_name, err); +#else +error_printf ("v9fs_co_mkdir: %d\n" , err); +#endif return err; }
@@ -144,6 +173,11 @@ int v9fs_co_opendir(V9fsPDU *pdu, V9fsFidState *fidp)v9fs_reclaim_fd (pdu); } } +#ifdef _WIN32 +error_printf ("v9fs_co_opendir: %s %d\n" , (&fidp->fs)->dir->dd_name, err); +#else +error_printf ("v9fs_co_opendir: %d\n" , err); +#endif return err; }
@@ -165,5 +199,6 @@ int v9fs_co_closedir(V9fsPDU *pdu, V9fsFidOpenState *fs)if (!err) { total_open_fd--; } +error_printf ("v9fs_co_closedir: %d\n" , err);return err; }
hw/9pfs/cofile.c +15 -0
@@ -17,6 +17,8 @@#include "qemu/thread.h" #include "qemu/coroutine.h" #include "coth.h" +/* mifritscher: after killing the debug printf, kill this as well! */ +#include "qemu/error-report.h" int v9fs_co_st_gen (V9fsPDU *pdu,V9fsPath *path,mode_t st_mode,V9fsStatDotl *v9stat)
@@ -39,6 +41,7 @@ int v9fs_co_st_gen(V9fsPDU *pdu, V9fsPath *path, mode_t st_mode, });v9fs_path_unlock (s); } +error_printf ("v9fs_co_st_gen: %d\n" , err);return err; }
@@ -59,6 +62,7 @@ int v9fs_co_lstat(V9fsPDU *pdu, V9fsPath *path, struct stat *stbuf) } });v9fs_path_unlock (s); +error_printf ("v9fs_co_lstat: %d\n" , err);return err; }
@@ -91,6 +95,7 @@ int v9fs_co_fstat(V9fsPDU *pdu, V9fsFidState *fidp, struct stat *stbuf) err =0 ; } } +error_printf ("v9fs_co_fstat: %s %d\n" , (&fidp->path)->data, err);return err; }
@@ -119,6 +124,7 @@ int v9fs_co_open(V9fsPDU *pdu, V9fsFidState *fidp, int flags)v9fs_reclaim_fd (pdu); } } +error_printf ("v9fs_co_open: %s %d\n" , (&fidp->path)->data, err);return err; }
@@ -147,13 +153,17 @@ int v9fs_co_open2(V9fsPDU *pdu, V9fsFidState *fidp, V9fsString *name, gid_t gid, { err = s->ops->open2 (&s->ctx, &fidp->path, name->data, flags, &cred, &fidp->fs); +error_printf ("v9fs_co_open2: open returned %d\n" , err);if (err <0 ) { err = -errno; }else {v9fs_path_init (&path); err =v9fs_name_to_path (s, &fidp->path, name->data, &path); +error_printf ("v9fs_co_open2: v9fs_name_to_path returned %d\n" , + err);if (!err) { err = s->ops->lstat (&s->ctx, &path, stbuf); +error_printf ("v9fs_co_open2: lstat returned %d\n" , err);if (err <0 ) { err = -errno; s->ops->close (&s->ctx, &fidp->fs);
@@ -173,6 +183,7 @@ int v9fs_co_open2(V9fsPDU *pdu, V9fsFidState *fidp, V9fsString *name, gid_t gid,v9fs_reclaim_fd (pdu); } } +error_printf ("v9fs_co_open2: %s %d\n" , (&fidp->path)->data, err);return err; }
@@ -194,6 +205,7 @@ int v9fs_co_close(V9fsPDU *pdu, V9fsFidOpenState *fs)if (!err) { total_open_fd--; } +error_printf ("v9fs_co_close: %d\n" , err);return err; }
@@ -234,6 +246,7 @@ int v9fs_co_link(V9fsPDU *pdu, V9fsFidState *oldfid, } });v9fs_path_unlock (s); +error_printf ("v9fs_co_link: %d\n" , err);return err; }
@@ -253,6 +266,7 @@ int v9fs_co_pwritev(V9fsPDU *pdu, V9fsFidState *fidp, err = -errno; } }); +error_printf ("v9fs_co_pwritev: %s %d\n" , (&fidp->path)->data, err);return err; }
@@ -272,5 +286,6 @@ int v9fs_co_preadv(V9fsPDU *pdu, V9fsFidState *fidp, err = -errno; } }); +error_printf ("v9fs_co_preadv: %s %d\n" , (&fidp->path)->data, err);return err; }
hw/9pfs/cofs.c +15 -0
@@ -17,6 +17,8 @@#include "qemu/thread.h" #include "qemu/coroutine.h" #include "coth.h" +/* mifritscher: after killing the debug printf, kill this as well! */ +#include "qemu/error-report.h" static ssize_t __readlink (V9fsState *s,V9fsPath *path,V9fsString *buf) {
@@ -67,6 +69,7 @@ int v9fs_co_readlink(V9fsPDU *pdu, V9fsPath *path, V9fsString *buf) } });v9fs_path_unlock (s); +error_printf ("v9fs_co_readlink: %d\n" , err);return err; }
@@ -87,6 +90,7 @@ int v9fs_co_statfs(V9fsPDU *pdu, V9fsPath *path, struct statfs *stbuf) } });v9fs_path_unlock (s); +error_printf ("v9fs_co_statfs: %d\n" , err);return err; }
@@ -110,6 +114,7 @@ int v9fs_co_chmod(V9fsPDU *pdu, V9fsPath *path, mode_t mode) } });v9fs_path_unlock (s); +error_printf ("v9fs_co_chmod: %d\n" , err);return err; }
@@ -131,6 +136,7 @@ int v9fs_co_utimensat(V9fsPDU *pdu, V9fsPath *path, } });v9fs_path_unlock (s); +error_printf ("v9fs_co_utimensat: %d\n" , err);return err; }
@@ -155,6 +161,7 @@ int v9fs_co_chown(V9fsPDU *pdu, V9fsPath *path, uid_t uid, gid_t gid) } });v9fs_path_unlock (s); +error_printf ("v9fs_co_chown: %d\n" , err);return err; }
@@ -175,6 +182,7 @@ int v9fs_co_truncate(V9fsPDU *pdu, V9fsPath *path, off_t size) } });v9fs_path_unlock (s); +error_printf ("v9fs_co_truncate: %d\n" , err);return err; }
@@ -213,6 +221,7 @@ int v9fs_co_mknod(V9fsPDU *pdu, V9fsFidState *fidp, V9fsString *name, uid_t uid, } });v9fs_path_unlock (s); +error_printf ("v9fs_co_mknod: %d\n" , err);return err; }
@@ -234,6 +243,7 @@ int v9fs_co_remove(V9fsPDU *pdu, V9fsPath *path) } });v9fs_path_unlock (s); +error_printf ("v9fs_co_remove: %d\n" , err);return err; }
@@ -254,6 +264,7 @@ int v9fs_co_unlinkat(V9fsPDU *pdu, V9fsPath *path, V9fsString *name, int flags) } });v9fs_path_unlock (s); +error_printf ("v9fs_co_unlinkat: %d\n" , err);return err; }
@@ -273,6 +284,7 @@ int v9fs_co_rename(V9fsPDU *pdu, V9fsPath *oldpath, V9fsPath *newpath) err = -errno; } }); +error_printf ("v9fs_co_rename: %d\n" , err);return err; }
@@ -293,6 +305,7 @@ int v9fs_co_renameat(V9fsPDU *pdu, V9fsPath *olddirpath, V9fsString *oldname, err = -errno; } }); +error_printf ("v9fs_co_renameat: %d\n" , err);return err; }
@@ -331,6 +344,7 @@ int v9fs_co_symlink(V9fsPDU *pdu, V9fsFidState *dfidp, V9fsString *name, } });v9fs_path_unlock (s); +error_printf ("v9fs_co_symlink: %d\n" , err);return err; }
@@ -361,5 +375,6 @@ int v9fs_co_name_to_path(V9fsPDU *pdu, V9fsPath *dirpath, } }); } +error_printf ("v9fs_co_name_to_path: %d\n" , err);return err; }
hw/9pfs/virtio-9p-device.c +3 -1
@@ -17,7 +17,9 @@#include "qemu/sockets.h" #include "virtio-9p.h" #include "fsdev/qemu-fsdev.h" -#include "9p-xattr.h" +#ifndef WIN32 +#include "9p-xattr.h" +#endif #include "coth.h" #include "hw/virtio/virtio-access.h" #include "qemu/iov.h"
Signature · 1 line
2.7.4