From patchwork Fri Dec 6 00:07:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takeshi Suzuki X-Patchwork-Id: 13896117 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 0619BE7716E for ; Fri, 6 Dec 2024 00:08:53 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tJLtO-00056o-Jv; Thu, 05 Dec 2024 19:08:22 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tJLtM-00056P-39; Thu, 05 Dec 2024 19:08:20 -0500 Received: from mail-oo1-xc32.google.com ([2607:f8b0:4864:20::c32]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tJLtK-0000fK-99; Thu, 05 Dec 2024 19:08:19 -0500 Received: by mail-oo1-xc32.google.com with SMTP id 006d021491bc7-5f1d1fdb328so423618eaf.3; Thu, 05 Dec 2024 16:08:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733443696; x=1734048496; darn=nongnu.org; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=Wui8MJ22WEMSJ4dKXTOKhXCd0e/cs43WDijGmkD/eL4=; b=exlS51rh/5EemMrP/W9XABKeNhtmhL16EC4yHyZCz20gmww4efCFusiJ+Nx/X32n8+ pFDdxonfUcpVFy9cPlPYKX7TQvMrWbQY1/SOpz/svCri9sw1VsV+ogKnab2A+0CfiQQl NejOWNN/BT9Slz1SBpVsxhetg1c7lzQiaLro9mkNsVYCggu10IqG/y8YJhQg7Djl33mJ 5whZD8PiCDQVYptHgtsJ40872XkCnnt1geqFEB/BkO0FlSitzBdpc//Rr/Sq6IzL8Fh6 L3XMlg5fo3koXoFjfrHmPtBHUDuC/Mgpt0APgSq0dw+FNrKSq7G26EqhN5nnulUZuuXc U6Rg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733443696; x=1734048496; h=references:in-reply-to:message-id:date:subject:cc:to:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Wui8MJ22WEMSJ4dKXTOKhXCd0e/cs43WDijGmkD/eL4=; b=UObyGYP1LpSTq2H8GMUzhLox03cMHMnyc41uzz4bKDzCRIc2lB876jaKbxEEiunrYf Zy/axTxCYrJDl40excksAtmjUClzvXZTnLJlML6l2WBNKWDuxjZOe0WBCV6ciWcdZkTZ uvVu6YN8HPqE/CBU/KAUBfrFWB6o8JFqW3/KPGSUtxsJGwoIQOXLYEfVVNaKiHncnMHT Ynak//WiV+nUoV53M6kzmj04vhJyYznnRgu/pscSM9hrK428uTOWWLfVRxv51EU/BvuD rLMB4fdNlD3qxbssMoDan7SDVxsKva8hsowJPXcqEuXinbLIFlJ4uZSgO5jCmbX9/byB uAiw== X-Forwarded-Encrypted: i=1; AJvYcCU5tBDyhB7zSosn1W+OUdHRc31tulGIJqik3bMD9p+Gs+LZIqMCcg7bFKxuYupn1hsPeL4R1K2IwkuM@nongnu.org X-Gm-Message-State: AOJu0YxWCBzAxMznXZ3a5LPxwFV5Hh5W4wESoNb/1u5pOtITOjkyHAPY HQvUik85rOI9oBV3ELrzmu83OHmayoWdXc1tvgXy0JhtfZQQKAF4yMktr13M X-Gm-Gg: ASbGnctJ9Ue+k9G9tQbTzs1yJoGtZH6SQkRbc7HLHCh7I/OtTyUUnf0nPhLz4Lc1xeQ kR9pt8yKB08PKRI/MwRYW/SDsZKxRCAv758nCzuPMk2KVSMOZs1RB7ZGOM+2z3T7bhFc/EAooS0 J1dad3RSDHFSHg/+SOV/aKL41tawTgb5IF9LQT2LpONI/RVKW5IS5OEYwR5q6ASkflU806uZ5TM VBJbOk9yNZ9LBg8EKYiJ2zJLkOtcFg2Jaw37dMpXAZTkZuYSjzPRSys3mSzJQVovd1oWv8yG1aD d9XU4x8WAOBC1b39kog= X-Google-Smtp-Source: AGHT+IESix98SC+a14ZgIUJqAgTgyoYZYAXQRLy9i1FNLKRj0oxfZFGegYofpwfwijkY4RN1zoDigg== X-Received: by 2002:a05:6830:628b:b0:71d:40b6:2ba8 with SMTP id 46e09a7af769-71dcf553372mr484839a34.22.1733443696259; Thu, 05 Dec 2024 16:08:16 -0800 (PST) Received: from takeshi-suzuki-dev01.colo.rubrik.com ([104.171.196.13]) by smtp.gmail.com with ESMTPSA id 006d021491bc7-5f2793046d9sm486212eaf.30.2024.12.05.16.08.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Dec 2024 16:08:15 -0800 (PST) From: Takeshi Suzuki To: qemu-devel@nongnu.org Cc: codyprime@gmail.com, kwolf@redhat.com, hreitz@redhat.com, eblake@redhat.com, armbru@redhat.com, qemu-block@nongnu.org, Takeshi Suzuki Subject: [PATCH v2 1/3] Add RW support for 4k sector size vhdx Date: Thu, 5 Dec 2024 16:07:49 -0800 Message-Id: <20241206000751.34694-2-takeshibaconsuzuki@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20241206000751.34694-1-takeshibaconsuzuki@gmail.com> References: <20241206000751.34694-1-takeshibaconsuzuki@gmail.com> Received-SPF: pass client-ip=2607:f8b0:4864:20::c32; envelope-from=takeshibaconsuzuki@gmail.com; helo=mail-oo1-xc32.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Signed-off-by: Takeshi Suzuki --- block/vhdx.c | 76 +++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 70 insertions(+), 6 deletions(-) diff --git a/block/vhdx.c b/block/vhdx.c index 5aa1a13506..495ddc2815 100644 --- a/block/vhdx.c +++ b/block/vhdx.c @@ -824,8 +824,8 @@ vhdx_parse_metadata(BlockDriverState *bs, BDRVVHDXState *s) goto exit; } - /* Currently we only support 512 */ - if (s->logical_sector_size != 512) { + /* Currently we only support 512 and 4096 */ + if (s->logical_sector_size != 512 && s->logical_sector_size != 4096) { ret = -ENOTSUP; goto exit; } @@ -1060,7 +1060,7 @@ static int vhdx_open(BlockDriverState *bs, QDict *options, int flags, /* the VHDX spec dictates that virtual_disk_size is always a multiple of * logical_sector_size */ - bs->total_sectors = s->virtual_disk_size >> s->logical_sector_size_bits; + bs->total_sectors = s->virtual_disk_size >> BDRV_SECTOR_BITS; vhdx_calc_bat_entries(s); @@ -1178,11 +1178,52 @@ vhdx_co_get_info(BlockDriverState *bs, BlockDriverInfo *bdi) } +/* + * Converts bdrv sectors to sectors of s->logical_sector_size. + */ +static void bdrv_sectors_to_sectors(const int64_t bdrv_sector_num, + const int bdrv_nb_sectors, + const BDRVVHDXState *const s, + int64_t * const out_sector_num, + int * const out_nb_sectors, + /* in bytes */ + int * const out_begin_skip, + /* in bytes */ + int * const out_end_skip) { + if (bdrv_nb_sectors == 0) { + *out_nb_sectors = 0; + return; + } + const int64_t begin_off = bdrv_sector_num * BDRV_SECTOR_SIZE; + const int64_t sector_num = begin_off >> s->logical_sector_size_bits; + const int begin_skip = begin_off - sector_num * s->logical_sector_size; + const int64_t end_off = (bdrv_sector_num + bdrv_nb_sectors) * + BDRV_SECTOR_SIZE; + const int64_t end_sector_num = (end_off + s->logical_sector_size - 1) >> + s->logical_sector_size_bits; + const int end_skip = end_sector_num * s->logical_sector_size - end_off; + const int nb_sectors = end_sector_num - sector_num; + *out_sector_num = sector_num; + *out_nb_sectors = nb_sectors; + *out_begin_skip = begin_skip; + *out_end_skip = end_skip; +} + + static int coroutine_fn GRAPH_RDLOCK vhdx_co_readv(BlockDriverState *bs, int64_t sector_num, int nb_sectors, QEMUIOVector *qiov) { BDRVVHDXState *s = bs->opaque; + int begin_skip, end_skip; + bdrv_sectors_to_sectors(sector_num, + nb_sectors, + s, + §or_num, + &nb_sectors, + &begin_skip, + &end_skip); + int ret = 0; VHDXSectorInfo sinfo; uint64_t bytes_done = 0; @@ -1216,9 +1257,16 @@ vhdx_co_readv(BlockDriverState *bs, int64_t sector_num, int nb_sectors, qemu_iovec_memset(&hd_qiov, 0, 0, sinfo.bytes_avail); break; case PAYLOAD_BLOCK_FULLY_PRESENT: + if (bytes_done == 0) { + sinfo.file_offset += begin_skip; + sinfo.bytes_avail -= begin_skip; + } + if (nb_sectors - sinfo.sectors_avail <= 0) { + sinfo.bytes_avail -= end_skip; + } qemu_co_mutex_unlock(&s->lock); ret = bdrv_co_preadv(bs->file, sinfo.file_offset, - sinfo.sectors_avail * BDRV_SECTOR_SIZE, + sinfo.bytes_avail, &hd_qiov, 0); qemu_co_mutex_lock(&s->lock); if (ret < 0) { @@ -1336,8 +1384,17 @@ static int coroutine_fn GRAPH_RDLOCK vhdx_co_writev(BlockDriverState *bs, int64_t sector_num, int nb_sectors, QEMUIOVector *qiov, int flags) { - int ret = -ENOTSUP; BDRVVHDXState *s = bs->opaque; + int begin_skip, end_skip; + bdrv_sectors_to_sectors(sector_num, + nb_sectors, + s, + §or_num, + &nb_sectors, + &begin_skip, + &end_skip); + + int ret = -ENOTSUP; VHDXSectorInfo sinfo; uint64_t bytes_done = 0; uint64_t bat_entry = 0; @@ -1451,9 +1508,16 @@ vhdx_co_writev(BlockDriverState *bs, int64_t sector_num, int nb_sectors, sinfo.bytes_avail); } /* block exists, so we can just overwrite it */ + if (bytes_done == 0) { + sinfo.file_offset += begin_skip; + sinfo.bytes_avail -= begin_skip; + } + if (nb_sectors - sinfo.sectors_avail <= 0) { + sinfo.bytes_avail -= end_skip; + } qemu_co_mutex_unlock(&s->lock); ret = bdrv_co_pwritev(bs->file, sinfo.file_offset, - sectors_to_write * BDRV_SECTOR_SIZE, + sinfo.bytes_avail, &hd_qiov, 0); qemu_co_mutex_lock(&s->lock); if (ret < 0) { From patchwork Fri Dec 6 00:07:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takeshi Suzuki X-Patchwork-Id: 13896118 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 35E53E77173 for ; Fri, 6 Dec 2024 00:08:54 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tJLtS-000586-WA; Thu, 05 Dec 2024 19:08:28 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tJLtO-00056t-H4; Thu, 05 Dec 2024 19:08:22 -0500 Received: from mail-oi1-x236.google.com ([2607:f8b0:4864:20::236]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tJLtM-0000fa-9e; Thu, 05 Dec 2024 19:08:21 -0500 Received: by mail-oi1-x236.google.com with SMTP id 5614622812f47-3ea4f9825f6so468411b6e.2; Thu, 05 Dec 2024 16:08:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733443698; x=1734048498; darn=nongnu.org; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=jpFDBGvKaWqPHra1Mp+6gNMkQKP06H67VZjifeZ9HBA=; b=K4oNbJh2xQTMqksxBM147no1IxleAFAjpRvMVJgfovvQ1wfLrKNlnu+Nu/DqF9xMru 6E4mXC6POjQ5O+JBTqCwB4VWmNw6ZAZ+HVTKBdJacUd6CwjQoIU3Jxf9F/jiePv7yaGe tYJaHOh5Zv3FhXS7clwIC4WVSb9CdYGJu3n3/6Rmp9jadgKOJ4T4kWPHju+VjOrqBkkZ YUIkf3whEYrtG1npTxgY54q4mEm196HUSqiEPK3nluPz66bcBUqHAGkoawomTJ9na6Zj BaQcEPsiDOskNJp9OV5duJEhI0J4Oiplmr+SWj+s0HMJMiPIvjZCBfWcTJaM3FssHIYs Eigw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733443698; x=1734048498; h=references:in-reply-to:message-id:date:subject:cc:to:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=jpFDBGvKaWqPHra1Mp+6gNMkQKP06H67VZjifeZ9HBA=; b=tWcz6I1PjNJY8OR/moDvRBGWVgliFatzhSIGSwDtPk9JkvzRpt+CqiT3K2Jgx7WqWf tYSQ10ee7OctSs2JrHQpMyylIme+avu9SUd0vokNiYnbpciyduo7P1hDKlNEuwK3kFGz pPdYfDg7vvz7DA9P1Q5VuVktQNtjhnckK7HY5XLWJplgXCQNVCpKQ0dl/NoCujeZuA4+ 2mOZHx2zklpn0+gZrx2/A6UZRkpKEPpIMu5v6x6BaeinuBaYT0hB9oJpd9MJaT0fPUyr MMZWoK2r1JJ7a2RzYS0BHOoQNil+aANOlu3JcqBF5gLNBmFjfGRcIyhqC1YSHFWq5lPu 1AFg== X-Forwarded-Encrypted: i=1; AJvYcCVCt3J9id0BtHKIFH776bzDPJ+5u2nPkFSgpbc2YLq/IIW5HVfjB4xyo91vSJKyxzBaRbWdXKb5DyCK@nongnu.org X-Gm-Message-State: AOJu0YwMCoGJaMaARgPJDxbuwCEdwb1VU9zmLFlhy7hXZfzrxYcg/gWk HTPtObDTqQNuL8biuS1gFoFAK9BcAf0DXPPreoFMLXEfvXZJRL09gMHtCecJ X-Gm-Gg: ASbGncuYx8d5AbWRvRW+mcmp2Y53h69NiLhXrIMHxVlyu4xabRjmOBby9cqoGEXSu61 JaMk5EkDWl/7GOasSBSetjyIfSG4fphfRyQc50pShQp/ABiNpjXV+1vJz7/YXOm5S5ei0VMksxx EDcnPoFygeDsVbMdUkX1DUkEvyWcNxLdNmvfHcHxKeYtWRRVzbEtvfSJg0tzQL9i6R83hQeeRuq JdsKLtLbpxHXNslD4CmUAPeR6Ny72JXatMkcZazV+lRMxspFqDZ5mrhUNWzM5jX1BR3np02Uchj 56aGG6/zVXyVsxQoN2A= X-Google-Smtp-Source: AGHT+IGJffJjaGVziJTrrHBcq281iA8MO2TtM7lwgC0YuSPImEMPUetlmk78/xUo642sOlcAMeQ1Aw== X-Received: by 2002:a05:6830:610d:b0:717:dee5:3876 with SMTP id 46e09a7af769-71dcf4e7e3cmr555833a34.16.1733443698422; Thu, 05 Dec 2024 16:08:18 -0800 (PST) Received: from takeshi-suzuki-dev01.colo.rubrik.com ([104.171.196.13]) by smtp.gmail.com with ESMTPSA id 006d021491bc7-5f2793046d9sm486212eaf.30.2024.12.05.16.08.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Dec 2024 16:08:18 -0800 (PST) From: Takeshi Suzuki To: qemu-devel@nongnu.org Cc: codyprime@gmail.com, kwolf@redhat.com, hreitz@redhat.com, eblake@redhat.com, armbru@redhat.com, qemu-block@nongnu.org, Takeshi Suzuki Subject: [PATCH v2 2/3] Add iotest for 4k sector size vhdx Date: Thu, 5 Dec 2024 16:07:50 -0800 Message-Id: <20241206000751.34694-3-takeshibaconsuzuki@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20241206000751.34694-1-takeshibaconsuzuki@gmail.com> References: <20241206000751.34694-1-takeshibaconsuzuki@gmail.com> Received-SPF: pass client-ip=2607:f8b0:4864:20::236; envelope-from=takeshibaconsuzuki@gmail.com; helo=mail-oi1-x236.google.com X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, FREEMAIL_REPLY=1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org See https://github.com/takeshibaconsuzuki/qemu/blob/vhdx_4k_rw/tests/qemu-iotests/sample_images/4k.vhdx.bz2 for binary file. Signed-off-by: Takeshi Suzuki --- tests/qemu-iotests/315 | 65 +++++++++++++++++++ tests/qemu-iotests/315.out | 20 ++++++ tests/qemu-iotests/sample_images/4k.vhdx.bz2 | Bin 0 -> 37834 bytes 3 files changed, 85 insertions(+) create mode 100644 tests/qemu-iotests/315 create mode 100644 tests/qemu-iotests/315.out create mode 100644 tests/qemu-iotests/sample_images/4k.vhdx.bz2 Binary files /dev/null and b/tests/qemu-iotests/sample_images/4k.vhdx.bz2 differ diff --git a/tests/qemu-iotests/315 b/tests/qemu-iotests/315 new file mode 100644 index 0000000000..e5c4978c8c --- /dev/null +++ b/tests/qemu-iotests/315 @@ -0,0 +1,65 @@ +#!/usr/bin/env bash +# group: rw quick +# +# Test VHDX read/write from a 4k sector size sample image created with Hyper-V +# +# Copyright (C) 2013 Red Hat, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# + +# creator +owner=takeshibaconsuzuki@gmail.com + +seq=`basename $0` +echo "QA output created by $seq" + +status=1 # failure is the default! + +_cleanup() +{ + _cleanup_test_img +} +trap "_cleanup; exit \$status" 0 1 2 3 15 + +# get standard environment, filters and checks +. ./common.rc +. ./common.filter + +_supported_fmt vhdx +_supported_proto generic +_supported_os Linux + +_use_sample_img 4k.vhdx.bz2 + +echo +echo "=== Verify pattern 0xaa, 1024MB - 1088MB ===" +$QEMU_IO -r -c "read -pP 0xaa 1024M 64M" "$TEST_IMG" | _filter_qemu_io +echo +echo "=== Verify pattern 0x00, 1088MB - 1152MB ===" +$QEMU_IO -r -c "read -pP 0x00 1088M 64M" "$TEST_IMG" | _filter_qemu_io + +echo +echo "=== Verify pattern write, 0xbb 1072MB - 1104MB ===" +$QEMU_IO -c "write -pP 0xbb 1072M 32M" "$TEST_IMG" | _filter_qemu_io +# first verify we didn't write where we should not have +$QEMU_IO -r -c "read -pP 0xaa 1024M 48M" "$TEST_IMG" | _filter_qemu_io +$QEMU_IO -r -c "read -pP 0x00 1104M 48M" "$TEST_IMG" | _filter_qemu_io +# now verify what we should have actually written +$QEMU_IO -r -c "read -pP 0xbb 1072M 32M" "$TEST_IMG" | _filter_qemu_io + +# success, all done +echo "*** done" +rm -f $seq.full +status=0 diff --git a/tests/qemu-iotests/315.out b/tests/qemu-iotests/315.out new file mode 100644 index 0000000000..31dd48b223 --- /dev/null +++ b/tests/qemu-iotests/315.out @@ -0,0 +1,20 @@ +QA output created by 315 + +=== Verify pattern 0xaa, 1024MB - 1088MB === +read 67108864/67108864 bytes at offset 1073741824 +64 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +=== Verify pattern 0x00, 1088MB - 1152MB === +read 67108864/67108864 bytes at offset 1140850688 +64 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +=== Verify pattern write, 0xbb 1072MB - 1104MB === +wrote 33554432/33554432 bytes at offset 1124073472 +32 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +read 50331648/50331648 bytes at offset 1073741824 +48 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +read 50331648/50331648 bytes at offset 1157627904 +48 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +read 33554432/33554432 bytes at offset 1124073472 +32 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +*** done diff --git a/tests/qemu-iotests/sample_images/4k.vhdx.bz2 b/tests/qemu-iotests/sample_images/4k.vhdx.bz2 new file mode 100644 index 0000000000..6cc10919ab From patchwork Fri Dec 6 00:07:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takeshi Suzuki X-Patchwork-Id: 13896119 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 08882E7716E for ; Fri, 6 Dec 2024 00:09:34 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tJLtV-00059I-DU; Thu, 05 Dec 2024 19:08:29 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tJLtQ-00057h-4m; Thu, 05 Dec 2024 19:08:24 -0500 Received: from mail-oo1-xc36.google.com ([2607:f8b0:4864:20::c36]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tJLtO-0000fx-Kk; Thu, 05 Dec 2024 19:08:23 -0500 Received: by mail-oo1-xc36.google.com with SMTP id 006d021491bc7-5f22ea6d72aso614420eaf.1; Thu, 05 Dec 2024 16:08:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733443700; x=1734048500; darn=nongnu.org; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=se6qbCp0/OCGWSFKD0YAo16T7mN1hR6rpmZ2Msx5uN8=; b=GwG5UQiSW+1W92klm/KOH6i/O4oXWOjAG4p3d+M5Ta2GF6/Oaa8WptqASxBjm72GTl 22MPH5jbS/zS5hGrPCX6YR66weSFiGyyEedMMwUmHof3HCIrm6wPHCeFqRVcjntBR574 f8FsJk35UHrJ9Q0wuhD6emVccp9UOpYHkP0bV7PKSMEu0Z7MThRENVg7G4VA+zM7Djj1 AsNMubIDdN9a+naIayw4I7ZAVG7DrnSCEJTfMnHlUOuwyTxs+nVik5DD8nUc6MWDXawN Yv2xWUsGr3UIziG0eI1EjGBvvuhZ89DKeinoT+gWyGeLU3iVH7TGlE/JHAobm4u3jdXM r9nQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733443700; x=1734048500; h=references:in-reply-to:message-id:date:subject:cc:to:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=se6qbCp0/OCGWSFKD0YAo16T7mN1hR6rpmZ2Msx5uN8=; b=cjnDDTgdgmx/NYBLoTDqwc/EO0/KIt61dGMoTqX3eu3/v/sYloqREIKcS3dVLEAJKZ 0AAqV7dQDD6eZIUgBgCr3mPYlRC7WCsjKpXwRVNd4Deb571STYRSgUGAnihBHGeEhE5g xIjF9M2VyUhSeHtAUxRTqk6gLkAWvi4dO1x1KQLEXG3q1bch/tSAAFOd+fK+wKhH5S1e 1rzs/PWDPUSK0PzgbPJQoMrJ3wGhxwyywseaw0AGHZOBWiiciOobWt8pIcID9rr2sRNA d5nWNn7+f4TtPzqixWoiw6WpN0IzTCkCHmbTT3FhhkWKB9ymwjKGHhkU3LXYPlc+fIWa l9hw== X-Forwarded-Encrypted: i=1; AJvYcCVkOEX5AIa8BTQNxWdOJhV/SDYDKZ2uOhgXVegJorG4Q7lrbEwxiAmGElyIA6gPRUpN020m2WNGj/My@nongnu.org X-Gm-Message-State: AOJu0YzDFoBjSU8aunb/PXGObS36qUaYD5gcJ6SDavkQBE7jD4v8tGew lN2tZHAlhBuT40sb2rHvjVy4w9vfsLfZYxhplz8mbY4Q0gosTRNEDtzOuTEV X-Gm-Gg: ASbGncv/eQOPLrmC+ye5uuGY2EMbO0jXUOsVZNj5uvGIWZVFTgSjSgoUqCG/TFTrtWf SnTKKEHHq/Npo2GuR47ykaW9EE3XT0RJF7LbzmC8VBnweqX38oDSykoo5PyOGxr+kbbuoMF6JAn KUI5/jb+8AyfVyo6/kvU6jUUj4s4Dg8lMTgbblPPYDefhoGKsFVUpyuqXlXuYzcBRnYlTlhY25I OGFneoONmvKE4if4CG2YwyyPRSfB3Awtzq7cdtPSjsyWPVJ5mdVEL3gxYKU5blkjV+Vy7PPeJ8V xh7aU8K43bow5wgN/5U= X-Google-Smtp-Source: AGHT+IEvZua6Wun32X42LNi8saoHubNgbLELEtXvvpL9my6jbgSBe7wUP10cI69p1Kq18Z+3jyoTQw== X-Received: by 2002:a05:6820:54b:b0:5e1:ea03:9286 with SMTP id 006d021491bc7-5f2870a4d80mr867773eaf.6.1733443700505; Thu, 05 Dec 2024 16:08:20 -0800 (PST) Received: from takeshi-suzuki-dev01.colo.rubrik.com ([104.171.196.13]) by smtp.gmail.com with ESMTPSA id 006d021491bc7-5f2793046d9sm486212eaf.30.2024.12.05.16.08.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Dec 2024 16:08:20 -0800 (PST) From: Takeshi Suzuki To: qemu-devel@nongnu.org Cc: codyprime@gmail.com, kwolf@redhat.com, hreitz@redhat.com, eblake@redhat.com, armbru@redhat.com, qemu-block@nongnu.org, Takeshi Suzuki Subject: [PATCH v2 3/3] Add VHDX specific image info Date: Thu, 5 Dec 2024 16:07:51 -0800 Message-Id: <20241206000751.34694-4-takeshibaconsuzuki@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20241206000751.34694-1-takeshibaconsuzuki@gmail.com> References: <20241206000751.34694-1-takeshibaconsuzuki@gmail.com> Received-SPF: pass client-ip=2607:f8b0:4864:20::c36; envelope-from=takeshibaconsuzuki@gmail.com; helo=mail-oo1-xc36.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Show logical sector size as follows: ``` Format specific information: logical sector size: 4096 ``` Signed-off-by: Takeshi Suzuki --- block/vhdx.c | 21 +++++++++++++++++++++ qapi/block-core.json | 27 +++++++++++++++++++++++++-- 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/block/vhdx.c b/block/vhdx.c index 495ddc2815..957aa99c2d 100644 --- a/block/vhdx.c +++ b/block/vhdx.c @@ -2270,6 +2270,26 @@ static int GRAPH_RDLOCK vhdx_has_zero_init(BlockDriverState *bs) return 1; } +static ImageInfoSpecific * GRAPH_RDLOCK +vhdx_get_specific_info(BlockDriverState *bs, Error **errp) +{ + const BDRVVHDXState *const s = bs->opaque; + ImageInfoSpecific *const spec_info = g_new0(ImageInfoSpecific, 1); + + *spec_info = (ImageInfoSpecific){ + .type = IMAGE_INFO_SPECIFIC_KIND_VHDX, + .u = { + .vhdx.data = g_new0(ImageInfoSpecificVHDX, 1), + }, + }; + + *spec_info->u.vhdx.data = (ImageInfoSpecificVHDX) { + .logical_sector_size = s->logical_sector_size, + }; + + return spec_info; +} + static QemuOptsList vhdx_create_opts = { .name = "vhdx-create-opts", .head = QTAILQ_HEAD_INITIALIZER(vhdx_create_opts.head), @@ -2321,6 +2341,7 @@ static BlockDriver bdrv_vhdx = { .bdrv_co_writev = vhdx_co_writev, .bdrv_co_create = vhdx_co_create, .bdrv_co_create_opts = vhdx_co_create_opts, + .bdrv_get_specific_info = vhdx_get_specific_info, .bdrv_co_get_info = vhdx_co_get_info, .bdrv_co_check = vhdx_co_check, .bdrv_has_zero_init = vhdx_has_zero_init, diff --git a/qapi/block-core.json b/qapi/block-core.json index fd3bcc1c17..7d6ac22776 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -179,6 +179,18 @@ '*extent-size-hint': 'size' } } +## +# @ImageInfoSpecificVHDX: +# +# @logical-sector-size: Logical sector size +# +# Since: 9.2 +## +{ 'struct': 'ImageInfoSpecificVHDX', + 'data': { + 'logical-sector-size': 'int' + } } + ## # @ImageInfoSpecificKind: # @@ -191,7 +203,7 @@ # Since: 1.7 ## { 'enum': 'ImageInfoSpecificKind', - 'data': [ 'qcow2', 'vmdk', 'luks', 'rbd', 'file' ] } + 'data': [ 'qcow2', 'vmdk', 'luks', 'rbd', 'file', 'vhdx' ] } ## # @ImageInfoSpecificQCow2Wrapper: @@ -246,6 +258,16 @@ { 'struct': 'ImageInfoSpecificFileWrapper', 'data': { 'data': 'ImageInfoSpecificFile' } } +## +# @ImageInfoSpecificVHDXWrapper: +# +# @data: image information specific to VHDX +# +# Since: 9.2 +## +{ 'struct': 'ImageInfoSpecificVHDXWrapper', + 'data': { 'data': 'ImageInfoSpecificVHDX' } } + ## # @ImageInfoSpecific: # @@ -264,7 +286,8 @@ 'vmdk': 'ImageInfoSpecificVmdkWrapper', 'luks': 'ImageInfoSpecificLUKSWrapper', 'rbd': 'ImageInfoSpecificRbdWrapper', - 'file': 'ImageInfoSpecificFileWrapper' + 'file': 'ImageInfoSpecificFileWrapper', + 'vhdx': 'ImageInfoSpecificVHDXWrapper' } } ##