From nobody Wed May 14 12:37:29 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1523993034285619.8734840577454; Tue, 17 Apr 2018 12:23:54 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7836F85540; Tue, 17 Apr 2018 19:23:52 +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 4C6697BE52; Tue, 17 Apr 2018 19:23:52 +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 D1226180215F; Tue, 17 Apr 2018 19:23:51 +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 w3HJNmlX008653 for ; Tue, 17 Apr 2018 15:23:48 -0400 Received: by smtp.corp.redhat.com (Postfix) id C2F267E6DF; Tue, 17 Apr 2018 19:23:48 +0000 (UTC) Received: from unknown54ee7586bd10.attlocal.net.com (ovpn-116-30.phx2.redhat.com [10.3.116.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 83C085FC29 for ; Tue, 17 Apr 2018 19:23:48 +0000 (UTC) From: John Ferlan To: libvir-list@redhat.com Date: Tue, 17 Apr 2018 15:23:32 -0400 Message-Id: <20180417192333.16805-2-jferlan@redhat.com> In-Reply-To: <20180417192333.16805-1-jferlan@redhat.com> References: <20180417192333.16805-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 1/2] storage: Separate out the qemu-img help output generation 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Tue, 17 Apr 2018 19:23:53 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Separate out and return the output string for future comparison. Going to need to add new checks shortly. Signed-off-by: John Ferlan --- src/storage/storage_util.c | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/src/storage/storage_util.c b/src/storage/storage_util.c index 897dfdaaee..7df52239c2 100644 --- a/src/storage/storage_util.c +++ b/src/storage/storage_util.c @@ -799,11 +799,10 @@ enum { QEMU_IMG_BACKING_FORMAT_OPTIONS_COMPAT, }; =20 -static bool -virStorageBackendQemuImgSupportsCompat(const char *qemuimg) +static char * +virStorageBackendQemuImgCreateHelp(const char *qemuimg) { - bool ret =3D false; - char *output; + char *output =3D NULL; virCommandPtr cmd =3D NULL; =20 cmd =3D virCommandNewArgList(qemuimg, "create", "-o", "?", "-f", "qcow= 2", @@ -812,34 +811,40 @@ virStorageBackendQemuImgSupportsCompat(const char *qe= muimg) virCommandAddEnvString(cmd, "LC_ALL=3DC"); virCommandSetOutputBuffer(cmd, &output); =20 - if (virCommandRun(cmd, NULL) < 0) - goto cleanup; - - if (strstr(output, "\ncompat ")) - ret =3D true; + ignore_value(virCommandRun(cmd, NULL)); =20 - cleanup: virCommandFree(cmd); - VIR_FREE(output); - return ret; + return output; } =20 =20 +static bool +virStorageBackendQemuImgSupportsCompat(const char *output) +{ + return strstr(output, "\ncompat "); +} + static int virStorageBackendQEMUImgBackingFormat(const char *qemuimg) { + char *output =3D NULL; /* As of QEMU 0.11 the [-o options] support was added via qemu * commit id '9ea2ea71', so we start with that base and figure * out what else we have */ int ret =3D QEMU_IMG_BACKING_FORMAT_OPTIONS; =20 + if (!(output =3D virStorageBackendQemuImgCreateHelp(qemuimg))) + goto cleanup; + /* QEMU 2.0 changed to using a format that only QEMU 1.1 and newer * understands. Since we still support QEMU 0.12 and newer, we need * to be able to handle the previous format as can be set via a * compat=3D0.10 option. */ - if (virStorageBackendQemuImgSupportsCompat(qemuimg)) + if (virStorageBackendQemuImgSupportsCompat(output)) ret =3D QEMU_IMG_BACKING_FORMAT_OPTIONS_COMPAT; =20 + cleanup: + VIR_FREE(output); return ret; } =20 --=20 2.13.6 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list