qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH V3] block/nfs: cache allocated filesize for read-only files
@ 2015-08-27 10:30 Peter Lieven
  2015-08-28 17:42 ` Jeff Cody
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Peter Lieven @ 2015-08-27 10:30 UTC (permalink / raw)
  To: qemu-devel, qemu-block; +Cc: kwolf, jcody, Peter Lieven

If the file is readonly its not expected to grow so
save the blocking call to nfs_fstat_async and use
the value saved at connection time. Also important
the monitor (and thus the main loop) will not hang
if block device info is queried and the NFS share
is unresponsive.

Signed-off-by: Peter Lieven <pl@kamp.de>
---
v1->v2: update cache on reopen_prepare [Max]
v2->v3: use cache only if cache.direct=off [Max]

 block/nfs.c | 36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)

diff --git a/block/nfs.c b/block/nfs.c
index 02eb4e4..887a98e 100644
--- a/block/nfs.c
+++ b/block/nfs.c
@@ -43,6 +43,7 @@ typedef struct NFSClient {
     int events;
     bool has_zero_init;
     AioContext *aio_context;
+    blkcnt_t st_blocks;
 } NFSClient;
 
 typedef struct NFSRPC {
@@ -374,6 +375,7 @@ static int64_t nfs_client_open(NFSClient *client, const char *filename,
     }
 
     ret = DIV_ROUND_UP(st.st_size, BDRV_SECTOR_SIZE);
+    client->st_blocks = st.st_blocks;
     client->has_zero_init = S_ISREG(st.st_mode);
     goto out;
 fail:
@@ -464,6 +466,11 @@ static int64_t nfs_get_allocated_file_size(BlockDriverState *bs)
     NFSRPC task = {0};
     struct stat st;
 
+    if (bdrv_is_read_only(bs) &&
+        !(bs->open_flags & BDRV_O_NOCACHE)) {
+        return client->st_blocks * 512;
+    }
+
     task.st = &st;
     if (nfs_fstat_async(client->context, client->fh, nfs_co_generic_cb,
                         &task) != 0) {
@@ -484,6 +491,34 @@ static int nfs_file_truncate(BlockDriverState *bs, int64_t offset)
     return nfs_ftruncate(client->context, client->fh, offset);
 }
 
+/* Note that this will not re-establish a connection with the NFS server
+ * - it is effectively a NOP.  */
+static int nfs_reopen_prepare(BDRVReopenState *state,
+                              BlockReopenQueue *queue, Error **errp)
+{
+    NFSClient *client = state->bs->opaque;
+    struct stat st;
+    int ret = 0;
+
+    if (state->flags & BDRV_O_RDWR && bdrv_is_read_only(state->bs)) {
+        error_setg(errp, "Cannot open a read-only mount as read-write");
+        return -EACCES;
+    }
+
+    /* Update cache for read-only reopens */
+    if (!(state->flags & BDRV_O_RDWR)) {
+        ret = nfs_fstat(client->context, client->fh, &st);
+        if (ret < 0) {
+            error_setg(errp, "Failed to fstat file: %s",
+                       nfs_get_error(client->context));
+            return ret;
+        }
+        client->st_blocks = st.st_blocks;
+    }
+
+    return 0;
+}
+
 static BlockDriver bdrv_nfs = {
     .format_name                    = "nfs",
     .protocol_name                  = "nfs",
@@ -499,6 +534,7 @@ static BlockDriver bdrv_nfs = {
     .bdrv_file_open                 = nfs_file_open,
     .bdrv_close                     = nfs_file_close,
     .bdrv_create                    = nfs_file_create,
+    .bdrv_reopen_prepare            = nfs_reopen_prepare,
 
     .bdrv_co_readv                  = nfs_co_readv,
     .bdrv_co_writev                 = nfs_co_writev,
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] [PATCH V3] block/nfs: cache allocated filesize for read-only files
  2015-08-27 10:30 [Qemu-devel] [PATCH V3] block/nfs: cache allocated filesize for read-only files Peter Lieven
@ 2015-08-28 17:42 ` Jeff Cody
  2015-08-29 15:24 ` [Qemu-devel] [Qemu-block] " Max Reitz
  2015-08-31 20:45 ` [Qemu-devel] " Jeff Cody
  2 siblings, 0 replies; 4+ messages in thread
From: Jeff Cody @ 2015-08-28 17:42 UTC (permalink / raw)
  To: Peter Lieven; +Cc: kwolf, qemu-devel, qemu-block

On Thu, Aug 27, 2015 at 12:30:41PM +0200, Peter Lieven wrote:
> If the file is readonly its not expected to grow so
> save the blocking call to nfs_fstat_async and use
> the value saved at connection time. Also important
> the monitor (and thus the main loop) will not hang
> if block device info is queried and the NFS share
> is unresponsive.
> 
> Signed-off-by: Peter Lieven <pl@kamp.de>
> ---
> v1->v2: update cache on reopen_prepare [Max]
> v2->v3: use cache only if cache.direct=off [Max]
> 

Reviewed-by: Jeff Cody <jcody@redhat.com>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] [Qemu-block] [PATCH V3] block/nfs: cache allocated filesize for read-only files
  2015-08-27 10:30 [Qemu-devel] [PATCH V3] block/nfs: cache allocated filesize for read-only files Peter Lieven
  2015-08-28 17:42 ` Jeff Cody
@ 2015-08-29 15:24 ` Max Reitz
  2015-08-31 20:45 ` [Qemu-devel] " Jeff Cody
  2 siblings, 0 replies; 4+ messages in thread
From: Max Reitz @ 2015-08-29 15:24 UTC (permalink / raw)
  To: Peter Lieven, qemu-devel, qemu-block; +Cc: kwolf

[-- Attachment #1: Type: text/plain, Size: 633 bytes --]

On 27.08.2015 12:30, Peter Lieven wrote:
> If the file is readonly its not expected to grow so
> save the blocking call to nfs_fstat_async and use
> the value saved at connection time. Also important
> the monitor (and thus the main loop) will not hang
> if block device info is queried and the NFS share
> is unresponsive.
> 
> Signed-off-by: Peter Lieven <pl@kamp.de>
> ---
> v1->v2: update cache on reopen_prepare [Max]
> v2->v3: use cache only if cache.direct=off [Max]
> 
>  block/nfs.c | 36 ++++++++++++++++++++++++++++++++++++
>  1 file changed, 36 insertions(+)

Reviewed-by: Max Reitz <mreitz@redhat.com>


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 473 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] [PATCH V3] block/nfs: cache allocated filesize for read-only files
  2015-08-27 10:30 [Qemu-devel] [PATCH V3] block/nfs: cache allocated filesize for read-only files Peter Lieven
  2015-08-28 17:42 ` Jeff Cody
  2015-08-29 15:24 ` [Qemu-devel] [Qemu-block] " Max Reitz
@ 2015-08-31 20:45 ` Jeff Cody
  2 siblings, 0 replies; 4+ messages in thread
From: Jeff Cody @ 2015-08-31 20:45 UTC (permalink / raw)
  To: Peter Lieven; +Cc: kwolf, qemu-devel, qemu-block

On Thu, Aug 27, 2015 at 12:30:41PM +0200, Peter Lieven wrote:
> If the file is readonly its not expected to grow so
> save the blocking call to nfs_fstat_async and use
> the value saved at connection time. Also important
> the monitor (and thus the main loop) will not hang
> if block device info is queried and the NFS share
> is unresponsive.
> 
> Signed-off-by: Peter Lieven <pl@kamp.de>
> ---
> v1->v2: update cache on reopen_prepare [Max]
> v2->v3: use cache only if cache.direct=off [Max]
> 

Thanks,

Applied to my block branch:

git git://github.com/codyprime/qemu-kvm-jtc.git block

-Jeff

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2015-08-31 20:45 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-08-27 10:30 [Qemu-devel] [PATCH V3] block/nfs: cache allocated filesize for read-only files Peter Lieven
2015-08-28 17:42 ` Jeff Cody
2015-08-29 15:24 ` [Qemu-devel] [Qemu-block] " Max Reitz
2015-08-31 20:45 ` [Qemu-devel] " Jeff Cody

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).