From nobody Sun Feb 8 12:38:25 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.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 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1541023626343892.165859885169; Wed, 31 Oct 2018 15:07:06 -0700 (PDT) Received: from localhost ([::1]:33724 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHydh-0005mm-3z for importer@patchew.org; Wed, 31 Oct 2018 18:07:01 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57721) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHyTv-0004bg-S9 for qemu-devel@nongnu.org; Wed, 31 Oct 2018 17:56:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gHyTm-0008C1-Gm for qemu-devel@nongnu.org; Wed, 31 Oct 2018 17:56:52 -0400 Received: from mx1.redhat.com ([209.132.183.28]:35230) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gHyTd-000843-M2; Wed, 31 Oct 2018 17:56:38 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7B35B87632; Wed, 31 Oct 2018 21:56:27 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-240.ams2.redhat.com [10.36.116.240]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8DFE019744; Wed, 31 Oct 2018 21:56:26 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Wed, 31 Oct 2018 22:56:11 +0100 Message-Id: <20181031215622.27690-2-kwolf@redhat.com> In-Reply-To: <20181031215622.27690-1-kwolf@redhat.com> References: <20181031215622.27690-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Wed, 31 Oct 2018 21:56:27 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 01/12] file-posix: Reorganise RawPosixAIOData 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, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" RawPosixAIOData contains a lot of fields for several separate operations that are to be processed in a worker thread and that need different parameters. The struct is currently rather unorganised, with unions that cover some, but not all operations, and even one #define for field names instead of a union. Clean this up to have some common fields and a single union. As a side effect, on x86_64 the struct shrinks from 72 to 48 bytes. Signed-off-by: Kevin Wolf --- block/file-posix.c | 89 +++++++++++++++++++++++++--------------------- 1 file changed, 49 insertions(+), 40 deletions(-) diff --git a/block/file-posix.c b/block/file-posix.c index 0c1b81ce4b..68cea7685a 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -178,25 +178,29 @@ static int64_t raw_getlength(BlockDriverState *bs); =20 typedef struct RawPosixAIOData { BlockDriverState *bs; + int aio_type; int aio_fildes; - union { - struct iovec *aio_iov; - void *aio_ioctl_buf; - }; - int aio_niov; - uint64_t aio_nbytes; -#define aio_ioctl_cmd aio_nbytes /* for QEMU_AIO_IOCTL */ + off_t aio_offset; - int aio_type; + uint64_t aio_nbytes; + union { + struct { + struct iovec *iov; + int niov; + } io; + struct { + uint64_t cmd; + void *buf; + } ioctl; struct { int aio_fd2; off_t aio_offset2; - }; + } copy_range; struct { PreallocMode prealloc; Error **errp; - }; + } truncate; }; } RawPosixAIOData; =20 @@ -1131,7 +1135,7 @@ static ssize_t handle_aiocb_ioctl(RawPosixAIOData *ai= ocb) { int ret; =20 - ret =3D ioctl(aiocb->aio_fildes, aiocb->aio_ioctl_cmd, aiocb->aio_ioct= l_buf); + ret =3D ioctl(aiocb->aio_fildes, aiocb->ioctl.cmd, aiocb->ioctl.buf); if (ret =3D=3D -1) { return -errno; } @@ -1212,13 +1216,13 @@ static ssize_t handle_aiocb_rw_vector(RawPosixAIODa= ta *aiocb) do { if (aiocb->aio_type & QEMU_AIO_WRITE) len =3D qemu_pwritev(aiocb->aio_fildes, - aiocb->aio_iov, - aiocb->aio_niov, + aiocb->io.iov, + aiocb->io.niov, aiocb->aio_offset); else len =3D qemu_preadv(aiocb->aio_fildes, - aiocb->aio_iov, - aiocb->aio_niov, + aiocb->io.iov, + aiocb->io.niov, aiocb->aio_offset); } while (len =3D=3D -1 && errno =3D=3D EINTR); =20 @@ -1284,8 +1288,8 @@ static ssize_t handle_aiocb_rw(RawPosixAIOData *aiocb) * If there is just a single buffer, and it is properly aligned * we can just use plain pread/pwrite without any problems. */ - if (aiocb->aio_niov =3D=3D 1) { - return handle_aiocb_rw_linear(aiocb, aiocb->aio_iov->iov_base= ); + if (aiocb->io.niov =3D=3D 1) { + return handle_aiocb_rw_linear(aiocb, aiocb->io.iov->iov_base); } /* * We have more than one iovec, and all are properly aligned. @@ -1322,9 +1326,9 @@ static ssize_t handle_aiocb_rw(RawPosixAIOData *aiocb) char *p =3D buf; int i; =20 - for (i =3D 0; i < aiocb->aio_niov; ++i) { - memcpy(p, aiocb->aio_iov[i].iov_base, aiocb->aio_iov[i].iov_le= n); - p +=3D aiocb->aio_iov[i].iov_len; + for (i =3D 0; i < aiocb->io.niov; ++i) { + memcpy(p, aiocb->io.iov[i].iov_base, aiocb->io.iov[i].iov_len); + p +=3D aiocb->io.iov[i].iov_len; } assert(p - buf =3D=3D aiocb->aio_nbytes); } @@ -1335,12 +1339,12 @@ static ssize_t handle_aiocb_rw(RawPosixAIOData *aio= cb) size_t count =3D aiocb->aio_nbytes, copy; int i; =20 - for (i =3D 0; i < aiocb->aio_niov && count; ++i) { + for (i =3D 0; i < aiocb->io.niov && count; ++i) { copy =3D count; - if (copy > aiocb->aio_iov[i].iov_len) { - copy =3D aiocb->aio_iov[i].iov_len; + if (copy > aiocb->io.iov[i].iov_len) { + copy =3D aiocb->io.iov[i].iov_len; } - memcpy(aiocb->aio_iov[i].iov_base, p, copy); + memcpy(aiocb->io.iov[i].iov_base, p, copy); assert(count >=3D copy); p +=3D copy; count -=3D copy; @@ -1551,14 +1555,15 @@ static ssize_t handle_aiocb_copy_range(RawPosixAIOD= ata *aiocb) { uint64_t bytes =3D aiocb->aio_nbytes; off_t in_off =3D aiocb->aio_offset; - off_t out_off =3D aiocb->aio_offset2; + off_t out_off =3D aiocb->copy_range.aio_offset2; =20 while (bytes) { ssize_t ret =3D copy_file_range(aiocb->aio_fildes, &in_off, - aiocb->aio_fd2, &out_off, + aiocb->copy_range.aio_fd2, &out_off, bytes, 0); trace_file_copy_file_range(aiocb->bs, aiocb->aio_fildes, in_off, - aiocb->aio_fd2, out_off, bytes, 0, ret); + aiocb->copy_range.aio_fd2, out_off, byt= es, + 0, ret); if (ret =3D=3D 0) { /* No progress (e.g. when beyond EOF), let the caller fall bac= k to * buffer I/O. */ @@ -1627,7 +1632,8 @@ static int handle_aiocb_truncate(RawPosixAIOData *aio= cb) struct stat st; int fd =3D aiocb->aio_fildes; int64_t offset =3D aiocb->aio_offset; - Error **errp =3D aiocb->errp; + PreallocMode prealloc =3D aiocb->truncate.prealloc; + Error **errp =3D aiocb->truncate.errp; =20 if (fstat(fd, &st) < 0) { result =3D -errno; @@ -1636,12 +1642,12 @@ static int handle_aiocb_truncate(RawPosixAIOData *a= iocb) } =20 current_length =3D st.st_size; - if (current_length > offset && aiocb->prealloc !=3D PREALLOC_MODE_OFF)= { + if (current_length > offset && prealloc !=3D PREALLOC_MODE_OFF) { error_setg(errp, "Cannot use preallocation for shrinking files"); return -ENOTSUP; } =20 - switch (aiocb->prealloc) { + switch (prealloc) { #ifdef CONFIG_POSIX_FALLOCATE case PREALLOC_MODE_FALLOC: /* @@ -1722,7 +1728,7 @@ static int handle_aiocb_truncate(RawPosixAIOData *aio= cb) default: result =3D -ENOTSUP; error_setg(errp, "Unsupported preallocation mode: %s", - PreallocMode_str(aiocb->prealloc)); + PreallocMode_str(prealloc)); return result; } =20 @@ -1747,7 +1753,7 @@ static int aio_worker(void *arg) case QEMU_AIO_READ: ret =3D handle_aiocb_rw(aiocb); if (ret >=3D 0 && ret < aiocb->aio_nbytes) { - iov_memset(aiocb->aio_iov, aiocb->aio_niov, ret, + iov_memset(aiocb->io.iov, aiocb->io.niov, ret, 0, aiocb->aio_nbytes - ret); =20 ret =3D aiocb->aio_nbytes; @@ -1808,16 +1814,17 @@ static int paio_submit_co_full(BlockDriverState *bs= , int fd, acb->bs =3D bs; acb->aio_type =3D type; acb->aio_fildes =3D fd; - acb->aio_fd2 =3D fd2; - acb->aio_offset2 =3D offset2; =20 acb->aio_nbytes =3D bytes; acb->aio_offset =3D offset; =20 if (qiov) { - acb->aio_iov =3D qiov->iov; - acb->aio_niov =3D qiov->niov; + acb->io.iov =3D qiov->iov; + acb->io.niov =3D qiov->niov; assert(qiov->size =3D=3D bytes); + } else { + acb->copy_range.aio_fd2 =3D fd2; + acb->copy_range.aio_offset2 =3D offset2; } =20 trace_file_paio_submit_co(offset, bytes, type); @@ -1959,8 +1966,10 @@ raw_regular_truncate(BlockDriverState *bs, int fd, i= nt64_t offset, .aio_fildes =3D fd, .aio_type =3D QEMU_AIO_TRUNCATE, .aio_offset =3D offset, - .prealloc =3D prealloc, - .errp =3D errp, + .truncate =3D { + .prealloc =3D prealloc, + .errp =3D errp, + }, }; =20 /* @bs can be NULL, bdrv_get_aio_context() returns the main context th= en */ @@ -3072,8 +3081,8 @@ static BlockAIOCB *hdev_aio_ioctl(BlockDriverState *b= s, acb->aio_type =3D QEMU_AIO_IOCTL; acb->aio_fildes =3D s->fd; acb->aio_offset =3D 0; - acb->aio_ioctl_buf =3D buf; - acb->aio_ioctl_cmd =3D req; + acb->ioctl.buf =3D buf; + acb->ioctl.cmd =3D req; pool =3D aio_get_thread_pool(bdrv_get_aio_context(bs)); return thread_pool_submit_aio(pool, aio_worker, acb, cb, opaque); } --=20 2.19.1