From patchwork Mon Jan 14 11:18:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Nefedov X-Patchwork-Id: 1024433 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=virtuozzo.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=virtuozzo.com header.i=@virtuozzo.com header.b="MBPCzYkO"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 43dWM13NT4z9s9G for ; Mon, 14 Jan 2019 22:23:56 +1100 (AEDT) Received: from localhost ([127.0.0.1]:49690 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gj0LQ-0003ui-EG for incoming@patchwork.ozlabs.org; Mon, 14 Jan 2019 06:23:52 -0500 Received: from eggs.gnu.org ([209.51.188.92]:37453) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gj0Gc-0000Vl-FL for qemu-devel@nongnu.org; Mon, 14 Jan 2019 06:18:56 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gj0Ga-0001BI-QB for qemu-devel@nongnu.org; Mon, 14 Jan 2019 06:18:54 -0500 Received: from mail-am5eur02on0707.outbound.protection.outlook.com ([2a01:111:f400:fe07::707]:30621 helo=EUR02-AM5-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gj0Ga-0000Wf-AK; Mon, 14 Jan 2019 06:18:52 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtuozzo.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Jk4Ou71Ecg5NH8Uoivhsp51jEo5uchjOikj365cBYPo=; b=MBPCzYkOAxwU+167Uc+WGy5SA7az7dGPgkUfU/jUI2X5k+wpclEW0dmdNc9P7UVSAfEbiyauoXpyrZPtRvDC55K9jlTpkx7bNB9gqY59WGEH5Hb07OuPAXea77uf98/NtqH3EUbQiGb1UMnQ452pAlzy43sHZs3fop0N/cROSiY= Received: from AM0PR08MB4292.eurprd08.prod.outlook.com (20.179.33.17) by AM0PR08MB2977.eurprd08.prod.outlook.com (52.134.92.150) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1516.14; Mon, 14 Jan 2019 11:18:26 +0000 Received: from AM0PR08MB4292.eurprd08.prod.outlook.com ([fe80::d13a:1305:bb54:1916]) by AM0PR08MB4292.eurprd08.prod.outlook.com ([fe80::d13a:1305:bb54:1916%6]) with mapi id 15.20.1516.019; Mon, 14 Jan 2019 11:18:26 +0000 From: Anton Nefedov To: "qemu-devel@nongnu.org" Thread-Topic: [PATCH v12 04/10] block: introduce BDRV_REQ_ALLOCATE flag Thread-Index: AQHUq/reTrm4r3g2pk6/zDL/tMY6ew== Date: Mon, 14 Jan 2019 11:18:26 +0000 Message-ID: <20190114111744.113188-5-anton.nefedov@virtuozzo.com> References: <20190114111744.113188-1-anton.nefedov@virtuozzo.com> In-Reply-To: <20190114111744.113188-1-anton.nefedov@virtuozzo.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: HE1PR0701CA0065.eurprd07.prod.outlook.com (2603:10a6:3:9e::33) To AM0PR08MB4292.eurprd08.prod.outlook.com (2603:10a6:208:13b::17) x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.17.1 x-originating-ip: [185.231.240.5] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; AM0PR08MB2977; 20:QGagsOTlpYAirrEwqDBfHG9bM1yo2QS5+2dNejbFCpqFjl0ZU5XFGdo6tGvq/dS+4wek9vpow853qfOyYCjDmt5JsfNl9fJey6P0IN5RBBBCQKnqNAZggCbqPBjdzKimtajRb8TlbDNSwk2H+mu67VoOWXjsnEB05A7djQ4+7Ho= x-ms-office365-filtering-correlation-id: ddd14434-80cc-47a7-8869-08d67a12009b x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600109)(711020)(2017052603328)(7153060)(7193020); SRVR:AM0PR08MB2977; x-ms-traffictypediagnostic: AM0PR08MB2977: x-microsoft-antispam-prvs: x-forefront-prvs: 0917DFAC67 x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(39840400004)(396003)(136003)(366004)(346002)(376002)(199004)(189003)(6346003)(256004)(14454004)(5640700003)(6486002)(6916009)(8936002)(1076003)(36756003)(97736004)(53936002)(305945005)(476003)(107886003)(478600001)(186003)(2906002)(486006)(6116002)(50226002)(3846002)(26005)(2501003)(2616005)(99286004)(8676002)(11346002)(66066001)(4326008)(5660300001)(52116002)(71200400001)(81156014)(25786009)(81166006)(71190400001)(76176011)(2351001)(7736002)(316002)(105586002)(106356001)(68736007)(102836004)(44832011)(6436002)(446003)(54906003)(6512007)(86362001)(6506007)(386003); DIR:OUT; SFP:1102; SCL:1; SRVR:AM0PR08MB2977; H:AM0PR08MB4292.eurprd08.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; received-spf: None (protection.outlook.com: virtuozzo.com does not designate permitted sender hosts) authentication-results: spf=none (sender IP is ) smtp.mailfrom=anton.nefedov@virtuozzo.com; x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: 5+Kx+zg6jNP3vTUswnHtqFcMcQyDHa/rwnK9Es3ImXTbFOp5JRx1AkKk3Ec3NT0ltIahtknbTF4B5WPfRThwfIGIFY4iW0in8PhSaeO+GYKgZPwFxiamMAB/mc56qUqSGesxXQNDMPWI924To2W9Kp8w13HcLhZqlUfSup5gAKwk0mYH0NoC6zn5RidltETqIfeRtHXgF7UDaybNXyzJoi6CJMb9LIQgJwi8r5f8g8axnnHSomfjzomNs5BdAXDqMOucPRdnHa+NY17UKLMgQ3Z2H248IcHToEwET7iKyPQerj+QDXQ918Ym76OKeQTdoONQNBJCOU9Gt1UXIPWVtRhGrt49+GWMzQ1S41W0jMhN4Fxj6Z7hDWASiTHtvn7TvZIQAAPCNCU8BmLzT9EtXMQTUqs6xMOfexibp6E2MbY= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: ddd14434-80cc-47a7-8869-08d67a12009b X-MS-Exchange-CrossTenant-originalarrivaltime: 14 Jan 2019 11:18:25.1852 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR08MB2977 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 2a01:111:f400:fe07::707 Subject: [Qemu-devel] [PATCH v12 04/10] block: introduce BDRV_REQ_ALLOCATE flag 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" , Vladimir Sementsov-Ogievskiy , "berto@igalia.com" , Denis Lunev , "qemu-block@nongnu.org" , "mreitz@redhat.com" , Anton Nefedov Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" The flag is supposed to indicate that the region of the disk image has to be sufficiently allocated so it reads as zeroes. The call with the flag set must return -ENOTSUP if allocation cannot be done efficiently. This has to be made sure of by both - the drivers that support the flag - and the common block layer (so it will not fall back to any slowpath (like writing zero buffers) in case the driver does not support the flag). Signed-off-by: Anton Nefedov Reviewed-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Alberto Garcia --- include/block/block.h | 10 +++++++++- include/block/block_int.h | 3 ++- block/io.c | 14 +++++++++++++- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/include/block/block.h b/include/block/block.h index f70a843b72..643d32f4b8 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -83,8 +83,16 @@ typedef enum { */ BDRV_REQ_SERIALISING = 0x80, + /* + * The BDRV_REQ_ALLOCATE flag is used to indicate that the driver has to + * efficiently allocate the space so it reads as zeroes, or return an error. + * If this flag is set then BDRV_REQ_ZERO_WRITE must also be set. + * This flag cannot be set together with BDRV_REQ_MAY_UNMAP. + */ + BDRV_REQ_ALLOCATE = 0x100, + /* Mask of valid flags */ - BDRV_REQ_MASK = 0xff, + BDRV_REQ_MASK = 0x1ff, } BdrvRequestFlags; typedef struct BlockSizes { diff --git a/include/block/block_int.h b/include/block/block_int.h index f605622216..833129d912 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -724,7 +724,8 @@ struct BlockDriverState { * their children. */ unsigned int supported_write_flags; /* Flags honored during pwrite_zeroes (so far: BDRV_REQ_FUA, - * BDRV_REQ_MAY_UNMAP, BDRV_REQ_WRITE_UNCHANGED) */ + * BDRV_REQ_MAY_UNMAP, BDRV_REQ_WRITE_UNCHANGED, BDRV_REQ_ALLOCATE) + */ unsigned int supported_zero_flags; /* the following member gives a name to every node on the bs graph. */ diff --git a/block/io.c b/block/io.c index bd9d688f8b..66006a089d 100644 --- a/block/io.c +++ b/block/io.c @@ -1534,7 +1534,7 @@ static int coroutine_fn bdrv_co_do_pwrite_zeroes(BlockDriverState *bs, assert(!bs->supported_zero_flags); } - if (ret == -ENOTSUP) { + if (ret == -ENOTSUP && !(flags & BDRV_REQ_ALLOCATE)) { /* Fall back to bounce buffer if write zeroes is unsupported */ BdrvRequestFlags write_flags = flags & ~BDRV_REQ_ZERO_WRITE; @@ -1773,6 +1773,9 @@ static int coroutine_fn bdrv_co_do_zero_pwritev(BdrvChild *child, assert(flags & BDRV_REQ_ZERO_WRITE); if (head_padding_bytes || tail_padding_bytes) { + if (flags & BDRV_REQ_ALLOCATE) { + return -ENOTSUP; + } buf = qemu_blockalign(bs, align); iov = (struct iovec) { .iov_base = buf, @@ -1858,6 +1861,9 @@ int coroutine_fn bdrv_co_pwritev(BdrvChild *child, bool use_local_qiov = false; int ret; + assert(!((flags & BDRV_REQ_ALLOCATE) && (flags & BDRV_REQ_MAY_UNMAP))); + assert(!((flags & BDRV_REQ_ALLOCATE) && !(flags & BDRV_REQ_ZERO_WRITE))); + trace_bdrv_co_pwritev(child->bs, offset, bytes, flags); if (!bs->drv) { @@ -1980,6 +1986,12 @@ int coroutine_fn bdrv_co_pwrite_zeroes(BdrvChild *child, int64_t offset, { trace_bdrv_co_pwrite_zeroes(child->bs, offset, bytes, flags); + if ((flags & BDRV_REQ_ALLOCATE) && + !(child->bs->supported_zero_flags & BDRV_REQ_ALLOCATE)) + { + return -ENOTSUP; + } + if (!(child->bs->open_flags & BDRV_O_UNMAP)) { flags &= ~BDRV_REQ_MAY_UNMAP; }