From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
To: qemu-devel@nongnu.org, qemu-block@nongnu.org
Cc: mreitz@redhat.com, kwolf@redhat.com, fam@euphon.net, stefanha@redhat.com
Subject: [Qemu-devel] [RFC PATCH] block: local qiov helper
Date: Fri, 25 Jan 2019 19:46:01 +0300 [thread overview]
Message-ID: <20190125164601.130556-1-vsementsov@virtuozzo.com> (raw)
Hi all.
What about such a simple helper for a very often patter around
qemu_iovec_init_external ?
If we like it, I'll update other callers of qemu_iovec_init_external.
Possible interface change would be
LOCAL_QIOV(lc, buf, len);
instead of
LocalQiov lc = LOCAL_QIOV(lc, buf, len);
or, may be, someone has a better idea?
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
---
include/qemu/iov.h | 19 +++++++++++++++++++
block/io.c | 9 ++-------
2 files changed, 21 insertions(+), 7 deletions(-)
diff --git a/include/qemu/iov.h b/include/qemu/iov.h
index 5f433c7768..e0963d8ebe 100644
--- a/include/qemu/iov.h
+++ b/include/qemu/iov.h
@@ -137,6 +137,25 @@ typedef struct QEMUIOVector {
size_t size;
} QEMUIOVector;
+typedef struct LocalQiov {
+ QEMUIOVector qiov;
+ struct iovec iov;
+} LocalQiov;
+
+#define LOCAL_QIOV(self, buf, len) \
+{ \
+ .qiov = { \
+ .iov = &self.iov, \
+ .size = len, \
+ .niov = 1, \
+ .nalloc = -1 \
+ }, \
+ .iov = { \
+ .iov_base = (void *)(buf), \
+ .iov_len = len \
+ } \
+}
+
void qemu_iovec_init(QEMUIOVector *qiov, int alloc_hint);
void qemu_iovec_init_external(QEMUIOVector *qiov, struct iovec *iov, int niov);
void qemu_iovec_add(QEMUIOVector *qiov, void *base, size_t len);
diff --git a/block/io.c b/block/io.c
index bd9d688f8b..c7d7b199c1 100644
--- a/block/io.c
+++ b/block/io.c
@@ -949,18 +949,13 @@ int bdrv_preadv(BdrvChild *child, int64_t offset, QEMUIOVector *qiov)
int bdrv_pread(BdrvChild *child, int64_t offset, void *buf, int bytes)
{
- QEMUIOVector qiov;
- struct iovec iov = {
- .iov_base = (void *)buf,
- .iov_len = bytes,
- };
+ LocalQiov lq = LOCAL_QIOV(lq, buf, bytes);
if (bytes < 0) {
return -EINVAL;
}
- qemu_iovec_init_external(&qiov, &iov, 1);
- return bdrv_preadv(child, offset, &qiov);
+ return bdrv_preadv(child, offset, &lq.qiov);
}
int bdrv_pwritev(BdrvChild *child, int64_t offset, QEMUIOVector *qiov)
--
2.18.0
next reply other threads:[~2019-01-25 16:46 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-01-25 16:46 Vladimir Sementsov-Ogievskiy [this message]
2019-01-29 3:31 ` [Qemu-devel] [Qemu-block] [RFC PATCH] block: local qiov helper Stefan Hajnoczi
2019-01-29 10:24 ` Vladimir Sementsov-Ogievskiy
2019-01-29 10:32 ` Stefan Hajnoczi
2019-01-29 11:18 ` Vladimir Sementsov-Ogievskiy
2019-01-29 12:34 ` Kevin Wolf
2019-01-30 3:10 ` Stefan Hajnoczi
2019-02-03 5:54 ` [Qemu-devel] " no-reply
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=20190125164601.130556-1-vsementsov@virtuozzo.com \
--to=vsementsov@virtuozzo.com \
--cc=fam@euphon.net \
--cc=kwolf@redhat.com \
--cc=mreitz@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
/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).