qemu-block
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v4 02/30] qcow2: Convert qcow2_get_cluster_offset() into qcow


From: Max Reitz
Subject: Re: [PATCH v4 02/30] qcow2: Convert qcow2_get_cluster_offset() into qcow2_get_host_offset()
Date: Wed, 8 Apr 2020 12:51:24 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.6.0

On 17.03.20 19:15, Alberto Garcia wrote:
> qcow2_get_cluster_offset() takes an (unaligned) guest offset and
> returns the (aligned) offset of the corresponding cluster in the qcow2
> image.
> 
> In practice none of the callers need to know where the cluster starts
> so this patch makes the function calculate and return the final host
> offset directly. The function is also renamed accordingly.
> 
> There is a pre-existing exception with compressed clusters: in this
> case the function returns the complete cluster descriptor (containing
> the offset and size of the compressed data). This does not change with
> this patch but it is now documented.
> 
> Signed-off-by: Alberto Garcia <address@hidden>
> ---
>  block/qcow2.h         |  4 ++--
>  block/qcow2-cluster.c | 38 ++++++++++++++++++++++----------------
>  block/qcow2.c         | 24 +++++++-----------------
>  3 files changed, 31 insertions(+), 35 deletions(-)
> 
> diff --git a/block/qcow2.h b/block/qcow2.h
> index 0942126232..f47ef6ca4e 100644
> --- a/block/qcow2.h
> +++ b/block/qcow2.h

[...]

>      case QCOW2_CLUSTER_ZERO_ALLOC:
>      case QCOW2_CLUSTER_NORMAL:
>          /* how many allocated clusters ? */
>          c = count_contiguous_clusters(bs, nb_clusters, s->cluster_size,
>                                        &l2_slice[l2_index], QCOW_OFLAG_ZERO);
> -        *cluster_offset &= L2E_OFFSET_MASK;
> -        if (offset_into_cluster(s, *cluster_offset)) {
> +        *host_offset = l2_entry & L2E_OFFSET_MASK;
> +        if (offset_into_cluster(s, *host_offset)) {
>              qcow2_signal_corruption(bs, true, -1, -1,
>                                      "Cluster allocation offset %#"
>                                      PRIx64 " unaligned (L2 offset: %#" PRIx64
> -                                    ", L2 index: %#x)", *cluster_offset,
> +                                    ", L2 index: %#x)", *host_offset,
>                                      l2_offset, l2_index);
>              ret = -EIO;
>              goto fail;
>          }
> -        if (has_data_file(bs) && *cluster_offset != offset - 
> offset_in_cluster)
> +        if (has_data_file(bs) && *host_offset != offset - offset_in_cluster)
>          {

(1) The { should be moved to the preceding line;

(2) I think it makes more sense to move the
“*host_offset += offset_in_cluster” before this condition, so it becomes
“... && *host_offset != offset”.

>              qcow2_signal_corruption(bs, true, -1, -1,
>                                      "External data file host cluster offset 
> %#"

(Maybe we then need to drop the “cluster” from this line, but other than
that, it would fit with this error message.)

Max

>                                      PRIx64 " does not match guest cluster "
>                                      "offset: %#" PRIx64
> -                                    ", L2 index: %#x)", *cluster_offset,
> +                                    ", L2 index: %#x)", *host_offset,
>                                      offset - offset_in_cluster, l2_index);
>              ret = -EIO;
>              goto fail;
>          }
> +        *host_offset += offset_in_cluster;
>          break;
>      default:
>          abort();

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]