diff mbox series

[v7,03/25] block: Fixes nfs compiling error on msys2/mingw

Message ID 20200910103059.987-4-luoyonggang@gmail.com
State New
Headers show
Series None | expand

Commit Message

罗勇刚(Yonggang Luo) Sept. 10, 2020, 10:30 a.m. UTC
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(-)

Comments

Peter Lieven Sept. 10, 2020, 8:16 p.m. UTC | #1
> 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 &lt;<a href="mailto:luoyonggang@gmail.com" class="">luoyonggang@gmail.com</a>&gt;:</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=""> &nbsp;&nbsp;27 | #include &lt;poll.h&gt;<br class=""> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;^~~~~~~~<br class="">compilation terminated.<br class=""><br class="">../block/nfs.c:63:5: error: unknown type name 'blkcnt_t'<br class=""> &nbsp;&nbsp;63 | &nbsp;&nbsp;&nbsp;&nbsp;blkcnt_t st_blocks;<br class=""> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;&nbsp;^~~~~~~~<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=""> &nbsp;550 | &nbsp;&nbsp;&nbsp;&nbsp;client-&gt;st_blocks = st.st_blocks;<br class=""> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;^<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=""> &nbsp;751 | &nbsp;&nbsp;&nbsp;&nbsp;return (task.ret &lt; 0 ? task.ret : st.st_blocks * 512);<br class=""> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;^<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=""> &nbsp;805 | &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;client-&gt;st_blocks = st.st_blocks;<br class=""> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;^<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=""> &nbsp;752 | }<br class=""> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| ^<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 &lt;<a href="mailto:luoyonggang@gmail.com" class="">luoyonggang@gmail.com</a>&gt;<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 &lt;poll.h&gt;<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=""> &nbsp;&nbsp;&nbsp;&nbsp;struct nfs_context *context;<br class=""> &nbsp;&nbsp;&nbsp;&nbsp;struct nfsfh *fh;<br class="">@@ -70,7 +79,7 @@ typedef struct NFSRPC {<br class=""> &nbsp;&nbsp;&nbsp;&nbsp;int ret;<br class=""> &nbsp;&nbsp;&nbsp;&nbsp;int complete;<br class=""> &nbsp;&nbsp;&nbsp;&nbsp;QEMUIOVector *iov;<br class="">- &nbsp;&nbsp;&nbsp;struct stat *st;<br class="">+ &nbsp;&nbsp;&nbsp;struct nfs_stat *st;<br class=""> &nbsp;&nbsp;&nbsp;&nbsp;Coroutine *co;<br class=""> &nbsp;&nbsp;&nbsp;&nbsp;NFSClient *client;<br class=""> } NFSRPC;<br class="">@@ -415,11 +424,20 @@ static void nfs_file_close(BlockDriverState *bs)<br class=""> &nbsp;&nbsp;&nbsp;&nbsp;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="">+ &nbsp;&nbsp;&nbsp;return (st-&gt;st_size + 511) / 512;<br class="">+#else<br class="">+ &nbsp;&nbsp;&nbsp;return st-&gt;st_blocks;<br class="">+#endif<br class="">+}<br class="">+<br class=""> static int64_t nfs_client_open(NFSClient *client, BlockdevOptionsNfs *opts,<br class=""> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;int flags, int open_flags, Error **errp)<br class=""> {<br class=""> &nbsp;&nbsp;&nbsp;&nbsp;int64_t ret = -EINVAL;<br class="">- &nbsp;&nbsp;&nbsp;struct stat st;<br class="">+ &nbsp;&nbsp;&nbsp;struct nfs_stat st;<br class=""> &nbsp;&nbsp;&nbsp;&nbsp;char *file = NULL, *strp = NULL;<br class=""><br class=""> &nbsp;&nbsp;&nbsp;&nbsp;qemu_mutex_init(&amp;client-&gt;mutex);<br class="">@@ -545,7 +563,7 @@ static int64_t nfs_client_open(NFSClient *client, BlockdevOptionsNfs *opts,<br class=""> &nbsp;&nbsp;&nbsp;&nbsp;}<br class=""><br class=""> &nbsp;&nbsp;&nbsp;&nbsp;ret = DIV_ROUND_UP(st.st_size, BDRV_SECTOR_SIZE);<br class="">- &nbsp;&nbsp;&nbsp;client-&gt;st_blocks = st.st_blocks;<br class="">+ &nbsp;&nbsp;&nbsp;client-&gt;st_blocks = nfs_get_st_blocks(&amp;st);<br class=""> &nbsp;&nbsp;&nbsp;&nbsp;client-&gt;has_zero_init = S_ISREG(st.st_mode);<br class=""> &nbsp;&nbsp;&nbsp;&nbsp;*strp = '/';<br class=""> &nbsp;&nbsp;&nbsp;&nbsp;goto out;<br class="">@@ -729,7 +747,7 @@ static int64_t nfs_get_allocated_file_size(BlockDriverState *bs)<br class=""> {<br class=""> &nbsp;&nbsp;&nbsp;&nbsp;NFSClient *client = bs-&gt;opaque;<br class=""> &nbsp;&nbsp;&nbsp;&nbsp;NFSRPC task = {0};<br class="">- &nbsp;&nbsp;&nbsp;struct stat st;<br class="">+ &nbsp;&nbsp;&nbsp;struct nfs_stat st;<br class=""><br class=""> &nbsp;&nbsp;&nbsp;&nbsp;if (bdrv_is_read_only(bs) &amp;&amp;<br class=""> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;!(bs-&gt;open_flags &amp; BDRV_O_NOCACHE)) {<br class="">@@ -746,7 +764,7 @@ static int64_t nfs_get_allocated_file_size(BlockDriverState *bs)<br class=""> &nbsp;&nbsp;&nbsp;&nbsp;nfs_set_events(client);<br class=""> &nbsp;&nbsp;&nbsp;&nbsp;BDRV_POLL_WHILE(bs, !task.complete);<br class=""><br class="">- &nbsp;&nbsp;&nbsp;return (task.ret &lt; 0 ? task.ret : st.st_blocks * 512);<br class="">+ &nbsp;&nbsp;&nbsp;return (task.ret &lt; 0 ? task.ret : nfs_get_st_blocks(&amp;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=""> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;BlockReopenQueue *queue, Error **errp)<br class=""> {<br class=""> &nbsp;&nbsp;&nbsp;&nbsp;NFSClient *client = state-&gt;bs-&gt;opaque;<br class="">- &nbsp;&nbsp;&nbsp;struct stat st;<br class="">+ &nbsp;&nbsp;&nbsp;struct nfs_stat st;<br class=""> &nbsp;&nbsp;&nbsp;&nbsp;int ret = 0;<br class=""><br class=""> &nbsp;&nbsp;&nbsp;&nbsp;if (state-&gt;flags &amp; BDRV_O_RDWR &amp;&amp; bdrv_is_read_only(state-&gt;bs)) {<br class="">@@ -800,7 +818,7 @@ static int nfs_reopen_prepare(BDRVReopenState *state,<br class=""> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;nfs_get_error(client-&gt;context));<br class=""> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return ret;<br class=""> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br class="">- &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;client-&gt;st_blocks = st.st_blocks;<br class="">+ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;client-&gt;st_blocks = nfs_get_st_blocks(&amp;st);<br class=""> &nbsp;&nbsp;&nbsp;&nbsp;}<br class=""><br class=""> &nbsp;&nbsp;&nbsp;&nbsp;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.&nbsp;</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="">&nbsp;</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="">&nbsp;#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="">&nbsp;</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="">&nbsp;#include &lt;poll.h&gt;</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="">&nbsp;#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="">&nbsp;#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="">&nbsp;#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="">&nbsp;&nbsp; &nbsp; 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="">&nbsp;&nbsp; &nbsp; 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="">&nbsp;&nbsp; &nbsp; 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="">&nbsp;&nbsp; &nbsp; 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="">&nbsp;&nbsp; &nbsp; 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="">&nbsp;&nbsp; &nbsp; 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="">&nbsp;&nbsp; &nbsp; 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="">&nbsp;&nbsp; &nbsp; }</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="">&nbsp;</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="">&nbsp;&nbsp; &nbsp; 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="">&nbsp;&nbsp; &nbsp; client-&gt;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="">&nbsp;&nbsp; &nbsp; client-&gt;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="">&nbsp;&nbsp; &nbsp; *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="">&nbsp;&nbsp; &nbsp; 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="">&nbsp;&nbsp; &nbsp; return client-&gt;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="">&nbsp;}</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="">&nbsp;</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="">&nbsp;/* Called (via nfs_service) with QemuMutex held.&nbsp; */</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="">&nbsp;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="">&nbsp;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="">&nbsp;</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="">&nbsp;&nbsp; &nbsp; return (task.ret &lt; 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="">&nbsp;}</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="">&nbsp;</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="">&nbsp;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="">&nbsp;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="">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; 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="">&nbsp;&nbsp; &nbsp; }</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="">&nbsp;</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="">&nbsp;&nbsp; &nbsp; /* 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="">&nbsp;&nbsp; &nbsp; if (!(state-&gt;flags &amp; 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="">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; ret = nfs_fstat(client-&gt;context, client-&gt;fh, &amp;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="">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; }</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="">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; client-&gt;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="">&nbsp;&nbsp; &nbsp; }</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="">&nbsp;</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="">&nbsp;&nbsp; &nbsp; 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="">&nbsp;}</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="">&nbsp;&nbsp; &nbsp; .create_opts&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = &amp;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="">&nbsp;</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="">&nbsp;&nbsp; &nbsp; .bdrv_has_zero_init &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = 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="">&nbsp;&nbsp; &nbsp; .bdrv_get_allocated_file_size &nbsp; = 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="">&nbsp;&nbsp; &nbsp; .bdrv_co_truncate &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = 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="">&nbsp;</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="">&nbsp;&nbsp; &nbsp; .bdrv_file_open &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = 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 mbox series

Patch

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;