From nobody Fri May 3 10:08:27 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) client-ip=207.211.31.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 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-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by mx.zohomail.com with SMTPS id 1581959660013371.0164868831031; Mon, 17 Feb 2020 09:14:20 -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-307-WEC_arjNNdiWOhm5ZAziPQ-1; Mon, 17 Feb 2020 12:14:14 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2D1C2100DFC4; Mon, 17 Feb 2020 17:14:08 +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 B90488B563; Mon, 17 Feb 2020 17:14:07 +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 98F1735B02; Mon, 17 Feb 2020 17:14:06 +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 01HHE4EE018667 for ; Mon, 17 Feb 2020 12:14:04 -0500 Received: by smtp.corp.redhat.com (Postfix) id 655F110001AE; Mon, 17 Feb 2020 17:14:04 +0000 (UTC) Received: from angien.redhat.com (unknown [10.43.2.48]) by smtp.corp.redhat.com (Postfix) with ESMTP id B69F01001B28 for ; Mon, 17 Feb 2020 17:14:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1581959658; 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=bJGFB6TZ4kdtC1o9ECxM3NBWCypYNZ0lc9wP6WdY8rE=; b=GpaUKwBYqHI2ny5TKJ1QT8QMdFYD+QYwsb3VmuFBxAmkJ83vvPAI1L7s15qWL95y1xaAOa 7GnZzTwEUr5JYqKBhqPqu72YQFvXBVBQUMic3wXQNT6YYLIxliOvsWMYnaDQ6vyQfqFTch rmNcRLpXTtYChLyUVwvvUpY6hwqxbjg= From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 1/9] util: storagefile: Drop image format probing by file suffix Date: Mon, 17 Feb 2020 18:13:51 +0100 Message-Id: <8b9739f571c2a0dffcf8ebcef0490e45545def75.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.11 X-MC-Unique: WEC_arjNNdiWOhm5ZAziPQ-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" Probing by file suffix was meant to be a last resort if probing by contents fails or is not supported. For most formats we never specified any suffix. There's a few formats implementing both magic bytes and suffix and finally DMG which had only suffix probing. Since suffix probing is nowhere reliable and only one format depends on in whic has a comment that qemu doesn't do the probing either drop the whole infrastructure. Signed-off-by: Peter Krempa Reviewed-by: Eric Blake --- src/util/virstoragefile.c | 58 ++++++++++++--------------------------- 1 file changed, 17 insertions(+), 41 deletions(-) diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index 9347c7ab30..4d2e39246c 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -146,12 +146,10 @@ struct FileEncryptionInfo { int payloadOffset; /* start offset of the volume data (in 512 byte sec= tors) */ }; -/* Either 'magic' or 'extension' *must* be provided */ struct FileTypeInfo { int magicOffset; /* Byte offset of the magic */ const char *magic; /* Optional string of file magic * to check at head of file */ - const char *extension; /* Optional file extension to check */ enum lv_endian endian; /* Endianness of file format */ int versionOffset; /* Byte offset from start of file @@ -297,17 +295,17 @@ static struct FileEncryptionInfo const qcow2Encryptio= nInfo[] =3D { }; static struct FileTypeInfo const fileTypeInfo[] =3D { - [VIR_STORAGE_FILE_NONE] =3D { 0, NULL, NULL, LV_LITTLE_ENDIAN, + [VIR_STORAGE_FILE_NONE] =3D { 0, NULL, LV_LITTLE_ENDIAN, -1, 0, {0}, 0, 0, 0, NULL, NULL, NULL }, - [VIR_STORAGE_FILE_RAW] =3D { 0, NULL, NULL, LV_LITTLE_ENDIAN, + [VIR_STORAGE_FILE_RAW] =3D { 0, NULL, LV_LITTLE_ENDIAN, -1, 0, {0}, 0, 0, 0, luksEncryptionInfo, NULL, NULL }, - [VIR_STORAGE_FILE_DIR] =3D { 0, NULL, NULL, LV_LITTLE_ENDIAN, + [VIR_STORAGE_FILE_DIR] =3D { 0, NULL, LV_LITTLE_ENDIAN, -1, 0, {0}, 0, 0, 0, NULL, NULL, NULL }, [VIR_STORAGE_FILE_BOCHS] =3D { /*"Bochs Virtual HD Image", */ /* Untested */ - 0, NULL, NULL, + 0, NULL, LV_LITTLE_ENDIAN, 64, 4, {0x20000}, 32+16+16+4+4+4+4+4, 8, 1, NULL, NULL, NULL }, @@ -316,7 +314,7 @@ static struct FileTypeInfo const fileTypeInfo[] =3D { #V2.0 Format modprobe cloop file=3D$0 && mount -r -t iso9660 /dev/cloop $1 */ /* Untested */ - 0, NULL, NULL, + 0, NULL, LV_LITTLE_ENDIAN, -1, 0, {0}, -1, 0, 0, NULL, NULL, NULL }, @@ -324,50 +322,50 @@ static struct FileTypeInfo const fileTypeInfo[] =3D { /* XXX QEMU says there's no magic for dmg, * /usr/share/misc/magic lists double magic (both offsets * would have to match) but then disables that check. */ - 0, NULL, ".dmg", + 0, NULL, 0, -1, 0, {0}, -1, 0, 0, NULL, NULL, NULL }, [VIR_STORAGE_FILE_ISO] =3D { - 32769, "CD001", ".iso", + 32769, "CD001", LV_LITTLE_ENDIAN, -2, 0, {0}, -1, 0, 0, NULL, NULL, NULL }, [VIR_STORAGE_FILE_VPC] =3D { - 0, "conectix", NULL, + 0, "conectix", LV_BIG_ENDIAN, 12, 4, {0x10000}, 8 + 4 + 4 + 8 + 4 + 4 + 2 + 2 + 4, 8, 1, NULL, NULL, NULL }, /* TODO: add getBackingStore function */ [VIR_STORAGE_FILE_VDI] =3D { - 64, "\x7f\x10\xda\xbe", ".vdi", + 64, "\x7f\x10\xda\xbe", LV_LITTLE_ENDIAN, 68, 4, {0x00010001}, 64 + 5 * 4 + 256 + 7 * 4, 8, 1, NULL, NULL, NULL}, /* Not direct file formats, but used for various drivers */ - [VIR_STORAGE_FILE_FAT] =3D { 0, NULL, NULL, LV_LITTLE_ENDIAN, + [VIR_STORAGE_FILE_FAT] =3D { 0, NULL, LV_LITTLE_ENDIAN, -1, 0, {0}, 0, 0, 0, NULL, NULL, NULL }, - [VIR_STORAGE_FILE_VHD] =3D { 0, NULL, NULL, LV_LITTLE_ENDIAN, + [VIR_STORAGE_FILE_VHD] =3D { 0, NULL, LV_LITTLE_ENDIAN, -1, 0, {0}, 0, 0, 0, NULL, NULL, NULL }, - [VIR_STORAGE_FILE_PLOOP] =3D { 0, "WithouFreSpacExt", NULL, LV_LITTLE_= ENDIAN, + [VIR_STORAGE_FILE_PLOOP] =3D { 0, "WithouFreSpacExt", LV_LITTLE_ENDIAN, -2, 0, {0}, PLOOP_IMAGE_SIZE_OFFSET, 0, PLOOP_SIZE_MULTIPLIER, NULL, NULL, NULL }, /* All formats with a backing store probe below here */ [VIR_STORAGE_FILE_COW] =3D { - 0, "OOOM", NULL, + 0, "OOOM", LV_BIG_ENDIAN, 4, 4, {2}, 4+4+1024+4, 8, 1, NULL, cowGetBackingStore, NULL }, [VIR_STORAGE_FILE_QCOW] =3D { - 0, "QFI", NULL, + 0, "QFI", LV_BIG_ENDIAN, 4, 4, {1}, QCOWX_HDR_IMAGE_SIZE, 8, 1, qcow1EncryptionInfo, qcowXGetBackingStore, NULL }, [VIR_STORAGE_FILE_QCOW2] =3D { - 0, "QFI", NULL, + 0, "QFI", LV_BIG_ENDIAN, 4, 4, {2, 3}, QCOWX_HDR_IMAGE_SIZE, 8, 1, qcow2EncryptionInfo, @@ -376,12 +374,12 @@ static struct FileTypeInfo const fileTypeInfo[] =3D { }, [VIR_STORAGE_FILE_QED] =3D { /* https://wiki.qemu.org/Features/QED */ - 0, "QED", NULL, + 0, "QED", LV_LITTLE_ENDIAN, -2, 0, {0}, QED_HDR_IMAGE_SIZE, 8, 1, NULL, qedGetBackingStore, NULL }, [VIR_STORAGE_FILE_VMDK] =3D { - 0, "KDMV", NULL, + 0, "KDMV", LV_LITTLE_ENDIAN, 4, 4, {1, 2, 3}, 4+4+4, 8, 512, NULL, vmdk4GetBackingStore, NULL }, @@ -707,20 +705,6 @@ virStorageFileMatchesMagic(int magicOffset, } -static bool -virStorageFileMatchesExtension(const char *extension, - const char *path) -{ - if (extension =3D=3D NULL) - return false; - - if (virStringHasCaseSuffix(path, extension)) - return true; - - return false; -} - - static bool virStorageFileMatchesVersion(int versionOffset, int versionSize, @@ -842,14 +826,6 @@ virStorageFileProbeFormatFromBuf(const char *path, "Please report new version to libvir-list@redhat.com", path, virStorageFileFormatTypeToString(possibleFormat)); - /* No magic, so check file extension */ - for (i =3D 0; i < VIR_STORAGE_FILE_LAST; i++) { - if (virStorageFileMatchesExtension(fileTypeInfo[i].extension, path= )) { - format =3D i; - goto cleanup; - } - } - cleanup: VIR_DEBUG("format=3D%d", format); return format; --=20 2.24.1 From nobody Fri May 3 10:08:27 2024 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-1.mimecast.com [207.211.31.81]) by mx.zohomail.com with SMTPS id 1581959675667180.3153643548576; Mon, 17 Feb 2020 09:14:35 -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-169-D5J7B6ZrPEm1WU3CTpIS-g-1; Mon, 17 Feb 2020 12:14:28 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 46E048010F8; Mon, 17 Feb 2020 17:14:19 +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 C65F019756; Mon, 17 Feb 2020 17:14:18 +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 6E86B35B06; Mon, 17 Feb 2020 17:14:18 +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 01HHE5RG018676 for ; Mon, 17 Feb 2020 12:14:05 -0500 Received: by smtp.corp.redhat.com (Postfix) id 3ABC410027A3; Mon, 17 Feb 2020 17:14:05 +0000 (UTC) Received: from angien.redhat.com (unknown [10.43.2.48]) by smtp.corp.redhat.com (Postfix) with ESMTP id B4F3510001AE for ; Mon, 17 Feb 2020 17:14:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1581959674; 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=4JvdyhoXoHEqfnAjDdhvl82S5yDZHqI6120s8HYRuGk=; b=KXQua2SAyb0foYKcA1i3+rSJ6iKAEfOXc6HlhFapvT2ciUVLACv8Gsu8p1ZKnnjnjQpnxF hWUJcStdO9vm9bkCjnioeNpVoOxjqt6C4ZPwvqbZcnFlJDZAbAvmh6eDXux+rXSkCVw2eB K6FXP8xR165qIwyGEQY2XfR4DRi9X5g= From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 2/9] virStorageFileGetMetadataRecurse: Remove impossible error report Date: Mon, 17 Feb 2020 18:13:52 +0100 Message-Id: <3edb0665f38190500dfddbd49bfee52ddfb38b35.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.84 on 10.5.11.23 X-MC-Unique: D5J7B6ZrPEm1WU3CTpIS-g-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" We call virStorageFileSupportsBackingChainTraversal which already checks that the 'storageFileRead' callback is non-NULL, which in turn means that virStorageFileRead will not return -2. Signed-off-by: Peter Krempa Reviewed-by: Eric Blake --- src/util/virstoragefile.c | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index 4d2e39246c..7aeeab0739 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -5003,15 +5003,8 @@ virStorageFileGetMetadataRecurse(virStorageSourcePtr= src, goto cleanup; if ((headerLen =3D virStorageFileRead(src, 0, VIR_STORAGE_MAX_HEADER, - &buf)) < 0) { - if (headerLen =3D=3D -2) - virReportError(VIR_ERR_INTERNAL_ERROR, - _("storage file reading is not supported for " - "storage type %s (protocol: %s)"), - virStorageTypeToString(src->type), - virStorageNetProtocolTypeToString(src->protocol= )); + &buf)) < 0) goto cleanup; - } if (virStorageFileGetMetadataInternal(src, buf, headerLen, &backingFormat) < 0) --=20 2.24.1 From nobody Fri May 3 10:08:27 2024 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-1.mimecast.com [207.211.31.81]) by mx.zohomail.com with SMTPS id 15819596769701020.1284855579094; 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-147-IPBivGGhOem08A6_ctKXMw-1; Mon, 17 Feb 2020 12:14:33 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B03868010F5; Mon, 17 Feb 2020 17:14:22 +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 846B519488; Mon, 17 Feb 2020 17:14:22 +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 3989A35B07; Mon, 17 Feb 2020 17:14:22 +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 01HHE6vK018684 for ; Mon, 17 Feb 2020 12:14:06 -0500 Received: by smtp.corp.redhat.com (Postfix) id 10D2D10021B2; Mon, 17 Feb 2020 17:14:06 +0000 (UTC) Received: from angien.redhat.com (unknown [10.43.2.48]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8A7ED10027A3 for ; Mon, 17 Feb 2020 17:14:05 +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=vUL2pshtVM4ZaZ60zpQfW4gDeDBZNpRgwlOovH7sX9g=; b=Qc2qv7G6wPJGhUqv6lNQjnTR41LbMQqlqolOGoIKrAL023IZB15O879mnB3kWiLH0Wb2wl /4luJKGBgaVyzg38LjfP2hu0+VBHrLYjGUq+hHv1TKk3TNIgvH89j1RSabcBdjT/R8E/kJ 10K6oCG+4J4KW36DkvknH4c4UgClW+4= From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 3/9] virStorageFileGetMetadataRecurse: Shuffle around assignment of backing chain depth Date: Mon, 17 Feb 2020 18:13:53 +0100 Message-Id: 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.84 on 10.5.11.23 X-MC-Unique: IPBivGGhOem08A6_ctKXMw-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" Move the assignment to a place where we know that the backing store is present rather than having to check in the cleanup section. Signed-off-by: Peter Krempa Reviewed-by: Eric Blake --- src/util/virstoragefile.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index 7aeeab0739..f8e4102588 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -5053,14 +5053,15 @@ virStorageFileGetMetadataRecurse(virStorageSourcePt= r src, ret =3D 0; goto cleanup; } + + backingStore->id =3D depth; + src->backingStore =3D g_steal_pointer(&backingStore); } else { /* add terminator */ - if (!(backingStore =3D virStorageSourceNew())) + if (!(src->backingStore =3D virStorageSourceNew())) goto cleanup; } - src->backingStore =3D g_steal_pointer(&backingStore); - if (src->externalDataStoreRaw) { g_autoptr(virStorageSource) externalDataStore =3D NULL; @@ -5080,8 +5081,6 @@ virStorageFileGetMetadataRecurse(virStorageSourcePtr = src, ret =3D 0; cleanup: - if (virStorageSourceHasBacking(src)) - src->backingStore->id =3D depth; virStorageFileDeinit(src); return ret; } --=20 2.24.1 From nobody Fri May 3 10:08:27 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) client-ip=207.211.31.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 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-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by mx.zohomail.com with SMTPS id 158195967296871.67458969567792; Mon, 17 Feb 2020 09:14:32 -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-75-Z01fed_EOYCdOFTimWSVXA-1; Mon, 17 Feb 2020 12:14:26 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1D95E100DFC1; Mon, 17 Feb 2020 17:14:18 +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 E4C4D19756; Mon, 17 Feb 2020 17:14:17 +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 79D2135B05; Mon, 17 Feb 2020 17:14:17 +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 01HHE9NQ018705 for ; Mon, 17 Feb 2020 12:14:09 -0500 Received: by smtp.corp.redhat.com (Postfix) id F39A610021B2; Mon, 17 Feb 2020 17:14:08 +0000 (UTC) Received: from angien.redhat.com (unknown [10.43.2.48]) by smtp.corp.redhat.com (Postfix) with ESMTP id 79B3610001AE for ; Mon, 17 Feb 2020 17:14:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1581959671; 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=SPLu4yk2zp+neIUQaHYqkjTT7NTb9kS3mL2vyQNIJS4=; b=Tg4QafUTIsKi4oApfi22m54MVkqw0kObbEjVp/fxpIBRwgJcxlhq8W1EGMw6IlCaTvs6UW 5zQnwxUIrRsJJOA6vq6nJI8HPWY+UsukTjE809i1OoEh/o63j0+OPYBrFJWeoV2eqkRaBl D7pVYDViMJpd4M12M+sNKI8j6J/Yf84= From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 4/9] virStorageFileGetMetadataRecurse: Expect NULL src->path Date: Mon, 17 Feb 2020 18:13:54 +0100 Message-Id: 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.84 on 10.5.11.23 X-MC-Unique: Z01fed_EOYCdOFTimWSVXA-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" The path can be NULL e.g. for NBD disks. Use NULLSTR to prevent use of NULL in %s. Signed-off-by: Peter Krempa Reviewed-by: Eric Blake --- src/util/virstoragefile.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index f8e4102588..cf37744d6f 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -4973,7 +4973,7 @@ virStorageFileGetMetadataRecurse(virStorageSourcePtr = src, g_autoptr(virStorageSource) backingStore =3D NULL; VIR_DEBUG("path=3D%s format=3D%d uid=3D%u gid=3D%u", - src->path, src->format, + NULLSTR(src->path), src->format, (unsigned int)uid, (unsigned int)gid); /* exit if we can't load information about the current image */ @@ -4995,7 +4995,7 @@ virStorageFileGetMetadataRecurse(virStorageSourcePtr = src, if (virHashLookup(cycle, uniqueName)) { virReportError(VIR_ERR_INTERNAL_ERROR, _("backing store for %s (%s) is self-referential"), - src->path, uniqueName); + NULLSTR(src->path), uniqueName); goto cleanup; } --=20 2.24.1 From nobody Fri May 3 10:08:27 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) client-ip=207.211.31.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 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-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by mx.zohomail.com with SMTPS id 158195970535294.86022879956272; Mon, 17 Feb 2020 09:15:05 -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-418-9EOhDqDZNNSFBlbTmbcY3w-1; Mon, 17 Feb 2020 12:14:30 -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 E90BA801F7D; Mon, 17 Feb 2020 17:14:21 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BB6C460BEC; Mon, 17 Feb 2020 17:14:21 +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 714401832DF0; Mon, 17 Feb 2020 17:14:21 +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 01HHE9mO018710 for ; Mon, 17 Feb 2020 12:14:09 -0500 Received: by smtp.corp.redhat.com (Postfix) id C969E10001AE; Mon, 17 Feb 2020 17:14:09 +0000 (UTC) Received: from angien.redhat.com (unknown [10.43.2.48]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4FE4610021B2 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=1581959704; 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=MRBAAF4XkEn9oiFBk0qGdxsnN+OhCC2xQ0FVix39T/c=; b=UepMz9+3fkLADw7cm+fJRqPDlRnloYOW+HKbdECrLkLTobKbqQ8Yh7Hl3dp1gTTVMLjm8c fplX9H+TkaVYClwcE2F+S7r0aL1HfYHcMtERYIN9Sf1t0Q9tuRJ43EgG56I7HTOILgNLQ3 2bRNyyG72Fy5GZMTQwHMq0+oCOj+Mh0= From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 5/9] virStorageFileGetMetadataRecurse: Use virHashHasEntry instead of fake pointers Date: Mon, 17 Feb 2020 18:13:55 +0100 Message-Id: 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: 9EOhDqDZNNSFBlbTmbcY3w-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" Replacing virHashLookup by virHashHasEntry allows to use NULL as the payload of the hash table rather than putting a fake '1' pointer into the table. Signed-off-by: Peter Krempa Reviewed-by: Eric Blake --- src/util/virstoragefile.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index cf37744d6f..bb3fa65a14 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -4992,14 +4992,14 @@ virStorageFileGetMetadataRecurse(virStorageSourcePt= r src, if (!(uniqueName =3D virStorageFileGetUniqueIdentifier(src))) goto cleanup; - if (virHashLookup(cycle, uniqueName)) { + if (virHashHasEntry(cycle, uniqueName)) { virReportError(VIR_ERR_INTERNAL_ERROR, _("backing store for %s (%s) is self-referential"), NULLSTR(src->path), uniqueName); goto cleanup; } - if (virHashAddEntry(cycle, uniqueName, (void *)1) < 0) + if (virHashAddEntry(cycle, uniqueName, NULL) < 0) goto cleanup; if ((headerLen =3D virStorageFileRead(src, 0, VIR_STORAGE_MAX_HEADER, --=20 2.24.1 From nobody Fri May 3 10:08:27 2024 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 From nobody Fri May 3 10:08:27 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) client-ip=205.139.110.61; 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 205.139.110.61 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 [205.139.110.61]) by mx.zohomail.com with SMTPS id 158195967594953.55981430405939; Mon, 17 Feb 2020 09:14:35 -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-144-4w-nLs7FOc2zfgsjfz4XJw-1; Mon, 17 Feb 2020 12:14:32 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id BCECE800D53; Mon, 17 Feb 2020 17:14:25 +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 913A61001B28; Mon, 17 Feb 2020 17:14:25 +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 4485635B09; Mon, 17 Feb 2020 17:14:25 +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 01HHEB5u018725 for ; Mon, 17 Feb 2020 12:14:11 -0500 Received: by smtp.corp.redhat.com (Postfix) id 78A6A10021B2; Mon, 17 Feb 2020 17:14:11 +0000 (UTC) Received: from angien.redhat.com (unknown [10.43.2.48]) by smtp.corp.redhat.com (Postfix) with ESMTP id F352C10001AE for ; Mon, 17 Feb 2020 17:14:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1581959674; 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=w2b4zDQMDVMr7ujp+OQtMubn1VogZM/1S19gkdE3tTY=; b=emCLh8YAaRKGGVC4afv6JE4YW9jrYqt2zAaDXdQOyJRmwiJeBAhDlcPrGR0VC3i5bK3vwn /LKShcwr8qQ4USsMDeI/ohaVHLuWocsUsA0lmw2n5difL82sE342EXcqe2PxDldtD4tHFm 5QbuyBdOgtIi4OaueB0IFAY5lD71SHg= From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 7/9] virStorageFileGetMetadataRecurse: Remove 'cleanup' label Date: Mon, 17 Feb 2020 18:13:57 +0100 Message-Id: <1e828b5156ca15b23f1faeb5441225dc71a80561.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.84 on 10.5.11.22 X-MC-Unique: 4w-nLs7FOc2zfgsjfz4XJw-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" There's nothing to clean up. Make it obvious what is returned. Signed-off-by: Peter Krempa Reviewed-by: Eric Blake --- src/util/virstoragefile.c | 50 +++++++++++++++------------------------ 1 file changed, 19 insertions(+), 31 deletions(-) diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index 1e21d44c67..b984204b93 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -5010,7 +5010,6 @@ virStorageFileGetMetadataRecurse(virStorageSourcePtr = src, virHashTablePtr cycle, unsigned int depth) { - int ret =3D -1; size_t headerLen; int backingFormat; int rv; @@ -5030,19 +5029,16 @@ virStorageFileGetMetadataRecurse(virStorageSourcePt= r src, &buf, &headerLen, cycle= ) < 0) return -1; - if (virStorageFileGetMetadataInternal(src, buf, headerLen, - &backingFormat) < 0) - goto cleanup; + if (virStorageFileGetMetadataInternal(src, buf, headerLen, &backingFor= mat) < 0) + return -1; if (src->backingStoreRaw) { if ((rv =3D virStorageSourceNewFromBacking(src, &backingStore)) < = 0) - goto cleanup; + return -1; - if (rv =3D=3D 1) { - /* the backing file would not be usable for VM usage */ - ret =3D 0; - goto cleanup; - } + /* the backing file would not be usable for VM usage */ + if (rv =3D=3D 1) + return 0; backingStore->format =3D backingFormat; @@ -5065,17 +5061,14 @@ virStorageFileGetMetadataRecurse(virStorageSourcePt= r src, if (backingStore->format =3D=3D VIR_STORAGE_FILE_AUTO_SAFE) backingStore->format =3D VIR_STORAGE_FILE_AUTO; - if ((ret =3D virStorageFileGetMetadataRecurse(backingStore, parent, - uid, gid, - report_broken, - cycle, depth + 1)) < 0= ) { + if (virStorageFileGetMetadataRecurse(backingStore, parent, + uid, gid, + report_broken, + cycle, depth + 1) < 0) { if (report_broken) - goto cleanup; - - /* if we fail somewhere midway, just accept and return a - * broken chain */ - ret =3D 0; - goto cleanup; + return -1; + else + return 0; } backingStore->id =3D depth; @@ -5083,7 +5076,7 @@ virStorageFileGetMetadataRecurse(virStorageSourcePtr = src, } else { /* add terminator */ if (!(src->backingStore =3D virStorageSourceNew())) - goto cleanup; + return -1; } if (src->externalDataStoreRaw) { @@ -5091,21 +5084,16 @@ virStorageFileGetMetadataRecurse(virStorageSourcePt= r src, if ((rv =3D virStorageSourceNewFromExternalData(src, &externalDataStore))= < 0) - goto cleanup; + return -1; - if (rv =3D=3D 1) { - /* the file would not be usable for VM usage */ - ret =3D 0; - goto cleanup; - } + /* the file would not be usable for VM usage */ + if (rv =3D=3D 1) + return 0; src->externalDataStore =3D g_steal_pointer(&externalDataStore); } - ret =3D 0; - - cleanup: - return ret; + return 0; } --=20 2.24.1 From nobody Fri May 3 10:08:27 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) client-ip=205.139.110.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 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-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by mx.zohomail.com with SMTPS id 1581959707582776.2172709881322; Mon, 17 Feb 2020 09:15:07 -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-393--4FAnrj3O96Sqm98Fc6Dhw-1; Mon, 17 Feb 2020 12:14:38 -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 6AD86107ACCD; Mon, 17 Feb 2020 17:14:31 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3C2D360BFB; Mon, 17 Feb 2020 17:14:31 +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 E5A601832DF3; Mon, 17 Feb 2020 17:14:30 +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 01HHECmE018730 for ; Mon, 17 Feb 2020 12:14:12 -0500 Received: by smtp.corp.redhat.com (Postfix) id 5019010001AE; Mon, 17 Feb 2020 17:14:12 +0000 (UTC) Received: from angien.redhat.com (unknown [10.43.2.48]) by smtp.corp.redhat.com (Postfix) with ESMTP id C97C410021B2 for ; Mon, 17 Feb 2020 17:14:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1581959706; 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=qXvZOYnmGHe+Tb7/qEP071Jbqro1Joxt0wRH38W2WSs=; b=XD+87TlaqpkDKdl94JDGjn+DsJOhpgLQDXbaW1PtOMwyEL2vuQzgIqED0EXE/u87UpinGr pa8D76wuiek0mEeRiRUxhdGlxxieCoBYO4tqbvezcmBEH0t7U7+puA0sDZjd4lb4DlYQer iXjidwLY5SxQ57G2NzFJuxmg6ONW1vg= From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 8/9] virStorageFileGetMetadataRecurse: Allow format probing under special circumstances Date: Mon, 17 Feb 2020 18:13:58 +0100 Message-Id: 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: -4FAnrj3O96Sqm98Fc6Dhw-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" Allow format probing to work around lazy clients which did not specify their format in the overlay. Format probing will be allowed only, if we are able to probe the image, the probing result was successful and the probed image does not have any backing or data file. This relaxes the restrictions which were imposed in commit 3615e8b39bad in cases when we know that the image probing will not result in security issues or data corruption. We perform the image format detection and in the case that we were able to probe the format and the format does not specify a backing store (or doesn't support backing store) we can use this format. With pre-blockdev configurations this will restore the previous behaviour for the images mentioned above as qemu would probe the format anyways. It also improves error reporting compared to the old state as we now report that the backing chain will be broken in case when there is a backing file. In blockdev configurations this ensures that libvirt will not cause data corruption by ending the chain prematurely without notifying the user, but still allows the old semantics when the users forgot to specify the format. The price for this is that libvirt will need to keep the image format detector still current and working or replace it by invocation of qemu-img. Signed-off-by: Peter Krempa --- src/util/virstoragefile.c | 52 ++++++++++++++++++++++----------------- 1 file changed, 30 insertions(+), 22 deletions(-) diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index b984204b93..bbdf7be094 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -5010,6 +5010,7 @@ virStorageFileGetMetadataRecurse(virStorageSourcePtr = src, virHashTablePtr cycle, unsigned int depth) { + virStorageFileFormat orig_format =3D src->format; size_t headerLen; int backingFormat; int rv; @@ -5020,10 +5021,17 @@ virStorageFileGetMetadataRecurse(virStorageSourcePt= r src, NULLSTR(src->path), src->format, (unsigned int)uid, (unsigned int)gid); + if (src->format =3D=3D VIR_STORAGE_FILE_AUTO_SAFE) + src->format =3D VIR_STORAGE_FILE_AUTO; + /* exit if we can't load information about the current image */ rv =3D virStorageFileSupportsBackingChainTraversal(src); - if (rv <=3D 0) + if (rv <=3D 0) { + if (orig_format =3D=3D VIR_STORAGE_FILE_AUTO) + return -2; + return rv; + } if (virStorageFileGetMetadataRecurseReadHeader(src, parent, uid, gid, &buf, &headerLen, cycle= ) < 0) @@ -5032,6 +5040,18 @@ virStorageFileGetMetadataRecurse(virStorageSourcePtr= src, if (virStorageFileGetMetadataInternal(src, buf, headerLen, &backingFor= mat) < 0) return -1; + /* If we probed the format we MUST ensure that nothing else than the c= urrent + * image (this includes both backing files and external data store) is + * considered for security labelling and/or recursion. */ + if (orig_format =3D=3D VIR_STORAGE_FILE_AUTO) { + if (src->backingStoreRaw || src->externalDataStoreRaw) { + src->format =3D VIR_STORAGE_FILE_RAW; + VIR_FREE(src->backingStoreRaw); + VIR_FREE(src->externalDataStoreRaw); + return -2; + } + } + if (src->backingStoreRaw) { if ((rv =3D virStorageSourceNewFromBacking(src, &backingStore)) < = 0) return -1; @@ -5042,33 +5062,21 @@ virStorageFileGetMetadataRecurse(virStorageSourcePt= r src, backingStore->format =3D backingFormat; - if (backingStore->format =3D=3D VIR_STORAGE_FILE_AUTO) { - /* Assuming the backing store to be raw can lead to failures. = We do - * it only when we must not report an error to prevent losing = VMs. - * Otherwise report an error. - */ - if (report_broken) { + if ((rv =3D virStorageFileGetMetadataRecurse(backingStore, parent, + uid, gid, + report_broken, + cycle, depth + 1)) < 0)= { + if (!report_broken) + return 0; + + if (rv =3D=3D -2) { virReportError(VIR_ERR_OPERATION_INVALID, _("format of backing image '%s' of image '%= s' was not specified in the image metadata " "(See https://libvirt.org/kbase/backing_c= hains.html for troubleshooting)"), src->backingStoreRaw, NULLSTR(src->path)); - return -1; } - backingStore->format =3D VIR_STORAGE_FILE_RAW; - } - - if (backingStore->format =3D=3D VIR_STORAGE_FILE_AUTO_SAFE) - backingStore->format =3D VIR_STORAGE_FILE_AUTO; - - if (virStorageFileGetMetadataRecurse(backingStore, parent, - uid, gid, - report_broken, - cycle, depth + 1) < 0) { - if (report_broken) - return -1; - else - return 0; + return -1; } backingStore->id =3D depth; --=20 2.24.1 From nobody Fri May 3 10:08:27 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) client-ip=205.139.110.61; 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 205.139.110.61 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 [205.139.110.61]) by mx.zohomail.com with SMTPS id 1581959684239871.179133933434; Mon, 17 Feb 2020 09:14:44 -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-66-BJVIrzBeP0-OoZp59TkDhw-1; Mon, 17 Feb 2020 12:14:36 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C496B189F770; Mon, 17 Feb 2020 17:14:30 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9872110001AE; Mon, 17 Feb 2020 17:14:30 +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 4ABD91832DF2; Mon, 17 Feb 2020 17:14:30 +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 01HHED55018738 for ; Mon, 17 Feb 2020 12:14:13 -0500 Received: by smtp.corp.redhat.com (Postfix) id 25D2010027A7; Mon, 17 Feb 2020 17:14:13 +0000 (UTC) Received: from angien.redhat.com (unknown [10.43.2.48]) by smtp.corp.redhat.com (Postfix) with ESMTP id A000310001AE for ; Mon, 17 Feb 2020 17:14:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1581959682; 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=Pl5UNOE9u44ULrzi9rbHDCSGEXzSXh0SS4geAJikUC4=; b=PCfaV2K2Yzrf7JooMa4z9cRzfvtx2r7zoXf3/HMSzw/jzy3l1ePinutiRBGu27EeCalgb9 McIwXDsr27kyIWe700KcK+eVt5l1IFiQw99EIbkmSP1pjhD/1cRG/TXY0Hh7YVAggMn8Im JZ05Z1VN/sZzo/VI4tknUhIfPBxH5Ms= From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 9/9] WIP: Add tool for probing images Date: Mon, 17 Feb 2020 18:13:59 +0100 Message-Id: <3e85b74cfa3942fc3908851ad2bbeb6cb2b2c796.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.84 on 10.5.11.22 X-MC-Unique: BJVIrzBeP0-OoZp59TkDhw-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" Note that this is not finished yet, but allows to test the image detection patches: Prepare few images: qemu-img create -f qcow2 /tmp/base.qcow2 10M qemu-img create -f qcow2 -b /tmp/base.qcow2 /tmp/overlay1-noformat= .qcow2 qemu-img create -f qcow2 -F qcow2 -b /tmp/base.qcow2 /tmp/overlay1-format.q= cow2 qemu-img create -f qcow2 -F qcow2 -b /tmp/overlay1-format.qcow2 /tmp/overla= y2-format.qcow2 qemu-img create -f qcow2 -b /tmp/overlay1-noformat.qcow2 /tmp/over= lay2-noformat.qcow2 qemu-img creage -f qcow2 -b nbd://example/asdf /tmp/nbd-noformat.qcow2 10M (Note that the last one prints error, but that's expected) Probe images: $ ./tests/qemublockprobe -f qcow2 -p /tmp/overlay1-noformat.qcow2 type: file (1) path: /tmp/overlay1-noformat.qcow2 format: qcow2 (14) protocol: none' (0) backing store raw: /tmp/base.qcow2 type: file (1) path: /tmp/base.qcow2 format: qcow2 (14) protocol: none' (0) type: none (0) path: (null) format: none (0) protocol: none' (0) $ ./tests/qemublockprobe -f qcow2 -p /tmp/overlay2-format.qcow2 type: file (1) path: /tmp/overlay2-format.qcow2 format: qcow2 (14) protocol: none' (0) backing store raw: /tmp/overlay1-format.qcow2 type: file (1) path: /tmp/overlay1-format.qcow2 format: qcow2 (14) protocol: none' (0) backing store raw: /tmp/base.qcow2 type: file (1) path: /tmp/base.qcow2 format: qcow2 (14) protocol: none' (0) type: none (0) path: (null) format: none (0) protocol: none' (0) $ ./tests/qemublockprobe -f qcow2 -p /tmp/overlay2-noformat.qcow2 /home/pipo/build/libvirt/gcc/tests/.libs/lt-qemublockprobe: libvirt error: = Requested operation is not valid: format of backing image '/tmp/overlay1-no= format.qcow2' of image '/tmp/overlay2-noformat.qcow2' was not specified in = the image metadata (See https://libvirt.org/kbase/backing_chains.html for t= roubleshooting) $ ./tests/qemublockprobe -f qcow2 -p /tmp/nbd-noformat.qcow2 /home/pipo/build/libvirt/gcc/tests/.libs/lt-qemublockprobe: libvirt error: = Requested operation is not valid: format of backing image 'nbd://example/as= df' of image '/tmp/nbd-noformat.qcow2' was not specified in the image metad= ata (See https://libvirt.org/kbase/backing_chains.html for troubleshooting) --- tests/Makefile.am | 13 ++++- tests/qemublockprobe.c | 130 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 142 insertions(+), 1 deletion(-) create mode 100644 tests/qemublockprobe.c diff --git a/tests/Makefile.am b/tests/Makefile.am index ed5255b62d..a47c7eda22 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -291,7 +291,9 @@ test_programs +=3D qemuxml2argvtest qemuxml2xmltest \ qemufirmwaretest \ qemuvhostusertest \ $(NULL) -test_helpers +=3D qemucapsprobe +test_helpers +=3D qemucapsprobe \ + qemublockprobe \ + $(NULL) test_libraries +=3D libqemumonitortestutils.la \ libqemutestdriver.la \ libqemuxml2argvmock.la \ @@ -652,6 +654,14 @@ qemublocktest_LDADD =3D \ $(qemu_LDADDS) \ $(NULL) +qemublockprobe_SOURCES =3D \ + qemublockprobe.c \ + $(NULL) +qemublockprobe_LDADD =3D \ + ../src/libvirt.la \ + $(qemu_LDADDS) \ + $(NULL) + qemudomaincheckpointxml2xmltest_SOURCES =3D \ qemudomaincheckpointxml2xmltest.c testutilsqemu.c testutilsqemu.h \ testutils.c testutils.h @@ -707,6 +717,7 @@ EXTRA_DIST +=3D qemuxml2argvtest.c qemuxml2xmltest.c \ qemucaps2xmltest.c qemucommandutiltest.c \ qemumemlocktest.c qemucpumock.c testutilshostcpus.h \ qemublocktest.c \ + qemublockprobe.c \ qemumigparamstest.c \ qemusecuritytest.c qemusecuritytest.h \ qemusecuritymock.c \ diff --git a/tests/qemublockprobe.c b/tests/qemublockprobe.c new file mode 100644 index 0000000000..0dbc31028c --- /dev/null +++ b/tests/qemublockprobe.c @@ -0,0 +1,130 @@ +/* + * qemublockprobe.c: image backing chain prober + * + * Copyright (C) 2019 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * . + */ + +#include + +#include +#include + +#include "util/virfile.h" +#include "util/virlog.h" +#include "util/virstoragefile.h" + +#include "virgettext.h" + +#define VIR_FROM_THIS VIR_FROM_QEMU + + +static void +print_source(virStorageSourcePtr src) +{ + size_t i; + + g_print("type: %s (%d)\n", virStorageTypeToString(src->type), src->typ= e); + g_print("path: %s\n", src->path); + g_print("format: %s (%d)\n", virStorageFileFormatTypeToString(src->for= mat), src->format); + g_print("protocol: %s' (%d)\n", virStorageNetProtocolTypeToString(src-= >protocol), src->protocol); + for (i =3D 0; i < src->nhosts; i++) { + virStorageNetHostDefPtr h =3D src->hosts + i; + + g_print("host %zu: name: '%s', port: '%u', transport: '%s'(%d), so= cket: '%s'\n", + i, h->name, h->port, virStorageNetHostTransportTypeToStrin= g(h->transport), + h->transport, h->socket); + } + if (src->sliceStorage) + g_print("slice type: storage, offset: %llu, size: %llu\n", + src->sliceStorage->offset, src->sliceStorage->size); + if (src->backingStoreRaw) + g_print("backing store raw: %s\n", src->backingStoreRaw); + if (src->externalDataStoreRaw) + g_print("external store raw: %s\n", src->externalDataStoreRaw); + if (src->relPath) + g_print("relative path: %s\n", src->relPath); + + g_print("\n"); +} + + +int main(int argc, char **argv) +{ + g_autofree char *path =3D NULL; + g_autofree char *format =3D NULL; + g_autoptr(GError) error =3D NULL; + bool verbose =3D false; + g_autoptr(virStorageSource) src =3D NULL; + GOptionContext *ctx; + virStorageSourcePtr n; + int ret =3D 1; + + GOptionEntry entries[] =3D { + { "path", 'p', 0, G_OPTION_ARG_STRING, &path, "path to image", "DI= R" }, + { "format", 'f', 0, G_OPTION_ARG_STRING, &format, "format of image= ", "DIR" }, + { "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose, "Verbose output"= , NULL }, + { 0 } + }; + + + ctx =3D g_option_context_new("- inspect an image"); + g_option_context_add_main_entries(ctx, entries, PACKAGE); + if (!g_option_context_parse(ctx, &argc, &argv, &error)) { + g_printerr("%s: option parsing failed: %s\n", + argv[0], error->message); + return 1; + } + + if (!path) { + g_printerr("%s: missing path\n", argv[0]); + return 1; + } + + if (virErrorInitialize() < 0) { + g_printerr("%s: failed to initialize error handling\n", argv[0]); + return 1; + } + + virLogSetFromEnv(); + virFileActivateDirOverrideForProg(argv[0]); + + if (!(src =3D virStorageSourceNew())) + goto cleanup; + + src->path =3D g_steal_pointer(&path); + src->type =3D VIR_STORAGE_TYPE_FILE; + + if (format && + (src->format =3D virStorageFileFormatTypeFromString(format)) < 0) { + g_printerr("%s: unknown format '%s'\n", argv[0], format); + goto cleanup; + } + + if (virStorageFileGetMetadata(src, -1, -1, true) < 0) + goto cleanup; + + for (n =3D src; n; n =3D n->backingStore) + print_source(n); + + ret =3D 0; + + cleanup: + if (virGetLastErrorCode() !=3D VIR_ERR_OK) + g_printerr("%s: libvirt error: %s\n", argv[0], virGetLastErrorMess= age()); + + return ret; +} --=20 2.24.1