From nobody Sat Nov 8 07:57:43 2025 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 1549536165693946.829719308224; Thu, 7 Feb 2019 02:42:45 -0800 (PST) Received: from localhost ([127.0.0.1]:37564 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1grh8k-0007pI-PA for importer@patchew.org; Thu, 07 Feb 2019 05:42:42 -0500 Received: from eggs.gnu.org ([209.51.188.92]:37051) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1grgru-0002zA-Sd for qemu-devel@nongnu.org; Thu, 07 Feb 2019 05:25:19 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1grgrt-00025Y-PD for qemu-devel@nongnu.org; Thu, 07 Feb 2019 05:25:18 -0500 Received: from relay.sw.ru ([185.231.240.75]:43076) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1grgrt-0001gV-G9; Thu, 07 Feb 2019 05:25:17 -0500 Received: from [10.28.8.145] (helo=kvm.sw.ru) by relay.sw.ru with esmtp (Exim 4.91) (envelope-from ) id 1grgrP-0005bY-GO; Thu, 07 Feb 2019 13:24:47 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org, qemu-block@nongnu.org Date: Thu, 7 Feb 2019 13:24:38 +0300 Message-Id: <20190207102445.71998-11-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20190207102445.71998-1-vsementsov@virtuozzo.com> References: <20190207102445.71998-1-vsementsov@virtuozzo.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 185.231.240.75 Subject: [Qemu-devel] [PATCH v3 10/17] block/qed: use qemu_iovec_init_buf 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: fam@euphon.net, kwolf@redhat.com, vsementsov@virtuozzo.com, quintela@redhat.com, jcody@redhat.com, dgilbert@redhat.com, mreitz@redhat.com, stefanha@redhat.com, den@openvz.org, jsnow@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" Use new qemu_iovec_init_buf() instead of qemu_iovec_init_external( ... , 1), which simplifies the code. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Eric Blake --- block/qed-table.c | 16 +++------------- block/qed.c | 31 +++++++++---------------------- 2 files changed, 12 insertions(+), 35 deletions(-) diff --git a/block/qed-table.c b/block/qed-table.c index 7df5680adb..c497bd4aec 100644 --- a/block/qed-table.c +++ b/block/qed-table.c @@ -21,16 +21,11 @@ /* Called with table_lock held. */ static int qed_read_table(BDRVQEDState *s, uint64_t offset, QEDTable *tabl= e) { - QEMUIOVector qiov; + QEMUIOVector qiov =3D QEMU_IOVEC_INIT_BUF( + qiov, table->offsets, s->header.cluster_size * s->header.table_siz= e); int noffsets; int i, ret; =20 - struct iovec iov =3D { - .iov_base =3D table->offsets, - .iov_len =3D s->header.cluster_size * s->header.table_size, - }; - qemu_iovec_init_external(&qiov, &iov, 1); - trace_qed_read_table(s, offset, table); =20 qemu_co_mutex_unlock(&s->table_lock); @@ -71,7 +66,6 @@ static int qed_write_table(BDRVQEDState *s, uint64_t offs= et, QEDTable *table, unsigned int sector_mask =3D BDRV_SECTOR_SIZE / sizeof(uint64_t) - 1; unsigned int start, end, i; QEDTable *new_table; - struct iovec iov; QEMUIOVector qiov; size_t len_bytes; int ret; @@ -85,11 +79,7 @@ static int qed_write_table(BDRVQEDState *s, uint64_t off= set, QEDTable *table, len_bytes =3D (end - start) * sizeof(uint64_t); =20 new_table =3D qemu_blockalign(s->bs, len_bytes); - iov =3D (struct iovec) { - .iov_base =3D new_table->offsets, - .iov_len =3D len_bytes, - }; - qemu_iovec_init_external(&qiov, &iov, 1); + qemu_iovec_init_buf(&qiov, new_table->offsets, len_bytes); =20 /* Byteswap table */ for (i =3D start; i < end; i++) { diff --git a/block/qed.c b/block/qed.c index 1280870024..a010e5b349 100644 --- a/block/qed.c +++ b/block/qed.c @@ -113,18 +113,13 @@ static int coroutine_fn qed_write_header(BDRVQEDState= *s) int nsectors =3D DIV_ROUND_UP(sizeof(QEDHeader), BDRV_SECTOR_SIZE); size_t len =3D nsectors * BDRV_SECTOR_SIZE; uint8_t *buf; - struct iovec iov; QEMUIOVector qiov; int ret; =20 assert(s->allocating_acb || s->allocating_write_reqs_plugged); =20 buf =3D qemu_blockalign(s->bs, len); - iov =3D (struct iovec) { - .iov_base =3D buf, - .iov_len =3D len, - }; - qemu_iovec_init_external(&qiov, &iov, 1); + qemu_iovec_init_buf(&qiov, buf, len); =20 ret =3D bdrv_co_preadv(s->bs->file, 0, qiov.size, &qiov, 0); if (ret < 0) { @@ -913,7 +908,6 @@ static int coroutine_fn qed_copy_from_backing_file(BDRV= QEDState *s, { QEMUIOVector qiov; QEMUIOVector *backing_qiov =3D NULL; - struct iovec iov; int ret; =20 /* Skip copy entirely if there is no work to do */ @@ -921,11 +915,7 @@ static int coroutine_fn qed_copy_from_backing_file(BDR= VQEDState *s, return 0; } =20 - iov =3D (struct iovec) { - .iov_base =3D qemu_blockalign(s->bs, len), - .iov_len =3D len, - }; - qemu_iovec_init_external(&qiov, &iov, 1); + qemu_iovec_init_buf(&qiov, qemu_blockalign(s->bs, len), len); =20 ret =3D qed_read_backing_file(s, pos, &qiov, &backing_qiov); =20 @@ -946,7 +936,7 @@ static int coroutine_fn qed_copy_from_backing_file(BDRV= QEDState *s, } ret =3D 0; out: - qemu_vfree(iov.iov_base); + qemu_vfree(qemu_iovec_get_buf(&qiov)); return ret; } =20 @@ -1447,8 +1437,12 @@ static int coroutine_fn bdrv_qed_co_pwrite_zeroes(Bl= ockDriverState *bs, BdrvRequestFlags flags) { BDRVQEDState *s =3D bs->opaque; - QEMUIOVector qiov; - struct iovec iov; + + /* + * Zero writes start without an I/O buffer. If a buffer becomes neces= sary + * then it will be allocated during request processing. + */ + QEMUIOVector qiov =3D QEMU_IOVEC_INIT_BUF(qiov, NULL, bytes); =20 /* Fall back if the request is not aligned */ if (qed_offset_into_cluster(s, offset) || @@ -1456,13 +1450,6 @@ static int coroutine_fn bdrv_qed_co_pwrite_zeroes(Bl= ockDriverState *bs, return -ENOTSUP; } =20 - /* Zero writes start without an I/O buffer. If a buffer becomes neces= sary - * then it will be allocated during request processing. - */ - iov.iov_base =3D NULL; - iov.iov_len =3D bytes; - - qemu_iovec_init_external(&qiov, &iov, 1); return qed_co_request(bs, offset >> BDRV_SECTOR_BITS, &qiov, bytes >> BDRV_SECTOR_BITS, QED_AIOCB_WRITE | QED_AIOCB_ZERO); --=20 2.18.0