Message ID | 20200910103059.987-4-luoyonggang@gmail.com |
---|---|
State | New |
Headers | show |
Series | None | expand |
> Am 10.09.2020 um 12:30 schrieb Yonggang Luo <luoyonggang@gmail.com>: > > 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_blocks in struct _stat64, so we use consistence st_size instead. > > Signed-off-by: Yonggang Luo <luoyonggang@gmail.com> > --- > block/nfs.c | 32 +++++++++++++++++++++++++------- > 1 file changed, 25 insertions(+), 7 deletions(-) > > diff --git a/block/nfs.c b/block/nfs.c > index 61a249a9fc..db6d8c2d2b 100644 > --- a/block/nfs.c > +++ b/block/nfs.c > @@ -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; > -- > 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: diff --git a/block/nfs.c b/block/nfs.c index 61a249a..0983143 100644 --- a/block/nfs.c +++ b/block/nfs.c @@ -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 <html><head><meta http-equiv="Content-Type" content="text/html; charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><br class=""><div><br class=""><blockquote type="cite" class=""><div class="">Am 10.09.2020 um 12:30 schrieb Yonggang Luo <<a href="mailto:luoyonggang@gmail.com" class="">luoyonggang@gmail.com</a>>:</div><br class="Apple-interchange-newline"><div class=""><div class="">These compiling errors are fixed:<br class="">../block/nfs.c:27:10: fatal error: poll.h: No such file or directory<br class=""> 27 | #include <poll.h><br class=""> | ^~~~~~~~<br class="">compilation terminated.<br class=""><br class="">../block/nfs.c:63:5: error: unknown type name 'blkcnt_t'<br class=""> 63 | blkcnt_t st_blocks;<br class=""> | ^~~~~~~~<br class="">../block/nfs.c: In function 'nfs_client_open':<br class="">../block/nfs.c:550:27: error: 'struct _stat64' has no member named 'st_blocks'<br class=""> 550 | client->st_blocks = st.st_blocks;<br class=""> | ^<br class="">../block/nfs.c: In function 'nfs_get_allocated_file_size':<br class="">../block/nfs.c:751:41: error: 'struct _stat64' has no member named 'st_blocks'<br class=""> 751 | return (task.ret < 0 ? task.ret : st.st_blocks * 512);<br class=""> | ^<br class="">../block/nfs.c: In function 'nfs_reopen_prepare':<br class="">../block/nfs.c:805:31: error: 'struct _stat64' has no member named 'st_blocks'<br class=""> 805 | client->st_blocks = st.st_blocks;<br class=""> | ^<br class="">../block/nfs.c: In function 'nfs_get_allocated_file_size':<br class="">../block/nfs.c:752:1: error: control reaches end of non-void function [-Werror=return-type]<br class=""> 752 | }<br class=""> | ^<br class=""><br class="">On msys2/mingw, there is no st_blocks in struct _stat64, so we use consistence st_size instead.<br class=""><br class="">Signed-off-by: Yonggang Luo <<a href="mailto:luoyonggang@gmail.com" class="">luoyonggang@gmail.com</a>><br class="">---<br class=""> block/nfs.c | 32 +++++++++++++++++++++++++-------<br class=""> 1 file changed, 25 insertions(+), 7 deletions(-)<br class=""><br class="">diff --git a/block/nfs.c b/block/nfs.c<br class="">index 61a249a9fc..db6d8c2d2b 100644<br class="">--- a/block/nfs.c<br class="">+++ b/block/nfs.c<br class="">@@ -24,7 +24,9 @@<br class=""><br class=""> #include "qemu/osdep.h"<br class=""><br class="">+#if !defined(_WIN32)<br class=""> #include <poll.h><br class="">+#endif<br class=""> #include "qemu/config-file.h"<br class=""> #include "qemu/error-report.h"<br class=""> #include "qapi/error.h"<br class="">@@ -51,6 +53,13 @@<br class=""> #define QEMU_NFS_MAX_PAGECACHE_SIZE (8388608 / NFS_BLKSIZE)<br class=""> #define QEMU_NFS_MAX_DEBUG_LEVEL 2<br class=""><br class="">+#if defined (_WIN32)<br class="">+#define nfs_stat __stat64<br class="">+typedef long long blkcnt_t;<br class="">+#else<br class="">+#define nfs_stat stat<br class="">+#endif<br class="">+<br class=""> typedef struct NFSClient {<br class=""> struct nfs_context *context;<br class=""> struct nfsfh *fh;<br class="">@@ -70,7 +79,7 @@ typedef struct NFSRPC {<br class=""> int ret;<br class=""> int complete;<br class=""> QEMUIOVector *iov;<br class="">- struct stat *st;<br class="">+ struct nfs_stat *st;<br class=""> Coroutine *co;<br class=""> NFSClient *client;<br class=""> } NFSRPC;<br class="">@@ -415,11 +424,20 @@ static void nfs_file_close(BlockDriverState *bs)<br class=""> nfs_client_close(client);<br class=""> }<br class=""><br class="">+static blkcnt_t nfs_get_st_blocks(const struct nfs_stat *st)<br class="">+{<br class="">+#if defined(_WIN32)<br class="">+ return (st->st_size + 511) / 512;<br class="">+#else<br class="">+ return st->st_blocks;<br class="">+#endif<br class="">+}<br class="">+<br class=""> static int64_t nfs_client_open(NFSClient *client, BlockdevOptionsNfs *opts,<br class=""> int flags, int open_flags, Error **errp)<br class=""> {<br class=""> int64_t ret = -EINVAL;<br class="">- struct stat st;<br class="">+ struct nfs_stat st;<br class=""> char *file = NULL, *strp = NULL;<br class=""><br class=""> qemu_mutex_init(&client->mutex);<br class="">@@ -545,7 +563,7 @@ static int64_t nfs_client_open(NFSClient *client, BlockdevOptionsNfs *opts,<br class=""> }<br class=""><br class=""> ret = DIV_ROUND_UP(st.st_size, BDRV_SECTOR_SIZE);<br class="">- client->st_blocks = st.st_blocks;<br class="">+ client->st_blocks = nfs_get_st_blocks(&st);<br class=""> client->has_zero_init = S_ISREG(st.st_mode);<br class=""> *strp = '/';<br class=""> goto out;<br class="">@@ -729,7 +747,7 @@ static int64_t nfs_get_allocated_file_size(BlockDriverState *bs)<br class=""> {<br class=""> NFSClient *client = bs->opaque;<br class=""> NFSRPC task = {0};<br class="">- struct stat st;<br class="">+ struct nfs_stat st;<br class=""><br class=""> if (bdrv_is_read_only(bs) &&<br class=""> !(bs->open_flags & BDRV_O_NOCACHE)) {<br class="">@@ -746,7 +764,7 @@ static int64_t nfs_get_allocated_file_size(BlockDriverState *bs)<br class=""> nfs_set_events(client);<br class=""> BDRV_POLL_WHILE(bs, !task.complete);<br class=""><br class="">- return (task.ret < 0 ? task.ret : st.st_blocks * 512);<br class="">+ return (task.ret < 0 ? task.ret : nfs_get_st_blocks(&st) * 512);<br class=""> }<br class=""><br class=""> static int coroutine_fn<br class="">@@ -778,7 +796,7 @@ static int nfs_reopen_prepare(BDRVReopenState *state,<br class=""> BlockReopenQueue *queue, Error **errp)<br class=""> {<br class=""> NFSClient *client = state->bs->opaque;<br class="">- struct stat st;<br class="">+ struct nfs_stat st;<br class=""> int ret = 0;<br class=""><br class=""> if (state->flags & BDRV_O_RDWR && bdrv_is_read_only(state->bs)) {<br class="">@@ -800,7 +818,7 @@ static int nfs_reopen_prepare(BDRVReopenState *state,<br class=""> nfs_get_error(client->context));<br class=""> return ret;<br class=""> }<br class="">- client->st_blocks = st.st_blocks;<br class="">+ client->st_blocks = nfs_get_st_blocks(&st);<br class=""> }<br class=""><br class=""> return 0;<br class="">-- <br class="">2.28.0.windows.1<br class=""></div></div></blockquote><div><br class=""></div><div><br class=""></div>You still implement nfs_get_allocated_file_size without actually returning the allocated file size on WIN32. </div><div>I would simply do this:</div><div><br class=""></div><div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 0, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><b class="">diff --git a/block/nfs.c b/block/nfs.c</b></span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 0, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><b class="">index 61a249a..0983143 100644</b></span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 0, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><b class="">--- a/block/nfs.c</b></span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 0, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><b class="">+++ b/block/nfs.c</b></span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(56, 185, 199);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">@@ -24,7 +24,9 @@</span></div><p style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 0, 0); min-height: 13px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><br class="webkit-block-placeholder"></p><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 0, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> #include "qemu/osdep.h"</span></div><p style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 0, 0); min-height: 13px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><br class="webkit-block-placeholder"></p><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(57, 192, 38);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">+#if !defined(_WIN32)</span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 0, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> #include <poll.h></span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(57, 192, 38);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">+#endif</span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 0, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> #include "qemu/config-file.h"</span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 0, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> #include "qemu/error-report.h"</span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 0, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> #include "qapi/error.h"</span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 0, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #38b9c7" class="">@@ -58,7 +60,9 @@</span><span style="font-variant-ligatures: no-common-ligatures" class=""> typedef struct NFSClient {</span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 0, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> bool has_zero_init;</span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 0, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> AioContext *aio_context;</span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 0, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> QemuMutex mutex;</span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(57, 192, 38);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">+#if !defined(_WIN32)</span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 0, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> blkcnt_t st_blocks;</span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(57, 192, 38);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">+#endif</span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 0, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> bool cache_used;</span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 0, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> NFSServer *server;</span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 0, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> char *path;</span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 0, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #38b9c7" class="">@@ -545,7 +549,9 @@</span><span style="font-variant-ligatures: no-common-ligatures" class=""> static int64_t nfs_client_open(NFSClient *client, BlockdevOptionsNfs *opts,</span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 0, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> }</span></div><p style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 0, 0); min-height: 13px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><br class="webkit-block-placeholder"></p><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 0, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> ret = DIV_ROUND_UP(st.st_size, BDRV_SECTOR_SIZE);</span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(57, 192, 38);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">+#if !defined(_WIN32)</span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 0, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> client->st_blocks = st.st_blocks;</span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(57, 192, 38);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">+#endif</span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 0, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> client->has_zero_init = S_ISREG(st.st_mode);</span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 0, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> *strp = '/';</span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 0, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> goto out;</span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 0, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #38b9c7" class="">@@ -706,6 +712,8 @@</span><span style="font-variant-ligatures: no-common-ligatures" class=""> static int nfs_has_zero_init(BlockDriverState *bs)</span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 0, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> return client->has_zero_init;</span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 0, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> }</span></div><p style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 0, 0); min-height: 13px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><br class="webkit-block-placeholder"></p><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(57, 192, 38);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">+</span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(57, 192, 38);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">+#if !defined(_WIN32)</span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 0, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> /* Called (via nfs_service) with QemuMutex held. */</span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 0, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> static void</span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 0, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> nfs_get_allocated_file_size_cb(int ret, struct nfs_context *nfs, void *data,</span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 0, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #38b9c7" class="">@@ -748,6 +756,7 @@</span><span style="font-variant-ligatures: no-common-ligatures" class=""> static int64_t nfs_get_allocated_file_size(BlockDriverState *bs)</span></div><p style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 0, 0); min-height: 13px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><br class="webkit-block-placeholder"></p><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 0, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> return (task.ret < 0 ? task.ret : st.st_blocks * 512);</span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 0, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> }</span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(57, 192, 38);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">+#endif</span></div><p style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 0, 0); min-height: 13px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><br class="webkit-block-placeholder"></p><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 0, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> static int coroutine_fn</span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 0, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> nfs_file_co_truncate(BlockDriverState *bs, int64_t offset, bool exact,</span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 0, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #38b9c7" class="">@@ -792,6 +801,7 @@</span><span style="font-variant-ligatures: no-common-ligatures" class=""> static int nfs_reopen_prepare(BDRVReopenState *state,</span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 0, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> return -EINVAL;</span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 0, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> }</span></div><p style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 0, 0); min-height: 13px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><br class="webkit-block-placeholder"></p><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(57, 192, 38);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">+#if !defined(_WIN32)</span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 0, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> /* Update cache for read-only reopens */</span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 0, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> if (!(state->flags & BDRV_O_RDWR)) {</span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 0, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> ret = nfs_fstat(client->context, client->fh, &st);</span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 0, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #38b9c7" class="">@@ -802,6 +812,7 @@</span><span style="font-variant-ligatures: no-common-ligatures" class=""> static int nfs_reopen_prepare(BDRVReopenState *state,</span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 0, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> }</span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 0, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> client->st_blocks = st.st_blocks;</span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 0, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> }</span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(57, 192, 38);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">+#endif</span></div><p style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 0, 0); min-height: 13px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><br class="webkit-block-placeholder"></p><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 0, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> return 0;</span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 0, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> }</span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 0, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #38b9c7" class="">@@ -869,7 +880,9 @@</span><span style="font-variant-ligatures: no-common-ligatures" class=""> static BlockDriver bdrv_nfs = {</span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 0, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> .create_opts = &nfs_create_opts,</span></div><p style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 0, 0); min-height: 13px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><br class="webkit-block-placeholder"></p><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 0, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> .bdrv_has_zero_init = nfs_has_zero_init,</span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(57, 192, 38);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">+#if !defined(_WIN32)</span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 0, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> .bdrv_get_allocated_file_size = nfs_get_allocated_file_size,</span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(57, 192, 38);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">+#endif</span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 0, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> .bdrv_co_truncate = nfs_file_co_truncate,</span></div><p style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 0, 0); min-height: 13px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><br class="webkit-block-placeholder"></p><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 0, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> .bdrv_file_open = nfs_file_open,</span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 0, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><br class=""></span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 0, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><br class=""></span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 0, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">Best,</span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 0, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">Peter</span></div></div><br class=""></body></html>
diff --git a/block/nfs.c b/block/nfs.c index 61a249a9fc..db6d8c2d2b 100644 --- a/block/nfs.c +++ b/block/nfs.c @@ -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;
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_blocks in struct _stat64, so we use consistence st_size instead. Signed-off-by: Yonggang Luo <luoyonggang@gmail.com> --- block/nfs.c | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-)