From patchwork Fri Jun 23 16:21:28 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 780106 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3wvPDd55T1z9sNW for ; Sat, 24 Jun 2017 02:34:41 +1000 (AEST) Received: from localhost ([::1]:36282 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dORXb-000469-Cy for incoming@patchwork.ozlabs.org; Fri, 23 Jun 2017 12:34:39 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59818) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dORM8-0001Nu-Ut for qemu-devel@nongnu.org; Fri, 23 Jun 2017 12:22:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dORM7-0007ku-PL for qemu-devel@nongnu.org; Fri, 23 Jun 2017 12:22:48 -0400 Received: from mx1.redhat.com ([209.132.183.28]:39592) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dORM2-0007iY-1w; Fri, 23 Jun 2017 12:22:42 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 151507F416; Fri, 23 Jun 2017 16:22:41 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 151507F416 Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 151507F416 Received: from noname.redhat.com (ovpn-117-196.ams2.redhat.com [10.36.117.196]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2C9117E8E5; Fri, 23 Jun 2017 16:22:40 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 23 Jun 2017 18:21:28 +0200 Message-Id: <1498234919-27316-31-git-send-email-kwolf@redhat.com> In-Reply-To: <1498234919-27316-1-git-send-email-kwolf@redhat.com> References: <1498234919-27316-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Fri, 23 Jun 2017 16:22:41 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 30/61] qed: Make qed_read_backing_file() synchronous 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Note that this code is generally not running in coroutine context, so this is an actual blocking synchronous operation. We'll fix this in a moment. Signed-off-by: Kevin Wolf Reviewed-by: Eric Blake Reviewed-by: Stefan Hajnoczi --- block/qed.c | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/block/qed.c b/block/qed.c index 290cbcd..1105f19 100644 --- a/block/qed.c +++ b/block/qed.c @@ -808,13 +808,13 @@ static BDRVQEDState *acb_to_s(QEDAIOCB *acb) * This function reads qiov->size bytes starting at pos from the backing file. * If there is no backing file then zeroes are read. */ -static void qed_read_backing_file(BDRVQEDState *s, uint64_t pos, - QEMUIOVector *qiov, - QEMUIOVector **backing_qiov, - BlockCompletionFunc *cb, void *opaque) +static int qed_read_backing_file(BDRVQEDState *s, uint64_t pos, + QEMUIOVector *qiov, + QEMUIOVector **backing_qiov) { uint64_t backing_length = 0; size_t size; + int ret; /* If there is a backing file, get its length. Treat the absence of a * backing file like a zero length backing file. @@ -822,8 +822,7 @@ static void qed_read_backing_file(BDRVQEDState *s, uint64_t pos, if (s->bs->backing) { int64_t l = bdrv_getlength(s->bs->backing->bs); if (l < 0) { - cb(opaque, l); - return; + return l; } backing_length = l; } @@ -836,8 +835,7 @@ static void qed_read_backing_file(BDRVQEDState *s, uint64_t pos, /* Complete now if there are no backing file sectors to read */ if (pos >= backing_length) { - cb(opaque, 0); - return; + return 0; } /* If the read straddles the end of the backing file, shorten it */ @@ -849,8 +847,11 @@ static void qed_read_backing_file(BDRVQEDState *s, uint64_t pos, qemu_iovec_concat(*backing_qiov, qiov, 0, size); BLKDBG_EVENT(s->bs->file, BLKDBG_READ_BACKING_AIO); - bdrv_aio_readv(s->bs->backing, pos / BDRV_SECTOR_SIZE, - *backing_qiov, size / BDRV_SECTOR_SIZE, cb, opaque); + ret = bdrv_preadv(s->bs->backing, pos, *backing_qiov); + if (ret < 0) { + return ret; + } + return 0; } typedef struct { @@ -907,6 +908,7 @@ static void qed_copy_from_backing_file(BDRVQEDState *s, uint64_t pos, void *opaque) { CopyFromBackingFileCB *copy_cb; + int ret; /* Skip copy entirely if there is no work to do */ if (len == 0) { @@ -922,8 +924,9 @@ static void qed_copy_from_backing_file(BDRVQEDState *s, uint64_t pos, copy_cb->iov.iov_len = len; qemu_iovec_init_external(©_cb->qiov, ©_cb->iov, 1); - qed_read_backing_file(s, pos, ©_cb->qiov, ©_cb->backing_qiov, - qed_copy_from_backing_file_write, copy_cb); + ret = qed_read_backing_file(s, pos, ©_cb->qiov, + ©_cb->backing_qiov); + qed_copy_from_backing_file_write(copy_cb, ret); } /** @@ -1366,8 +1369,9 @@ static void qed_aio_read_data(void *opaque, int ret, qed_aio_start_io(acb); return; } else if (ret != QED_CLUSTER_FOUND) { - qed_read_backing_file(s, acb->cur_pos, &acb->cur_qiov, - &acb->backing_qiov, qed_aio_next_io_cb, acb); + ret = qed_read_backing_file(s, acb->cur_pos, &acb->cur_qiov, + &acb->backing_qiov); + qed_aio_next_io(acb, ret); return; }