From nobody Mon Apr 29 04:03:08 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1572622377; cv=none; d=zoho.com; s=zohoarc; b=ke8faHBiV2D3NGSdJselR65s980eNXDUiju/hVIeiT/qgey+lr+jucK5iZH5VT2IiWlacDGgau3zdTl+uOepmVNz7a9Cl9RKVqWRswh3vwfDalUx6MNuWbLuYpEKdeN3UaTPR2l1YIG7Z0E3eii2BBdxBRSdmdL5C8L5CYBqG14= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1572622377; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=dnBtfPanCpkQhB8YXyZbX9l7wtgxl4lx1Ac9A8bX38E=; b=SNn6eletE5l+xihSW0kiUeS0Ki2FTihGENc/ZRHFQrH95JdAM+0j0gwU9F8vWwelXxQpqsA9xPAek6D6ZkjsjXWgCYs/tFao6yFaQOhFOa6xeKf3Q6F6AaD+bzj7yx75C9GeDWUbSUA6m8i+ciGUlrQ2jylRak3EO3xo2FnoB/4= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; 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 header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1572622377461123.13494317816185; Fri, 1 Nov 2019 08:32:57 -0700 (PDT) Received: from localhost ([::1]:40354 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iQYv2-0006Vj-2J for importer@patchew.org; Fri, 01 Nov 2019 11:32:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49989) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iQYo1-00018L-UO for qemu-devel@nongnu.org; Fri, 01 Nov 2019 11:25:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iQYnw-0006Wa-J2 for qemu-devel@nongnu.org; Fri, 01 Nov 2019 11:25:38 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:26130 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iQYnw-0006Q2-Eb for qemu-devel@nongnu.org; Fri, 01 Nov 2019 11:25:36 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-124-ySc46r3WOk-vpWBPCzs-rw-1; Fri, 01 Nov 2019 11:25:22 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3ACFD801E7D; Fri, 1 Nov 2019 15:25:21 +0000 (UTC) Received: from localhost (ovpn-117-28.ams2.redhat.com [10.36.117.28]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D49205D6A7; Fri, 1 Nov 2019 15:25:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1572621935; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=dnBtfPanCpkQhB8YXyZbX9l7wtgxl4lx1Ac9A8bX38E=; b=XcGyZKFg3l01q5CgpZ5bnC/MqtciLxcRlDZfwA5di8mdxWKX1/XAzBD66IYzfsnU5YCP18 MGgpUAkqUNpRVf1wBfJvxXOYcf/SAppC5dtU//7xNUdTirP2DlVWvw/rQ2MHAZSeKeG/hv LMxmAsm8q7VvxUtyUisJ855LlunUXCs= From: Max Reitz To: qemu-block@nongnu.org Subject: [PATCH for-4.2 v2 1/3] block: Make wait/mark serialising requests public Date: Fri, 1 Nov 2019 16:25:08 +0100 Message-Id: <20191101152510.11719-2-mreitz@redhat.com> In-Reply-To: <20191101152510.11719-1-mreitz@redhat.com> References: <20191101152510.11719-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-MC-Unique: ySc46r3WOk-vpWBPCzs-rw-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 205.139.110.120 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Vladimir Sementsov-Ogievskiy , qemu-stable@nongnu.org, qemu-devel@nongnu.org, Anton Nefedov , Stefan Hajnoczi , "Denis V . Lunev" , Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Make both bdrv_mark_request_serialising() and bdrv_wait_serialising_requests() public so they can be used from block drivers. Cc: qemu-stable@nongnu.org Signed-off-by: Max Reitz Reviewed-by: Stefan Hajnoczi --- include/block/block_int.h | 3 +++ block/io.c | 24 ++++++++++++------------ 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/include/block/block_int.h b/include/block/block_int.h index 02dc0034a2..32fa323b63 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -999,6 +999,9 @@ extern unsigned int bdrv_drain_all_count; void bdrv_apply_subtree_drain(BdrvChild *child, BlockDriverState *new_pare= nt); void bdrv_unapply_subtree_drain(BdrvChild *child, BlockDriverState *old_pa= rent); =20 +bool coroutine_fn bdrv_wait_serialising_requests(BdrvTrackedRequest *self); +void bdrv_mark_request_serialising(BdrvTrackedRequest *req, uint64_t align= ); + int get_tmp_filename(char *filename, int size); BlockDriver *bdrv_probe_all(const uint8_t *buf, int buf_size, const char *filename); diff --git a/block/io.c b/block/io.c index 02659f994d..039c0d49c9 100644 --- a/block/io.c +++ b/block/io.c @@ -715,7 +715,7 @@ static void tracked_request_begin(BdrvTrackedRequest *r= eq, qemu_co_mutex_unlock(&bs->reqs_lock); } =20 -static void mark_request_serialising(BdrvTrackedRequest *req, uint64_t ali= gn) +void bdrv_mark_request_serialising(BdrvTrackedRequest *req, uint64_t align) { int64_t overlap_offset =3D req->offset & ~(align - 1); uint64_t overlap_bytes =3D ROUND_UP(req->offset + req->bytes, align) @@ -805,7 +805,7 @@ void bdrv_dec_in_flight(BlockDriverState *bs) bdrv_wakeup(bs); } =20 -static bool coroutine_fn wait_serialising_requests(BdrvTrackedRequest *sel= f) +bool coroutine_fn bdrv_wait_serialising_requests(BdrvTrackedRequest *self) { BlockDriverState *bs =3D self->bs; BdrvTrackedRequest *req; @@ -1437,14 +1437,14 @@ static int coroutine_fn bdrv_aligned_preadv(BdrvChi= ld *child, * with each other for the same cluster. For example, in copy-on-= read * it ensures that the CoR read and write operations are atomic and * guest writes cannot interleave between them. */ - mark_request_serialising(req, bdrv_get_cluster_size(bs)); + bdrv_mark_request_serialising(req, bdrv_get_cluster_size(bs)); } =20 /* BDRV_REQ_SERIALISING is only for write operation */ assert(!(flags & BDRV_REQ_SERIALISING)); =20 if (!(flags & BDRV_REQ_NO_SERIALISING)) { - wait_serialising_requests(req); + bdrv_wait_serialising_requests(req); } =20 if (flags & BDRV_REQ_COPY_ON_READ) { @@ -1841,10 +1841,10 @@ bdrv_co_write_req_prepare(BdrvChild *child, int64_t= offset, uint64_t bytes, assert(!(flags & ~BDRV_REQ_MASK)); =20 if (flags & BDRV_REQ_SERIALISING) { - mark_request_serialising(req, bdrv_get_cluster_size(bs)); + bdrv_mark_request_serialising(req, bdrv_get_cluster_size(bs)); } =20 - waited =3D wait_serialising_requests(req); + waited =3D bdrv_wait_serialising_requests(req); =20 assert(!waited || !req->serialising || is_request_serialising_and_aligned(req)); @@ -2008,8 +2008,8 @@ static int coroutine_fn bdrv_co_do_zero_pwritev(BdrvC= hild *child, =20 padding =3D bdrv_init_padding(bs, offset, bytes, &pad); if (padding) { - mark_request_serialising(req, align); - wait_serialising_requests(req); + bdrv_mark_request_serialising(req, align); + bdrv_wait_serialising_requests(req); =20 bdrv_padding_rmw_read(child, req, &pad, true); =20 @@ -2111,8 +2111,8 @@ int coroutine_fn bdrv_co_pwritev_part(BdrvChild *chil= d, } =20 if (bdrv_pad_request(bs, &qiov, &qiov_offset, &offset, &bytes, &pad)) { - mark_request_serialising(&req, align); - wait_serialising_requests(&req); + bdrv_mark_request_serialising(&req, align); + bdrv_wait_serialising_requests(&req); bdrv_padding_rmw_read(child, &req, &pad, false); } =20 @@ -3205,7 +3205,7 @@ static int coroutine_fn bdrv_co_copy_range_internal( /* BDRV_REQ_SERIALISING is only for write operation */ assert(!(read_flags & BDRV_REQ_SERIALISING)); if (!(read_flags & BDRV_REQ_NO_SERIALISING)) { - wait_serialising_requests(&req); + bdrv_wait_serialising_requests(&req); } =20 ret =3D src->bs->drv->bdrv_co_copy_range_from(src->bs, @@ -3336,7 +3336,7 @@ int coroutine_fn bdrv_co_truncate(BdrvChild *child, i= nt64_t offset, bool exact, * new area, we need to make sure that no write requests are made to it * concurrently or they might be overwritten by preallocation. */ if (new_bytes) { - mark_request_serialising(&req, 1); + bdrv_mark_request_serialising(&req, 1); } if (bs->read_only) { error_setg(errp, "Image is read-only"); --=20 2.21.0 From nobody Mon Apr 29 04:03:08 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1572622091; cv=none; d=zoho.com; s=zohoarc; b=YoODqlQD+fLRf6gSV1mDfXep+rP76IVV64v5KRVEuKpofzkSc0kBlFakE+RZGVGt2iQna4AHc3wEQB2WB7r/5GdMS6q+fEagPpTklBHkon4zz/zyS8dRil8z3dkQDYzsbNexIKbqm62jlTYg3JXvf4zFytKFmYgF+PDRqfp1E3w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1572622091; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=/+JGbgzYVa6+tgel3U3VRqT2uhI2IgP5/wG0sg3jL20=; b=AdHLz6M0uuYiv3p/mhOwguE4jQMPV1XeREbESkD25nX12fN+9+pQXCBHbJ4+4Gvr6m+e2vq1CXl6QUmMSUmldTu5oPv2Q3mdHjc1V5V+GpGKfegKtm+FyTykaEcS4V9xLSrm44aeCel50w5LvLwsK5JbaS9uRsJZ1lSg5Yyhe6o= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; 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 header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1572622091061692.5628047949988; Fri, 1 Nov 2019 08:28:11 -0700 (PDT) Received: from localhost ([::1]:40296 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iQYqO-0002h2-Nb for importer@patchew.org; Fri, 01 Nov 2019 11:28:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49919) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iQYnu-00010M-5A for qemu-devel@nongnu.org; Fri, 01 Nov 2019 11:25:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iQYnt-0006HJ-1F for qemu-devel@nongnu.org; Fri, 01 Nov 2019 11:25:34 -0400 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:20093 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iQYnr-00064m-Ss for qemu-devel@nongnu.org; Fri, 01 Nov 2019 11:25:32 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-212-2K3fbpoGPLqEmSFpZAJ5hg-1; Fri, 01 Nov 2019 11:25:28 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id AA7D52B4; Fri, 1 Nov 2019 15:25:27 +0000 (UTC) Received: from localhost (ovpn-117-28.ams2.redhat.com [10.36.117.28]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B6B315C548; Fri, 1 Nov 2019 15:25:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1572621930; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/+JGbgzYVa6+tgel3U3VRqT2uhI2IgP5/wG0sg3jL20=; b=JR8uzjiZz5cpAP/zUopUcE7GM90qIMufispHrbdaLpQGdaXTg6t5p+4qXD4idZzHH+5AEh ACp4+Cb9W6N2wGB4QKy9Ild2yBZGhvIIgb5fjiDV7awo91gLo94htpo5R5v2pK64ue09P9 0k1AxbR224qiRDQB8Pk/eXzBhgHsodU= From: Max Reitz To: qemu-block@nongnu.org Subject: [PATCH for-4.2 v2 2/3] block: Add bdrv_co_get_self_request() Date: Fri, 1 Nov 2019 16:25:09 +0100 Message-Id: <20191101152510.11719-3-mreitz@redhat.com> In-Reply-To: <20191101152510.11719-1-mreitz@redhat.com> References: <20191101152510.11719-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-MC-Unique: 2K3fbpoGPLqEmSFpZAJ5hg-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 205.139.110.61 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Vladimir Sementsov-Ogievskiy , qemu-stable@nongnu.org, qemu-devel@nongnu.org, Anton Nefedov , Stefan Hajnoczi , "Denis V . Lunev" , Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Cc: qemu-stable@nongnu.org Signed-off-by: Max Reitz Reviewed-by: Stefan Hajnoczi --- include/block/block_int.h | 1 + block/io.c | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/include/block/block_int.h b/include/block/block_int.h index 32fa323b63..dd033d0b37 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -1001,6 +1001,7 @@ void bdrv_unapply_subtree_drain(BdrvChild *child, Blo= ckDriverState *old_parent); =20 bool coroutine_fn bdrv_wait_serialising_requests(BdrvTrackedRequest *self); void bdrv_mark_request_serialising(BdrvTrackedRequest *req, uint64_t align= ); +BdrvTrackedRequest *coroutine_fn bdrv_co_get_self_request(BlockDriverState= *bs); =20 int get_tmp_filename(char *filename, int size); BlockDriver *bdrv_probe_all(const uint8_t *buf, int buf_size, diff --git a/block/io.c b/block/io.c index 039c0d49c9..f75777f5ea 100644 --- a/block/io.c +++ b/block/io.c @@ -742,6 +742,24 @@ static bool is_request_serialising_and_aligned(BdrvTra= ckedRequest *req) (req->bytes =3D=3D req->overlap_bytes); } =20 +/** + * Return the tracked request on @bs for the current coroutine, or + * NULL if there is none. + */ +BdrvTrackedRequest *coroutine_fn bdrv_co_get_self_request(BlockDriverState= *bs) +{ + BdrvTrackedRequest *req; + Coroutine *self =3D qemu_coroutine_self(); + + QLIST_FOREACH(req, &bs->tracked_requests, list) { + if (req->co =3D=3D self) { + return req; + } + } + + return NULL; +} + /** * Round a region to cluster boundaries */ --=20 2.21.0 From nobody Mon Apr 29 04:03:08 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1572622149; cv=none; d=zoho.com; s=zohoarc; b=jucdgU6WFXLjiuD1RcuZsFsym4w1inWvuguMystyVc9tMfu2OCsKnN+Wvwlg8za6A1niVS51qcwe/dFUo2/tDE5LMv5a/gv9iNzRPp4PR2yF0UzromIFFkD0G9lQKixRTtPvh4VFn5XZ3HnRgnfc7cPkuPi/qMH0DMVGHEGaj60= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1572622149; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=icUeNLBSxyx75ffAXIxpWLaiCSmihYFyORHxaJ+gyyQ=; b=Xa550afNjVVWtNlVa5f2JHRmNcvYSnK6Lnpjr2O2MdhCXvvNSfFuMju1lKSUDpgDmGBaQxqz1u1DS6lRdegg7awT+j18YB19jqCztgRuCcCQ62CG5C+BxaHP9zqlUyUZbQjDiRlginb0eDkqRRc/fFmF8wHcLLFULFd0J0Y54oE= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; 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 header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1572622149575510.2469188907713; Fri, 1 Nov 2019 08:29:09 -0700 (PDT) Received: from localhost ([::1]:40298 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iQYrL-0003Ex-Jv for importer@patchew.org; Fri, 01 Nov 2019 11:29:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49986) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iQYnz-00017i-O3 for qemu-devel@nongnu.org; Fri, 01 Nov 2019 11:25:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iQYnx-0006aj-FF for qemu-devel@nongnu.org; Fri, 01 Nov 2019 11:25:38 -0400 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:21205 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iQYnx-0006ZQ-B7 for qemu-devel@nongnu.org; Fri, 01 Nov 2019 11:25:37 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-319-M1hTulrCPgG_8SUMBogPhg-1; Fri, 01 Nov 2019 11:25:33 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 80E051800D67; Fri, 1 Nov 2019 15:25:32 +0000 (UTC) Received: from localhost (ovpn-117-28.ams2.redhat.com [10.36.117.28]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5CBB0600F8; Fri, 1 Nov 2019 15:25:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1572621937; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=icUeNLBSxyx75ffAXIxpWLaiCSmihYFyORHxaJ+gyyQ=; b=DgeFbS/B55U/uEfUUojMr5FwMaHGG+7xn742aCMrzpDxNiq8pgXmWo11JCNpIFZ1JBDIlr Ed3UsnfaoQWlV/fBhhdRtGgLUpNYs5hnoIQNh64CaUUaxNfgErvC2Vs4TyNk0yilS6DfR5 4cHvmWoU7hHK+J8VsHHuK7+BRBZDREo= From: Max Reitz To: qemu-block@nongnu.org Subject: [PATCH for-4.2 v2 3/3] block/file-posix: Let post-EOF fallocate serialize Date: Fri, 1 Nov 2019 16:25:10 +0100 Message-Id: <20191101152510.11719-4-mreitz@redhat.com> In-Reply-To: <20191101152510.11719-1-mreitz@redhat.com> References: <20191101152510.11719-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-MC-Unique: M1hTulrCPgG_8SUMBogPhg-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.81 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Vladimir Sementsov-Ogievskiy , qemu-stable@nongnu.org, qemu-devel@nongnu.org, Anton Nefedov , Stefan Hajnoczi , "Denis V . Lunev" , Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" The XFS kernel driver has a bug that may cause data corruption for qcow2 images as of qemu commit c8bb23cbdbe32f. We can work around it by treating post-EOF fallocates as serializing up until infinity (INT64_MAX in practice). Cc: qemu-stable@nongnu.org Signed-off-by: Max Reitz Reviewed-by: Stefan Hajnoczi --- block/file-posix.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/block/file-posix.c b/block/file-posix.c index 0b7e904d48..1f0f61a02b 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -2721,6 +2721,42 @@ raw_do_pwrite_zeroes(BlockDriverState *bs, int64_t o= ffset, int bytes, RawPosixAIOData acb; ThreadPoolFunc *handler; =20 +#ifdef CONFIG_FALLOCATE + if (offset + bytes > bs->total_sectors * BDRV_SECTOR_SIZE) { + BdrvTrackedRequest *req; + uint64_t end; + + /* + * This is a workaround for a bug in the Linux XFS driver, + * where writes submitted through the AIO interface will be + * discarded if they happen beyond a concurrently running + * fallocate() that increases the file length (i.e., both the + * write and the fallocate() happen beyond the EOF). + * + * To work around it, we extend the tracked request for this + * zero write until INT64_MAX (effectively infinity), and mark + * it as serializing. + * + * We have to enable this workaround for all filesystems and + * AIO modes (not just XFS with aio=3Dnative), because for + * remote filesystems we do not know the host configuration. + */ + + req =3D bdrv_co_get_self_request(bs); + assert(req); + assert(req->type =3D=3D BDRV_TRACKED_WRITE); + assert(req->offset <=3D offset); + assert(req->offset + req->bytes >=3D offset + bytes); + + end =3D INT64_MAX & -(uint64_t)bs->bl.request_alignment; + req->bytes =3D end - req->offset; + req->overlap_bytes =3D req->bytes; + + bdrv_mark_request_serialising(req, bs->bl.request_alignment); + bdrv_wait_serialising_requests(req); + } +#endif + acb =3D (RawPosixAIOData) { .bs =3D bs, .aio_fildes =3D s->fd, --=20 2.21.0