From: Fabiano Rosas <farosas@suse.de>
To: qemu-devel@nongnu.org
Cc: qemu-block@nongnu.org, "Kevin Wolf" <kwolf@redhat.com>,
"Hanna Reitz" <hreitz@redhat.com>,
"Markus Armbruster" <armbru@redhat.com>,
"João Silva" <jsilva@suse.de>, "Lin Ma" <lma@suse.com>,
"Claudio Fontana" <cfontana@suse.de>,
"Dario Faggioli" <dfaggioli@suse.com>,
"Eric Blake" <eblake@redhat.com>
Subject: [RFC PATCH 6/6] block: Add a thread-pool version of fstat
Date: Tue, 23 May 2023 18:39:03 -0300 [thread overview]
Message-ID: <20230523213903.18418-7-farosas@suse.de> (raw)
In-Reply-To: <20230523213903.18418-1-farosas@suse.de>
From: João Silva <jsilva@suse.de>
The fstat call can take a long time to finish when running over
NFS. Add a version of it that runs in the thread pool.
Adapt one of its users, raw_co_get_allocated_file size to use the new
version. That function is called via QMP under the qemu_global_mutex
so it has a large chance of blocking VCPU threads in case it takes too
long to finish.
Signed-off-by: João Silva <jsilva@suse.de>
Signed-off-by: Fabiano Rosas <farosas@suse.de>
---
block/file-posix.c | 40 +++++++++++++++++++++++++++++++++++++---
include/block/raw-aio.h | 4 +++-
2 files changed, 40 insertions(+), 4 deletions(-)
diff --git a/block/file-posix.c b/block/file-posix.c
index 0ab158efba..0a29a6cc43 100644
--- a/block/file-posix.c
+++ b/block/file-posix.c
@@ -227,6 +227,9 @@ typedef struct RawPosixAIOData {
struct {
unsigned long op;
} zone_mgmt;
+ struct {
+ struct stat *st;
+ } fstat;
};
} RawPosixAIOData;
@@ -2644,6 +2647,34 @@ static void raw_close(BlockDriverState *bs)
}
}
+static int handle_aiocb_fstat(void *opaque)
+{
+ RawPosixAIOData *aiocb = opaque;
+
+ if (fstat(aiocb->aio_fildes, aiocb->fstat.st) < 0) {
+ return -errno;
+ }
+
+ return 0;
+}
+
+static int coroutine_fn raw_co_fstat(BlockDriverState *bs, struct stat *st)
+{
+ BDRVRawState *s = bs->opaque;
+ RawPosixAIOData acb;
+
+ acb = (RawPosixAIOData) {
+ .bs = bs,
+ .aio_fildes = s->fd,
+ .aio_type = QEMU_AIO_FSTAT,
+ .fstat = {
+ .st = st,
+ },
+ };
+
+ return raw_thread_pool_submit(handle_aiocb_fstat, &acb);
+}
+
/**
* Truncates the given regular file @fd to @offset and, when growing, fills the
* new space according to @prealloc.
@@ -2883,11 +2914,14 @@ static int64_t coroutine_fn raw_co_getlength(BlockDriverState *bs)
static int64_t coroutine_fn raw_co_get_allocated_file_size(BlockDriverState *bs)
{
struct stat st;
- BDRVRawState *s = bs->opaque;
+ int ret;
- if (fstat(s->fd, &st) < 0) {
- return -errno;
+ ret = raw_co_fstat(bs, &st);
+
+ if (ret) {
+ return ret;
}
+
return (int64_t)st.st_blocks * 512;
}
diff --git a/include/block/raw-aio.h b/include/block/raw-aio.h
index 0fe85ade77..7dc6d24e21 100644
--- a/include/block/raw-aio.h
+++ b/include/block/raw-aio.h
@@ -31,6 +31,7 @@
#define QEMU_AIO_ZONE_REPORT 0x0100
#define QEMU_AIO_ZONE_MGMT 0x0200
#define QEMU_AIO_ZONE_APPEND 0x0400
+#define QEMU_AIO_FSTAT 0x0800
#define QEMU_AIO_TYPE_MASK \
(QEMU_AIO_READ | \
QEMU_AIO_WRITE | \
@@ -42,7 +43,8 @@
QEMU_AIO_TRUNCATE | \
QEMU_AIO_ZONE_REPORT | \
QEMU_AIO_ZONE_MGMT | \
- QEMU_AIO_ZONE_APPEND)
+ QEMU_AIO_ZONE_APPEND | \
+ QEMU_AIO_FSTAT)
/* AIO flags */
#define QEMU_AIO_MISALIGNED 0x1000
--
2.35.3
next prev parent reply other threads:[~2023-05-23 21:40 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-23 21:38 [RFC PATCH 0/6] block: Make raw_co_get_allocated_file_size asynchronous Fabiano Rosas
2023-05-23 21:38 ` [RFC PATCH 1/6] block: Remove bdrv_query_block_node_info Fabiano Rosas
2023-05-24 8:31 ` Claudio Fontana
2023-05-23 21:38 ` [RFC PATCH 2/6] block: Mark bdrv_co_get_allocated_file_size() as mixed Fabiano Rosas
2023-05-25 14:17 ` Eric Blake
2023-05-26 9:12 ` Kevin Wolf
2023-05-23 21:39 ` [RFC PATCH 3/6] Convert query-block/info_block to coroutine Fabiano Rosas
2023-05-24 8:48 ` Claudio Fontana
2023-05-25 14:26 ` Eric Blake
2023-05-26 14:05 ` Fabiano Rosas
2023-05-23 21:39 ` [RFC PATCH 4/6] " Fabiano Rosas
2023-05-24 4:23 ` Lin Ma
2023-05-24 12:30 ` Fabiano Rosas
2023-05-24 8:49 ` Claudio Fontana
2023-05-24 9:24 ` Lin Ma
2023-05-24 15:57 ` Claudio Fontana
2023-05-23 21:39 ` [RFC PATCH 5/6] block: Allow bdrv_get_allocated_file_size to run in bdrv context Fabiano Rosas
2023-05-26 9:28 ` Kevin Wolf
2023-05-29 17:47 ` Fabiano Rosas
2023-05-23 21:39 ` Fabiano Rosas [this message]
2023-05-24 15:56 ` [RFC PATCH 6/6] block: Add a thread-pool version of fstat Claudio Fontana
2023-05-25 15:45 ` Eric Blake
2023-05-26 14:20 ` Fabiano Rosas
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230523213903.18418-7-farosas@suse.de \
--to=farosas@suse.de \
--cc=armbru@redhat.com \
--cc=cfontana@suse.de \
--cc=dfaggioli@suse.com \
--cc=eblake@redhat.com \
--cc=hreitz@redhat.com \
--cc=jsilva@suse.de \
--cc=kwolf@redhat.com \
--cc=lma@suse.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).