From patchwork Wed Oct 31 21:56:11 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 10663295 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 31C0913B5 for ; Wed, 31 Oct 2018 22:06:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 232EE2BB68 for ; Wed, 31 Oct 2018 22:06:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 177422BB6E; Wed, 31 Oct 2018 22:06:40 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 71AFB2BB68 for ; Wed, 31 Oct 2018 22:06:39 +0000 (UTC) Received: from localhost ([::1]:33724 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHydK-0005mm-Og for patchwork-qemu-devel@patchwork.kernel.org; Wed, 31 Oct 2018 18:06:38 -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) 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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); 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; @@ -1131,7 +1135,7 @@ static ssize_t handle_aiocb_ioctl(RawPosixAIOData *aiocb) { int ret; - ret = ioctl(aiocb->aio_fildes, aiocb->aio_ioctl_cmd, aiocb->aio_ioctl_buf); + ret = ioctl(aiocb->aio_fildes, aiocb->ioctl.cmd, aiocb->ioctl.buf); if (ret == -1) { return -errno; } @@ -1212,13 +1216,13 @@ static ssize_t handle_aiocb_rw_vector(RawPosixAIOData *aiocb) do { if (aiocb->aio_type & QEMU_AIO_WRITE) len = qemu_pwritev(aiocb->aio_fildes, - aiocb->aio_iov, - aiocb->aio_niov, + aiocb->io.iov, + aiocb->io.niov, aiocb->aio_offset); else len = qemu_preadv(aiocb->aio_fildes, - aiocb->aio_iov, - aiocb->aio_niov, + aiocb->io.iov, + aiocb->io.niov, aiocb->aio_offset); } while (len == -1 && errno == EINTR); @@ -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 == 1) { - return handle_aiocb_rw_linear(aiocb, aiocb->aio_iov->iov_base); + if (aiocb->io.niov == 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 = buf; int i; - for (i = 0; i < aiocb->aio_niov; ++i) { - memcpy(p, aiocb->aio_iov[i].iov_base, aiocb->aio_iov[i].iov_len); - p += aiocb->aio_iov[i].iov_len; + for (i = 0; i < aiocb->io.niov; ++i) { + memcpy(p, aiocb->io.iov[i].iov_base, aiocb->io.iov[i].iov_len); + p += aiocb->io.iov[i].iov_len; } assert(p - buf == aiocb->aio_nbytes); } @@ -1335,12 +1339,12 @@ static ssize_t handle_aiocb_rw(RawPosixAIOData *aiocb) size_t count = aiocb->aio_nbytes, copy; int i; - for (i = 0; i < aiocb->aio_niov && count; ++i) { + for (i = 0; i < aiocb->io.niov && count; ++i) { copy = count; - if (copy > aiocb->aio_iov[i].iov_len) { - copy = aiocb->aio_iov[i].iov_len; + if (copy > aiocb->io.iov[i].iov_len) { + copy = 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 >= copy); p += copy; count -= copy; @@ -1551,14 +1555,15 @@ static ssize_t handle_aiocb_copy_range(RawPosixAIOData *aiocb) { uint64_t bytes = aiocb->aio_nbytes; off_t in_off = aiocb->aio_offset; - off_t out_off = aiocb->aio_offset2; + off_t out_off = aiocb->copy_range.aio_offset2; while (bytes) { ssize_t ret = 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, bytes, + 0, ret); if (ret == 0) { /* No progress (e.g. when beyond EOF), let the caller fall back to * buffer I/O. */ @@ -1627,7 +1632,8 @@ static int handle_aiocb_truncate(RawPosixAIOData *aiocb) struct stat st; int fd = aiocb->aio_fildes; int64_t offset = aiocb->aio_offset; - Error **errp = aiocb->errp; + PreallocMode prealloc = aiocb->truncate.prealloc; + Error **errp = aiocb->truncate.errp; if (fstat(fd, &st) < 0) { result = -errno; @@ -1636,12 +1642,12 @@ static int handle_aiocb_truncate(RawPosixAIOData *aiocb) } current_length = st.st_size; - if (current_length > offset && aiocb->prealloc != PREALLOC_MODE_OFF) { + if (current_length > offset && prealloc != PREALLOC_MODE_OFF) { error_setg(errp, "Cannot use preallocation for shrinking files"); return -ENOTSUP; } - switch (aiocb->prealloc) { + switch (prealloc) { #ifdef CONFIG_POSIX_FALLOCATE case PREALLOC_MODE_FALLOC: /* @@ -1722,7 +1728,7 @@ static int handle_aiocb_truncate(RawPosixAIOData *aiocb) default: result = -ENOTSUP; error_setg(errp, "Unsupported preallocation mode: %s", - PreallocMode_str(aiocb->prealloc)); + PreallocMode_str(prealloc)); return result; } @@ -1747,7 +1753,7 @@ static int aio_worker(void *arg) case QEMU_AIO_READ: ret = handle_aiocb_rw(aiocb); if (ret >= 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); ret = aiocb->aio_nbytes; @@ -1808,16 +1814,17 @@ static int paio_submit_co_full(BlockDriverState *bs, int fd, acb->bs = bs; acb->aio_type = type; acb->aio_fildes = fd; - acb->aio_fd2 = fd2; - acb->aio_offset2 = offset2; acb->aio_nbytes = bytes; acb->aio_offset = offset; if (qiov) { - acb->aio_iov = qiov->iov; - acb->aio_niov = qiov->niov; + acb->io.iov = qiov->iov; + acb->io.niov = qiov->niov; assert(qiov->size == bytes); + } else { + acb->copy_range.aio_fd2 = fd2; + acb->copy_range.aio_offset2 = offset2; } trace_file_paio_submit_co(offset, bytes, type); @@ -1959,8 +1966,10 @@ raw_regular_truncate(BlockDriverState *bs, int fd, int64_t offset, .aio_fildes = fd, .aio_type = QEMU_AIO_TRUNCATE, .aio_offset = offset, - .prealloc = prealloc, - .errp = errp, + .truncate = { + .prealloc = prealloc, + .errp = errp, + }, }; /* @bs can be NULL, bdrv_get_aio_context() returns the main context then */ @@ -3072,8 +3081,8 @@ static BlockAIOCB *hdev_aio_ioctl(BlockDriverState *bs, acb->aio_type = QEMU_AIO_IOCTL; acb->aio_fildes = s->fd; acb->aio_offset = 0; - acb->aio_ioctl_buf = buf; - acb->aio_ioctl_cmd = req; + acb->ioctl.buf = buf; + acb->ioctl.cmd = req; pool = aio_get_thread_pool(bdrv_get_aio_context(bs)); return thread_pool_submit_aio(pool, aio_worker, acb, cb, opaque); } From patchwork Wed Oct 31 21:56:12 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 10663275 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 424D413B5 for ; Wed, 31 Oct 2018 21:58:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 347862B842 for ; Wed, 31 Oct 2018 21:58:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 280E02B898; Wed, 31 Oct 2018 21:58:31 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id BBF5E2B842 for ; Wed, 31 Oct 2018 21:58:30 +0000 (UTC) Received: from localhost ([::1]:33674 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHyVR-0006ls-Ig for patchwork-qemu-devel@patchwork.kernel.org; Wed, 31 Oct 2018 17:58:29 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57628) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHyTo-0004Tl-DQ for qemu-devel@nongnu.org; Wed, 31 Oct 2018 17:56:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gHyTl-0008BV-8q for qemu-devel@nongnu.org; Wed, 31 Oct 2018 17:56:46 -0400 Received: from mx1.redhat.com ([209.132.183.28]:45262) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gHyTc-00084F-SP; Wed, 31 Oct 2018 17:56:37 -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 B821D4E915; Wed, 31 Oct 2018 21:56:28 +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 C8D9B19744; Wed, 31 Oct 2018 21:56:27 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Wed, 31 Oct 2018 22:56:12 +0100 Message-Id: <20181031215622.27690-3-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.38]); Wed, 31 Oct 2018 21:56:28 +0000 (UTC) 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 02/12] file-posix: Factor out raw_thread_pool_submit() 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Getting the thread pool of the AioContext of a block node and scheduling some work in it is an operation that is already done twice, and we'll get more instances. Factor it out into a separate function. Signed-off-by: Kevin Wolf --- block/file-posix.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/block/file-posix.c b/block/file-posix.c index 68cea7685a..28eb55c29e 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -1803,13 +1803,20 @@ static int aio_worker(void *arg) return ret; } +static int coroutine_fn raw_thread_pool_submit(BlockDriverState *bs, + ThreadPoolFunc func, void *arg) +{ + /* @bs can be NULL, bdrv_get_aio_context() returns the main context then */ + ThreadPool *pool = aio_get_thread_pool(bdrv_get_aio_context(bs)); + return thread_pool_submit_co(pool, func, arg); +} + static int paio_submit_co_full(BlockDriverState *bs, int fd, int64_t offset, int fd2, int64_t offset2, QEMUIOVector *qiov, int bytes, int type) { RawPosixAIOData *acb = g_new(RawPosixAIOData, 1); - ThreadPool *pool; acb->bs = bs; acb->aio_type = type; @@ -1828,8 +1835,7 @@ static int paio_submit_co_full(BlockDriverState *bs, int fd, } trace_file_paio_submit_co(offset, bytes, type); - pool = aio_get_thread_pool(bdrv_get_aio_context(bs)); - return thread_pool_submit_co(pool, aio_worker, acb); + return raw_thread_pool_submit(bs, aio_worker, acb); } static inline int paio_submit_co(BlockDriverState *bs, int fd, @@ -1959,7 +1965,6 @@ raw_regular_truncate(BlockDriverState *bs, int fd, int64_t offset, PreallocMode prealloc, Error **errp) { RawPosixAIOData *acb = g_new(RawPosixAIOData, 1); - ThreadPool *pool; *acb = (RawPosixAIOData) { .bs = bs, @@ -1972,9 +1977,7 @@ raw_regular_truncate(BlockDriverState *bs, int fd, int64_t offset, }, }; - /* @bs can be NULL, bdrv_get_aio_context() returns the main context then */ - pool = aio_get_thread_pool(bdrv_get_aio_context(bs)); - return thread_pool_submit_co(pool, aio_worker, acb); + return raw_thread_pool_submit(bs, aio_worker, acb); } static int coroutine_fn raw_co_truncate(BlockDriverState *bs, int64_t offset, From patchwork Wed Oct 31 21:56:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 10663281 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2A25B14BD for ; Wed, 31 Oct 2018 22:01:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1C6902BB2D for ; Wed, 31 Oct 2018 22:01:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 10DA02BB60; Wed, 31 Oct 2018 22:01:05 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 947F52BB2D for ; Wed, 31 Oct 2018 22:01:04 +0000 (UTC) Received: from localhost ([::1]:33693 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHyXv-0000hx-Bi for patchwork-qemu-devel@patchwork.kernel.org; Wed, 31 Oct 2018 18:01:03 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57629) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHyTo-0004Tm-DU for qemu-devel@nongnu.org; Wed, 31 Oct 2018 17:56:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gHyTl-0008BW-8o for qemu-devel@nongnu.org; Wed, 31 Oct 2018 17:56:46 -0400 Received: from mx1.redhat.com ([209.132.183.28]:13831) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gHyTc-00084n-8q; Wed, 31 Oct 2018 17:56:36 -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 0C0BD3082142; Wed, 31 Oct 2018 21:56:30 +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 11ACB19744; Wed, 31 Oct 2018 21:56:28 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Wed, 31 Oct 2018 22:56:13 +0100 Message-Id: <20181031215622.27690-4-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.42]); Wed, 31 Oct 2018 21:56:30 +0000 (UTC) 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 03/12] file-posix: Avoid aio_worker() for QEMU_AIO_TRUNCATE 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP aio_worker() doesn't add anything interesting, it's only a useless indirection. Call the handler function directly instead. As we know that this handler function is only called from coroutine context and the coroutine stays around until the worker thread finishes, we can keep RawPosixAIOData on the stack. Signed-off-by: Kevin Wolf --- block/file-posix.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/block/file-posix.c b/block/file-posix.c index 28eb55c29e..69e1b761b4 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -1624,8 +1624,9 @@ static ssize_t handle_aiocb_discard(RawPosixAIOData *aiocb) return ret; } -static int handle_aiocb_truncate(RawPosixAIOData *aiocb) +static int handle_aiocb_truncate(void *opaque) { + RawPosixAIOData *aiocb = opaque; int result = 0; int64_t current_length = 0; char *buf = NULL; @@ -1791,8 +1792,7 @@ static int aio_worker(void *arg) ret = handle_aiocb_copy_range(aiocb); break; case QEMU_AIO_TRUNCATE: - ret = handle_aiocb_truncate(aiocb); - break; + g_assert_not_reached(); default: fprintf(stderr, "invalid aio request (0x%x)\n", aiocb->aio_type); ret = -EINVAL; @@ -1964,9 +1964,9 @@ static int coroutine_fn raw_regular_truncate(BlockDriverState *bs, int fd, int64_t offset, PreallocMode prealloc, Error **errp) { - RawPosixAIOData *acb = g_new(RawPosixAIOData, 1); + RawPosixAIOData acb; - *acb = (RawPosixAIOData) { + acb = (RawPosixAIOData) { .bs = bs, .aio_fildes = fd, .aio_type = QEMU_AIO_TRUNCATE, @@ -1977,7 +1977,7 @@ raw_regular_truncate(BlockDriverState *bs, int fd, int64_t offset, }, }; - return raw_thread_pool_submit(bs, aio_worker, acb); + return raw_thread_pool_submit(bs, handle_aiocb_truncate, &acb); } static int coroutine_fn raw_co_truncate(BlockDriverState *bs, int64_t offset, From patchwork Wed Oct 31 21:56:14 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 10663287 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9F71E13B5 for ; Wed, 31 Oct 2018 22:03:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 909E82BB68 for ; Wed, 31 Oct 2018 22:03:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 81D1A2BB71; Wed, 31 Oct 2018 22:03:54 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 1D1532BB68 for ; Wed, 31 Oct 2018 22:03:53 +0000 (UTC) Received: from localhost ([::1]:33704 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHyae-00045W-PT for patchwork-qemu-devel@patchwork.kernel.org; Wed, 31 Oct 2018 18:03:52 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57720) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHyTv-0004bf-SC for qemu-devel@nongnu.org; Wed, 31 Oct 2018 17:56:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gHyTm-0008C6-Gq for qemu-devel@nongnu.org; Wed, 31 Oct 2018 17:56:52 -0400 Received: from mx1.redhat.com ([209.132.183.28]:45274) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gHyTc-00085D-5U; Wed, 31 Oct 2018 17:56:36 -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 B3E0F4E91F; Wed, 31 Oct 2018 21:56:31 +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 52FBB19744; Wed, 31 Oct 2018 21:56:30 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Wed, 31 Oct 2018 22:56:14 +0100 Message-Id: <20181031215622.27690-5-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.38]); Wed, 31 Oct 2018 21:56:31 +0000 (UTC) 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 04/12] file-posix: Avoid aio_worker() for QEMU_AIO_COPY_RANGE 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP aio_worker() doesn't add anything interesting, it's only a useless indirection. Call the handler function directly instead. As we know that this handler function is only called from coroutine context and the coroutine stays around until the worker thread finishes, we can keep RawPosixAIOData on the stack. Signed-off-by: Kevin Wolf --- block/file-posix.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/block/file-posix.c b/block/file-posix.c index 69e1b761b4..fe5e95cc0a 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -1551,8 +1551,9 @@ static off_t copy_file_range(int in_fd, off_t *in_off, int out_fd, } #endif -static ssize_t handle_aiocb_copy_range(RawPosixAIOData *aiocb) +static int handle_aiocb_copy_range(void *opaque) { + RawPosixAIOData *aiocb = opaque; uint64_t bytes = aiocb->aio_nbytes; off_t in_off = aiocb->aio_offset; off_t out_off = aiocb->copy_range.aio_offset2; @@ -1789,8 +1790,6 @@ static int aio_worker(void *arg) ret = handle_aiocb_write_zeroes_unmap(aiocb); break; case QEMU_AIO_COPY_RANGE: - ret = handle_aiocb_copy_range(aiocb); - break; case QEMU_AIO_TRUNCATE: g_assert_not_reached(); default: @@ -2697,6 +2696,7 @@ static int coroutine_fn raw_co_copy_range_to(BlockDriverState *bs, BdrvRequestFlags read_flags, BdrvRequestFlags write_flags) { + RawPosixAIOData acb; BDRVRawState *s = bs->opaque; BDRVRawState *src_s; @@ -2709,8 +2709,20 @@ static int coroutine_fn raw_co_copy_range_to(BlockDriverState *bs, if (fd_open(src->bs) < 0 || fd_open(dst->bs) < 0) { return -EIO; } - return paio_submit_co_full(bs, src_s->fd, src_offset, s->fd, dst_offset, - NULL, bytes, QEMU_AIO_COPY_RANGE); + + acb = (RawPosixAIOData) { + .bs = bs, + .aio_type = QEMU_AIO_COPY_RANGE, + .aio_fildes = src_s->fd, + .aio_offset = src_offset, + .aio_nbytes = bytes, + .copy_range = { + .aio_fd2 = s->fd, + .aio_offset2 = dst_offset, + }, + }; + + return raw_thread_pool_submit(bs, handle_aiocb_copy_range, &acb); } BlockDriver bdrv_file = { From patchwork Wed Oct 31 21:56:15 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 10663291 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 46B4A14BD for ; Wed, 31 Oct 2018 22:04:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 37C552BB33 for ; Wed, 31 Oct 2018 22:04:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2BBF42BB6E; Wed, 31 Oct 2018 22:04:09 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id BB8242BB33 for ; Wed, 31 Oct 2018 22:04:08 +0000 (UTC) Received: from localhost ([::1]:33706 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHyau-0004DG-3r for patchwork-qemu-devel@patchwork.kernel.org; Wed, 31 Oct 2018 18:04:08 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57717) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHyTv-0004bb-Rq for qemu-devel@nongnu.org; Wed, 31 Oct 2018 17:56:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gHyTm-0008C3-Gs for qemu-devel@nongnu.org; Wed, 31 Oct 2018 17:56:52 -0400 Received: from mx1.redhat.com ([209.132.183.28]:39886) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gHyTd-00085h-Ny; 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 ED58A30832C9; Wed, 31 Oct 2018 21:56:32 +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 0B6FD45BE; Wed, 31 Oct 2018 21:56:31 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Wed, 31 Oct 2018 22:56:15 +0100 Message-Id: <20181031215622.27690-6-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.44]); Wed, 31 Oct 2018 21:56:33 +0000 (UTC) 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 05/12] file-posix: Avoid aio_worker() for QEMU_AIO_WRITE_ZEROES 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP aio_worker() doesn't add anything interesting, it's only a useless indirection. Call the handler function directly instead. As we know that this handler function is only called from coroutine context and the coroutine stays around until the worker thread finishes, we can keep RawPosixAIOData on the stack. Signed-off-by: Kevin Wolf --- block/file-posix.c | 53 +++++++++++++++++++++++++++++----------------- 1 file changed, 34 insertions(+), 19 deletions(-) diff --git a/block/file-posix.c b/block/file-posix.c index fe5e95cc0a..3d3bddd511 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -1443,8 +1443,9 @@ static ssize_t handle_aiocb_write_zeroes_block(RawPosixAIOData *aiocb) return ret; } -static ssize_t handle_aiocb_write_zeroes(RawPosixAIOData *aiocb) +static int handle_aiocb_write_zeroes(void *opaque) { + RawPosixAIOData *aiocb = opaque; #if defined(CONFIG_FALLOCATE) || defined(CONFIG_XFS) BDRVRawState *s = aiocb->bs->opaque; #endif @@ -1508,8 +1509,9 @@ static ssize_t handle_aiocb_write_zeroes(RawPosixAIOData *aiocb) return -ENOTSUP; } -static ssize_t handle_aiocb_write_zeroes_unmap(RawPosixAIOData *aiocb) +static int handle_aiocb_write_zeroes_unmap(void *opaque) { + RawPosixAIOData *aiocb = opaque; BDRVRawState *s G_GNUC_UNUSED = aiocb->bs->opaque; int ret; @@ -1784,11 +1786,7 @@ static int aio_worker(void *arg) ret = handle_aiocb_discard(aiocb); break; case QEMU_AIO_WRITE_ZEROES: - ret = handle_aiocb_write_zeroes(aiocb); - break; case QEMU_AIO_WRITE_ZEROES | QEMU_AIO_DISCARD: - ret = handle_aiocb_write_zeroes_unmap(aiocb); - break; case QEMU_AIO_COPY_RANGE: case QEMU_AIO_TRUNCATE: g_assert_not_reached(); @@ -2614,18 +2612,41 @@ raw_co_pdiscard(BlockDriverState *bs, int64_t offset, int bytes) return paio_submit_co(bs, s->fd, offset, NULL, bytes, QEMU_AIO_DISCARD); } -static int coroutine_fn raw_co_pwrite_zeroes( - BlockDriverState *bs, int64_t offset, - int bytes, BdrvRequestFlags flags) +static int coroutine_fn +raw_do_pwrite_zeroes(BlockDriverState *bs, int64_t offset, int bytes, + BdrvRequestFlags flags, bool blkdev) { BDRVRawState *s = bs->opaque; - int operation = QEMU_AIO_WRITE_ZEROES; + RawPosixAIOData acb; + ThreadPoolFunc *handler; + + acb = (RawPosixAIOData) { + .bs = bs, + .aio_fildes = s->fd, + .aio_type = QEMU_AIO_WRITE_ZEROES, + .aio_offset = offset, + .aio_nbytes = bytes, + }; + + if (blkdev) { + acb.aio_type |= QEMU_AIO_BLKDEV; + } if (flags & BDRV_REQ_MAY_UNMAP) { - operation |= QEMU_AIO_DISCARD; + acb.aio_type |= QEMU_AIO_DISCARD; + handler = handle_aiocb_write_zeroes_unmap; + } else { + handler = handle_aiocb_write_zeroes; } - return paio_submit_co(bs, s->fd, offset, NULL, bytes, operation); + return raw_thread_pool_submit(bs, handler, &acb); +} + +static int coroutine_fn raw_co_pwrite_zeroes( + BlockDriverState *bs, int64_t offset, + int bytes, BdrvRequestFlags flags) +{ + return raw_do_pwrite_zeroes(bs, offset, bytes, flags, false); } static int raw_get_info(BlockDriverState *bs, BlockDriverInfo *bdi) @@ -3130,8 +3151,6 @@ hdev_co_pdiscard(BlockDriverState *bs, int64_t offset, int bytes) static coroutine_fn int hdev_co_pwrite_zeroes(BlockDriverState *bs, int64_t offset, int bytes, BdrvRequestFlags flags) { - BDRVRawState *s = bs->opaque; - int operation = QEMU_AIO_WRITE_ZEROES | QEMU_AIO_BLKDEV; int rc; rc = fd_open(bs); @@ -3139,11 +3158,7 @@ static coroutine_fn int hdev_co_pwrite_zeroes(BlockDriverState *bs, return rc; } - if (flags & BDRV_REQ_MAY_UNMAP) { - operation |= QEMU_AIO_DISCARD; - } - - return paio_submit_co(bs, s->fd, offset, NULL, bytes, operation); + return raw_do_pwrite_zeroes(bs, offset, bytes, flags, true); } static int coroutine_fn hdev_co_create_opts(const char *filename, QemuOpts *opts, From patchwork Wed Oct 31 21:56:16 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 10663279 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 81F311734 for ; Wed, 31 Oct 2018 21:58:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 74F0E2B951 for ; Wed, 31 Oct 2018 21:58:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 695172B966; Wed, 31 Oct 2018 21:58:44 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 15A842B951 for ; Wed, 31 Oct 2018 21:58:44 +0000 (UTC) Received: from localhost ([::1]:33676 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHyVf-0007G0-85 for patchwork-qemu-devel@patchwork.kernel.org; Wed, 31 Oct 2018 17:58:43 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57701) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHyTu-0004Zj-6c for qemu-devel@nongnu.org; Wed, 31 Oct 2018 17:56:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gHyTm-0008CA-Go for qemu-devel@nongnu.org; Wed, 31 Oct 2018 17:56:52 -0400 Received: from mx1.redhat.com ([209.132.183.28]:27931) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gHyTd-00086Z-Mo; 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 32EEE30821A7; Wed, 31 Oct 2018 21:56:35 +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 3EAA819744; Wed, 31 Oct 2018 21:56:34 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Wed, 31 Oct 2018 22:56:16 +0100 Message-Id: <20181031215622.27690-7-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.47]); Wed, 31 Oct 2018 21:56:35 +0000 (UTC) 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 06/12] file-posix: Avoid aio_worker() for QEMU_AIO_DISCARD 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP aio_worker() doesn't add anything interesting, it's only a useless indirection. Call the handler function directly instead. As we know that this handler function is only called from coroutine context and the coroutine stays around until the worker thread finishes, we can keep RawPosixAIOData on the stack. Signed-off-by: Kevin Wolf --- block/file-posix.c | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/block/file-posix.c b/block/file-posix.c index 3d3bddd511..291ffaeded 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -1587,8 +1587,9 @@ static int handle_aiocb_copy_range(void *opaque) return 0; } -static ssize_t handle_aiocb_discard(RawPosixAIOData *aiocb) +static int handle_aiocb_discard(void *opaque) { + RawPosixAIOData *aiocb = opaque; int ret = -EOPNOTSUPP; BDRVRawState *s = aiocb->bs->opaque; @@ -1783,8 +1784,6 @@ static int aio_worker(void *arg) ret = handle_aiocb_ioctl(aiocb); break; case QEMU_AIO_DISCARD: - ret = handle_aiocb_discard(aiocb); - break; case QEMU_AIO_WRITE_ZEROES: case QEMU_AIO_WRITE_ZEROES | QEMU_AIO_DISCARD: case QEMU_AIO_COPY_RANGE: @@ -2605,11 +2604,30 @@ static void coroutine_fn raw_co_invalidate_cache(BlockDriverState *bs, } static coroutine_fn int -raw_co_pdiscard(BlockDriverState *bs, int64_t offset, int bytes) +raw_do_pdiscard(BlockDriverState *bs, int64_t offset, int bytes, bool blkdev) { BDRVRawState *s = bs->opaque; + RawPosixAIOData acb; + + acb = (RawPosixAIOData) { + .bs = bs, + .aio_fildes = s->fd, + .aio_type = QEMU_AIO_DISCARD, + .aio_offset = offset, + .aio_nbytes = bytes, + }; - return paio_submit_co(bs, s->fd, offset, NULL, bytes, QEMU_AIO_DISCARD); + if (blkdev) { + acb.aio_type |= QEMU_AIO_BLKDEV; + } + + return raw_thread_pool_submit(bs, handle_aiocb_discard, &acb); +} + +static coroutine_fn int +raw_co_pdiscard(BlockDriverState *bs, int64_t offset, int bytes) +{ + return raw_do_pdiscard(bs, offset, bytes, false); } static int coroutine_fn @@ -3137,15 +3155,13 @@ static int fd_open(BlockDriverState *bs) static coroutine_fn int hdev_co_pdiscard(BlockDriverState *bs, int64_t offset, int bytes) { - BDRVRawState *s = bs->opaque; int ret; ret = fd_open(bs); if (ret < 0) { return ret; } - return paio_submit_co(bs, s->fd, offset, NULL, bytes, - QEMU_AIO_DISCARD | QEMU_AIO_BLKDEV); + return raw_do_pdiscard(bs, offset, bytes, true); } static coroutine_fn int hdev_co_pwrite_zeroes(BlockDriverState *bs, From patchwork Wed Oct 31 21:56:17 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 10663285 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8589614BD for ; Wed, 31 Oct 2018 22:01:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 795422BB6E for ; Wed, 31 Oct 2018 22:01:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6B0AF2BB76; Wed, 31 Oct 2018 22:01:21 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 0BF622BB71 for ; Wed, 31 Oct 2018 22:01:21 +0000 (UTC) Received: from localhost ([::1]:33697 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHyYB-0000r4-Rt for patchwork-qemu-devel@patchwork.kernel.org; Wed, 31 Oct 2018 18:01:19 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57723) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHyTv-0004bi-S9 for qemu-devel@nongnu.org; Wed, 31 Oct 2018 17:56:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gHyTn-0008EE-SI for qemu-devel@nongnu.org; Wed, 31 Oct 2018 17:56:52 -0400 Received: from mx1.redhat.com ([209.132.183.28]:45296) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gHyTe-00086w-Qd; Wed, 31 Oct 2018 17:56:39 -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 68CE54E91C; Wed, 31 Oct 2018 21:56:36 +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 7BB8C19744; Wed, 31 Oct 2018 21:56:35 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Wed, 31 Oct 2018 22:56:17 +0100 Message-Id: <20181031215622.27690-8-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.38]); Wed, 31 Oct 2018 21:56:36 +0000 (UTC) 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 07/12] file-posix: Avoid aio_worker() for QEMU_AIO_FLUSH 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP aio_worker() doesn't add anything interesting, it's only a useless indirection. Call the handler function directly instead. As we know that this handler function is only called from coroutine context and the coroutine stays around until the worker thread finishes, we can keep RawPosixAIOData on the stack. Signed-off-by: Kevin Wolf --- block/file-posix.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/block/file-posix.c b/block/file-posix.c index 291ffaeded..074848ed1f 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -1143,8 +1143,9 @@ static ssize_t handle_aiocb_ioctl(RawPosixAIOData *aiocb) return 0; } -static ssize_t handle_aiocb_flush(RawPosixAIOData *aiocb) +static int handle_aiocb_flush(void *opaque) { + RawPosixAIOData *aiocb = opaque; BDRVRawState *s = aiocb->bs->opaque; int ret; @@ -1777,12 +1778,10 @@ static int aio_worker(void *arg) ret = -EINVAL; } break; - case QEMU_AIO_FLUSH: - ret = handle_aiocb_flush(aiocb); - break; case QEMU_AIO_IOCTL: ret = handle_aiocb_ioctl(aiocb); break; + case QEMU_AIO_FLUSH: case QEMU_AIO_DISCARD: case QEMU_AIO_WRITE_ZEROES: case QEMU_AIO_WRITE_ZEROES | QEMU_AIO_DISCARD: @@ -1910,6 +1909,7 @@ static void raw_aio_unplug(BlockDriverState *bs) static int raw_co_flush_to_disk(BlockDriverState *bs) { BDRVRawState *s = bs->opaque; + RawPosixAIOData acb; int ret; ret = fd_open(bs); @@ -1917,7 +1917,13 @@ static int raw_co_flush_to_disk(BlockDriverState *bs) return ret; } - return paio_submit_co(bs, s->fd, 0, NULL, 0, QEMU_AIO_FLUSH); + acb = (RawPosixAIOData) { + .bs = bs, + .aio_fildes = s->fd, + .aio_type = QEMU_AIO_FLUSH, + }; + + return raw_thread_pool_submit(bs, handle_aiocb_flush, &acb); } static void raw_aio_attach_aio_context(BlockDriverState *bs, From patchwork Wed Oct 31 21:56:18 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 10663289 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D07F713B5 for ; Wed, 31 Oct 2018 22:04:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C322C2BB33 for ; Wed, 31 Oct 2018 22:04:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B6C252BB6E; Wed, 31 Oct 2018 22:04:07 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 5D41A2BB33 for ; Wed, 31 Oct 2018 22:04:07 +0000 (UTC) Received: from localhost ([::1]:33705 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHyas-0004C7-Mv for patchwork-qemu-devel@patchwork.kernel.org; Wed, 31 Oct 2018 18:04:06 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57837) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHyU4-0004il-Ff for qemu-devel@nongnu.org; Wed, 31 Oct 2018 17:57:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gHyTz-0008Lo-6O for qemu-devel@nongnu.org; Wed, 31 Oct 2018 17:57:01 -0400 Received: from mx1.redhat.com ([209.132.183.28]:56414) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gHyTm-00087j-I1; Wed, 31 Oct 2018 17:56:47 -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 A4FD283F3F; Wed, 31 Oct 2018 21:56:37 +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 B7D5318500; Wed, 31 Oct 2018 21:56:36 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Wed, 31 Oct 2018 22:56:18 +0100 Message-Id: <20181031215622.27690-9-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.27]); Wed, 31 Oct 2018 21:56:37 +0000 (UTC) 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 08/12] file-posix: Move read/write operation logic out of aio_worker() 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP aio_worker() for reads and writes isn't boring enough yet. It still does some postprocessing for handling short reads and turning the result into the right return value. However, there is no reason why handle_aiocb_rw() couldn't do the same, and even without duplicating code between the read and write path. So move the code there. Signed-off-by: Kevin Wolf --- block/file-posix.c | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/block/file-posix.c b/block/file-posix.c index 074848ed1f..4989208ba3 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -1290,7 +1290,8 @@ static ssize_t handle_aiocb_rw(RawPosixAIOData *aiocb) * we can just use plain pread/pwrite without any problems. */ if (aiocb->io.niov == 1) { - return handle_aiocb_rw_linear(aiocb, aiocb->io.iov->iov_base); + nbytes = handle_aiocb_rw_linear(aiocb, aiocb->io.iov->iov_base); + goto out; } /* * We have more than one iovec, and all are properly aligned. @@ -1302,7 +1303,7 @@ static ssize_t handle_aiocb_rw(RawPosixAIOData *aiocb) nbytes = handle_aiocb_rw_vector(aiocb); if (nbytes == aiocb->aio_nbytes || (nbytes < 0 && nbytes != -ENOSYS)) { - return nbytes; + goto out; } preadv_present = false; } @@ -1320,7 +1321,8 @@ static ssize_t handle_aiocb_rw(RawPosixAIOData *aiocb) */ buf = qemu_try_blockalign(aiocb->bs, aiocb->aio_nbytes); if (buf == NULL) { - return -ENOMEM; + nbytes = -ENOMEM; + goto out; } if (aiocb->aio_type & QEMU_AIO_WRITE) { @@ -1354,7 +1356,21 @@ static ssize_t handle_aiocb_rw(RawPosixAIOData *aiocb) } qemu_vfree(buf); - return nbytes; +out: + if (nbytes == aiocb->aio_nbytes) { + return 0; + } else if (nbytes >= 0 && nbytes < aiocb->aio_nbytes) { + if (aiocb->aio_type & QEMU_AIO_WRITE) { + return -EINVAL; + } else { + iov_memset(aiocb->io.iov, aiocb->io.niov, nbytes, + 0, aiocb->aio_nbytes - nbytes); + return aiocb->aio_nbytes; + } + } else { + assert(nbytes < 0); + return nbytes; + } } #ifdef CONFIG_XFS @@ -1758,25 +1774,9 @@ static int aio_worker(void *arg) switch (aiocb->aio_type & QEMU_AIO_TYPE_MASK) { case QEMU_AIO_READ: ret = handle_aiocb_rw(aiocb); - if (ret >= 0 && ret < aiocb->aio_nbytes) { - iov_memset(aiocb->io.iov, aiocb->io.niov, ret, - 0, aiocb->aio_nbytes - ret); - - ret = aiocb->aio_nbytes; - } - if (ret == aiocb->aio_nbytes) { - ret = 0; - } else if (ret >= 0 && ret < aiocb->aio_nbytes) { - ret = -EINVAL; - } break; case QEMU_AIO_WRITE: ret = handle_aiocb_rw(aiocb); - if (ret == aiocb->aio_nbytes) { - ret = 0; - } else if (ret >= 0 && ret < aiocb->aio_nbytes) { - ret = -EINVAL; - } break; case QEMU_AIO_IOCTL: ret = handle_aiocb_ioctl(aiocb); From patchwork Wed Oct 31 21:56:19 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 10663283 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 499A413B5 for ; Wed, 31 Oct 2018 22:01:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3C6032BB69 for ; Wed, 31 Oct 2018 22:01:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 30F892BB6A; Wed, 31 Oct 2018 22:01:13 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id B6AAF2BB69 for ; Wed, 31 Oct 2018 22:01:12 +0000 (UTC) Received: from localhost ([::1]:33696 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHyY3-0000pu-R6 for patchwork-qemu-devel@patchwork.kernel.org; Wed, 31 Oct 2018 18:01:11 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57836) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHyU4-0004ik-Fb for qemu-devel@nongnu.org; Wed, 31 Oct 2018 17:57:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gHyTy-0008Kk-Kt for qemu-devel@nongnu.org; Wed, 31 Oct 2018 17:57:01 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38080) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gHyTp-00088M-8S; Wed, 31 Oct 2018 17:56:49 -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 E4823C04959E; Wed, 31 Oct 2018 21:56:38 +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 F2AF619744; Wed, 31 Oct 2018 21:56:37 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Wed, 31 Oct 2018 22:56:19 +0100 Message-Id: <20181031215622.27690-10-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.31]); Wed, 31 Oct 2018 21:56:38 +0000 (UTC) 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 09/12] file-posix: Avoid aio_worker() for QEMU_AIO_READ/WRITE 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP aio_worker() doesn't add anything interesting, it's only a useless indirection. Call the handler function directly instead. As we know that this handler function is only called from coroutine context and the coroutine stays around until the worker thread finishes, we can keep RawPosixAIOData on the stack. Signed-off-by: Kevin Wolf --- block/file-posix.c | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/block/file-posix.c b/block/file-posix.c index 4989208ba3..c5e83140d3 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -1279,8 +1279,9 @@ static ssize_t handle_aiocb_rw_linear(RawPosixAIOData *aiocb, char *buf) return offset; } -static ssize_t handle_aiocb_rw(RawPosixAIOData *aiocb) +static int handle_aiocb_rw(void *opaque) { + RawPosixAIOData *aiocb = opaque; ssize_t nbytes; char *buf; @@ -1772,15 +1773,11 @@ static int aio_worker(void *arg) ssize_t ret = 0; switch (aiocb->aio_type & QEMU_AIO_TYPE_MASK) { - case QEMU_AIO_READ: - ret = handle_aiocb_rw(aiocb); - break; - case QEMU_AIO_WRITE: - ret = handle_aiocb_rw(aiocb); - break; case QEMU_AIO_IOCTL: ret = handle_aiocb_ioctl(aiocb); break; + case QEMU_AIO_READ: + case QEMU_AIO_WRITE: case QEMU_AIO_FLUSH: case QEMU_AIO_DISCARD: case QEMU_AIO_WRITE_ZEROES: @@ -1844,6 +1841,7 @@ static int coroutine_fn raw_co_prw(BlockDriverState *bs, uint64_t offset, uint64_t bytes, QEMUIOVector *qiov, int type) { BDRVRawState *s = bs->opaque; + RawPosixAIOData acb; if (fd_open(bs) < 0) return -EIO; @@ -1866,7 +1864,20 @@ static int coroutine_fn raw_co_prw(BlockDriverState *bs, uint64_t offset, } } - return paio_submit_co(bs, s->fd, offset, qiov, bytes, type); + acb = (RawPosixAIOData) { + .bs = bs, + .aio_fildes = s->fd, + .aio_type = type, + .aio_offset = offset, + .aio_nbytes = bytes, + .io = { + .iov = qiov->iov, + .niov = qiov->niov, + }, + }; + + assert(qiov->size == bytes); + return raw_thread_pool_submit(bs, handle_aiocb_rw, &acb); } static int coroutine_fn raw_co_preadv(BlockDriverState *bs, uint64_t offset, From patchwork Wed Oct 31 21:56:20 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 10663299 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A32BC13B5 for ; Wed, 31 Oct 2018 22:08:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 963E42B880 for ; Wed, 31 Oct 2018 22:08:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8ABC22B91A; Wed, 31 Oct 2018 22:08:43 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 3B9A72BA44 for ; Wed, 31 Oct 2018 22:08:43 +0000 (UTC) Received: from localhost ([::1]:33734 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHyfK-0008DT-FS for patchwork-qemu-devel@patchwork.kernel.org; Wed, 31 Oct 2018 18:08:42 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57835) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHyU4-0004ij-FZ for qemu-devel@nongnu.org; Wed, 31 Oct 2018 17:57:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gHyTx-0008Jg-Ou for qemu-devel@nongnu.org; Wed, 31 Oct 2018 17:57:01 -0400 Received: from mx1.redhat.com ([209.132.183.28]:32880) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gHyTn-00088k-Sw; Wed, 31 Oct 2018 17:56:48 -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 26CF6307D861; Wed, 31 Oct 2018 21:56:40 +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 39DCF19744; Wed, 31 Oct 2018 21:56:39 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Wed, 31 Oct 2018 22:56:20 +0100 Message-Id: <20181031215622.27690-11-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.48]); Wed, 31 Oct 2018 21:56:40 +0000 (UTC) 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 10/12] file-posix: Remove paio_submit_co() 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP The function is not used any more, remove it. Signed-off-by: Kevin Wolf --- block/file-posix.c | 34 ---------------------------------- 1 file changed, 34 deletions(-) diff --git a/block/file-posix.c b/block/file-posix.c index c5e83140d3..821743d2b2 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -1803,40 +1803,6 @@ static int coroutine_fn raw_thread_pool_submit(BlockDriverState *bs, return thread_pool_submit_co(pool, func, arg); } -static int paio_submit_co_full(BlockDriverState *bs, int fd, - int64_t offset, int fd2, int64_t offset2, - QEMUIOVector *qiov, - int bytes, int type) -{ - RawPosixAIOData *acb = g_new(RawPosixAIOData, 1); - - acb->bs = bs; - acb->aio_type = type; - acb->aio_fildes = fd; - - acb->aio_nbytes = bytes; - acb->aio_offset = offset; - - if (qiov) { - acb->io.iov = qiov->iov; - acb->io.niov = qiov->niov; - assert(qiov->size == bytes); - } else { - acb->copy_range.aio_fd2 = fd2; - acb->copy_range.aio_offset2 = offset2; - } - - trace_file_paio_submit_co(offset, bytes, type); - return raw_thread_pool_submit(bs, aio_worker, acb); -} - -static inline int paio_submit_co(BlockDriverState *bs, int fd, - int64_t offset, QEMUIOVector *qiov, - int bytes, int type) -{ - return paio_submit_co_full(bs, fd, offset, -1, 0, qiov, bytes, type); -} - static int coroutine_fn raw_co_prw(BlockDriverState *bs, uint64_t offset, uint64_t bytes, QEMUIOVector *qiov, int type) { From patchwork Wed Oct 31 21:56:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 10663297 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7D32617DB for ; Wed, 31 Oct 2018 22:08:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6EDCF2B87F for ; Wed, 31 Oct 2018 22:08:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6333B2B880; Wed, 31 Oct 2018 22:08:42 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id D829E2B8CF for ; Wed, 31 Oct 2018 22:08:41 +0000 (UTC) Received: from localhost ([::1]:33733 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHyfJ-0008Cw-3p for patchwork-qemu-devel@patchwork.kernel.org; Wed, 31 Oct 2018 18:08:41 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57869) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHyU5-0004kC-D6 for qemu-devel@nongnu.org; Wed, 31 Oct 2018 17:57:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gHyU2-0008Py-TV for qemu-devel@nongnu.org; Wed, 31 Oct 2018 17:57:05 -0400 Received: from mx1.redhat.com ([209.132.183.28]:53750) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gHyTm-00089N-Jc; Wed, 31 Oct 2018 17:56:47 -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 61B24308FB9B; Wed, 31 Oct 2018 21:56:41 +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 743CF19744; Wed, 31 Oct 2018 21:56:40 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Wed, 31 Oct 2018 22:56:21 +0100 Message-Id: <20181031215622.27690-12-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.43]); Wed, 31 Oct 2018 21:56:41 +0000 (UTC) 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 11/12] file-posix: Switch to .bdrv_co_ioctl 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP No real reason to keep using the callback based mechanism here when the rest of the file-posix driver is coroutine based. Changing it brings ioctls more in line with how other request types work. Signed-off-by: Kevin Wolf --- include/scsi/pr-manager.h | 8 +++----- block/file-posix.c | 21 +++++++++++---------- scsi/pr-manager.c | 21 +++++++++------------ scsi/trace-events | 2 +- 4 files changed, 24 insertions(+), 28 deletions(-) diff --git a/include/scsi/pr-manager.h b/include/scsi/pr-manager.h index 50a77b08fc..6ad5fd1ff7 100644 --- a/include/scsi/pr-manager.h +++ b/include/scsi/pr-manager.h @@ -5,6 +5,7 @@ #include "qapi/visitor.h" #include "qom/object_interfaces.h" #include "block/aio.h" +#include "qemu/coroutine.h" #define TYPE_PR_MANAGER "pr-manager" @@ -37,11 +38,8 @@ typedef struct PRManagerClass { } PRManagerClass; bool pr_manager_is_connected(PRManager *pr_mgr); -BlockAIOCB *pr_manager_execute(PRManager *pr_mgr, - AioContext *ctx, int fd, - struct sg_io_hdr *hdr, - BlockCompletionFunc *complete, - void *opaque); +int coroutine_fn pr_manager_execute(PRManager *pr_mgr, AioContext *ctx, int fd, + struct sg_io_hdr *hdr); PRManager *pr_manager_lookup(const char *id, Error **errp); diff --git a/block/file-posix.c b/block/file-posix.c index 821743d2b2..9439e8c054 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -3092,24 +3092,25 @@ hdev_open_Mac_error: } #if defined(__linux__) - -static BlockAIOCB *hdev_aio_ioctl(BlockDriverState *bs, - unsigned long int req, void *buf, - BlockCompletionFunc *cb, void *opaque) +static int coroutine_fn +hdev_co_ioctl(BlockDriverState *bs, unsigned long int req, void *buf) { BDRVRawState *s = bs->opaque; RawPosixAIOData *acb; ThreadPool *pool; + int ret; - if (fd_open(bs) < 0) - return NULL; + ret = fd_open(bs); + if (ret < 0) { + return ret; + } if (req == SG_IO && s->pr_mgr) { struct sg_io_hdr *io_hdr = buf; if (io_hdr->cmdp[0] == PERSISTENT_RESERVE_OUT || io_hdr->cmdp[0] == PERSISTENT_RESERVE_IN) { return pr_manager_execute(s->pr_mgr, bdrv_get_aio_context(bs), - s->fd, io_hdr, cb, opaque); + s->fd, io_hdr); } } @@ -3121,7 +3122,7 @@ static BlockAIOCB *hdev_aio_ioctl(BlockDriverState *bs, acb->ioctl.buf = buf; acb->ioctl.cmd = req; pool = aio_get_thread_pool(bdrv_get_aio_context(bs)); - return thread_pool_submit_aio(pool, aio_worker, acb, cb, opaque); + return thread_pool_submit_co(pool, aio_worker, acb); } #endif /* linux */ @@ -3263,7 +3264,7 @@ static BlockDriver bdrv_host_device = { /* generic scsi device */ #ifdef __linux__ - .bdrv_aio_ioctl = hdev_aio_ioctl, + .bdrv_co_ioctl = hdev_co_ioctl, #endif }; @@ -3385,7 +3386,7 @@ static BlockDriver bdrv_host_cdrom = { .bdrv_lock_medium = cdrom_lock_medium, /* generic scsi device */ - .bdrv_aio_ioctl = hdev_aio_ioctl, + .bdrv_co_ioctl = hdev_co_ioctl, }; #endif /* __linux__ */ diff --git a/scsi/pr-manager.c b/scsi/pr-manager.c index 2a8f300dde..d9f4e8c3ad 100644 --- a/scsi/pr-manager.c +++ b/scsi/pr-manager.c @@ -48,24 +48,21 @@ static int pr_manager_worker(void *opaque) } -BlockAIOCB *pr_manager_execute(PRManager *pr_mgr, - AioContext *ctx, int fd, - struct sg_io_hdr *hdr, - BlockCompletionFunc *complete, - void *opaque) +int coroutine_fn pr_manager_execute(PRManager *pr_mgr, AioContext *ctx, int fd, + struct sg_io_hdr *hdr) { - PRManagerData *data = g_new(PRManagerData, 1); ThreadPool *pool = aio_get_thread_pool(ctx); + PRManagerData data = { + .pr_mgr = pr_mgr, + .fd = fd, + .hdr = hdr, + }; - trace_pr_manager_execute(fd, hdr->cmdp[0], hdr->cmdp[1], opaque); - data->pr_mgr = pr_mgr; - data->fd = fd; - data->hdr = hdr; + trace_pr_manager_execute(fd, hdr->cmdp[0], hdr->cmdp[1]); /* The matching object_unref is in pr_manager_worker. */ object_ref(OBJECT(pr_mgr)); - return thread_pool_submit_aio(pool, pr_manager_worker, - data, complete, opaque); + return thread_pool_submit_co(pool, pr_manager_worker, &data); } bool pr_manager_is_connected(PRManager *pr_mgr) diff --git a/scsi/trace-events b/scsi/trace-events index 45f5b6e49b..f8a68b11eb 100644 --- a/scsi/trace-events +++ b/scsi/trace-events @@ -1,3 +1,3 @@ # scsi/pr-manager.c -pr_manager_execute(int fd, int cmd, int sa, void *opaque) "fd=%d cmd=0x%02x service action=0x%02x opaque=%p" +pr_manager_execute(int fd, int cmd, int sa) "fd=%d cmd=0x%02x service action=0x%02x" pr_manager_run(int fd, int cmd, int sa) "fd=%d cmd=0x%02x service action=0x%02x" From patchwork Wed Oct 31 21:56:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 10663293 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id ED74314BD for ; Wed, 31 Oct 2018 22:06:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DF6682BB68 for ; Wed, 31 Oct 2018 22:06:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D3C8A2BB70; Wed, 31 Oct 2018 22:06:38 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 7921C2BB68 for ; Wed, 31 Oct 2018 22:06:38 +0000 (UTC) Received: from localhost ([::1]:33723 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHydJ-0005mK-O0 for patchwork-qemu-devel@patchwork.kernel.org; Wed, 31 Oct 2018 18:06:37 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57838) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHyU4-0004io-Fg for qemu-devel@nongnu.org; Wed, 31 Oct 2018 17:57:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gHyTy-0008Ke-KU for qemu-devel@nongnu.org; Wed, 31 Oct 2018 17:57:01 -0400 Received: from mx1.redhat.com ([209.132.183.28]:32886) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gHyTo-0008A2-Th; Wed, 31 Oct 2018 17:56:49 -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 9C825307D864; Wed, 31 Oct 2018 21:56:42 +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 AF68F19744; Wed, 31 Oct 2018 21:56:41 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Wed, 31 Oct 2018 22:56:22 +0100 Message-Id: <20181031215622.27690-13-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.48]); Wed, 31 Oct 2018 21:56:42 +0000 (UTC) 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 12/12] file-posix: Avoid aio_worker() for QEMU_AIO_IOCTL 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP aio_worker() doesn't add anything interesting, it's only a useless indirection. Call the handler function directly instead. As we know that this handler function is only called from coroutine context and the coroutine stays around until the worker thread finishes, we can keep RawPosixAIOData on the stack. This was the last user of aio_worker(), so the function goes away now. Signed-off-by: Kevin Wolf --- block/file-posix.c | 55 +++++++++++++--------------------------------- 1 file changed, 15 insertions(+), 40 deletions(-) diff --git a/block/file-posix.c b/block/file-posix.c index 9439e8c054..9f305f3d49 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -1131,8 +1131,9 @@ static int hdev_probe_geometry(BlockDriverState *bs, HDGeometry *geo) } #endif -static ssize_t handle_aiocb_ioctl(RawPosixAIOData *aiocb) +static int handle_aiocb_ioctl(void *opaque) { + RawPosixAIOData *aiocb = opaque; int ret; ret = ioctl(aiocb->aio_fildes, aiocb->ioctl.cmd, aiocb->ioctl.buf); @@ -1767,34 +1768,6 @@ out: return result; } -static int aio_worker(void *arg) -{ - RawPosixAIOData *aiocb = arg; - ssize_t ret = 0; - - switch (aiocb->aio_type & QEMU_AIO_TYPE_MASK) { - case QEMU_AIO_IOCTL: - ret = handle_aiocb_ioctl(aiocb); - break; - case QEMU_AIO_READ: - case QEMU_AIO_WRITE: - case QEMU_AIO_FLUSH: - case QEMU_AIO_DISCARD: - case QEMU_AIO_WRITE_ZEROES: - case QEMU_AIO_WRITE_ZEROES | QEMU_AIO_DISCARD: - case QEMU_AIO_COPY_RANGE: - case QEMU_AIO_TRUNCATE: - g_assert_not_reached(); - default: - fprintf(stderr, "invalid aio request (0x%x)\n", aiocb->aio_type); - ret = -EINVAL; - break; - } - - g_free(aiocb); - return ret; -} - static int coroutine_fn raw_thread_pool_submit(BlockDriverState *bs, ThreadPoolFunc func, void *arg) { @@ -3096,8 +3069,7 @@ static int coroutine_fn hdev_co_ioctl(BlockDriverState *bs, unsigned long int req, void *buf) { BDRVRawState *s = bs->opaque; - RawPosixAIOData *acb; - ThreadPool *pool; + RawPosixAIOData acb; int ret; ret = fd_open(bs); @@ -3114,15 +3086,18 @@ hdev_co_ioctl(BlockDriverState *bs, unsigned long int req, void *buf) } } - acb = g_new(RawPosixAIOData, 1); - acb->bs = bs; - acb->aio_type = QEMU_AIO_IOCTL; - acb->aio_fildes = s->fd; - acb->aio_offset = 0; - acb->ioctl.buf = buf; - acb->ioctl.cmd = req; - pool = aio_get_thread_pool(bdrv_get_aio_context(bs)); - return thread_pool_submit_co(pool, aio_worker, acb); + acb = (RawPosixAIOData) { + .bs = bs, + .aio_type = QEMU_AIO_IOCTL, + .aio_fildes = s->fd, + .aio_offset = 0, + .ioctl = { + .buf = buf, + .cmd = req, + }, + }; + + return raw_thread_pool_submit(bs, handle_aiocb_ioctl, &acb); } #endif /* linux */