All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kevin Wolf <kwolf@redhat.com>
To: Sanne Raymaekers <sraymaek@redhat.com>
Cc: qemu-devel@nongnu.org, hreitz@redhat.com, fam@euphon.net
Subject: Re: [PATCH 2/3] block/vmdk: skip RGD for stream optimized disks
Date: Wed, 7 Oct 2026 16:40:31 +0200	[thread overview]
Message-ID: <asZZ3_1EptsU4Uk7@redhat.com> (raw)
In-Reply-To: <20261005133316.198087-2-sraymaek@redhat.com>

Am 05.10.2026 um 15:33 hat Sanne Raymaekers geschrieben:
> Stream optimized disks the spec notes: "The rgdOffset should be ignored
> because bit 1 of the flags field is not set." Where bit 1 of the flags
> field indicates a redundant grain directory (RGD).[^1]
> 
> In short, stream optimized disks should have the RGD offset set to 0,
> and only write the main grain directory.
> 
> [^1] Virtual Disk Format 5.0 Technical Note.
> 
> Signed-off-by: Sanne Raymaekers <sraymaek@redhat.com>
> ---
>  block/vmdk.c | 76 +++++++++++++++++++++++++++++++---------------------
>  1 file changed, 46 insertions(+), 30 deletions(-)
> 
> diff --git a/block/vmdk.c b/block/vmdk.c
> index 3cdca06fff..040f38cd1d 100644
> --- a/block/vmdk.c
> +++ b/block/vmdk.c
> @@ -2218,7 +2218,7 @@ vmdk_co_pwrite_zeroes(BlockDriverState *bs, int64_t offset, int64_t bytes,
>  
>  static int coroutine_fn GRAPH_UNLOCKED
>  vmdk_init_extent(BlockBackend *blk, int64_t filesize, bool flat, bool compress,
> -                 bool zeroed_grain, Error **errp)
> +                 bool zeroed_grain, bool stream_optimized, Error **errp)

You changed quite a few functions to add a new stream_optimized
parameter. This seems unnecessary as there is already a compress
parameter, which originates in vmdk_co_do_create() like this:

    compress = subformat == BLOCKDEV_VMDK_SUBFORMAT_STREAMOPTIMIZED;

So stream_optimized duplicates the same information.

>  {
>      int ret, i;
>      VMDK4Header header;
> @@ -2239,9 +2239,10 @@ vmdk_init_extent(BlockBackend *blk, int64_t filesize, bool flat, bool compress,
>      } else {
>          header.version = 1;
>      }
> -    header.flags = VMDK4_FLAG_RGD | VMDK4_FLAG_NL_DETECT
> +    header.flags =  VMDK4_FLAG_NL_DETECT

Minor formatting issue: There are two spaces before VMDK4_FLAG_NL_DETECT.

>                     | (compress ? VMDK4_FLAG_COMPRESS | VMDK4_FLAG_MARKER : 0)
> -                   | (zeroed_grain ? VMDK4_FLAG_ZERO_GRAIN : 0);
> +                   | (zeroed_grain ? VMDK4_FLAG_ZERO_GRAIN : 0)
> +                   | (stream_optimized ? 0 : VMDK4_FLAG_RGD);
>      header.compressAlgorithm = compress ? VMDK4_COMPRESSION_DEFLATE : 0;
>      header.capacity = filesize / BDRV_SECTOR_SIZE;
>      header.granularity = 128;
> @@ -2255,8 +2256,15 @@ vmdk_init_extent(BlockBackend *blk, int64_t filesize, bool flat, bool compress,
>  
>      header.desc_offset = 1;
>      header.desc_size = 20;
> -    header.rgd_offset = header.desc_offset + header.desc_size;
> -    header.gd_offset = header.rgd_offset + gd_sectors + (gt_size * gt_count);
> +
> +    if (stream_optimized) {
> +        header.rgd_offset = 0;
> +        header.gd_offset = header.desc_offset + header.desc_size;
> +    } else {
> +        header.rgd_offset = header.desc_offset + header.desc_size;
> +        header.gd_offset = header.rgd_offset + gd_sectors + (gt_size * gt_count);
> +    }
> +
>      header.grain_offset =
>          ROUND_UP(header.gd_offset + gd_sectors + (gt_size * gt_count),
>                   header.granularity);
> @@ -2296,21 +2304,24 @@ vmdk_init_extent(BlockBackend *blk, int64_t filesize, bool flat, bool compress,
>          goto exit;
>      }
>  
> -    /* write grain directory */
> +    /* write backup grain directory */

Heh, good point, the existing code had them reversed in the comments.

It would be good to mention this in the commit message because it came
as a surprise that you seemingly swapped them.

>      gd_buf_size = gd_sectors * BDRV_SECTOR_SIZE;
>      gd_buf = g_malloc0(gd_buf_size);
> -    for (i = 0, tmp = le64_to_cpu(header.rgd_offset) + gd_sectors;
> -         i < gt_count; i++, tmp += gt_size) {
> -        gd_buf[i] = cpu_to_le32(tmp);
> -    }
> -    ret = blk_co_pwrite(blk, le64_to_cpu(header.rgd_offset) * BDRV_SECTOR_SIZE,
> -                        gd_buf_size, gd_buf, 0);
> -    if (ret < 0) {
> -        error_setg_errno(errp, -ret, "failed to write VMDK grain directory");
> -        goto exit;
> +
> +    if (!stream_optimized) {
> +        for (i = 0, tmp = le64_to_cpu(header.rgd_offset) + gd_sectors;
> +             i < gt_count; i++, tmp += gt_size) {
> +            gd_buf[i] = cpu_to_le32(tmp);
> +        }
> +        ret = blk_co_pwrite(blk, le64_to_cpu(header.rgd_offset) * BDRV_SECTOR_SIZE,
> +                            gd_buf_size, gd_buf, 0);
> +        if (ret < 0) {
> +            error_setg_errno(errp, -ret, "failed to write VMDK grain directory");

This should probably be "failed to write VMDK backup grain directory"
(you removed the "backup" below, but didn't add it here).

> +            goto exit;
> +        }
>      }
>  
> -    /* write backup grain directory */
> +    /* write grain directory */
>      for (i = 0, tmp = le64_to_cpu(header.gd_offset) + gd_sectors;
>           i < gt_count; i++, tmp += gt_size) {
>          gd_buf[i] = cpu_to_le32(tmp);
> @@ -2319,7 +2330,7 @@ vmdk_init_extent(BlockBackend *blk, int64_t filesize, bool flat, bool compress,
>                          gd_buf_size, gd_buf, 0);
>      if (ret < 0) {
>          error_setg_errno(errp, -ret,
> -                         "failed to write VMDK backup grain directory");
> +                         "failed to write VMDK grain directory");
>      }
>  
>      ret = 0;

Kevin



  reply	other threads:[~2026-10-07 14:41 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-05 13:33 [PATCH 1/3] block/vmdk: align stream optimized data grains on 512 byte chunks Sanne Raymaekers
2026-10-05 13:33 ` [PATCH 2/3] block/vmdk: skip RGD for stream optimized disks Sanne Raymaekers
2026-10-07 14:40   ` Kevin Wolf [this message]
2026-10-05 13:33 ` [PATCH 3/3] block/vmdk: add eos marker " Sanne Raymaekers
2026-10-07 15:19   ` Kevin Wolf
2026-10-07 14:28 ` [PATCH 1/3] block/vmdk: align stream optimized data grains on 512 byte chunks Kevin Wolf
2026-10-08 12:14   ` Sanne Raymaekers

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=asZZ3_1EptsU4Uk7@redhat.com \
    --to=kwolf@redhat.com \
    --cc=fam@euphon.net \
    --cc=hreitz@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=sraymaek@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.