W32, W64 msys2/mingw patches
Subsystems (2)
v7 cover W32, W64 msys2/mingw patches
It first introduce msys2 CI on cirrus by fixes nfs, capstone, curses and disable partial test-char tests.
And then fixes all unit tests failure on msys2/mingw
This fixes the reviews suggested in the mailling list
Kevin Wolf (1):
file-win32: Fix "locking" option
Maxim Levitsky (1):
rcu: Implement drain_call_rcu
Yonggang Luo (23):
block: Fixes nfs compiling error on msys2/mingw
ci: fixes msys2 build by upgrading capstone to 4.0.2
configure: Fixes ncursesw detection under msys2/mingw and enable
curses
win32: Simplify gmtime_r detection direct base on
_POSIX_THREAD_SAFE_FUNCTIONS.
curses: Fixes curses compiling errors.
tests: disable /char/stdio/* tests in test-char.c on win32
tests: Fixes test-replication.c on msys2/mingw.
tests: test-replication disable /replication/secondary/* on
msys2/mingw.
osdep: file locking functions are not available on Win32
meson: Use -b to ignore CR vs. CR-LF issues on Windows
gcrypt: test_tls_psk_init should write binary file instead text file.
tests: Enable crypto tests under msys2/mingw
meson: remove empty else and duplicated gio deps
vmstate: Fixes test-vmstate.c on msys2/mingw
cirrus: Building freebsd in a single short
tests: Convert g_free to g_autofree macro in test-logging.c
tests: Fixes test-io-channel-socket.c tests under msys2/mingw
tests: fixes aio-win32 about aio_remove_fd_handler, get it consistence
with aio-posix.c
tests: Fixes test-io-channel-file by mask only owner file state mask
bits
tests: fix test-util-sockets.c
tests: Fixes test-qdev-global-props.c
rcu: fixes test-logging.c by call drain_call_rcu before rmdir_full
ci: Enable msys2 ci in cirrus
.cirrus.yml | 95 ++++++++++++----- block/file-win32.c | 22 +++- block/nfs.c | 32 ++++-- capstone | 2 +- configure | 61 +++-------- include/qemu/osdep.h | 2 +- include/qemu/rcu.h | 1 + include/sysemu/os-win32.h | 4 +- meson.build | 6 -- tests/crypto-tls-psk-helpers.c | 6 +- tests/crypto-tls-x509-helpers.c | 169 ++++++++++++++++++++++++++++++- tests/crypto-tls-x509-helpers.h | 9 +- tests/qapi-schema/meson.build | 2 +- tests/test-char.c | 26 +++-- tests/test-crypto-tlscredsx509.c | 47 +++++---- tests/test-crypto-tlssession.c | 68 +++++++------ tests/test-io-channel-file.c | 10 +- tests/test-io-channel-socket.c | 2 + tests/test-io-channel-tls.c | 51 ++++++---- tests/test-logging.c | 5 +- tests/test-qdev-global-props.c | 6 +- tests/test-replication.c | 22 +++- tests/test-util-sockets.c | 6 +- tests/test-vmstate.c | 3 +- ui/curses.c | 14 +-- util/aio-win32.c | 11 +- util/oslib-win32.c | 2 +- util/rcu.c | 55 ++++++++++ 28 files changed, 536 insertions(+), 203 deletions(-)
Signature · 1 line
2.28.0.windows.1
PATCH v7 1/25 file-win32: Fix "locking" option
From: Kevin Wolf <[email protected]>
The intended behaviour was that locking=off/auto work and have no effect (to remain compatible with file-posix), whereas locking=on would return an error. Unfortunately, the code forgot to remove "locking" from the options QDict, so any attempt to use the option would fail.
Replace the option parsing code for "locking" with something that is part of the raw_runtime_opts QemuOptsList (so it is properly removed from the QDict) and looks more like file-posix.
Message-Id: <[email protected]>
--- block/file-win32.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-)
block/file-win32.c +21 -1
@@ -299,6 +299,11 @@ static QemuOptsList raw_runtime_opts = { .type = QEMU_OPT_STRING, .help = "host AIO implementation (threads, native)", }, + { + .name = "locking", + .type = QEMU_OPT_STRING, + .help = "file locking mode (on/off/auto, default: auto)", + }, {/* end of list */ } }, };
@@ -333,6 +338,7 @@ static int raw_open(BlockDriverState *bs, QDict *options, int flags,Error *local_err =NULL ;const char *filename;bool use_aio; +OnOffAuto locking;int ret; s->type =FTYPE_FILE ;
@@ -343,10 +349,24 @@ static int raw_open(BlockDriverState *bs, QDict *options, int flags, goto fail; } -if (qdict_get_try_bool (options,"locking" , false)) { + locking =qapi_enum_parse (&OnOffAuto_lookup, +qemu_opt_get (opts,"locking" ), +ON_OFF_AUTO_AUTO , &local_err); +if (local_err) { +error_propagate (errp, local_err); + ret = -EINVAL ; + goto fail; + } +switch (locking) { +case ON_OFF_AUTO_ON :error_setg (errp,"locking=on is not supported on Windows" ); ret = -EINVAL ; goto fail; +case ON_OFF_AUTO_OFF : +case ON_OFF_AUTO_AUTO : +break ; +default : +g_assert_not_reached (); } filename =qemu_opt_get (opts,"filename" );
Signature · 1 line
2.28.0.windows.1
PATCH v7 2/25 rcu: Implement drain_call_rcu
In reply to Yonggang LuoFrom: Maxim Levitsky <[email protected]>
This will allow is to preserve the semantics of hmp_device_del, that the device is deleted immediatly which was changed by previos patch that delayed this to RCU callback
--- include/qemu/rcu.h | 1 + util/rcu.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+)
include/qemu/rcu.h +1 -0
@@ -133,6 +133,7 @@ struct rcu_head { };extern void call_rcu1 (struct rcu_head *head,RCUCBFunc *func); +extern void drain_call_rcu (void );/* The operands of the minus operator must have the same type, * which must be the one that we specify in the cast.
util/rcu.c +55 -0
61 lines not on this page · raw message
Signature · 1 line
2.28.0.windows.1
PATCH v7 3/25 block: Fixes nfs compiling error on msys2/mingw
In reply to Yonggang LuoThese compiling errors are fixed:../block/nfs.c:27:10: fatal error: poll.h: No such file or directory
27 | #include <poll.h>
| ^~~~~~~~
compilation terminated.
../block/nfs.c:63:5: error: unknown type name 'blkcnt_t'
63 | blkcnt_t st_blocks;
| ^~~~~~~~../block/nfs.c: In function 'nfs_client_open':../block/nfs.c:550:27: error: 'struct _stat64' has no member named 'st_blocks'
550 | client->st_blocks = st.st_blocks;
| ^../block/nfs.c: In function 'nfs_get_allocated_file_size':../block/nfs.c:751:41: error: 'struct _stat64' has no member named 'st_blocks'
751 | return (task.ret < 0 ? task.ret : st.st_blocks * 512);
| ^../block/nfs.c: In function 'nfs_reopen_prepare':../block/nfs.c:805:31: error: 'struct _stat64' has no member named 'st_blocks'
805 | client->st_blocks = st.st_blocks;
| ^../block/nfs.c: In function 'nfs_get_allocated_file_size':../block/nfs.c:752:1: error: control reaches end of non-void function [-Werror=return-type]
752 | }
| ^
On msys2/mingw, there is no st_blocks in struct _stat64, so we use consistence st_size instead.
--- block/nfs.c | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-)
block/nfs.c +25 -7
@@ -24,7 +24,9 @@#include "qemu/osdep.h" +#if !defined(_WIN32)#include <poll.h> +#endif #include "qemu/config-file.h" #include "qemu/error-report.h" #include "qapi/error.h"
@@ -51,6 +53,13 @@#define QEMU_NFS_MAX_PAGECACHE_SIZE (8388608 / NFS_BLKSIZE)#define QEMU_NFS_MAX_DEBUG_LEVEL 2 +#if defined (_WIN32) +#define nfs_stat __stat64 +typedef long long blkcnt_t ; +#else +#define nfs_stat stat +#endif + typedef struct NFSClient { struct nfs_context *context; struct nfsfh *fh;
@@ -70,7 +79,7 @@ typedef struct NFSRPC {int ret;int complete;QEMUIOVector *iov; -struct stat *st; +struct nfs_stat *st;Coroutine *co;NFSClient *client; }NFSRPC ;
@@ -415,11 +424,20 @@ static void nfs_file_close(BlockDriverState *bs)nfs_client_close (client); } +static blkcnt_t nfs_get_st_blocks (const struct nfs_stat *st) +{ +#if defined(_WIN32) +return (st->st_size +511 ) /512 ; +#else +return st->st_blocks; +#endif +} +static int64_t nfs_client_open (NFSClient *client,BlockdevOptionsNfs *opts,int flags,int open_flags,Error **errp) {int64_t ret = -EINVAL ; -struct stat st; +struct nfs_stat st;char *file =NULL , *strp =NULL ;qemu_mutex_init (&client->mutex);
@@ -545,7 +563,7 @@ static int64_t nfs_client_open(NFSClient *client, BlockdevOptionsNfs *opts, } ret =DIV_ROUND_UP (st.st_size,BDRV_SECTOR_SIZE ); - client->st_blocks = st.st_blocks; + client->st_blocks =nfs_get_st_blocks (&st); client->has_zero_init =S_ISREG (st.st_mode); *strp ='/' ; goto out;
@@ -729,7 +747,7 @@ static int64_t nfs_get_allocated_file_size(BlockDriverState *bs) {NFSClient *client = bs->opaque;NFSRPC task = {0 }; -struct stat st; +struct nfs_stat st;if (bdrv_is_read_only (bs) && !(bs->open_flags &BDRV_O_NOCACHE )) {
@@ -746,7 +764,7 @@ static int64_t nfs_get_allocated_file_size(BlockDriverState *bs)nfs_set_events (client);BDRV_POLL_WHILE (bs, !task.complete); -return (task.ret <0 ? task.ret : st.st_blocks *512 ); +return (task.ret <0 ? task.ret :nfs_get_st_blocks (&st) *512 ); }static int coroutine_fn
@@ -778,7 +796,7 @@ static int nfs_reopen_prepare(BDRVReopenState *state, BlockReopenQueue *queue, Error **errp) {NFSClient *client = state->bs->opaque; -struct stat st; +struct nfs_stat st;int ret =0 ;if (state->flags &BDRV_O_RDWR &&bdrv_is_read_only (state->bs)) {
@@ -800,7 +818,7 @@ static int nfs_reopen_prepare(BDRVReopenState *state, nfs_get_error(client->context));return ret; } - client->st_blocks = st.st_blocks; + client->st_blocks =nfs_get_st_blocks (&st); }return 0 ;
Signature · 1 line
2.28.0.windows.1
Re: [PATCH v7 03/25] block: Fixes nfs compiling error on msys2/mingw
Quoted 143 lines
Am 10.09.2020 um 12:30 schrieb Yonggang Luo <[email protected]>:
These compiling errors are fixed:
../block/nfs.c:27:10: fatal error:poll.h: No such file or directory
27 | #include <poll.h>| ^~~~~~~~compilation terminated.
../block/nfs.c:63:5: error: unknown type name 'blkcnt_t'63 | blkcnt_t st_blocks; | ^~~~~~~~
../block/nfs.c: In function 'nfs_client_open':../block/nfs.c:550:27: error: 'struct_stat64' has no member named 'st_blocks'
550 |client->st_blocks= st.st_blocks;
| ^../block/nfs.c: In function 'nfs_get_allocated_file_size':../block/nfs.c:751:41: error: 'struct_stat64' has no member named 'st_blocks'
751 | return (task.ret < 0 ? task.ret : st.st_blocks * 512);
| ^../block/nfs.c: In function 'nfs_reopen_prepare':../block/nfs.c:805:31: error: 'struct_stat64' has no member named 'st_blocks'
805 |client->st_blocks= st.st_blocks;
| ^../block/nfs.c: In function 'nfs_get_allocated_file_size':../block/nfs.c:752:1: error: control reaches end of non-void function [-Werror=return-type]
752 | }| ^On msys2/mingw, there is no
st_blocksin struct_stat64, so we use consistencest_sizeinstead.Signed-off-by Yonggang Luo <[email protected]>---
block/nfs.c| 32 +++++++++++++++++++++++++-------1 file changed, 25 insertions(+), 7 deletions(-)block/nfs.c +23
-5@@ -24,7 +24,9 @@#include "qemu/osdep.h" +#if !defined(_WIN32)#include <poll.h> +#endif #include "qemu/config-file.h" #include "qemu/error-report.h" #include "qapi/error.h" @@ -51,6 +53,13 @@#define QEMU_NFS_MAX_PAGECACHE_SIZE (8388608 / NFS_BLKSIZE)#define QEMU_NFS_MAX_DEBUG_LEVEL 2 +#if defined (_WIN32) +#define nfs_stat __stat64 +typedef long long blkcnt_t ; +#else +#define nfs_stat stat +#endif + typedef struct NFSClient { struct nfs_context *context; struct nfsfh *fh;@@ -70,7 +79,7 @@ typedef struct NFSRPC {int ret;int complete;QEMUIOVector *iov; -struct stat *st; +struct nfs_stat *st;Coroutine *co;NFSClient *client; }NFSRPC ;@@ -415,11 +424,20 @@ static void nfs_file_close(BlockDriverState *bs)nfs_client_close (client); } +static blkcnt_t nfs_get_st_blocks (const struct nfs_stat *st) +{ +#if defined(_WIN32) +return (st->st_size +511 ) /512 ; +#else +return st->st_blocks; +#endif +} +static int64_t nfs_client_open (NFSClient *client,BlockdevOptionsNfs *opts,int flags,int open_flags,Error **errp) {int64_t ret = -EINVAL ; -struct stat st; +struct nfs_stat st;char *file =NULL , *strp =NULL ;qemu_mutex_init (&client->mutex);@@ -545,7 +563,7 @@ static int64_t nfs_client_open(NFSClient *client, BlockdevOptionsNfs *opts, } ret =DIV_ROUND_UP (st.st_size,BDRV_SECTOR_SIZE ); - client->st_blocks = st.st_blocks; + client->st_blocks =nfs_get_st_blocks (&st); client->has_zero_init =S_ISREG (st.st_mode); *strp ='/' ; goto out;@@ -729,7 +747,7 @@ static int64_t nfs_get_allocated_file_size(BlockDriverState *bs) {NFSClient *client = bs->opaque;NFSRPC task = {0 }; -struct stat st; +struct nfs_stat st;if (bdrv_is_read_only (bs) && !(bs->open_flags &BDRV_O_NOCACHE )) {@@ -746,7 +764,7 @@ static int64_t nfs_get_allocated_file_size(BlockDriverState *bs)nfs_set_events (client);BDRV_POLL_WHILE (bs, !task.complete); -return (task.ret <0 ? task.ret : st.st_blocks *512 ); +return (task.ret <0 ? task.ret :nfs_get_st_blocks (&st) *512 ); }static int
coroutine_fnblock/nfs.c +2
-2@@ -778,7 +796,7 @@ static int nfs_reopen_prepare(BDRVReopenState *state, BlockReopenQueue *queue, Error **errp) {NFSClient *client = state->bs->opaque; -struct stat st; +struct nfs_stat st;int ret =0 ;if (state->flags &BDRV_O_RDWR &&bdrv_is_read_only (state->bs)) {@@ -800,7 +818,7 @@ static int nfs_reopen_prepare(BDRVReopenState *state, nfs_get_error(client->context));return ret; } - client->st_blocks = st.st_blocks; + client->st_blocks =nfs_get_st_blocks (&st); }return 0 ;Signature · 1 line
2.28.0.windows.1
You still implement nfs_get_allocated_file_size without actually returning the allocated file size on WIN32. I would simply do this:
block/nfs.c +13 -0
@@ -24,7 +24,9 @@#include "qemu/osdep.h" +#if !defined(_WIN32)#include <poll.h> +#endif #include "qemu/config-file.h" #include "qemu/error-report.h" #include "qapi/error.h"
@@ -58,7 +60,9 @@ typedef struct NFSClient {bool has_zero_init;AioContext *aio_context;QemuMutex mutex; +#if !defined(_WIN32)blkcnt_t st_blocks; +#endif bool cache_used;NFSServer *server;char *path;
@@ -545,7 +549,9 @@ static int64_t nfs_client_open(NFSClient *client, BlockdevOptionsNfs *opts, } ret =DIV_ROUND_UP (st.st_size,BDRV_SECTOR_SIZE ); +#if !defined(_WIN32) client->st_blocks = st.st_blocks; +#endif client->has_zero_init =S_ISREG (st.st_mode); *strp ='/' ; goto out;
@@ -706,6 +712,8 @@ static int nfs_has_zero_init(BlockDriverState *bs)return client->has_zero_init; } + +#if !defined(_WIN32)/* Called (via nfs_service) with QemuMutex held. */ static void nfs_get_allocated_file_size_cb(int ret, struct nfs_context *nfs, void *data,
@@ -748,6 +756,7 @@ static int64_t nfs_get_allocated_file_size(BlockDriverState *bs)return (task.ret <0 ? task.ret : st.st_blocks *512 ); } +#endif static int coroutine_fn nfs_file_co_truncate(BlockDriverState *bs, int64_t offset, bool exact,
@@ -792,6 +801,7 @@ static int nfs_reopen_prepare(BDRVReopenState *state,return -EINVAL ; } +#if !defined(_WIN32)/* Update cache for read-only reopens */ if (!(state->flags &BDRV_O_RDWR )) { ret =nfs_fstat (client->context, client->fh, &st);
@@ -802,6 +812,7 @@ static int nfs_reopen_prepare(BDRVReopenState *state, } client->st_blocks = st.st_blocks; } +#endif return 0 ; }
@@ -869,7 +880,9 @@ static BlockDriver bdrv_nfs = { .create_opts = &nfs_create_opts, .bdrv_has_zero_init = nfs_has_zero_init, +#if !defined(_WIN32) .bdrv_get_allocated_file_size = nfs_get_allocated_file_size, +#endif .bdrv_co_truncate = nfs_file_co_truncate, .bdrv_file_open = nfs_file_open,
Best,
Peter
Re: [PATCH v7 03/25] block: Fixes nfs compiling error on msys2/mingw
Quoted 247 lines · Peter Lieven
Am 10.09.2020 um 12:30 schrieb Yonggang Luo <[email protected]>:
These compiling errors are fixed:
../block/nfs.c:27:10: fatal error:poll.h: No such file or directory
27 | #include <poll.h>| ^~~~~~~~compilation terminated.
../block/nfs.c:63:5: error: unknown type name 'blkcnt_t'63 | blkcnt_t st_blocks; | ^~~~~~~~
../block/nfs.c: In function 'nfs_client_open':../block/nfs.c:550:27: error: 'struct_stat64' has no member named 'st_blocks'
550 |client->st_blocks= st.st_blocks;
| ^../block/nfs.c: In function 'nfs_get_allocated_file_size':../block/nfs.c:751:41: error: 'struct_stat64' has no member named 'st_blocks'
751 | return (task.ret < 0 ? task.ret : st.st_blocks * 512);
| ^../block/nfs.c: In function 'nfs_reopen_prepare':../block/nfs.c:805:31: error: 'struct_stat64' has no member named 'st_blocks'
805 |client->st_blocks= st.st_blocks;
| ^../block/nfs.c: In function 'nfs_get_allocated_file_size':../block/nfs.c:752:1: error: control reaches end of non-void function [-Werror=return-type]
752 | }| ^On msys2/mingw, there is no
st_blocksin struct_stat64, so we use consistencest_sizeinstead.Signed-off-by Yonggang Luo <[email protected]>---
block/nfs.c| 32 +++++++++++++++++++++++++-------1 file changed, 25 insertions(+), 7 deletions(-)block/nfs.c +21
-3@@ -24,7 +24,9 @@#include "qemu/osdep.h" +#if !defined(_WIN32)#include <poll.h> +#endif #include "qemu/config-file.h" #include "qemu/error-report.h" #include "qapi/error.h" @@ -51,6 +53,13 @@#define QEMU_NFS_MAX_PAGECACHE_SIZE (8388608 / NFS_BLKSIZE)#define QEMU_NFS_MAX_DEBUG_LEVEL 2 +#if defined (_WIN32) +#define nfs_stat __stat64 +typedef long long blkcnt_t ; +#else +#define nfs_stat stat +#endif + typedef struct NFSClient { struct nfs_context *context; struct nfsfh *fh;@@ -70,7 +79,7 @@ typedef struct NFSRPC {int ret;int complete;QEMUIOVector *iov; -struct stat *st; +struct nfs_stat *st;Coroutine *co;NFSClient *client; }NFSRPC ;@@ -415,11 +424,20 @@ static void nfs_file_close(BlockDriverState *bs)nfs_client_close (client); } +static blkcnt_t nfs_get_st_blocks (const struct nfs_stat *st) +{ +#if defined(_WIN32) +return (st->st_size +511 ) /512 ; +#else +return st->st_blocks; +#endif +} +static int64_t nfs_client_open (NFSClient *client,BlockdevOptionsNfs *opts,int flags,int open_flags,Error **errp) {int64_t ret = -EINVAL ; -struct stat st; +struct nfs_stat st;char *file =NULL , *strp =NULL ;qemu_mutex_init (&client->mutex);@@ -545,7 +563,7 @@ static int64_t nfs_client_open(NFSClient *client,BlockdevOptionsNfs *opts, } ret =DIV_ROUND_UP (st.st_size,BDRV_SECTOR_SIZE ); - client->st_blocks = st.st_blocks; + client->st_blocks =nfs_get_st_blocks (&st); client->has_zero_init =S_ISREG (st.st_mode); *strp ='/' ;goto out;block/nfs.c +1
-1@@ -729,7 +747,7 @@ static int64_t nfs_get_allocated_file_size(BlockDriverState *bs) {NFSClient *client = bs->opaque;NFSRPC task = {0 }; -struct stat st; +struct nfs_stat st; if (bdrv_is_read_only(bs) &&!(bs->open_flags & BDRV_O_NOCACHE)) {block/nfs.c +1
-1@@ -746,7 +764,7 @@ static int64_t nfs_get_allocated_file_size(BlockDriverState *bs)nfs_set_events (client);BDRV_POLL_WHILE (bs, !task.complete); -return (task.ret <0 ? task.ret : st.st_blocks *512 ); +return (task.ret <0 ? task.ret :nfs_get_st_blocks (&st) *512 ); }static int
coroutine_fnblock/nfs.c +2
-3@@ -778,7 +796,7 @@ static int nfs_reopen_prepare(BDRVReopenState *state, BlockReopenQueue *queue, Error **errp) {NFSClient *client = state->bs->opaque; -struct stat st; +struct nfs_stat st;int ret =0 ;if (state->flags &BDRV_O_RDWR &&bdrv_is_read_only (state->bs)) {@@ -800,7 +818,7 @@ static int nfs_reopen_prepare(BDRVReopenState *state, nfs_get_error(client->context));return ret; } - client->st_blocks = st.st_blocks; + client->st_blocks =nfs_get_st_blocks (&st); }return 0 ; --2.28.0.windows.1
You still implement
nfs_get_allocated_file_sizewithout actually returning the allocated file size on WIN32.
I would simply do this:*diff --git
a/block/nfs.cb/block/nfs.c*
*index 61a249a..0983143 100644*
*--- a/block/nfs.c*
*+++ b/block/nfs.c*block/nfs.c +2
-0@@ -24,7 +24,9 @@#include "qemu/osdep.h" +#if !defined(_WIN32)#include <poll.h> +#endif #include "qemu/config-file.h" #include "
qemu/error-report.h"
#include "qapi/error.h"block/nfs.c +4
-0@@ -58,7 +60,9 @@ typedef struct NFSClient {bool has_zero_init;AioContext *aio_context;QemuMutex mutex; +#if !defined(_WIN32)blkcnt_t st_blocks; +#endif bool cache_used;NFSServer *server;char *path;@@ -545,7 +549,9 @@ static int64_t nfs_client_open(NFSClient *client,BlockdevOptionsNfs *opts, } ret =DIV_ROUND_UP (st.st_size,BDRV_SECTOR_SIZE ); +#if !defined(_WIN32) client->st_blocks = st.st_blocks; +#endif client->has_zero_init =S_ISREG (st.st_mode);*strp = '/'; goto out;block/nfs.c +2
-0@@ -706,6 +712,8 @@ static int nfs_has_zero_init(BlockDriverState *bs)return client->has_zero_init; } + +#if !defined(_WIN32)/* Called (via nfs_service) with QemuMutex held. */ static voidnfs_get_allocated_file_size_cb(int ret, struct
nfs_context*nfs, void
*data,block/nfs.c +1
-0@@ -748,6 +756,7 @@ static int64_tnfs_get_allocated_file_size (BlockDriverState *bs) return (task.ret < 0 ? task.ret : st.st_blocks * 512); } +#endif static int
coroutine_fnnfs_file_co_truncate(BlockDriverState *bs,int64_toffset, bool exact,block/nfs.c +1
-0@@ -792,6 +801,7 @@ static int nfs_reopen_prepare(BDRVReopenState *state,return -EINVAL ; } +#if !defined(_WIN32)/* Update cache for read-only reopens */ if (!(state->flags &BDRV_O_RDWR )) {ret = nfs_fstat(client->context, client->fh, &st);block/nfs.c +1
-0@@ -802,6 +812,7 @@ static int nfs_reopen_prepare(BDRVReopenState *state, } client->st_blocks = st.st_blocks; } +#endif return 0 ;}
block/nfs.c +2
-0@@ -869,7 +880,9 @@ static BlockDriver bdrv_nfs = { .create_opts = &nfs_create_opts, .bdrv_has_zero_init = nfs_has_zero_init, +#if !defined(_WIN32) .bdrv_get_allocated_file_size = nfs_get_allocated_file_size, +#endif .bdrv_co_truncate = nfs_file_co_truncate,
Quoted 6 lines
.bdrv_file_open =
nfs_file_open,Best,
Peter
Any git repo have this patch? I can cherry-pick it directly
Signature · 6 lines
此致
礼
罗勇刚
Yours
sincerely,
Yonggang LuoRe: [PATCH v7 03/25] block: Fixes nfs compiling error on msys2/mingw
Quoted 232 lines
Am 10.09.2020 um 22:36 schrieb 罗勇刚(Yonggang Luo) <[email protected]>:
Quoted 225 lines · Peter Lieven
Quoted 143 lines
Am 10.09.2020 um 12:30 schrieb Yonggang Luo <[email protected]>:
These compiling errors are fixed:
../block/nfs.c:27:10: fatal error:poll.h: No such file or directory
27 | #include <poll.h>| ^~~~~~~~compilation terminated.
../block/nfs.c:63:5: error: unknown type name 'blkcnt_t'63 | blkcnt_t st_blocks; | ^~~~~~~~
../block/nfs.c: In function 'nfs_client_open':../block/nfs.c:550:27: error: 'struct_stat64' has no member named 'st_blocks'
550 |client->st_blocks= st.st_blocks;
| ^../block/nfs.c: In function 'nfs_get_allocated_file_size':../block/nfs.c:751:41: error: 'struct_stat64' has no member named 'st_blocks'
751 | return (task.ret < 0 ? task.ret : st.st_blocks * 512);
| ^../block/nfs.c: In function 'nfs_reopen_prepare':../block/nfs.c:805:31: error: 'struct_stat64' has no member named 'st_blocks'
805 |client->st_blocks= st.st_blocks;
| ^../block/nfs.c: In function 'nfs_get_allocated_file_size':../block/nfs.c:752:1: error: control reaches end of non-void function [-Werror=return-type]
752 | }| ^On msys2/mingw, there is no
st_blocksin struct_stat64, so we use consistencest_sizeinstead.Signed-off-by Yonggang Luo <[email protected]>---
block/nfs.c| 32 +++++++++++++++++++++++++-------1 file changed, 25 insertions(+), 7 deletions(-)block/nfs.c +23
-5@@ -24,7 +24,9 @@#include "qemu/osdep.h" +#if !defined(_WIN32)#include <poll.h> +#endif #include "qemu/config-file.h" #include "qemu/error-report.h" #include "qapi/error.h" @@ -51,6 +53,13 @@#define QEMU_NFS_MAX_PAGECACHE_SIZE (8388608 / NFS_BLKSIZE)#define QEMU_NFS_MAX_DEBUG_LEVEL 2 +#if defined (_WIN32) +#define nfs_stat __stat64 +typedef long long blkcnt_t ; +#else +#define nfs_stat stat +#endif + typedef struct NFSClient { struct nfs_context *context; struct nfsfh *fh;@@ -70,7 +79,7 @@ typedef struct NFSRPC {int ret;int complete;QEMUIOVector *iov; -struct stat *st; +struct nfs_stat *st;Coroutine *co;NFSClient *client; }NFSRPC ;@@ -415,11 +424,20 @@ static void nfs_file_close(BlockDriverState *bs)nfs_client_close (client); } +static blkcnt_t nfs_get_st_blocks (const struct nfs_stat *st) +{ +#if defined(_WIN32) +return (st->st_size +511 ) /512 ; +#else +return st->st_blocks; +#endif +} +static int64_t nfs_client_open (NFSClient *client,BlockdevOptionsNfs *opts,int flags,int open_flags,Error **errp) {int64_t ret = -EINVAL ; -struct stat st; +struct nfs_stat st;char *file =NULL , *strp =NULL ;qemu_mutex_init (&client->mutex);@@ -545,7 +563,7 @@ static int64_t nfs_client_open(NFSClient *client, BlockdevOptionsNfs *opts, } ret =DIV_ROUND_UP (st.st_size,BDRV_SECTOR_SIZE ); - client->st_blocks = st.st_blocks; + client->st_blocks =nfs_get_st_blocks (&st); client->has_zero_init =S_ISREG (st.st_mode); *strp ='/' ; goto out;@@ -729,7 +747,7 @@ static int64_t nfs_get_allocated_file_size(BlockDriverState *bs) {NFSClient *client = bs->opaque;NFSRPC task = {0 }; -struct stat st; +struct nfs_stat st;if (bdrv_is_read_only (bs) && !(bs->open_flags &BDRV_O_NOCACHE )) {@@ -746,7 +764,7 @@ static int64_t nfs_get_allocated_file_size(BlockDriverState *bs)nfs_set_events (client);BDRV_POLL_WHILE (bs, !task.complete); -return (task.ret <0 ? task.ret : st.st_blocks *512 ); +return (task.ret <0 ? task.ret :nfs_get_st_blocks (&st) *512 ); }static int
coroutine_fnblock/nfs.c +2
-2@@ -778,7 +796,7 @@ static int nfs_reopen_prepare(BDRVReopenState *state, BlockReopenQueue *queue, Error **errp) {NFSClient *client = state->bs->opaque; -struct stat st; +struct nfs_stat st;int ret =0 ;if (state->flags &BDRV_O_RDWR &&bdrv_is_read_only (state->bs)) {@@ -800,7 +818,7 @@ static int nfs_reopen_prepare(BDRVReopenState *state, nfs_get_error(client->context));return ret; } - client->st_blocks = st.st_blocks; + client->st_blocks =nfs_get_st_blocks (&st); }return 0 ;Signature · 1 line
2.28.0.windows.1You still implement
nfs_get_allocated_file_sizewithout actually returning the allocated file size on WIN32. I would simply do this:block/nfs.c +13
-0@@ -24,7 +24,9 @@#include "qemu/osdep.h" +#if !defined(_WIN32)#include <poll.h> +#endif #include "qemu/config-file.h" #include "qemu/error-report.h" #include "qapi/error.h" @@ -58,7 +60,9 @@ typedef struct NFSClient {bool has_zero_init;AioContext *aio_context;QemuMutex mutex; +#if !defined(_WIN32)blkcnt_t st_blocks; +#endif bool cache_used;NFSServer *server;char *path;@@ -545,7 +549,9 @@ static int64_t nfs_client_open(NFSClient *client, BlockdevOptionsNfs *opts, } ret =DIV_ROUND_UP (st.st_size,BDRV_SECTOR_SIZE ); +#if !defined(_WIN32) client->st_blocks = st.st_blocks; +#endif client->has_zero_init =S_ISREG (st.st_mode); *strp ='/' ; goto out;@@ -706,6 +712,8 @@ static int nfs_has_zero_init(BlockDriverState *bs)return client->has_zero_init; } + +#if !defined(_WIN32)/* Called (via nfs_service) with QemuMutex held. */ static void nfs_get_allocated_file_size_cb(int ret, struct nfs_context *nfs, void *data,@@ -748,6 +756,7 @@ static int64_t nfs_get_allocated_file_size(BlockDriverState *bs)return (task.ret <0 ? task.ret : st.st_blocks *512 ); } +#endif static int coroutine_fn nfs_file_co_truncate(BlockDriverState *bs, int64_t offset, bool exact,@@ -792,6 +801,7 @@ static int nfs_reopen_prepare(BDRVReopenState *state,return -EINVAL ; } +#if !defined(_WIN32)/* Update cache for read-only reopens */ if (!(state->flags &BDRV_O_RDWR )) { ret =nfs_fstat (client->context, client->fh, &st);@@ -802,6 +812,7 @@ static int nfs_reopen_prepare(BDRVReopenState *state, } client->st_blocks = st.st_blocks; } +#endif return 0 ; }@@ -869,7 +880,9 @@ static BlockDriver bdrv_nfs = { .create_opts = &nfs_create_opts, .bdrv_has_zero_init = nfs_has_zero_init, +#if !defined(_WIN32) .bdrv_get_allocated_file_size = nfs_get_allocated_file_size, +#endif .bdrv_co_truncate = nfs_file_co_truncate,
Quoted 6 lines
Quoted 5 lines
block/nfs.c +0
-0.bdrv_file_open = nfs_file_open,Best,
PeterAny git repo have this patch? I can cherry-pick it directly
not yet. but feel free to use this diff for your own patch. otherwise i can setup a branch with this patch on github where you can pick it.
Peter
PATCH v7 4/25 ci: fixes msys2 build by upgrading capstone to 4.0.2
In reply to Yonggang LuoThe currently random version capstone have the following compiling issue:
CC /c/work/xemu/qemu/build/slirp/src/arp_table.o
make[1]: *** No rule to make target “/c/work/xemu/qemu/build/capstone/capstone.lib”。 Stop.
Subproject commit 1d230532840a37ac032c6ab80128238fc930c6c1 are the tagged version 4.0.2 when upgrading to this version, the folder structure of include are changed to qemu\capstone\include
│ platform.h │ ├─capstone │ arm.h │ arm64.h │ capstone.h │ evm.h │ m680x.h │ m68k.h │ mips.h │ platform.h │ ppc.h │ sparc.h │ systemz.h │ tms320c64x.h │ x86.h │ xcore.h │ └─windowsce
intrin.h
stdint.h
in capstone. so we need add extra include path -I${source_path}/capstone/include/capstone for directly #include <capstone.h>, and the exist include path should preserve, because in capstone code there something like #include "capstone/capstone.h"
If only using
capstone_cflags="-I${source_path}/capstone/include/capstone"Then will cause the following compiling error:
CC cs.o
cs.c:17:10: fatal error: 'capstone/capstone.h' file not found
#include <capstone/capstone.h>
^~~~~~~~~~~~~~~~~~~~~1 error generated.
--- capstone | 2 +- configure | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
capstone +1 -1
@@ -1 +1 @@ -Subproject commit 22ead3e0bfdb87516656453336160e0a37b066bf +Subproject commit 1d230532840a37ac032c6ab80128238fc930c6c1
configure +1 -1
@@ -5156,7 +5156,7 @@ case "$capstone" in LIBCAPSTONE=libcapstone.a fi capstone_libs="-Lcapstone -lcapstone" - capstone_cflags="-I${source_path}/capstone/include" + capstone_cflags="-I${source_path}/capstone/include -I${source_path}/capstone/include/capstone" ;; system)
Signature · 1 line
2.28.0.windows.1
PATCH v7 5/25 configure: Fixes ncursesw detection under msys2/mingw and enable curses
In reply to Yonggang LuoThe mingw pkg-config are showing following absolute path and contains : as the separator, so we must not use : as path separator. and we know the command line parameter are not likely contains newline, we could use newline as path command line parameter separator
-D_XOPEN_SOURCE=600 -D_POSIX_C_SOURCE=199506L -IC:/CI-Tools/msys64/mingw64/include/ncursesw:-I/usr/include/ncursesw:
-DNCURSES_WIDECHAR -D_XOPEN_SOURCE=600 -D_POSIX_C_SOURCE=199506L -IC -pipe -lncursesw -lgnurx -ltre -lintl -liconv -DNCURSES_WIDECHAR -D_XOPEN_SOURCE=600 -D_POSIX_C_SOURCE=199506L -IC -lncursesw -DNCURSES_WIDECHAR -D_XOPEN_SOURCE=600 -D_POSIX_C_SOURCE=199506L -IC -lcursesw
-DNCURSES_WIDECHAR /CI-Tools/msys64/mingw64/include/ncursesw -pipe -lncursesw -lgnurx -ltre -lintl -liconv -DNCURSES_WIDECHAR /CI-Tools/msys64/mingw64/include/ncursesw -lncursesw
-DNCURSES_WIDECHAR /CI-Tools/msys64/mingw64/include/ncursesw -lcursesw
-DNCURSES_WIDECHAR -I/usr/include/ncursesw -pipe -lncursesw -lgnurx -ltre -lintl -liconv -DNCURSES_WIDECHAR -I/usr/include/ncursesw -lncursesw
-DNCURSES_WIDECHAR -I/usr/include/ncursesw -lcursesw
Refer to https://unix.stackexchange.com/a/103011/218958
If your file names are guaranteed not to contain newlines, you can use newlines as the separator. W hen you expand the variable, first turn off globbing with set -f and set the list of field splitting characters IFS to contain only a newline.
msys2/mingw lacks the POSIX-required langinfo.h.
gcc test.c -DNCURSES_WIDECHAR -I/mingw64/include/ncursesw -pipe -lncursesw -lgnurx -ltre -lintl -liconv test.c:4:10: fatal error: langinfo.h: No such file or directory
4 | #include <langinfo.h>
| ^~~~~~~~~~~~
compilation terminated.
So we using g_get_codeset instead of nl_langinfo(CODESET)
--- configure | 25 +++++++++++++++---------- ui/curses.c | 10 +++++----- 2 files changed, 20 insertions(+), 15 deletions(-)
configure +15 -10
@@ -3653,35 +3653,40 @@ if test "$iconv" = "no" ; then fi if test "$curses" != "no" ; then if test "$mingw32" = "yes" ; then - curses_inc_list="$($pkg_config --cflags ncurses 2>/dev/null):" - curses_lib_list="$($pkg_config --libs ncurses 2>/dev/null):-lpdcurses" + curses_inc_list="$($pkg_config --cflags ncurses 2>/dev/null) + $($pkg_config --cflags ncursesw 2>/dev/null)" + curses_lib_list="$($pkg_config --libs ncurses 2>/dev/null) + $($pkg_config --libs ncursesw 2>/dev/null) + -lpdcurses" else - curses_inc_list="$($pkg_config --cflags ncursesw 2>/dev/null):-I/usr/include/ncursesw:" - curses_lib_list="$($pkg_config --libs ncursesw 2>/dev/null):-lncursesw:-lcursesw" + curses_inc_list="$($pkg_config --cflags ncursesw 2>/dev/null) + -I/usr/include/ncursesw:" + curses_lib_list="$($pkg_config --libs ncursesw 2>/dev/null) + -lncursesw + -lcursesw" fi curses_found=no cat > $TMPC << EOF #include <locale.h> #include <curses.h> #include <wchar.h> -#include <langinfo.h> int main(void) { - const char *codeset; wchar_t wch = L'w'; setlocale(LC_ALL, ""); resize_term(0, 0); addwstr(L"wide chars\n"); addnwstr(&wch, 1); add_wch(WACS_DEGREE); - codeset = nl_langinfo(CODESET); - return codeset != 0; + return 0; } EOF - IFS=: + IFS=' +' # turn off variable value expansion except for splitting at newlines for curses_inc in $curses_inc_list; do # Make sure we get the wide character prototypes curses_inc="-DNCURSES_WIDECHAR $curses_inc" - IFS=: + IFS=' +' # turn off variable value expansion except for splitting at newlines for curses_lib in $curses_lib_list; do unset IFS if compile_prog "$curses_inc" "$curses_lib" ; then
ui/curses.c +5 -5
@@ -30,7 +30,6 @@#endif #include <locale.h> #include <wchar.h> -#include <langinfo.h> #include <iconv.h> #include "qapi/error.h"
@@ -526,6 +525,7 @@ static void font_setup(void)iconv_t nativecharset_to_ucs2;iconv_t font_conv;int i; + g_autofree gchar *local_codeset = g_get_codeset();/* * Control characters are normally non-printable, but VGA does have
@@ -566,14 +566,14 @@ static void font_setup(void)0x25bc }; - ucs2_to_nativecharset =iconv_open (nl_langinfo (CODESET ),"UCS-2" ); + ucs2_to_nativecharset =iconv_open (local_codeset,"UCS-2" );if (ucs2_to_nativecharset == (iconv_t) -1 ) {fprintf (stderr,"Could not convert font glyphs from UCS-2: '%s'\n" ,strerror (errno));exit (1 ); } - nativecharset_to_ucs2 =iconv_open ("UCS-2" ,nl_langinfo (CODESET )); + nativecharset_to_ucs2 =iconv_open ("UCS-2" , local_codeset);if (nativecharset_to_ucs2 == (iconv_t) -1 ) {iconv_close (ucs2_to_nativecharset); fprintf(stderr, "Could not convert font glyphs to UCS-2: '%s'\n",
@@ -581,7 +581,7 @@ static void font_setup(void)exit (1 ); } - font_conv =iconv_open (nl_langinfo (CODESET ), font_charset); + font_conv =iconv_open (local_codeset, font_charset);if (font_conv == (iconv_t) -1 ) {iconv_close (ucs2_to_nativecharset);iconv_close (nativecharset_to_ucs2);
@@ -602,7 +602,7 @@ static void font_setup(void)/* DEL */ convert_ucs (0x7F ,0x2302 , ucs2_to_nativecharset); -if (strcmp (nl_langinfo (CODESET ),"UTF-8" )) { +if (strcmp (local_codeset,"UTF-8" )) {/* Non-Unicode capable, use termcap equivalents for those available */ for (i =0 ; i <=0xFF ; i++) {wchar_t wch[CCHARW_MAX ];
Signature · 1 line
2.28.0.windows.1
PATCH v7 6/25 win32: Simplify gmtime_r detection direct base on _POSIX_THREAD_SAFE_FUNCTIONS.
In reply to Yonggang LuoFirst, this reduce the size of configure, configure are tending to removal in future, and this didn't introduce any new feature or remove any exist feature. Second, the current localtime_r detection are conflict with ncursesw detection in mingw, when ncursesw detected, it will provide the following compile flags pkg-config --cflags ncursesw
-D_XOPEN_SOURCE=600 -D_POSIX_C_SOURCE=199506L -IC:/CI-Tools/msys64/mingw64/include/ncursesw And the compile flag _POSIX_C_SOURCE will always cause _POSIX_THREAD_SAFE_FUNCTIONS to be defined, in new version of mingw, that's will cause localtime_r to be defined. But the configure script didn't provide _POSIX_C_SOURCE macro, and that's will result localtime_r not detected because localtime_r are defined in forceinline manner.
And finally cause conflict between QEMU defined localtime_r struct tm *localtime_r(const time_t *timep, struct tm *result); with mingw defined localtime_r
```
#if defined(_POSIX_C_SOURCE) && !defined(_POSIX_THREAD_SAFE_FUNCTIONS)
#define _POSIX_THREAD_SAFE_FUNCTIONS 200112L
#endif
#ifdef _POSIX_THREAD_SAFE_FUNCTIONS
__forceinline struct tm *__CRTDECL localtime_r(const time_t *_Time, struct tm *_Tm) {
return localtime_s(_Tm, _Time) ? NULL : _Tm;
}
__forceinline struct tm *__CRTDECL gmtime_r(const time_t *_Time, struct tm *_Tm) {
return gmtime_s(_Tm, _Time) ? NULL : _Tm;
}
__forceinline char *__CRTDECL ctime_r(const time_t *_Time, char *_Str) {
return ctime_s(_Str, 0x7fffffff, _Time) ? NULL : _Str;
}
__forceinline char *__CRTDECL asctime_r(const struct tm *_Tm, char * _Str) {
return asctime_s(_Str, 0x7fffffff, _Tm) ? NULL : _Str;
}
#endif
```So I suggest remove this configure script, and restrict msys2/mingw version to easy to maintain. And use _POSIX_THREAD_SAFE_FUNCTIONS to guard the localtime_r and counterpart functions
--- configure | 34 ---------------------------------- include/sysemu/os-win32.h | 4 ++-- util/oslib-win32.c | 2 +- 3 files changed, 3 insertions(+), 37 deletions(-)
configure +0 -34
@@ -2495,37 +2495,6 @@ if test "$vhost_net" = ""; then test "$vhost_kernel" = "yes" && vhost_net=yes fi -########################################## -# MinGW / Mingw-w64 localtime_r/gmtime_r check - -if test "$mingw32" = "yes"; then - # Some versions of MinGW / Mingw-w64 lack localtime_r - # and gmtime_r entirely. - # - # Some versions of Mingw-w64 define a macro for - # localtime_r/gmtime_r. - # - # Some versions of Mingw-w64 will define functions - # for localtime_r/gmtime_r, but only if you have - # _POSIX_THREAD_SAFE_FUNCTIONS defined. For fun - # though, unistd.h and pthread.h both define - # that for you. - # - # So this #undef localtime_r and #include <unistd.h> - # are not in fact redundant. -cat > $TMPC << EOF -#include <unistd.h> -#include <time.h> -#undef localtime_r -int main(void) { localtime_r(NULL, NULL); return 0; } -EOF - if compile_prog "" "" ; then - localtime_r="yes" - else - localtime_r="no" - fi -fi - ########################################## # pkg-config probe
@@ -7087,9 +7056,6 @@ if [ "$bsd" = "yes" ] ; then echo "CONFIG_BSD=y" >> $config_host_mak fi -if test "$localtime_r" = "yes" ; then - echo "CONFIG_LOCALTIME_R=y" >> $config_host_mak -fi if test "$qom_cast_debug" = "yes" ; then echo "CONFIG_QOM_CAST_DEBUG=y" >> $config_host_mak fi
include/sysemu/os-win32.h +2 -2
@@ -48,12 +48,12 @@#define siglongjmp (env, val) longjmp(env, val)/* Missing POSIX functions. Don't use MinGW-w64 macros. */ -#ifndef CONFIG_LOCALTIME_R +#ifndef _POSIX_THREAD_SAFE_FUNCTIONS#undef gmtime_rstruct tm *gmtime_r (const time_t *timep,struct tm *result);#undef localtime_rstruct tm *localtime_r (const time_t *timep,struct tm *result); -#endif /* CONFIG_LOCALTIME_R */ +#endif static inline void os_setup_signal_handling (void ) {}static inline void os_daemonize (void ) {}
util/oslib-win32.c +1 -1
@@ -106,7 +106,7 @@ void qemu_anon_ram_free(void *ptr, size_t size) } } -#ifndef CONFIG_LOCALTIME_R +#ifndef _POSIX_THREAD_SAFE_FUNCTIONS/* FIXME: add proper locking */ struct tm *gmtime_r (const time_t *timep,struct tm *result) {
Signature · 1 line
2.28.0.windows.1
PATCH v7 7/25 curses: Fixes curses compiling errors.
In reply to Yonggang LuoThis is the compiling error:../ui/curses.c: In function 'curses_refresh':../ui/curses.c:256:5: error: 'next_maybe_keycode' may be used uninitialized in this function [-Werror=maybe-uninitialized]
256 | curses2foo(_curses2keycode, _curseskey2keycode, chr, maybe_keycode)
| ^~~~~~~~~~
../ui/curses.c:302:32: note: 'next_maybe_keycode' was declared here
302 | enum maybe_keycode next_maybe_keycode;
| ^~~~~~~~~~~~~~~~~~
../ui/curses.c:256:5: error: 'maybe_keycode' may be used uninitialized in this function [-Werror=maybe-uninitialized]
256 | curses2foo(_curses2keycode, _curseskey2keycode, chr, maybe_keycode)
| ^~~~~~~~~~
../ui/curses.c:265:24: note: 'maybe_keycode' was declared here
265 | enum maybe_keycode maybe_keycode;
| ^~~~~~~~~~~~~cc1.exe: all warnings being treated as errors
gcc version 10.2.0 (Rev1, Built by MSYS2 project)
--- ui/curses.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
ui/curses.c +2 -2
@@ -262,7 +262,7 @@ static int curses2foo(const int _curses2foo[], const int _curseskey2foo[],static void curses_refresh (DisplayChangeListener *dcl) {int chr, keysym, keycode, keycode_alt; -enum maybe_keycode maybe_keycode; +enum maybe_keycode maybe_keycode =CURSES_KEYCODE ;curses_winch_check ();
@@ -299,7 +299,7 @@ static void curses_refresh(DisplayChangeListener *dcl)/* alt or esc key */ if (keycode ==1 ) { -enum maybe_keycode next_maybe_keycode; +enum maybe_keycode next_maybe_keycode =CURSES_KEYCODE ;int nextchr =console_getch (&next_maybe_keycode);if (nextchr !=-1 ) {
Signature · 1 line
2.28.0.windows.1
PATCH v7 8/25 tests: disable /char/stdio/* tests in test-char.c on win32
In reply to Yonggang LuoThese tests are blocking test-char to be finished. Disable them by using variable is_win32, so we doesn't need macro to open it. and easy recover those function latter.
--- tests/test-char.c | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-)
tests/test-char.c +16 -10
@@ -77,7 +77,6 @@ static void fe_event(void *opaque, QEMUChrEvent event) } } -#ifdef _WIN32static void char_console_test_subprocess (void ) {QemuOpts *opts;
@@ -102,7 +101,7 @@ static void char_console_test(void)g_test_trap_assert_passed ();g_test_trap_assert_stdout ("CONSOLE" ); } -#endif +static void char_stdio_test_subprocess (void ) {Chardev *chr;
@@ -1448,7 +1447,11 @@ static SocketAddress unixaddr = {int main (int argc,char **argv) { -bool has_ipv4, has_ipv6; +bool has_ipv4, has_ipv6, is_win32 = false; + +#ifdef _WIN32 + is_win32 = true; +#endif qemu_init_main_loop (&error_abort);socket_init ();
@@ -1467,12 +1470,15 @@ int main(int argc, char **argv)g_test_add_func ("/char/invalid" , char_invalid_test);g_test_add_func ("/char/ringbuf" , char_ringbuf_test);g_test_add_func ("/char/mux" , char_mux_test); -#ifdef _WIN32 -g_test_add_func ("/char/console/subprocess" , char_console_test_subprocess); -g_test_add_func ("/char/console" , char_console_test); -#endif -g_test_add_func ("/char/stdio/subprocess" , char_stdio_test_subprocess); -g_test_add_func ("/char/stdio" , char_stdio_test); +if (0 ) { +g_test_add_func ("/char/console/subprocess" , char_console_test_subprocess); +g_test_add_func ("/char/console" , char_console_test); + } + +if (!is_win32) { +g_test_add_func ("/char/stdio/subprocess" , char_stdio_test_subprocess); +g_test_add_func ("/char/stdio" , char_stdio_test); + }#ifndef _WIN32g_test_add_func ("/char/pipe" , char_pipe_test);#endif
@@ -1534,7 +1540,7 @@ int main(int argc, char **argv) g_test_add_data_func("/char/socket/client/dupid-reconnect/" # name, \ &client8 ##name, char_socket_client_dupid_test) -if (has_ipv4) { +if (has_ipv4 && !is_win32) {SOCKET_SERVER_TEST (tcp, &tcpaddr);SOCKET_CLIENT_TEST (tcp, &tcpaddr); g_test_add_data_func("/char/socket/server/two-clients/tcp", &tcpaddr,
Signature · 1 line
2.28.0.windows.1
PATCH v7 9/25 tests: Fixes test-replication.c on msys2/mingw.
In reply to Yonggang LuoOn Windows there is no path like /tmp/s_local_disk.XXXXXX Use g_get_tmp_dir instead of /tmp.
--- tests/test-replication.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-)
tests/test-replication.c +14 -4
@@ -23,14 +23,14 @@/* primary */ #define P_ID "primary-id" -static char p_local_disk[] ="/tmp/p_local_disk.XXXXXX" ; +static char *p_local_disk;/* secondary */ #define S_ID "secondary-id"#define S_LOCAL_DISK_ID "secondary-local-disk-id" -static char s_local_disk[] ="/tmp/s_local_disk.XXXXXX" ; -static char s_active_disk[] ="/tmp/s_active_disk.XXXXXX" ; -static char s_hidden_disk[] ="/tmp/s_hidden_disk.XXXXXX" ; +static char *s_local_disk; +static char *s_active_disk; +static char *s_hidden_disk;/* FIXME: steal from blockdev.c */ QemuOptsList qemu_drive_opts = {
@@ -571,6 +571,11 @@ static void setup_sigabrt_handler(void)int main (int argc,char **argv) {int ret; +const char *tmpdir =g_get_tmp_dir (); + p_local_disk =g_strdup_printf ("%s/p_local_disk.XXXXXX" , tmpdir); + s_local_disk =g_strdup_printf ("%s/s_local_disk.XXXXXX" , tmpdir); + s_active_disk =g_strdup_printf ("%s/s_active_disk.XXXXXX" , tmpdir); + s_hidden_disk =g_strdup_printf ("%s/s_hidden_disk.XXXXXX" , tmpdir);qemu_init_main_loop (&error_fatal);bdrv_init ();
@@ -605,5 +610,10 @@ int main(int argc, char **argv)cleanup_imgs (); +g_free (p_local_disk); +g_free (s_local_disk); +g_free (s_active_disk); +g_free (s_hidden_disk); +return ret; }
Signature · 1 line
2.28.0.windows.1
PATCH v7 10/25 tests: test-replication disable /replication/secondary/* on msys2/mingw.
In reply to Yonggang LuoThey caused failure on msys2/mingw, that's because file-win32.c not implement .bdrv_reopen_prepare/commit/abort yet.
This is the error message:
Quoted 10 lines
$ ./tests/test-replication.exe # random seed: R02S3f4d1c01af2b0a046990e0235c481faf 1..13 # Start of replication tests # Start of primary tests ok 1 /replication/primary/read ok 2 /replication/primary/write ok 3 /replication/primary/start ok 4 /replication/primary/stop ok 5 /replication/primary/do_checkpoint
Quoted 8 lines
ok 6 /replication/primary/get_error_all # End of primary tests # Start of secondary tests ok 7 /replication/secondary/read ok 8 /replication/secondary/write Unexpected error in bdrv_reopen_prepare() at ../block.c:4191: Block format 'file' used by node '#block4287' does not support reopening files
--- tests/test-replication.c | 4 ++++ 1 file changed, 4 insertions(+)
tests/test-replication.c +4 -0
@@ -392,6 +392,7 @@ static void test_secondary_write(void)teardown_secondary (); } +#ifndef _WIN32static void test_secondary_start (void ) {BlockBackend *top_blk, *local_blk;
@@ -546,6 +547,7 @@ static void test_secondary_get_error_all(void) teardown_secondary(); } +#endif static void sigabrt_handler (int signo) {
@@ -597,6 +599,7 @@ int main(int argc, char **argv)/* Secondary */ g_test_add_func ("/replication/secondary/read" , test_secondary_read);g_test_add_func ("/replication/secondary/write" , test_secondary_write); +#ifndef _WIN32g_test_add_func ("/replication/secondary/start" , test_secondary_start);g_test_add_func ("/replication/secondary/stop" , test_secondary_stop); g_test_add_func("/replication/secondary/continuous_replication",
@@ -605,6 +608,7 @@ int main(int argc, char **argv) test_secondary_do_checkpoint);g_test_add_func ("/replication/secondary/get_error_all" , test_secondary_get_error_all); +#endif ret =g_test_run ();
Signature · 1 line
2.28.0.windows.1
PATCH v7 11/25 osdep: file locking functions are not available on Win32
In reply to Yonggang Luoint qemu_lock_fd(int fd, int64_t start, int64_t len, bool exclusive); int qemu_unlock_fd(int fd, int64_t start, int64_t len);
int qemu_lock_fd_test(int fd, int64_t start, int64_t len, bool exclusive); bool qemu_has_ofd_lock(void);
--- include/qemu/osdep.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/qemu/osdep.h +1 -1
@@ -502,11 +502,11 @@ int qemu_close(int fd);int qemu_unlink (const char *name);#ifndef _WIN32int qemu_dup (int fd); -#endif int qemu_lock_fd (int fd,int64_t start,int64_t len,bool exclusive);int qemu_unlock_fd (int fd,int64_t start,int64_t len);int qemu_lock_fd_test (int fd,int64_t start,int64_t len,bool exclusive);bool qemu_has_ofd_lock (void ); +#endif #if defined(__HAIKU__) && defined(__i386__)#define FMT_pid "%ld"
Signature · 1 line
2.28.0.windows.1
PATCH v7 12/25 meson: Use -b to ignore CR vs. CR-LF issues on Windows
In reply to Yonggang LuoOn windows, a difference in line endings causes testsuite failures complaining that every single line in files such as 'tests/qapi-schemadoc-good.texi' is wrong. Fix it by adding -b to diff.
--- tests/qapi-schema/meson.build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tests/qapi-schema/meson.build +1 -1
@@ -220,6 +220,6 @@ qapi_doc = custom_target('QAPI doc', # "full_path()" needed here to work around # https://github.com/mesonbuild/meson/issues/7585 -test('QAPI doc', diff, args: ['-u', files('doc-good.texi'), qapi_doc[0].full_path()], +test('QAPI doc', diff, args: ['-b', '-u', files('doc-good.texi'), qapi_doc[0].full_path()], depends: qapi_doc, suite: ['qapi-schema', 'qapi-doc'])
Signature · 1 line
2.28.0.windows.1
PATCH v7 13/25 gcrypt: test_tls_psk_init should write binary file instead text file.
In reply to Yonggang LuoOn windows, if open file with "w", it's will automatically convert "\n" to "\r\n" when writing to file.
Convert unlink to use g_remove.
--- tests/crypto-tls-psk-helpers.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
tests/crypto-tls-psk-helpers.c +4 -2
@@ -26,13 +26,15 @@#include "crypto-tls-psk-helpers.h" #include "qemu/sockets.h" +#include <glib/gstdio.h> +#ifdef QCRYPTO_HAVE_TLS_TEST_SUPPORT void test_tls_psk_init (const char *pskfile) {FILE *fp; - fp =fopen (pskfile,"w" ); + fp =fopen (pskfile,"wb" );if (fp ==NULL ) {g_critical ("Failed to create pskfile %s" , pskfile);abort ();
@@ -44,7 +46,7 @@ void test_tls_psk_init(const char *pskfile)void test_tls_psk_cleanup (const char *pskfile) { -unlink (pskfile); +g_remove (pskfile); }#endif /* QCRYPTO_HAVE_TLS_TEST_SUPPORT */
Signature · 1 line
2.28.0.windows.1
PATCH v7 14/25 tests: Enable crypto tests under msys2/mingw
In reply to Yonggang LuoFixes following tests on msys2/mingw
'test-crypto-tlscredsx509': ['crypto-tls-x509-helpers.c', 'pkix_asn1_tab.c',
tasn1, crypto],
'test-crypto-tlssession': ['crypto-tls-x509-helpers.c', 'pkix_asn1_tab.c', 'crypto-tls-psk-helpers.c',
tasn1, crypto],
'test-io-channel-tls': ['io-channel-helpers.c', 'crypto-tls-x509-helpers.c', 'pkix_asn1_tab.c',
tasn1, io, crypto]}These tests are failure with:
ERROR test-crypto-tlscredsx509 - missing test plan ERROR test-crypto-tlssession - missing test plan ERROR test-io-channel-tls - missing test plan
Because on win32 those test case are all disabled in the header
Add qemu_socket_pair for cross platform support, convert file system handling functions to glib
Add qemu_link function instead posix only link function. Use send ad recv from qemu that convert Windows Socks error to errno properly.
--- tests/crypto-tls-x509-helpers.c | 169 ++++++++++++++++++++++++++++++- tests/crypto-tls-x509-helpers.h | 9 +- tests/test-crypto-tlscredsx509.c | 47 +++++---- tests/test-crypto-tlssession.c | 68 +++++++------ tests/test-io-channel-tls.c | 51 ++++++---- 5 files changed, 266 insertions(+), 78 deletions(-)
tests/crypto-tls-x509-helpers.c +167 -2
@@ -23,6 +23,8 @@#include "crypto-tls-x509-helpers.h" #include "crypto/init.h" #include "qemu/sockets.h" +#include <glib.h> +#include <glib/gstdio.h> #ifdef QCRYPTO_HAVE_TLS_TEST_SUPPORT
@@ -133,7 +135,7 @@ void test_tls_init(const char *keyfile)void test_tls_cleanup (const char *keyfile) {asn1_delete_structure (&pkix_asn1); -unlink (keyfile); +g_remove (keyfile); }/*
@@ -501,8 +503,171 @@ void test_tls_discard_cert(QCryptoTLSTestCertReq *req) req->crt =NULL ;if (getenv ("QEMU_TEST_DEBUG_CERTS" ) ==NULL ) { -unlink (req->filename); +g_remove (req->filename); } } +int qemu_link (const char *exist_path1,const char *new_path2) +{ +#ifdef _WIN32 + g_autofree gchar *current_dir = g_get_current_dir(); + g_autofree gchar *full_path = g_build_filename(current_dir, exist_path1, NULL); +return CreateSymbolicLinkA (new_path2, full_path,0 |SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE ) ?0 :-1 ; +#else +return link (exist_path1, new_path2); +#endif +} + +#ifdef _WIN32 + +static int __stream_socketpair (struct addrinfo * addr_info,int sock[2 ]){ +SOCKET listener, client, server; +int opt =1 ; + + listener = server = client =INVALID_SOCKET ; + listener =socket (addr_info->ai_family, addr_info->ai_socktype, addr_info->ai_protocol); +if (INVALID_SOCKET == listener) + goto fail; + +setsockopt (listener,SOL_SOCKET ,SO_REUSEADDR ,(const char *)&opt,sizeof (opt)); + +if (SOCKET_ERROR ==bind (listener, addr_info->ai_addr, addr_info->ai_addrlen)) + goto fail; + +if (SOCKET_ERROR ==getsockname (listener, addr_info->ai_addr, (int *)&addr_info->ai_addrlen)) + goto fail; + +if (SOCKET_ERROR ==listen (listener,5 )) + goto fail; + + client =socket (addr_info->ai_family, addr_info->ai_socktype, addr_info->ai_protocol); + +if (INVALID_SOCKET == client) + goto fail; + +if (SOCKET_ERROR ==connect (client,addr_info->ai_addr,addr_info->ai_addrlen)) + goto fail; + + server =accept (listener,0 ,0 ); + +if (INVALID_SOCKET == server) + goto fail; + +closesocket (listener); + + sock[0 ] = client; + sock[1 ] = server; + +return 0 ; +fail: +if (INVALID_SOCKET !=listener) +closesocket (listener); +if (INVALID_SOCKET !=client) +closesocket (client); +return -1 ; +} + +static int __dgram_socketpair (struct addrinfo * addr_info,int sock[2 ]) +{ +SOCKET client, server; +struct addrinfo addr, *result =NULL ; +const char * address; +int opt =1 ; + + server = client =INVALID_SOCKET ; + + server =socket (addr_info->ai_family, addr_info->ai_socktype, addr_info->ai_protocol); +if (INVALID_SOCKET == server) + goto fail; + +setsockopt (server,SOL_SOCKET ,SO_REUSEADDR , (const char *)&opt,sizeof (opt)); + +if (SOCKET_ERROR ==bind (server, addr_info->ai_addr, addr_info->ai_addrlen)) + goto fail; + +if (SOCKET_ERROR ==getsockname (server, addr_info->ai_addr, (int *)&addr_info->ai_addrlen)) + goto fail; + + client =socket (addr_info->ai_family, addr_info->ai_socktype, addr_info->ai_protocol); +if (INVALID_SOCKET == client) + goto fail; + +memset (&addr,0 ,sizeof (addr)); + addr.ai_family = addr_info->ai_family; + addr.ai_socktype = addr_info->ai_socktype; + addr.ai_protocol = addr_info->ai_protocol; + +if (AF_INET6 ==addr.ai_family) + address ="0:0:0:0:0:0:0:1" ; +else + address ="127.0.0.1" ; + +if (getaddrinfo (address,"0" , &addr, &result)) + goto fail; + +setsockopt (client,SOL_SOCKET ,SO_REUSEADDR ,(const char *)&opt,sizeof (opt)); +if (SOCKET_ERROR ==bind (client, result->ai_addr, result->ai_addrlen)) + goto fail; + +if (SOCKET_ERROR ==getsockname (client, result->ai_addr, (int *)&result->ai_addrlen)) + goto fail; + +if (SOCKET_ERROR ==connect (server, result->ai_addr, result->ai_addrlen)) + goto fail; + +if (SOCKET_ERROR ==connect (client, addr_info->ai_addr, addr_info->ai_addrlen)) + goto fail; + +freeaddrinfo (result); + sock[0 ] = client; + sock[1 ] = server; +return 0 ; + +fail: +if (INVALID_SOCKET !=client) +closesocket (client); +if (INVALID_SOCKET !=server) +closesocket (server); +if (result) +freeaddrinfo (result); +return -1 ; +} + +int qemu_socketpair (int family,int type,int protocol,int recv[2 ]){ +const char * address; +struct addrinfo addr_info,*p_addrinfo; +int result =-1 ; + +if (family ==AF_UNIX ) + { + family =AF_INET ; + } + +memset (&addr_info,0 ,sizeof (addr_info)); + addr_info.ai_family = family; + addr_info.ai_socktype = type; + addr_info.ai_protocol = protocol; +if (AF_INET6 ==family) + address ="0:0:0:0:0:0:0:1" ; +else + address ="127.0.0.1" ; + +if (0 ==getaddrinfo (address,"0" , &addr_info, &p_addrinfo)){ +if (SOCK_STREAM == type) + result =__stream_socketpair (p_addrinfo, recv); +else if (SOCK_DGRAM == type) + result =__dgram_socketpair (p_addrinfo, recv); +freeaddrinfo (p_addrinfo); + } +return result; +} + +#else + +int qemu_socketpair (int family,int type,int protocol,int recv[2 ]) { +return socketpair (family, type, protocol, recv); +} + +#endif +#endif /* QCRYPTO_HAVE_TLS_TEST_SUPPORT */
tests/crypto-tls-x509-helpers.h +7 -2
@@ -24,8 +24,9 @@#include <gnutls/gnutls.h> #include <gnutls/x509.h> -#if !(definedWIN32 ) && \ - defined(CONFIG_TASN1 ) +#include "qemu/osdep.h" + +#if defined(CONFIG_TASN1 )# define QCRYPTO_HAVE_TLS_TEST_SUPPORT #endif
@@ -127,6 +128,10 @@ void test_tls_cleanup(const char *keyfile);extern const ASN1_ARRAY_TYPE pkix_asn1_tab[]; +int qemu_link (const char *exist_path1,const char *new_path2); + +int qemu_socketpair (int family,int type,int protocol,int recv[2 ]); +#endif /* QCRYPTO_HAVE_TLS_TEST_SUPPORT */ #endif
tests/test-crypto-tlscredsx509.c +25 -22
94 lines not on this page · raw message
tests/test-crypto-tlssession.c +38 -30
142 lines not on this page · raw message
tests/test-io-channel-tls.c +29 -22
94 lines not on this page · raw message
Signature · 1 line
2.28.0.windows.1
PATCH v7 15/25 meson: remove empty else and duplicated gio deps
In reply to Yonggang Luo--- meson.build | 6 ------ 1 file changed, 6 deletions(-)
meson.build +0 -6
@@ -317,7 +317,6 @@ opengl = not_found if 'CONFIG_OPENGL' in config_host opengl = declare_dependency(compile_args: config_host['OPENGL_CFLAGS'].split(), link_args: config_host['OPENGL_LIBS'].split()) -else endif gtk = not_found if 'CONFIG_GTK' in config_host
@@ -344,11 +343,6 @@ if 'CONFIG_ICONV' in config_host iconv = declare_dependency(compile_args: config_host['ICONV_CFLAGS'].split(), link_args: config_host['ICONV_LIBS'].split()) endif -gio = not_found -if 'CONFIG_GIO' in config_host - gio = declare_dependency(compile_args: config_host['GIO_CFLAGS'].split(), - link_args: config_host['GIO_LIBS'].split()) -endif vnc = not_found png = not_found jpeg = not_found
Signature · 1 line
2.28.0.windows.1
Re: [PATCH v7 15/25] meson: remove empty else and duplicated gio deps
Quoted 21 lines · Yonggang Luo
Signed-off-by Yonggang Luo <[email protected]>Reviewed-by Daniel P. Berrangé <[email protected]>--- meson.build | 6 ------ 1 file changed, 6 deletions(-)meson.build +0
-1@@ -317,7 +317,6 @@ opengl = not_found if 'CONFIG_OPENGL' in config_host opengl = declare_dependency(compile_args: config_host['OPENGL_CFLAGS'].split(), link_args: config_host['OPENGL_LIBS'].split()) -else endif gtk = not_found if 'CONFIG_GTK' in config_host@@ -344,11 +343,6 @@ if 'CONFIG_ICONV' in config_host iconv = declare_dependency(compile_args: config_host['ICONV_CFLAGS'].split(),
meson.build if 'CONFIG_ICONV' in config_host · line 348
Quoted 10 lines
meson.build +0
-5link_args: config_host['ICONV_LIBS'].split()) endif -gio = not_found -if 'CONFIG_GIO' in config_host - gio = declare_dependency(compile_args: config_host['GIO_CFLAGS'].split(), - link_args: config_host['GIO_LIBS'].split()) -endif vnc = not_found png = not_found jpeg = not_found
PATCH v7 16/25 vmstate: Fixes test-vmstate.c on msys2/mingw
In reply to Yonggang LuoThe vmstate are valid on win32, just need generate tmp path properly
--- tests/test-vmstate.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
tests/test-vmstate.c +2 -1
@@ -34,7 +34,6 @@#include "qemu/module.h" #include "io/channel-file.h" -static char temp_file[] ="/tmp/vmst.test.XXXXXX" ;static int temp_fd;
@@ -1487,6 +1486,8 @@ static void test_tmp_struct(void)int main (int argc,char **argv) { + g_autofree char *temp_file = g_strdup_printf( +"%s/vmst.test.XXXXXX" ,g_get_tmp_dir ()); temp_fd =mkstemp (temp_file);module_call_init (MODULE_INIT_QOM );
Signature · 1 line
2.28.0.windows.1