From nobody Mon Feb 9 23:16:15 2026 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; 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=1558719202; cv=none; d=zoho.com; s=zohoarc; b=ooe5K3JvraokIjL0JknEabKnAwEtDL2zn6Il8QEhJD4Yj2yEpEoM3ncngheJUhGUpWnvq2L6OP6XYGOYH76qBWdbA5O4qIP0Nua/QTtWC1aiX/snDwyx9hpwd8ZrrJ3IqfvL44NklgaNdUT+G0CwWpUCX12XtWobi86B54GPnDI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1558719202; h=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:ARC-Authentication-Results; bh=nUc+ueOaz96pN++YhPyk/luEcu0+CbaLvrx8ZjvhZOA=; b=fY7HW48TOdtTJ0lgTsAqVY4VbYq6E0fWGk+J8rbrQafOLDl3Ym5+BMQFGP2DvAMTcF21rzjj6zNtIK+FyseLp81HuB3C4KZIn/DOWoOZ7k9a8FSCn7QLlv7BPRlS8O8Mj1zO3KroWWxG82T5oa/XDOc5WQeNbtVkpOLIKnAkKdY= ARC-Authentication-Results: i=1; mx.zoho.com; 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 (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1558719202328165.9591818810684; Fri, 24 May 2019 10:33:22 -0700 (PDT) Received: from localhost ([127.0.0.1]:57883 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hUE46-0000jv-6y for importer@patchew.org; Fri, 24 May 2019 13:33:10 -0400 Received: from eggs.gnu.org ([209.51.188.92]:53416) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hUE23-0007Ea-VF for qemu-devel@nongnu.org; Fri, 24 May 2019 13:31:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hUDzg-0004SL-7v for qemu-devel@nongnu.org; Fri, 24 May 2019 13:28:37 -0400 Received: from mx1.redhat.com ([209.132.183.28]:40850) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hUDze-0004RO-VN; Fri, 24 May 2019 13:28:35 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4610030C1AE6; Fri, 24 May 2019 17:28:29 +0000 (UTC) Received: from localhost (ovpn-204-150.brq.redhat.com [10.40.204.150]) by smtp.corp.redhat.com (Postfix) with ESMTPS id CEBA510027B6; Fri, 24 May 2019 17:28:26 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Fri, 24 May 2019 19:28:12 +0200 Message-Id: <20190524172812.27308-4-mreitz@redhat.com> In-Reply-To: <20190524172812.27308-1-mreitz@redhat.com> References: <20190524172812.27308-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Fri, 24 May 2019 17:28:34 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [RFC 3/3] qcow2: Evaluate rotational info 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: Kevin Wolf , Anton Nefedov , Alberto Garcia , qemu-devel@nongnu.org, Max Reitz , Vladimir Sementsov-Ogievskiy Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" The new handle_alloc_space() function only speeds up the allocation of new ranges on solid-state drives. We should skip it if we know that the file is stored on a rotating disk. Signed-off-by: Max Reitz --- block/qcow2.h | 3 +++ block/qcow2.c | 34 ++++++++++++++++++++++++++++++---- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/block/qcow2.h b/block/qcow2.h index fc1b0d3c1e..5052ab187f 100644 --- a/block/qcow2.h +++ b/block/qcow2.h @@ -359,6 +359,9 @@ typedef struct BDRVQcow2State { =20 bool metadata_preallocation_checked; bool metadata_preallocation; + + /* True if the image is stored on a rotating disk */ + bool optimize_for_rotating; } BDRVQcow2State; =20 typedef struct Qcow2COWRegion { diff --git a/block/qcow2.c b/block/qcow2.c index 14f914117f..b4df6d5085 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -1197,6 +1197,22 @@ static int qcow2_update_options(BlockDriverState *bs= , QDict *options, return ret; } =20 +static void qcow2_update_rotational_info(BlockDriverState *bs) +{ + BDRVQcow2State *s =3D bs->opaque; + BlockDriverInfo file_bdi; + + s->optimize_for_rotating =3D false; + + if (bdrv_get_info(bs->file->bs, &file_bdi) < 0) { + return; + } + + s->optimize_for_rotating =3D + file_bdi.has_rotational_info && + file_bdi.rotational_info =3D=3D IMAGE_ROTATIONAL_INFO_ROTATING; +} + /* Called with s->lock held. */ static int coroutine_fn qcow2_do_open(BlockDriverState *bs, QDict *options, int flags, Error **errp) @@ -1461,6 +1477,8 @@ static int coroutine_fn qcow2_do_open(BlockDriverStat= e *bs, QDict *options, } } =20 + qcow2_update_rotational_info(bs); + /* Parse driver-specific options */ ret =3D qcow2_update_options(bs, options, flags, errp); if (ret < 0) { @@ -1829,6 +1847,8 @@ static void qcow2_reopen_commit(BDRVReopenState *stat= e) { qcow2_update_options_commit(state->bs, state->opaque); g_free(state->opaque); + + qcow2_update_rotational_info(state->bs); } =20 static void qcow2_reopen_abort(BDRVReopenState *state) @@ -2297,10 +2317,16 @@ static coroutine_fn int qcow2_co_pwritev(BlockDrive= rState *bs, uint64_t offset, qemu_iovec_add(&hd_qiov, cluster_data, cur_bytes); } =20 - /* Try to efficiently initialize the physical space with zeroes */ - ret =3D handle_alloc_space(bs, l2meta); - if (ret < 0) { - goto out_unlocked; + /* + * Try to efficiently initialize the physical space with zeroes. + * This incurs a performance penalty on rotating disks, so + * avoid doing it there. + */ + if (!s->optimize_for_rotating) { + ret =3D handle_alloc_space(bs, l2meta); + if (ret < 0) { + goto out_unlocked; + } } =20 /* If we need to do COW, check if it's possible to merge the --=20 2.21.0