From nobody Sun May 19 12:00:48 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=virtuozzo.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1548434885144194.92200036289432; Fri, 25 Jan 2019 08:48:05 -0800 (PST) Received: from localhost ([127.0.0.1]:47189 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gn4eC-0006rf-6i for importer@patchew.org; Fri, 25 Jan 2019 11:48:04 -0500 Received: from eggs.gnu.org ([209.51.188.92]:55562) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gn4cL-00063l-GU for qemu-devel@nongnu.org; Fri, 25 Jan 2019 11:46:10 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gn4cJ-0007Zu-Fn for qemu-devel@nongnu.org; Fri, 25 Jan 2019 11:46:09 -0500 Received: from relay.sw.ru ([185.231.240.75]:38312) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gn4cH-0007Y1-Im; Fri, 25 Jan 2019 11:46:07 -0500 Received: from [10.28.8.145] (helo=kvm.sw.ru) by relay.sw.ru with esmtp (Exim 4.91) (envelope-from ) id 1gn4cD-0002M8-R0; Fri, 25 Jan 2019 19:46:02 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org, qemu-block@nongnu.org Date: Fri, 25 Jan 2019 19:46:01 +0300 Message-Id: <20190125164601.130556-1-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.18.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 185.231.240.75 Subject: [Qemu-devel] [RFC PATCH] block: local qiov helper X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, fam@euphon.net, stefanha@redhat.com, mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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=20 LocalQiov lc =3D LOCAL_QIOV(lc, buf, len); or, may be, someone has a better idea? Signed-off-by: Vladimir Sementsov-Ogievskiy --- 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; =20 +typedef struct LocalQiov { + QEMUIOVector qiov; + struct iovec iov; +} LocalQiov; + +#define LOCAL_QIOV(self, buf, len) \ +{ \ + .qiov =3D { \ + .iov =3D &self.iov, \ + .size =3D len, \ + .niov =3D 1, \ + .nalloc =3D -1 \ + }, \ + .iov =3D { \ + .iov_base =3D (void *)(buf), \ + .iov_len =3D len \ + } \ +} + void qemu_iovec_init(QEMUIOVector *qiov, int alloc_hint); void qemu_iovec_init_external(QEMUIOVector *qiov, struct iovec *iov, int n= iov); 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, QEM= UIOVector *qiov) =20 int bdrv_pread(BdrvChild *child, int64_t offset, void *buf, int bytes) { - QEMUIOVector qiov; - struct iovec iov =3D { - .iov_base =3D (void *)buf, - .iov_len =3D bytes, - }; + LocalQiov lq =3D LOCAL_QIOV(lq, buf, bytes); =20 if (bytes < 0) { return -EINVAL; } =20 - qemu_iovec_init_external(&qiov, &iov, 1); - return bdrv_preadv(child, offset, &qiov); + return bdrv_preadv(child, offset, &lq.qiov); } =20 int bdrv_pwritev(BdrvChild *child, int64_t offset, QEMUIOVector *qiov) --=20 2.18.0