From patchwork Mon Oct 7 21:49:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cole Robinson X-Patchwork-Id: 175419 Delivered-To: patch@linaro.org Received: by 2002:a92:7e96:0:0:0:0:0 with SMTP id q22csp4845827ill; Mon, 7 Oct 2019 14:49:40 -0700 (PDT) X-Google-Smtp-Source: APXvYqyxjb/ZSqFZxEG/hQjq8UNsEtfGhhuKLbZvty8utMrB8+EbaergbkcG3bWVKNTvpo+iy6kM X-Received: by 2002:a92:39d4:: with SMTP id h81mr31882955ilf.250.1570484980170; Mon, 07 Oct 2019 14:49:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570484980; cv=none; d=google.com; s=arc-20160816; b=Ols8/C645FRD9gKvHPhJlWGVu4WBFpjLQbrH+k4k98pjyH/AKiIITe43Iy0yI2Na8l XnelMEuGrkfKmwimzaYhMdrWVEDa789cE8aa5zXXsudkVMCL0gqH8zB3ScDaQsaWllua GbDrxsCA4RXfsPqWMlnnrXXodz146px63XL0kaxyFuFcgvabM3JLxIPtC61UIlJqALab qeb5ykSvzkNj34Sn2qvxneavLw7c1tdBD5KtAVqbudMEc1YuNi1JP8EyMFfGLd6I9FmG /HP6jpb48q0tlzaMY/Vr+ztna1K/1XrxiJrPaX6ENpIVymlj9Se7QuWIgWl/Mf95wyF6 wAzA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:sender:content-transfer-encoding:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence:subject :mime-version:references:in-reply-to:message-id:date:to:from :delivered-to; bh=l1XIbidfq4Hv0ypGR9hk6RgE9rMDC9wTu608dd9IQrM=; b=SE2ohKx6RFLlkn4IfljSaD7P9Gh+MSOVoDD1xNlrHAnhLp8wUluLBN50zoVZEjVT0j IEOyj/m/it225NdJH0aHNRmGwHR2cE53EH0S9pRpsnbGlidOV3s/VE46WF837MffPEpL cljivSZn45RVVko4ioBxz+Y+zs7Wo8Lpxv0HNbelwezriGnuZD8yT5QX6QNKi/Cs1Z7l ipbYNNM5b3A3rpUmAZUBlKNT9pYmFwzeC2pG4zQLwSGftdx9T23fVkdi+srZ4ZS49/+Q CiuhujP5W28Fh112rl1RCvJX7MEd5bCqOfRLcCHCqzG1WVw6td+QMdlwfC1foOoqlImJ iJWg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of libvir-list-bounces@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com. [209.132.183.28]) by mx.google.com with ESMTPS id t20si19276684jap.69.2019.10.07.14.49.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 07 Oct 2019 14:49:40 -0700 (PDT) Received-SPF: pass (google.com: domain of libvir-list-bounces@redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; Authentication-Results: mx.google.com; spf=pass (google.com: domain of libvir-list-bounces@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id F29B118CB8F7; Mon, 7 Oct 2019 21:49:38 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id CB3475DAAD; Mon, 7 Oct 2019 21:49:38 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 8F0144EE68; Mon, 7 Oct 2019 21:49:38 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x97LnT73014587 for ; Mon, 7 Oct 2019 17:49:29 -0400 Received: by smtp.corp.redhat.com (Postfix) id 4660D5C240; Mon, 7 Oct 2019 21:49:29 +0000 (UTC) Delivered-To: libvir-list@redhat.com Received: from worklaptop.redhat.com (ovpn-123-156.rdu2.redhat.com [10.10.123.156]) by smtp.corp.redhat.com (Postfix) with ESMTP id 378C25C1D4; Mon, 7 Oct 2019 21:49:28 +0000 (UTC) From: Cole Robinson To: libvir-list@redhat.com Date: Mon, 7 Oct 2019 17:49:22 -0400 Message-Id: <8f91d8e24e5076b4909516b7dc155e171a248f2e.1570482718.git.crobinso@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 08/30] storagefile: Push 'start' into qcow2GetBackingStoreFormat X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.63]); Mon, 07 Oct 2019 21:49:39 +0000 (UTC) This is a step towards making this qcow2GetBackingStoreFormat into a generic qcow2 extensions parser Signed-off-by: Cole Robinson --- src/util/virstoragefile.c | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) -- 2.23.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list Reviewed-by: Daniel Henrique Barboza diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index a9a6c3e132..4a3c9df7a2 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -430,10 +430,22 @@ static int qcow2GetBackingStoreFormat(int *format, const char *buf, size_t buf_size, - size_t extension_start, size_t extension_end) { - size_t offset = extension_start; + size_t offset; + size_t extension_start; + int version = virReadBufInt32BE(buf + QCOWX_HDR_VERSION); + + if (version < 2) { + /* QCow1 doesn't have the extensions capability + * used to store backing format */ + return 0; + } + + if (version == 2) + extension_start = QCOW2_HDR_TOTAL_SIZE; + else + extension_start = virReadBufInt32BE(buf + QCOW2v3_HDR_SIZE); /* * The extensions take format of @@ -445,6 +457,7 @@ qcow2GetBackingStoreFormat(int *format, * Unknown extensions can be ignored by skipping * over "length" bytes in the data stream. */ + offset = extension_start; while (offset < (buf_size-8) && offset < (extension_end-8)) { unsigned int magic = virReadBufInt32BE(buf + offset); @@ -487,8 +500,6 @@ qcowXGetBackingStore(char **res, { unsigned long long offset; unsigned int size; - unsigned long long start; - int version; *res = NULL; *format = VIR_STORAGE_FILE_AUTO; @@ -546,18 +557,8 @@ qcowXGetBackingStore(char **res, * is stored at QCOW2v3_HDR_SIZE */ - version = virReadBufInt32BE(buf + QCOWX_HDR_VERSION); - if (version >= 2) { - /* QCow1 doesn't have the extensions capability - * used to store backing format */ - if (version == 2) - start = QCOW2_HDR_TOTAL_SIZE; - else - start = virReadBufInt32BE(buf + QCOW2v3_HDR_SIZE); - if (qcow2GetBackingStoreFormat(format, buf, buf_size, - start, offset) < 0) - return BACKING_STORE_INVALID; - } + if (qcow2GetBackingStoreFormat(format, buf, buf_size, offset) < 0) + return BACKING_STORE_INVALID; return BACKING_STORE_OK; }