From nobody Tue Feb 10 00:20:05 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1733443734; cv=none; d=zohomail.com; s=zohoarc; b=BqzuBMlqa4C6402mfyTGfNOxAPVSi1a/+K7Gcs6dLvPQB46liJKCRAIfi+3vrkO7fn1Hvl6zEyucHdnAWM4qPkUVAPMRGJhPQiMw6abTkNjFevyIKbwBBfGKn2chR0UKyME7KWqiKgvcA5jZmTO8XvM7pRRXUeCjOFCcgr11ogA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1733443734; h=Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Wui8MJ22WEMSJ4dKXTOKhXCd0e/cs43WDijGmkD/eL4=; b=OBgMZs10PZ28U680RNQrDEfFdpja5mCrnURFWD2EL2x3KuYXyY6krkA8BSyrNypd+7LcvSv12NrG5TbgjDMu2pmh1hQM8+gTbYAJMEMPpX1bDEiqJlU6qDleFxacEZkXMr8pj7nw2vy28NKyYPVsShJ6N68fRfI/jW+c+qLZooo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1733443734396559.7731682904923; Thu, 5 Dec 2024 16:08:54 -0800 (PST) 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) 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) 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) 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 (zohomail.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; 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1733443736834116600 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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; } =20 - /* Currently we only support 512 */ - if (s->logical_sector_size !=3D 512) { + /* Currently we only support 512 and 4096 */ + if (s->logical_sector_size !=3D 512 && s->logical_sector_size !=3D 409= 6) { ret =3D -ENOTSUP; goto exit; } @@ -1060,7 +1060,7 @@ static int vhdx_open(BlockDriverState *bs, QDict *opt= ions, int flags, =20 /* the VHDX spec dictates that virtual_disk_size is always a multiple = of * logical_sector_size */ - bs->total_sectors =3D s->virtual_disk_size >> s->logical_sector_size_b= its; + bs->total_sectors =3D s->virtual_disk_size >> BDRV_SECTOR_BITS; =20 vhdx_calc_bat_entries(s); =20 @@ -1178,11 +1178,52 @@ vhdx_co_get_info(BlockDriverState *bs, BlockDriverI= nfo *bdi) } =20 =20 +/* + * 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 =3D=3D 0) { + *out_nb_sectors =3D 0; + return; + } + const int64_t begin_off =3D bdrv_sector_num * BDRV_SECTOR_SIZE; + const int64_t sector_num =3D begin_off >> s->logical_sector_size_bits; + const int begin_skip =3D begin_off - sector_num * s->logical_sector_si= ze; + const int64_t end_off =3D (bdrv_sector_num + bdrv_nb_sectors) * + BDRV_SECTOR_SIZE; + const int64_t end_sector_num =3D (end_off + s->logical_sector_size - 1= ) >> + s->logical_sector_size_bits; + const int end_skip =3D end_sector_num * s->logical_sector_size - end_o= ff; + const int nb_sectors =3D end_sector_num - sector_num; + *out_sector_num =3D sector_num; + *out_nb_sectors =3D nb_sectors; + *out_begin_skip =3D begin_skip; + *out_end_skip =3D end_skip; +} + + static int coroutine_fn GRAPH_RDLOCK vhdx_co_readv(BlockDriverState *bs, int64_t sector_num, int nb_sectors, QEMUIOVector *qiov) { BDRVVHDXState *s =3D 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 =3D 0; VHDXSectorInfo sinfo; uint64_t bytes_done =3D 0; @@ -1216,9 +1257,16 @@ vhdx_co_readv(BlockDriverState *bs, int64_t sector_n= um, int nb_sectors, qemu_iovec_memset(&hd_qiov, 0, 0, sinfo.bytes_avail); break; case PAYLOAD_BLOCK_FULLY_PRESENT: + if (bytes_done =3D=3D 0) { + sinfo.file_offset +=3D begin_skip; + sinfo.bytes_avail -=3D begin_skip; + } + if (nb_sectors - sinfo.sectors_avail <=3D 0) { + sinfo.bytes_avail -=3D end_skip; + } qemu_co_mutex_unlock(&s->lock); ret =3D bdrv_co_preadv(bs->file, sinfo.file_offset, - sinfo.sectors_avail * BDRV_SECTOR_SIZ= E, + 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 =3D -ENOTSUP; BDRVVHDXState *s =3D 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 =3D -ENOTSUP; VHDXSectorInfo sinfo; uint64_t bytes_done =3D 0; uint64_t bat_entry =3D 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 =3D=3D 0) { + sinfo.file_offset +=3D begin_skip; + sinfo.bytes_avail -=3D begin_skip; + } + if (nb_sectors - sinfo.sectors_avail <=3D 0) { + sinfo.bytes_avail -=3D end_skip; + } qemu_co_mutex_unlock(&s->lock); ret =3D 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) { --=20 2.17.1