From nobody Tue May 7 12:08:01 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; 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=cJRiuwM/v1hBB/nHpqCiyY1fIh+KnQyjPEz5Oda3oYe1UeayYdHjYZgdolbRjNu5ZDPyQTZXw2RNBrSKryCgS1bWp8080rPgIO8ax22A8foGbJtK4YxOgY4ouxCMRFsVpmh0DFiM8hUF0kc+EYmpJbl2EkEniWV4ii1kt4zE2HU= 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=npTNUtjC5deoBc58HFfKiUWI/EEJd16FVY7vW/PAcNQ=; b=aTvlUx/R4ls0eUwnO4MIZIhmZR4mrab/2myLM3juCbkAys619lKrczt8Y1N9penb1t3AWyyGo4Zu0FCsPaRHWog0FMtNKJ7Fin78G/Z/misXuAulK9OR3FIUvoVojOj57vrja+wnEoWn5Dq+56f68ks4v0XAl2jfsNIhyeTmaLI= 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 1558719202014642.3004097815243; Fri, 24 May 2019 10:33:22 -0700 (PDT) Received: from localhost ([127.0.0.1]:57885 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hUE48-0000mJ-Q2 for importer@patchew.org; Fri, 24 May 2019 13:33:12 -0400 Received: from eggs.gnu.org ([209.51.188.92]:53399) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hUE25-0007DD-Lv for qemu-devel@nongnu.org; Fri, 24 May 2019 13:31:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hUDzb-0004Q5-Gn for qemu-devel@nongnu.org; Fri, 24 May 2019 13:28:32 -0400 Received: from mx1.redhat.com ([209.132.183.28]:56422) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hUDza-0004P8-6B; Fri, 24 May 2019 13:28:30 -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 1DF463004413; Fri, 24 May 2019 17:28:21 +0000 (UTC) Received: from localhost (ovpn-204-150.brq.redhat.com [10.40.204.150]) by smtp.corp.redhat.com (Postfix) with ESMTPS id AB2F760C62; Fri, 24 May 2019 17:28:19 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Fri, 24 May 2019 19:28:10 +0200 Message-Id: <20190524172812.27308-2-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.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.44]); Fri, 24 May 2019 17:28:24 +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 1/3] block: Add ImageRotationalInfo 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" This enum indicates whether a file is stored on a rotating disk or a solid-state drive. Drivers report it via the .bdrv_get_info() callback, and if they do not, the global bdrv_get_info() implementation automatically takes it from bs->file or bs->backing, if available. On the QAPI side, we report the value as part of the ImageInfo structure. Signed-off-by: Max Reitz --- qapi/block-core.json | 19 ++++++++++++++++++- include/block/block.h | 7 +++++++ block.c | 20 +++++++++++++++++++- block/qapi.c | 3 +++ 4 files changed, 47 insertions(+), 2 deletions(-) diff --git a/qapi/block-core.json b/qapi/block-core.json index 3e4042be7f..80b9f2a69c 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -130,6 +130,20 @@ 'luks': 'QCryptoBlockInfoLUKS' } } =20 +## +# @ImageRotationalInfo: +# +# Indicates whether an image is stored on a rotating disk or not. +# +# @solid-state: Image is stored on a solid-state drive +# +# @rotating: Image is stored on a rotating disk +# +# Since: 4.1 +## +{ 'enum': 'ImageRotationalInfo', + 'data': [ 'solid-state', 'rotating' ] } + ## # @ImageInfo: # @@ -161,6 +175,9 @@ # # @backing-image: info of the backing image (since 1.6) # +# @rotational: indicates whether the image is stored on a rotating +# disk or not (since 4.1) +# # @format-specific: structure supplying additional format-specific # information (since 1.7) # @@ -173,7 +190,7 @@ '*cluster-size': 'int', '*encrypted': 'bool', '*compressed': 'b= ool', '*backing-filename': 'str', '*full-backing-filename': 'str', '*backing-filename-format': 'str', '*snapshots': ['SnapshotInfo= '], - '*backing-image': 'ImageInfo', + '*backing-image': 'ImageInfo', '*rotational': 'ImageRotationalI= nfo', '*format-specific': 'ImageInfoSpecific' } } =20 ## diff --git a/include/block/block.h b/include/block/block.h index 531cf595cf..dc0f8a4671 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -31,6 +31,13 @@ typedef struct BlockDriverInfo { * True if this block driver only supports compressed writes */ bool needs_compressed_writes; + + /* + * Indicates whether this image file is stored on a rotating disk + * or a solid-state drive. + */ + bool has_rotational_info; + ImageRotationalInfo rotational_info; } BlockDriverInfo; =20 typedef struct BlockFragInfo { diff --git a/block.c b/block.c index 4c3902508d..e6b2d6d23b 100644 --- a/block.c +++ b/block.c @@ -4950,6 +4950,8 @@ void bdrv_get_backing_filename(BlockDriverState *bs, int bdrv_get_info(BlockDriverState *bs, BlockDriverInfo *bdi) { BlockDriver *drv =3D bs->drv; + int ret; + /* if bs->drv =3D=3D NULL, bs is closed, so there's nothing to do here= */ if (!drv) { return -ENOMEDIUM; @@ -4960,8 +4962,24 @@ int bdrv_get_info(BlockDriverState *bs, BlockDriverI= nfo *bdi) } return -ENOTSUP; } + memset(bdi, 0, sizeof(*bdi)); - return drv->bdrv_get_info(bs, bdi); + ret =3D drv->bdrv_get_info(bs, bdi); + if (ret < 0) { + return ret; + } + + if (!bdi->has_rotational_info && (bs->file || bs->backing)) { + BlockDriverState *child =3D bs->file ? bs->file->bs : bs->backing-= >bs; + BlockDriverInfo child_bdi; + + if (bdrv_get_info(child, &child_bdi) >=3D 0) { + bdi->rotational_info =3D child_bdi.rotational_info; + bdi->has_rotational_info =3D child_bdi.has_rotational_info; + } + } + + return 0; } =20 ImageInfoSpecific *bdrv_get_specific_info(BlockDriverState *bs, diff --git a/block/qapi.c b/block/qapi.c index 0c13c86f4e..48ebfbdcc1 100644 --- a/block/qapi.c +++ b/block/qapi.c @@ -286,6 +286,9 @@ void bdrv_query_image_info(BlockDriverState *bs, } info->dirty_flag =3D bdi.is_dirty; info->has_dirty_flag =3D true; + + info->rotational =3D bdi.rotational_info; + info->has_rotational =3D bdi.has_rotational_info; } info->format_specific =3D bdrv_get_specific_info(bs, &err); if (err) { --=20 2.21.0 From nobody Tue May 7 12:08:01 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; 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=1558719223; cv=none; d=zoho.com; s=zohoarc; b=Fhxd2qR4BpNRUeut9Y044LaQY+t/qZNJcXK3wvbAfq8x8bU3JhZBJkgWIILO+L/0H3toCc/Jv2qNd1geprRM0a8E8pE3D0s6OHAWbfGHE4Kv8SXkMvGhD8e7vIFTgrC4GH3eXcxPNLDQBntBRyO1z9WWIcQ0aaqvORRz2SXe3lw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1558719223; 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=EsfoZMCnjru2RFJGgmTTVEertVg1nW74EyiTfdN6vWo=; b=K4Hv0Sn/Kb98tlkTTm47Nf/ycu/3K7Dr/A9wTq+U4XQpvHGyrMpakbRtK8U+OO77D/pAlv7Gq8VZjP1sKIBGSFUmjW3EjJh8C/xRCF1d9lw6HtM+OQe4/+/dOoXyQNkfRtAM1m8aD/x7dHHEhsbav2vVvG5c9k0FfwB++xGBJlA= 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 (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1558719223937399.71644251733414; Fri, 24 May 2019 10:33:43 -0700 (PDT) Received: from localhost ([127.0.0.1]:57887 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hUE4W-00015C-V9 for importer@patchew.org; Fri, 24 May 2019 13:33:36 -0400 Received: from eggs.gnu.org ([209.51.188.92]:53416) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hUE27-0007Ea-DV for qemu-devel@nongnu.org; Fri, 24 May 2019 13:31:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hUDzW-0004NN-PV for qemu-devel@nongnu.org; Fri, 24 May 2019 13:28:27 -0400 Received: from mx1.redhat.com ([209.132.183.28]:50212) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hUDzV-0004MN-Hp; Fri, 24 May 2019 13:28:25 -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 mx1.redhat.com (Postfix) with ESMTPS id CD7E330001EB; Fri, 24 May 2019 17:28:24 +0000 (UTC) Received: from localhost (ovpn-204-150.brq.redhat.com [10.40.204.150]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 170545C1B4; Fri, 24 May 2019 17:28:22 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Fri, 24 May 2019 19:28:11 +0200 Message-Id: <20190524172812.27308-3-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.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Fri, 24 May 2019 17:28:24 +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 2/3] file-posix: Inquire rotational status 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" On Linux, we can inquire whether the file is stored on a rotating disk or on a solid-state drive through the sysfs. (The BLKROTATIONAL ioctl only works on device files themselves.) Signed-off-by: Max Reitz --- block/file-posix.c | 73 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) diff --git a/block/file-posix.c b/block/file-posix.c index d018429672..f84179c0dc 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -161,6 +161,9 @@ typedef struct BDRVRawState { bool check_cache_dropped; =20 PRManager *pr_mgr; + + bool has_rotational_info; + ImageRotationalInfo rotational_info; } BDRVRawState; =20 typedef struct BDRVRawReopenState { @@ -378,6 +381,68 @@ static void raw_probe_alignment(BlockDriverState *bs, = int fd, Error **errp) } } =20 +/** + * Tries to inquire whether the file is stored on a rotating disk or a + * solid-state drive. + */ +static void raw_update_rotational_info(BDRVRawState *s) +{ +#ifdef CONFIG_LINUX + struct stat st; + char *part_fname, *rot_fname; + char rot_info[3]; + dev_t dev; + int rot_fd; + int ret; + + s->has_rotational_info =3D false; + + if (fstat(s->fd, &st) < 0) { + return; + } + + if (st.st_rdev) { + dev =3D st.st_rdev; + } else { + dev =3D st.st_dev; + } + + part_fname =3D g_strdup_printf("/sys/dev/block/%u:%u/partition", + major(dev), minor(dev)); + if (access(part_fname, F_OK) =3D=3D 0) { + rot_fname =3D g_strdup_printf("/sys/dev/block/%u:%u/../queue/rotat= ional", + major(dev), minor(dev)); + } else { + rot_fname =3D g_strdup_printf("/sys/dev/block/%u:%u/queue/rotation= al", + major(dev), minor(dev)); + } + g_free(part_fname); + + rot_fd =3D open(rot_fname, O_RDONLY); + g_free(rot_fname); + if (rot_fd < 0) { + return; + } + + ret =3D read(rot_fd, rot_info, 2); + close(rot_fd); + if (ret < 2) { + return; + } + + rot_info[2] =3D '\0'; + if (!strcmp(rot_info, "0\n")) { + s->rotational_info =3D IMAGE_ROTATIONAL_INFO_SOLID_STATE; + s->has_rotational_info =3D true; + } else if (!strcmp(rot_info, "1\n")) { + s->rotational_info =3D IMAGE_ROTATIONAL_INFO_ROTATING; + s->has_rotational_info =3D true; + } +#else /* CONFIG_LINUX */ + s->has_rotational_info =3D false; +#endif +} + static void raw_parse_flags(int bdrv_flags, int *open_flags, bool has_writ= ers) { bool read_write =3D false; @@ -652,6 +717,8 @@ static int raw_open_common(BlockDriverState *bs, QDict = *options, } #endif =20 + raw_update_rotational_info(s); + bs->supported_zero_flags =3D BDRV_REQ_MAY_UNMAP | BDRV_REQ_NO_FALLBACK; ret =3D 0; fail: @@ -1007,6 +1074,8 @@ static void raw_reopen_commit(BDRVReopenState *state) qemu_close(s->fd); s->fd =3D rs->fd; =20 + raw_update_rotational_info(s); + g_free(state->opaque); state->opaque =3D NULL; =20 @@ -2731,6 +2800,10 @@ static int raw_get_info(BlockDriverState *bs, BlockD= riverInfo *bdi) BDRVRawState *s =3D bs->opaque; =20 bdi->unallocated_blocks_are_zero =3D s->discard_zeroes; + + bdi->rotational_info =3D s->rotational_info; + bdi->has_rotational_info =3D s->has_rotational_info; + return 0; } =20 --=20 2.21.0 From nobody Tue May 7 12:08:01 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; 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