From nobody Sun Feb 8 19:56:07 2026 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