From nobody Mon Feb 9 01:50:51 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) client-ip=207.211.31.81; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-2.mimecast.com [207.211.31.81]) by mx.zohomail.com with SMTPS id 1581959676629999.6576751399832; Mon, 17 Feb 2020 09:14:36 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-121-SSXQaZgHP0mzE3M3cbSlyQ-1; Mon, 17 Feb 2020 12:14:33 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C7ADF800D55; Mon, 17 Feb 2020 17:14:26 +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 9D58060BEC; Mon, 17 Feb 2020 17:14:26 +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 5420D35B0E; Mon, 17 Feb 2020 17:14:26 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 01HHEAtU018720 for ; Mon, 17 Feb 2020 12:14:10 -0500 Received: by smtp.corp.redhat.com (Postfix) id A279410001AE; Mon, 17 Feb 2020 17:14:10 +0000 (UTC) Received: from angien.redhat.com (unknown [10.43.2.48]) by smtp.corp.redhat.com (Postfix) with ESMTP id 277B910021B2 for ; Mon, 17 Feb 2020 17:14:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1581959675; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=j2kwdigzaSw2P4dSMOICWY8pRPcyfBfp7bbBirQ9DSA=; b=KDyQCsQQUHfIvoZIFDSonrex/DH2knLm4tafTkjaBuvSZ35+RNidGEvpgix8LybWKPVnjW 0Bivis8nyw4eCHSKM/KmvOZp6Kf9DhqvTs+d/Ui0aiHaCYHRlubD68vZSEii3YB/4AyYrC Weg6ChxYSb7mx+M/PcxIXjmHJ/wZwL0= From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 6/9] virStorageFileGetMetadataRecurse: Extract storage access Date: Mon, 17 Feb 2020 18:13:56 +0100 Message-Id: <674514e31af066620914ff24ca1ec8fe886755df.1581959449.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com 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.12 X-MC-Unique: SSXQaZgHP0mzE3M3cbSlyQ-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Extract the code that directly deals with storage. This allows further simplification and clarification of virStorageFileGetMetadataRecurse. Signed-off-by: Peter Krempa Reviewed-by: Eric Blake --- src/util/virstoragefile.c | 71 ++++++++++++++++++++++++++------------- 1 file changed, 47 insertions(+), 24 deletions(-) diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index bb3fa65a14..1e21d44c67 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -4955,31 +4955,18 @@ virStorageFileReportBrokenChain(int errcode, } -/* Recursive workhorse for virStorageFileGetMetadata. */ static int -virStorageFileGetMetadataRecurse(virStorageSourcePtr src, - virStorageSourcePtr parent, - uid_t uid, gid_t gid, - bool report_broken, - virHashTablePtr cycle, - unsigned int depth) +virStorageFileGetMetadataRecurseReadHeader(virStorageSourcePtr src, + virStorageSourcePtr parent, + uid_t uid, + gid_t gid, + char **buf, + size_t *headerLen, + virHashTablePtr cycle) { int ret =3D -1; const char *uniqueName; - ssize_t headerLen; - int backingFormat; - int rv; - g_autofree char *buf =3D NULL; - g_autoptr(virStorageSource) backingStore =3D NULL; - - VIR_DEBUG("path=3D%s format=3D%d uid=3D%u gid=3D%u", - NULLSTR(src->path), src->format, - (unsigned int)uid, (unsigned int)gid); - - /* exit if we can't load information about the current image */ - rv =3D virStorageFileSupportsBackingChainTraversal(src); - if (rv <=3D 0) - return rv; + ssize_t len; if (virStorageFileInitAs(src, uid, gid) < 0) return -1; @@ -5002,10 +4989,47 @@ virStorageFileGetMetadataRecurse(virStorageSourcePt= r src, if (virHashAddEntry(cycle, uniqueName, NULL) < 0) goto cleanup; - if ((headerLen =3D virStorageFileRead(src, 0, VIR_STORAGE_MAX_HEADER, - &buf)) < 0) + if ((len =3D virStorageFileRead(src, 0, VIR_STORAGE_MAX_HEADER, buf)) = < 0) goto cleanup; + *headerLen =3D len; + ret =3D 0; + + cleanup: + virStorageFileDeinit(src); + return ret; +} + + +/* Recursive workhorse for virStorageFileGetMetadata. */ +static int +virStorageFileGetMetadataRecurse(virStorageSourcePtr src, + virStorageSourcePtr parent, + uid_t uid, gid_t gid, + bool report_broken, + virHashTablePtr cycle, + unsigned int depth) +{ + int ret =3D -1; + size_t headerLen; + int backingFormat; + int rv; + g_autofree char *buf =3D NULL; + g_autoptr(virStorageSource) backingStore =3D NULL; + + VIR_DEBUG("path=3D%s format=3D%d uid=3D%u gid=3D%u", + NULLSTR(src->path), src->format, + (unsigned int)uid, (unsigned int)gid); + + /* exit if we can't load information about the current image */ + rv =3D virStorageFileSupportsBackingChainTraversal(src); + if (rv <=3D 0) + return rv; + + if (virStorageFileGetMetadataRecurseReadHeader(src, parent, uid, gid, + &buf, &headerLen, cycle= ) < 0) + return -1; + if (virStorageFileGetMetadataInternal(src, buf, headerLen, &backingFormat) < 0) goto cleanup; @@ -5081,7 +5105,6 @@ virStorageFileGetMetadataRecurse(virStorageSourcePtr = src, ret =3D 0; cleanup: - virStorageFileDeinit(src); return ret; } --=20 2.24.1