From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40518) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZSpSu-0003M8-8X for qemu-devel@nongnu.org; Fri, 21 Aug 2015 12:46:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZSpSt-0005oN-1Z for qemu-devel@nongnu.org; Fri, 21 Aug 2015 12:46:52 -0400 References: <1440143355-2918-1-git-send-email-pl@kamp.de> From: Max Reitz Message-ID: <55D755F6.2@redhat.com> Date: Fri, 21 Aug 2015 09:46:46 -0700 MIME-Version: 1.0 In-Reply-To: <1440143355-2918-1-git-send-email-pl@kamp.de> Content-Type: text/plain; charset=iso-8859-15; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH] block/nfs: cache allocated filesize for read-only files List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Peter Lieven , qemu-devel@nongnu.org, qemu-block@nongnu.org Cc: kwolf@redhat.com, jcody@redhat.com On 2015-08-21 at 00:49, 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 > --- > block/nfs.c | 6 ++++++ > 1 file changed, 6 insertions(+) First, I don't like the idea of this patch very much, but since I've never used qemu's native NFS client, it's not up to me to decide whether it's worth it. When it comes to breaking this, what comes to mind first is some external program opening the image read-write outside of qemu and writing to it. Maybe that's a case we generally don't want, but maybe that's something some people do on purpose, knowing what they're doing (with raw images), you never know. Other than that, there's reopening. As far as I'm aware, qemu can reopen a R/W image read-only, and if that happens, st_blocks may be stale. Max > diff --git a/block/nfs.c b/block/nfs.c > index 02eb4e4..dc9ed21 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,10 @@ static int64_t nfs_get_allocated_file_size(BlockDriverState *bs) > NFSRPC task = {0}; > struct stat st; > > + if (bdrv_is_read_only(bs)) { > + return client->st_blocks * 512; > + } > + > task.st = &st; > if (nfs_fstat_async(client->context, client->fh, nfs_co_generic_cb, > &task) != 0) { >